2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2006 by Digital Mars
5 // written by Walter Bright
6 // http://www.digitalmars.com
7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt.
9 // See the included readme.txt for details.
11 /* NOTE: This file has been patched from the original DMD distribution to
12 work with the GDC compiler.
14 Modified by David Friedman, May 2005
21 #include "identifier.h"
26 Identifier::Identifier(const char *string
, int value
)
28 //printf("Identifier('%s', %d)\n", string, value);
29 this->string
= string
;
31 this->len
= strlen(string
);
34 hash_t
Identifier::hashCode()
36 return String::calcHash(string
);
39 int Identifier::equals(Object
*o
)
41 return this == o
|| memcmp(string
,o
->toChars(),len
+1) == 0;
44 int Identifier::compare(Object
*o
)
46 return memcmp(string
, o
->toChars(), len
+ 1);
49 char *Identifier::toChars()
51 return (char *)string
;
54 char *Identifier::toHChars2()
58 if (this == Id::ctor
) p
= "this";
59 else if (this == Id::dtor
) p
= "~this";
60 else if (this == Id::classInvariant
) p
= "invariant";
61 else if (this == Id::unitTest
) p
= "unittest";
62 else if (this == Id::dollar
) p
= "$";
63 else if (this == Id::withSym
) p
= "with";
64 else if (this == Id::result
) p
= "result";
65 else if (this == Id::returnLabel
) p
= "return";
70 if (memcmp(p
, "_staticCtor", 11) == 0)
72 else if (memcmp(p
, "_staticDtor", 11) == 0)
80 void Identifier::print()
82 fprintf(stdmsg
, "%s",string
);
85 int Identifier::dyncast()
87 return DYNCAST_IDENTIFIER
;
90 Identifier
*Identifier::generateId(char *prefix
)
95 buf
.writestring(prefix
);
96 buf
.printf("%u", ++i
);
100 return new Identifier(id
, TOKidentifier
);