comparison dmd2/func.c @ 847:356e65836fb5

Merged DMD 2.021 frontend. Removed generated files from dmd/dmd2 dirs.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sat, 13 Dec 2008 16:14:37 +0100
parents f04dde6e882c
children 063ba84a965f
comparison
equal deleted inserted replaced
846:bc982f1ad106 847:356e65836fb5
683 assert(!isNested()); // can't be both member and nested 683 assert(!isNested()); // can't be both member and nested
684 assert(ad->handle); 684 assert(ad->handle);
685 Type *thandle = ad->handle; 685 Type *thandle = ad->handle;
686 if (storage_class & STCconst || type->isConst()) 686 if (storage_class & STCconst || type->isConst())
687 { 687 {
688 #if STRUCTTHISREF
689 thandle = thandle->constOf();
690 #else
688 if (thandle->ty == Tclass) 691 if (thandle->ty == Tclass)
689 thandle = thandle->constOf(); 692 thandle = thandle->constOf();
690 else 693 else
691 { assert(thandle->ty == Tpointer); 694 { assert(thandle->ty == Tpointer);
692 thandle = thandle->nextOf()->constOf()->pointerTo(); 695 thandle = thandle->nextOf()->constOf()->pointerTo();
693 } 696 }
697 #endif
694 } 698 }
695 else if (storage_class & STCinvariant || type->isInvariant()) 699 else if (storage_class & STCinvariant || type->isInvariant())
696 { 700 {
701 #if STRUCTTHISREF
702 thandle = thandle->invariantOf();
703 #else
697 if (thandle->ty == Tclass) 704 if (thandle->ty == Tclass)
698 thandle = thandle->invariantOf(); 705 thandle = thandle->invariantOf();
699 else 706 else
700 { assert(thandle->ty == Tpointer); 707 { assert(thandle->ty == Tpointer);
701 thandle = thandle->nextOf()->invariantOf()->pointerTo(); 708 thandle = thandle->nextOf()->invariantOf()->pointerTo();
702 } 709 }
710 #endif
703 } 711 }
704 v = new ThisDeclaration(thandle); 712 v = new ThisDeclaration(thandle);
705 v->storage_class |= STCparameter; 713 v->storage_class |= STCparameter;
714 #if STRUCTTHISREF
715 if (thandle->ty == Tstruct)
716 v->storage_class |= STCref;
717 #endif
706 v->semantic(sc2); 718 v->semantic(sc2);
707 if (!sc2->insert(v)) 719 if (!sc2->insert(v))
708 assert(0); 720 assert(0);
709 v->parent = this; 721 v->parent = this;
710 vthis = v; 722 vthis = v;
948 e = e->semantic(sc2); 960 e = e->semantic(sc2);
949 } 961 }
950 } 962 }
951 else 963 else
952 { // Call invariant virtually 964 { // Call invariant virtually
953 ThisExp *v = new ThisExp(0); 965 Expression *v = new ThisExp(0);
954 v->type = vthis->type; 966 v->type = vthis->type;
967 #if STRUCTTHISREF
968 if (ad->isStructDeclaration())
969 v = v->addressOf(sc);
970 #endif
955 e = new AssertExp(0, v); 971 e = new AssertExp(0, v);
956 } 972 }
957 if (e) 973 if (e)
958 { 974 {
959 ExpStatement *s = new ExpStatement(0, e); 975 ExpStatement *s = new ExpStatement(0, e);
1212 e = e->semantic(sc2); 1228 e = e->semantic(sc2);
1213 } 1229 }
1214 } 1230 }
1215 else 1231 else
1216 { // Call invariant virtually 1232 { // Call invariant virtually
1217 ThisExp *v = new ThisExp(0); 1233 Expression *v = new ThisExp(0);
1218 v->type = vthis->type; 1234 v->type = vthis->type;
1235 #if STRUCTTHISREF
1236 if (ad->isStructDeclaration())
1237 v = v->addressOf(sc);
1238 #endif
1219 Expression *se = new StringExp(0, (char *)"null this"); 1239 Expression *se = new StringExp(0, (char *)"null this");
1220 se = se->semantic(sc); 1240 se = se->semantic(sc);
1221 se->type = Type::tchar->arrayOf(); 1241 se->type = Type::tchar->arrayOf();
1222 e = new AssertExp(loc, v, se); 1242 e = new AssertExp(loc, v, se);
1223 } 1243 }
2015 toParent()->isClassDeclaration(); 2035 toParent()->isClassDeclaration();
2016 } 2036 }
2017 2037
2018 int FuncDeclaration::isFinal() 2038 int FuncDeclaration::isFinal()
2019 { 2039 {
2040 ClassDeclaration *cd;
2020 #if 0 2041 #if 0
2021 printf("FuncDeclaration::isFinal(%s)\n", toChars()); 2042 printf("FuncDeclaration::isFinal(%s)\n", toChars());
2022 printf("%p %d %d %d %d\n", isMember(), isStatic(), protection == PROTprivate, isCtorDeclaration(), linkage != LINKd); 2043 printf("%p %d %d %d %d\n", isMember(), isStatic(), protection == PROTprivate, isCtorDeclaration(), linkage != LINKd);
2023 printf("result is %d\n", 2044 printf("result is %d\n",
2024 isMember() && 2045 isMember() &&
2025 !(isStatic() || protection == PROTprivate || protection == PROTpackage) && 2046 !(isStatic() || protection == PROTprivate || protection == PROTpackage) &&
2026 toParent()->isClassDeclaration()); 2047 (cd = toParent()->isClassDeclaration()) != NULL &&
2027 #endif 2048 cd->storage_class & STCfinal);
2028 ClassDeclaration *cd; 2049 #endif
2029 return isMember() && 2050 return isMember() &&
2030 (Declaration::isFinal() || 2051 (Declaration::isFinal() ||
2031 ((cd = toParent()->isClassDeclaration()) != NULL && cd->storage_class & STCfinal)); 2052 ((cd = toParent()->isClassDeclaration()) != NULL && cd->storage_class & STCfinal));
2032 } 2053 }
2033 2054
2329 else 2350 else
2330 { tret = ad->handle; 2351 { tret = ad->handle;
2331 assert(tret); 2352 assert(tret);
2332 } 2353 }
2333 type = new TypeFunction(arguments, tret, varargs, LINKd); 2354 type = new TypeFunction(arguments, tret, varargs, LINKd);
2355 #if STRUCTTHISREF
2356 if (ad && ad->isStructDeclaration())
2357 ((TypeFunction *)type)->isref = 1;
2358 #endif
2334 if (!originalType) 2359 if (!originalType)
2335 originalType = type; 2360 originalType = type;
2336 2361
2337 sc->flags |= SCOPEctor; 2362 sc->flags |= SCOPEctor;
2338 type = type->semantic(loc, sc); 2363 type = type->semantic(loc, sc);
2855 2880
2856 void UnitTestDeclaration::semantic(Scope *sc) 2881 void UnitTestDeclaration::semantic(Scope *sc)
2857 { 2882 {
2858 if (global.params.useUnitTests) 2883 if (global.params.useUnitTests)
2859 { 2884 {
2860 Type *tret;
2861
2862 type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); 2885 type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
2863 FuncDeclaration::semantic(sc); 2886 Scope *sc2 = sc->push();
2887 sc2->linkage = LINKd;
2888 FuncDeclaration::semantic(sc2);
2889 sc2->pop();
2864 } 2890 }
2865 2891
2866 // We're going to need ModuleInfo even if the unit tests are not 2892 // We're going to need ModuleInfo even if the unit tests are not
2867 // compiled in, because other modules may import this module and refer 2893 // compiled in, because other modules may import this module and refer
2868 // to this ModuleInfo. 2894 // to this ModuleInfo.