annotate trunk/src/dil/Symbols.d @ 565:184a8d8bad2e

Added semantic() to StructDeclaration.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 28 Dec 2007 23:22:33 +0100
parents b0533550d64c
children ab9f5020cd02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
517
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
1 /++
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
2 Author: Aziz Köksal
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
3 License: GPL3
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
4 +/
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
5 module dil.Symbols;
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
6
517
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
7 import dil.Symbol;
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
8 import dil.SymbolTable;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
9 import dil.SyntaxTree;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
10 import dil.Enums;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
11 import dil.TypeSystem;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
12 import dil.Identifier;
517
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
13 import common;
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
14
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
15 /// A symbol that has its own scope with a symbol table.
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
16 class ScopeSymbol : Symbol
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
17 {
562
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
18 protected SymbolTable symbolTable; /// The symbol table.
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
19
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
20 this()
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
21 {
562
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
22 }
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
23
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
24 /// Look up ident in the table.
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
25 Symbol lookup(Identifier* ident)
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
26 {
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
27 return symbolTable.lookup(ident);
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
28 }
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
29
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
30 /// Insert a symbol into the table.
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
31 void insert(Symbol s, Identifier* ident)
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
32 {
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
33 symbolTable.insert(s, ident);
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
34 }
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
35 }
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
36
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
37 /// Aggregates have function and field members.
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
38 class Aggregate : ScopeSymbol
517
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
39 {
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
40 Function[] funcs;
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
41 Variable[] fields;
562
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
42
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
43 override void insert(Symbol s, Identifier* ident)
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
44 {
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
45 if (s.sid == SYM.Variable)
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
46 // Append variable to fields.
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
47 fields ~= cast(Variable)cast(void*)s;
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
48 else if (s.sid == SYM.Function)
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
49 // Append function to funcs.
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
50 funcs ~= cast(Function)cast(void*)s;
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
51 super.insert(s, ident);
b0533550d64c Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
52 }
517
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
53 }
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
54
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
55 class Class : Aggregate
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
56 {
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
57 this()
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
58 {
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
59 this.sid = SYM.Class;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
60 }
517
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
61 }
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
62
561
302e50e71ec2 Added Interface symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 560
diff changeset
63 class Interface : Aggregate
302e50e71ec2 Added Interface symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 560
diff changeset
64 {
302e50e71ec2 Added Interface symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 560
diff changeset
65 this()
302e50e71ec2 Added Interface symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 560
diff changeset
66 {
302e50e71ec2 Added Interface symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 560
diff changeset
67 this.sid = SYM.Interface;
302e50e71ec2 Added Interface symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 560
diff changeset
68 }
302e50e71ec2 Added Interface symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 560
diff changeset
69 }
302e50e71ec2 Added Interface symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 560
diff changeset
70
517
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
71 class Union : Aggregate
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
72 {
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
73 this()
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
74 {
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
75 this.sid = SYM.Union;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
76 }
517
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
77 }
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
78
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
79 class Struct : Aggregate
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
80 {
565
184a8d8bad2e Added semantic() to StructDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 562
diff changeset
81 Identifier* ident;
184a8d8bad2e Added semantic() to StructDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 562
diff changeset
82 this(Identifier* ident)
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
83 {
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
84 this.sid = SYM.Struct;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
85 }
517
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
86 }
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
87
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
88 class Function : ScopeSymbol
517
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
89 {
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
90 StorageClass stc;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
91 LinkageType linkType;
517
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
92
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
93 Type returnType;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
94 Identifier* ident;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
95 Variable[] params;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
96
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
97 this()
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
98 {
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
99 this.sid = SYM.Function;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
100 }
517
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
101 }
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
102
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
103 class Variable : Symbol
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
104 {
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
105 StorageClass stc;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
106 LinkageType linkType;
517
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
107
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
108 Type type;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
109 Identifier* ident;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
110 Node varDecl; /// The VariableDeclaration or Parameter node - for source code location.
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
111
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
112 this(StorageClass stc, LinkageType linkType,
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
113 Type type, Identifier* ident, Node varDecl)
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
114 {
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
115 this.sid = SYM.Variable;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
116
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
117 this.stc = stc;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
118 this.linkType = linkType;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
119 this.type = type;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
120 this.ident = ident;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
121 this.varDecl = varDecl;
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 517
diff changeset
122 }
517
b465c669d70c Added module dil.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
123 }