Mercurial > projects > ddmd
comparison dmd/WithStatement.d @ 129:010eb8f0e18d
further work on dmd test suite
author | korDen |
---|---|
date | Sun, 05 Sep 2010 15:32:22 +0400 |
parents | e28b18c23469 |
children | e3afd1303184 |
comparison
equal
deleted
inserted
replaced
128:e6e542f37b94 | 129:010eb8f0e18d |
---|---|
4 import dmd.Statement; | 4 import dmd.Statement; |
5 import dmd.Expression; | 5 import dmd.Expression; |
6 import dmd.VarDeclaration; | 6 import dmd.VarDeclaration; |
7 import dmd.Loc; | 7 import dmd.Loc; |
8 import dmd.OutBuffer; | 8 import dmd.OutBuffer; |
9 import dmd.ScopeDsymbol; | |
10 import dmd.TypeExp; | |
11 import dmd.TOK; | |
12 import dmd.Initializer; | |
13 import dmd.ExpInitializer; | |
14 import dmd.Id; | |
15 import dmd.ScopeExp; | |
16 import dmd.WithScopeSymbol; | |
17 import dmd.TY; | |
18 import dmd.Type; | |
9 import dmd.HdrGenState; | 19 import dmd.HdrGenState; |
10 import dmd.InlineScanState; | 20 import dmd.InlineScanState; |
11 import dmd.IRState; | 21 import dmd.IRState; |
12 import dmd.Scope; | 22 import dmd.Scope; |
13 import dmd.BE; | 23 import dmd.BE; |
24 | |
25 import dmd.backend.Symbol; | |
26 import dmd.backend.block; | |
27 import dmd.backend.Blockx; | |
28 import dmd.backend.elem; | |
29 import dmd.backend.Util; | |
30 import dmd.backend.OPER; | |
14 | 31 |
15 class WithStatement : Statement | 32 class WithStatement : Statement |
16 { | 33 { |
17 Expression exp; | 34 Expression exp; |
18 Statement body_; | 35 Statement body_; |
26 wthis = null; | 43 wthis = null; |
27 } | 44 } |
28 | 45 |
29 override Statement syntaxCopy() | 46 override Statement syntaxCopy() |
30 { | 47 { |
31 assert(false); | 48 WithStatement s = new WithStatement(loc, exp.syntaxCopy(), body_ ? body_.syntaxCopy() : null); |
49 return s; | |
32 } | 50 } |
33 | 51 |
34 override Statement semantic(Scope sc) | 52 override Statement semantic(Scope sc) |
35 { | 53 { |
36 assert(false); | 54 ScopeDsymbol sym; |
55 Initializer init; | |
56 | |
57 //printf("WithStatement.semantic()\n"); | |
58 exp = exp.semantic(sc); | |
59 exp = resolveProperties(sc, exp); | |
60 if (exp.op == TOKimport) | |
61 { | |
62 ScopeExp es = cast(ScopeExp)exp; | |
63 | |
64 sym = es.sds; | |
65 } | |
66 else if (exp.op == TOKtype) | |
67 { | |
68 TypeExp es = cast(TypeExp)exp; | |
69 | |
70 sym = es.type.toDsymbol(sc).isScopeDsymbol(); | |
71 if (!sym) | |
72 { | |
73 error("%s has no members", es.toChars()); | |
74 body_ = body_.semantic(sc); | |
75 return this; | |
76 } | |
77 } | |
78 else | |
79 { | |
80 Type t = exp.type; | |
81 | |
82 assert(t); | |
83 t = t.toBasetype(); | |
84 if (t.isClassHandle()) | |
85 { | |
86 init = new ExpInitializer(loc, exp); | |
87 wthis = new VarDeclaration(loc, exp.type, Id.withSym, init); | |
88 wthis.semantic(sc); | |
89 | |
90 sym = new WithScopeSymbol(this); | |
91 sym.parent = sc.scopesym; | |
92 } | |
93 else if (t.ty == Tstruct) | |
94 { | |
95 Expression e = exp.addressOf(sc); | |
96 init = new ExpInitializer(loc, e); | |
97 wthis = new VarDeclaration(loc, e.type, Id.withSym, init); | |
98 wthis.semantic(sc); | |
99 sym = new WithScopeSymbol(this); | |
100 sym.parent = sc.scopesym; | |
101 } | |
102 else | |
103 { | |
104 error("with expressions must be class objects, not '%s'", exp.type.toChars()); | |
105 return null; | |
106 } | |
107 } | |
108 sc = sc.push(sym); | |
109 | |
110 if (body_) | |
111 body_ = body_.semantic(sc); | |
112 | |
113 sc.pop(); | |
114 | |
115 return this; | |
37 } | 116 } |
38 | 117 |
39 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) | 118 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
40 { | 119 { |
41 assert(false); | 120 assert(false); |
46 assert(false); | 125 assert(false); |
47 } | 126 } |
48 | 127 |
49 override BE blockExit() | 128 override BE blockExit() |
50 { | 129 { |
51 assert(false); | 130 BE result = BEnone; |
131 if (exp.canThrow()) | |
132 result = BEthrow; | |
133 if (body_) | |
134 result |= body_.blockExit(); | |
135 else | |
136 result |= BEfallthru; | |
137 return result; | |
52 } | 138 } |
53 | 139 |
54 override Statement inlineScan(InlineScanState* iss) | 140 override Statement inlineScan(InlineScanState* iss) |
55 { | 141 { |
56 assert(false); | 142 assert(false); |
57 } | 143 } |
58 | 144 |
59 override void toIR(IRState* irs) | 145 override void toIR(IRState* irs) |
60 { | 146 { |
61 assert(false); | 147 Symbol* sp; |
148 elem* e; | |
149 elem* ei; | |
150 ExpInitializer ie; | |
151 Blockx* blx = irs.blx; | |
152 | |
153 //printf("WithStatement.toIR()\n"); | |
154 if (exp.op == TOKimport || exp.op == TOKtype) | |
155 { | |
156 } | |
157 else | |
158 { | |
159 // Declare with handle | |
160 sp = wthis.toSymbol(); | |
161 symbol_add(sp); | |
162 | |
163 // Perform initialization of with handle | |
164 ie = wthis.init.isExpInitializer(); | |
165 assert(ie); | |
166 ei = ie.exp.toElem(irs); | |
167 e = el_var(sp); | |
168 e = el_bin(OPeq,e.Ety, e, ei); | |
169 elem_setLoc(e, loc); | |
170 incUsage(irs, loc); | |
171 block_appendexp(blx.curblock,e); | |
172 } | |
173 // Execute with block | |
174 if (body_) | |
175 body_.toIR(irs); | |
62 } | 176 } |
63 } | 177 } |