diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2014-12-18 23:49:56 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2014-12-18 23:49:56 +0800 |
commit | 0cdacde3b9bc8209c910c0d0df4744390714dffc (patch) | |
tree | 7f3511fcb042b078a0b0b7a595770e28fcf534c7 | |
parent | e6e5d5ea24a495caeae4a3b18fab18248b47841d (diff) | |
parent | f744c34ccc30e053eb61aecb5621f4e8060a8b0c (diff) | |
download | dexon-solidity-0cdacde3b9bc8209c910c0d0df4744390714dffc.tar dexon-solidity-0cdacde3b9bc8209c910c0d0df4744390714dffc.tar.gz dexon-solidity-0cdacde3b9bc8209c910c0d0df4744390714dffc.tar.bz2 dexon-solidity-0cdacde3b9bc8209c910c0d0df4744390714dffc.tar.lz dexon-solidity-0cdacde3b9bc8209c910c0d0df4744390714dffc.tar.xz dexon-solidity-0cdacde3b9bc8209c910c0d0df4744390714dffc.tar.zst dexon-solidity-0cdacde3b9bc8209c910c0d0df4744390714dffc.zip |
Merge branch 'develop' into sol_natspecMultiline
-rw-r--r-- | CompilerStack.cpp | 12 | ||||
-rw-r--r-- | CompilerStack.h | 9 |
2 files changed, 15 insertions, 6 deletions
diff --git a/CompilerStack.cpp b/CompilerStack.cpp index 9fdc88ba..79716fde 100644 --- a/CompilerStack.cpp +++ b/CompilerStack.cpp @@ -36,13 +36,12 @@ namespace dev namespace solidity { -void CompilerStack::addSource(string const& _name, string const& _content) +bool CompilerStack::addSource(string const& _name, string const& _content) { - if (m_sources.count(_name)) - BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Source by given name already exists.")); - + bool existed = m_sources.count(_name); reset(true); m_sources[_name].scanner = make_shared<Scanner>(CharStream(_content), _name); + return existed; } void CompilerStack::setSource(string const& _sourceCode) @@ -181,6 +180,11 @@ SourceUnit const& CompilerStack::getAST(string const& _sourceName) const return *getSource(_sourceName).ast; } +ContractDefinition const& CompilerStack::getContractDefinition(string const& _contractName) const +{ + return *getContract(_contractName).contract; +} + bytes CompilerStack::staticCompile(std::string const& _sourceCode, bool _optimize) { CompilerStack stack; diff --git a/CompilerStack.h b/CompilerStack.h index 5ad6f0a6..358c8fb7 100644 --- a/CompilerStack.h +++ b/CompilerStack.h @@ -57,7 +57,8 @@ public: CompilerStack(): m_parseSuccessful(false) {} /// Adds a source object (e.g. file) to the parser. After this, parse has to be called again. - void addSource(std::string const& _name, std::string const& _content); + /// @returns true if a source object by the name already existed and was replaced. + bool addSource(std::string const& _name, std::string const& _content); void setSource(std::string const& _sourceCode); /// Parses all source units that were added void parse(); @@ -86,9 +87,13 @@ public: /// Can be one of 3 types defined at @c DocumentationType std::string const& getJsonDocumentation(std::string const& _contractName, DocumentationType _type) const; - /// Returns the previously used scanner, useful for counting lines during error reporting. + /// @returns the previously used scanner, useful for counting lines during error reporting. Scanner const& getScanner(std::string const& _sourceName = "") const; + /// @returns the parsed source unit with the supplied name. SourceUnit const& getAST(std::string const& _sourceName = "") const; + /// @returns the parsed contract with the supplied name. Throws an exception if the contract + /// does not exist. + ContractDefinition const& getContractDefinition(std::string const& _contractName) const; /// Compile the given @a _sourceCode to bytecode. If a scanner is provided, it is used for /// scanning the source code - this is useful for printing exception information. |