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.
This commit is contained in:
Michael Norrish 2015-04-29 11:59:03 +10:00
parent b5b9248583
commit 2a24e22bca
2 changed files with 5 additions and 5 deletions

View File

@ -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"

View File

@ -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')