Mercurial > projects > dil
annotate trunk/src/dil/semantic/Symbols.d @ 600:041eae272362
Moved dil.Identifier to dil.lexer.Identifier.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sun, 06 Jan 2008 00:52:20 +0100 |
parents | 26addda6365b |
children | 8c5b1558244b |
rev | line source |
---|---|
517 | 1 /++ |
2 Author: Aziz Köksal | |
3 License: GPL3 | |
4 +/ | |
590
641041912670
Moved dil.Symbols to dil.semantic.Symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
589
diff
changeset
|
5 module dil.semantic.Symbols; |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
6 |
589
de365ddcfbd4
Moved dil.Symbol to dil.semantic.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
584
diff
changeset
|
7 import dil.semantic.Symbol; |
591
26addda6365b
Moved dil.SymbolTable to dil.semantic.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
590
diff
changeset
|
8 import dil.semantic.SymbolTable; |
600
041eae272362
Moved dil.Identifier to dil.lexer.Identifier.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
591
diff
changeset
|
9 import dil.semantic.Types; |
580
fa6d3c52757d
Moved SyntaxTree.d to new package 'ast'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
573
diff
changeset
|
10 import dil.ast.Node; |
600
041eae272362
Moved dil.Identifier to dil.lexer.Identifier.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
591
diff
changeset
|
11 import dil.lexer.Identifier; |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
12 import dil.Enums; |
517 | 13 import common; |
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 | 39 { |
570
3ebdc510a7fc
Added semantic() to InterfaceDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
568
diff
changeset
|
40 Identifier* ident; /// The name of this aggregate. |
517 | 41 Function[] funcs; |
42 Variable[] fields; | |
562
b0533550d64c
Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
561
diff
changeset
|
43 |
b0533550d64c
Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
561
diff
changeset
|
44 override void insert(Symbol s, Identifier* ident) |
b0533550d64c
Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
561
diff
changeset
|
45 { |
567
ab9f5020cd02
Added 'is-methods' to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
565
diff
changeset
|
46 if (s.isVariable) |
562
b0533550d64c
Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
561
diff
changeset
|
47 // Append variable to fields. |
b0533550d64c
Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
561
diff
changeset
|
48 fields ~= cast(Variable)cast(void*)s; |
567
ab9f5020cd02
Added 'is-methods' to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
565
diff
changeset
|
49 else if (s.isFunction) |
562
b0533550d64c
Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
561
diff
changeset
|
50 // Append function to funcs. |
b0533550d64c
Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
561
diff
changeset
|
51 funcs ~= cast(Function)cast(void*)s; |
b0533550d64c
Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
561
diff
changeset
|
52 super.insert(s, ident); |
b0533550d64c
Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
561
diff
changeset
|
53 } |
517 | 54 } |
55 | |
56 class Class : Aggregate | |
57 { | |
573
87c4474a1295
Added semantic() to ClassDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
572
diff
changeset
|
58 this(Identifier* ident, Node classNode) |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
59 { |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
60 this.sid = SYM.Class; |
573
87c4474a1295
Added semantic() to ClassDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
572
diff
changeset
|
61 this.ident = ident; |
87c4474a1295
Added semantic() to ClassDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
572
diff
changeset
|
62 this.node = classNode; |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
63 } |
517 | 64 } |
65 | |
561
302e50e71ec2
Added Interface symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
560
diff
changeset
|
66 class Interface : Aggregate |
302e50e71ec2
Added Interface symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
560
diff
changeset
|
67 { |
572
751d84733e07
Added semantic() to UnionDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
570
diff
changeset
|
68 this(Identifier* ident, Node interfaceNode) |
561
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 this.sid = SYM.Interface; |
570
3ebdc510a7fc
Added semantic() to InterfaceDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
568
diff
changeset
|
71 this.ident = ident; |
572
751d84733e07
Added semantic() to UnionDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
570
diff
changeset
|
72 this.node = interfaceNode; |
561
302e50e71ec2
Added Interface symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
560
diff
changeset
|
73 } |
302e50e71ec2
Added Interface symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
560
diff
changeset
|
74 } |
302e50e71ec2
Added Interface symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
560
diff
changeset
|
75 |
517 | 76 class Union : Aggregate |
77 { | |
572
751d84733e07
Added semantic() to UnionDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
570
diff
changeset
|
78 this(Identifier* ident, Node unionNode) |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
79 { |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
80 this.sid = SYM.Union; |
572
751d84733e07
Added semantic() to UnionDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
570
diff
changeset
|
81 this.ident = ident; |
751d84733e07
Added semantic() to UnionDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
570
diff
changeset
|
82 this.node = unionNode; |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
83 } |
517 | 84 } |
85 | |
86 class Struct : Aggregate | |
87 { | |
570
3ebdc510a7fc
Added semantic() to InterfaceDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
568
diff
changeset
|
88 this(Identifier* ident, Node structNode) |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
89 { |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
90 this.sid = SYM.Struct; |
570
3ebdc510a7fc
Added semantic() to InterfaceDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
568
diff
changeset
|
91 this.ident = ident; |
3ebdc510a7fc
Added semantic() to InterfaceDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
568
diff
changeset
|
92 this.node = structNode; |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
93 } |
517 | 94 } |
95 | |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
96 class Function : ScopeSymbol |
517 | 97 { |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
98 StorageClass stc; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
99 LinkageType linkType; |
517 | 100 |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
101 Type returnType; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
102 Identifier* ident; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
103 Variable[] params; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
104 |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
105 this() |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
106 { |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
107 this.sid = SYM.Function; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
108 } |
517 | 109 } |
110 | |
111 class Variable : Symbol | |
112 { | |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
113 StorageClass stc; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
114 LinkageType linkType; |
517 | 115 |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
116 Type type; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
117 Identifier* ident; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
118 |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
119 this(StorageClass stc, LinkageType linkType, |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
120 Type type, Identifier* ident, Node varDecl) |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
121 { |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
122 this.sid = SYM.Variable; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
123 |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
124 this.stc = stc; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
125 this.linkType = linkType; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
126 this.type = type; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
127 this.ident = ident; |
568
c8861b452eb3
Added members 'node' and 'parent' to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
567
diff
changeset
|
128 this.node = varDecl; |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
129 } |
517 | 130 } |