diff options
author | chriseth <c@ethdev.com> | 2015-10-09 00:01:12 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-10-09 00:25:44 +0800 |
commit | b9a166061bc94cd06458c945d66bf52e76e84b70 (patch) | |
tree | 9e317a5de58a050f49187a0318fff0e4981d7c98 /libsolidity/AST.h | |
parent | 23865e39295dd9199769727b037c1d126807b20e (diff) | |
download | dexon-solidity-b9a166061bc94cd06458c945d66bf52e76e84b70.tar dexon-solidity-b9a166061bc94cd06458c945d66bf52e76e84b70.tar.gz dexon-solidity-b9a166061bc94cd06458c945d66bf52e76e84b70.tar.bz2 dexon-solidity-b9a166061bc94cd06458c945d66bf52e76e84b70.tar.lz dexon-solidity-b9a166061bc94cd06458c945d66bf52e76e84b70.tar.xz dexon-solidity-b9a166061bc94cd06458c945d66bf52e76e84b70.tar.zst dexon-solidity-b9a166061bc94cd06458c945d66bf52e76e84b70.zip |
Refactoring to allow multi-variable declarations.
Diffstat (limited to 'libsolidity/AST.h')
-rw-r--r-- | libsolidity/AST.h | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/libsolidity/AST.h b/libsolidity/AST.h index 075c1ff5..354beb7c 100644 --- a/libsolidity/AST.h +++ b/libsolidity/AST.h @@ -963,20 +963,31 @@ public: * Definition of a variable as a statement inside a function. It requires a type name (which can * also be "var") but the actual assignment can be missing. * Examples: var a = 2; uint256 a; + * As a second form, multiple variables can be declared, cannot have a type and must be assigned + * right away. If the first or last component is unnamed, it can "consume" an arbitrary number + * of components. + * Examples: var (a, b) = f(); var (a,,,c) = g(); var (a,) = d(); */ class VariableDeclarationStatement: public Statement { public: - VariableDeclarationStatement(SourceLocation const& _location, ASTPointer<VariableDeclaration> _variable): - Statement(_location), m_variable(_variable) {} + VariableDeclarationStatement( + SourceLocation const& _location, + std::vector<ASTPointer<VariableDeclaration>> const& _variables, + ASTPointer<Expression> const& _initialValue + ): + Statement(_location), m_variables(_variables), m_initialValue(_initialValue) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - VariableDeclaration const& declaration() const { return *m_variable; } - Expression const* expression() const { return m_variable->value().get(); } + std::vector<ASTPointer<VariableDeclaration>> const& declarations() const { return m_variables; } + Expression const* initialValue() const { return m_initialValue.get(); } private: - ASTPointer<VariableDeclaration> m_variable; + /// List of variables, some of which can be empty pointers (unnamed components). + std::vector<ASTPointer<VariableDeclaration>> m_variables; + /// The assigned expression / initial value. + ASTPointer<Expression> m_initialValue; }; /** |