Mercurial > projects > ddmd
comparison dmd/ArrayLiteralExp.d @ 130:60bb0fe4563e
dmdfe 2.037 first main iteration
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 22:51:44 +0100 |
parents | 9e39c7de8438 |
children | af1bebfd96a4 |
comparison
equal
deleted
inserted
replaced
129:010eb8f0e18d | 130:60bb0fe4563e |
---|---|
56 return new ArrayLiteralExp(loc, arraySyntaxCopy(elements)); | 56 return new ArrayLiteralExp(loc, arraySyntaxCopy(elements)); |
57 } | 57 } |
58 | 58 |
59 override Expression semantic(Scope sc) | 59 override Expression semantic(Scope sc) |
60 { | 60 { |
61 Expression e; | |
62 Type t0 = null; | |
63 | |
64 version (LOGSEMANTIC) { | 61 version (LOGSEMANTIC) { |
65 printf("ArrayLiteralExp.semantic('%s')\n", toChars()); | 62 printf("ArrayLiteralExp.semantic('%s')\n", toChars()); |
66 } | 63 } |
67 if (type) | 64 if (type) |
68 return this; | 65 return this; |
69 | 66 |
70 // Run semantic() on each element | 67 arrayExpressionSemantic(elements, sc); // run semantic() on each element |
71 foreach (ref Expression e; elements) | |
72 { | |
73 e = e.semantic(sc); | |
74 assert(e.type); | |
75 } | |
76 | 68 |
77 expandTuples(elements); | 69 expandTuples(elements); |
78 | 70 |
79 foreach (size_t i, Expression e; elements) | 71 Type t0; |
80 { | 72 elements = arrayExpressionToCommonType(sc, elements, &t0); |
81 if (!e.type) | 73 |
82 error("%s has no value", e.toChars()); | |
83 | |
84 e = resolveProperties(sc, e); | |
85 | |
86 ubyte committed = 1; | |
87 if (e.op == TOKstring) | |
88 committed = (cast(StringExp)e).committed; | |
89 | |
90 if (!t0) | |
91 { | |
92 t0 = e.type; | |
93 // Convert any static arrays to dynamic arrays | |
94 if (t0.ty == Tsarray) | |
95 { | |
96 t0 = (cast(TypeSArray)t0).next.arrayOf(); | |
97 e = e.implicitCastTo(sc, t0); | |
98 } | |
99 } | |
100 else | |
101 e = e.implicitCastTo(sc, t0); | |
102 | |
103 if (!committed && e.op == TOKstring) | |
104 { | |
105 auto se = cast(StringExp)e; | |
106 se.committed = 0; | |
107 } | |
108 elements[i] = e; | |
109 } | |
110 | |
111 if (!t0) | |
112 t0 = Type.tvoid; | |
113 type = new TypeSArray(t0, new IntegerExp(elements.dim)); | 74 type = new TypeSArray(t0, new IntegerExp(elements.dim)); |
114 type = type.semantic(loc, sc); | 75 type = type.semantic(loc, sc); |
115 return this; | 76 return this; |
116 } | 77 } |
117 | 78 |