Mercurial > projects > ddmd
annotate dmd/ArrayExp.d @ 191:52188e7e3fb5
Fixed deprecated features, now compiles with DMD2.058
Also changed Array allocation policy:
Now doesn't reallocate but malloc's, followed by a memcpy (no free).
(this fixes a crash while compiling druntime. Same bug in dmd)
author | korDen@korDen-pc |
---|---|
date | Sun, 25 Mar 2012 03:11:12 +0400 |
parents | b0d41ff5e0df |
children |
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 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
181
diff
changeset
|
24 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
181
diff
changeset
|
25 |
0 | 26 class ArrayExp : UnaExp |
27 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
181
diff
changeset
|
28 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
181
diff
changeset
|
29 |
0 | 30 Expressions arguments; |
31 | |
32 this(Loc loc, Expression e1, Expressions args) | |
33 { | |
178 | 34 register(); |
0 | 35 super(loc, TOK.TOKarray, ArrayExp.sizeof, e1); |
36 arguments = args; | |
37 } | |
38 | |
72 | 39 override Expression syntaxCopy() |
0 | 40 { |
72 | 41 return new ArrayExp(loc, e1.syntaxCopy(), arraySyntaxCopy(arguments)); |
0 | 42 } |
43 | |
72 | 44 override Expression semantic(Scope sc) |
0 | 45 { |
46 Expression e; | |
47 Type t1; | |
48 | |
49 version (LOGSEMANTIC) { | |
50 printf("ArrayExp::semantic('%s')\n", toChars()); | |
51 } | |
52 UnaExp.semantic(sc); | |
53 e1 = resolveProperties(sc, e1); | |
54 | |
55 t1 = e1.type.toBasetype(); | |
56 if (t1.ty != Tclass && t1.ty != Tstruct) | |
57 { | |
58 // Convert to IndexExp | |
59 if (arguments.dim != 1) | |
60 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
|
61 e = new IndexExp(loc, e1, arguments[0]); |
0 | 62 return e.semantic(sc); |
63 } | |
64 | |
65 // Run semantic() on each argument | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
66 foreach (size_t i, Expression e; arguments) |
0 | 67 { |
68 e = e.semantic(sc); | |
69 if (!e.type) | |
70 error("%s has no value", e.toChars()); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
71 arguments[i] = e; |
0 | 72 } |
73 | |
74 expandTuples(arguments); | |
75 assert(arguments && arguments.dim); | |
76 | |
77 e = op_overload(sc); | |
78 if (!e) | |
79 { | |
80 error("no [] operator overload for type %s", e1.type.toChars()); | |
81 e = e1; | |
82 } | |
83 return e; | |
84 } | |
85 | |
191
52188e7e3fb5
Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents:
187
diff
changeset
|
86 override bool isLvalue() |
0 | 87 { |
88 assert(false); | |
89 } | |
90 | |
72 | 91 override Expression toLvalue(Scope sc, Expression e) |
0 | 92 { |
93 assert(false); | |
94 } | |
95 | |
72 | 96 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 97 { |
181 | 98 expToCBuffer(buf, hgs, e1, PREC_primary); |
99 buf.writeByte('['); | |
100 argsToCBuffer(buf, arguments, hgs); | |
101 buf.writeByte(']'); | |
0 | 102 } |
103 | |
72 | 104 override void scanForNestedRef(Scope sc) |
0 | 105 { |
106 assert(false); | |
107 } | |
108 | |
72 | 109 override Identifier opId() |
0 | 110 { |
111 return Id.index; | |
112 } | |
113 | |
72 | 114 override int inlineCost(InlineCostState* ics) |
0 | 115 { |
116 return 1 + e1.inlineCost(ics) + arrayInlineCost(ics, arguments); | |
117 } | |
118 | |
72 | 119 override Expression doInline(InlineDoState ids) |
0 | 120 { |
121 ArrayExp ce; | |
122 | |
123 ce = cast(ArrayExp)copy(); | |
124 ce.e1 = e1.doInline(ids); | |
125 ce.arguments = arrayExpressiondoInline(arguments, ids); | |
126 return ce; | |
127 } | |
128 | |
72 | 129 override Expression inlineScan(InlineScanState* iss) |
0 | 130 { |
131 Expression e = this; | |
132 | |
133 //printf("ArrayExp.inlineScan()\n"); | |
134 e1 = e1.inlineScan(iss); | |
135 arrayInlineScan(iss, arguments); | |
136 | |
137 return e; | |
138 } | |
139 } | |
140 |