diff options
author | Liana Husikyan <liana@ethdev.com> | 2015-02-17 23:21:38 +0800 |
---|---|---|
committer | Liana Husikyan <liana@ethdev.com> | 2015-02-21 05:50:34 +0800 |
commit | 52050201e39b823ea9e6133e47c7e9e779dc1f07 (patch) | |
tree | bf415cf6c45a0f6ee9468849c5c708217f366260 /AST.h | |
parent | 26132363d5a11d762224cc7c8acc6b8c854cf646 (diff) | |
download | dexon-solidity-52050201e39b823ea9e6133e47c7e9e779dc1f07.tar.gz dexon-solidity-52050201e39b823ea9e6133e47c7e9e779dc1f07.tar.zst dexon-solidity-52050201e39b823ea9e6133e47c7e9e779dc1f07.zip |
Inline member initialisation
renamed VariableDefinition class to VariableDeclarationStatement
added tests
Diffstat (limited to 'AST.h')
-rw-r--r-- | AST.h | 25 |
1 files changed, 15 insertions, 10 deletions
@@ -432,14 +432,17 @@ class VariableDeclaration: public Declaration { public: VariableDeclaration(Location const& _location, ASTPointer<TypeName> const& _type, - ASTPointer<ASTString> const& _name, Visibility _visibility, - bool _isStateVar = false, bool _isIndexed = false): - Declaration(_location, _name, _visibility), m_typeName(_type), - m_isStateVariable(_isStateVar), m_isIndexed(_isIndexed) {} + ASTPointer<ASTString> const& _name, ASTPointer<Expression> _value, + Visibility _visibility, + bool _isStateVar = false, bool _isIndexed = false): + Declaration(_location, _name, _visibility), + m_typeName(_type), m_value(_value), + m_isStateVariable(_isStateVar), m_isIndexed(_isIndexed) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; TypeName const* getTypeName() const { return m_typeName.get(); } + ASTPointer<Expression> const& getValue() const { return m_value; } /// 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. @@ -447,6 +450,9 @@ public: void setType(std::shared_ptr<Type const> const& _type) { m_type = _type; } virtual bool isLValue() const override; + + /// Checks that all parameters have allowed types and calls checkTypeRequirements on the body. + void checkTypeRequirements(); bool isLocalVariable() const { return !!dynamic_cast<FunctionDefinition const*>(getScope()); } bool isExternalFunctionParameter() const; bool isStateVariable() const { return m_isStateVariable; } @@ -457,6 +463,7 @@ protected: private: ASTPointer<TypeName> m_typeName; ///< can be empty ("var") + ASTPointer<Expression> m_value; ///< the assigned value, can be missing bool m_isStateVariable; ///< Whether or not this is a contract state variable bool m_isIndexed; ///< Whether this is an indexed variable (used by events). @@ -833,22 +840,20 @@ private: * also be "var") but the actual assignment can be missing. * Examples: var a = 2; uint256 a; */ -class VariableDefinition: public Statement +class VariableDeclarationStatement: public Statement { public: - VariableDefinition(Location const& _location, ASTPointer<VariableDeclaration> _variable, - ASTPointer<Expression> _value): - Statement(_location), m_variable(_variable), m_value(_value) {} + VariableDeclarationStatement(Location const& _location, ASTPointer<VariableDeclaration> _variable): + Statement(_location), m_variable(_variable) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; virtual void checkTypeRequirements() override; VariableDeclaration const& getDeclaration() const { return *m_variable; } - Expression const* getExpression() const { return m_value.get(); } + Expression const* getExpression() const { return m_variable->getValue().get(); } private: ASTPointer<VariableDeclaration> m_variable; - ASTPointer<Expression> m_value; ///< the assigned value, can be missing }; /** |