Mercurial > projects > ddmd
annotate dmd/InlineScanState.d @ 113:3482c73a991b
More cleanup for arrays
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Tue, 31 Aug 2010 23:57:32 +0100 |
parents | be2ab491772e |
children | e28b18c23469 |
rev | line source |
---|---|
0 | 1 module dmd.InlineScanState; |
2 | |
3 import dmd.FuncDeclaration; | |
4 import dmd.ExpInitializer; | |
5 import dmd.Dsymbol; | |
6 import dmd.InlineScanState; | |
7 import dmd.TupleDeclaration; | |
8 import dmd.VarDeclaration; | |
9 import dmd.Type; | |
10 import dmd.TypeStruct; | |
11 import dmd.StructDeclaration; | |
12 import dmd.Array; | |
13 import dmd.Expression; | |
14 import dmd.DsymbolExp; | |
15 import dmd.TOK; | |
16 import dmd.TY; | |
17 | |
18 struct InlineScanState | |
19 { | |
20 FuncDeclaration fd; // function being scanned | |
21 } | |
22 | |
23 void scanVar(Dsymbol s, InlineScanState* iss) | |
24 { | |
25 VarDeclaration vd = s.isVarDeclaration(); | |
26 if (vd) | |
27 { | |
28 TupleDeclaration td = vd.toAlias().isTupleDeclaration(); | |
29 if (td) | |
30 { | |
31 for (size_t i = 0; i < td.objects.dim; i++) | |
32 { | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
84
diff
changeset
|
33 auto se = cast(DsymbolExp)td.objects[i]; |
0 | 34 assert(se.op == TOKdsymbol); |
35 scanVar(se.s, iss); | |
36 } | |
37 } | |
38 else | |
39 { | |
40 // Scan initializer (vd.init) | |
41 if (vd.init) | |
42 { | |
43 ExpInitializer ie = vd.init.isExpInitializer(); | |
44 | |
45 if (ie) | |
46 { | |
47 version (DMDV2) { | |
48 if (vd.type) | |
49 { | |
50 Type tb = vd.type.toBasetype(); | |
51 if (tb.ty == Tstruct) | |
52 { | |
53 StructDeclaration sd = (cast(TypeStruct)tb).sym; | |
54 if (sd.cpctor) | |
55 { | |
56 /* The problem here is that if the initializer is a | |
57 * function call that returns a struct S with a cpctor: | |
58 * S s = foo(); | |
59 * the postblit is done by the return statement in foo() | |
60 * in s2ir.c, the intermediate code generator. | |
61 * But, if foo() is inlined and now the code looks like: | |
62 * S s = x; | |
63 * the postblit is not there, because such assignments | |
64 * are rewritten as s.cpctor(&x) by the front end. | |
65 * So, the inlining won't get the postblit called. | |
66 * Work around by not inlining these cases. | |
67 * A proper fix would be to move all the postblit | |
68 * additions to the front end. | |
69 */ | |
70 return; | |
71 } | |
72 } | |
73 } | |
74 } | |
75 ie.exp = ie.exp.inlineScan(iss); | |
76 } | |
77 } | |
78 } | |
79 } | |
80 } | |
81 | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
0
diff
changeset
|
82 void arrayInlineScan(InlineScanState* iss, Expressions arguments) |
0 | 83 { |
84 if (arguments) | |
85 { | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
0
diff
changeset
|
86 foreach (ref Expression e; arguments) |
0 | 87 { |
88 if (e) | |
89 { | |
90 e = e.inlineScan(iss); | |
91 } | |
92 } | |
93 } | |
94 } |