some more style fixes

This commit is contained in:
LianaHus 2015-10-15 16:27:26 +02:00
parent 3871e77946
commit 162d021c3f
7 changed files with 14 additions and 27 deletions

View File

@ -44,14 +44,14 @@ class NameAndTypeResolver: private boost::noncopyable
public: public:
NameAndTypeResolver(std::vector<Declaration const*> const& _globals, ErrorList& _errors); NameAndTypeResolver(std::vector<Declaration const*> const& _globals, ErrorList& _errors);
/// Registers all declarations found in the source unit. /// Registers all declarations found in the source unit.
/// @returns false in case of type error. /// @returns false in case of error.
bool registerDeclarations(SourceUnit& _sourceUnit); bool registerDeclarations(SourceUnit& _sourceUnit);
/// Resolves all names and types referenced from the given contract. /// Resolves all names and types referenced from the given contract.
/// @returns false in case of type error. /// @returns false in case of error.
bool resolveNamesAndTypes(ContractDefinition& _contract); bool resolveNamesAndTypes(ContractDefinition& _contract);
/// Updates the given global declaration (used for "this"). Not to be used with declarations /// Updates the given global declaration (used for "this"). Not to be used with declarations
/// that create their own scope. /// that create their own scope.
/// @returns false in case of type error. /// @returns false in case of error.
bool updateDeclaration(Declaration const& _declaration); bool updateDeclaration(Declaration const& _declaration);
/// Resolves the given @a _name inside the scope @a _scope. If @a _scope is omitted, /// Resolves the given @a _name inside the scope @a _scope. If @a _scope is omitted,

View File

@ -66,7 +66,8 @@ private:
ASTPointer<SourceUnit> Parser::parse(shared_ptr<Scanner> const& _scanner) ASTPointer<SourceUnit> Parser::parse(shared_ptr<Scanner> const& _scanner)
{ {
try{ try
{
m_scanner = _scanner; m_scanner = _scanner;
ASTNodeFactory nodeFactory(*this); ASTNodeFactory nodeFactory(*this);
vector<ASTPointer<ASTNode>> nodes; vector<ASTPointer<ASTNode>> nodes;

View File

@ -34,8 +34,7 @@ class Scanner;
class Parser class Parser
{ {
public: public:
Parser(ErrorList& errors): Parser(ErrorList& errors): m_errors(errors){};
m_errors(errors){};
ASTPointer<SourceUnit> parse(std::shared_ptr<Scanner> const& _scanner); ASTPointer<SourceUnit> parse(std::shared_ptr<Scanner> const& _scanner);
std::shared_ptr<std::string const> const& sourceName() const; std::shared_ptr<std::string const> const& sourceName() const;

View File

@ -43,19 +43,7 @@ bool TypeChecker::checkTypeRequirements(const ContractDefinition& _contract)
if (m_errors.empty()) if (m_errors.empty())
throw; // Something is weird here, rather throw again. throw; // Something is weird here, rather throw again.
} }
return Error::containsOnlyWarnings(m_errors);
return Error::containsOnlyWarnings(m_errors);
// bool success = true;
// for (auto const& it: m_errors)
// {
// auto e = dynamic_cast<Error const*>(it.get());
// if (e->type() != Error::Type::Warning)
// {
// success = false;
// break;
// }
// }
// return success;
} }
TypePointer const& TypeChecker::type(Expression const& _expression) const TypePointer const& TypeChecker::type(Expression const& _expression) const
@ -72,7 +60,6 @@ TypePointer const& TypeChecker::type(VariableDeclaration const& _variable) const
bool TypeChecker::visit(ContractDefinition const& _contract) bool TypeChecker::visit(ContractDefinition const& _contract)
{ {
// We force our own visiting order here. // We force our own visiting order here.
ASTNode::listAccept(_contract.definedStructs(), *this); ASTNode::listAccept(_contract.definedStructs(), *this);
ASTNode::listAccept(_contract.baseContracts(), *this); ASTNode::listAccept(_contract.baseContracts(), *this);

View File

@ -42,7 +42,7 @@ namespace solidity
class TypeChecker: private ASTConstVisitor class TypeChecker: private ASTConstVisitor
{ {
public: public:
/// @_errors the reference to the list of errors and warnings to add them found during type checking. /// @param _errors the reference to the list of errors and warnings to add them found during type checking.
TypeChecker(ErrorList& _errors): m_errors(_errors) {} TypeChecker(ErrorList& _errors): m_errors(_errors) {}
/// Performs type checking on the given contract and all of its sub-nodes. /// Performs type checking on the given contract and all of its sub-nodes.

View File

@ -42,7 +42,7 @@ namespace
ASTPointer<ContractDefinition> parseText(std::string const& _source, ErrorList& _errors) ASTPointer<ContractDefinition> parseText(std::string const& _source, ErrorList& _errors)
{ {
ASTPointer<SourceUnit> sourceUnit = Parser(_errors).parse(std::make_shared<Scanner>(CharStream(_source))); ASTPointer<SourceUnit> sourceUnit = Parser(_errors).parse(std::make_shared<Scanner>(CharStream(_source)));
if(!sourceUnit) if (!sourceUnit)
return ASTPointer<ContractDefinition>(); return ASTPointer<ContractDefinition>();
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes()) for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
if (ASTPointer<ContractDefinition> contract = dynamic_pointer_cast<ContractDefinition>(node)) if (ASTPointer<ContractDefinition> contract = dynamic_pointer_cast<ContractDefinition>(node))
@ -57,7 +57,7 @@ bool successParse(std::string const& _source)
try try
{ {
auto sourceUnit = parseText(_source, errors); auto sourceUnit = parseText(_source, errors);
if(!sourceUnit) if (!sourceUnit)
return false; return false;
} }
catch (FatalError const& _exception) catch (FatalError const& _exception)
@ -68,6 +68,7 @@ bool successParse(std::string const& _source)
if (Error::containsErrorOfType(errors, Error::Type::ParserError)) if (Error::containsErrorOfType(errors, Error::Type::ParserError))
return false; return false;
BOOST_CHECK(Error::containsOnlyWarnings(errors));
return true; return true;
} }
@ -168,7 +169,6 @@ BOOST_AUTO_TEST_CASE(two_exact_functions)
// with support of overloaded functions, during parsing, // with support of overloaded functions, during parsing,
// we can't determine whether they match exactly, however // we can't determine whether they match exactly, however
// it will throw DeclarationError in following stage. // it will throw DeclarationError in following stage.
// TODO add test to the SolidityNameAndTypeDeclaration
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
@ -848,7 +848,7 @@ BOOST_AUTO_TEST_CASE(external_variable)
BOOST_CHECK(!successParse(text)); BOOST_CHECK(!successParse(text));
} }
BOOST_AUTO_TEST_CASE(arrays_in_storagze) BOOST_AUTO_TEST_CASE(arrays_in_storage)
{ {
char const* text = R"( char const* text = R"(
contract c { contract c {

View File

@ -77,12 +77,12 @@ public:
m_compiler.compile(m_optimize, m_optimizeRuns); m_compiler.compile(m_optimize, m_optimizeRuns);
BOOST_REQUIRE(Error::containsErrorOfType(m_compiler.errors(), _type)); BOOST_REQUIRE(Error::containsErrorOfType(m_compiler.errors(), _type));
} }
catch(Error const& _e) catch (Error const& _e)
{ {
BOOST_REQUIRE(_e.type() == _type); BOOST_REQUIRE(_e.type() == _type);
foundError = true; foundError = true;
} }
catch(Exception const& _exception) catch (Exception const& _exception)
{ {
BOOST_REQUIRE(false); BOOST_REQUIRE(false);
} }