remove empty dir
[ghc-hetmet.git] / ghc / compiler / basicTypes / SrcLoc.lhs
index 8b25be9..51d4318 100644 (file)
@@ -23,7 +23,7 @@ module SrcLoc (
        srcLocFile,             -- return the file name part
        srcLocLine,             -- return the line part
        srcLocCol,              -- return the column part
-
+       pprDefnLoc,
 
        SrcSpan,                -- Abstract
        noSrcSpan,
@@ -65,20 +65,6 @@ data SrcLoc
   | ImportedLoc        String          -- Module name
 
   | UnhelpfulLoc FastString    -- Just a general indication
-
-{-
-data SrcSpan
-  = WiredInSpan
-
-       -- A precise source file span
-  | SrcSpan    FastString      -- file name
-               FastInt         -- beginning line
-               FastInt         -- beginning column
-               FastInt         -- end line
-               FastInt         -- end column           
-
-  | UnhelpfulSrcSpan FastString        -- Just a general indication
--}
 \end{code}
 
 Note that an entity might be imported via more than one route, and
@@ -122,14 +108,9 @@ srcLocCol (SrcLoc _ l c) = c
 srcLocCol other          = panic "srcLocCol: unknown col"
 
 advanceSrcLoc :: SrcLoc -> Char -> SrcLoc
-advanceSrcLoc (SrcLoc f l c) '\t' = SrcLoc f  l (tab c)
 advanceSrcLoc (SrcLoc f l c) '\n' = SrcLoc f  (l + 1) 0
 advanceSrcLoc (SrcLoc f l c) _    = SrcLoc f  l (c + 1)
 advanceSrcLoc loc           _    = loc -- Better than nothing
-
--- Advance to the next tab stop.  Tabs are at column positions 0, 8, 16, etc.
-tab :: Int -> Int
-tab c = (c `quot` 8 + 1) * 8
 \end{code}
 
 %************************************************************************
@@ -175,7 +156,7 @@ instance Outputable SrcLoc where
           hcat [text "{-# LINE ", int src_line, space,
                 char '\"', ftext src_path, text " #-}"]
 
-    ppr (ImportedLoc mod) = ptext SLIT("Imported from") <+> quotes (text mod)
+    ppr (ImportedLoc mod) = ptext SLIT("Imported from") <+> text mod
     ppr (UnhelpfulLoc s)  = ftext s
 \end{code}
 
@@ -298,21 +279,31 @@ mkSrcSpan loc1 loc2
        file = srcLocFile loc1
 
 combineSrcSpans        :: SrcSpan -> SrcSpan -> SrcSpan
+-- Assumes the 'file' part is the same in both
 combineSrcSpans        (ImportedSpan str) _  = ImportedSpan str
 combineSrcSpans        (UnhelpfulSpan str) r = r -- this seems more useful
 combineSrcSpans        _ (ImportedSpan str)  = ImportedSpan str
 combineSrcSpans        l (UnhelpfulSpan str) = l
 combineSrcSpans        start end 
- | line1 == line2 = if col1 == col2
-                       then SrcSpanPoint file line1 col1
-                       else SrcSpanOneLine file line1 col1 col2
- | otherwise      = SrcSpanMultiLine file line1 col1 line2 col2
+ = case line1 `compare` line2 of
+     EQ -> case col1 `compare` col2 of
+               EQ -> SrcSpanPoint file line1 col1
+               LT -> SrcSpanOneLine file line1 col1 col2
+               GT -> SrcSpanOneLine file line1 col2 col1
+     LT -> SrcSpanMultiLine file line1 col1 line2 col2
+     GT -> SrcSpanMultiLine file line2 col2 line1 col1
   where
        line1 = srcSpanStartLine start
+       col1  = srcSpanStartCol start
        line2 = srcSpanEndLine end
-       col1 = srcSpanStartCol start
-       col2 = srcSpanEndCol end
-       file = srcSpanFile start
+       col2  = srcSpanEndCol end
+       file  = srcSpanFile start
+
+pprDefnLoc :: SrcLoc -> SDoc
+-- "defined at ..." or "imported from ..."
+pprDefnLoc loc
+  | isGoodSrcLoc loc = ptext SLIT("Defined at") <+> ppr loc
+  | otherwise       = ppr loc
 
 instance Outputable SrcSpan where
     ppr span
@@ -390,6 +381,6 @@ instance Functor Located where
   fmap f (L l e) = L l (f e)
 
 instance Outputable e => Outputable (Located e) where
-  ppr (L span e) = ppr e
+  ppr (L span e) =  ppr e
        -- do we want to dump the span in debugSty mode?    
 \end{code}