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 }
|
|
23
|
|
24 // Look up Identifier. Return Dsymbol if found, NULL if not.
|
|
25 Dsymbol lookup(Identifier ident)
|
|
26 {
|
|
27 debug {
|
|
28 assert(ident);
|
|
29 assert(tab);
|
|
30 }
|
|
31 StringValue* sv = tab.lookup(ident.string_);
|
|
32 return (sv ? cast(Dsymbol)sv.ptrvalue : null);
|
|
33 }
|
|
34
|
|
35 // Insert Dsymbol in table. Return NULL if already there.
|
|
36 Dsymbol insert(Dsymbol s)
|
|
37 {
|
|
38 Identifier ident = s.ident;
|
|
39 debug {
|
|
40 assert(ident);
|
|
41 assert(tab);
|
|
42 }
|
|
43
|
|
44 return insert(ident, s);
|
|
45 }
|
|
46
|
|
47 // Look for Dsymbol in table. If there, return it. If not, insert s and return that.
|
|
48 Dsymbol update(Dsymbol s)
|
|
49 {
|
|
50 assert(false);
|
|
51 }
|
|
52
|
|
53 Dsymbol insert(Identifier ident, Dsymbol s) // when ident and s are not the same
|
|
54 {
|
|
55 StringValue* sv = tab.insert(ident.toChars());
|
|
56 if (sv is null) {
|
|
57 return null; // already in table
|
|
58 }
|
|
59
|
|
60 sv.ptrvalue = cast(void*)s;
|
|
61 return s;
|
|
62 }
|
|
63 } |