Mercurial > projects > ddmd
comparison dmd/TemplateInstance.d @ 20:1628b221808d
Fleshed out more unimplemented methods.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Wed, 07 Apr 2010 00:29:13 +0100 |
parents | 10317f0c89a5 |
children | 460959608115 |
comparison
equal
deleted
inserted
replaced
19:01cadcfa4842 | 20:1628b221808d |
---|---|
34 import dmd.VarDeclaration; | 34 import dmd.VarDeclaration; |
35 import dmd.VarExp; | 35 import dmd.VarExp; |
36 import dmd.FuncExp; | 36 import dmd.FuncExp; |
37 import dmd.Declaration; | 37 import dmd.Declaration; |
38 import dmd.MATCH; | 38 import dmd.MATCH; |
39 import dmd.templates.Util; | |
39 | 40 |
40 import dmd.backend.glue; | 41 import dmd.backend.glue; |
41 | 42 |
42 Tuple isTuple(Object o) | 43 Tuple isTuple(Object o) |
43 { | 44 { |
227 tdtypes = new Objects(); | 228 tdtypes = new Objects(); |
228 } | 229 } |
229 | 230 |
230 static Objects arraySyntaxCopy(Objects objs) | 231 static Objects arraySyntaxCopy(Objects objs) |
231 { | 232 { |
232 assert(false); | 233 Objects a = null; |
233 } | 234 if (objs) |
234 | 235 { a = new Objects(); |
235 Dsymbol syntaxCopy(Dsymbol) | 236 a.setDim(objs.dim); |
236 { | 237 for (size_t i = 0; i < objs.dim; i++) |
237 assert(false); | 238 { |
239 a.data[i] = cast(void*)objectSyntaxCopy(cast(Object)objs.data[i]); | |
240 } | |
241 } | |
242 return a; | |
243 } | |
244 | |
245 Dsymbol syntaxCopy(Dsymbol s) | |
246 { | |
247 TemplateInstance ti; | |
248 | |
249 if (s) | |
250 ti = cast(TemplateInstance)s; | |
251 else | |
252 ti = new TemplateInstance(loc, name); | |
253 | |
254 ti.tiargs = arraySyntaxCopy(tiargs); | |
255 | |
256 ScopeDsymbol.syntaxCopy(ti); | |
257 return ti; | |
238 } | 258 } |
239 | 259 |
240 void semantic(Scope sc) | 260 void semantic(Scope sc) |
241 { | 261 { |
242 if (global.errors) | 262 if (global.errors) |
525 //printf("test4: isnested = %d, s.parent = %s\n", isnested, s.parent.toChars()); | 545 //printf("test4: isnested = %d, s.parent = %s\n", isnested, s.parent.toChars()); |
526 sc2.module_.runDeferredSemantic(); | 546 sc2.module_.runDeferredSemantic(); |
527 } | 547 } |
528 --nest; | 548 --nest; |
529 } | 549 } |
530 catch | 550 catch (Exception e) |
531 { | 551 { |
532 global.gag = 0; // ensure error message gets printed | 552 global.gag = 0; // ensure error message gets printed |
533 error("recursive expansion"); | 553 error("recursive expansion"); |
534 fatal(); | 554 fatal(); |
535 } | 555 } |
594 if (semanticRun >= 2) | 614 if (semanticRun >= 2) |
595 return; | 615 return; |
596 | 616 |
597 semanticRun = 2; | 617 semanticRun = 2; |
598 version (LOG) { | 618 version (LOG) { |
599 printf("+TemplateInstance::semantic2('%s')\n", toChars()); | 619 printf("+TemplateInstance.semantic2('%s')\n", toChars()); |
600 } | 620 } |
601 | 621 |
602 if (!errors && members) | 622 if (!errors && members) |
603 { | 623 { |
604 sc = tempdecl.scope_; | 624 sc = tempdecl.scope_; |
619 sc = sc.pop(); | 639 sc = sc.pop(); |
620 sc.pop(); | 640 sc.pop(); |
621 } | 641 } |
622 | 642 |
623 version (LOG) { | 643 version (LOG) { |
624 printf("-TemplateInstance::semantic2('%s')\n", toChars()); | 644 printf("-TemplateInstance.semantic2('%s')\n", toChars()); |
625 } | 645 } |
626 } | 646 } |
627 | 647 |
628 void semantic3(Scope sc) | 648 void semantic3(Scope sc) |
629 { | 649 { |
691 } | 711 } |
692 | 712 |
693 Dsymbol toAlias() // resolve real symbol | 713 Dsymbol toAlias() // resolve real symbol |
694 { | 714 { |
695 version (LOG) { | 715 version (LOG) { |
696 printf("TemplateInstance::toAlias()\n"); | 716 printf("TemplateInstance.toAlias()\n"); |
697 } | 717 } |
698 if (!inst) | 718 if (!inst) |
699 { | 719 { |
700 error("cannot resolve forward reference"); | 720 error("cannot resolve forward reference"); |
701 return this; | 721 return this; |
712 return inst; | 732 return inst; |
713 } | 733 } |
714 | 734 |
715 string kind() | 735 string kind() |
716 { | 736 { |
717 assert(false); | 737 return "template instance"; |
718 } | 738 } |
719 | 739 |
720 bool oneMember(Dsymbol* ps) | 740 bool oneMember(Dsymbol* ps) |
721 { | 741 { |
722 assert(false); | 742 *ps = null; |
743 return true; | |
723 } | 744 } |
724 | 745 |
725 string toChars() | 746 string toChars() |
726 { | 747 { |
727 scope OutBuffer buf = new OutBuffer(); | 748 scope OutBuffer buf = new OutBuffer(); |
731 return buf.extractString(); | 752 return buf.extractString(); |
732 } | 753 } |
733 | 754 |
734 string mangle() | 755 string mangle() |
735 { | 756 { |
736 assert(false); | 757 OutBuffer buf = new OutBuffer(); |
758 string id; | |
759 | |
760 static if (0) { | |
761 printf("TemplateInstance.mangle() %s", toChars()); | |
762 if (parent) | |
763 printf(" parent = %s %s", parent.kind(), parent.toChars()); | |
764 printf("\n"); | |
765 } | |
766 id = ident ? ident.toChars() : toChars(); | |
767 if (!tempdecl) | |
768 error("is not defined"); | |
769 else if (tempdecl.parent) | |
770 { | |
771 string p = tempdecl.parent.mangle(); | |
772 if (p[0] == '_' && p[1] == 'D') | |
773 p = p[2..$]; | |
774 buf.writestring(p); | |
775 } | |
776 buf.printf("%d%s", id.length, id); | |
777 id = buf.toChars(); | |
778 buf.data = null; | |
779 //printf("TemplateInstance.mangle() %s = %s\n", toChars(), id); | |
780 return id; | |
737 } | 781 } |
738 | 782 |
739 void printInstantiationTrace() | 783 void printInstantiationTrace() |
740 { | 784 { |
741 assert(false); | 785 if (global.gag) |
786 return; | |
742 } | 787 } |
743 | 788 |
744 void toObjFile(int multiobj) // compile to .obj file | 789 void toObjFile(int multiobj) // compile to .obj file |
745 { | 790 { |
746 version (LOG) { | 791 version (LOG) { |
1157 * Declare parameters of template instance, initialize them with the | 1202 * Declare parameters of template instance, initialize them with the |
1158 * template instance arguments. | 1203 * template instance arguments. |
1159 */ | 1204 */ |
1160 void declareParameters(Scope sc) | 1205 void declareParameters(Scope sc) |
1161 { | 1206 { |
1162 //printf("TemplateInstance::declareParameters()\n"); | 1207 //printf("TemplateInstance.declareParameters()\n"); |
1163 for (int i = 0; i < tdtypes.dim; i++) | 1208 for (int i = 0; i < tdtypes.dim; i++) |
1164 { | 1209 { |
1165 TemplateParameter tp = cast(TemplateParameter)tempdecl.parameters.data[i]; | 1210 TemplateParameter tp = cast(TemplateParameter)tempdecl.parameters.data[i]; |
1166 //Object o = cast(Object)tiargs.data[i]; | 1211 //Object o = cast(Object)tiargs.data[i]; |
1167 Object o = cast(Object)tdtypes.data[i]; // initializer for tp | 1212 Object o = cast(Object)tdtypes.data[i]; // initializer for tp |
1176 * generation of the TemplateDeclaration. | 1221 * generation of the TemplateDeclaration. |
1177 */ | 1222 */ |
1178 bool hasNestedArgs(Objects args) | 1223 bool hasNestedArgs(Objects args) |
1179 { | 1224 { |
1180 bool nested = false; | 1225 bool nested = false; |
1181 //printf("TemplateInstance::hasNestedArgs('%s')\n", tempdecl.ident.toChars()); | 1226 //printf("TemplateInstance.hasNestedArgs('%s')\n", tempdecl.ident.toChars()); |
1182 | 1227 |
1183 /* A nested instance happens when an argument references a local | 1228 /* A nested instance happens when an argument references a local |
1184 * symbol that is on the stack. | 1229 * symbol that is on the stack. |
1185 */ | 1230 */ |
1186 for (size_t i = 0; i < args.dim; i++) | 1231 for (size_t i = 0; i < args.dim; i++) |
1272 { | 1317 { |
1273 scope OutBuffer buf = new OutBuffer(); | 1318 scope OutBuffer buf = new OutBuffer(); |
1274 string id; | 1319 string id; |
1275 Objects args; | 1320 Objects args; |
1276 | 1321 |
1277 //printf("TemplateInstance::genIdent('%s')\n", tempdecl.ident.toChars()); | 1322 //printf("TemplateInstance.genIdent('%s')\n", tempdecl.ident.toChars()); |
1278 id = tempdecl.ident.toChars(); | 1323 id = tempdecl.ident.toChars(); |
1279 buf.printf("__T%d%s", id.length, id); ///! | 1324 buf.printf("__T%d%s", id.length, id); ///! |
1280 args = tiargs; | 1325 args = tiargs; |
1281 for (int i = 0; i < args.dim; i++) | 1326 for (int i = 0; i < args.dim; i++) |
1282 { | 1327 { |