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