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