0
|
1 module dmd.Identifier;
|
|
2
|
114
|
3 import dmd.common;
|
0
|
4 import dmd.TOK;
|
|
5 import dmd.DYNCAST;
|
|
6 import dmd.Lexer;
|
|
7 import dmd.OutBuffer;
|
|
8
|
|
9 import std.stdio : writef;
|
|
10
|
|
11 class Identifier
|
|
12 {
|
|
13 TOK value;
|
|
14 string string_;
|
|
15
|
|
16 this(string string_, TOK value)
|
|
17 {
|
|
18 this.string_ = string_;
|
|
19 this.value = value;
|
|
20 }
|
|
21
|
45
|
22 bool equals(Object o)
|
0
|
23 {
|
|
24 return this is o || string_ == (cast(Identifier)o).toChars(); /// hack
|
|
25 }
|
|
26
|
|
27 hash_t hashCode()
|
|
28 {
|
|
29 assert(false);
|
|
30 }
|
|
31
|
72
|
32 override int opCmp(Object o)
|
0
|
33 {
|
|
34 assert(false);
|
|
35 }
|
|
36
|
|
37 void print()
|
|
38 {
|
|
39 assert(false);
|
|
40 }
|
|
41
|
|
42 string toChars()
|
|
43 {
|
|
44 return string_;
|
|
45 }
|
|
46
|
|
47 version (_DH) {
|
|
48 char* toHChars()
|
|
49 {
|
|
50 assert(false);
|
|
51 }
|
|
52 }
|
|
53 string toHChars2()
|
|
54 {
|
|
55 assert(false);
|
|
56 }
|
|
57
|
|
58 DYNCAST dyncast()
|
|
59 {
|
|
60 return DYNCAST.DYNCAST_IDENTIFIER;
|
|
61 }
|
|
62
|
|
63 // BUG: these are redundant with Lexer::uniqueId()
|
|
64 static Identifier generateId(string prefix)
|
|
65 {
|
|
66 static size_t i;
|
|
67 return generateId(prefix, ++i);
|
|
68 }
|
|
69
|
|
70 static Identifier generateId(string prefix, size_t i)
|
|
71 {
|
|
72 scope OutBuffer buf = new OutBuffer();
|
|
73
|
|
74 buf.writestring(prefix);
|
|
75 buf.printf("%d", i); ///<!
|
|
76
|
|
77 string id = buf.extractString();
|
|
78 return Lexer.idPool(id);
|
|
79 }
|
72
|
80 }
|