diff options
author | Christian <c@ethdev.com> | 2014-12-05 22:27:07 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-12-05 22:27:07 +0800 |
commit | d4a958e1fe96174f8fab09b5360106895c40e09a (patch) | |
tree | 3b1b19552c703690be233d990979580c62b08616 /CompilerStack.cpp | |
parent | d2cf34548322598ae067434a61a171bd190fc2c9 (diff) | |
parent | c8f96589c58c1a0ab290a192e4aa1dfb263d01df (diff) | |
download | dexon-solidity-d4a958e1fe96174f8fab09b5360106895c40e09a.tar.gz dexon-solidity-d4a958e1fe96174f8fab09b5360106895c40e09a.tar.zst dexon-solidity-d4a958e1fe96174f8fab09b5360106895c40e09a.zip |
Merge remote-tracking branch 'ethereum/develop' into sol_import
Conflicts:
libsolidity/CompilerStack.cpp
libsolidity/CompilerStack.h
solc/main.cpp
Diffstat (limited to 'CompilerStack.cpp')
-rw-r--r-- | CompilerStack.cpp | 66 |
1 files changed, 29 insertions, 37 deletions
diff --git a/CompilerStack.cpp b/CompilerStack.cpp index 198ded09..62172384 100644 --- a/CompilerStack.cpp +++ b/CompilerStack.cpp @@ -27,6 +27,7 @@ #include <libsolidity/NameAndTypeResolver.h> #include <libsolidity/Compiler.h> #include <libsolidity/CompilerStack.h> +#include <libsolidity/InterfaceHandler.h> using namespace std; @@ -127,45 +128,34 @@ void CompilerStack::streamAssembly(ostream& _outStream, string const& _contractN string const& CompilerStack::getInterface(std::string const& _contractName) { + return getJsonDocumentation(_contractName, ABI_INTERFACE); +} + +std::string const& CompilerStack::getJsonDocumentation(std::string const& _contractName, enum DocumentationType _type) +{ + if (!m_parseSuccessful) + BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful.")); + Contract& contract = getContract(_contractName); - if (contract.interface.empty()) + + std::unique_ptr<string>* doc; + switch (_type) { - stringstream interface; - interface << '['; - vector<FunctionDefinition const*> exportedFunctions = contract.contract->getInterfaceFunctions(); - unsigned functionsCount = exportedFunctions.size(); - for (FunctionDefinition const* f: exportedFunctions) - { - 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 (--functionsCount > 0) - interface << ","; - } - interface << ']'; - contract.interface = interface.str(); + case NATSPEC_USER: + doc = &contract.userDocumentation; + break; + case NATSPEC_DEV: + doc = &contract.devDocumentation; + break; + case ABI_INTERFACE: + doc = &contract.interface; + break; + default: + BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Illegal documentation type.")); } - return contract.interface; + if (!*doc) + *doc = contract.interfaceHandler->getDocumentation(*contract.contract, _type); + return *(*doc); } Scanner const& CompilerStack::getScanner(string const& _sourceName) @@ -193,7 +183,6 @@ void CompilerStack::reset(bool _keepSources) else m_sources.clear(); m_globalContext.reset(); - m_compiler.reset(); m_sourceOrder.clear(); m_contracts.clear(); } @@ -247,5 +236,8 @@ CompilerStack::Source& CompilerStack::getSource(string const& _sourceName) BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Given source file not found.")); return it->second; } + +CompilerStack::Contract::Contract(): interfaceHandler(make_shared<InterfaceHandler>()) {} + } } |