changeset 570:3ebdc510a7fc

Added semantic() to InterfaceDeclaration.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sat, 29 Dec 2007 23:02:46 +0100
parents 86fa0d36da51
children 35a8926253c8
files trunk/src/dil/Declarations.d trunk/src/dil/Module.d trunk/src/dil/Scope.d trunk/src/dil/Symbols.d
diffstat 4 files changed, 37 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/Declarations.d	Sat Dec 29 21:57:33 2007 +0100
+++ b/trunk/src/dil/Declarations.d	Sat Dec 29 23:02:46 2007 +0100
@@ -289,6 +289,22 @@
     this.bases = bases;
     this.decls = decls;
   }
+
+  alias dil.Symbols.Interface InterfaceSymbol;
+
+  InterfaceSymbol interface_; /// The interface symbol for this declaration.
+
+  override void semantic(Scope scop)
+  {
+    if (interface_)
+      return;
+    interface_ = new InterfaceSymbol(name, this);
+    // Create a new scope.
+    scop = scop.push(interface_);
+    // Continue semantic analysis.
+    decls.semantic(scop);
+    scop.pop();
+  }
 }
 
 class StructDeclaration : Declaration
@@ -320,7 +336,7 @@
   {
     if (struct_)
       return;
-    struct_ = new Struct(name);
+    struct_ = new Struct(name, this);
     // Create a new scope.
     scop = scop.push(struct_);
     // Continue semantic analysis.
@@ -477,6 +493,10 @@
     }
     assert(type !is null);
 
+    // Check for interface.
+    if (scop.isInterface)
+      return scop.error(begin, "an interface can't have member variables");
+
     // Iterate over variable identifiers in this declaration.
     foreach (i, ident; idents)
     {
--- a/trunk/src/dil/Module.d	Sat Dec 29 21:57:33 2007 +0100
+++ b/trunk/src/dil/Module.d	Sat Dec 29 23:02:46 2007 +0100
@@ -88,6 +88,8 @@
   /// Starts the semantic analysis of this module.
   void semantic()
   {
+    if (this.hasErrors)
+      return;
     // Create module scope.
     auto scop = new Scope();
     scop.symbol = this; // Set this module as the scope's symbol.
--- a/trunk/src/dil/Scope.d	Sat Dec 29 21:57:33 2007 +0100
+++ b/trunk/src/dil/Scope.d	Sat Dec 29 23:02:46 2007 +0100
@@ -50,6 +50,8 @@
     }
     else
       symbol.insert(var, var.ident);
+    // Set the current scope symbol as the parent.
+    var.parent = symbol;
   }
 
   /++
@@ -74,6 +76,11 @@
     return sc;
   }
 
+  bool isInterface()
+  {
+    return symbol.isInterface;
+  }
+
   /// Search for the enclosing Class scope.
   Scope classScope()
   {
--- a/trunk/src/dil/Symbols.d	Sat Dec 29 21:57:33 2007 +0100
+++ b/trunk/src/dil/Symbols.d	Sat Dec 29 23:02:46 2007 +0100
@@ -37,6 +37,7 @@
 /// Aggregates have function and field members.
 class Aggregate : ScopeSymbol
 {
+  Identifier* ident; /// The name of this aggregate.
   Function[] funcs;
   Variable[] fields;
 
@@ -62,9 +63,11 @@
 
 class Interface : Aggregate
 {
-  this()
+  this(Identifier* ident, Node interfNode)
   {
     this.sid = SYM.Interface;
+    this.ident = ident;
+    this.node = interfNode;
   }
 }
 
@@ -78,10 +81,11 @@
 
 class Struct : Aggregate
 {
-  Identifier* ident;
-  this(Identifier* ident)
+  this(Identifier* ident, Node structNode)
   {
     this.sid = SYM.Struct;
+    this.ident = ident;
+    this.node = structNode;
   }
 }