Mercurial > projects > ddmd
annotate dmd/ArrayExp.d @ 178:e3afd1303184
Many small bugs fixed
Made all classes derive from TObject to detect memory leaks (functionality is disabled for now)
Began work on overriding backend memory allocations (to avoid memory leaks)
author | korDen |
---|---|
date | Sun, 17 Oct 2010 07:42:00 +0400 |
parents | e28b18c23469 |
children | aa70dca07cb0 |
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 { | |
178 | 29 register(); |
0 | 30 super(loc, TOK.TOKarray, ArrayExp.sizeof, e1); |
31 arguments = args; | |
32 } | |
33 | |
72 | 34 override Expression syntaxCopy() |
0 | 35 { |
72 | 36 return new ArrayExp(loc, e1.syntaxCopy(), arraySyntaxCopy(arguments)); |
0 | 37 } |
38 | |
72 | 39 override Expression semantic(Scope sc) |
0 | 40 { |
41 Expression e; | |
42 Type t1; | |
43 | |
44 version (LOGSEMANTIC) { | |
45 printf("ArrayExp::semantic('%s')\n", toChars()); | |
46 } | |
47 UnaExp.semantic(sc); | |
48 e1 = resolveProperties(sc, e1); | |
49 | |
50 t1 = e1.type.toBasetype(); | |
51 if (t1.ty != Tclass && t1.ty != Tstruct) | |
52 { | |
53 // Convert to IndexExp | |
54 if (arguments.dim != 1) | |
55 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
|
56 e = new IndexExp(loc, e1, arguments[0]); |
0 | 57 return e.semantic(sc); |
58 } | |
59 | |
60 // Run semantic() on each argument | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
61 foreach (size_t i, Expression e; arguments) |
0 | 62 { |
63 e = e.semantic(sc); | |
64 if (!e.type) | |
65 error("%s has no value", e.toChars()); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
66 arguments[i] = e; |
0 | 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 |