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