From d8673daa5bdc3059cd52222299399c8a3c72a3e4 Mon Sep 17 00:00:00 2001 From: arkpar Date: Wed, 11 Mar 2015 11:14:37 +0100 Subject: [PATCH] style --- mix/ClientModel.cpp | 7 +-- mix/CodeModel.cpp | 143 ++++++++++++++++++++++---------------------- mix/CodeModel.h | 5 +- 3 files changed, 76 insertions(+), 79 deletions(-) diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index 4e099b05b..3949c78e1 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -387,21 +387,20 @@ void ClientModel::showDebuggerForTransaction(ExecutionResult const& _t) } //format solidity context values - QStringList locals; + QStringList locals; for(auto l: solLocals) if (l.first < (int)s.stack.size()) locals.push_back(l.second.name + "\t" + formatValue(l.second.type, s.stack[l.first])); - QStringList storage; + QStringList storage; for(auto st: s.storage) - { if (st.first < std::numeric_limits::max()) { auto storageIter = contract->storage().find(static_cast(st.first)); if (storageIter != contract->storage().end()) storage.push_back(storageIter.value().name + "\t" + formatValue(storageIter.value().type, st.second)); } - } + prevInstructionIndex = instructionIndex; solState = new QSolState(debugData, storage, solCallStack, locals, instruction.getLocation().start, instruction.getLocation().end); } diff --git a/mix/CodeModel.cpp b/mix/CodeModel.cpp index bb258334c..35029aa86 100644 --- a/mix/CodeModel.cpp +++ b/mix/CodeModel.cpp @@ -49,86 +49,87 @@ const std::set c_predefinedContracts = namespace { - using namespace dev::solidity; - class CollectDeclarationsVisitor: public ASTConstVisitor +using namespace dev::solidity; +class CollectDeclarationsVisitor: public ASTConstVisitor +{ +public: + CollectDeclarationsVisitor(QHash* _functions, QHash* _locals, QHash* _storage): + m_functions(_functions), m_locals(_locals), m_storage(_storage), m_functionScope(false), m_storageSlot(0) {} +private: + LocationPair nodeLocation(ASTNode const& _node) { - public: - CollectDeclarationsVisitor(QHash* _functions, QHash* _locals, QHash* _storage): - m_functions(_functions), m_locals(_locals), m_storage(_storage), m_functionScope(false), m_storageSlot(0) {} - private: - QHash* m_functions; - QHash* m_locals; - QHash* m_storage; - bool m_functionScope; - uint m_storageSlot; - - LocationPair nodeLocation(ASTNode const& _node) - { - return LocationPair(_node.getLocation().start, _node.getLocation().end); - } + return LocationPair(_node.getLocation().start, _node.getLocation().end); + } - SolidityType nodeType(Type const* _type) + SolidityType nodeType(Type const* _type) + { + if (!_type) + return SolidityType { SolidityType::Type::UnsignedInteger, 32 }; + switch (_type->getCategory()) { - if (!_type) - return SolidityType { SolidityType::Type::UnsignedInteger, 32 }; - switch (_type->getCategory()) + case Type::Category::Integer: { - case Type::Category::Integer: - { - IntegerType const* it = dynamic_cast(_type); - unsigned size = it->getNumBits() / 8; - SolidityType::Type typeCode = it->isAddress() ? SolidityType::Type::Address : it->isHash() ? SolidityType::Type::Hash : it->isSigned() ? SolidityType::Type::SignedInteger : SolidityType::Type::UnsignedInteger; - return SolidityType { typeCode, size }; - } - case Type::Category::Bool: - return SolidityType { SolidityType::Type::Bool, _type->getSizeOnStack() * 32 }; - case Type::Category::String: - { - StaticStringType const* s = dynamic_cast(_type); - return SolidityType { SolidityType::Type::String, static_cast(s->getNumBytes()) }; - } - case Type::Category::Contract: - return SolidityType { SolidityType::Type::Address, _type->getSizeOnStack() * 32 }; - case Type::Category::Array: - case Type::Category::Enum: - case Type::Category::Function: - case Type::Category::IntegerConstant: - case Type::Category::Magic: - case Type::Category::Mapping: - case Type::Category::Modifier: - case Type::Category::Real: - case Type::Category::Struct: - case Type::Category::TypeType: - case Type::Category::Void: - default: - return SolidityType { SolidityType::Type::UnsignedInteger, 32 }; + IntegerType const* it = dynamic_cast(_type); + unsigned size = it->getNumBits() / 8; + SolidityType::Type typeCode = it->isAddress() ? SolidityType::Type::Address : it->isHash() ? SolidityType::Type::Hash : it->isSigned() ? SolidityType::Type::SignedInteger : SolidityType::Type::UnsignedInteger; + return SolidityType { typeCode, size }; } + case Type::Category::Bool: + return SolidityType { SolidityType::Type::Bool, _type->getSizeOnStack() * 32 }; + case Type::Category::String: + { + StaticStringType const* s = dynamic_cast(_type); + return SolidityType { SolidityType::Type::String, static_cast(s->getNumBytes()) }; + } + case Type::Category::Contract: + return SolidityType { SolidityType::Type::Address, _type->getSizeOnStack() * 32 }; + case Type::Category::Array: + case Type::Category::Enum: + case Type::Category::Function: + case Type::Category::IntegerConstant: + case Type::Category::Magic: + case Type::Category::Mapping: + case Type::Category::Modifier: + case Type::Category::Real: + case Type::Category::Struct: + case Type::Category::TypeType: + case Type::Category::Void: + default: + return SolidityType { SolidityType::Type::UnsignedInteger, 32 }; } + } - virtual bool visit(FunctionDefinition const& _node) - { - m_functions->insert(nodeLocation(_node), QString::fromStdString(_node.getName())); - m_functionScope = true; - return true; - } + virtual bool visit(FunctionDefinition const& _node) + { + m_functions->insert(nodeLocation(_node), QString::fromStdString(_node.getName())); + m_functionScope = true; + return true; + } - virtual void endVisit(FunctionDefinition const&) - { - m_functionScope = false; - } + virtual void endVisit(FunctionDefinition const&) + { + m_functionScope = false; + } - virtual bool visit(VariableDeclaration const& _node) - { - SolidityDeclaration decl; - decl.type = nodeType(_node.getType().get()); - decl.name = QString::fromStdString(_node.getName()); - if (m_functionScope) - m_locals->insert(nodeLocation(_node), decl); - else - m_storage->insert(m_storageSlot++, decl); - return true; - } - }; + virtual bool visit(VariableDeclaration const& _node) + { + SolidityDeclaration decl; + decl.type = nodeType(_node.getType().get()); + decl.name = QString::fromStdString(_node.getName()); + if (m_functionScope) + m_locals->insert(nodeLocation(_node), decl); + else + m_storage->insert(m_storageSlot++, decl); + return true; + } + +private: + QHash* m_functions; + QHash* m_locals; + QHash* m_storage; + bool m_functionScope; + uint m_storageSlot; +}; } void BackgroundWorker::queueCodeChange(int _jobId) diff --git a/mix/CodeModel.h b/mix/CodeModel.h index 92111996c..f274917c4 100644 --- a/mix/CodeModel.h +++ b/mix/CodeModel.h @@ -37,10 +37,7 @@ class QTextDocument; namespace dev { -namespace solidity -{ - class CompilerStack; -} +namespace solidity { class CompilerStack; } namespace mix {