blob: 028fdd52a26512f36c246a954664ad551d46a727 [file] [log] [blame]
Niko Matsakis86b6e6e2013-05-10 17:10:351// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11use middle::cfg::*;
12use middle::graph;
13use middle::typeck;
14use middle::ty;
15use std::hashmap::HashMap;
16use syntax::ast;
17use syntax::ast_util;
18use syntax::opt_vec;
19
20struct CFGBuilder {
21 tcx: ty::ctxt,
22 method_map: typeck::method_map,
Michael Woerister8a329772013-07-27 08:25:5923 exit_map: HashMap<ast::NodeId, CFGIndex>,
Niko Matsakis86b6e6e2013-05-10 17:10:3524 graph: CFGGraph,
25 loop_scopes: ~[LoopScope],
26}
27
28struct LoopScope {
Michael Woerister8a329772013-07-27 08:25:5929 loop_id: ast::NodeId, // id of loop/while node
Niko Matsakis86b6e6e2013-05-10 17:10:3530 continue_index: CFGIndex, // where to go on a `loop`
31 break_index: CFGIndex, // where to go on a `break
32}
33
34pub fn construct(tcx: ty::ctxt,
35 method_map: typeck::method_map,
Michael Woerister4bd14242013-07-19 05:38:5536 blk: &ast::Block) -> CFG {
Niko Matsakis86b6e6e2013-05-10 17:10:3537 let mut cfg_builder = CFGBuilder {
38 exit_map: HashMap::new(),
39 graph: graph::Graph::new(),
40 tcx: tcx,
41 method_map: method_map,
42 loop_scopes: ~[]
43 };
44 let entry = cfg_builder.add_node(0, []);
45 let exit = cfg_builder.block(blk, entry);
Alex Crichtonab387a62013-11-28 20:22:5346 let CFGBuilder {exit_map, graph, ..} = cfg_builder;
Niko Matsakis86b6e6e2013-05-10 17:10:3547 CFG {exit_map: exit_map,
48 graph: graph,
49 entry: entry,
50 exit: exit}
51}
52
53impl CFGBuilder {
Michael Woerister4bd14242013-07-19 05:38:5554 fn block(&mut self, blk: &ast::Block, pred: CFGIndex) -> CFGIndex {
Niko Matsakis86b6e6e2013-05-10 17:10:3555 let mut stmts_exit = pred;
Daniel Micay100894552013-08-03 16:45:2356 for &stmt in blk.stmts.iter() {
Niko Matsakis86b6e6e2013-05-10 17:10:3557 stmts_exit = self.stmt(stmt, stmts_exit);
58 }
59
Michael Woerister0cc70742013-07-16 18:08:3560 let expr_exit = self.opt_expr(blk.expr, stmts_exit);
Niko Matsakis86b6e6e2013-05-10 17:10:3561
Michael Woerister0cc70742013-07-16 18:08:3562 self.add_node(blk.id, [expr_exit])
Niko Matsakis86b6e6e2013-05-10 17:10:3563 }
64
Marvin Löbel74190852013-09-02 01:45:3765 fn stmt(&mut self, stmt: @ast::Stmt, pred: CFGIndex) -> CFGIndex {
Niko Matsakis86b6e6e2013-05-10 17:10:3566 match stmt.node {
Marvin Löbel74190852013-09-02 01:45:3767 ast::StmtDecl(decl, _) => {
Niko Matsakis86b6e6e2013-05-10 17:10:3568 self.decl(decl, pred)
69 }
70
Marvin Löbel74190852013-09-02 01:45:3771 ast::StmtExpr(expr, _) | ast::StmtSemi(expr, _) => {
Niko Matsakis86b6e6e2013-05-10 17:10:3572 self.expr(expr, pred)
73 }
74
Alex Crichtonab387a62013-11-28 20:22:5375 ast::StmtMac(..) => {
Niko Matsakis86b6e6e2013-05-10 17:10:3576 self.tcx.sess.span_bug(stmt.span, "unexpanded macro");
77 }
78 }
79 }
80
Marvin Löbel74190852013-09-02 01:45:3781 fn decl(&mut self, decl: @ast::Decl, pred: CFGIndex) -> CFGIndex {
Niko Matsakis86b6e6e2013-05-10 17:10:3582 match decl.node {
Marvin Löbel74190852013-09-02 01:45:3783 ast::DeclLocal(local) => {
Michael Woerister4bd14242013-07-19 05:38:5584 let init_exit = self.opt_expr(local.init, pred);
85 self.pat(local.pat, init_exit)
Niko Matsakis86b6e6e2013-05-10 17:10:3586 }
87
Marvin Löbel74190852013-09-02 01:45:3788 ast::DeclItem(_) => {
Niko Matsakis86b6e6e2013-05-10 17:10:3589 pred
90 }
91 }
92 }
93
Marvin Löbel74190852013-09-02 01:45:3794 fn pat(&mut self, pat: @ast::Pat, pred: CFGIndex) -> CFGIndex {
Niko Matsakis86b6e6e2013-05-10 17:10:3595 match pat.node {
Marvin Löbel74190852013-09-02 01:45:3796 ast::PatIdent(_, _, None) |
97 ast::PatEnum(_, None) |
Alex Crichtonab387a62013-11-28 20:22:5398 ast::PatLit(..) |
99 ast::PatRange(..) |
Brian Anderson85f107d2013-11-08 03:25:39100 ast::PatWild | ast::PatWildMulti => {
Niko Matsakis86b6e6e2013-05-10 17:10:35101 self.add_node(pat.id, [pred])
102 }
103
Marvin Löbel74190852013-09-02 01:45:37104 ast::PatBox(subpat) |
105 ast::PatUniq(subpat) |
106 ast::PatRegion(subpat) |
107 ast::PatIdent(_, _, Some(subpat)) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35108 let subpat_exit = self.pat(subpat, pred);
109 self.add_node(pat.id, [subpat_exit])
110 }
111
Marvin Löbel74190852013-09-02 01:45:37112 ast::PatEnum(_, Some(ref subpats)) |
113 ast::PatTup(ref subpats) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35114 let pats_exit =
Erick Tryzelaar68f40d22013-08-10 03:09:47115 self.pats_all(subpats.iter().map(|p| *p), pred);
Niko Matsakis86b6e6e2013-05-10 17:10:35116 self.add_node(pat.id, [pats_exit])
117 }
118
Marvin Löbel74190852013-09-02 01:45:37119 ast::PatStruct(_, ref subpats, _) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35120 let pats_exit =
Erick Tryzelaar68f40d22013-08-10 03:09:47121 self.pats_all(subpats.iter().map(|f| f.pat), pred);
Niko Matsakis86b6e6e2013-05-10 17:10:35122 self.add_node(pat.id, [pats_exit])
123 }
124
Marvin Löbel74190852013-09-02 01:45:37125 ast::PatVec(ref pre, ref vec, ref post) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35126 let pre_exit =
Erick Tryzelaar68f40d22013-08-10 03:09:47127 self.pats_all(pre.iter().map(|p| *p), pred);
Niko Matsakis86b6e6e2013-05-10 17:10:35128 let vec_exit =
Erick Tryzelaar68f40d22013-08-10 03:09:47129 self.pats_all(vec.iter().map(|p| *p), pre_exit);
Niko Matsakis86b6e6e2013-05-10 17:10:35130 let post_exit =
Erick Tryzelaar68f40d22013-08-10 03:09:47131 self.pats_all(post.iter().map(|p| *p), vec_exit);
Niko Matsakis86b6e6e2013-05-10 17:10:35132 self.add_node(pat.id, [post_exit])
133 }
134 }
135 }
136
Marvin Löbel74190852013-09-02 01:45:37137 fn pats_all<I: Iterator<@ast::Pat>>(&mut self,
Niko Matsakis86b6e6e2013-05-10 17:10:35138 pats: I,
139 pred: CFGIndex) -> CFGIndex {
140 //! Handles case where all of the patterns must match.
141 let mut pats = pats;
142 pats.fold(pred, |pred, pat| self.pat(pat, pred))
143 }
144
145 fn pats_any(&mut self,
Marvin Löbel74190852013-09-02 01:45:37146 pats: &[@ast::Pat],
Niko Matsakis86b6e6e2013-05-10 17:10:35147 pred: CFGIndex) -> CFGIndex {
148 //! Handles case where just one of the patterns must match.
149
150 if pats.len() == 1 {
151 self.pat(pats[0], pred)
152 } else {
153 let collect = self.add_dummy_node([]);
Daniel Micay100894552013-08-03 16:45:23154 for &pat in pats.iter() {
Niko Matsakis86b6e6e2013-05-10 17:10:35155 let pat_exit = self.pat(pat, pred);
156 self.add_contained_edge(pat_exit, collect);
157 }
158 collect
159 }
160 }
161
Marvin Löbel74190852013-09-02 01:45:37162 fn expr(&mut self, expr: @ast::Expr, pred: CFGIndex) -> CFGIndex {
Niko Matsakis86b6e6e2013-05-10 17:10:35163 match expr.node {
Marvin Löbel74190852013-09-02 01:45:37164 ast::ExprBlock(ref blk) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35165 let blk_exit = self.block(blk, pred);
166 self.add_node(expr.id, [blk_exit])
167 }
168
Marvin Löbel74190852013-09-02 01:45:37169 ast::ExprIf(cond, ref then, None) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35170 //
171 // [pred]
172 // |
173 // v 1
174 // [cond]
175 // |
176 // / \
177 // / \
178 // v 2 *
179 // [then] |
180 // | |
181 // v 3 v 4
182 // [..expr..]
183 //
184 let cond_exit = self.expr(cond, pred); // 1
185 let then_exit = self.block(then, cond_exit); // 2
186 self.add_node(expr.id, [cond_exit, then_exit]) // 3,4
187 }
188
Marvin Löbel74190852013-09-02 01:45:37189 ast::ExprIf(cond, ref then, Some(otherwise)) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35190 //
191 // [pred]
192 // |
193 // v 1
194 // [cond]
195 // |
196 // / \
197 // / \
198 // v 2 v 3
199 // [then][otherwise]
200 // | |
201 // v 4 v 5
202 // [..expr..]
203 //
204 let cond_exit = self.expr(cond, pred); // 1
205 let then_exit = self.block(then, cond_exit); // 2
206 let else_exit = self.expr(otherwise, cond_exit); // 3
207 self.add_node(expr.id, [then_exit, else_exit]) // 4, 5
208 }
209
Marvin Löbel74190852013-09-02 01:45:37210 ast::ExprWhile(cond, ref body) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35211 //
212 // [pred]
213 // |
214 // v 1
215 // [loopback] <--+ 5
216 // | |
217 // v 2 |
218 // +-----[cond] |
219 // | | |
220 // | v 4 |
221 // | [body] -----+
222 // v 3
223 // [expr]
224 //
225 // Note that `break` and `loop` statements
226 // may cause additional edges.
227
Michael Sullivan7dbc5ae2013-07-30 23:47:22228 // Is the condition considered part of the loop?
Niko Matsakis86b6e6e2013-05-10 17:10:35229 let loopback = self.add_dummy_node([pred]); // 1
230 let cond_exit = self.expr(cond, loopback); // 2
231 let expr_exit = self.add_node(expr.id, [cond_exit]); // 3
232 self.loop_scopes.push(LoopScope {
233 loop_id: expr.id,
234 continue_index: loopback,
235 break_index: expr_exit
236 });
237 let body_exit = self.block(body, cond_exit); // 4
238 self.add_contained_edge(body_exit, loopback); // 5
239 expr_exit
240 }
241
Alex Crichtonab387a62013-11-28 20:22:53242 ast::ExprForLoop(..) => fail!("non-desugared expr_for_loop"),
Graydon Hoarec29e9fb2013-07-30 00:25:00243
Marvin Löbel74190852013-09-02 01:45:37244 ast::ExprLoop(ref body, _) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35245 //
246 // [pred]
247 // |
248 // v 1
249 // [loopback] <---+
250 // | 4 |
251 // v 3 |
252 // [body] ------+
253 //
254 // [expr] 2
255 //
256 // Note that `break` and `loop` statements
257 // may cause additional edges.
258
259 let loopback = self.add_dummy_node([pred]); // 1
260 let expr_exit = self.add_node(expr.id, []); // 2
261 self.loop_scopes.push(LoopScope {
262 loop_id: expr.id,
263 continue_index: loopback,
264 break_index: expr_exit,
265 });
266 let body_exit = self.block(body, loopback); // 3
267 self.add_contained_edge(body_exit, loopback); // 4
268 self.loop_scopes.pop();
269 expr_exit
270 }
271
Marvin Löbel74190852013-09-02 01:45:37272 ast::ExprMatch(discr, ref arms) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35273 //
274 // [pred]
275 // |
276 // v 1
277 // [discr]
278 // |
279 // v 2
280 // [guard1]
281 // / \
282 // | \
283 // v 3 |
284 // [pat1] |
285 // |
286 // v 4 |
287 // [body1] v
288 // | [guard2]
289 // | / \
290 // | [body2] \
291 // | | ...
292 // | | |
293 // v 5 v v
294 // [....expr....]
295 //
296 let discr_exit = self.expr(discr, pred); // 1
297
298 let expr_exit = self.add_node(expr.id, []);
299 let mut guard_exit = discr_exit;
Daniel Micay100894552013-08-03 16:45:23300 for arm in arms.iter() {
Niko Matsakis86b6e6e2013-05-10 17:10:35301 guard_exit = self.opt_expr(arm.guard, guard_exit); // 2
302 let pats_exit = self.pats_any(arm.pats, guard_exit); // 3
303 let body_exit = self.block(&arm.body, pats_exit); // 4
304 self.add_contained_edge(body_exit, expr_exit); // 5
305 }
306 expr_exit
307 }
308
Marvin Löbel74190852013-09-02 01:45:37309 ast::ExprBinary(_, op, l, r) if ast_util::lazy_binop(op) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35310 //
311 // [pred]
312 // |
313 // v 1
314 // [l]
315 // |
316 // / \
317 // / \
318 // v 2 *
319 // [r] |
320 // | |
321 // v 3 v 4
322 // [..exit..]
323 //
324 let l_exit = self.expr(l, pred); // 1
325 let r_exit = self.expr(r, l_exit); // 2
326 self.add_node(expr.id, [l_exit, r_exit]) // 3,4
327 }
328
Marvin Löbel74190852013-09-02 01:45:37329 ast::ExprRet(v) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35330 let v_exit = self.opt_expr(v, pred);
331 let loop_scope = self.loop_scopes[0];
332 self.add_exiting_edge(expr, v_exit,
333 loop_scope, loop_scope.break_index);
334 self.add_node(expr.id, [])
335 }
336
Marvin Löbel74190852013-09-02 01:45:37337 ast::ExprBreak(label) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35338 let loop_scope = self.find_scope(expr, label);
339 self.add_exiting_edge(expr, pred,
340 loop_scope, loop_scope.break_index);
341 self.add_node(expr.id, [])
342 }
343
Marvin Löbel74190852013-09-02 01:45:37344 ast::ExprAgain(label) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35345 let loop_scope = self.find_scope(expr, label);
346 self.add_exiting_edge(expr, pred,
347 loop_scope, loop_scope.continue_index);
348 self.add_node(expr.id, [])
349 }
350
Marvin Löbel74190852013-09-02 01:45:37351 ast::ExprVec(ref elems, _) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35352 self.straightline(expr, pred, *elems)
353 }
354
Marvin Löbel74190852013-09-02 01:45:37355 ast::ExprCall(func, ref args, _) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35356 self.call(expr, pred, func, *args)
357 }
358
Marvin Löbel74190852013-09-02 01:45:37359 ast::ExprMethodCall(_, rcvr, _, _, ref args, _) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35360 self.call(expr, pred, rcvr, *args)
361 }
362
Marvin Löbel74190852013-09-02 01:45:37363 ast::ExprIndex(_, l, r) |
364 ast::ExprBinary(_, _, l, r) if self.is_method_call(expr) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35365 self.call(expr, pred, l, [r])
366 }
367
Marvin Löbel74190852013-09-02 01:45:37368 ast::ExprUnary(_, _, e) if self.is_method_call(expr) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35369 self.call(expr, pred, e, [])
370 }
371
Marvin Löbel74190852013-09-02 01:45:37372 ast::ExprTup(ref exprs) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35373 self.straightline(expr, pred, *exprs)
374 }
375
Marvin Löbel74190852013-09-02 01:45:37376 ast::ExprStruct(_, ref fields, base) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35377 let base_exit = self.opt_expr(base, pred);
Marvin Löbel74190852013-09-02 01:45:37378 let field_exprs: ~[@ast::Expr] =
Erick Tryzelaar68f40d22013-08-10 03:09:47379 fields.iter().map(|f| f.expr).collect();
Niko Matsakis86b6e6e2013-05-10 17:10:35380 self.straightline(expr, base_exit, field_exprs)
381 }
382
Marvin Löbel74190852013-09-02 01:45:37383 ast::ExprRepeat(elem, count, _) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35384 self.straightline(expr, pred, [elem, count])
385 }
386
Marvin Löbel74190852013-09-02 01:45:37387 ast::ExprAssign(l, r) |
388 ast::ExprAssignOp(_, _, l, r) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35389 self.straightline(expr, pred, [r, l])
390 }
391
Marvin Löbel74190852013-09-02 01:45:37392 ast::ExprIndex(_, l, r) |
393 ast::ExprBinary(_, _, l, r) => { // NB: && and || handled earlier
Niko Matsakis86b6e6e2013-05-10 17:10:35394 self.straightline(expr, pred, [l, r])
395 }
396
Marvin Löbel74190852013-09-02 01:45:37397 ast::ExprAddrOf(_, e) |
398 ast::ExprDoBody(e) |
399 ast::ExprCast(e, _) |
400 ast::ExprUnary(_, _, e) |
401 ast::ExprParen(e) |
402 ast::ExprVstore(e, _) |
403 ast::ExprField(e, _, _) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35404 self.straightline(expr, pred, [e])
405 }
406
Alex Crichton8a966182013-08-28 06:12:05407 ast::ExprLogLevel |
Alex Crichtonab387a62013-11-28 20:22:53408 ast::ExprMac(..) |
409 ast::ExprInlineAsm(..) |
Marvin Löbel74190852013-09-02 01:45:37410 ast::ExprSelf |
Alex Crichtonab387a62013-11-28 20:22:53411 ast::ExprFnBlock(..) |
412 ast::ExprProc(..) |
413 ast::ExprLit(..) |
414 ast::ExprPath(..) => {
Niko Matsakis86b6e6e2013-05-10 17:10:35415 self.straightline(expr, pred, [])
416 }
417 }
418 }
419
420 fn call(&mut self,
Marvin Löbel74190852013-09-02 01:45:37421 call_expr: @ast::Expr,
Niko Matsakis86b6e6e2013-05-10 17:10:35422 pred: CFGIndex,
Marvin Löbel74190852013-09-02 01:45:37423 func_or_rcvr: @ast::Expr,
424 args: &[@ast::Expr]) -> CFGIndex {
Niko Matsakis86b6e6e2013-05-10 17:10:35425 let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
426 self.straightline(call_expr, func_or_rcvr_exit, args)
427 }
428
429 fn exprs(&mut self,
Marvin Löbel74190852013-09-02 01:45:37430 exprs: &[@ast::Expr],
Niko Matsakis86b6e6e2013-05-10 17:10:35431 pred: CFGIndex) -> CFGIndex {
432 //! Constructs graph for `exprs` evaluated in order
433
434 exprs.iter().fold(pred, |p, &e| self.expr(e, p))
435 }
436
437 fn opt_expr(&mut self,
Marvin Löbel74190852013-09-02 01:45:37438 opt_expr: Option<@ast::Expr>,
Niko Matsakis86b6e6e2013-05-10 17:10:35439 pred: CFGIndex) -> CFGIndex {
440 //! Constructs graph for `opt_expr` evaluated, if Some
441
442 opt_expr.iter().fold(pred, |p, &e| self.expr(e, p))
443 }
444
445 fn straightline(&mut self,
Marvin Löbel74190852013-09-02 01:45:37446 expr: @ast::Expr,
Niko Matsakis86b6e6e2013-05-10 17:10:35447 pred: CFGIndex,
Marvin Löbel74190852013-09-02 01:45:37448 subexprs: &[@ast::Expr]) -> CFGIndex {
Niko Matsakis86b6e6e2013-05-10 17:10:35449 //! Handles case of an expression that evaluates `subexprs` in order
450
451 let subexprs_exit = self.exprs(subexprs, pred);
452 self.add_node(expr.id, [subexprs_exit])
453 }
454
455 fn add_dummy_node(&mut self, preds: &[CFGIndex]) -> CFGIndex {
456 self.add_node(0, preds)
457 }
458
Michael Woerister8a329772013-07-27 08:25:59459 fn add_node(&mut self, id: ast::NodeId, preds: &[CFGIndex]) -> CFGIndex {
Niko Matsakis86b6e6e2013-05-10 17:10:35460 assert!(!self.exit_map.contains_key(&id));
461 let node = self.graph.add_node(CFGNodeData {id: id});
462 self.exit_map.insert(id, node);
Daniel Micay100894552013-08-03 16:45:23463 for &pred in preds.iter() {
Niko Matsakis86b6e6e2013-05-10 17:10:35464 self.add_contained_edge(pred, node);
465 }
466 node
467 }
468
469 fn add_contained_edge(&mut self,
470 source: CFGIndex,
471 target: CFGIndex) {
472 let data = CFGEdgeData {exiting_scopes: opt_vec::Empty};
473 self.graph.add_edge(source, target, data);
474 }
475
476 fn add_exiting_edge(&mut self,
Marvin Löbel74190852013-09-02 01:45:37477 from_expr: @ast::Expr,
Niko Matsakis86b6e6e2013-05-10 17:10:35478 from_index: CFGIndex,
479 to_loop: LoopScope,
480 to_index: CFGIndex) {
481 let mut data = CFGEdgeData {exiting_scopes: opt_vec::Empty};
482 let mut scope_id = from_expr.id;
483 while scope_id != to_loop.loop_id {
484 data.exiting_scopes.push(scope_id);
485 scope_id = self.tcx.region_maps.encl_scope(scope_id);
486 }
487 self.graph.add_edge(from_index, to_index, data);
488 }
489
490 fn find_scope(&self,
Marvin Löbel74190852013-09-02 01:45:37491 expr: @ast::Expr,
John Clements422cf1a2013-09-10 19:01:44492 label: Option<ast::Name>) -> LoopScope {
Niko Matsakis86b6e6e2013-05-10 17:10:35493 match label {
494 None => {
495 return *self.loop_scopes.last();
496 }
497
498 Some(_) => {
499 match self.tcx.def_map.find(&expr.id) {
Marvin Löbel74190852013-09-02 01:45:37500 Some(&ast::DefLabel(loop_id)) => {
Daniel Micay100894552013-08-03 16:45:23501 for l in self.loop_scopes.iter() {
Niko Matsakis86b6e6e2013-05-10 17:10:35502 if l.loop_id == loop_id {
503 return *l;
504 }
505 }
506 self.tcx.sess.span_bug(
507 expr.span,
Alex Crichton1b805582013-09-28 05:38:08508 format!("No loop scope for id {:?}", loop_id));
Niko Matsakis86b6e6e2013-05-10 17:10:35509 }
510
511 r => {
512 self.tcx.sess.span_bug(
513 expr.span,
Alex Crichton1b805582013-09-28 05:38:08514 format!("Bad entry `{:?}` in def_map for label", r));
Niko Matsakis86b6e6e2013-05-10 17:10:35515 }
516 }
517 }
518 }
519 }
520
Marvin Löbel74190852013-09-02 01:45:37521 fn is_method_call(&self, expr: &ast::Expr) -> bool {
Niko Matsakis86b6e6e2013-05-10 17:10:35522 self.method_map.contains_key(&expr.id)
523 }
Patrick Walton99d44d22013-07-10 02:32:09524}