changeset 94:0fe650a7a8d1

- Renamed Type enum to InfoType in module Information. - Changed 'TOK type' member of TypeDotIdExpression to 'Type type'. - Added module Types. - Implemented most of parseBasicType(). - Indented code of 'BasicType . Identifier' parser and creating Type instance.
author aziz
date Fri, 06 Jul 2007 15:23:04 +0000
parents 9f8b6c205ecc
children 0eb4c8a5b32b
files trunk/src/Expressions.d trunk/src/Information.d trunk/src/Lexer.d trunk/src/Parser.d trunk/src/Types.d
diffstat 5 files changed, 120 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/Expressions.d	Fri Jul 06 10:18:03 2007 +0000
+++ b/trunk/src/Expressions.d	Fri Jul 06 15:23:04 2007 +0000
@@ -4,6 +4,7 @@
 +/
 module Expressions;
 import Token;
+import Types;
 
 class Expression
 {
@@ -467,9 +468,9 @@
 
 class TypeDotIdExpression : Expression
 {
-  TOK type;
+  Type type;
   string ident;
-  this(TOK type, string ident)
+  this(Type type, string ident)
   {
     this.type = type;
     this.ident = ident;
--- a/trunk/src/Information.d	Fri Jul 06 10:18:03 2007 +0000
+++ b/trunk/src/Information.d	Fri Jul 06 15:23:04 2007 +0000
@@ -7,7 +7,7 @@
 import std.string;
 import std.stdarg;
 
-enum Type
+enum InfoType
 {
   Lexer,
   Parser,
@@ -17,11 +17,11 @@
 class Information
 {
   MID id;
-  Type type;
+  InfoType type;
   uint loc;
   string[] arguments;
 
-  this(Type type, MID id, uint loc, string[] arguments)
+  this(InfoType type, MID id, uint loc, string[] arguments)
   {
     this.id = id;
     this.type = type;
--- a/trunk/src/Lexer.d	Fri Jul 06 10:18:03 2007 +0000
+++ b/trunk/src/Lexer.d	Fri Jul 06 15:23:04 2007 +0000
@@ -1436,7 +1436,7 @@
 
   void error(MID id, ...)
   {
-    errors ~= new Information(Information.Type.Lexer, id, loc, arguments(_arguments, _argptr));
+    errors ~= new Information(InfoType.Lexer, id, loc, arguments(_arguments, _argptr));
   }
 
   public TOK nextToken()
--- a/trunk/src/Parser.d	Fri Jul 06 10:18:03 2007 +0000
+++ b/trunk/src/Parser.d	Fri Jul 06 15:23:04 2007 +0000
@@ -8,6 +8,7 @@
 import Messages;
 import Information;
 import Expressions;
+import Types;
 
 enum STC
 {
@@ -530,24 +531,26 @@
     case T.LParen:
       break;
     // BasicType . Identifier
-    case T.Void, T.Char, T.Wchar, T.Dchar, T.Bool, T.Byte, T.Ubyte,
-         T.Short, T.Ushort, T.Int, T.Uint, T.Long, T.Ulong,
-         T.Float, T.Double, T.Real, T.Ifloat, T.Idouble, T.Ireal,
+    case T.Void,   T.Char,    T.Wchar,  T.Dchar, T.Bool,
+         T.Byte,   T.Ubyte,   T.Short,  T.Ushort,
+         T.Int,    T.Uint,    T.Long,   T.Ulong,
+         T.Float,  T.Double,  T.Real,
+         T.Ifloat, T.Idouble, T.Ireal,
          T.Cfloat, T.Cdouble, T.Creal:
-    TOK type = token.type;
+      auto type = new Type(token.type);
 
-    requireNext(T.Dot);
+      requireNext(T.Dot);
 
-    string ident;
-    if (token.type == T.Identifier)
-    {
-      ident = token.srcText;
-      nT();
-    }
-    else
-      errorIfNot(T.Identifier);
+      string ident;
+      if (token.type == T.Identifier)
+      {
+        ident = token.srcText;
+        nT();
+      }
+      else
+        errorIfNot(T.Identifier);
 
-    e = new TypeDotIdExpression(type, ident);
+      e = new TypeDotIdExpression(type, ident);
     default:
 //       error();
     }
@@ -581,6 +584,54 @@
     return es;
   }
 
+  Type parseBasicType()
+  {
+    Type t;
+    IdentifierType tident;
+
+    switch (token.type)
+    {
+    case T.Void,   T.Char,    T.Wchar,  T.Dchar, T.Bool,
+         T.Byte,   T.Ubyte,   T.Short,  T.Ushort,
+         T.Int,    T.Uint,    T.Long,   T.Ulong,
+         T.Float,  T.Double,  T.Real,
+         T.Ifloat, T.Idouble, T.Ireal,
+         T.Cfloat, T.Cdouble, T.Creal:
+      t = new Type(token.type);
+      nT();
+      break;
+    case T.Identifier, T.Dot:
+      tident = new IdentifierType([token.srcText]);
+      nT();
+//       if (token.type == T.Not)
+//         parse template instance
+    Lident:
+      while (token.type == T.Dot)
+      {
+        nT();
+        if (token.type == T.Identifier)
+        {
+          tident ~= token.srcText;
+        }
+        else
+          errorIfNot(T.Identifier);
+        nT();
+//       if (token.type == T.Not)
+//         parse template instance
+      }
+      t = tident;
+      break;
+    case T.Typeof:
+      requireNext(T.LParen);
+      tident = new TypeofType(parseExpression());
+      require(T.RParen);
+      goto Lident;
+    default:
+//       error();
+    }
+    return t;
+  }
+
   void errorIfNot(TOK tok)
   {
     if (token.type != tok)
@@ -606,6 +657,6 @@
 
   void error(MID id, ...)
   {
-    errors ~= new Information(Information.Type.Parser, id, lx.loc, arguments(_arguments, _argptr));
+    errors ~= new Information(InfoType.Parser, id, lx.loc, arguments(_arguments, _argptr));
   }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trunk/src/Types.d	Fri Jul 06 15:23:04 2007 +0000
@@ -0,0 +1,47 @@
+/++
+  Author: Aziz Köksal
+  License: GPL2
++/
+module Types;
+import Token;
+import Expressions;
+
+class Type
+{
+  TOK type;
+  this(TOK type)
+  {
+    this.type = type;
+  }
+}
+
+class IdentifierType : Type
+{
+  string[] idents;
+
+  this(string[] idents)
+  {
+    super(TOK.Identifier);
+    this.idents = idents;
+  }
+
+  this(TOK type)
+  {
+    super(type);
+  }
+
+  void opCatAssign(string ident)
+  {
+    this.idents ~= ident;
+  }
+}
+
+class TypeofType : IdentifierType
+{
+  Expression e;
+  this(Expression e)
+  {
+    super(TOK.Typeof);
+    this.e = e;
+  }
+}