From 5778af07a390f70692be927f3e9702f1725d78f4 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Aug 2018 12:56:28 +0100 Subject: Do not crash on filesystemFriendlyName if no contracts were compiled --- libsolidity/interface/CompilerStack.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 441c7897..889903f0 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -389,6 +389,9 @@ string const* CompilerStack::runtimeSourceMapping(string const& _contractName) c std::string const CompilerStack::filesystemFriendlyName(string const& _contractName) const { + if (m_contracts.empty()) + BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("No compiled contracts found.")); + // Look up the contract (by its fully-qualified name) Contract const& matchContract = m_contracts.at(_contractName); // Check to see if it could collide on name -- cgit v1.2.3 From be70703f82d7ac0822ce518ca11acb7c34514b00 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Aug 2018 13:00:21 +0100 Subject: Move lastContractName closer to contractNames --- libsolidity/interface/CompilerStack.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 889903f0..082a0939 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -353,6 +353,19 @@ vector CompilerStack::contractNames() const return contractNames; } +string const CompilerStack::lastContractName() const +{ + if (m_contracts.empty()) + BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("No compiled contracts found.")); + // try to find some user-supplied contract + string contractName; + for (auto const& it: m_sources) + for (ASTPointer const& node: it.second.ast->nodes()) + if (auto contract = dynamic_cast(node.get())) + contractName = contract->fullyQualifiedName(); + return contractName; +} + eth::AssemblyItems const* CompilerStack::assemblyItems(string const& _contractName) const { Contract const& currentContract = contract(_contractName); @@ -760,19 +773,6 @@ void CompilerStack::compileContract( _compiledContracts[compiledContract.contract] = &compiler->assembly(); } -string const CompilerStack::lastContractName() const -{ - if (m_contracts.empty()) - BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("No compiled contracts found.")); - // try to find some user-supplied contract - string contractName; - for (auto const& it: m_sources) - for (ASTPointer const& node: it.second.ast->nodes()) - if (auto contract = dynamic_cast(node.get())) - contractName = contract->fullyQualifiedName(); - return contractName; -} - CompilerStack::Contract const& CompilerStack::contract(string const& _contractName) const { if (m_contracts.empty()) -- cgit v1.2.3 From d60cab1983039b3fd7c3eef7ad02246d58a7d1ac Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Aug 2018 13:09:19 +0100 Subject: Add CompilerStack state assertions in internal methods --- libsolidity/interface/CompilerStack.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 082a0939..d6a63f1d 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -329,13 +329,14 @@ bool CompilerStack::compile() if (auto contract = dynamic_cast(node.get())) if (isRequestedContract(*contract)) compileContract(*contract, compiledContracts); - this->link(); m_stackState = CompilationSuccessful; + this->link(); return true; } void CompilerStack::link() { + solAssert(m_stackState >= CompilationSuccessful, ""); for (auto& contract: m_contracts) { contract.second.object.link(m_libraries); @@ -355,8 +356,8 @@ vector CompilerStack::contractNames() const string const CompilerStack::lastContractName() const { - if (m_contracts.empty()) - BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("No compiled contracts found.")); + if (m_stackState < AnalysisSuccessful) + BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful.")); // try to find some user-supplied contract string contractName; for (auto const& it: m_sources) @@ -402,7 +403,7 @@ string const* CompilerStack::runtimeSourceMapping(string const& _contractName) c std::string const CompilerStack::filesystemFriendlyName(string const& _contractName) const { - if (m_contracts.empty()) + if (m_stackState < AnalysisSuccessful) BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("No compiled contracts found.")); // Look up the contract (by its fully-qualified name) @@ -600,6 +601,7 @@ tuple CompilerStack::positionFromSourceLocation(SourceLocati StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string const& _sourcePath) { + solAssert(m_stackState < ParsingSuccessful, ""); StringMap newSources; for (auto const& node: _ast.nodes()) if (ImportDirective const* import = dynamic_cast(node.get())) @@ -633,6 +635,7 @@ StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string string CompilerStack::applyRemapping(string const& _path, string const& _context) { + solAssert(m_stackState < ParsingSuccessful, ""); // Try to find the longest prefix match in all remappings that are active in the current context. auto isPrefixOf = [](string const& _a, string const& _b) { @@ -674,6 +677,8 @@ string CompilerStack::applyRemapping(string const& _path, string const& _context void CompilerStack::resolveImports() { + solAssert(m_stackState == ParsingSuccessful, ""); + // topological sorting (depth first search) of the import graph, cutting potential cycles vector sourceOrder; set sourcesSeen; @@ -718,6 +723,8 @@ void CompilerStack::compileContract( map& _compiledContracts ) { + solAssert(m_stackState >= AnalysisSuccessful, ""); + if ( _compiledContracts.count(&_contract) || !_contract.annotation().unimplementedFunctions.empty() || @@ -775,8 +782,7 @@ void CompilerStack::compileContract( CompilerStack::Contract const& CompilerStack::contract(string const& _contractName) const { - if (m_contracts.empty()) - BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("No compiled contracts found.")); + solAssert(m_stackState >= AnalysisSuccessful, ""); auto it = m_contracts.find(_contractName); if (it != m_contracts.end()) -- cgit v1.2.3 From 87821c53c3a73d3e35a0e50a7c159d9aa5d6b253 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 14 Nov 2018 14:59:30 +0100 Subject: Isolating files shared between Yul- and Solidity language frontend. --- libsolidity/interface/CompilerStack.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index d6a63f1d..08a248dd 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include -- cgit v1.2.3 From d67322a1861d60a88151f7c25d6c3478a9a39acf Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 14 Nov 2018 17:11:55 +0100 Subject: Introduce namespace `langutil` in liblangutil directory. Also: - Use {}-style list initialisation for SourceLocation construction - Introduce new system includes - Changes the API of the Scanner to take source as value (with move) as opposed to as a reference --- libsolidity/interface/CompilerStack.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 08a248dd..a5674705 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -58,6 +58,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; boost::optional CompilerStack::parseRemapping(string const& _remapping) -- cgit v1.2.3 From bb10be789c269927e593b41d37aa0637db68bbe1 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 13 Oct 2017 15:19:53 +0200 Subject: Inject SMTLIB2 queries and responses via standard-json-io. --- libsolidity/interface/CompilerStack.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index a5674705..ae85276e 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -107,6 +107,8 @@ void CompilerStack::reset(bool _keepSources) m_stackState = Empty; m_sources.clear(); } + m_smtlib2Responses.clear(); + m_unhandledSMTLib2Queries.clear(); m_libraries.clear(); m_evmVersion = EVMVersion(); m_optimize = false; @@ -283,9 +285,10 @@ bool CompilerStack::analyze() if (noErrors) { - SMTChecker smtChecker(m_errorReporter, m_smtQuery); + SMTChecker smtChecker(m_errorReporter, m_smtlib2Responses); for (Source const* source: m_sourceOrder) smtChecker.analyze(*source->ast, source->scanner); + m_unhandledSMTLib2Queries += smtChecker.unhandledQueries(); } } catch(FatalError const&) -- cgit v1.2.3 From 713d94476ec5ba61901b538c622c8cca6873c2af Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Fri, 23 Nov 2018 11:31:45 +0100 Subject: Reorder some include files and group 's together (as much as possible) --- libsolidity/interface/CompilerStack.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index a5674705..f3c15cc9 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -45,10 +44,12 @@ #include #include -#include - #include +#include + +#include + #include #include -- cgit v1.2.3 From 22eff22492b2d569fe56b59763ddc1cd1cf9ccf4 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 28 Nov 2018 16:13:36 +0100 Subject: liblangutil: extends CharStream to know about the respective (file-)name (and adapt codebase to it) --- libsolidity/interface/CompilerStack.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index de4a7ec2..cc5a2102 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -125,7 +125,7 @@ bool CompilerStack::addSource(string const& _name, string const& _content, bool { bool existed = m_sources.count(_name) != 0; reset(true); - m_sources[_name].scanner = make_shared(CharStream(_content), _name); + m_sources[_name].scanner = make_shared(CharStream(_content, _name), _name); m_sources[_name].isLibrary = _isLibrary; m_stackState = SourcesSet; return existed; @@ -160,7 +160,7 @@ bool CompilerStack::parse() { string const& newPath = newSource.first; string const& newContents = newSource.second; - m_sources[newPath].scanner = make_shared(CharStream(newContents), newPath); + m_sources[newPath].scanner = make_shared(CharStream(newContents, newPath), newPath); sourcesToParse.push_back(newPath); } } -- cgit v1.2.3 From 0bd9db480f54d846abbdb4218e000f08ead4fbd5 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 29 Nov 2018 17:35:14 +0100 Subject: Add skeleton for contract level checker. --- libsolidity/interface/CompilerStack.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index de4a7ec2..623ccca8 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -225,8 +226,21 @@ bool CompilerStack::analyze() m_contracts[contract->fullyQualifiedName()].contract = contract; } - // This cannot be done in the above loop, because cross-contract types couldn't be resolved. - // A good example is `LibraryName.TypeName x;`. + // Next, we check inheritance, overrides, function collisions and other things at + // contract or function level. + // This also calculates whether a contract is abstract, which is needed by the + // type checker. + ContractLevelChecker contractLevelChecker(m_errorReporter); + for (Source const* source: m_sourceOrder) + for (ASTPointer const& node: source->ast->nodes()) + if (ContractDefinition* contract = dynamic_cast(node.get())) + if (!contractLevelChecker.check(*contract)) + noErrors = false; + + // New we run full type checks that go down to the expression level. This + // cannot be done earlier, because we need cross-contract types and information + // about whether a contract is abstract for the `new` expression. + // This populates the `type` annotation for all expressions. // // Note: this does not resolve overloaded functions. In order to do that, types of arguments are needed, // which is only done one step later. -- cgit v1.2.3 From c48a5264be4221873fe02cac57f6a41a32010fea Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 28 Nov 2018 16:19:22 +0100 Subject: liblangutil: SourceLocation: adds (shared) pointer to underlying CharStream source, eliminating sourceName Also, adapted affecting code to those changes. --- libsolidity/interface/CompilerStack.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index cc5a2102..58229379 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -598,8 +598,8 @@ tuple CompilerStack::positionFromSourceLocation(SourceLocati int startColumn; int endLine; int endColumn; - tie(startLine, startColumn) = scanner(*_sourceLocation.sourceName).translatePositionToLineColumn(_sourceLocation.start); - tie(endLine, endColumn) = scanner(*_sourceLocation.sourceName).translatePositionToLineColumn(_sourceLocation.end); + tie(startLine, startColumn) = scanner(_sourceLocation.source->name()).translatePositionToLineColumn(_sourceLocation.start); + tie(endLine, endColumn) = scanner(_sourceLocation.source->name()).translatePositionToLineColumn(_sourceLocation.end); return make_tuple(++startLine, ++startColumn, ++endLine, ++endColumn); } @@ -922,8 +922,8 @@ string CompilerStack::computeSourceMapping(eth::AssemblyItems const& _items) con SourceLocation const& location = item.location(); int length = location.start != -1 && location.end != -1 ? location.end - location.start : -1; int sourceIndex = - location.sourceName && sourceIndicesMap.count(*location.sourceName) ? - sourceIndicesMap.at(*location.sourceName) : + location.source && sourceIndicesMap.count(location.source->name()) ? + sourceIndicesMap.at(location.source->name()) : -1; char jump = '-'; if (item.getJumpType() == eth::AssemblyItem::JumpType::IntoFunction) -- cgit v1.2.3 From 435f7b3b72157e884344adbc7b62033bd08bb51c Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Thu, 29 Nov 2018 01:58:15 +0100 Subject: liblangutil: Scanner: remove superfluous sourceName field (it's in CharStream already) Also, ParserBase::sourceName() was dead code. Eliminating it should increase test coverage (how sneaky) :-) --- libsolidity/interface/CompilerStack.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 58229379..534073f1 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -125,7 +125,7 @@ bool CompilerStack::addSource(string const& _name, string const& _content, bool { bool existed = m_sources.count(_name) != 0; reset(true); - m_sources[_name].scanner = make_shared(CharStream(_content, _name), _name); + m_sources[_name].scanner = make_shared(CharStream(_content, _name)); m_sources[_name].isLibrary = _isLibrary; m_stackState = SourcesSet; return existed; @@ -160,7 +160,7 @@ bool CompilerStack::parse() { string const& newPath = newSource.first; string const& newContents = newSource.second; - m_sources[newPath].scanner = make_shared(CharStream(newContents, newPath), newPath); + m_sources[newPath].scanner = make_shared(CharStream(newContents, newPath)); sourcesToParse.push_back(newPath); } } -- cgit v1.2.3