0
|
1 module dmd.DsymbolTable;
|
|
2
|
114
|
3 import dmd.common;
|
0
|
4 import dmd.StringTable;
|
|
5 import dmd.Dsymbol;
|
|
6 import dmd.Identifier;
|
|
7 import dmd.StringValue;
|
|
8
|
|
9 import std.stdio;
|
|
10
|
|
11 class DsymbolTable
|
|
12 {
|
|
13 StringTable tab;
|
|
14
|
|
15 this()
|
|
16 {
|
|
17 tab = new StringTable;
|
|
18 }
|
|
19
|
|
20 ~this()
|
|
21 {
|
|
22 delete tab;
|
|
23 }
|
|
24
|
|
25 // Look up Identifier. Return Dsymbol if found, NULL if not.
|
|
26 Dsymbol lookup(Identifier ident)
|
|
27 {
|
|
28 debug {
|
|
29 assert(ident);
|
|
30 assert(tab);
|
|
31 }
|
|
32 StringValue* sv = tab.lookup(ident.string_);
|
|
33 return (sv ? cast(Dsymbol)sv.ptrvalue : null);
|
|
34 }
|
|
35
|
|
36 // Insert Dsymbol in table. Return NULL if already there.
|
|
37 Dsymbol insert(Dsymbol s)
|
|
38 {
|
|
39 Identifier ident = s.ident;
|
|
40 debug {
|
|
41 assert(ident);
|
|
42 assert(tab);
|
|
43 }
|
|
44
|
|
45 return insert(ident, s);
|
|
46 }
|
|
47
|
|
48 // Look for Dsymbol in table. If there, return it. If not, insert s and return that.
|
|
49 Dsymbol update(Dsymbol s)
|
|
50 {
|
|
51 assert(false);
|
|
52 }
|
|
53
|
|
54 Dsymbol insert(Identifier ident, Dsymbol s) // when ident and s are not the same
|
|
55 {
|
|
56 StringValue* sv = tab.insert(ident.toChars());
|
|
57 if (sv is null) {
|
|
58 return null; // already in table
|
|
59 }
|
|
60
|
|
61 sv.ptrvalue = cast(void*)s;
|
|
62 return s;
|
|
63 }
|
|
64 } |