annotate dmd/DsymbolTable.d @ 177:1475fd394c9e

bug fixes
author korDen
date Sun, 10 Oct 2010 10:38:55 +0400
parents e28b18c23469
children e3afd1303184
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.DsymbolTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 0
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.StringTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.StringValue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import std.stdio;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 class DsymbolTable
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 StringTable tab;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 this()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 tab = new StringTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 ~this()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 // Look up Identifier. Return Dsymbol if found, NULL if not.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 Dsymbol lookup(Identifier ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 assert(ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 assert(tab);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 StringValue* sv = tab.lookup(ident.string_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 return (sv ? cast(Dsymbol)sv.ptrvalue : null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 // Insert Dsymbol in table. Return NULL if already there.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 Dsymbol insert(Dsymbol s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 Identifier ident = s.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 assert(ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 assert(tab);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 return insert(ident, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 // Look for Dsymbol in table. If there, return it. If not, insert s and return that.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 Dsymbol update(Dsymbol s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 Dsymbol insert(Identifier ident, Dsymbol s) // when ident and s are not the same
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 StringValue* sv = tab.insert(ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 if (sv is null) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 return null; // already in table
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 sv.ptrvalue = cast(void*)s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 }