annotate dmd/DsymbolTable.d @ 178:e3afd1303184

Many small bugs fixed Made all classes derive from TObject to detect memory leaks (functionality is disabled for now) Began work on overriding backend memory allocations (to avoid memory leaks)
author korDen
date Sun, 17 Oct 2010 07:42:00 +0400
parents 1475fd394c9e
children b0d41ff5e0df
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
178
e3afd1303184 Many small bugs fixed
korDen
parents: 177
diff changeset
11 import dmd.TObject;
e3afd1303184 Many small bugs fixed
korDen
parents: 177
diff changeset
12
e3afd1303184 Many small bugs fixed
korDen
parents: 177
diff changeset
13 class DsymbolTable : TObject
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 StringTable tab;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 this()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 177
diff changeset
19 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 // Look up Identifier. Return Dsymbol if found, NULL if not.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 Dsymbol lookup(Identifier ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 assert(ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 177
diff changeset
28 Object* sv = tab.lookup(ident.string_);
e3afd1303184 Many small bugs fixed
korDen
parents: 177
diff changeset
29 return (sv ? cast(Dsymbol)*sv : null);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 // Insert Dsymbol in table. Return NULL if already there.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 Dsymbol insert(Dsymbol s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 Identifier ident = s.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 assert(ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 return insert(ident, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 // Look for Dsymbol in table. If there, return it. If not, insert s and return that.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 Dsymbol update(Dsymbol s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 177
diff changeset
48
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 Dsymbol insert(Identifier ident, Dsymbol s) // when ident and s are not the same
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 177
diff changeset
51 Object* sv = tab.insert(ident.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 if (sv is null) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 return null; // already in table
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55
178
e3afd1303184 Many small bugs fixed
korDen
parents: 177
diff changeset
56 *sv = s;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 177
diff changeset
59 }