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. 30
      libsolidity/SourceReferenceFormatter.cpp
  6. 8
      libsolidity/SourceReferenceFormatter.h

6
libsolidity/AST.cpp

@ -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()))
);
}
}

2
libsolidity/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:

1
libsolidity/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));

30
libsolidity/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

30
libsolidity/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 << " ";

8
libsolidity/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);
};

Loading…
Cancel
Save