Mercurial > projects > ddmd
annotate dmd/TemplateTupleParameter.d @ 178:e3afd1303184
Many small bugs fixed
Made all classes derive from TObject to detect memory leaks (functionality is disabled for now)
Began work on overriding backend memory allocations (to avoid memory leaks)
author | korDen |
---|---|
date | Sun, 17 Oct 2010 07:42:00 +0400 |
parents | e28b18c23469 |
children | b0d41ff5e0df |
rev | line source |
---|---|
0 | 1 module dmd.TemplateTupleParameter; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.TemplateParameter; |
5 import dmd.Loc; | |
6 import dmd.Identifier; | |
7 import dmd.TypeIdentifier; | |
8 import dmd.AliasDeclaration; | |
9 import dmd.Scope; | |
10 import dmd.ArrayTypes; | |
11 import dmd.MATCH; | |
12 import dmd.Declaration; | |
13 import dmd.OutBuffer; | |
14 import dmd.HdrGenState; | |
15 import dmd.Util; | |
16 import dmd.Tuple; | |
17 import dmd.Dsymbol; | |
18 import dmd.TemplateInstance; | |
19 import dmd.Type; | |
20 import dmd.Expression; | |
21 import dmd.TupleDeclaration; | |
22 | |
23 class TemplateTupleParameter : TemplateParameter | |
24 { | |
25 /* Syntax: | |
26 * ident ... | |
27 */ | |
28 | |
29 this(Loc loc, Identifier ident) | |
30 { | |
178 | 31 register(); |
0 | 32 super(loc, ident); |
33 this.ident = ident; | |
34 } | |
35 | |
72 | 36 override TemplateTupleParameter isTemplateTupleParameter() |
0 | 37 { |
38 return this; | |
39 } | |
40 | |
72 | 41 override TemplateParameter syntaxCopy() |
0 | 42 { |
43 TemplateTupleParameter tp = new TemplateTupleParameter(loc, ident); | |
44 return tp; | |
45 } | |
46 | |
72 | 47 override void declareParameter(Scope sc) |
0 | 48 { |
49 TypeIdentifier ti = new TypeIdentifier(loc, ident); | |
50 sparam = new AliasDeclaration(loc, ident, ti); | |
51 if (!sc.insert(sparam)) | |
52 error(loc, "parameter '%s' multiply defined", ident.toChars()); | |
53 } | |
54 | |
72 | 55 override void semantic(Scope) |
0 | 56 { |
57 } | |
58 | |
72 | 59 override void print(Object oarg, Object oded) |
0 | 60 { |
61 writef(" %s... [", ident.toChars()); | |
62 Tuple v = isTuple(oded); | |
63 assert(v); | |
64 | |
65 //printf("|%d| ", v.objects.dim); | |
66 for (int i = 0; i < v.objects.dim; i++) | |
67 { | |
68 if (i) | |
69 writef(", "); | |
70 | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
94
diff
changeset
|
71 Object o = v.objects[i]; |
0 | 72 |
73 Dsymbol sa = isDsymbol(o); | |
74 if (sa) | |
75 writef("alias: %s", sa.toChars()); | |
76 | |
77 Type ta = isType(o); | |
78 if (ta) | |
79 writef("type: %s", ta.toChars()); | |
80 | |
81 Expression ea = isExpression(o); | |
82 if (ea) | |
83 writef("exp: %s", ea.toChars()); | |
84 | |
85 assert(!isTuple(o)); // no nested Tuple arguments | |
86 } | |
87 | |
88 writef("]\n"); | |
89 } | |
90 | |
72 | 91 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 92 { |
93 buf.writestring(ident.toChars()); | |
94 buf.writestring("..."); | |
95 } | |
96 | |
72 | 97 override Object specialization() |
0 | 98 { |
99 return null; | |
100 } | |
101 | |
72 | 102 override Object defaultArg(Loc loc, Scope sc) |
0 | 103 { |
104 return null; | |
105 } | |
106 | |
72 | 107 override bool overloadMatch(TemplateParameter tp) |
0 | 108 { |
109 TemplateTupleParameter tvp = tp.isTemplateTupleParameter(); | |
110 if (tvp) { | |
111 return true; // match | |
112 } | |
113 | |
114 Lnomatch: | |
115 return false; | |
116 } | |
117 | |
72 | 118 override MATCH matchArg(Scope sc, Objects tiargs, int i, TemplateParameters parameters, Objects dedtypes, Declaration* psparam, int flags) |
0 | 119 { |
120 //printf("TemplateTupleParameter.matchArg()\n"); | |
121 | |
122 /* The rest of the actual arguments (tiargs[]) form the match | |
123 * for the variadic parameter. | |
124 */ | |
125 assert(i + 1 == dedtypes.dim); // must be the last one | |
126 Tuple ovar; | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
94
diff
changeset
|
127 if (i + 1 == tiargs.dim && isTuple(tiargs[i])) |
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
94
diff
changeset
|
128 ovar = isTuple(tiargs[i]); |
0 | 129 else |
130 { | |
131 ovar = new Tuple(); | |
132 //printf("ovar = %p\n", ovar); | |
133 if (i < tiargs.dim) | |
134 { | |
135 //printf("i = %d, tiargs.dim = %d\n", i, tiargs.dim); | |
136 ovar.objects.setDim(tiargs.dim - i); | |
137 for (size_t j = 0; j < ovar.objects.dim; j++) | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
94
diff
changeset
|
138 ovar.objects[j] = tiargs[i + j]; |
0 | 139 } |
140 } | |
141 *psparam = new TupleDeclaration(loc, ident, ovar.objects); | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
142 dedtypes[i] = ovar; |
0 | 143 |
144 return MATCH.MATCHexact; | |
145 } | |
146 | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
147 override Object dummyArg() |
0 | 148 { |
149 return null; | |
150 } | |
72 | 151 } |