Mercurial > projects > ldc
comparison dmd/mtype.c @ 1228:79758fd2f48a
Added Doxygen file.
Completely seperated type and symbol generation. Should fix a lot of bugs, but is not yet 100% complete.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail.com> |
---|---|
date | Wed, 15 Apr 2009 20:06:25 +0200 |
parents | e961851fb8be |
children | 465a77c904d4 |
comparison
equal
deleted
inserted
replaced
1215:08f87d8cd101 | 1228:79758fd2f48a |
---|---|
348 | 348 |
349 /******************************** | 349 /******************************** |
350 * Name mangling. | 350 * Name mangling. |
351 */ | 351 */ |
352 | 352 |
353 void Type::toDecoBuffer(OutBuffer *buf) | 353 void Type::toDecoBuffer(OutBuffer *buf, bool mangle) |
354 { | 354 { |
355 buf->writeByte(mangleChar[ty]); | 355 buf->writeByte(mangleChar[ty]); |
356 if (next) | 356 if (next) |
357 { | 357 { |
358 assert(next != this); | 358 assert(next != this); |
359 //printf("this = %p, ty = %d, next = %p, ty = %d\n", this, this->ty, next, next->ty); | 359 //printf("this = %p, ty = %d, next = %p, ty = %d\n", this, this->ty, next, next->ty); |
360 next->toDecoBuffer(buf); | 360 next->toDecoBuffer(buf, mangle); |
361 } | 361 } |
362 } | 362 } |
363 | 363 |
364 /******************************** | 364 /******************************** |
365 * For pretty-printing a type. | 365 * For pretty-printing a type. |
432 OutBuffer buf; | 432 OutBuffer buf; |
433 StringValue *sv; | 433 StringValue *sv; |
434 | 434 |
435 if (next) | 435 if (next) |
436 next = next->merge(); | 436 next = next->merge(); |
437 toDecoBuffer(&buf); | 437 toDecoBuffer(&buf, false); |
438 sv = stringtable.update((char *)buf.data, buf.offset); | 438 sv = stringtable.update((char *)buf.data, buf.offset); |
439 if (sv->ptrvalue) | 439 if (sv->ptrvalue) |
440 { t = (Type *) sv->ptrvalue; | 440 { t = (Type *) sv->ptrvalue; |
441 assert(t->deco); | 441 assert(t->deco); |
442 //printf("old value, deco = '%s' %p\n", t->deco, t->deco); | 442 //printf("old value, deco = '%s' %p\n", t->deco, t->deco); |
443 } | 443 } |
444 else | 444 else |
445 { | 445 { |
446 sv->ptrvalue = this; | 446 sv->ptrvalue = this; |
447 deco = sv->lstring.string; | 447 |
448 OutBuffer mangle; | |
449 toDecoBuffer(&mangle, true); | |
450 mangle.writeByte(0); | |
451 deco = mem.strdup((char *)mangle.data); | |
448 //printf("new value, deco = '%s' %p\n", t->deco, t->deco); | 452 //printf("new value, deco = '%s' %p\n", t->deco, t->deco); |
449 } | 453 } |
450 } | 454 } |
451 return t; | 455 return t; |
452 } | 456 } |
741 { buf.writeByte(mangleChar[ty]); | 745 { buf.writeByte(mangleChar[ty]); |
742 if (ty == Tarray) | 746 if (ty == Tarray) |
743 buf.writeByte(mangleChar[((TypeArray *)this)->next->ty]); | 747 buf.writeByte(mangleChar[((TypeArray *)this)->next->ty]); |
744 } | 748 } |
745 else | 749 else |
746 toDecoBuffer(&buf); | 750 toDecoBuffer(&buf, true); |
747 len = buf.offset; | 751 len = buf.offset; |
748 name = (char *)alloca(19 + sizeof(len) * 3 + len + 1); | 752 name = (char *)alloca(19 + sizeof(len) * 3 + len + 1); |
749 buf.writeByte(0); | 753 buf.writeByte(0); |
750 sprintf(name, "_D%dTypeInfo_%s6__initZ", 9 + len, buf.data); | 754 sprintf(name, "_D%dTypeInfo_%s6__initZ", 9 + len, buf.data); |
751 // LDC | 755 // LDC |
1931 if (tbn->isauto()) | 1935 if (tbn->isauto()) |
1932 error(loc, "cannot have array of auto %s", tbn->toChars()); | 1936 error(loc, "cannot have array of auto %s", tbn->toChars()); |
1933 return merge(); | 1937 return merge(); |
1934 } | 1938 } |
1935 | 1939 |
1936 void TypeSArray::toDecoBuffer(OutBuffer *buf) | 1940 void TypeSArray::toDecoBuffer(OutBuffer *buf, bool mangle) |
1937 { | 1941 { |
1938 buf->writeByte(mangleChar[ty]); | 1942 buf->writeByte(mangleChar[ty]); |
1939 if (dim) | 1943 if (dim) |
1940 buf->printf("%ju", dim->toInteger()); | 1944 buf->printf("%ju", dim->toInteger()); |
1941 if (next) | 1945 if (next) |
1942 next->toDecoBuffer(buf); | 1946 next->toDecoBuffer(buf, mangle); |
1943 } | 1947 } |
1944 | 1948 |
1945 void TypeSArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | 1949 void TypeSArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) |
1946 { | 1950 { |
1947 if (mod != this->mod) | 1951 if (mod != this->mod) |
2097 //deco = NULL; // redo | 2101 //deco = NULL; // redo |
2098 return tn->arrayOf(); | 2102 return tn->arrayOf(); |
2099 return merge(); | 2103 return merge(); |
2100 } | 2104 } |
2101 | 2105 |
2102 void TypeDArray::toDecoBuffer(OutBuffer *buf) | 2106 void TypeDArray::toDecoBuffer(OutBuffer *buf, bool mangle) |
2103 { | 2107 { |
2104 buf->writeByte(mangleChar[ty]); | 2108 buf->writeByte(mangleChar[ty]); |
2105 if (next) | 2109 if (next) |
2106 next->toDecoBuffer(buf); | 2110 next->toDecoBuffer(buf, mangle); |
2107 } | 2111 } |
2108 | 2112 |
2109 void TypeDArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | 2113 void TypeDArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) |
2110 { | 2114 { |
2111 if (mod != this->mod) | 2115 if (mod != this->mod) |
2423 e = Type::dotExp(sc, e, ident); | 2427 e = Type::dotExp(sc, e, ident); |
2424 } | 2428 } |
2425 return e; | 2429 return e; |
2426 } | 2430 } |
2427 | 2431 |
2428 void TypeAArray::toDecoBuffer(OutBuffer *buf) | 2432 void TypeAArray::toDecoBuffer(OutBuffer *buf, bool mangle) |
2429 { | 2433 { |
2430 buf->writeByte(mangleChar[ty]); | 2434 buf->writeByte(mangleChar[ty]); |
2431 index->toDecoBuffer(buf); | 2435 index->toDecoBuffer(buf, mangle); |
2432 next->toDecoBuffer(buf); | 2436 next->toDecoBuffer(buf, mangle); |
2433 } | 2437 } |
2434 | 2438 |
2435 void TypeAArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | 2439 void TypeAArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) |
2436 { | 2440 { |
2437 if (mod != this->mod) | 2441 if (mod != this->mod) |
2649 // assert(treturn); | 2653 // assert(treturn); |
2650 this->parameters = parameters; | 2654 this->parameters = parameters; |
2651 this->varargs = varargs; | 2655 this->varargs = varargs; |
2652 this->linkage = linkage; | 2656 this->linkage = linkage; |
2653 this->inuse = 0; | 2657 this->inuse = 0; |
2658 | |
2659 #if IN_LLVM | |
2660 this->funcdecl = NULL; | |
2661 #endif | |
2654 } | 2662 } |
2655 | 2663 |
2656 Type *TypeFunction::syntaxCopy() | 2664 Type *TypeFunction::syntaxCopy() |
2657 { | 2665 { |
2658 Type *treturn = next ? next->syntaxCopy() : NULL; | 2666 Type *treturn = next ? next->syntaxCopy() : NULL; |
2748 Lnotcovariant: | 2756 Lnotcovariant: |
2749 //printf("\tcovaraint: 2\n"); | 2757 //printf("\tcovaraint: 2\n"); |
2750 return 2; | 2758 return 2; |
2751 } | 2759 } |
2752 | 2760 |
2753 void TypeFunction::toDecoBuffer(OutBuffer *buf) | 2761 void TypeFunction::toDecoBuffer(OutBuffer *buf, bool mangle) |
2754 { unsigned char mc; | 2762 { unsigned char mc; |
2755 | 2763 |
2756 //printf("TypeFunction::toDecoBuffer() this = %p %s\n", this, toChars()); | 2764 //printf("TypeFunction::toDecoBuffer() this = %p %s\n", this, toChars()); |
2757 //static int nest; if (++nest == 50) *(char*)0=0; | 2765 //static int nest; if (++nest == 50) *(char*)0=0; |
2758 if (inuse) | 2766 if (inuse) |
2773 | 2781 |
2774 default: | 2782 default: |
2775 assert(0); | 2783 assert(0); |
2776 } | 2784 } |
2777 buf->writeByte(mc); | 2785 buf->writeByte(mc); |
2786 | |
2787 // LDC: if we're not producing a mangle string, add the this | |
2788 // type to prevent merging different member function | |
2789 if (!mangle && funcdecl) | |
2790 { | |
2791 if (AggregateDeclaration* ad = funcdecl->isMember()) | |
2792 { | |
2793 buf->writeByte('M'); | |
2794 ad->type->toDecoBuffer(buf, false); | |
2795 } | |
2796 } | |
2797 | |
2778 // Write argument types | 2798 // Write argument types |
2779 Argument::argsToDecoBuffer(buf, parameters); | 2799 Argument::argsToDecoBuffer(buf, parameters, mangle); |
2780 //if (buf->data[buf->offset - 1] == '@') halt(); | 2800 //if (buf->data[buf->offset - 1] == '@') halt(); |
2781 buf->writeByte('Z' - varargs); // mark end of arg list | 2801 buf->writeByte('Z' - varargs); // mark end of arg list |
2782 next->toDecoBuffer(buf); | 2802 next->toDecoBuffer(buf, mangle); |
2783 inuse--; | 2803 inuse--; |
2784 } | 2804 } |
2785 | 2805 |
2786 void TypeFunction::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) | 2806 void TypeFunction::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) |
2787 { | 2807 { |
3459 t = new TypeIdentifier(loc, ident); | 3479 t = new TypeIdentifier(loc, ident); |
3460 t->syntaxCopyHelper(this); | 3480 t->syntaxCopyHelper(this); |
3461 return t; | 3481 return t; |
3462 } | 3482 } |
3463 | 3483 |
3464 void TypeIdentifier::toDecoBuffer(OutBuffer *buf) | 3484 void TypeIdentifier::toDecoBuffer(OutBuffer *buf, bool mangle) |
3465 { unsigned len; | 3485 { unsigned len; |
3466 char *name; | 3486 char *name; |
3467 | 3487 |
3468 name = ident->toChars(); | 3488 name = ident->toChars(); |
3469 len = strlen(name); | 3489 len = strlen(name); |
3913 return tint32; | 3933 return tint32; |
3914 } | 3934 } |
3915 return sym->memtype->toBasetype(); | 3935 return sym->memtype->toBasetype(); |
3916 } | 3936 } |
3917 | 3937 |
3918 void TypeEnum::toDecoBuffer(OutBuffer *buf) | 3938 void TypeEnum::toDecoBuffer(OutBuffer *buf, bool mangle) |
3919 { char *name; | 3939 { char *name; |
3920 | 3940 |
3921 name = sym->mangle(); | 3941 name = sym->mangle(); |
3922 // if (name[0] == '_' && name[1] == 'D') | 3942 // if (name[0] == '_' && name[1] == 'D') |
3923 // name += 2; | 3943 // name += 2; |
4101 Dsymbol *TypeTypedef::toDsymbol(Scope *sc) | 4121 Dsymbol *TypeTypedef::toDsymbol(Scope *sc) |
4102 { | 4122 { |
4103 return sym; | 4123 return sym; |
4104 } | 4124 } |
4105 | 4125 |
4106 void TypeTypedef::toDecoBuffer(OutBuffer *buf) | 4126 void TypeTypedef::toDecoBuffer(OutBuffer *buf, bool mangle) |
4107 { unsigned len; | 4127 { unsigned len; |
4108 char *name; | 4128 char *name; |
4109 | 4129 |
4110 name = sym->mangle(); | 4130 name = sym->mangle(); |
4111 // if (name[0] == '_' && name[1] == 'D') | 4131 // if (name[0] == '_' && name[1] == 'D') |
4326 Dsymbol *TypeStruct::toDsymbol(Scope *sc) | 4346 Dsymbol *TypeStruct::toDsymbol(Scope *sc) |
4327 { | 4347 { |
4328 return sym; | 4348 return sym; |
4329 } | 4349 } |
4330 | 4350 |
4331 void TypeStruct::toDecoBuffer(OutBuffer *buf) | 4351 void TypeStruct::toDecoBuffer(OutBuffer *buf, bool mangle) |
4332 { unsigned len; | 4352 { unsigned len; |
4333 char *name; | 4353 char *name; |
4334 | 4354 |
4335 name = sym->mangle(); | 4355 name = sym->mangle(); |
4336 //printf("TypeStruct::toDecoBuffer('%s') = '%s'\n", toChars(), name); | 4356 //printf("TypeStruct::toDecoBuffer('%s') = '%s'\n", toChars(), name); |
4619 Dsymbol *TypeClass::toDsymbol(Scope *sc) | 4639 Dsymbol *TypeClass::toDsymbol(Scope *sc) |
4620 { | 4640 { |
4621 return sym; | 4641 return sym; |
4622 } | 4642 } |
4623 | 4643 |
4624 void TypeClass::toDecoBuffer(OutBuffer *buf) | 4644 void TypeClass::toDecoBuffer(OutBuffer *buf, bool mangle) |
4625 { unsigned len; | 4645 { unsigned len; |
4626 char *name; | 4646 char *name; |
4627 | 4647 |
4628 name = sym->mangle(); | 4648 name = sym->mangle(); |
4629 // if (name[0] == '_' && name[1] == 'D') | 4649 // if (name[0] == '_' && name[1] == 'D') |
5141 void TypeTuple::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | 5161 void TypeTuple::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) |
5142 { | 5162 { |
5143 Argument::argsToCBuffer(buf, hgs, arguments, 0); | 5163 Argument::argsToCBuffer(buf, hgs, arguments, 0); |
5144 } | 5164 } |
5145 | 5165 |
5146 void TypeTuple::toDecoBuffer(OutBuffer *buf) | 5166 void TypeTuple::toDecoBuffer(OutBuffer *buf, bool mangle) |
5147 { | 5167 { |
5148 //printf("TypeTuple::toDecoBuffer() this = %p\n", this); | 5168 //printf("TypeTuple::toDecoBuffer() this = %p\n", this); |
5149 OutBuffer buf2; | 5169 OutBuffer buf2; |
5150 Argument::argsToDecoBuffer(&buf2, arguments); | 5170 Argument::argsToDecoBuffer(&buf2, arguments, mangle); |
5151 unsigned len = buf2.offset; | 5171 unsigned len = buf2.offset; |
5152 buf->printf("%c%d%.*s", mangleChar[ty], len, len, (char *)buf2.extractData()); | 5172 buf->printf("%c%d%.*s", mangleChar[ty], len, len, (char *)buf2.extractData()); |
5153 } | 5173 } |
5154 | 5174 |
5155 Expression *TypeTuple::getProperty(Loc loc, Identifier *ident) | 5175 Expression *TypeTuple::getProperty(Loc loc, Identifier *ident) |
5407 } | 5427 } |
5408 buf->writeByte(')'); | 5428 buf->writeByte(')'); |
5409 } | 5429 } |
5410 | 5430 |
5411 | 5431 |
5412 void Argument::argsToDecoBuffer(OutBuffer *buf, Arguments *arguments) | 5432 void Argument::argsToDecoBuffer(OutBuffer *buf, Arguments *arguments, bool mangle) |
5413 { | 5433 { |
5414 //printf("Argument::argsToDecoBuffer()\n"); | 5434 //printf("Argument::argsToDecoBuffer()\n"); |
5415 | 5435 |
5416 // Write argument types | 5436 // Write argument types |
5417 if (arguments) | 5437 if (arguments) |
5418 { | 5438 { |
5419 size_t dim = Argument::dim(arguments); | 5439 size_t dim = Argument::dim(arguments); |
5420 for (size_t i = 0; i < dim; i++) | 5440 for (size_t i = 0; i < dim; i++) |
5421 { | 5441 { |
5422 Argument *arg = Argument::getNth(arguments, i); | 5442 Argument *arg = Argument::getNth(arguments, i); |
5423 arg->toDecoBuffer(buf); | 5443 arg->toDecoBuffer(buf, mangle); |
5424 } | 5444 } |
5425 } | 5445 } |
5426 } | 5446 } |
5427 | 5447 |
5428 /**************************************************** | 5448 /**************************************************** |
5452 } | 5472 } |
5453 } | 5473 } |
5454 return NULL; | 5474 return NULL; |
5455 } | 5475 } |
5456 | 5476 |
5457 void Argument::toDecoBuffer(OutBuffer *buf) | 5477 void Argument::toDecoBuffer(OutBuffer *buf, bool mangle) |
5458 { | 5478 { |
5459 switch (storageClass & (STCin | STCout | STCref | STClazy)) | 5479 switch (storageClass & (STCin | STCout | STCref | STClazy)) |
5460 { case 0: | 5480 { case 0: |
5461 case STCin: | 5481 case STCin: |
5462 break; | 5482 break; |
5473 #ifdef DEBUG | 5493 #ifdef DEBUG |
5474 halt(); | 5494 halt(); |
5475 #endif | 5495 #endif |
5476 assert(0); | 5496 assert(0); |
5477 } | 5497 } |
5478 type->toDecoBuffer(buf); | 5498 type->toDecoBuffer(buf, mangle); |
5479 } | 5499 } |
5480 | 5500 |
5481 /*************************************** | 5501 /*************************************** |
5482 * Determine number of arguments, folding in tuples. | 5502 * Determine number of arguments, folding in tuples. |
5483 */ | 5503 */ |