Browse Source

Parsing an enum AST node

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
133969bd2a
  1. 10
      libsolidity/AST.cpp
  2. 5
      libsolidity/AST.h
  3. 2
      libsolidity/ASTPrinter.cpp
  4. 4
      libsolidity/ASTVisitor.h
  5. 24
      libsolidity/AST_accept.h
  6. 2
      libsolidity/Parser.cpp
  7. 2
      libsolidity/Token.h

10
libsolidity/AST.cpp

@ -206,6 +206,12 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
return *m_interfaceFunctionList;
}
TypePointer EnumDeclaration::getType(ContractDefinition const*) const
{
// LTODO
return nullptr;
}
void InheritanceSpecifier::checkTypeRequirements()
{
m_baseName->checkTypeRequirements();
@ -268,7 +274,9 @@ void EnumDefinition::checkValidityOfMembers() const
TypePointer EnumDefinition::getType(ContractDefinition const*) const
{
return make_shared<TypeType>(make_shared<EnumType>(*this));
//LTODO:
return nullptr;
// return make_shared<TypeType>(make_shared<EnumType>(*this));
}
TypePointer FunctionDefinition::getType(ContractDefinition const*) const

5
libsolidity/AST.h

@ -170,10 +170,13 @@ private:
*/
class EnumDeclaration : public Declaration
{
public:
EnumDeclaration(Location const& _location,
ASTPointer<ASTString> const& _name):
Declaration(_location, _name) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
TypePointer getType(ContractDefinition const*) const;
};
@ -717,7 +720,7 @@ public:
Expression const& getCondition() const { return *m_condition; }
Statement const& getTrueStatement() const { return *m_trueBody; }
/// @returns the "else" part of the if statement or nullptr if there is no "else" part.
/// @returns the "else" part of the if statement or nullptr if there is no "else" part.
Statement const* getFalseStatement() const { return m_falseBody.get(); }
private:

2
libsolidity/ASTPrinter.cpp

@ -77,7 +77,7 @@ bool ASTPrinter::visit(EnumDefinition const& _node)
return goDeeper();
}
bool ASTPrinter::visit(EnuumDeclaration const& _node)
bool ASTPrinter::visit(EnumDeclaration const& _node)
{
writeLine("EnumValue \"" + _node.getName() + "\"");
return goDeeper();

4
libsolidity/ASTVisitor.h

@ -48,6 +48,7 @@ public:
virtual bool visit(InheritanceSpecifier&) { return true; }
virtual bool visit(StructDefinition&) { return true; }
virtual bool visit(EnumDefinition&) { return true; }
virtual bool visit(EnumDeclaration&) { return true; }
virtual bool visit(ParameterList&) { return true; }
virtual bool visit(FunctionDefinition&) { return true; }
virtual bool visit(VariableDeclaration&) { return true; }
@ -90,6 +91,7 @@ public:
virtual void endVisit(InheritanceSpecifier&) { }
virtual void endVisit(StructDefinition&) { }
virtual void endVisit(EnumDefinition&) { }
virtual void endVisit(EnumDeclaration&) { }
virtual void endVisit(ParameterList&) { }
virtual void endVisit(FunctionDefinition&) { }
virtual void endVisit(VariableDeclaration&) { }
@ -136,6 +138,7 @@ public:
virtual bool visit(InheritanceSpecifier const&) { return true; }
virtual bool visit(StructDefinition const&) { return true; }
virtual bool visit(EnumDefinition const&) { return true; }
virtual bool visit(EnumDeclaration const&) { return true; }
virtual bool visit(ParameterList const&) { return true; }
virtual bool visit(FunctionDefinition const&) { return true; }
virtual bool visit(VariableDeclaration const&) { return true; }
@ -178,6 +181,7 @@ public:
virtual void endVisit(InheritanceSpecifier const&) { }
virtual void endVisit(StructDefinition const&) { }
virtual void endVisit(EnumDefinition const&) { }
virtual void endVisit(EnumDeclaration const&) { }
virtual void endVisit(ParameterList const&) { }
virtual void endVisit(FunctionDefinition const&) { }
virtual void endVisit(VariableDeclaration const&) { }

24
libsolidity/AST_accept.h

@ -105,22 +105,36 @@ void InheritanceSpecifier::accept(ASTConstVisitor& _visitor) const
_visitor.endVisit(*this);
}
void StructDefinition::accept(ASTVisitor& _visitor)
void EnumDefinition::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
listAccept(m_members, _visitor);
_visitor.endVisit(*this);
}
void EnumDefinition::accept(ASTVisitor& _visitor)
void EnumDefinition::accept(ASTConstVisitor& _visitor) const
{
_visitor.visit(*this)
if (_visitor.visit(*this))
listAccept(m_members, _visitor);
_visitor.endVisit(*this);
}
void EnumDefinition::accept(ASTConstVisitor& _visitor) const
void EnumDeclaration::accept(ASTVisitor& _visitor)
{
_visitor.visit(*this);
_visitor.endVisit(*this);
}
void EnumDeclaration::accept(ASTConstVisitor& _visitor) const
{
_visitor.visit(*this);
_visitor.endVisit(*this);
}
void StructDefinition::accept(ASTVisitor& _visitor)
{
_visitor.visit(*this)
if (_visitor.visit(*this))
listAccept(m_members, _visitor);
_visitor.endVisit(*this);
}

2
libsolidity/Parser.cpp

@ -279,7 +279,7 @@ ASTPointer<EnumDefinition> Parser::parseEnumDefinition()
ASTNodeFactory nodeFactory(*this);
expectToken(Token::Enum);
ASTPointer<ASTString> name = expectIdentifierToken();
vector<ASTPointer<Declaration>> members;
vector<ASTPointer<EnumDeclaration>> members;
expectToken(Token::LBrace);
while (m_scanner->getCurrentToken() == Token::Identifier)

2
libsolidity/Token.h

@ -168,7 +168,7 @@ namespace solidity
K(Switch, "switch", 0) \
K(Var, "var", 0) \
K(While, "while", 0) \
\
K(Enum, "enum", 0) \
\
/* Ether subdenominations */ \
K(SubWei, "wei", 0) \

Loading…
Cancel
Save