Browse Source

small fix

cl-refactor
Liana Husikyan 10 years ago
parent
commit
1c6fcca6e2
  1. 6
      libsolidity/AST.cpp
  2. 2
      libsolidity/DeclarationContainer.h
  3. 1
      libsolidity/Exceptions.h
  4. 30
      libsolidity/NameAndTypeResolver.cpp
  5. 22
      libsolidity/SourceReferenceFormatter.cpp
  6. 8
      libsolidity/SourceReferenceFormatter.h

6
libsolidity/AST.cpp

@ -151,7 +151,7 @@ void ContractDefinition::checkDuplicateFunctions() const
BOOST_THROW_EXCEPTION( BOOST_THROW_EXCEPTION(
DeclarationError() << DeclarationError() <<
errinfo_sourceLocation(getConstructor()->getLocation()) << errinfo_sourceLocation(functions[getName()].front()->getLocation()) <<
errinfo_comment("More than one constructor defined.") << errinfo_comment("More than one constructor defined.") <<
errinfo_secondarySourceLocation(ssl) errinfo_secondarySourceLocation(ssl)
); );
@ -165,9 +165,9 @@ void ContractDefinition::checkDuplicateFunctions() const
BOOST_THROW_EXCEPTION( BOOST_THROW_EXCEPTION(
DeclarationError() << DeclarationError() <<
errinfo_sourceLocation(overloads[j]->getLocation()) << 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( errinfo_secondarySourceLocation(SecondarySourceLocation().append(
"The previous declaration is here:", overloads[i]->getLocation())) "Other declaration is here:", overloads[i]->getLocation()))
); );
} }
} }

2
libsolidity/DeclarationContainer.h

@ -51,7 +51,7 @@ public:
std::set<Declaration const*> resolveName(ASTString const& _name, bool _recursive = false) const; std::set<Declaration const*> resolveName(ASTString const& _name, bool _recursive = false) const;
Declaration const* getEnclosingDeclaration() const { return m_enclosingDeclaration; } Declaration const* getEnclosingDeclaration() const { return m_enclosingDeclaration; }
std::map<ASTString, std::set<Declaration const*>> const& getDeclarations() const { return m_declarations; } 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; Declaration const* conflictingDeclaration(Declaration const& _declaration) const;
private: private:

1
libsolidity/Exceptions.h

@ -44,7 +44,6 @@ using errorSourceLocationInfo = std::pair<std::string, SourceLocation>;
class SecondarySourceLocation class SecondarySourceLocation
{ {
public: public:
//SecondarySourceLocation(){}
SecondarySourceLocation& append(std::string const& _errMsg, SourceLocation const& _sourceLocation) SecondarySourceLocation& append(std::string const& _errMsg, SourceLocation const& _sourceLocation)
{ {
infos.push_back(std::make_pair(_errMsg, _sourceLocation)); infos.push_back(std::make_pair(_errMsg, _sourceLocation));

30
libsolidity/NameAndTypeResolver.cpp

@ -357,25 +357,26 @@ void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaratio
{ {
SourceLocation firstDeclarationLocation; SourceLocation firstDeclarationLocation;
SourceLocation secondDeclarationLocation; 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(); firstDeclarationLocation = _declaration.getLocation();
secondDeclarationLocation = m_scopes[m_currentScope].conflictingDeclaration(_declaration)->getLocation(); secondDeclarationLocation = conflictingDeclaration->getLocation();
} }
else else
{ {
firstDeclarationLocation = m_scopes[m_currentScope].conflictingDeclaration(_declaration)->getLocation(); firstDeclarationLocation = conflictingDeclaration->getLocation();
secondDeclarationLocation = _declaration.getLocation(); secondDeclarationLocation = _declaration.getLocation();
} }
solAssert(m_scopes[m_currentScope].conflictingDeclaration(_declaration), "");
BOOST_THROW_EXCEPTION(DeclarationError() BOOST_THROW_EXCEPTION(
<< errinfo_sourceLocation(secondDeclarationLocation) DeclarationError() <<
<< errinfo_comment("Identifier already declared.") errinfo_sourceLocation(secondDeclarationLocation) <<
<< errinfo_secondarySourceLocation(SecondarySourceLocation().append( errinfo_comment("Identifier already declared.") <<
"The previous declaration is here:", errinfo_secondarySourceLocation(
firstDeclarationLocation SecondarySourceLocation().append("The previous declaration is here:", firstDeclarationLocation)));
)));
} }
_declaration.setScope(m_currentScope); _declaration.setScope(m_currentScope);
@ -456,8 +457,11 @@ bool ReferencesResolver::visit(Identifier& _identifier)
{ {
auto declarations = m_resolver.getNameFromCurrentScope(_identifier.getName()); auto declarations = m_resolver.getNameFromCurrentScope(_identifier.getName());
if (declarations.empty()) if (declarations.empty())
BOOST_THROW_EXCEPTION(DeclarationError() << errinfo_sourceLocation(_identifier.getLocation()) BOOST_THROW_EXCEPTION(
<< errinfo_comment("Undeclared identifier.")); DeclarationError() <<
errinfo_sourceLocation(_identifier.getLocation()) <<
errinfo_comment("Undeclared identifier.")
);
else if (declarations.size() == 1) else if (declarations.size() == 1)
_identifier.setReferencedDeclaration(**declarations.begin(), m_currentContract); _identifier.setReferencedDeclaration(**declarations.begin(), m_currentContract);
else else

22
libsolidity/SourceReferenceFormatter.cpp

@ -32,9 +32,11 @@ namespace dev
namespace solidity namespace solidity
{ {
void SourceReferenceFormatter::printSourceLocation(ostream& _stream, void SourceReferenceFormatter::printSourceLocation(
ostream& _stream,
SourceLocation const& _location, SourceLocation const& _location,
Scanner const& _scanner) Scanner const& _scanner
)
{ {
int startLine; int startLine;
int startColumn; int startColumn;
@ -64,9 +66,11 @@ void SourceReferenceFormatter::printSourceLocation(ostream& _stream,
<< "Spanning multiple lines.\n"; << "Spanning multiple lines.\n";
} }
void SourceReferenceFormatter::printSourceName(ostream& _stream, void SourceReferenceFormatter::printSourceName(
ostream& _stream,
SourceLocation const& _location, SourceLocation const& _location,
Scanner const& _scanner) Scanner const& _scanner
)
{ {
int startLine; int startLine;
int startColumn; int startColumn;
@ -74,14 +78,16 @@ void SourceReferenceFormatter::printSourceName(ostream& _stream,
_stream << *_location.sourceName << ":" << (startLine + 1) << ":" << (startColumn + 1) << ": "; _stream << *_location.sourceName << ":" << (startLine + 1) << ":" << (startColumn + 1) << ": ";
} }
void SourceReferenceFormatter::printExceptionInformation(ostream& _stream, void SourceReferenceFormatter::printExceptionInformation(
ostream& _stream,
Exception const& _exception, Exception const& _exception,
string const& _name, string const& _name,
CompilerStack const& _compiler) CompilerStack const& _compiler
)
{ {
SourceLocation const* location = boost::get_error_info<errinfo_sourceLocation>(_exception); SourceLocation const* location = boost::get_error_info<errinfo_sourceLocation>(_exception);
auto secondarylocation = boost::get_error_info<errinfo_secondarySourceLocation>(_exception); auto secondarylocation = boost::get_error_info<errinfo_secondarySourceLocation>(_exception);
Scanner const* scanner; Scanner const* scanner = nullptr;
if (location) if (location)
{ {
@ -101,7 +107,7 @@ void SourceReferenceFormatter::printExceptionInformation(ostream& _stream,
if (secondarylocation && !secondarylocation->infos.empty()) if (secondarylocation && !secondarylocation->infos.empty())
{ {
for(auto info: secondarylocation->infos) for (auto info: secondarylocation->infos)
{ {
scanner = &_compiler.getScanner(*info.second.sourceName); scanner = &_compiler.getScanner(*info.second.sourceName);
_stream << info.first << " "; _stream << info.first << " ";

8
libsolidity/SourceReferenceFormatter.h

@ -40,8 +40,12 @@ struct SourceReferenceFormatter
{ {
public: public:
static void printSourceLocation(std::ostream& _stream, SourceLocation const& _location, Scanner const& _scanner); static void printSourceLocation(std::ostream& _stream, SourceLocation const& _location, Scanner const& _scanner);
static void printExceptionInformation(std::ostream& _stream, Exception const& _exception, static void printExceptionInformation(
std::string const& _name, CompilerStack const& _compiler); std::ostream& _stream,
Exception const& _exception,
std::string const& _name,
CompilerStack const& _compiler
);
private: private:
static void printSourceName(std::ostream& _stream, SourceLocation const& _location, Scanner const& _scanner); static void printSourceName(std::ostream& _stream, SourceLocation const& _location, Scanner const& _scanner);
}; };

Loading…
Cancel
Save