diff options
-rw-r--r-- | AST.cpp | 6 | ||||
-rw-r--r-- | DeclarationContainer.h | 2 | ||||
-rw-r--r-- | Exceptions.h | 1 | ||||
-rw-r--r-- | NameAndTypeResolver.cpp | 30 | ||||
-rw-r--r-- | SourceReferenceFormatter.cpp | 30 | ||||
-rw-r--r-- | SourceReferenceFormatter.h | 8 |
6 files changed, 45 insertions, 32 deletions
@@ -151,7 +151,7 @@ void ContractDefinition::checkDuplicateFunctions() const BOOST_THROW_EXCEPTION( DeclarationError() << - errinfo_sourceLocation(getConstructor()->getLocation()) << + errinfo_sourceLocation(functions[getName()].front()->getLocation()) << errinfo_comment("More than one constructor defined.") << errinfo_secondarySourceLocation(ssl) ); @@ -165,9 +165,9 @@ void ContractDefinition::checkDuplicateFunctions() const BOOST_THROW_EXCEPTION( DeclarationError() << errinfo_sourceLocation(overloads[j]->getLocation()) << - errinfo_comment("Function with same name and arguments already defined.") << + errinfo_comment("Function with same name and arguments defined twice.") << errinfo_secondarySourceLocation(SecondarySourceLocation().append( - "The previous declaration is here:", overloads[i]->getLocation())) + "Other declaration is here:", overloads[i]->getLocation())) ); } } diff --git a/DeclarationContainer.h b/DeclarationContainer.h index 9ae25880..94545eef 100644 --- a/DeclarationContainer.h +++ b/DeclarationContainer.h @@ -51,7 +51,7 @@ public: std::set<Declaration const*> resolveName(ASTString const& _name, bool _recursive = false) const; Declaration const* getEnclosingDeclaration() const { return m_enclosingDeclaration; } std::map<ASTString, std::set<Declaration const*>> const& getDeclarations() const { return m_declarations; } - /// @returns weather declaration is valid, and if not also returns previous declaration. + /// @returns whether declaration is valid, and if not also returns previous declaration. Declaration const* conflictingDeclaration(Declaration const& _declaration) const; private: diff --git a/Exceptions.h b/Exceptions.h index 51106c2b..a0031ba7 100644 --- a/Exceptions.h +++ b/Exceptions.h @@ -44,7 +44,6 @@ using errorSourceLocationInfo = std::pair<std::string, SourceLocation>; class SecondarySourceLocation { public: - //SecondarySourceLocation(){} SecondarySourceLocation& append(std::string const& _errMsg, SourceLocation const& _sourceLocation) { infos.push_back(std::make_pair(_errMsg, _sourceLocation)); diff --git a/NameAndTypeResolver.cpp b/NameAndTypeResolver.cpp index a81c8238..813e0452 100644 --- a/NameAndTypeResolver.cpp +++ b/NameAndTypeResolver.cpp @@ -357,25 +357,26 @@ void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaratio { SourceLocation firstDeclarationLocation; SourceLocation secondDeclarationLocation; + Declaration const* conflictingDeclaration = m_scopes[m_currentScope].conflictingDeclaration(_declaration); + solAssert(conflictingDeclaration, ""); - if (_declaration.getLocation().start < m_scopes[m_currentScope].conflictingDeclaration(_declaration)->getLocation().start) + if (_declaration.getLocation().start < conflictingDeclaration->getLocation().start) { firstDeclarationLocation = _declaration.getLocation(); - secondDeclarationLocation = m_scopes[m_currentScope].conflictingDeclaration(_declaration)->getLocation(); + secondDeclarationLocation = conflictingDeclaration->getLocation(); } else { - firstDeclarationLocation = m_scopes[m_currentScope].conflictingDeclaration(_declaration)->getLocation(); + firstDeclarationLocation = conflictingDeclaration->getLocation(); secondDeclarationLocation = _declaration.getLocation(); } - solAssert(m_scopes[m_currentScope].conflictingDeclaration(_declaration), ""); - BOOST_THROW_EXCEPTION(DeclarationError() - << errinfo_sourceLocation(secondDeclarationLocation) - << errinfo_comment("Identifier already declared.") - << errinfo_secondarySourceLocation(SecondarySourceLocation().append( - "The previous declaration is here:", - firstDeclarationLocation - ))); + + BOOST_THROW_EXCEPTION( + DeclarationError() << + errinfo_sourceLocation(secondDeclarationLocation) << + errinfo_comment("Identifier already declared.") << + errinfo_secondarySourceLocation( + SecondarySourceLocation().append("The previous declaration is here:", firstDeclarationLocation))); } _declaration.setScope(m_currentScope); @@ -456,8 +457,11 @@ bool ReferencesResolver::visit(Identifier& _identifier) { auto declarations = m_resolver.getNameFromCurrentScope(_identifier.getName()); if (declarations.empty()) - BOOST_THROW_EXCEPTION(DeclarationError() << errinfo_sourceLocation(_identifier.getLocation()) - << errinfo_comment("Undeclared identifier.")); + BOOST_THROW_EXCEPTION( + DeclarationError() << + errinfo_sourceLocation(_identifier.getLocation()) << + errinfo_comment("Undeclared identifier.") + ); else if (declarations.size() == 1) _identifier.setReferencedDeclaration(**declarations.begin(), m_currentContract); else diff --git a/SourceReferenceFormatter.cpp b/SourceReferenceFormatter.cpp index 87796aa3..e6685135 100644 --- a/SourceReferenceFormatter.cpp +++ b/SourceReferenceFormatter.cpp @@ -32,9 +32,11 @@ namespace dev namespace solidity { -void SourceReferenceFormatter::printSourceLocation(ostream& _stream, - SourceLocation const& _location, - Scanner const& _scanner) +void SourceReferenceFormatter::printSourceLocation( + ostream& _stream, + SourceLocation const& _location, + Scanner const& _scanner +) { int startLine; int startColumn; @@ -64,9 +66,11 @@ void SourceReferenceFormatter::printSourceLocation(ostream& _stream, << "Spanning multiple lines.\n"; } -void SourceReferenceFormatter::printSourceName(ostream& _stream, - SourceLocation const& _location, - Scanner const& _scanner) +void SourceReferenceFormatter::printSourceName( + ostream& _stream, + SourceLocation const& _location, + Scanner const& _scanner +) { int startLine; int startColumn; @@ -74,14 +78,16 @@ void SourceReferenceFormatter::printSourceName(ostream& _stream, _stream << *_location.sourceName << ":" << (startLine + 1) << ":" << (startColumn + 1) << ": "; } -void SourceReferenceFormatter::printExceptionInformation(ostream& _stream, - Exception const& _exception, - string const& _name, - CompilerStack const& _compiler) +void SourceReferenceFormatter::printExceptionInformation( + ostream& _stream, + Exception const& _exception, + string const& _name, + CompilerStack const& _compiler +) { SourceLocation const* location = boost::get_error_info<errinfo_sourceLocation>(_exception); auto secondarylocation = boost::get_error_info<errinfo_secondarySourceLocation>(_exception); - Scanner const* scanner; + Scanner const* scanner = nullptr; if (location) { @@ -101,7 +107,7 @@ void SourceReferenceFormatter::printExceptionInformation(ostream& _stream, if (secondarylocation && !secondarylocation->infos.empty()) { - for(auto info: secondarylocation->infos) + for (auto info: secondarylocation->infos) { scanner = &_compiler.getScanner(*info.second.sourceName); _stream << info.first << " "; diff --git a/SourceReferenceFormatter.h b/SourceReferenceFormatter.h index 43d3882e..ed2564f3 100644 --- a/SourceReferenceFormatter.h +++ b/SourceReferenceFormatter.h @@ -40,8 +40,12 @@ struct SourceReferenceFormatter { public: static void printSourceLocation(std::ostream& _stream, SourceLocation const& _location, Scanner const& _scanner); - static void printExceptionInformation(std::ostream& _stream, Exception const& _exception, - std::string const& _name, CompilerStack const& _compiler); + static void printExceptionInformation( + std::ostream& _stream, + Exception const& _exception, + std::string const& _name, + CompilerStack const& _compiler + ); private: static void printSourceName(std::ostream& _stream, SourceLocation const& _location, Scanner const& _scanner); }; |