Remove the concept of crate directive expressions. Issue #604

This commit is contained in:
Brian Anderson 2011-06-30 23:38:40 -07:00
parent bca45720f7
commit d8fe0d7cee
4 changed files with 1 additions and 66 deletions

View File

@ -88,8 +88,6 @@ type crate_ = rec(vec[@crate_directive] directives,
crate_cfg config);
tag crate_directive_ {
cdir_expr(@expr);
// FIXME: cdir_let should be eliminated
// and redirected to the use of const stmt_decls inside
// crate directive blocks.

View File

@ -196,63 +196,6 @@ fn eval_crate_directive_block(ctx cx, &ast::block blk, str prefix,
}
}
fn eval_crate_directive_expr(ctx cx, @ast::expr x, str prefix,
&mutable vec[@ast::view_item] view_items,
&mutable vec[@ast::item] items) {
alt (x.node) {
case (ast::expr_if(?cond, ?thn, ?elopt)) {
auto cv = eval_expr(cx, cond);
if (!val_is_bool(cv)) {
cx.sess.span_fatal(x.span, "bad cond type in 'if'");
}
if (val_as_bool(cv)) {
ret eval_crate_directive_block(cx, thn, prefix, view_items,
items);
}
alt (elopt) {
case (some(?els)) {
ret eval_crate_directive_expr(cx, els, prefix,
view_items, items);
}
case (_) {
// Absent-else is ok.
}
}
}
case (ast::expr_alt(?v, ?arms)) {
auto vv = eval_expr(cx, v);
for (ast::arm arm in arms) {
alt (arm.pat.node) {
case (ast::pat_lit(?lit, _)) {
auto pv = eval_lit(cx, arm.pat.span, lit);
if (val_eq(cx.sess, arm.pat.span, vv, pv)) {
ret eval_crate_directive_block(cx, arm.block,
prefix, view_items,
items);
}
}
case (ast::pat_wild(_)) {
ret eval_crate_directive_block(cx, arm.block,
prefix, view_items,
items);
}
case (_) {
cx.sess.span_fatal(arm.pat.span,
"bad pattern type in 'alt'");
}
}
}
cx.sess.span_fatal(x.span, "no cases matched in 'alt'");
}
case (ast::expr_block(?block)) {
ret eval_crate_directive_block(cx, block, prefix, view_items,
items);
}
case (_) { cx.sess.span_fatal(x.span, "unsupported expr type"); }
}
}
fn eval_crate_directive(ctx cx, @ast::crate_directive cdir, str prefix,
&mutable vec[@ast::view_item] view_items,
&mutable vec[@ast::item] items) {
@ -261,9 +204,6 @@ fn eval_crate_directive(ctx cx, @ast::crate_directive cdir, str prefix,
auto v = eval_expr(cx, x);
eval_crate_directives(cx, cdirs, prefix, view_items, items);
}
case (ast::cdir_expr(?x)) {
eval_crate_directive_expr(cx, x, prefix, view_items, items);
}
case (ast::cdir_src_mod(?id, ?file_opt, ?attrs)) {
auto file_path = id + ".rs";
alt (file_opt) {

View File

@ -139,7 +139,6 @@ fn noop_fold_crate(&crate_ c, ast_fold fld) -> crate_ {
fn noop_fold_crate_directive(&crate_directive_ cd, ast_fold fld)
-> crate_directive_ {
ret alt(cd) {
case(cdir_expr(?e)) { cdir_expr(fld.fold_expr(e)) }
case(cdir_let(?id, ?e, ?cds)) {
cdir_let(fld.fold_ident(id), fld.fold_expr(e),
map(fld.fold_crate_directive, cds))

View File

@ -2412,10 +2412,8 @@ fn parse_crate_directive(&parser p, vec[ast::attribute] first_outer_attr)
auto vi = parse_view_item(p);
ret spanned(lo, vi.span.hi, ast::cdir_view_item(vi));
} else {
auto x = parse_expr(p);
ret spanned(lo, x.span.hi, ast::cdir_expr(x));
ret p.fatal("expected crate directive");
}
fail;
}
fn parse_crate_directives(&parser p, token::token term,