Mercurial > projects > ddmd
annotate dmd/Identifier.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 | af724d3510d7 |
children |
rev | line source |
---|---|
0 | 1 module dmd.Identifier; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.TOK; |
5 import dmd.DYNCAST; | |
6 import dmd.Lexer; | |
168
ceed63f310fb
stringtable, stringbuffer and freelist moved to Global
korDen
parents:
114
diff
changeset
|
7 import dmd.Global; |
174 | 8 import dmd.Id; |
0 | 9 import dmd.OutBuffer; |
10 | |
174 | 11 import std.string; |
12 | |
178 | 13 import dmd.TObject; |
14 | |
15 class Identifier : TObject | |
0 | 16 { |
17 TOK value; | |
18 string string_; | |
19 | |
20 this(string string_, TOK value) | |
21 { | |
178 | 22 register(); |
0 | 23 this.string_ = string_; |
24 this.value = value; | |
25 } | |
174 | 26 |
45 | 27 bool equals(Object o) |
0 | 28 { |
168
ceed63f310fb
stringtable, stringbuffer and freelist moved to Global
korDen
parents:
114
diff
changeset
|
29 if (this is o) { |
ceed63f310fb
stringtable, stringbuffer and freelist moved to Global
korDen
parents:
114
diff
changeset
|
30 return true; |
ceed63f310fb
stringtable, stringbuffer and freelist moved to Global
korDen
parents:
114
diff
changeset
|
31 } |
174 | 32 |
168
ceed63f310fb
stringtable, stringbuffer and freelist moved to Global
korDen
parents:
114
diff
changeset
|
33 if (auto i = cast(Identifier)o) { |
ceed63f310fb
stringtable, stringbuffer and freelist moved to Global
korDen
parents:
114
diff
changeset
|
34 return string_ == i.string_; |
ceed63f310fb
stringtable, stringbuffer and freelist moved to Global
korDen
parents:
114
diff
changeset
|
35 } |
174 | 36 |
168
ceed63f310fb
stringtable, stringbuffer and freelist moved to Global
korDen
parents:
114
diff
changeset
|
37 return false; |
0 | 38 } |
174 | 39 |
0 | 40 hash_t hashCode() |
41 { | |
42 assert(false); | |
43 } | |
174 | 44 |
72 | 45 override int opCmp(Object o) |
0 | 46 { |
47 assert(false); | |
48 } | |
174 | 49 |
0 | 50 void print() |
51 { | |
52 assert(false); | |
53 } | |
174 | 54 |
0 | 55 string toChars() |
56 { | |
57 return string_; | |
58 } | |
174 | 59 |
0 | 60 version (_DH) { |
61 char* toHChars() | |
62 { | |
63 assert(false); | |
64 } | |
65 } | |
66 string toHChars2() | |
67 { | |
174 | 68 string p; |
69 | |
70 if (this == Id.ctor) p = "this"; | |
71 else if (this == Id.dtor) p = "~this"; | |
72 else if (this == Id.classInvariant) p = "invariant"; | |
73 else if (this == Id.unitTest) p = "unittest"; | |
74 else if (this == Id.dollar) p = "$"; | |
75 else if (this == Id.withSym) p = "with"; | |
76 else if (this == Id.result) p = "result"; | |
77 else if (this == Id.returnLabel) p = "return"; | |
78 else | |
79 { | |
80 p = toChars(); | |
81 if (p.length != 0 && p[0] == '_') | |
82 { | |
83 if (p.startsWith("_staticCtor")) | |
84 p = "static this"; | |
85 else if (p.startsWith("_staticDtor")) | |
86 p = "static ~this"; | |
87 } | |
88 } | |
89 | |
90 return p; | |
0 | 91 } |
174 | 92 |
0 | 93 DYNCAST dyncast() |
94 { | |
95 return DYNCAST.DYNCAST_IDENTIFIER; | |
96 } | |
97 | |
98 // BUG: these are redundant with Lexer::uniqueId() | |
99 static Identifier generateId(string prefix) | |
100 { | |
168
ceed63f310fb
stringtable, stringbuffer and freelist moved to Global
korDen
parents:
114
diff
changeset
|
101 return generateId(prefix, ++global.i); |
0 | 102 } |
174 | 103 |
0 | 104 static Identifier generateId(string prefix, size_t i) |
105 { | |
106 scope OutBuffer buf = new OutBuffer(); | |
107 | |
108 buf.writestring(prefix); | |
109 buf.printf("%d", i); ///<! | |
110 | |
111 string id = buf.extractString(); | |
112 return Lexer.idPool(id); | |
113 } | |
72 | 114 } |