Mercurial > projects > ddmd
comparison 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 |
comparison
equal
deleted
inserted
replaced
173:d237b38b5858 | 174:af724d3510d7 |
---|---|
3 import dmd.common; | 3 import dmd.common; |
4 import dmd.TOK; | 4 import dmd.TOK; |
5 import dmd.DYNCAST; | 5 import dmd.DYNCAST; |
6 import dmd.Lexer; | 6 import dmd.Lexer; |
7 import dmd.Global; | 7 import dmd.Global; |
8 import dmd.Id; | |
8 import dmd.OutBuffer; | 9 import dmd.OutBuffer; |
10 | |
11 import std.string; | |
9 | 12 |
10 class Identifier | 13 class Identifier |
11 { | 14 { |
12 TOK value; | 15 TOK value; |
13 string string_; | 16 string string_; |
15 this(string string_, TOK value) | 18 this(string string_, TOK value) |
16 { | 19 { |
17 this.string_ = string_; | 20 this.string_ = string_; |
18 this.value = value; | 21 this.value = value; |
19 } | 22 } |
20 | 23 |
21 bool equals(Object o) | 24 bool equals(Object o) |
22 { | 25 { |
23 if (this is o) { | 26 if (this is o) { |
24 return true; | 27 return true; |
25 } | 28 } |
26 | 29 |
27 if (auto i = cast(Identifier)o) { | 30 if (auto i = cast(Identifier)o) { |
28 return string_ == i.string_; | 31 return string_ == i.string_; |
29 } | 32 } |
30 | 33 |
31 return false; | 34 return false; |
32 } | 35 } |
33 | 36 |
34 hash_t hashCode() | 37 hash_t hashCode() |
35 { | 38 { |
36 assert(false); | 39 assert(false); |
37 } | 40 } |
38 | 41 |
39 override int opCmp(Object o) | 42 override int opCmp(Object o) |
40 { | 43 { |
41 assert(false); | 44 assert(false); |
42 } | 45 } |
43 | 46 |
44 void print() | 47 void print() |
45 { | 48 { |
46 assert(false); | 49 assert(false); |
47 } | 50 } |
48 | 51 |
49 string toChars() | 52 string toChars() |
50 { | 53 { |
51 return string_; | 54 return string_; |
52 } | 55 } |
53 | 56 |
54 version (_DH) { | 57 version (_DH) { |
55 char* toHChars() | 58 char* toHChars() |
56 { | 59 { |
57 assert(false); | 60 assert(false); |
58 } | 61 } |
59 } | 62 } |
60 string toHChars2() | 63 string toHChars2() |
61 { | 64 { |
62 assert(false); | 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; | |
63 } | 88 } |
64 | 89 |
65 DYNCAST dyncast() | 90 DYNCAST dyncast() |
66 { | 91 { |
67 return DYNCAST.DYNCAST_IDENTIFIER; | 92 return DYNCAST.DYNCAST_IDENTIFIER; |
68 } | 93 } |
69 | 94 |
70 // BUG: these are redundant with Lexer::uniqueId() | 95 // BUG: these are redundant with Lexer::uniqueId() |
71 static Identifier generateId(string prefix) | 96 static Identifier generateId(string prefix) |
72 { | 97 { |
73 return generateId(prefix, ++global.i); | 98 return generateId(prefix, ++global.i); |
74 } | 99 } |
75 | 100 |
76 static Identifier generateId(string prefix, size_t i) | 101 static Identifier generateId(string prefix, size_t i) |
77 { | 102 { |
78 scope OutBuffer buf = new OutBuffer(); | 103 scope OutBuffer buf = new OutBuffer(); |
79 | 104 |
80 buf.writestring(prefix); | 105 buf.writestring(prefix); |