diff options
author | Christian <c@ethdev.com> | 2014-12-03 14:46:55 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-12-03 17:44:46 +0800 |
commit | 328387d6d0a14143f1634df11036a91fad85cec9 (patch) | |
tree | 0c790402332a3fdc4fc8beddd57929db148b8c36 /AST.cpp | |
parent | 9dadeea37710fe23a7512035b69356f3405ee6f1 (diff) | |
download | dexon-solidity-328387d6d0a14143f1634df11036a91fad85cec9.tar.gz dexon-solidity-328387d6d0a14143f1634df11036a91fad85cec9.tar.zst dexon-solidity-328387d6d0a14143f1634df11036a91fad85cec9.zip |
Import directive.
Diffstat (limited to 'AST.cpp')
-rw-r--r-- | AST.cpp | 69 |
1 files changed, 41 insertions, 28 deletions
@@ -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<VariableDeclaration> const& member: getMembers()) - if (!member->getType()->canBeStored()) - BOOST_THROW_EXCEPTION(member->createTypeError("Type cannot be used in struct.")); -} - -void StructDefinition::checkRecursion() -{ - set<StructDefinition const*> definitionsSeen; - vector<StructDefinition const*> 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<VariableDeclaration> const& member: def->getMembers()) - if (member->getType()->getCategory() == Type::Category::STRUCT) - { - UserDefinedTypeName const& typeName = dynamic_cast<UserDefinedTypeName&>(*member->getTypeName()); - queue.push_back(&dynamic_cast<StructDefinition const&>(*typeName.getReferencedDeclaration())); - } - } -} - void ParameterList::accept(ASTVisitor& _visitor) { if (_visitor.visit(*this)) @@ -312,6 +297,34 @@ vector<FunctionDefinition const*> ContractDefinition::getInterfaceFunctions() co return exportedFunctions; } +void StructDefinition::checkMemberTypes() +{ + for (ASTPointer<VariableDeclaration> const& member: getMembers()) + if (!member->getType()->canBeStored()) + BOOST_THROW_EXCEPTION(member->createTypeError("Type cannot be used in struct.")); +} + +void StructDefinition::checkRecursion() +{ + set<StructDefinition const*> definitionsSeen; + vector<StructDefinition const*> 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<VariableDeclaration> const& member: def->getMembers()) + if (member->getType()->getCategory() == Type::Category::STRUCT) + { + UserDefinedTypeName const& typeName = dynamic_cast<UserDefinedTypeName&>(*member->getTypeName()); + queue.push_back(&dynamic_cast<StructDefinition const&>(*typeName.getReferencedDeclaration())); + } + } +} + void FunctionDefinition::checkTypeRequirements() { for (ASTPointer<VariableDeclaration> const& var: getParameters() + getReturnParameters()) |