aboutsummaryrefslogtreecommitdiffstats
path: root/AST.h
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-12-06 09:19:10 +0800
committerChristian <c@ethdev.com>2014-12-08 19:53:56 +0800
commit13640d7db82562592958fcce2d7ce8155cc7ea35 (patch)
treea27fc38d8fb642ad602d875e3218542adb533de5 /AST.h
parentc78c330634997e5d8e2ec27db9e3d9cf50bae230 (diff)
downloaddexon-solidity-13640d7db82562592958fcce2d7ce8155cc7ea35.tar.gz
dexon-solidity-13640d7db82562592958fcce2d7ce8155cc7ea35.tar.zst
dexon-solidity-13640d7db82562592958fcce2d7ce8155cc7ea35.zip
Clear separation between ASTVisitor and ASTConstVisitor and more const specifiers.
Diffstat (limited to 'AST.h')
-rw-r--r--AST.h119
1 files changed, 61 insertions, 58 deletions
diff --git a/AST.h b/AST.h
index 966acb97..f0071b95 100644
--- a/AST.h
+++ b/AST.h
@@ -39,6 +39,7 @@ namespace solidity
{
class ASTVisitor;
+class ASTConstVisitor;
/**
@@ -54,7 +55,7 @@ public:
virtual ~ASTNode() {}
virtual void accept(ASTVisitor& _visitor) = 0;
- virtual void accept(ASTVisitor& _visitor) const = 0;
+ virtual void accept(ASTConstVisitor& _visitor) const = 0;
template <class T>
static void listAccept(std::vector<ASTPointer<T>>& _list, ASTVisitor& _visitor)
{
@@ -62,9 +63,9 @@ public:
element->accept(_visitor);
}
template <class T>
- static void listAccept(std::vector<ASTPointer<T>> const& _list, ASTVisitor& _visitor)
+ static void listAccept(std::vector<ASTPointer<T>> const& _list, ASTConstVisitor& _visitor)
{
- for (ASTPointer<T const> const& element: _list)
+ for (ASTPointer<T> const& element: _list)
element->accept(_visitor);
}
@@ -96,6 +97,7 @@ public:
ASTNode(_location), m_nodes(_nodes) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
std::vector<ASTPointer<ASTNode>> getNodes() const { return m_nodes; }
@@ -115,6 +117,7 @@ public:
ASTNode(_location), m_identifier(_identifier) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
ASTString const& getIdentifier() const { return *m_identifier; }
@@ -135,7 +138,7 @@ public:
ASTString const& getName() const { return *m_name; }
/// @returns the scope this declaration resides in. Can be nullptr if it is the global scope.
/// Available only after name and type resolution step.
- Declaration* getScope() const { return m_scope; }
+ Declaration const* getScope() const { return m_scope; }
void setScope(Declaration* const& _scope) { m_scope = _scope; }
private:
@@ -163,7 +166,7 @@ public:
{}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
std::vector<ASTPointer<StructDefinition>> const& getDefinedStructs() const { return m_definedStructs; }
std::vector<ASTPointer<VariableDeclaration>> const& getStateVariables() const { return m_stateVariables; }
@@ -186,17 +189,17 @@ public:
std::vector<ASTPointer<VariableDeclaration>> const& _members):
Declaration(_location, _name), m_members(_members) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
std::vector<ASTPointer<VariableDeclaration>> const& getMembers() const { return m_members; }
/// Checks that the members do not include any recursive structs and have valid types
/// (e.g. no functions).
- void checkValidityOfMembers();
+ void checkValidityOfMembers() const;
private:
- void checkMemberTypes();
- void checkRecursion();
+ void checkMemberTypes() const;
+ void checkRecursion() const;
std::vector<ASTPointer<VariableDeclaration>> m_members;
};
@@ -213,7 +216,7 @@ public:
std::vector<ASTPointer<VariableDeclaration>> const& _parameters):
ASTNode(_location), m_parameters(_parameters) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
std::vector<ASTPointer<VariableDeclaration>> const& getParameters() const { return m_parameters; }
@@ -240,7 +243,7 @@ public:
{}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
bool isPublic() const { return m_isPublic; }
bool isDeclaredConst() const { return m_isDeclaredConst; }
@@ -281,16 +284,16 @@ public:
ASTPointer<ASTString> const& _name):
Declaration(_location, _name), m_typeName(_type) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
- TypeName* getTypeName() const { return m_typeName.get(); }
+ TypeName const* getTypeName() const { return m_typeName.get(); }
/// Returns the declared or inferred type. Can be an empty pointer if no type was explicitly
/// declared and there is no assignment to the variable that fixes the type.
std::shared_ptr<Type const> const& getType() const { return m_type; }
void setType(std::shared_ptr<Type const> const& _type) { m_type = _type; }
- bool isLocalVariable() const { return !!dynamic_cast<FunctionDefinition*>(getScope()); }
+ bool isLocalVariable() const { return !!dynamic_cast<FunctionDefinition const*>(getScope()); }
private:
ASTPointer<TypeName> m_typeName; ///< can be empty ("var")
@@ -309,7 +312,7 @@ public:
Declaration(Location(), std::make_shared<ASTString>(_name)), m_type(_type) {}
virtual void accept(ASTVisitor&) override { BOOST_THROW_EXCEPTION(InternalCompilerError()
<< errinfo_comment("MagicVariableDeclaration used inside real AST.")); }
- virtual void accept(ASTVisitor&) const override { BOOST_THROW_EXCEPTION(InternalCompilerError()
+ virtual void accept(ASTConstVisitor&) const override { BOOST_THROW_EXCEPTION(InternalCompilerError()
<< errinfo_comment("MagicVariableDeclaration used inside real AST.")); }
std::shared_ptr<Type const> const& getType() const { return m_type; }
@@ -329,12 +332,12 @@ class TypeName: public ASTNode
public:
explicit TypeName(Location const& _location): ASTNode(_location) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
/// Retrieve the element of the type hierarchy this node refers to. Can return an empty shared
/// pointer until the types have been resolved using the @ref NameAndTypeResolver.
/// If it returns an empty shared pointer after that, this indicates that the type was not found.
- virtual std::shared_ptr<Type> toType() const = 0;
+ virtual std::shared_ptr<Type const> toType() const = 0;
};
/**
@@ -350,8 +353,8 @@ public:
if (asserts(Token::isElementaryTypeName(_type))) BOOST_THROW_EXCEPTION(InternalCompilerError());
}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
- virtual std::shared_ptr<Type> toType() const override { return Type::fromElementaryTypeName(m_type); }
+ virtual void accept(ASTConstVisitor& _visitor) const override;
+ virtual std::shared_ptr<Type const> toType() const override { return Type::fromElementaryTypeName(m_type); }
Token::Value getTypeName() const { return m_type; }
@@ -368,8 +371,8 @@ public:
UserDefinedTypeName(Location const& _location, ASTPointer<ASTString> const& _name):
TypeName(_location), m_name(_name) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
- virtual std::shared_ptr<Type> toType() const override { return Type::fromUserDefinedTypeName(*this); }
+ virtual void accept(ASTConstVisitor& _visitor) const override;
+ virtual std::shared_ptr<Type const> toType() const override { return Type::fromUserDefinedTypeName(*this); }
ASTString const& getName() const { return *m_name; }
void setReferencedDeclaration(Declaration& _referencedDeclaration) { m_referencedDeclaration = &_referencedDeclaration; }
@@ -391,8 +394,8 @@ public:
ASTPointer<TypeName> const& _valueType):
TypeName(_location), m_keyType(_keyType), m_valueType(_valueType) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
- virtual std::shared_ptr<Type> toType() const override { return Type::fromMapping(*this); }
+ virtual void accept(ASTConstVisitor& _visitor) const override;
+ virtual std::shared_ptr<Type const> toType() const override { return Type::fromMapping(*this); }
ElementaryTypeName const& getKeyType() const { return *m_keyType; }
TypeName const& getValueType() const { return *m_valueType; }
@@ -431,7 +434,7 @@ public:
Block(Location const& _location, std::vector<ASTPointer<Statement>> const& _statements):
Statement(_location), m_statements(_statements) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
@@ -451,13 +454,13 @@ public:
Statement(_location),
m_condition(_condition), m_trueBody(_trueBody), m_falseBody(_falseBody) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
- Expression& getCondition() const { return *m_condition; }
- Statement& getTrueStatement() const { return *m_trueBody; }
+ 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.
- Statement* getFalseStatement() const { return m_falseBody.get(); }
+ Statement const* getFalseStatement() const { return m_falseBody.get(); }
private:
ASTPointer<Expression> m_condition;
@@ -481,11 +484,11 @@ public:
ASTPointer<Statement> const& _body):
BreakableStatement(_location), m_condition(_condition), m_body(_body) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
- Expression& getCondition() const { return *m_condition; }
- Statement& getBody() const { return *m_body; }
+ Expression const& getCondition() const { return *m_condition; }
+ Statement const& getBody() const { return *m_body; }
private:
ASTPointer<Expression> m_condition;
@@ -497,7 +500,7 @@ class Continue: public Statement
public:
Continue(Location const& _location): Statement(_location) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override {}
};
@@ -506,7 +509,7 @@ class Break: public Statement
public:
Break(Location const& _location): Statement(_location) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override {}
};
@@ -516,7 +519,7 @@ public:
Return(Location const& _location, ASTPointer<Expression> _expression):
Statement(_location), m_expression(_expression) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
void setFunctionReturnParameters(ParameterList& _parameters) { m_returnParameters = &_parameters; }
@@ -526,7 +529,7 @@ public:
BOOST_THROW_EXCEPTION(InternalCompilerError());
return *m_returnParameters;
}
- Expression* getExpression() const { return m_expression.get(); }
+ Expression const* getExpression() const { return m_expression.get(); }
private:
ASTPointer<Expression> m_expression; ///< value to return, optional
@@ -547,11 +550,11 @@ public:
ASTPointer<Expression> _value):
Statement(_location), m_variable(_variable), m_value(_value) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
VariableDeclaration const& getDeclaration() const { return *m_variable; }
- Expression* getExpression() const { return m_value.get(); }
+ Expression const* getExpression() const { return m_value.get(); }
private:
ASTPointer<VariableDeclaration> m_variable;
@@ -567,10 +570,10 @@ public:
ExpressionStatement(Location const& _location, ASTPointer<Expression> _expression):
Statement(_location), m_expression(_expression) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
- Expression& getExpression() const { return *m_expression; }
+ Expression const& getExpression() const { return *m_expression; }
private:
ASTPointer<Expression> m_expression;
@@ -632,12 +635,12 @@ public:
if (asserts(Token::isAssignmentOp(_assignmentOperator))) BOOST_THROW_EXCEPTION(InternalCompilerError());
}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
- Expression& getLeftHandSide() const { return *m_leftHandSide; }
+ Expression const& getLeftHandSide() const { return *m_leftHandSide; }
Token::Value getAssignmentOperator() const { return m_assigmentOperator; }
- Expression& getRightHandSide() const { return *m_rightHandSide; }
+ Expression const& getRightHandSide() const { return *m_rightHandSide; }
private:
ASTPointer<Expression> m_leftHandSide;
@@ -660,12 +663,12 @@ public:
if (asserts(Token::isUnaryOp(_operator))) BOOST_THROW_EXCEPTION(InternalCompilerError());
}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
Token::Value getOperator() const { return m_operator; }
bool isPrefixOperation() const { return m_isPrefix; }
- Expression& getSubExpression() const { return *m_subExpression; }
+ Expression const& getSubExpression() const { return *m_subExpression; }
private:
Token::Value m_operator;
@@ -687,11 +690,11 @@ public:
if (asserts(Token::isBinaryOp(_operator) || Token::isCompareOp(_operator))) BOOST_THROW_EXCEPTION(InternalCompilerError());
}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
- Expression& getLeftExpression() const { return *m_left; }
- Expression& getRightExpression() const { return *m_right; }
+ Expression const& getLeftExpression() const { return *m_left; }
+ Expression const& getRightExpression() const { return *m_right; }
Token::Value getOperator() const { return m_operator; }
Type const& getCommonType() const { return *m_commonType; }
@@ -715,11 +718,11 @@ public:
std::vector<ASTPointer<Expression>> const& _arguments):
Expression(_location), m_expression(_expression), m_arguments(_arguments) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
- Expression& getExpression() const { return *m_expression; }
- std::vector<ASTPointer<Expression>> const& getArguments() const { return m_arguments; }
+ Expression const& getExpression() const { return *m_expression; }
+ std::vector<ASTPointer<Expression const>> getArguments() const { return {m_arguments.begin(), m_arguments.end()}; }
/// Returns true if this is not an actual function call, but an explicit type conversion
/// or constructor call.
@@ -740,8 +743,8 @@ public:
ASTPointer<ASTString> const& _memberName):
Expression(_location), m_expression(_expression), m_memberName(_memberName) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
- Expression& getExpression() const { return *m_expression; }
+ virtual void accept(ASTConstVisitor& _visitor) const override;
+ Expression const& getExpression() const { return *m_expression; }
ASTString const& getMemberName() const { return *m_memberName; }
virtual void checkTypeRequirements() override;
@@ -760,11 +763,11 @@ public:
ASTPointer<Expression> const& _index):
Expression(_location), m_base(_base), m_index(_index) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
- Expression& getBaseExpression() const { return *m_base; }
- Expression& getIndexExpression() const { return *m_index; }
+ Expression const& getBaseExpression() const { return *m_base; }
+ Expression const& getIndexExpression() const { return *m_index; }
private:
ASTPointer<Expression> m_base;
@@ -790,7 +793,7 @@ public:
Identifier(Location const& _location, ASTPointer<ASTString> const& _name):
PrimaryExpression(_location), m_name(_name) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
ASTString const& getName() const { return *m_name; }
@@ -819,7 +822,7 @@ public:
if (asserts(Token::isElementaryTypeName(_typeToken))) BOOST_THROW_EXCEPTION(InternalCompilerError());
}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
Token::Value getTypeToken() const { return m_typeToken; }
@@ -837,7 +840,7 @@ public:
Literal(Location const& _location, Token::Value _token, ASTPointer<ASTString> const& _value):
PrimaryExpression(_location), m_token(_token), m_value(_value) {}
virtual void accept(ASTVisitor& _visitor) override;
- virtual void accept(ASTVisitor& _visitor) const override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
Token::Value getToken() const { return m_token; }