# HG changeset patch # User Aziz K?ksal # Date 1198965766 -3600 # Node ID 3ebdc510a7fcde21fe1e0ab94e4245bd366819d6 # Parent 86fa0d36da51ab7c23823003e6889b3470217bae Added semantic() to InterfaceDeclaration. diff -r 86fa0d36da51 -r 3ebdc510a7fc trunk/src/dil/Declarations.d --- 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) { diff -r 86fa0d36da51 -r 3ebdc510a7fc trunk/src/dil/Module.d --- 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. diff -r 86fa0d36da51 -r 3ebdc510a7fc trunk/src/dil/Scope.d --- 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() { diff -r 86fa0d36da51 -r 3ebdc510a7fc trunk/src/dil/Symbols.d --- 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; } }