annotate dmd/ArrayExp.d @ 182:b64060ab22df

Now compileable with dmd2.050
author korDen
date Sat, 30 Oct 2010 05:05:32 +0400
parents aa70dca07cb0
children b0d41ff5e0df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
1 module dmd.ArrayExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 90
diff changeset
3 import dmd.common;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
4 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
5 import dmd.Identifier;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
6 import dmd.UnaExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
7 import dmd.OutBuffer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
8 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
9 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
10 import dmd.InlineCostState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
11 import dmd.InlineDoState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
12 import dmd.HdrGenState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
13 import dmd.InlineScanState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
14 import dmd.ArrayTypes;
181
aa70dca07cb0 ArrayExp.toCBuffer and TypeReturn.toCBuffer2
korDen
parents: 178
diff changeset
15 import dmd.PREC;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.IndexExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
22 import dmd.expression.Util;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
23
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 class ArrayExp : UnaExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 this(Loc loc, Expression e1, Expressions args)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 114
diff changeset
30 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 super(loc, TOK.TOKarray, ArrayExp.sizeof, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 arguments = args;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
35 override Expression syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
37 return new ArrayExp(loc, e1.syntaxCopy(), arraySyntaxCopy(arguments));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
40 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 Type t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 printf("ArrayExp::semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 UnaExp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 e1 = resolveProperties(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 t1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 if (t1.ty != Tclass && t1.ty != Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 // Convert to IndexExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 if (arguments.dim != 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 error("only one index allowed to index %s", t1.toChars());
90
39648eb578f6 more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
57 e = new IndexExp(loc, e1, arguments[0]);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 return e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 // Run semantic() on each argument
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
62 foreach (size_t i, Expression e; arguments)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 if (!e.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 error("%s has no value", e.toChars());
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
67 arguments[i] = e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 expandTuples(arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 assert(arguments && arguments.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 e = op_overload(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 if (!e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 error("no [] operator overload for type %s", e1.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 e = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
82 override int isLvalue()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
87 override Expression toLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
92 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 {
181
aa70dca07cb0 ArrayExp.toCBuffer and TypeReturn.toCBuffer2
korDen
parents: 178
diff changeset
94 expToCBuffer(buf, hgs, e1, PREC_primary);
aa70dca07cb0 ArrayExp.toCBuffer and TypeReturn.toCBuffer2
korDen
parents: 178
diff changeset
95 buf.writeByte('[');
aa70dca07cb0 ArrayExp.toCBuffer and TypeReturn.toCBuffer2
korDen
parents: 178
diff changeset
96 argsToCBuffer(buf, arguments, hgs);
aa70dca07cb0 ArrayExp.toCBuffer and TypeReturn.toCBuffer2
korDen
parents: 178
diff changeset
97 buf.writeByte(']');
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
100 override void scanForNestedRef(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
105 override Identifier opId()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 return Id.index;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
110 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 return 1 + e1.inlineCost(ics) + arrayInlineCost(ics, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
115 override Expression doInline(InlineDoState ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 ArrayExp ce;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 ce = cast(ArrayExp)copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 ce.e1 = e1.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 ce.arguments = arrayExpressiondoInline(arguments, ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 return ce;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 20
diff changeset
125 override Expression inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 Expression e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 //printf("ArrayExp.inlineScan()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 e1 = e1.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 arrayInlineScan(iss, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136