Mercurial > projects > ldc
comparison dmd2/declaration.c @ 1526:54b3c1394d62
Merged dmdfe 2.031.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Tue, 07 Jul 2009 02:26:11 +0100 |
parents | f62347c22d81 |
children | e4f7b5d9c68a |
comparison
equal
deleted
inserted
replaced
1525:d28cd7c45267 | 1526:54b3c1394d62 |
---|---|
461 */ | 461 */ |
462 s = type->toDsymbol(sc); | 462 s = type->toDsymbol(sc); |
463 if (s && ((s->getType() && type->equals(s->getType())) || s->isEnumMember())) | 463 if (s && ((s->getType() && type->equals(s->getType())) || s->isEnumMember())) |
464 goto L2; // it's a symbolic alias | 464 goto L2; // it's a symbolic alias |
465 | 465 |
466 #if DMDV2 | |
466 if (storage_class & STCref) | 467 if (storage_class & STCref) |
467 { // For 'ref' to be attached to function types, and picked | 468 { // For 'ref' to be attached to function types, and picked |
468 // up by Type::resolve(), it has to go into sc. | 469 // up by Type::resolve(), it has to go into sc. |
469 sc = sc->push(); | 470 sc = sc->push(); |
470 sc->stc |= STCref; | 471 sc->stc |= STCref; |
471 type->resolve(loc, sc, &e, &t, &s); | 472 type->resolve(loc, sc, &e, &t, &s); |
472 sc = sc->pop(); | 473 sc = sc->pop(); |
473 } | 474 } |
474 else | 475 else |
476 #endif | |
475 type->resolve(loc, sc, &e, &t, &s); | 477 type->resolve(loc, sc, &e, &t, &s); |
476 if (s) | 478 if (s) |
477 { | 479 { |
478 goto L2; | 480 goto L2; |
479 } | 481 } |
486 | 488 |
487 error("cannot alias an expression %s", e->toChars()); | 489 error("cannot alias an expression %s", e->toChars()); |
488 t = e->type; | 490 t = e->type; |
489 } | 491 } |
490 else if (t) | 492 else if (t) |
493 { | |
491 type = t; | 494 type = t; |
495 } | |
492 if (overnext) | 496 if (overnext) |
493 ScopeDsymbol::multiplyDefined(0, this, overnext); | 497 ScopeDsymbol::multiplyDefined(0, this, overnext); |
494 this->inSemantic = 0; | 498 this->inSemantic = 0; |
495 return; | 499 return; |
496 | 500 |
509 if (f) | 513 if (f) |
510 { | 514 { |
511 if (overnext) | 515 if (overnext) |
512 { | 516 { |
513 FuncAliasDeclaration *fa = new FuncAliasDeclaration(f); | 517 FuncAliasDeclaration *fa = new FuncAliasDeclaration(f); |
518 #if IN_LLVM | |
514 fa->importprot = importprot; | 519 fa->importprot = importprot; |
520 #endif | |
515 if (!fa->overloadInsert(overnext)) | 521 if (!fa->overloadInsert(overnext)) |
516 ScopeDsymbol::multiplyDefined(0, f, overnext); | 522 ScopeDsymbol::multiplyDefined(0, f, overnext); |
517 overnext = NULL; | 523 overnext = NULL; |
518 s = fa; | 524 s = fa; |
519 s->parent = sc->parent; | 525 s->parent = sc->parent; |
525 { | 531 { |
526 assert(global.errors); | 532 assert(global.errors); |
527 s = NULL; | 533 s = NULL; |
528 } | 534 } |
529 } | 535 } |
536 //printf("setting aliassym %p to %p\n", this, s); | |
530 aliassym = s; | 537 aliassym = s; |
531 this->inSemantic = 0; | 538 this->inSemantic = 0; |
532 } | 539 } |
533 | 540 |
534 int AliasDeclaration::overloadInsert(Dsymbol *s) | 541 int AliasDeclaration::overloadInsert(Dsymbol *s) |
622 this->hinit = NULL; | 629 this->hinit = NULL; |
623 #endif | 630 #endif |
624 this->loc = loc; | 631 this->loc = loc; |
625 offset = 0; | 632 offset = 0; |
626 noauto = 0; | 633 noauto = 0; |
634 #if DMDV1 | |
635 nestedref = 0; | |
636 #endif | |
627 ctorinit = 0; | 637 ctorinit = 0; |
628 aliassym = NULL; | 638 aliassym = NULL; |
629 onstack = 0; | 639 onstack = 0; |
630 canassign = 0; | 640 canassign = 0; |
631 value = NULL; | 641 value = NULL; |
632 scope = NULL; | |
633 #if IN_LLVM | 642 #if IN_LLVM |
634 aggrIndex = 0; | 643 aggrIndex = 0; |
635 | 644 |
636 // LDC | 645 // LDC |
637 anonDecl = NULL; | 646 anonDecl = NULL; |
728 //printf("this = %p, parent = %p, '%s'\n", this, parent, parent->toChars()); | 737 //printf("this = %p, parent = %p, '%s'\n", this, parent, parent->toChars()); |
729 protection = sc->protection; | 738 protection = sc->protection; |
730 //printf("sc->stc = %x\n", sc->stc); | 739 //printf("sc->stc = %x\n", sc->stc); |
731 //printf("storage_class = x%x\n", storage_class); | 740 //printf("storage_class = x%x\n", storage_class); |
732 | 741 |
742 #if DMDV2 | |
733 if (storage_class & STCgshared && global.params.safe && !sc->module->safe) | 743 if (storage_class & STCgshared && global.params.safe && !sc->module->safe) |
734 { | 744 { |
735 error("__gshared not allowed in safe mode; use shared"); | 745 error("__gshared not allowed in safe mode; use shared"); |
736 } | 746 } |
747 #endif | |
737 | 748 |
738 Dsymbol *parent = toParent(); | 749 Dsymbol *parent = toParent(); |
739 FuncDeclaration *fd = parent->isFuncDeclaration(); | 750 FuncDeclaration *fd = parent->isFuncDeclaration(); |
740 | 751 |
741 Type *tb = type->toBasetype(); | 752 Type *tb = type->toBasetype(); |
849 { | 860 { |
850 AggregateDeclaration *aad = sc->anonAgg; | 861 AggregateDeclaration *aad = sc->anonAgg; |
851 if (!aad) | 862 if (!aad) |
852 aad = parent->isAggregateDeclaration(); | 863 aad = parent->isAggregateDeclaration(); |
853 if (aad) | 864 if (aad) |
854 { assert(!(storage_class & (STCextern | STCstatic | STCtls | STCgshared))); | 865 { |
866 #if DMDV2 | |
867 assert(!(storage_class & (STCextern | STCstatic | STCtls | STCgshared))); | |
855 | 868 |
856 if (storage_class & (STCconst | STCimmutable) && init) | 869 if (storage_class & (STCconst | STCimmutable) && init) |
857 { | 870 { |
858 if (!type->toBasetype()->isTypeBasic()) | 871 if (!type->toBasetype()->isTypeBasic()) |
859 storage_class |= STCstatic; | 872 storage_class |= STCstatic; |
860 } | 873 } |
861 else | 874 else |
875 #endif | |
862 aad->addField(sc, this); | 876 aad->addField(sc, this); |
863 } | 877 } |
864 | 878 |
865 InterfaceDeclaration *id = parent->isInterfaceDeclaration(); | 879 InterfaceDeclaration *id = parent->isInterfaceDeclaration(); |
866 if (id) | 880 if (id) |
889 error("cannot use template to add field to aggregate '%s'", ad->toChars()); | 903 error("cannot use template to add field to aggregate '%s'", ad->toChars()); |
890 } | 904 } |
891 } | 905 } |
892 } | 906 } |
893 | 907 |
908 #if DMDV2 | |
894 if ((storage_class & (STCref | STCparameter | STCforeach)) == STCref && | 909 if ((storage_class & (STCref | STCparameter | STCforeach)) == STCref && |
895 ident != Id::This) | 910 ident != Id::This) |
896 { | 911 { |
897 error("only parameters or foreach declarations can be ref"); | 912 error("only parameters or foreach declarations can be ref"); |
898 } | 913 } |
914 #endif | |
899 | 915 |
900 if (type->isauto() && !noauto) | 916 if (type->isauto() && !noauto) |
901 { | 917 { |
902 if (storage_class & (STCfield | STCout | STCref | STCstatic | STCmanifest | STCtls | STCgshared) || !fd) | 918 if (storage_class & (STCfield | STCout | STCref | STCstatic | STCmanifest | STCtls | STCgshared) || !fd) |
903 { | 919 { |
938 */ | 954 */ |
939 Expression *e = new IntegerExp(loc, 0, Type::tint32); | 955 Expression *e = new IntegerExp(loc, 0, Type::tint32); |
940 Expression *e1; | 956 Expression *e1; |
941 e1 = new VarExp(loc, this); | 957 e1 = new VarExp(loc, this); |
942 e = new AssignExp(loc, e1, e); | 958 e = new AssignExp(loc, e1, e); |
959 #if DMDV2 | |
943 e->op = TOKconstruct; | 960 e->op = TOKconstruct; |
961 #endif | |
944 e->type = e1->type; // don't type check this, it would fail | 962 e->type = e1->type; // don't type check this, it would fail |
945 init = new ExpInitializer(loc, e); | 963 init = new ExpInitializer(loc, e); |
946 return; | 964 return; |
947 } | 965 } |
948 else if (type->ty == Ttypedef) | 966 else if (type->ty == Ttypedef) |
959 } | 977 } |
960 else | 978 else |
961 { | 979 { |
962 init = getExpInitializer(); | 980 init = getExpInitializer(); |
963 } | 981 } |
982 #if DMDV2 | |
964 // Default initializer is always a blit | 983 // Default initializer is always a blit |
965 op = TOKblit; | 984 op = TOKblit; |
985 #endif | |
966 } | 986 } |
967 | 987 |
968 if (init) | 988 if (init) |
969 { | 989 { |
970 sc = sc->push(); | 990 sc = sc->push(); |
1038 e1 = new SliceExp(loc, e1, NULL, NULL); | 1058 e1 = new SliceExp(loc, e1, NULL, NULL); |
1039 } | 1059 } |
1040 else if (t->ty == Tstruct) | 1060 else if (t->ty == Tstruct) |
1041 { | 1061 { |
1042 ei->exp = ei->exp->semantic(sc); | 1062 ei->exp = ei->exp->semantic(sc); |
1043 | 1063 #if DMDV2 |
1044 /* Look to see if initializer is a call to the constructor | 1064 /* Look to see if initializer is a call to the constructor |
1045 */ | 1065 */ |
1046 StructDeclaration *sd = ((TypeStruct *)t)->sym; | 1066 StructDeclaration *sd = ((TypeStruct *)t)->sym; |
1047 if (sd->ctor && // there are constructors | 1067 if (sd->ctor && // there are constructors |
1048 ei->exp->type->ty == Tstruct && // rvalue is the same struct | 1068 ei->exp->type->ty == Tstruct && // rvalue is the same struct |
1076 return; | 1096 return; |
1077 } | 1097 } |
1078 } | 1098 } |
1079 } | 1099 } |
1080 } | 1100 } |
1081 | 1101 #endif |
1082 if (!ei->exp->implicitConvTo(type)) | 1102 if (!ei->exp->implicitConvTo(type)) |
1083 { Type *ti = ei->exp->type->toBasetype(); | 1103 { Type *ti = ei->exp->type->toBasetype(); |
1084 // Don't cast away invariant or mutability in initializer | 1104 // Don't cast away invariant or mutability in initializer |
1085 if (!(ti->ty == Tstruct && t->toDsymbol(sc) == ti->toDsymbol(sc))) | 1105 if (!(ti->ty == Tstruct && t->toDsymbol(sc) == ti->toDsymbol(sc))) |
1086 ei->exp = new CastExp(loc, ei->exp, type); | 1106 ei->exp = new CastExp(loc, ei->exp, type); |
1130 //printf("-gag\n"); | 1150 //printf("-gag\n"); |
1131 if (errors != global.errors) // if errors happened | 1151 if (errors != global.errors) // if errors happened |
1132 { | 1152 { |
1133 if (global.gag == 0) | 1153 if (global.gag == 0) |
1134 global.errors = errors; // act as if nothing happened | 1154 global.errors = errors; // act as if nothing happened |
1135 | 1155 #if DMDV2 |
1136 /* Save scope for later use, to try again | 1156 /* Save scope for later use, to try again |
1137 */ | 1157 */ |
1138 scope = new Scope(*sc); | 1158 scope = new Scope(*sc); |
1139 scope->setNoFree(); | 1159 scope->setNoFree(); |
1160 #endif | |
1140 } | 1161 } |
1141 else if (ei) | 1162 else if (ei) |
1142 { | 1163 { |
1143 if (isDataseg()) | 1164 if (isDataseg()) |
1144 /* static const/invariant does CTFE | 1165 /* static const/invariant does CTFE |
1148 e = e->optimize(WANTvalue); | 1169 e = e->optimize(WANTvalue); |
1149 if (e->op == TOKint64 || e->op == TOKstring) | 1170 if (e->op == TOKint64 || e->op == TOKstring) |
1150 { | 1171 { |
1151 ei->exp = e; // no errors, keep result | 1172 ei->exp = e; // no errors, keep result |
1152 } | 1173 } |
1174 #if DMDV2 | |
1153 else | 1175 else |
1154 { | 1176 { |
1155 /* Save scope for later use, to try again | 1177 /* Save scope for later use, to try again |
1156 */ | 1178 */ |
1157 scope = new Scope(*sc); | 1179 scope = new Scope(*sc); |
1158 scope->setNoFree(); | 1180 scope->setNoFree(); |
1159 } | 1181 } |
1182 #endif | |
1160 } | 1183 } |
1161 else | 1184 else |
1162 init = i2; // no errors, keep result | 1185 init = i2; // no errors, keep result |
1163 } | 1186 } |
1164 } | 1187 } |
1218 type->toCBuffer(buf, ident, hgs); | 1241 type->toCBuffer(buf, ident, hgs); |
1219 else | 1242 else |
1220 buf->writestring(ident->toChars()); | 1243 buf->writestring(ident->toChars()); |
1221 if (init) | 1244 if (init) |
1222 { buf->writestring(" = "); | 1245 { buf->writestring(" = "); |
1246 #if DMDV2 | |
1223 ExpInitializer *ie = init->isExpInitializer(); | 1247 ExpInitializer *ie = init->isExpInitializer(); |
1224 if (ie && (ie->exp->op == TOKconstruct || ie->exp->op == TOKblit)) | 1248 if (ie && (ie->exp->op == TOKconstruct || ie->exp->op == TOKblit)) |
1225 ((AssignExp *)ie->exp)->e2->toCBuffer(buf, hgs); | 1249 ((AssignExp *)ie->exp)->e2->toCBuffer(buf, hgs); |
1226 else | 1250 else |
1251 #endif | |
1227 init->toCBuffer(buf, hgs); | 1252 init->toCBuffer(buf, hgs); |
1228 } | 1253 } |
1229 buf->writeByte(';'); | 1254 buf->writeByte(';'); |
1230 buf->writenl(); | 1255 buf->writenl(); |
1231 } | 1256 } |
1586 } | 1611 } |
1587 | 1612 |
1588 void TypeInfoDeclaration::semantic(Scope *sc) | 1613 void TypeInfoDeclaration::semantic(Scope *sc) |
1589 { | 1614 { |
1590 assert(linkage == LINKc); | 1615 assert(linkage == LINKc); |
1591 // LDC | 1616 #if IN_LLVM |
1592 if (!global.params.useAvailableExternally) | 1617 if (!global.params.useAvailableExternally) |
1593 availableExternally = false; | 1618 availableExternally = false; |
1619 #endif | |
1594 } | 1620 } |
1595 | 1621 |
1596 /***************************** TypeInfoConstDeclaration **********************/ | 1622 /***************************** TypeInfoConstDeclaration **********************/ |
1597 | 1623 |
1598 #if DMDV2 | 1624 #if DMDV2 |