Scan dynamic libraries for GC roots
[delight/core.git] / dmd2 / identifier.c
blobccd1b80c1e4101f771311e5cf0a83c1f0164718a
2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2006 by Digital Mars
4 // All Rights Reserved
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
17 #include <stdio.h>
18 #include <string.h>
20 #include "root.h"
21 #include "identifier.h"
22 #include "mars.h"
23 #include "lexer.h"
24 #include "id.h"
26 Identifier::Identifier(const char *string, int value)
28 //printf("Identifier('%s', %d)\n", string, value);
29 this->string = string;
30 this->value = value;
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()
56 char *p = NULL;
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";
66 else
67 { p = toChars();
68 if (*p == '_')
70 if (memcmp(p, "_staticCtor", 11) == 0)
71 p = "static this";
72 else if (memcmp(p, "_staticDtor", 11) == 0)
73 p = "static ~this";
77 return p;
80 void Identifier::print()
82 fprintf(stdmsg, "%s",string);
85 int Identifier::dyncast()
87 return DYNCAST_IDENTIFIER;
90 Identifier *Identifier::generateId(char *prefix)
91 { OutBuffer buf;
92 char *id;
93 static unsigned i;
95 buf.writestring(prefix);
96 buf.printf("%u", ++i);
98 id = buf.toChars();
99 buf.data = NULL;
100 return new Identifier(id, TOKidentifier);