changeset 283:df657dd98ffa

- Fix: added member type to VariableDeclaration. - Changed class IfStatement. parseIfStatement() parses a DeclarationStatement if the condition is not an expression.
author aziz
date Tue, 07 Aug 2007 14:56:02 +0000
parents 74113a9aa77c
children 00c887e6c0aa
files trunk/src/Declarations.d trunk/src/Parser.d trunk/src/Statements.d
diffstat 3 files changed, 21 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- 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;
   }
--- 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()
--- 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;