aboutsummaryrefslogtreecommitdiffstats
path: root/CompilerStack.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-12-03 14:46:55 +0800
committerChristian <c@ethdev.com>2014-12-03 17:44:46 +0800
commit328387d6d0a14143f1634df11036a91fad85cec9 (patch)
tree0c790402332a3fdc4fc8beddd57929db148b8c36 /CompilerStack.cpp
parent9dadeea37710fe23a7512035b69356f3405ee6f1 (diff)
downloaddexon-solidity-328387d6d0a14143f1634df11036a91fad85cec9.tar.gz
dexon-solidity-328387d6d0a14143f1634df11036a91fad85cec9.tar.zst
dexon-solidity-328387d6d0a14143f1634df11036a91fad85cec9.zip
Import directive.
Diffstat (limited to 'CompilerStack.cpp')
-rw-r--r--CompilerStack.cpp87
1 files changed, 51 insertions, 36 deletions
diff --git a/CompilerStack.cpp b/CompilerStack.cpp
index 6535e00d..8f8c84fe 100644
--- a/CompilerStack.cpp
+++ b/CompilerStack.cpp
@@ -45,10 +45,14 @@ void CompilerStack::parse()
{
if (!m_scanner)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Source not available."));
- m_contractASTNode = Parser().parse(m_scanner);
+ m_sourceUnitASTNode = Parser().parse(m_scanner);
m_globalContext = make_shared<GlobalContext>();
- m_globalContext->setCurrentContract(*m_contractASTNode);
- NameAndTypeResolver(m_globalContext->getDeclarations()).resolveNamesAndTypes(*m_contractASTNode);
+ for (ASTPointer<ASTNode> const& node: m_sourceUnitASTNode->getNodes())
+ if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
+ {
+ m_globalContext->setCurrentContract(*contract);
+ NameAndTypeResolver(m_globalContext->getDeclarations()).resolveNamesAndTypes(*contract);
+ }
m_parseSuccessful = true;
}
@@ -62,10 +66,16 @@ bytes const& CompilerStack::compile(bool _optimize)
{
if (!m_parseSuccessful)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful."));
- m_bytecode.clear();
- m_compiler = make_shared<Compiler>();
- m_compiler->compileContract(*m_contractASTNode, m_globalContext->getMagicVariables());
- return m_bytecode = m_compiler->getAssembledBytecode(_optimize);
+ //@todo returns only the last contract for now
+ for (ASTPointer<ASTNode> const& node: m_sourceUnitASTNode->getNodes())
+ if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
+ {
+ m_bytecode.clear();
+ m_compiler = make_shared<Compiler>();
+ m_compiler->compileContract(*contract, m_globalContext->getMagicVariables());
+ m_bytecode = m_compiler->getAssembledBytecode(_optimize);
+ }
+ return m_bytecode;
}
bytes const& CompilerStack::compile(string const& _sourceCode, bool _optimize)
@@ -87,40 +97,45 @@ string const& CompilerStack::getInterface()
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful."));
if (m_interface.empty())
{
- stringstream interface;
- interface << '[';
- vector<FunctionDefinition const*> exportedFunctions = m_contractASTNode->getInterfaceFunctions();
- unsigned functionsCount = exportedFunctions.size();
- for (FunctionDefinition const* f: exportedFunctions)
- {
- auto streamVariables = [&](vector<ASTPointer<VariableDeclaration>> const& _vars)
+ //@todo returns only the last contract for now
+ for (ASTPointer<ASTNode> const& node: m_sourceUnitASTNode->getNodes())
+ if (ContractDefinition const* contract = dynamic_cast<ContractDefinition*>(node.get()))
{
- unsigned varCount = _vars.size();
- for (ASTPointer<VariableDeclaration> const& var: _vars)
+ stringstream interface;
+ interface << '[';
+ vector<FunctionDefinition const*> exportedFunctions = contract->getInterfaceFunctions();
+ unsigned functionsCount = exportedFunctions.size();
+ for (FunctionDefinition const* f: exportedFunctions)
{
- interface << "{"
- << "\"name\":" << escaped(var->getName(), false) << ","
- << "\"type\":" << escaped(var->getType()->toString(), false)
+ auto streamVariables = [&](vector<ASTPointer<VariableDeclaration>> const& _vars)
+ {
+ unsigned varCount = _vars.size();
+ for (ASTPointer<VariableDeclaration> const& var: _vars)
+ {
+ interface << "{"
+ << "\"name\":" << escaped(var->getName(), false) << ","
+ << "\"type\":" << escaped(var->getType()->toString(), false)
+ << "}";
+ if (--varCount > 0)
+ interface << ",";
+ }
+ };
+
+ interface << '{'
+ << "\"name\":" << escaped(f->getName(), false) << ","
+ << "\"inputs\":[";
+ streamVariables(f->getParameters());
+ interface << "],"
+ << "\"outputs\":[";
+ streamVariables(f->getReturnParameters());
+ interface << "]"
<< "}";
- if (--varCount > 0)
+ if (--functionsCount > 0)
interface << ",";
}
- };
-
- interface << '{'
- << "\"name\":" << escaped(f->getName(), false) << ","
- << "\"inputs\":[";
- streamVariables(f->getParameters());
- interface << "],"
- << "\"outputs\":[";
- streamVariables(f->getReturnParameters());
- interface << "]"
- << "}";
- if (--functionsCount > 0)
- interface << ",";
- }
- interface << ']';
- m_interface = interface.str();
+ interface << ']';
+ m_interface = interface.str();
+ }
}
return m_interface;
}