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