comparison dmd/Identifier.d @ 0:10317f0c89a5

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