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