Mercurial > projects > dil
annotate 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 |
rev | line source |
---|---|
517 | 1 /++ |
2 Author: Aziz Köksal | |
3 License: GPL3 | |
4 +/ | |
5 module dil.Symbols; | |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
6 |
517 | 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 | 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 { |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
18 SymbolTable symbolTable; /// The symbol table. |
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 { |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
22 symbolTable = new SymbolTable; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
23 } |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
24 } |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
25 |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
26 /// Aggregates have function and field members. |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
27 class Aggregate : ScopeSymbol |
517 | 28 { |
29 Function[] funcs; | |
30 Variable[] fields; | |
31 } | |
32 | |
33 class Class : Aggregate | |
34 { | |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
35 this() |
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 this.sid = SYM.Class; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
38 } |
517 | 39 } |
40 | |
41 class Union : Aggregate | |
42 { | |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
43 this() |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
44 { |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
45 this.sid = SYM.Union; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
46 } |
517 | 47 } |
48 | |
49 class Struct : Aggregate | |
50 { | |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
51 this() |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
52 { |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
53 this.sid = SYM.Struct; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
54 } |
517 | 55 } |
56 | |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
57 class Function : ScopeSymbol |
517 | 58 { |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
59 StorageClass stc; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
60 LinkageType linkType; |
517 | 61 |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
62 Type returnType; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
63 Identifier* ident; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
64 Variable[] params; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
65 |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
66 this() |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
67 { |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
68 this.sid = SYM.Function; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
69 } |
517 | 70 } |
71 | |
72 class Variable : Symbol | |
73 { | |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
74 StorageClass stc; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
75 LinkageType linkType; |
517 | 76 |
560
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
77 Type type; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
78 Identifier* ident; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
79 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
|
80 |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
81 this(StorageClass stc, LinkageType linkType, |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
82 Type type, Identifier* ident, Node varDecl) |
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.Variable; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
85 |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
86 this.stc = stc; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
87 this.linkType = linkType; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
88 this.type = type; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
89 this.ident = ident; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
90 this.varDecl = varDecl; |
709e223a8eb9
Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
517
diff
changeset
|
91 } |
517 | 92 } |