diff options
Diffstat (limited to 'libsolidity/interface')
-rw-r--r-- | libsolidity/interface/CompilerStack.cpp | 31 | ||||
-rw-r--r-- | libsolidity/interface/CompilerStack.h | 40 | ||||
-rw-r--r-- | libsolidity/interface/ErrorReporter.cpp | 14 | ||||
-rw-r--r-- | libsolidity/interface/ErrorReporter.h | 22 | ||||
-rw-r--r-- | libsolidity/interface/StandardCompiler.cpp | 4 |
5 files changed, 49 insertions, 62 deletions
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 9b630c31..f06dd4d7 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -87,6 +87,7 @@ void CompilerStack::reset(bool _keepSources) m_stackState = Empty; m_sources.clear(); } + m_libraries.clear(); m_optimize = false; m_optimizeRuns = 200; m_globalContext.reset(); @@ -106,12 +107,6 @@ bool CompilerStack::addSource(string const& _name, string const& _content, bool return existed; } -void CompilerStack::setSource(string const& _sourceCode) -{ - reset(); - addSource("", _sourceCode); -} - bool CompilerStack::parse() { //reset @@ -252,23 +247,11 @@ bool CompilerStack::analyze() return false; } -bool CompilerStack::parse(string const& _sourceCode) -{ - setSource(_sourceCode); - return parse(); -} - bool CompilerStack::parseAndAnalyze() { return parse() && analyze(); } -bool CompilerStack::parseAndAnalyze(std::string const& _sourceCode) -{ - setSource(_sourceCode); - return parseAndAnalyze(); -} - vector<string> CompilerStack::contractNames() const { if (m_stackState < AnalysisSuccessful) @@ -279,17 +262,12 @@ vector<string> CompilerStack::contractNames() const return contractNames; } - -bool CompilerStack::compile(bool _optimize, unsigned _runs, map<string, h160> const& _libraries) +bool CompilerStack::compile() { if (m_stackState < AnalysisSuccessful) if (!parseAndAnalyze()) return false; - m_optimize = _optimize; - m_optimizeRuns = _runs; - m_libraries = _libraries; - map<ContractDefinition const*, eth::Assembly const*> compiledContracts; for (Source const* source: m_sourceOrder) for (ASTPointer<ASTNode> const& node: source->ast->nodes()) @@ -300,11 +278,6 @@ bool CompilerStack::compile(bool _optimize, unsigned _runs, map<string, h160> co return true; } -bool CompilerStack::compile(string const& _sourceCode, bool _optimize, unsigned _runs) -{ - return parseAndAnalyze(_sourceCode) && compile(_optimize, _runs); -} - void CompilerStack::link() { for (auto& contract: m_contracts) diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 6b8fb538..356389db 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -96,46 +96,45 @@ public: /// Sets path remappings in the format "context:prefix=target" void setRemappings(std::vector<std::string> const& _remappings); + /// Sets library addresses. Addresses are cleared iff @a _libraries is missing. + /// Will not take effect before running compile. + void setLibraries(std::map<std::string, h160> const& _libraries = std::map<std::string, h160>{}) + { + m_libraries = _libraries; + } + + /// Changes the optimiser settings. + /// Will not take effect before running compile. + void setOptimiserSettings(bool _optimize, unsigned _runs = 200) + { + m_optimize = _optimize; + m_optimizeRuns = _runs; + } + /// Resets the compiler to a state where the sources are not parsed or even removed. + /// Sets the state to SourcesSet if @a _keepSources is true, otherwise to Empty. + /// All settings, with the exception of remappings, are reset. void reset(bool _keepSources = false); /// Adds a source object (e.g. file) to the parser. After this, parse has to be called again. /// @returns true if a source object by the name already existed and was replaced. - void addSources(StringMap const& _nameContents, bool _isLibrary = false) - { - for (auto const& i: _nameContents) addSource(i.first, i.second, _isLibrary); - } bool addSource(std::string const& _name, std::string const& _content, bool _isLibrary = false); - void setSource(std::string const& _sourceCode); /// Parses all source units that were added /// @returns false on error. bool parse(); - /// Sets the given source code as the only source unit apart from standard sources and parses it. - /// @returns false on error. - bool parse(std::string const& _sourceCode); - /// performs the analyisis steps (imports, scopesetting, syntaxCheck, referenceResolving, + /// Performs the analysis steps (imports, scopesetting, syntaxCheck, referenceResolving, /// typechecking, staticAnalysis) on previously set sources /// @returns false on error. bool analyze(); /// Parses and analyzes all source units that were added /// @returns false on error. bool parseAndAnalyze(); - /// Sets the given source code as the only source unit apart from standard sources and parses and analyzes it. - /// @returns false on error. - bool parseAndAnalyze(std::string const& _sourceCode); /// @returns a list of the contract names in the sources. std::vector<std::string> contractNames() const; /// Compiles the source units that were previously added and parsed. /// @returns false on error. - bool compile( - bool _optimize = false, - unsigned _runs = 200, - std::map<std::string, h160> const& _libraries = std::map<std::string, h160>{} - ); - /// Parses and compiles the given source code. - /// @returns false on error. - bool compile(std::string const& _sourceCode, bool _optimize = false, unsigned _runs = 200); + bool compile(); /// @returns the assembled object for a contract. eth::LinkerObject const& object(std::string const& _contractName = "") const; @@ -202,6 +201,7 @@ public: /// @returns the list of errors that occured during parsing and type checking. ErrorList const& errors() { return m_errorReporter.errors(); } + /// @returns the current state. State state() const { return m_stackState; } private: diff --git a/libsolidity/interface/ErrorReporter.cpp b/libsolidity/interface/ErrorReporter.cpp index 6e2667a5..f9ef4ceb 100644 --- a/libsolidity/interface/ErrorReporter.cpp +++ b/libsolidity/interface/ErrorReporter.cpp @@ -42,11 +42,23 @@ void ErrorReporter::warning(string const& _description) error(Error::Type::Warning, SourceLocation(), _description); } -void ErrorReporter::warning(SourceLocation const& _location, string const& _description) +void ErrorReporter::warning( + SourceLocation const& _location, + string const& _description +) { error(Error::Type::Warning, _location, _description); } +void ErrorReporter::warning( + SourceLocation const& _location, + string const& _description, + SecondarySourceLocation const& _secondaryLocation +) +{ + error(Error::Type::Warning, _location, _secondaryLocation, _description); +} + void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, string const& _description) { auto err = make_shared<Error>(_type); diff --git a/libsolidity/interface/ErrorReporter.h b/libsolidity/interface/ErrorReporter.h index e5605d24..8b066a3e 100644 --- a/libsolidity/interface/ErrorReporter.h +++ b/libsolidity/interface/ErrorReporter.h @@ -41,30 +41,30 @@ public: ErrorReporter& operator=(ErrorReporter const& _errorReporter); - void warning(std::string const& _description = std::string()); + void warning(std::string const& _description); + + void warning(SourceLocation const& _location, std::string const& _description); void warning( - SourceLocation const& _location = SourceLocation(), - std::string const& _description = std::string() + SourceLocation const& _location, + std::string const& _description, + SecondarySourceLocation const& _secondaryLocation ); void error( Error::Type _type, - SourceLocation const& _location = SourceLocation(), - std::string const& _description = std::string() - ); - - void declarationError( SourceLocation const& _location, - SecondarySourceLocation const& _secondaryLocation = SecondarySourceLocation(), - std::string const& _description = std::string() + std::string const& _description ); void declarationError( SourceLocation const& _location, - std::string const& _description = std::string() + SecondarySourceLocation const& _secondaryLocation, + std::string const& _description ); + void declarationError(SourceLocation const& _location, std::string const& _description); + void fatalDeclarationError(SourceLocation const& _location, std::string const& _description); void parserError(SourceLocation const& _location, std::string const& _description); diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index 82eeac3d..23687340 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -249,6 +249,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) Json::Value optimizerSettings = settings.get("optimizer", Json::Value()); bool const optimize = optimizerSettings.get("enabled", Json::Value(false)).asBool(); unsigned const optimizeRuns = optimizerSettings.get("runs", Json::Value(200u)).asUInt(); + m_compilerStack.setOptimiserSettings(optimize, optimizeRuns); map<string, h160> libraries; Json::Value jsonLibraries = settings.get("libraries", Json::Value()); @@ -259,6 +260,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) // @TODO use libraries only for the given source libraries[library] = h160(jsonSourceName[library].asString()); } + m_compilerStack.setLibraries(libraries); Json::Value metadataSettings = settings.get("metadata", Json::Value()); m_compilerStack.useMetadataLiteralSources(metadataSettings.get("useLiteralContent", Json::Value(false)).asBool()); @@ -267,7 +269,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) try { - m_compilerStack.compile(optimize, optimizeRuns, libraries); + m_compilerStack.compile(); for (auto const& error: m_compilerStack.errors()) { |