diff trunk/src/dil/Symbols.d @ 560:709e223a8eb9

Added code related to symbols. Added class ScopeSymbol. Module inherits from ScopeSymbol now. Added methods classScope() and moduleScope(), and member symbol to class Scope. Added enum SYM. Added member sid to class Symbol. Aggregate and Function inherit from ScopeSymbol now. Added Error to struct Types.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Wed, 26 Dec 2007 14:17:01 +0100
parents b465c669d70c
children 302e50e71ec2
line wrap: on
line diff
--- a/trunk/src/dil/Symbols.d	Mon Dec 24 20:39:14 2007 +0100
+++ b/trunk/src/dil/Symbols.d	Wed Dec 26 14:17:01 2007 +0100
@@ -3,10 +3,28 @@
   License: GPL3
 +/
 module dil.Symbols;
+
 import dil.Symbol;
+import dil.SymbolTable;
+import dil.SyntaxTree;
+import dil.Enums;
+import dil.TypeSystem;
+import dil.Identifier;
 import common;
 
-class Aggregate : Symbol
+/// A symbol that has its own scope with a symbol table.
+class ScopeSymbol : Symbol
+{
+  SymbolTable symbolTable; /// The symbol table.
+
+  this()
+  {
+    symbolTable = new SymbolTable;
+  }
+}
+
+/// Aggregates have function and field members.
+class Aggregate : ScopeSymbol
 {
   Function[] funcs;
   Variable[] fields;
@@ -14,25 +32,61 @@
 
 class Class : Aggregate
 {
-
+  this()
+  {
+    this.sid = SYM.Class;
+  }
 }
 
 class Union : Aggregate
 {
-
+  this()
+  {
+    this.sid = SYM.Union;
+  }
 }
 
 class Struct : Aggregate
 {
-
+  this()
+  {
+    this.sid = SYM.Struct;
+  }
 }
 
-class Function : Symbol
+class Function : ScopeSymbol
 {
+  StorageClass stc;
+  LinkageType linkType;
 
+  Type returnType;
+  Identifier* ident;
+  Variable[] params;
+
+  this()
+  {
+    this.sid = SYM.Function;
+  }
 }
 
 class Variable : Symbol
 {
+  StorageClass stc;
+  LinkageType linkType;
 
+  Type type;
+  Identifier* ident;
+  Node varDecl; /// The VariableDeclaration or Parameter node - for source code location.
+
+  this(StorageClass stc, LinkageType linkType,
+       Type type, Identifier* ident, Node varDecl)
+  {
+    this.sid = SYM.Variable;
+
+    this.stc = stc;
+    this.linkType = linkType;
+    this.type = type;
+    this.ident = ident;
+    this.varDecl = varDecl;
+  }
 }