[commit: ghc] master,ghc-lwc2,type-nats: Use unicode quote characters in error messages etc; fixes #2507 (e2bea60)
Ian Lynagh
igloo at earth.li
Thu Feb 28 15:19:54 CET 2013
Repository : http://darcs.haskell.org/ghc.git/
On branches: master,ghc-lwc2,type-nats
http://hackage.haskell.org/trac/ghc/changeset/e2bea6019fd523d4b6061174b114c49f55fa981c
>---------------------------------------------------------------
commit e2bea6019fd523d4b6061174b114c49f55fa981c
Author: Ian Lynagh <ian at well-typed.com>
Date: Sun Feb 24 00:26:07 2013 +0000
Use unicode quote characters in error messages etc; fixes #2507
We only use the unicode characters if the locale supports them.
>---------------------------------------------------------------
compiler/main/DynFlags.hs | 15 ++++++++++++++-
compiler/main/DynFlags.hs-boot | 1 +
compiler/utils/Outputable.lhs | 7 ++++++-
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index 66e42b5..3591a30 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -169,10 +169,13 @@ import qualified Data.Set as Set
import Data.Word
import System.FilePath
import System.IO
+import System.IO.Error
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
+import GHC.Foreign (withCString, peekCString)
+
-- -----------------------------------------------------------------------------
-- DynFlags
@@ -708,6 +711,8 @@ data DynFlags = DynFlags {
pprCols :: Int,
traceLevel :: Int, -- Standard level is 1. Less verbose is 0.
+ useUnicodeQuotes :: Bool,
+
-- | what kind of {-# SCC #-} to add automatically
profAuto :: ProfAuto,
@@ -1176,6 +1181,12 @@ initDynFlags dflags = do
refGeneratedDumps <- newIORef Set.empty
refLlvmVersion <- newIORef 28
wrapperNum <- newIORef 0
+ canUseUnicodeQuotes <- do let enc = localeEncoding
+ str = "ââ"
+ (withCString enc str $ \cstr ->
+ do str' <- peekCString enc cstr
+ return (str == str'))
+ `catchIOError` \_ -> return False
return dflags{
canGenerateDynamicToo = refCanGenerateDynamicToo,
filesToClean = refFilesToClean,
@@ -1183,7 +1194,8 @@ initDynFlags dflags = do
filesToNotIntermediateClean = refFilesToNotIntermediateClean,
generatedDumps = refGeneratedDumps,
llvmVersion = refLlvmVersion,
- nextWrapperNum = wrapperNum
+ nextWrapperNum = wrapperNum,
+ useUnicodeQuotes = canUseUnicodeQuotes
}
-- | The normal 'DynFlags'. Note that they is not suitable for use in this form
@@ -1308,6 +1320,7 @@ defaultDynFlags mySettings =
flushErr = defaultFlushErr,
pprUserLength = 5,
pprCols = 100,
+ useUnicodeQuotes = False,
traceLevel = 1,
profAuto = NoProfAuto,
llvmVersion = panic "defaultDynFlags: No llvmVersion",
diff --git a/compiler/main/DynFlags.hs-boot b/compiler/main/DynFlags.hs-boot
index da54e49..04ec5a4 100644
--- a/compiler/main/DynFlags.hs-boot
+++ b/compiler/main/DynFlags.hs-boot
@@ -9,3 +9,4 @@ targetPlatform :: DynFlags -> Platform
pprUserLength :: DynFlags -> Int
pprCols :: DynFlags -> Int
unsafeGlobalDynFlags :: DynFlags
+useUnicodeQuotes :: DynFlags -> Bool
diff --git a/compiler/utils/Outputable.lhs b/compiler/utils/Outputable.lhs
index 9e83634..f26f918 100644
--- a/compiler/utils/Outputable.lhs
+++ b/compiler/utils/Outputable.lhs
@@ -72,6 +72,7 @@ module Outputable (
import {-# SOURCE #-} DynFlags( DynFlags,
targetPlatform, pprUserLength, pprCols,
+ useUnicodeQuotes,
unsafeGlobalDynFlags )
import {-# SOURCE #-} Module( Module, ModuleName, moduleName )
import {-# SOURCE #-} Name( Name, nameModule )
@@ -448,7 +449,11 @@ cparen b d = SDoc $ Pretty.cparen b . runSDoc d
-- 'quotes' encloses something in single quotes...
-- but it omits them if the thing begins or ends in a single quote
-- so that we don't get `foo''. Instead we just have foo'.
-quotes d = SDoc $ \sty ->
+quotes d =
+ sdocWithDynFlags $ \dflags ->
+ if useUnicodeQuotes dflags
+ then char 'â' <> d <> char 'â'
+ else SDoc $ \sty ->
let pp_d = runSDoc d sty
str = show pp_d
in case (str, snocView str) of
More information about the ghc-commits
mailing list