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