parseInteger->parseUnsignedInteger to clarify meaning
authorIsaac Dupree <id@isaac.cedarswampstudios.org>
Sat, 26 May 2007 21:22:04 +0000 (21:22 +0000)
committerIsaac Dupree <id@isaac.cedarswampstudios.org>
Sat, 26 May 2007 21:22:04 +0000 (21:22 +0000)
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.

compiler/cmm/CmmLex.x
compiler/parser/Lexer.x
compiler/utils/StringBuffer.lhs

index 6ae5200..a1aa276 100644 (file)
@@ -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
index b063147..de025de 100644 (file)
@@ -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
index a1eddb0..28a7f67 100644 (file)
@@ -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