Commit 081d7ce8 authored by Ian Lynagh's avatar Ian Lynagh

Add a test for #3972

parent f658f056
module Main (main) where
import T3972A (Expr(E10), Token, spanning, getSpan)
import Control.Monad
import System.Exit
import System.IO
main :: IO ()
main = do h <- openFile "T3972.o" ReadMode
s <- hFileSize h
hClose h
-- size is just under 8k on amd64/Linux in 6.13, but was
-- around 3.5M in 6.12. Let's try >20k as the test for
-- having regressed.
when (s > 20000) $ do
hPutStrLn stderr ("T3972.o is too big! " ++ show s)
exitFailure
makeTupleOrExpr :: [Expr] -> Maybe Token -> Expr
makeTupleOrExpr [e] Nothing = e
makeTupleOrExpr es@(_:_) (Just t) = E10 (spanning es t)
makeTupleOrExpr es@(_:_) Nothing = E10 (getSpan es)
module T3972A (Expr(..), Token(..), spanning, getSpan) where
class Span a where
getSpan :: a -> SrcSpan
spanning :: (Span a, Span b) => a -> b -> SrcSpan
spanning x y = combineSrcSpans (getSpan x) (getSpan y)
instance Span a => Span [a] where
getSpan [] = error "[]"
getSpan [x] = getSpan x
getSpan list@(x:_) = combineSrcSpans (getSpan x) (getSpan (last list))
data SrcSpan
= SpanMultiLine
{ span_start_row :: !Int
, span_start_column :: !Int
, span_end_row :: !Int
, span_end_column :: !Int
}
combineSrcSpans :: SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans start end
= case row1 `compare` row2 of
LT -> SpanMultiLine row1 col1 row2 col2
_ -> SpanMultiLine row2 col2 row1 col1
where
row1 = startRow start
col1 = startCol start
row2 = endRow end
col2 = endCol end
startRow :: SrcSpan -> Int
startRow (SpanMultiLine { span_start_row = row }) = row
endRow :: SrcSpan -> Int
endRow (SpanMultiLine { span_end_row = row }) = row
startCol :: SrcSpan -> Int
startCol (SpanMultiLine { span_start_column = col }) = col
endCol :: SrcSpan -> Int
endCol (SpanMultiLine { span_end_column = col }) = col
data Token
= T10 { token_SrcSpan :: SrcSpan }
| T11 { token_SrcSpan :: SrcSpan }
| T12 { token_SrcSpan :: SrcSpan }
| T13 { token_SrcSpan :: SrcSpan }
| T14 { token_SrcSpan :: SrcSpan }
| T15 { token_SrcSpan :: SrcSpan }
| T16 { token_SrcSpan :: SrcSpan }
| T17 { token_SrcSpan :: SrcSpan }
| T18 { token_SrcSpan :: SrcSpan }
| T19 { token_SrcSpan :: SrcSpan }
| T20 { token_SrcSpan :: SrcSpan }
| T21 { token_SrcSpan :: SrcSpan }
| T22 { token_SrcSpan :: SrcSpan }
| T23 { token_SrcSpan :: SrcSpan }
| T24 { token_SrcSpan :: SrcSpan }
instance Span Token where
getSpan = token_SrcSpan
data Expr
= E10 { expr_SrcSpan :: SrcSpan }
| E11 { expr_SrcSpan :: SrcSpan }
| E12 { expr_SrcSpan :: SrcSpan }
| E13 { expr_SrcSpan :: SrcSpan }
| E14 { expr_SrcSpan :: SrcSpan }
| E15 { expr_SrcSpan :: SrcSpan }
| E16 { expr_SrcSpan :: SrcSpan }
| E17 { expr_SrcSpan :: SrcSpan }
| E18 { expr_SrcSpan :: SrcSpan }
| E19 { expr_SrcSpan :: SrcSpan }
| E20 { expr_SrcSpan :: SrcSpan }
| E21 { expr_SrcSpan :: SrcSpan }
| E22 { expr_SrcSpan :: SrcSpan }
| E23 { expr_SrcSpan :: SrcSpan }
| E24 { expr_SrcSpan :: SrcSpan }
instance Span Expr where
getSpan = expr_SrcSpan
......@@ -40,3 +40,6 @@ test('T3983', [only_ways(['normal','optc','optasm']),
extra_clean(['T3983_Foo.hi','T3983_Foo.o','T3983_Bar.hi','T3983_Bar.o',])],
multimod_compile_and_run,
['T3983',''])
test('T3972', extra_clean(['T3972A.hi', 'T3972A.o']),
compile_and_run,
[''])
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