Mercurial > projects > ddmd
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 |
rev | line source |
---|---|
72 | 1 module dmd.ArrayExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.Identifier; | |
6 import dmd.UnaExp; | |
7 import dmd.OutBuffer; | |
8 import dmd.Loc; | |
9 import dmd.Scope; | |
10 import dmd.InlineCostState; | |
11 import dmd.InlineDoState; | |
12 import dmd.HdrGenState; | |
13 import dmd.InlineScanState; | |
14 import dmd.ArrayTypes; | |
181 | 15 import dmd.PREC; |
0 | 16 import dmd.TOK; |
17 import dmd.Type; | |
18 import dmd.TY; | |
19 import dmd.Id; | |
20 import dmd.IndexExp; | |
21 | |
72 | 22 import dmd.expression.Util; |
23 | |
0 | 24 class ArrayExp : UnaExp |
25 { | |
26 Expressions arguments; | |
27 | |
28 this(Loc loc, Expression e1, Expressions args) | |
29 { | |
178 | 30 register(); |
0 | 31 super(loc, TOK.TOKarray, ArrayExp.sizeof, e1); |
32 arguments = args; | |
33 } | |
34 | |
72 | 35 override Expression syntaxCopy() |
0 | 36 { |
72 | 37 return new ArrayExp(loc, e1.syntaxCopy(), arraySyntaxCopy(arguments)); |
0 | 38 } |
39 | |
72 | 40 override Expression semantic(Scope sc) |
0 | 41 { |
42 Expression e; | |
43 Type t1; | |
44 | |
45 version (LOGSEMANTIC) { | |
46 printf("ArrayExp::semantic('%s')\n", toChars()); | |
47 } | |
48 UnaExp.semantic(sc); | |
49 e1 = resolveProperties(sc, e1); | |
50 | |
51 t1 = e1.type.toBasetype(); | |
52 if (t1.ty != Tclass && t1.ty != Tstruct) | |
53 { | |
54 // Convert to IndexExp | |
55 if (arguments.dim != 1) | |
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 | 58 return e.semantic(sc); |
59 } | |
60 | |
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 | 63 { |
64 e = e.semantic(sc); | |
65 if (!e.type) | |
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 | 68 } |
69 | |
70 expandTuples(arguments); | |
71 assert(arguments && arguments.dim); | |
72 | |
73 e = op_overload(sc); | |
74 if (!e) | |
75 { | |
76 error("no [] operator overload for type %s", e1.type.toChars()); | |
77 e = e1; | |
78 } | |
79 return e; | |
80 } | |
81 | |
72 | 82 override int isLvalue() |
0 | 83 { |
84 assert(false); | |
85 } | |
86 | |
72 | 87 override Expression toLvalue(Scope sc, Expression e) |
0 | 88 { |
89 assert(false); | |
90 } | |
91 | |
72 | 92 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 93 { |
181 | 94 expToCBuffer(buf, hgs, e1, PREC_primary); |
95 buf.writeByte('['); | |
96 argsToCBuffer(buf, arguments, hgs); | |
97 buf.writeByte(']'); | |
0 | 98 } |
99 | |
72 | 100 override void scanForNestedRef(Scope sc) |
0 | 101 { |
102 assert(false); | |
103 } | |
104 | |
72 | 105 override Identifier opId() |
0 | 106 { |
107 return Id.index; | |
108 } | |
109 | |
72 | 110 override int inlineCost(InlineCostState* ics) |
0 | 111 { |
112 return 1 + e1.inlineCost(ics) + arrayInlineCost(ics, arguments); | |
113 } | |
114 | |
72 | 115 override Expression doInline(InlineDoState ids) |
0 | 116 { |
117 ArrayExp ce; | |
118 | |
119 ce = cast(ArrayExp)copy(); | |
120 ce.e1 = e1.doInline(ids); | |
121 ce.arguments = arrayExpressiondoInline(arguments, ids); | |
122 return ce; | |
123 } | |
124 | |
72 | 125 override Expression inlineScan(InlineScanState* iss) |
0 | 126 { |
127 Expression e = this; | |
128 | |
129 //printf("ArrayExp.inlineScan()\n"); | |
130 e1 = e1.inlineScan(iss); | |
131 arrayInlineScan(iss, arguments); | |
132 | |
133 return e; | |
134 } | |
135 } | |
136 |