Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
middle: Add a pass to reject bad const expressions earlier. Currently…
… just rejects unimplemented const expressions, but will be needed later.
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import syntax::ast::*; | ||
import syntax::ast_util::{variant_def_ids, dummy_sp}; | ||
import syntax::visit; | ||
|
||
fn check_crate(tcx: ty::ctxt, crate: @crate) { | ||
let v = | ||
@{visit_item: bind check_item(tcx, _, _, _) | ||
with *visit::default_visitor::<()>()}; | ||
visit::visit_crate(*crate, (), visit::mk_vt(v)); | ||
tcx.sess.abort_if_errors(); | ||
} | ||
|
||
fn check_item(tcx: ty::ctxt, it: @item, &&s: (), v: visit::vt<()>) { | ||
visit::visit_item(it, s, v); | ||
alt it.node { | ||
item_const(_ /* ty */, ex) { | ||
let v = | ||
@{visit_expr: bind check_const_expr(tcx, _, _, _) | ||
with *visit::default_visitor::<()>()}; | ||
check_const_expr(tcx, ex, (), visit::mk_vt(v)); | ||
} | ||
_ { } | ||
} | ||
} | ||
|
||
fn check_const_expr(tcx: ty::ctxt, ex: @expr, &&s: (), v: visit::vt<()>) { | ||
visit::visit_expr(ex, s, v); | ||
alt ex.node { | ||
expr_lit(_) { } | ||
_ { tcx.sess.span_err(ex.span, | ||
"constant contains unimplemented expression type"); } | ||
} | ||
} | ||
|
||
// Local Variables: | ||
// mode: rust | ||
// fill-column: 78; | ||
// indent-tabs-mode: nil | ||
// c-basic-offset: 4 | ||
// buffer-file-coding-system: utf-8-unix | ||
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; | ||
// End: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters