|
@ -39,6 +39,7 @@ namespace solidity |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
class ASTVisitor; |
|
|
class ASTVisitor; |
|
|
|
|
|
class ASTConstVisitor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
@ -54,12 +55,19 @@ public: |
|
|
virtual ~ASTNode() {} |
|
|
virtual ~ASTNode() {} |
|
|
|
|
|
|
|
|
virtual void accept(ASTVisitor& _visitor) = 0; |
|
|
virtual void accept(ASTVisitor& _visitor) = 0; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const = 0; |
|
|
template <class T> |
|
|
template <class T> |
|
|
static void listAccept(std::vector<ASTPointer<T>>& _list, ASTVisitor& _visitor) |
|
|
static void listAccept(std::vector<ASTPointer<T>>& _list, ASTVisitor& _visitor) |
|
|
{ |
|
|
{ |
|
|
for (ASTPointer<T>& element: _list) |
|
|
for (ASTPointer<T>& element: _list) |
|
|
element->accept(_visitor); |
|
|
element->accept(_visitor); |
|
|
} |
|
|
} |
|
|
|
|
|
template <class T> |
|
|
|
|
|
static void listAccept(std::vector<ASTPointer<T>> const& _list, ASTConstVisitor& _visitor) |
|
|
|
|
|
{ |
|
|
|
|
|
for (ASTPointer<T> const& element: _list) |
|
|
|
|
|
element->accept(_visitor); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// Returns the source code location of this node.
|
|
|
/// Returns the source code location of this node.
|
|
|
Location const& getLocation() const { return m_location; } |
|
|
Location const& getLocation() const { return m_location; } |
|
@ -89,6 +97,7 @@ public: |
|
|
ASTNode(_location), m_nodes(_nodes) {} |
|
|
ASTNode(_location), m_nodes(_nodes) {} |
|
|
|
|
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
|
|
|
|
|
|
std::vector<ASTPointer<ASTNode>> getNodes() const { return m_nodes; } |
|
|
std::vector<ASTPointer<ASTNode>> getNodes() const { return m_nodes; } |
|
|
|
|
|
|
|
@ -108,6 +117,7 @@ public: |
|
|
ASTNode(_location), m_identifier(_identifier) {} |
|
|
ASTNode(_location), m_identifier(_identifier) {} |
|
|
|
|
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
|
|
|
|
|
|
ASTString const& getIdentifier() const { return *m_identifier; } |
|
|
ASTString const& getIdentifier() const { return *m_identifier; } |
|
|
|
|
|
|
|
@ -122,18 +132,18 @@ class Declaration: public ASTNode |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
Declaration(Location const& _location, ASTPointer<ASTString> const& _name): |
|
|
Declaration(Location const& _location, ASTPointer<ASTString> const& _name): |
|
|
ASTNode(_location), m_name(_name) {} |
|
|
ASTNode(_location), m_name(_name), m_scope(nullptr) {} |
|
|
|
|
|
|
|
|
/// @returns the declared name.
|
|
|
/// @returns the declared name.
|
|
|
ASTString const& getName() const { return *m_name; } |
|
|
ASTString const& getName() const { return *m_name; } |
|
|
/// @returns the scope this declaration resides in. Can be nullptr if it is the global scope.
|
|
|
/// @returns the scope this declaration resides in. Can be nullptr if it is the global scope.
|
|
|
/// Available only after name and type resolution step.
|
|
|
/// 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; } |
|
|
void setScope(Declaration const* _scope) { m_scope = _scope; } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
ASTPointer<ASTString> m_name; |
|
|
ASTPointer<ASTString> m_name; |
|
|
Declaration* m_scope; |
|
|
Declaration const* m_scope; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
@ -146,21 +156,28 @@ class ContractDefinition: public Declaration |
|
|
public: |
|
|
public: |
|
|
ContractDefinition(Location const& _location, |
|
|
ContractDefinition(Location const& _location, |
|
|
ASTPointer<ASTString> const& _name, |
|
|
ASTPointer<ASTString> const& _name, |
|
|
|
|
|
ASTPointer<ASTString> const& _documentation, |
|
|
std::vector<ASTPointer<StructDefinition>> const& _definedStructs, |
|
|
std::vector<ASTPointer<StructDefinition>> const& _definedStructs, |
|
|
std::vector<ASTPointer<VariableDeclaration>> const& _stateVariables, |
|
|
std::vector<ASTPointer<VariableDeclaration>> const& _stateVariables, |
|
|
std::vector<ASTPointer<FunctionDefinition>> const& _definedFunctions): |
|
|
std::vector<ASTPointer<FunctionDefinition>> const& _definedFunctions): |
|
|
Declaration(_location, _name), |
|
|
Declaration(_location, _name), |
|
|
m_definedStructs(_definedStructs), |
|
|
m_definedStructs(_definedStructs), |
|
|
m_stateVariables(_stateVariables), |
|
|
m_stateVariables(_stateVariables), |
|
|
m_definedFunctions(_definedFunctions) |
|
|
m_definedFunctions(_definedFunctions), |
|
|
|
|
|
m_documentation(_documentation) |
|
|
{} |
|
|
{} |
|
|
|
|
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
|
|
|
|
|
|
std::vector<ASTPointer<StructDefinition>> const& getDefinedStructs() const { return m_definedStructs; } |
|
|
std::vector<ASTPointer<StructDefinition>> const& getDefinedStructs() const { return m_definedStructs; } |
|
|
std::vector<ASTPointer<VariableDeclaration>> const& getStateVariables() const { return m_stateVariables; } |
|
|
std::vector<ASTPointer<VariableDeclaration>> const& getStateVariables() const { return m_stateVariables; } |
|
|
std::vector<ASTPointer<FunctionDefinition>> const& getDefinedFunctions() const { return m_definedFunctions; } |
|
|
std::vector<ASTPointer<FunctionDefinition>> const& getDefinedFunctions() const { return m_definedFunctions; } |
|
|
|
|
|
|
|
|
|
|
|
/// @return A shared pointer of an ASTString.
|
|
|
|
|
|
/// Can contain a nullptr in which case indicates absence of documentation
|
|
|
|
|
|
ASTPointer<ASTString> const& getDocumentation() const { return m_documentation; } |
|
|
|
|
|
|
|
|
/// Returns the functions that make up the calling interface in the intended order.
|
|
|
/// Returns the functions that make up the calling interface in the intended order.
|
|
|
std::vector<FunctionDefinition const*> getInterfaceFunctions() const; |
|
|
std::vector<FunctionDefinition const*> getInterfaceFunctions() const; |
|
|
|
|
|
|
|
@ -168,6 +185,7 @@ private: |
|
|
std::vector<ASTPointer<StructDefinition>> m_definedStructs; |
|
|
std::vector<ASTPointer<StructDefinition>> m_definedStructs; |
|
|
std::vector<ASTPointer<VariableDeclaration>> m_stateVariables; |
|
|
std::vector<ASTPointer<VariableDeclaration>> m_stateVariables; |
|
|
std::vector<ASTPointer<FunctionDefinition>> m_definedFunctions; |
|
|
std::vector<ASTPointer<FunctionDefinition>> m_definedFunctions; |
|
|
|
|
|
ASTPointer<ASTString> m_documentation; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
class StructDefinition: public Declaration |
|
|
class StructDefinition: public Declaration |
|
@ -178,16 +196,17 @@ public: |
|
|
std::vector<ASTPointer<VariableDeclaration>> const& _members): |
|
|
std::vector<ASTPointer<VariableDeclaration>> const& _members): |
|
|
Declaration(_location, _name), m_members(_members) {} |
|
|
Declaration(_location, _name), m_members(_members) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
|
|
|
|
|
|
std::vector<ASTPointer<VariableDeclaration>> const& getMembers() const { return m_members; } |
|
|
std::vector<ASTPointer<VariableDeclaration>> const& getMembers() const { return m_members; } |
|
|
|
|
|
|
|
|
/// Checks that the members do not include any recursive structs and have valid types
|
|
|
/// Checks that the members do not include any recursive structs and have valid types
|
|
|
/// (e.g. no functions).
|
|
|
/// (e.g. no functions).
|
|
|
void checkValidityOfMembers(); |
|
|
void checkValidityOfMembers() const; |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
void checkMemberTypes(); |
|
|
void checkMemberTypes() const; |
|
|
void checkRecursion(); |
|
|
void checkRecursion() const; |
|
|
|
|
|
|
|
|
std::vector<ASTPointer<VariableDeclaration>> m_members; |
|
|
std::vector<ASTPointer<VariableDeclaration>> m_members; |
|
|
}; |
|
|
}; |
|
@ -204,6 +223,7 @@ public: |
|
|
std::vector<ASTPointer<VariableDeclaration>> const& _parameters): |
|
|
std::vector<ASTPointer<VariableDeclaration>> const& _parameters): |
|
|
ASTNode(_location), m_parameters(_parameters) {} |
|
|
ASTNode(_location), m_parameters(_parameters) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
|
|
|
|
|
|
std::vector<ASTPointer<VariableDeclaration>> const& getParameters() const { return m_parameters; } |
|
|
std::vector<ASTPointer<VariableDeclaration>> const& getParameters() const { return m_parameters; } |
|
|
|
|
|
|
|
@ -230,14 +250,15 @@ public: |
|
|
{} |
|
|
{} |
|
|
|
|
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
|
|
|
|
|
|
bool isPublic() const { return m_isPublic; } |
|
|
bool isPublic() const { return m_isPublic; } |
|
|
bool isDeclaredConst() const { return m_isDeclaredConst; } |
|
|
bool isDeclaredConst() const { return m_isDeclaredConst; } |
|
|
std::vector<ASTPointer<VariableDeclaration>> const& getParameters() const { return m_parameters->getParameters(); } |
|
|
std::vector<ASTPointer<VariableDeclaration>> const& getParameters() const { return m_parameters->getParameters(); } |
|
|
ParameterList& getParameterList() { return *m_parameters; } |
|
|
ParameterList const& getParameterList() const { return *m_parameters; } |
|
|
std::vector<ASTPointer<VariableDeclaration>> const& getReturnParameters() const { return m_returnParameters->getParameters(); } |
|
|
std::vector<ASTPointer<VariableDeclaration>> const& getReturnParameters() const { return m_returnParameters->getParameters(); } |
|
|
ASTPointer<ParameterList> const& getReturnParameterList() const { return m_returnParameters; } |
|
|
ASTPointer<ParameterList> const& getReturnParameterList() const { return m_returnParameters; } |
|
|
Block& getBody() { return *m_body; } |
|
|
Block const& getBody() const { return *m_body; } |
|
|
/// @return A shared pointer of an ASTString.
|
|
|
/// @return A shared pointer of an ASTString.
|
|
|
/// Can contain a nullptr in which case indicates absence of documentation
|
|
|
/// Can contain a nullptr in which case indicates absence of documentation
|
|
|
ASTPointer<ASTString> const& getDocumentation() const { return m_documentation; } |
|
|
ASTPointer<ASTString> const& getDocumentation() const { return m_documentation; } |
|
@ -270,15 +291,16 @@ public: |
|
|
ASTPointer<ASTString> const& _name): |
|
|
ASTPointer<ASTString> const& _name): |
|
|
Declaration(_location, _name), m_typeName(_type) {} |
|
|
Declaration(_location, _name), m_typeName(_type) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) 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
|
|
|
/// 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.
|
|
|
/// declared and there is no assignment to the variable that fixes the type.
|
|
|
std::shared_ptr<Type const> const& getType() const { return m_type; } |
|
|
std::shared_ptr<Type const> const& getType() const { return m_type; } |
|
|
void setType(std::shared_ptr<Type const> const& _type) { m_type = _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: |
|
|
private: |
|
|
ASTPointer<TypeName> m_typeName; ///< can be empty ("var")
|
|
|
ASTPointer<TypeName> m_typeName; ///< can be empty ("var")
|
|
@ -297,6 +319,8 @@ public: |
|
|
Declaration(Location(), std::make_shared<ASTString>(_name)), m_type(_type) {} |
|
|
Declaration(Location(), std::make_shared<ASTString>(_name)), m_type(_type) {} |
|
|
virtual void accept(ASTVisitor&) override { BOOST_THROW_EXCEPTION(InternalCompilerError() |
|
|
virtual void accept(ASTVisitor&) override { BOOST_THROW_EXCEPTION(InternalCompilerError() |
|
|
<< errinfo_comment("MagicVariableDeclaration used inside real AST.")); } |
|
|
<< errinfo_comment("MagicVariableDeclaration used inside real AST.")); } |
|
|
|
|
|
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; } |
|
|
std::shared_ptr<Type const> const& getType() const { return m_type; } |
|
|
|
|
|
|
|
@ -315,11 +339,12 @@ class TypeName: public ASTNode |
|
|
public: |
|
|
public: |
|
|
explicit TypeName(Location const& _location): ASTNode(_location) {} |
|
|
explicit TypeName(Location const& _location): ASTNode(_location) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
|
|
|
|
|
|
/// Retrieve the element of the type hierarchy this node refers to. Can return an empty shared
|
|
|
/// 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.
|
|
|
/// 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.
|
|
|
/// 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; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
@ -335,7 +360,8 @@ public: |
|
|
if (asserts(Token::isElementaryTypeName(_type))) BOOST_THROW_EXCEPTION(InternalCompilerError()); |
|
|
if (asserts(Token::isElementaryTypeName(_type))) BOOST_THROW_EXCEPTION(InternalCompilerError()); |
|
|
} |
|
|
} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) 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; } |
|
|
Token::Value getTypeName() const { return m_type; } |
|
|
|
|
|
|
|
@ -350,18 +376,19 @@ class UserDefinedTypeName: public TypeName |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
UserDefinedTypeName(Location const& _location, ASTPointer<ASTString> const& _name): |
|
|
UserDefinedTypeName(Location const& _location, ASTPointer<ASTString> const& _name): |
|
|
TypeName(_location), m_name(_name) {} |
|
|
TypeName(_location), m_name(_name), m_referencedDeclaration(nullptr) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) 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; } |
|
|
ASTString const& getName() const { return *m_name; } |
|
|
void setReferencedDeclaration(Declaration& _referencedDeclaration) { m_referencedDeclaration = &_referencedDeclaration; } |
|
|
void setReferencedDeclaration(Declaration const& _referencedDeclaration) { m_referencedDeclaration = &_referencedDeclaration; } |
|
|
Declaration const* getReferencedDeclaration() const { return m_referencedDeclaration; } |
|
|
Declaration const* getReferencedDeclaration() const { return m_referencedDeclaration; } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
ASTPointer<ASTString> m_name; |
|
|
ASTPointer<ASTString> m_name; |
|
|
|
|
|
|
|
|
Declaration* m_referencedDeclaration; |
|
|
Declaration const* m_referencedDeclaration; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
@ -374,7 +401,8 @@ public: |
|
|
ASTPointer<TypeName> const& _valueType): |
|
|
ASTPointer<TypeName> const& _valueType): |
|
|
TypeName(_location), m_keyType(_keyType), m_valueType(_valueType) {} |
|
|
TypeName(_location), m_keyType(_keyType), m_valueType(_valueType) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) 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; } |
|
|
ElementaryTypeName const& getKeyType() const { return *m_keyType; } |
|
|
TypeName const& getValueType() const { return *m_valueType; } |
|
|
TypeName const& getValueType() const { return *m_valueType; } |
|
@ -397,7 +425,6 @@ class Statement: public ASTNode |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
explicit Statement(Location const& _location): ASTNode(_location) {} |
|
|
explicit Statement(Location const& _location): ASTNode(_location) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
|
|
|
|
|
|
/// Check all type requirements, throws exception if some requirement is not met.
|
|
|
/// Check all type requirements, throws exception if some requirement is not met.
|
|
|
/// This includes checking that operators are applicable to their arguments but also that
|
|
|
/// This includes checking that operators are applicable to their arguments but also that
|
|
@ -414,6 +441,7 @@ public: |
|
|
Block(Location const& _location, std::vector<ASTPointer<Statement>> const& _statements): |
|
|
Block(Location const& _location, std::vector<ASTPointer<Statement>> const& _statements): |
|
|
Statement(_location), m_statements(_statements) {} |
|
|
Statement(_location), m_statements(_statements) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
|
|
|
|
|
|
virtual void checkTypeRequirements() override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
|
|
|
|
|
@ -433,12 +461,13 @@ public: |
|
|
Statement(_location), |
|
|
Statement(_location), |
|
|
m_condition(_condition), m_trueBody(_trueBody), m_falseBody(_falseBody) {} |
|
|
m_condition(_condition), m_trueBody(_trueBody), m_falseBody(_falseBody) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
|
|
|
|
|
|
Expression& getCondition() const { return *m_condition; } |
|
|
Expression const& getCondition() const { return *m_condition; } |
|
|
Statement& getTrueStatement() const { return *m_trueBody; } |
|
|
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* getFalseStatement() const { return m_falseBody.get(); } |
|
|
Statement const* getFalseStatement() const { return m_falseBody.get(); } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
ASTPointer<Expression> m_condition; |
|
|
ASTPointer<Expression> m_condition; |
|
@ -447,13 +476,12 @@ private: |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* Statement in which a break statement is legal. |
|
|
* Statement in which a break statement is legal (abstract class). |
|
|
*/ |
|
|
*/ |
|
|
class BreakableStatement: public Statement |
|
|
class BreakableStatement: public Statement |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
BreakableStatement(Location const& _location): Statement(_location) {} |
|
|
BreakableStatement(Location const& _location): Statement(_location) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
class WhileStatement: public BreakableStatement |
|
|
class WhileStatement: public BreakableStatement |
|
@ -463,10 +491,11 @@ public: |
|
|
ASTPointer<Statement> const& _body): |
|
|
ASTPointer<Statement> const& _body): |
|
|
BreakableStatement(_location), m_condition(_condition), m_body(_body) {} |
|
|
BreakableStatement(_location), m_condition(_condition), m_body(_body) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
|
|
|
|
|
|
Expression& getCondition() const { return *m_condition; } |
|
|
Expression const& getCondition() const { return *m_condition; } |
|
|
Statement& getBody() const { return *m_body; } |
|
|
Statement const& getBody() const { return *m_body; } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
ASTPointer<Expression> m_condition; |
|
|
ASTPointer<Expression> m_condition; |
|
@ -478,6 +507,7 @@ class Continue: public Statement |
|
|
public: |
|
|
public: |
|
|
Continue(Location const& _location): Statement(_location) {} |
|
|
Continue(Location const& _location): Statement(_location) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
virtual void checkTypeRequirements() override {} |
|
|
virtual void checkTypeRequirements() override {} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -486,6 +516,7 @@ class Break: public Statement |
|
|
public: |
|
|
public: |
|
|
Break(Location const& _location): Statement(_location) {} |
|
|
Break(Location const& _location): Statement(_location) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
virtual void checkTypeRequirements() override {} |
|
|
virtual void checkTypeRequirements() override {} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -493,8 +524,9 @@ class Return: public Statement |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
Return(Location const& _location, ASTPointer<Expression> _expression): |
|
|
Return(Location const& _location, ASTPointer<Expression> _expression): |
|
|
Statement(_location), m_expression(_expression) {} |
|
|
Statement(_location), m_expression(_expression), m_returnParameters(nullptr) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
|
|
|
|
|
|
void setFunctionReturnParameters(ParameterList& _parameters) { m_returnParameters = &_parameters; } |
|
|
void setFunctionReturnParameters(ParameterList& _parameters) { m_returnParameters = &_parameters; } |
|
@ -504,7 +536,7 @@ public: |
|
|
BOOST_THROW_EXCEPTION(InternalCompilerError()); |
|
|
BOOST_THROW_EXCEPTION(InternalCompilerError()); |
|
|
return *m_returnParameters; |
|
|
return *m_returnParameters; |
|
|
} |
|
|
} |
|
|
Expression* getExpression() const { return m_expression.get(); } |
|
|
Expression const* getExpression() const { return m_expression.get(); } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
ASTPointer<Expression> m_expression; ///< value to return, optional
|
|
|
ASTPointer<Expression> m_expression; ///< value to return, optional
|
|
@ -525,10 +557,11 @@ public: |
|
|
ASTPointer<Expression> _value): |
|
|
ASTPointer<Expression> _value): |
|
|
Statement(_location), m_variable(_variable), m_value(_value) {} |
|
|
Statement(_location), m_variable(_variable), m_value(_value) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
|
|
|
|
|
|
VariableDeclaration const& getDeclaration() const { return *m_variable; } |
|
|
VariableDeclaration const& getDeclaration() const { return *m_variable; } |
|
|
Expression* getExpression() const { return m_value.get(); } |
|
|
Expression const* getExpression() const { return m_value.get(); } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
ASTPointer<VariableDeclaration> m_variable; |
|
|
ASTPointer<VariableDeclaration> m_variable; |
|
@ -544,9 +577,10 @@ public: |
|
|
ExpressionStatement(Location const& _location, ASTPointer<Expression> _expression): |
|
|
ExpressionStatement(Location const& _location, ASTPointer<Expression> _expression): |
|
|
Statement(_location), m_expression(_expression) {} |
|
|
Statement(_location), m_expression(_expression) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
|
|
|
|
|
|
Expression& getExpression() const { return *m_expression; } |
|
|
Expression const& getExpression() const { return *m_expression; } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
ASTPointer<Expression> m_expression; |
|
|
ASTPointer<Expression> m_expression; |
|
@ -608,11 +642,12 @@ public: |
|
|
if (asserts(Token::isAssignmentOp(_assignmentOperator))) BOOST_THROW_EXCEPTION(InternalCompilerError()); |
|
|
if (asserts(Token::isAssignmentOp(_assignmentOperator))) BOOST_THROW_EXCEPTION(InternalCompilerError()); |
|
|
} |
|
|
} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
virtual void checkTypeRequirements() 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; } |
|
|
Token::Value getAssignmentOperator() const { return m_assigmentOperator; } |
|
|
Expression& getRightHandSide() const { return *m_rightHandSide; } |
|
|
Expression const& getRightHandSide() const { return *m_rightHandSide; } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
ASTPointer<Expression> m_leftHandSide; |
|
|
ASTPointer<Expression> m_leftHandSide; |
|
@ -635,11 +670,12 @@ public: |
|
|
if (asserts(Token::isUnaryOp(_operator))) BOOST_THROW_EXCEPTION(InternalCompilerError()); |
|
|
if (asserts(Token::isUnaryOp(_operator))) BOOST_THROW_EXCEPTION(InternalCompilerError()); |
|
|
} |
|
|
} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
|
|
|
|
|
|
Token::Value getOperator() const { return m_operator; } |
|
|
Token::Value getOperator() const { return m_operator; } |
|
|
bool isPrefixOperation() const { return m_isPrefix; } |
|
|
bool isPrefixOperation() const { return m_isPrefix; } |
|
|
Expression& getSubExpression() const { return *m_subExpression; } |
|
|
Expression const& getSubExpression() const { return *m_subExpression; } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
Token::Value m_operator; |
|
|
Token::Value m_operator; |
|
@ -661,10 +697,11 @@ public: |
|
|
if (asserts(Token::isBinaryOp(_operator) || Token::isCompareOp(_operator))) BOOST_THROW_EXCEPTION(InternalCompilerError()); |
|
|
if (asserts(Token::isBinaryOp(_operator) || Token::isCompareOp(_operator))) BOOST_THROW_EXCEPTION(InternalCompilerError()); |
|
|
} |
|
|
} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
|
|
|
|
|
|
Expression& getLeftExpression() const { return *m_left; } |
|
|
Expression const& getLeftExpression() const { return *m_left; } |
|
|
Expression& getRightExpression() const { return *m_right; } |
|
|
Expression const& getRightExpression() const { return *m_right; } |
|
|
Token::Value getOperator() const { return m_operator; } |
|
|
Token::Value getOperator() const { return m_operator; } |
|
|
Type const& getCommonType() const { return *m_commonType; } |
|
|
Type const& getCommonType() const { return *m_commonType; } |
|
|
|
|
|
|
|
@ -688,10 +725,11 @@ public: |
|
|
std::vector<ASTPointer<Expression>> const& _arguments): |
|
|
std::vector<ASTPointer<Expression>> const& _arguments): |
|
|
Expression(_location), m_expression(_expression), m_arguments(_arguments) {} |
|
|
Expression(_location), m_expression(_expression), m_arguments(_arguments) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
|
|
|
|
|
|
Expression& getExpression() const { return *m_expression; } |
|
|
Expression const& getExpression() const { return *m_expression; } |
|
|
std::vector<ASTPointer<Expression>> const& getArguments() const { return m_arguments; } |
|
|
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
|
|
|
/// Returns true if this is not an actual function call, but an explicit type conversion
|
|
|
/// or constructor call.
|
|
|
/// or constructor call.
|
|
@ -712,7 +750,8 @@ public: |
|
|
ASTPointer<ASTString> const& _memberName): |
|
|
ASTPointer<ASTString> const& _memberName): |
|
|
Expression(_location), m_expression(_expression), m_memberName(_memberName) {} |
|
|
Expression(_location), m_expression(_expression), m_memberName(_memberName) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) 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; } |
|
|
ASTString const& getMemberName() const { return *m_memberName; } |
|
|
virtual void checkTypeRequirements() override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
|
|
|
|
|
@ -731,10 +770,11 @@ public: |
|
|
ASTPointer<Expression> const& _index): |
|
|
ASTPointer<Expression> const& _index): |
|
|
Expression(_location), m_base(_base), m_index(_index) {} |
|
|
Expression(_location), m_base(_base), m_index(_index) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
|
|
|
|
|
|
Expression& getBaseExpression() const { return *m_base; } |
|
|
Expression const& getBaseExpression() const { return *m_base; } |
|
|
Expression& getIndexExpression() const { return *m_index; } |
|
|
Expression const& getIndexExpression() const { return *m_index; } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
ASTPointer<Expression> m_base; |
|
|
ASTPointer<Expression> m_base; |
|
@ -758,20 +798,21 @@ class Identifier: public PrimaryExpression |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
Identifier(Location const& _location, ASTPointer<ASTString> const& _name): |
|
|
Identifier(Location const& _location, ASTPointer<ASTString> const& _name): |
|
|
PrimaryExpression(_location), m_name(_name) {} |
|
|
PrimaryExpression(_location), m_name(_name), m_referencedDeclaration(nullptr) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
|
|
|
|
|
|
ASTString const& getName() const { return *m_name; } |
|
|
ASTString const& getName() const { return *m_name; } |
|
|
|
|
|
|
|
|
void setReferencedDeclaration(Declaration& _referencedDeclaration) { m_referencedDeclaration = &_referencedDeclaration; } |
|
|
void setReferencedDeclaration(Declaration const& _referencedDeclaration) { m_referencedDeclaration = &_referencedDeclaration; } |
|
|
Declaration* getReferencedDeclaration() { return m_referencedDeclaration; } |
|
|
Declaration const* getReferencedDeclaration() const { return m_referencedDeclaration; } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
ASTPointer<ASTString> m_name; |
|
|
ASTPointer<ASTString> m_name; |
|
|
|
|
|
|
|
|
/// Declaration the name refers to.
|
|
|
/// Declaration the name refers to.
|
|
|
Declaration* m_referencedDeclaration; |
|
|
Declaration const* m_referencedDeclaration; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
@ -788,6 +829,7 @@ public: |
|
|
if (asserts(Token::isElementaryTypeName(_typeToken))) BOOST_THROW_EXCEPTION(InternalCompilerError()); |
|
|
if (asserts(Token::isElementaryTypeName(_typeToken))) BOOST_THROW_EXCEPTION(InternalCompilerError()); |
|
|
} |
|
|
} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
|
|
|
|
|
|
Token::Value getTypeToken() const { return m_typeToken; } |
|
|
Token::Value getTypeToken() const { return m_typeToken; } |
|
@ -805,6 +847,7 @@ public: |
|
|
Literal(Location const& _location, Token::Value _token, ASTPointer<ASTString> const& _value): |
|
|
Literal(Location const& _location, Token::Value _token, ASTPointer<ASTString> const& _value): |
|
|
PrimaryExpression(_location), m_token(_token), m_value(_value) {} |
|
|
PrimaryExpression(_location), m_token(_token), m_value(_value) {} |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
virtual void accept(ASTVisitor& _visitor) override; |
|
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
virtual void checkTypeRequirements() override; |
|
|
|
|
|
|
|
|
Token::Value getToken() const { return m_token; } |
|
|
Token::Value getToken() const { return m_token; } |
|
|