summary refs log tree commit diff
path: root/src/comp/syntax
diff options
context:
space:
mode:
authorKevin Atkinson <kevina@cs.utah.edu>2012-01-16 02:36:47 -0700
committerMarijn Haverbeke <marijnh@gmail.com>2012-01-16 11:19:33 +0100
commite1c50c4410804dfce9fbe040f341f6104cc9ba7e (patch)
tree5afd49a9f0b209d2853f991532297a315d342b13 /src/comp/syntax
parentedf11ebf021dba897e5419cca53de3b652670799 (diff)
downloadrust-e1c50c4410804dfce9fbe040f341f6104cc9ba7e.tar.gz
rust-e1c50c4410804dfce9fbe040f341f6104cc9ba7e.zip
Don't evaluate discriminator value constants when parsing.
Remove disr_val from ast::variant_ and always use ty::variant_info
when the value is needed.  Move what was done during parsing into
other passes, primary typeck.rs.  This move also correctly type checks
the disr. value expression; thus, fixing rustc --pretty=typed when
disr. values are used.
Diffstat (limited to 'src/comp/syntax')
-rw-r--r--src/comp/syntax/ast.rs2
-rw-r--r--src/comp/syntax/ast_util.rs3
-rw-r--r--src/comp/syntax/fold.rs17
-rw-r--r--src/comp/syntax/parse/parser.rs29
4 files changed, 8 insertions, 43 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs
index 4ce4e1ab111..b953362b1be 100644
--- a/src/comp/syntax/ast.rs
+++ b/src/comp/syntax/ast.rs
@@ -409,7 +409,7 @@ type native_mod =
 type variant_arg = {ty: @ty, id: node_id};
 
 type variant_ = {name: ident, args: [variant_arg], id: node_id,
-                disr_val: int, disr_expr: option::t<@expr>};
+                 disr_expr: option::t<@expr>};
 
 type variant = spanned<variant_>;
 
diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs
index 4ee2d8fa51e..eaac7fa9596 100644
--- a/src/comp/syntax/ast_util.rs
+++ b/src/comp/syntax/ast_util.rs
@@ -241,8 +241,7 @@ tag const_val {
     const_str(str);
 }
 
-// FIXME (#1417): any function that uses this function should likely be moved
-// into the middle end
+// FIXME: issue #1417
 fn eval_const_expr(e: @expr) -> const_val {
     fn fromb(b: bool) -> const_val { const_int(b as i64) }
     alt e.node {
diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs
index 54684bca83b..e74e1cd9ba7 100644
--- a/src/comp/syntax/fold.rs
+++ b/src/comp/syntax/fold.rs
@@ -432,21 +432,12 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
     }
     let fold_variant_arg = bind fold_variant_arg_(_, fld);
     let args = vec::map(v.args, fold_variant_arg);
-    let (de, dv) = alt v.disr_expr {
-      some(e) {
-        let de = fld.fold_expr(e);
-        // FIXME (#1417): see parser.rs
-        let dv = alt syntax::ast_util::eval_const_expr(e) {
-          ast_util::const_int(val) {
-            val as int
-          }
-        };
-        (some(de), dv)
-      }
-      none. { (none, v.disr_val) }
+    let de = alt v.disr_expr {
+      some(e) {some(fld.fold_expr(e))}
+      none. {none}
     };
     ret {name: v.name, args: args, id: v.id,
-         disr_val: dv,  disr_expr: de};
+         disr_expr: de};
 }
 
 fn noop_fold_ident(&&i: ident, _fld: ast_fold) -> ident { ret i; }
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 3f5cae0a161..ef65a0bd897 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -2023,7 +2023,6 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
                     {name: id,
                      args: [{ty: ty, id: p.get_id()}],
                      id: p.get_id(),
-                     disr_val: 0,
                      disr_expr: none});
         ret mk_item(p, lo, ty.span.hi, id,
                     ast::item_tag([variant], ty_params), attrs);
@@ -2031,7 +2030,6 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
     expect(p, token::LBRACE);
     let all_nullary = true;
     let have_disr = false;
-    let disr_val = 0;
     while p.token != token::RBRACE {
         let tok = p.token;
         alt tok {
@@ -2056,38 +2054,15 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
               token::EQ. {
                 have_disr = true;
                 p.bump();
-                let e = parse_expr(p);
-                // FIXME: eval_const_expr does no error checking, nor do I.
-                // Also, the parser is not the right place to do this; likely
-                // somewhere in the middle end so that constants can be
-                // refereed to, even if they are after the declaration for the
-                // type.  Finally, eval_const_expr probably shouldn't exist as
-                // it Graydon puts it: "[I] am a little worried at its
-                // presence since it quasi-duplicates stuff that trans should
-                // probably be doing."  (See issue #1417)
-                alt syntax::ast_util::eval_const_expr(e) {
-                  syntax::ast_util::const_int(val) {
-                    // FIXME: check that value is in range
-                    disr_val = val as int;
-                  }
-                }
-                if option::is_some
-                    (vec::find
-                     (variants, {|v| v.node.disr_val == disr_val}))
-                {
-                    p.fatal("discriminator value " + /* str(disr_val) + */
-                            "already exists.");
-                }
-                disr_expr = some(e);
+                disr_expr = some(parse_expr(p));
               }
               _ {/* empty */ }
             }
             expect(p, token::SEMI);
             p.get_id();
             let vr = {name: p.get_str(name), args: args, id: p.get_id(),
-                      disr_val: disr_val, disr_expr: disr_expr};
+                      disr_expr: disr_expr};
             variants += [spanned(vlo, vhi, vr)];
-            disr_val += 1;
           }
           token::RBRACE. {/* empty */ }
           _ {