Mercurial > projects > ldc
annotate dmd/identifier.c @ 1650:40bd4a0d4870
Update to work with LLVM 2.7.
Removed use of dyn_cast, llvm no compiles
without exceptions and rtti by
default. We do need exceptions for the libconfig stuff, but rtti isn't
necessary (anymore).
Debug info needs to be rewritten, as in LLVM 2.7 the format has
completely changed. To have something to look at while rewriting, the
old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means
that you have to define this to compile at the moment.
Updated tango 0.99.9 patch to include updated EH runtime code, which is
needed for LLVM 2.7 as well.
author | Tomas Lindquist Olsen |
---|---|
date | Wed, 19 May 2010 12:42:32 +0200 |
parents | e961851fb8be |
children |
rev | line source |
---|---|
1 | 1 |
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. | |
10 | |
11 #include <stdio.h> | |
12 #include <string.h> | |
13 | |
14 #include "root.h" | |
15 #include "identifier.h" | |
16 #include "mars.h" | |
17 #include "lexer.h" | |
18 #include "id.h" | |
19 | |
20 Identifier::Identifier(const char *string, int value) | |
21 { | |
22 //printf("Identifier('%s', %d)\n", string, value); | |
23 this->string = string; | |
24 this->value = value; | |
25 this->len = strlen(string); | |
26 } | |
27 | |
28 hash_t Identifier::hashCode() | |
29 { | |
30 return String::calcHash(string); | |
31 } | |
32 | |
33 int Identifier::equals(Object *o) | |
34 { | |
35 return this == o || memcmp(string,o->toChars(),len+1) == 0; | |
36 } | |
37 | |
38 int Identifier::compare(Object *o) | |
39 { | |
40 return memcmp(string, o->toChars(), len + 1); | |
41 } | |
42 | |
43 char *Identifier::toChars() | |
44 { | |
45 return (char *)string; | |
46 } | |
47 | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
48 const char *Identifier::toHChars2() |
1 | 49 { |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
50 const char *p = NULL; |
1 | 51 |
52 if (this == Id::ctor) p = "this"; | |
53 else if (this == Id::dtor) p = "~this"; | |
54 else if (this == Id::classInvariant) p = "invariant"; | |
55 else if (this == Id::unitTest) p = "unittest"; | |
56 else if (this == Id::dollar) p = "$"; | |
57 else if (this == Id::withSym) p = "with"; | |
58 else if (this == Id::result) p = "result"; | |
59 else if (this == Id::returnLabel) p = "return"; | |
60 else | |
19 | 61 { p = toChars(); |
62 if (*p == '_') | |
63 { | |
64 if (memcmp(p, "_staticCtor", 11) == 0) | |
65 p = "static this"; | |
66 else if (memcmp(p, "_staticDtor", 11) == 0) | |
67 p = "static ~this"; | |
68 } | |
69 } | |
1 | 70 |
71 return p; | |
72 } | |
73 | |
74 void Identifier::print() | |
75 { | |
76 fprintf(stdmsg, "%s",string); | |
77 } | |
78 | |
79 int Identifier::dyncast() | |
80 { | |
81 return DYNCAST_IDENTIFIER; | |
82 } | |
83 | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
19
diff
changeset
|
84 |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
19
diff
changeset
|
85 Identifier *Identifier::generateId(const char *prefix) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
19
diff
changeset
|
86 { |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
19
diff
changeset
|
87 static size_t i; |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
19
diff
changeset
|
88 |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
19
diff
changeset
|
89 return generateId(prefix, ++i); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
19
diff
changeset
|
90 } |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
19
diff
changeset
|
91 |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
19
diff
changeset
|
92 Identifier *Identifier::generateId(const char *prefix, size_t i) |
1 | 93 { OutBuffer buf; |
94 | |
95 buf.writestring(prefix); | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
817
diff
changeset
|
96 buf.printf("%zu", i); |
1 | 97 |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
19
diff
changeset
|
98 char *id = buf.toChars(); |
1 | 99 buf.data = NULL; |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
19
diff
changeset
|
100 return Lexer::idPool(id); |
1 | 101 } |