changeset 536:0781ac288537

Added some semantic() methods. Renamed member typ of dil.TypeSystem.Type to tid. Added 'Undefined' to struct Types. Removed charLiteral and added 'dchar character' to class CharExpression.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Tue, 18 Dec 2007 15:14:41 +0100
parents bdd49ad84f5f
children db7913148b29
files trunk/src/dil/Expressions.d trunk/src/dil/Parser.d trunk/src/dil/TypeSystem.d
diffstat 3 files changed, 35 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/Expressions.d	Tue Dec 18 00:32:30 2007 +0100
+++ b/trunk/src/dil/Expressions.d	Tue Dec 18 15:14:41 2007 +0100
@@ -11,6 +11,7 @@
 import dil.Identifier;
 import dil.Scope;
 import dil.TypeSystem;
+import common;
 
 abstract class Expression : Node
 {
@@ -20,9 +21,14 @@
     super(NodeCategory.Expression);
   }
 
+  // Semantic analysis:
+
   Expression semantic(Scope scop)
   {
-    return null;
+    debug Stdout("SA for "~this.classinfo.name).newline;
+    if (!type)
+      type = Types.Undefined;
+    return this;
   }
 
   import dil.Messages;
@@ -30,6 +36,11 @@
   {
     scop.error(this.begin, mid);
   }
+
+  void error(Scope scop, char[] msg)
+  {
+
+  }
 }
 
 class EmptyExpression : Expression
@@ -712,11 +723,24 @@
 
 class CharExpression : Expression
 {
-  Token* charLiteral;
-  this(Token* charLiteral)
+  dchar character;
+  this(dchar character)
   {
     mixin(set_kind);
-    this.charLiteral = charLiteral;
+    this.character = character;
+  }
+
+  Expression semantic(Scope scop)
+  {
+    if (type)
+      return this;
+    if (character <= 0xFF)
+      type = Types.Char;
+    else if (character <= 0xFFFF)
+      type = Types.Wchar;
+    else
+      type = Types.Dchar;
+    return this;
   }
 }
 
--- a/trunk/src/dil/Parser.d	Tue Dec 18 00:32:30 2007 +0100
+++ b/trunk/src/dil/Parser.d	Tue Dec 18 15:14:41 2007 +0100
@@ -3311,7 +3311,7 @@
       nT();
       break;
     case T.CharLiteral:
-      e = new CharExpression(token);
+      e = new CharExpression(token.dchar_);
       nT();
       break;
     case T.String:
--- a/trunk/src/dil/TypeSystem.d	Tue Dec 18 00:32:30 2007 +0100
+++ b/trunk/src/dil/TypeSystem.d	Tue Dec 18 15:14:41 2007 +0100
@@ -12,14 +12,14 @@
 abstract class Type : Symbol
 {
   Type next;
-  TYP typ;
+  TYP tid; /// The ID of the type.
 
   this(){}
 
-  this(Type next, TYP typ)
+  this(Type next, TYP tid)
   {
     this.next = next;
-    this.typ = typ;
+    this.tid = tid;
   }
 
   TypePointer ptrTo()
@@ -249,7 +249,7 @@
 
   size_t getSize(Type type)
   {
-    auto size = metaInfoTable[type.typ].size;
+    auto size = metaInfoTable[type.tid].size;
     if (size == SIZE_NOT_AVAILABLE)
       return type.sizeOf_();
     return size;
@@ -270,6 +270,7 @@
 
   TypeBasic Size_t, Ptrdiff_t;
   TypePointer Void_ptr;
+  TypeBasic Undefined;
 
   /// Allocates an instance of TypeBasic and assigns it to typeName.
   template newTB(char[] typeName)
@@ -314,5 +315,6 @@
       Ptrdiff_t = Int;
     }
     Void_ptr = Void.ptrTo;
+    Undefined = new TypeBasic(TYP.Error);
   }
 }