|
@ -88,11 +88,16 @@ 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) {} |
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
|
|
/// Available only after name and type resolution step.
|
|
|
|
|
|
Declaration* getScope() const { return m_scope; } |
|
|
|
|
|
void setScope(Declaration* const& _scope) { m_scope = _scope; } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
ASTPointer<ASTString> m_name; |
|
|
ASTPointer<ASTString> m_name; |
|
|
|
|
|
Declaration* m_scope; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
@ -237,6 +242,8 @@ public: |
|
|
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()); } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
ASTPointer<TypeName> m_typeName; ///< can be empty ("var")
|
|
|
ASTPointer<TypeName> m_typeName; ///< can be empty ("var")
|
|
|
|
|
|
|
|
@ -521,12 +528,16 @@ private: |
|
|
*/ |
|
|
*/ |
|
|
class Expression: public ASTNode |
|
|
class Expression: public ASTNode |
|
|
{ |
|
|
{ |
|
|
|
|
|
protected: |
|
|
|
|
|
enum class LValueType { NONE, LOCAL, STORAGE }; |
|
|
|
|
|
|
|
|
public: |
|
|
public: |
|
|
Expression(Location const& _location): ASTNode(_location), m_isLvalue(false), m_lvalueRequested(false) {} |
|
|
Expression(Location const& _location): ASTNode(_location), m_lvalue(LValueType::NONE), m_lvalueRequested(false) {} |
|
|
virtual void checkTypeRequirements() = 0; |
|
|
virtual void checkTypeRequirements() = 0; |
|
|
|
|
|
|
|
|
std::shared_ptr<Type const> const& getType() const { return m_type; } |
|
|
std::shared_ptr<Type const> const& getType() const { return m_type; } |
|
|
bool isLvalue() const { return m_isLvalue; } |
|
|
bool isLValue() const { return m_lvalue != LValueType::NONE; } |
|
|
|
|
|
bool isLocalLValue() const { return m_lvalue == LValueType::LOCAL; } |
|
|
|
|
|
|
|
|
/// Helper function, infer the type via @ref checkTypeRequirements and then check that it
|
|
|
/// Helper function, infer the type via @ref checkTypeRequirements and then check that it
|
|
|
/// is implicitly convertible to @a _expectedType. If not, throw exception.
|
|
|
/// is implicitly convertible to @a _expectedType. If not, throw exception.
|
|
@ -541,9 +552,9 @@ public: |
|
|
protected: |
|
|
protected: |
|
|
//! Inferred type of the expression, only filled after a call to checkTypeRequirements().
|
|
|
//! Inferred type of the expression, only filled after a call to checkTypeRequirements().
|
|
|
std::shared_ptr<Type const> m_type; |
|
|
std::shared_ptr<Type const> m_type; |
|
|
//! Whether or not this expression is an lvalue, i.e. something that can be assigned to.
|
|
|
//! If this expression is an lvalue (i.e. something that can be assigned to) and is stored
|
|
|
//! This is set during calls to @a checkTypeRequirements()
|
|
|
//! locally or in storage. This is set during calls to @a checkTypeRequirements()
|
|
|
bool m_isLvalue; |
|
|
LValueType m_lvalue; |
|
|
//! Whether the outer expression requested the address (true) or the value (false) of this expression.
|
|
|
//! Whether the outer expression requested the address (true) or the value (false) of this expression.
|
|
|
bool m_lvalueRequested; |
|
|
bool m_lvalueRequested; |
|
|
}; |
|
|
}; |
|
|