Commit 4a1aca10 authored by Isaac Dupree's avatar Isaac Dupree

parseInteger->parseUnsignedInteger to clarify meaning

I decided against adding parseSignedInteger since octal
and hex literals often have junk between the '-' and the
digits, but, compare to Util.readRational which does handle
signed numbers.  Also since Integers - mathematically and
in Haskell - can be negative, normally.
parent a12dcc89
......@@ -180,7 +180,7 @@ global_regN :: (Int -> GlobalReg) -> Action
global_regN con span buf len
= return (L span (CmmT_GlobalReg (con (fromIntegral n))))
where buf' = stepOn buf
n = parseInteger buf' (len-1) 10 octDecDigit
n = parseUnsignedInteger buf' (len-1) 10 octDecDigit
global_reg :: GlobalReg -> Action
global_reg r span buf len = return (L span (CmmT_GlobalReg r))
......@@ -227,13 +227,13 @@ reservedWordsFM = listToUFM $
]
tok_decimal span buf len
= return (L span (CmmT_Int $! parseInteger buf len 10 octDecDigit))
= return (L span (CmmT_Int $! parseUnsignedInteger buf len 10 octDecDigit))
tok_octal span buf len
= return (L span (CmmT_Int $! parseInteger (offsetBytes 1 buf) (len-1) 8 octDecDigit))
= return (L span (CmmT_Int $! parseUnsignedInteger (offsetBytes 1 buf) (len-1) 8 octDecDigit))
tok_hexadecimal span buf len
= return (L span (CmmT_Int $! parseInteger (offsetBytes 2 buf) (len-2) 16 hexDigit))
= return (L span (CmmT_Int $! parseUnsignedInteger (offsetBytes 2 buf) (len-2) 16 hexDigit))
tok_float str = CmmT_Float $! readRational str
......@@ -245,7 +245,7 @@ tok_string str = CmmT_String (read str)
setLine :: Int -> Action
setLine code span buf len = do
let line = parseInteger buf len 10 octDecDigit
let line = parseUnsignedInteger buf len 10 octDecDigit
setSrcLoc (mkSrcLoc (srcSpanFile span) (fromIntegral line - 1) 0)
-- subtract one: the line number refers to the *following* line
-- trace ("setLine " ++ show line) $ do
......
......@@ -935,22 +935,22 @@ sym con span buf len =
fs = lexemeToFastString buf len
tok_decimal span buf len
= return (L span (ITinteger $! parseInteger buf len 10 octDecDigit))
= return (L span (ITinteger $! parseUnsignedInteger buf len 10 octDecDigit))
tok_octal span buf len
= return (L span (ITinteger $! parseInteger (offsetBytes 2 buf) (len-2) 8 octDecDigit))
= return (L span (ITinteger $! parseUnsignedInteger (offsetBytes 2 buf) (len-2) 8 octDecDigit))
tok_hexadecimal span buf len
= return (L span (ITinteger $! parseInteger (offsetBytes 2 buf) (len-2) 16 hexDigit))
= return (L span (ITinteger $! parseUnsignedInteger (offsetBytes 2 buf) (len-2) 16 hexDigit))
prim_decimal span buf len
= return (L span (ITprimint $! parseInteger buf (len-1) 10 octDecDigit))
= return (L span (ITprimint $! parseUnsignedInteger buf (len-1) 10 octDecDigit))
prim_octal span buf len
= return (L span (ITprimint $! parseInteger (offsetBytes 2 buf) (len-3) 8 octDecDigit))
= return (L span (ITprimint $! parseUnsignedInteger (offsetBytes 2 buf) (len-3) 8 octDecDigit))
prim_hexadecimal span buf len
= return (L span (ITprimint $! parseInteger (offsetBytes 2 buf) (len-3) 16 hexDigit))
= return (L span (ITprimint $! parseUnsignedInteger (offsetBytes 2 buf) (len-3) 16 hexDigit))
tok_float str = ITrational $! readRational str
prim_float str = ITprimfloat $! readRational str
......@@ -1022,7 +1022,7 @@ do_layout_left span _buf _len = do
setLine :: Int -> Action
setLine code span buf len = do
let line = parseInteger buf len 10 octDecDigit
let line = parseUnsignedInteger buf len 10 octDecDigit
setSrcLoc (mkSrcLoc (srcSpanFile span) (fromIntegral line - 1) 0)
-- subtract one: the line number refers to the *following* line
popLexState
......
......@@ -33,7 +33,7 @@ module StringBuffer
lexemeToFastString,
-- * Parsing integers
parseInteger,
parseUnsignedInteger,
) where
#include "HsVersions.h"
......@@ -208,8 +208,8 @@ byteOff (StringBuffer buf _ cur) i =
return (unsafeChr (fromIntegral (w::Word8)))
-- | XXX assumes ASCII digits only (by using byteOff)
parseInteger :: StringBuffer -> Int -> Integer -> (Char->Int) -> Integer
parseInteger buf len radix char_to_int
parseUnsignedInteger :: StringBuffer -> Int -> Integer -> (Char->Int) -> Integer
parseUnsignedInteger buf len radix char_to_int
= go 0 0
where
go i x | i == len = x
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment