mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Refactoring to allow multi-variable declarations.
This commit is contained in:
+16
-5
@@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user