Mercurial > projects > ddmd
comparison dmd/TemplateDeclaration.d @ 179:cd48cb899aee
Updated to dmd2.040
author | korDen |
---|---|
date | Sun, 17 Oct 2010 20:56:07 +0400 |
parents | e3afd1303184 |
children | b0d41ff5e0df |
comparison
equal
deleted
inserted
replaced
178:e3afd1303184 | 179:cd48cb899aee |
---|---|
181 } | 181 } |
182 | 182 |
183 override void semantic(Scope sc) | 183 override void semantic(Scope sc) |
184 { | 184 { |
185 version (LOG) { | 185 version (LOG) { |
186 printf("TemplateDeclaration.semantic(this = %p, id = '%s')\n", this, ident.toChars()); | 186 writef("TemplateDeclaration.semantic(this = %p, id = '%s')\n", this, ident.toChars()); |
187 writef("sc.stc = %llx\n", sc.stc); | |
187 } | 188 } |
188 if (semanticRun) | 189 if (semanticRun) |
189 return; // semantic() already run | 190 return; // semantic() already run |
190 semanticRun = 1; | 191 semanticRun = 1; |
191 | 192 |
701 { | 702 { |
702 Expression e = cast(Expression)fargs.data[i]; | 703 Expression e = cast(Expression)fargs.data[i]; |
703 printf("\tfarg[%d] is %s, type is %s\n", i, e.toChars(), e.type.toChars()); | 704 printf("\tfarg[%d] is %s, type is %s\n", i, e.toChars(), e.type.toChars()); |
704 } | 705 } |
705 printf("fd = %s\n", fd.toChars()); | 706 printf("fd = %s\n", fd.toChars()); |
706 printf("fd.type = %p\n", fd.type); | 707 printf("fd.type = %s\n", fd.type.toChars()); |
708 if (ethis) | |
709 printf("ethis.type = %s\n", ethis.type.toChars()); | |
707 } | 710 } |
708 | 711 |
709 assert(cast(size_t)cast(void*)scope_ > 0x10000); | 712 assert(cast(size_t)cast(void*)scope_ > 0x10000); |
710 | 713 |
711 dedargs.setDim(parameters.dim); | 714 dedargs.setDim(parameters.dim); |
873 match = MATCHconvert; // match ... with a conversion | 876 match = MATCHconvert; // match ... with a conversion |
874 } | 877 } |
875 | 878 |
876 L2: | 879 L2: |
877 version (DMDV2) { | 880 version (DMDV2) { |
878 // Match 'ethis' to any TemplateThisParameter's | |
879 if (ethis) | 881 if (ethis) |
880 { | 882 { |
883 // Match 'ethis' to any TemplateThisParameter's | |
881 for (size_t i = 0; i < parameters.dim; i++) | 884 for (size_t i = 0; i < parameters.dim; i++) |
882 { | 885 { |
883 auto tp2 = parameters[i]; | 886 auto tp2 = parameters[i]; |
884 TemplateThisParameter ttp = tp2.isTemplateThisParameter(); | 887 TemplateThisParameter ttp = tp2.isTemplateThisParameter(); |
885 if (ttp) | 888 if (ttp) |
892 goto Lnomatch; | 895 goto Lnomatch; |
893 if (m < match) | 896 if (m < match) |
894 match = m; // pick worst match | 897 match = m; // pick worst match |
895 } | 898 } |
896 } | 899 } |
900 | |
901 // Match attributes of ethis against attributes of fd | |
902 if (fd.type) | |
903 { | |
904 Type tthis = ethis.type; | |
905 MOD mod = fd.type.mod; | |
906 StorageClass stc = scope_.stc; | |
907 if (stc & (STCshared | STCsynchronized)) | |
908 mod |= MODshared; | |
909 if (stc & STCimmutable) | |
910 mod |= MODimmutable; | |
911 if (stc & STCconst) | |
912 mod |= MODconst; | |
913 if (stc & STCwild) | |
914 mod |= MODwild; | |
915 // Fix mod | |
916 if (mod & MODimmutable) | |
917 mod = MODimmutable; | |
918 if (mod & MODconst) | |
919 mod &= ~STCwild; | |
920 if (tthis.mod != mod) | |
921 { | |
922 if (!MODimplicitConv(tthis.mod, mod)) | |
923 goto Lnomatch; | |
924 if (MATCHconst < match) | |
925 match = MATCHconst; | |
926 } | |
927 } | |
928 | |
897 } | 929 } |
898 } | 930 } |
899 | 931 |
900 // Loop through the function parameters | 932 // Loop through the function parameters |
901 for (size_t i = 0; i < nfparams; i++) | 933 for (size_t i = 0; i < nfparams; i++) |
1048 | 1080 |
1049 /* Fill in any missing arguments with their defaults. | 1081 /* Fill in any missing arguments with their defaults. |
1050 */ | 1082 */ |
1051 for (size_t i = nargsi; i < dedargs.dim; i++) | 1083 for (size_t i = nargsi; i < dedargs.dim; i++) |
1052 { | 1084 { |
1053 auto tp2 = parameters[i]; | 1085 auto tparam = parameters[i]; |
1054 //printf("tp2[%d] = %s\n", i, tp2.ident.toChars()); | 1086 //printf("tparam[%d] = %s\n", i, tparam.ident.toChars()); |
1055 /* For T:T*, the dedargs is the T*, dedtypes is the T | 1087 /* For T:T*, the dedargs is the T*, dedtypes is the T |
1056 * But for function templates, we really need them to match | 1088 * But for function templates, we really need them to match |
1057 */ | 1089 */ |
1058 Object oarg = dedargs[i]; | 1090 Object oarg = dedargs[i]; |
1059 Object oded = dedtypes[i]; | 1091 Object oded = dedtypes[i]; |
1062 //if (oded) printf("oded: %s\n", oded.toChars()); | 1094 //if (oded) printf("oded: %s\n", oded.toChars()); |
1063 if (!oarg) | 1095 if (!oarg) |
1064 { | 1096 { |
1065 if (oded) | 1097 if (oded) |
1066 { | 1098 { |
1067 if (tp2.specialization()) | 1099 if (tparam.specialization()) |
1068 { | 1100 { |
1069 /* The specialization can work as long as afterwards | 1101 /* The specialization can work as long as afterwards |
1070 * the oded == oarg | 1102 * the oded == oarg |
1071 */ | 1103 */ |
1072 Declaration sparam; | 1104 Declaration sparam; |
1073 dedargs[i] = oded; | 1105 dedargs[i] = oded; |
1074 MATCH m2 = tp2.matchArg(paramscope, dedargs, i, parameters, dedtypes, &sparam, 0); | 1106 MATCH m2 = tparam.matchArg(paramscope, dedargs, i, parameters, dedtypes, &sparam, 0); |
1075 //printf("m2 = %d\n", m2); | 1107 //printf("m2 = %d\n", m2); |
1076 if (!m2) | 1108 if (!m2) |
1077 goto Lnomatch; | 1109 goto Lnomatch; |
1078 if (m2 < match) | 1110 if (m2 < match) |
1079 match = m2; // pick worst match | 1111 match = m2; // pick worst match |
1080 if (dedtypes[i] !is oded) | 1112 if (dedtypes[i] !is oded) |
1081 error("specialization not allowed for deduced parameter %s", tp2.ident.toChars()); | 1113 error("specialization not allowed for deduced parameter %s", tparam.ident.toChars()); |
1082 } | 1114 } |
1083 } | 1115 } |
1084 else | 1116 else |
1085 { | 1117 { |
1086 oded = tp2.defaultArg(loc, paramscope); | |
1087 if (!oded) | 1118 if (!oded) |
1088 goto Lnomatch; | 1119 { |
1089 } | 1120 if (tp && // if tuple parameter and |
1090 declareParameter(paramscope, tp2, oded); | 1121 fptupindex < 0 && // tuple parameter was not in function parameter list and |
1122 nargsi == dedargs.dim - 1) // we're one argument short (i.e. no tuple argument) | |
1123 { | |
1124 // make tuple argument an empty tuple | |
1125 oded = new Tuple(); | |
1126 } | |
1127 else | |
1128 goto Lnomatch; | |
1129 } | |
1130 } | |
1131 declareParameter(paramscope, tparam, oded); | |
1091 dedargs[i] = oded; | 1132 dedargs[i] = oded; |
1092 } | 1133 } |
1093 } | 1134 } |
1094 | 1135 |
1095 version (DMDV2) { | 1136 version (DMDV2) { |
1167 { | 1208 { |
1168 Expression arg = cast(Expression)fargs.data[i]; | 1209 Expression arg = cast(Expression)fargs.data[i]; |
1169 printf("\t%s %s\n", arg.type.toChars(), arg.toChars()); | 1210 printf("\t%s %s\n", arg.type.toChars(), arg.toChars()); |
1170 //printf("\tty = %d\n", arg.type.ty); | 1211 //printf("\tty = %d\n", arg.type.ty); |
1171 } | 1212 } |
1213 printf("stc = %llx\n", scope_.stc); | |
1172 } | 1214 } |
1173 | 1215 |
1174 for (TemplateDeclaration td = this; td; td = td.overnext) | 1216 for (TemplateDeclaration td = this; td; td = td.overnext) |
1175 { | 1217 { |
1176 if (!td.semanticRun) | 1218 if (!td.semanticRun) |