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
|
|
59 for (size_t i = 0; i < arguments.dim; i++)
|
|
60 {
|
|
61 e = cast(Expression)arguments.data[i];
|
|
62
|
|
63 e = e.semantic(sc);
|
|
64 if (!e.type)
|
|
65 error("%s has no value", e.toChars());
|
|
66 arguments.data[i] = cast(void*)e;
|
|
67 }
|
|
68
|
|
69 expandTuples(arguments);
|
|
70 assert(arguments && arguments.dim);
|
|
71
|
|
72 e = op_overload(sc);
|
|
73 if (!e)
|
|
74 {
|
|
75 error("no [] operator overload for type %s", e1.type.toChars());
|
|
76 e = e1;
|
|
77 }
|
|
78 return e;
|
|
79 }
|
|
80
|
72
|
81 override int isLvalue()
|
0
|
82 {
|
|
83 assert(false);
|
|
84 }
|
|
85
|
72
|
86 override Expression toLvalue(Scope sc, Expression e)
|
0
|
87 {
|
|
88 assert(false);
|
|
89 }
|
|
90
|
72
|
91 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
0
|
92 {
|
|
93 assert(false);
|
|
94 }
|
|
95
|
72
|
96 override void scanForNestedRef(Scope sc)
|
0
|
97 {
|
|
98 assert(false);
|
|
99 }
|
|
100
|
72
|
101 override Identifier opId()
|
0
|
102 {
|
|
103 return Id.index;
|
|
104 }
|
|
105
|
72
|
106 override int inlineCost(InlineCostState* ics)
|
0
|
107 {
|
|
108 return 1 + e1.inlineCost(ics) + arrayInlineCost(ics, arguments);
|
|
109 }
|
|
110
|
72
|
111 override Expression doInline(InlineDoState ids)
|
0
|
112 {
|
|
113 ArrayExp ce;
|
|
114
|
|
115 ce = cast(ArrayExp)copy();
|
|
116 ce.e1 = e1.doInline(ids);
|
|
117 ce.arguments = arrayExpressiondoInline(arguments, ids);
|
|
118 return ce;
|
|
119 }
|
|
120
|
72
|
121 override Expression inlineScan(InlineScanState* iss)
|
0
|
122 {
|
|
123 Expression e = this;
|
|
124
|
|
125 //printf("ArrayExp.inlineScan()\n");
|
|
126 e1 = e1.inlineScan(iss);
|
|
127 arrayInlineScan(iss, arguments);
|
|
128
|
|
129 return e;
|
|
130 }
|
|
131 }
|
|
132
|