From b9a166061bc94cd06458c945d66bf52e76e84b70 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 8 Oct 2015 18:01:12 +0200 Subject: Refactoring to allow multi-variable declarations. --- libsolidity/AST.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'libsolidity/AST.h') 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 _variable): - Statement(_location), m_variable(_variable) {} + VariableDeclarationStatement( + SourceLocation const& _location, + std::vector> const& _variables, + ASTPointer 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> const& declarations() const { return m_variables; } + Expression const* initialValue() const { return m_initialValue.get(); } private: - ASTPointer m_variable; + /// List of variables, some of which can be empty pointers (unnamed components). + std::vector> m_variables; + /// The assigned expression / initial value. + ASTPointer m_initialValue; }; /** -- cgit