Alan Zimmerman pushed to branch wip/az/ghc-cpp at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/Parser/Lexer.x
    ... ... @@ -273,7 +273,7 @@ $tab { warnTab }
    273 273
     -- set.
    
    274 274
     
    
    275 275
     "{-" / { isNormalComment }       { nested_comment }
    
    276
    -"/*" / { ifExtension GhcCppBit } { cpp_comment }
    
    276
    +-- "/*" / { ifExtension GhcCppBit } { cpp_comment }
    
    277 277
     
    
    278 278
     -- Single-line comments are a bit tricky.  Haskell 98 says that two or
    
    279 279
     -- more dashes followed by a symbol should be parsed as a varsym, so we
    
    ... ... @@ -333,11 +333,16 @@ $unigraphic / { isSmartQuote } { smart_quote_error }
    333 333
       ^\# line                              { begin line_prag1 }
    
    334 334
       ^\# / { followedByDigit }             { begin line_prag1 }
    
    335 335
     
    
    336
    -  ^\#.*\n                    / { ifExtensionGhcCppNotComment } { cppSkip }
    
    336
    +  ^\ *\# \ * $idchar+ .*\n   / { ifExtensionGhcCppNotComment } { cppSkip }
    
    337
    +
    
    338
    +  ^\# pragma .* \n     / { ifExtensionGhcCppNotComment } { cppSkip } -- GCC 3.3 CPP generated, apparently
    
    339
    +  ^\# \! .* \n         / { ifExtensionGhcCppNotComment } { cppSkip } -- #!, for scripts  -- gcc
    
    340
    +  ^\  \# \! .* \n      / { ifExtensionGhcCppNotComment } { cppSkip } --  #!, for scripts -- clang; See #6132
    
    337 341
     
    
    338 342
       ^\# pragma .* \n                      ; -- GCC 3.3 CPP generated, apparently
    
    339 343
       ^\# \! .* \n                          ; -- #!, for scripts  -- gcc
    
    340 344
       ^\  \# \! .* \n                       ; --  #!, for scripts -- clang; See #6132
    
    345
    +
    
    341 346
       ()                                    { do_bol }
    
    342 347
     }
    
    343 348
     
    
    ... ... @@ -1771,8 +1776,9 @@ linePrag span buf len buf2 = do
    1771 1776
       usePosPrags <- getBit UsePosPragsBit
    
    1772 1777
       if usePosPrags
    
    1773 1778
         then begin line_prag2 span buf len buf2
    
    1774
    -    else let !src = lexemeToFastString buf len
    
    1775
    -         in return (L span (ITline_prag (SourceText src)))
    
    1779
    +    -- else let !src = lexemeToFastString buf len
    
    1780
    +    --      in return (L span (ITline_prag (SourceText src)))
    
    1781
    +    else nested_comment span buf len buf2
    
    1776 1782
     
    
    1777 1783
     -- When 'UsePosPragsBit' is not set, it is expected that we emit a token instead
    
    1778 1784
     -- of updating the position in 'PState'
    
    ... ... @@ -3736,6 +3742,7 @@ lexToken = do
    3736 3742
             let span = mkPsSpan loc1 end
    
    3737 3743
             let bytes = byteDiff buf buf2
    
    3738 3744
             span `seq` setLastToken buf span bytes
    
    3745
    +        -- function t is `Action p`
    
    3739 3746
             lt <- t span buf bytes buf2
    
    3740 3747
             let lt' = unLoc lt
    
    3741 3748
             if (isComment lt') then setLastComment lt else setLastTk lt
    

  • utils/check-cpp/Main.hs
    ... ... @@ -891,3 +891,29 @@ t40 = do
    891 891
             , "x='a'"
    
    892 892
             , ""
    
    893 893
             ]
    
    894
    +
    
    895
    +t41 :: IO ()
    
    896
    +t41 = do
    
    897
    +    dump
    
    898
    +        [ "{-# LANGUAGE GHC_CPP #-}"
    
    899
    +        , "module CFG where"
    
    900
    +        , ""
    
    901
    +        , "{-# LINE 6 \"src/CFG.ag\" #-}"
    
    902
    +        , ""
    
    903
    +        , "import Data.Word"
    
    904
    +        , "import ByteCode"
    
    905
    +        ]
    
    906
    +
    
    907
    +t42 :: IO ()
    
    908
    +t42 = do
    
    909
    +    dump
    
    910
    +        [ "{-# LANGUAGE GHC_CPP #-}"
    
    911
    +        , "module T23465 where"
    
    912
    +        , ""
    
    913
    +        , "{-# WARNInG"
    
    914
    +        , "   in \"x-f\" f \"fw\" ;"
    
    915
    +        , "   in \"x-f\" g \"gw\""
    
    916
    +        , "#-}"
    
    917
    +        , "f = f"
    
    918
    +        , "g = g"
    
    919
    +        ]