From 2a24e22bcaa4208b2593462126390f07f5600f69 Mon Sep 17 00:00:00 2001 From: Michael Norrish Date: Wed, 29 Apr 2015 11:59:03 +1000 Subject: [PATCH] Standalone parser now handles large enum consts Even if the value given to the constant inside the enum was "just" 2147483647, the loop that processed enumeration declarations would then add 1 to that number, and in mlton, this would cause an Overflow exception. By using IntInf in this position, mlton does the right thing, and Poly/ML's behaviour is completely unchanged. --- tools/c-parser/Absyn-Expr.ML | 6 +++--- tools/c-parser/program_analysis.ML | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/c-parser/Absyn-Expr.ML b/tools/c-parser/Absyn-Expr.ML index d41a27d27..b9e9f7148 100644 --- a/tools/c-parser/Absyn-Expr.ML +++ b/tools/c-parser/Absyn-Expr.ML @@ -59,7 +59,7 @@ and designator = datatype ecenv = - CE of {enumenv : (int * string option) Symtab.table, + CE of {enumenv : (IntInf.int * string option) Symtab.table, (* lookup is from econst name to value and the name of the type it belongs to, if any (they can be anonymous) *) @@ -111,7 +111,7 @@ sig datatype ecenv = datatype ExprDatatype.ecenv (* "enumerated constant environment" *) - val eclookup : ecenv -> string -> (int * string option) option + val eclookup : ecenv -> string -> (IntInf.int * string option) option val constify_abtype : ecenv -> expr CType.ctype -> int CType.ctype val consteval : ecenv -> expr -> IntInf.int @@ -428,7 +428,7 @@ in in case Symtab.lookup enumenv s of NONE => Fail ("Variable "^s^ " can't appear in a constant expression") - | SOME (v, _) => (fi v, Signed Int) + | SOME (v, _) => (v, Signed Int) end | StructDot _ => Fail "Can't evaluate fieldref in constant expression" diff --git a/tools/c-parser/program_analysis.ML b/tools/c-parser/program_analysis.ML index 55bfbe379..f3f6cce79 100644 --- a/tools/c-parser/program_analysis.ML +++ b/tools/c-parser/program_analysis.ML @@ -261,7 +261,7 @@ datatype csenv (* CalculateState environment *) = scope : var_info Symtab.table list, array_mentions : (int ctype * int) Binaryset.set, enumenv : string wrap list * - (int * string option) Symtab.table, + (IntInf.int * string option) Symtab.table, globinits : Absyn.expr MSymTab.table, heaptypes : int ctype Binaryset.set, call_info : fncall_type Binaryset.set Symtab.table, @@ -769,7 +769,7 @@ fun process_enumdecl (enameopt_w,econsts) env = let | NONE => let val e_val = case eopt of NONE => i - | SOME e => IntInf.toInt (consteval (cse2ecenv env) e) + | SOME e => consteval (cse2ecenv env) e val tab' = Symtab.update(node ecn_w, (e_val, node enameopt_w)) alist in (e_val + 1, ecn_w::set, tab')