From 328387d6d0a14143f1634df11036a91fad85cec9 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 3 Dec 2014 07:46:55 +0100 Subject: Import directive. --- AST.cpp | 69 +++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 28 deletions(-) (limited to 'AST.cpp') diff --git a/AST.cpp b/AST.cpp index 4bd0b2c0..697ffe8e 100644 --- a/AST.cpp +++ b/AST.cpp @@ -33,6 +33,19 @@ namespace dev namespace solidity { +void SourceUnit::accept(ASTVisitor& _visitor) +{ + if (_visitor.visit(*this)) + listAccept(m_nodes, _visitor); + _visitor.endVisit(*this); +} + +void ImportDirective::accept(ASTVisitor& _visitor) +{ + _visitor.visit(*this); + _visitor.endVisit(*this); +} + void ContractDefinition::accept(ASTVisitor& _visitor) { if (_visitor.visit(*this)) @@ -57,34 +70,6 @@ void StructDefinition::checkValidityOfMembers() checkRecursion(); } -void StructDefinition::checkMemberTypes() -{ - for (ASTPointer const& member: getMembers()) - if (!member->getType()->canBeStored()) - BOOST_THROW_EXCEPTION(member->createTypeError("Type cannot be used in struct.")); -} - -void StructDefinition::checkRecursion() -{ - set definitionsSeen; - vector queue = {this}; - while (!queue.empty()) - { - StructDefinition const* def = queue.back(); - queue.pop_back(); - if (definitionsSeen.count(def)) - BOOST_THROW_EXCEPTION(ParserError() << errinfo_sourceLocation(def->getLocation()) - << errinfo_comment("Recursive struct definition.")); - definitionsSeen.insert(def); - for (ASTPointer const& member: def->getMembers()) - if (member->getType()->getCategory() == Type::Category::STRUCT) - { - UserDefinedTypeName const& typeName = dynamic_cast(*member->getTypeName()); - queue.push_back(&dynamic_cast(*typeName.getReferencedDeclaration())); - } - } -} - void ParameterList::accept(ASTVisitor& _visitor) { if (_visitor.visit(*this)) @@ -312,6 +297,34 @@ vector ContractDefinition::getInterfaceFunctions() co return exportedFunctions; } +void StructDefinition::checkMemberTypes() +{ + for (ASTPointer const& member: getMembers()) + if (!member->getType()->canBeStored()) + BOOST_THROW_EXCEPTION(member->createTypeError("Type cannot be used in struct.")); +} + +void StructDefinition::checkRecursion() +{ + set definitionsSeen; + vector queue = {this}; + while (!queue.empty()) + { + StructDefinition const* def = queue.back(); + queue.pop_back(); + if (definitionsSeen.count(def)) + BOOST_THROW_EXCEPTION(ParserError() << errinfo_sourceLocation(def->getLocation()) + << errinfo_comment("Recursive struct definition.")); + definitionsSeen.insert(def); + for (ASTPointer const& member: def->getMembers()) + if (member->getType()->getCategory() == Type::Category::STRUCT) + { + UserDefinedTypeName const& typeName = dynamic_cast(*member->getTypeName()); + queue.push_back(&dynamic_cast(*typeName.getReferencedDeclaration())); + } + } +} + void FunctionDefinition::checkTypeRequirements() { for (ASTPointer const& var: getParameters() + getReturnParameters()) -- cgit