Mercurial > projects > ddmd
annotate dmd/ArrayExp.d @ 20:1628b221808d
Fleshed out more unimplemented methods.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Wed, 07 Apr 2010 00:29:13 +0100 |
parents | 10317f0c89a5 |
children | 2e2a5c3f943a |
rev | line source |
---|---|
0 | 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; | |
14 import dmd.TOK; | |
15 import dmd.Type; | |
16 import dmd.TY; | |
17 import dmd.Id; | |
18 import dmd.IndexExp; | |
19 | |
20 import dmd.expression.Util; | |
21 | |
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 | |
32 Expression syntaxCopy() | |
33 { | |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
34 return new ArrayExp(loc, e1.syntaxCopy(), arraySyntaxCopy(arguments)); |
0 | 35 } |
36 | |
37 Expression semantic(Scope sc) | |
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 | |
81 int isLvalue() | |
82 { | |
83 assert(false); | |
84 } | |
85 | |
86 Expression toLvalue(Scope sc, Expression e) | |
87 { | |
88 assert(false); | |
89 } | |
90 | |
91 void toCBuffer(OutBuffer buf, HdrGenState* hgs) | |
92 { | |
93 assert(false); | |
94 } | |
95 | |
96 void scanForNestedRef(Scope sc) | |
97 { | |
98 assert(false); | |
99 } | |
100 | |
101 Identifier opId() | |
102 { | |
103 return Id.index; | |
104 } | |
105 | |
106 int inlineCost(InlineCostState* ics) | |
107 { | |
108 return 1 + e1.inlineCost(ics) + arrayInlineCost(ics, arguments); | |
109 } | |
110 | |
111 Expression doInline(InlineDoState ids) | |
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 | |
121 Expression inlineScan(InlineScanState* iss) | |
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 |