Mercurial > projects > ldc
comparison dmd2/mangle.c @ 1452:638d16625da2
LDC 2 compiles again.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Sat, 30 May 2009 17:23:32 +0100 |
parents | f04dde6e882c |
children | 54b3c1394d62 |
comparison
equal
deleted
inserted
replaced
1423:42bd767ec5a4 | 1452:638d16625da2 |
---|---|
1 | 1 |
2 // Compiler implementation of the D programming language | 2 // Compiler implementation of the D programming language |
3 // Copyright (c) 1999-2007 by Digital Mars | 3 // Copyright (c) 1999-2009 by Digital Mars |
4 // All Rights Reserved | 4 // All Rights Reserved |
5 // written by Walter Bright | 5 // written by Walter Bright |
6 // http://www.digitalmars.com | 6 // http://www.digitalmars.com |
7 // License for redistribution is by either the Artistic License | 7 // License for redistribution is by either the Artistic License |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | 8 // in artistic.txt, or the GNU General Public License in gnu.txt. |
22 #include "attrib.h" | 22 #include "attrib.h" |
23 #include "template.h" | 23 #include "template.h" |
24 #include "id.h" | 24 #include "id.h" |
25 #include "module.h" | 25 #include "module.h" |
26 | 26 |
27 #if TARGET_LINUX | 27 #if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS |
28 char *cpp_mangle(Dsymbol *s); | 28 char *cpp_mangle(Dsymbol *s); |
29 #endif | 29 #endif |
30 | 30 |
31 char *mangle(Declaration *sthis) | 31 char *mangle(Declaration *sthis) |
32 { | 32 { |
71 if (fd && (fd->needThis() || fd->isNested())) | 71 if (fd && (fd->needThis() || fd->isNested())) |
72 buf.writeByte(Type::needThisPrefix()); | 72 buf.writeByte(Type::needThisPrefix()); |
73 if (sthis->type->deco) | 73 if (sthis->type->deco) |
74 buf.writestring(sthis->type->deco); | 74 buf.writestring(sthis->type->deco); |
75 else | 75 else |
76 { assert(fd->inferRetType); | 76 { |
77 #ifdef DEBUG | |
78 if (!fd->inferRetType) | |
79 printf("%s\n", fd->toChars()); | |
80 #endif | |
81 assert(fd->inferRetType); | |
77 } | 82 } |
78 | 83 |
79 id = buf.toChars(); | 84 id = buf.toChars(); |
80 buf.data = NULL; | 85 buf.data = NULL; |
81 return id; | 86 return id; |
115 case LINKwindows: | 120 case LINKwindows: |
116 case LINKpascal: | 121 case LINKpascal: |
117 return ident->toChars(); | 122 return ident->toChars(); |
118 | 123 |
119 case LINKcpp: | 124 case LINKcpp: |
120 #if TARGET_LINUX | 125 #if DMDV2 && (TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS) |
121 return cpp_mangle(this); | 126 return cpp_mangle(this); |
122 #else | 127 #else |
123 // Windows C++ mangling is done by C++ back end | 128 // Windows C++ mangling is done by C++ back end |
124 return ident->toChars(); | 129 return ident->toChars(); |
125 #endif | 130 #endif |
153 #endif | 158 #endif |
154 { | 159 { |
155 if (isMain()) | 160 if (isMain()) |
156 return (char *)"_Dmain"; | 161 return (char *)"_Dmain"; |
157 | 162 |
158 if (isWinMain() || isDllMain()) | 163 if (isWinMain() || isDllMain() || ident == Id::tls_get_addr) |
159 return ident->toChars(); | 164 return ident->toChars(); |
160 | 165 |
161 assert(this); | 166 assert(this); |
162 return Declaration::mangle(); | 167 return Declaration::mangle(); |
163 } | 168 } |
164 | |
165 | 169 |
166 char *StructDeclaration::mangle() | 170 char *StructDeclaration::mangle() |
167 { | 171 { |
168 //printf("StructDeclaration::mangle() '%s'\n", toChars()); | 172 //printf("StructDeclaration::mangle() '%s'\n", toChars()); |
169 return Dsymbol::mangle(); | 173 return Dsymbol::mangle(); |
219 if (parent) | 223 if (parent) |
220 printf(" parent = %s %s", parent->kind(), parent->toChars()); | 224 printf(" parent = %s %s", parent->kind(), parent->toChars()); |
221 printf("\n"); | 225 printf("\n"); |
222 #endif | 226 #endif |
223 id = ident ? ident->toChars() : toChars(); | 227 id = ident ? ident->toChars() : toChars(); |
224 if (tempdecl->parent) | 228 if (!tempdecl) |
229 error("is not defined"); | |
230 else if (tempdecl->parent) | |
225 { | 231 { |
226 char *p = tempdecl->parent->mangle(); | 232 char *p = tempdecl->parent->mangle(); |
227 if (p[0] == '_' && p[1] == 'D') | 233 if (p[0] == '_' && p[1] == 'D') |
228 p += 2; | 234 p += 2; |
229 buf.writestring(p); | 235 buf.writestring(p); |
230 } | 236 } |
231 buf.printf("%"PRIuSIZE"%s", strlen(id), id); | 237 buf.printf("%zu%s", strlen(id), id); |
232 id = buf.toChars(); | 238 id = buf.toChars(); |
233 buf.data = NULL; | 239 buf.data = NULL; |
234 //printf("TemplateInstance::mangle() %s = %s\n", toChars(), id); | 240 //printf("TemplateInstance::mangle() %s = %s\n", toChars(), id); |
235 return id; | 241 return id; |
236 } | 242 } |
237 | 243 |
238 | 244 #if IN_LLVM |
239 char *TemplateMixin::mangle() | 245 char *TemplateMixin::mangle() |
240 { | 246 { |
241 OutBuffer buf; | 247 OutBuffer buf; |
242 char *id; | 248 char *id; |
243 | 249 |
253 char *p = parent->mangle(); | 259 char *p = parent->mangle(); |
254 if (p[0] == '_' && p[1] == 'D') | 260 if (p[0] == '_' && p[1] == 'D') |
255 p += 2; | 261 p += 2; |
256 buf.writestring(p); | 262 buf.writestring(p); |
257 } | 263 } |
258 buf.printf("%"PRIuSIZE"%s", strlen(id), id); | 264 buf.printf("%zu%s", strlen(id), id); |
259 id = buf.toChars(); | 265 id = buf.toChars(); |
260 buf.data = NULL; | 266 buf.data = NULL; |
261 //printf("TemplateMixin::mangle() %s = %s\n", toChars(), id); | 267 //printf("TemplateMixin::mangle() %s = %s\n", toChars(), id); |
262 return id; | 268 return id; |
263 } | 269 } |
270 #endif | |
264 | 271 |
265 char *Dsymbol::mangle() | 272 char *Dsymbol::mangle() |
266 { | 273 { |
267 OutBuffer buf; | 274 OutBuffer buf; |
268 char *id; | 275 char *id; |
279 char *p = parent->mangle(); | 286 char *p = parent->mangle(); |
280 if (p[0] == '_' && p[1] == 'D') | 287 if (p[0] == '_' && p[1] == 'D') |
281 p += 2; | 288 p += 2; |
282 buf.writestring(p); | 289 buf.writestring(p); |
283 } | 290 } |
284 buf.printf("%"PRIuSIZE"%s", strlen(id), id); | 291 buf.printf("%zu%s", strlen(id), id); |
285 id = buf.toChars(); | 292 id = buf.toChars(); |
286 buf.data = NULL; | 293 buf.data = NULL; |
287 //printf("Dsymbol::mangle() %s = %s\n", toChars(), id); | 294 //printf("Dsymbol::mangle() %s = %s\n", toChars(), id); |
288 return id; | 295 return id; |
289 } | 296 } |