# HG changeset patch # User aziz # Date 1186498562 0 # Node ID df657dd98ffa0e1eeac379055b39241753da696d # Parent 74113a9aa77cb06aa425efa33393885621c39d1f - Fix: added member type to VariableDeclaration. - Changed class IfStatement. parseIfStatement() parses a DeclarationStatement if the condition is not an expression. diff -r 74113a9aa77c -r df657dd98ffa trunk/src/Declarations.d --- a/trunk/src/Declarations.d Tue Aug 07 09:09:03 2007 +0000 +++ b/trunk/src/Declarations.d Tue Aug 07 14:56:02 2007 +0000 @@ -236,12 +236,14 @@ class VariableDeclaration : Declaration { + Type type; Token*[] idents; Expression[] values; - this(Token*[] idents, Expression[] values) + this(Type type, Token*[] idents, Expression[] values) { super(false); mixin(set_kind); + this.type = type; this.idents = idents; this.values = values; } diff -r 74113a9aa77c -r df657dd98ffa trunk/src/Parser.d --- a/trunk/src/Parser.d Tue Aug 07 09:09:03 2007 +0000 +++ b/trunk/src/Parser.d Tue Aug 07 14:56:02 2007 +0000 @@ -383,7 +383,7 @@ values ~= null; } require(T.Semicolon); - return new VariableDeclaration(idents, values); + return new VariableDeclaration(type, idents, values); } Expression parseInitializer() @@ -1870,18 +1870,23 @@ assert(token.type == T.If); nT(); - Type type; - Token* ident; + Statement variable; Expression condition; Statement ifBody, elseBody; require(T.LParen); + + Token* ident; // auto Identifier = Expression if (token.type == T.Auto) { + auto a = new AttributeStatement(token.type, null); nT(); ident = requireId(); require(T.Assign); + auto init = parseExpression(); + a.statement = new DeclarationStatement(new VariableDeclaration(null, [ident], [init])); + variable = a; } else { @@ -1893,14 +1898,15 @@ return type; } bool success; - type = try_(parseDeclaratorAssign(), success); - if (!success) + auto type = try_(parseDeclaratorAssign(), success); + if (success) { - type = null; - ident = null; + auto init = parseExpression(); + variable = new DeclarationStatement(new VariableDeclaration(type, [ident], [init])); } + else + condition = parseExpression(); } - condition = parseExpression(); require(T.RParen); ifBody = parseScopeStatement(); if (token.type == T.Else) @@ -1908,7 +1914,7 @@ nT(); elseBody = parseScopeStatement(); } - return new IfStatement(type, ident, condition, ifBody, elseBody); + return new IfStatement(variable, condition, ifBody, elseBody); } Statement parseWhileStatement() diff -r 74113a9aa77c -r df657dd98ffa trunk/src/Statements.d --- a/trunk/src/Statements.d Tue Aug 07 09:09:03 2007 +0000 +++ b/trunk/src/Statements.d Tue Aug 07 14:56:02 2007 +0000 @@ -100,16 +100,14 @@ class IfStatement : Statement { - Type type; - Token* ident; + Statement variable; // AutoDeclaration or VariableDeclaration Expression condition; Statement ifBody; Statement elseBody; - this(Type type, Token* ident, Expression condition, Statement ifBody, Statement elseBody) + this(Statement variable, Expression condition, Statement ifBody, Statement elseBody) { mixin(set_kind); - this.type = type; - this.ident = ident; + this.variable = variable; this.condition = condition; this.ifBody = ifBody; this.elseBody = elseBody;