diff options
author | Christian <c@ethdev.com> | 2014-12-03 14:46:55 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-12-03 17:44:46 +0800 |
commit | 5b6a211b8aea80fc857e043fe5eb33f43c3f7df4 (patch) | |
tree | 3f50bd614fff7fcf75c71f82a82733d4dfc4ef82 /solidityExpressionCompiler.cpp | |
parent | e7201a032429534b4cde33c21c00777c04448b15 (diff) | |
download | dexon-solidity-5b6a211b8aea80fc857e043fe5eb33f43c3f7df4.tar.gz dexon-solidity-5b6a211b8aea80fc857e043fe5eb33f43c3f7df4.tar.zst dexon-solidity-5b6a211b8aea80fc857e043fe5eb33f43c3f7df4.zip |
Import directive.
Diffstat (limited to 'solidityExpressionCompiler.cpp')
-rw-r--r-- | solidityExpressionCompiler.cpp | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/solidityExpressionCompiler.cpp b/solidityExpressionCompiler.cpp index 6ea66bad..b077e262 100644 --- a/solidityExpressionCompiler.cpp +++ b/solidityExpressionCompiler.cpp @@ -86,27 +86,32 @@ bytes compileFirstExpression(const string& _sourceCode, vector<vector<string>> _ vector<vector<string>> _localVariables = {}) { Parser parser; - ASTPointer<ContractDefinition> contract; - BOOST_REQUIRE_NO_THROW(contract = parser.parse(make_shared<Scanner>(CharStream(_sourceCode)))); - NameAndTypeResolver resolver({}); - BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract)); - FirstExpressionExtractor extractor(*contract); - BOOST_REQUIRE(extractor.getExpression() != nullptr); - - CompilerContext context; - for (vector<string> const& function: _functions) - context.addFunction(dynamic_cast<FunctionDefinition const&>(resolveDeclaration(function, resolver))); - for (vector<string> const& variable: _localVariables) - context.addVariable(dynamic_cast<VariableDeclaration const&>(resolveDeclaration(variable, resolver))); - - ExpressionCompiler::compileExpression(context, *extractor.getExpression()); - - for (vector<string> const& function: _functions) - context << context.getFunctionEntryLabel(dynamic_cast<FunctionDefinition const&>(resolveDeclaration(function, resolver))); - bytes instructions = context.getAssembledBytecode(); - // debug - // cout << eth::disassemble(instructions) << endl; - return instructions; + ASTPointer<SourceUnit> sourceUnit; + BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(CharStream(_sourceCode)))); + for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes()) + if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) + { + NameAndTypeResolver resolver({}); + BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract)); + FirstExpressionExtractor extractor(*contract); + BOOST_REQUIRE(extractor.getExpression() != nullptr); + + CompilerContext context; + for (vector<string> const& function: _functions) + context.addFunction(dynamic_cast<FunctionDefinition const&>(resolveDeclaration(function, resolver))); + for (vector<string> const& variable: _localVariables) + context.addVariable(dynamic_cast<VariableDeclaration const&>(resolveDeclaration(variable, resolver))); + + ExpressionCompiler::compileExpression(context, *extractor.getExpression()); + + for (vector<string> const& function: _functions) + context << context.getFunctionEntryLabel(dynamic_cast<FunctionDefinition const&>(resolveDeclaration(function, resolver))); + bytes instructions = context.getAssembledBytecode(); + // debug + // cout << eth::disassemble(instructions) << endl; + return instructions; + } + BOOST_FAIL("No contract found in source."); } } // end anonymous namespace |