haskell-tools-ast 0.9.0.0 → 1.0.0.0
raw patch · 22 files changed
+169/−144 lines, 22 filesdep ~basedep ~ghcdep ~template-haskell
Dependency ranges changed: base, ghc, template-haskell
Files
- Language/Haskell/Tools/AST/Ann.hs +27/−56
- Language/Haskell/Tools/AST/Helpers.hs +2/−9
- Language/Haskell/Tools/AST/Instances/Data.hs +38/−7
- Language/Haskell/Tools/AST/Instances/Eq.hs +3/−1
- Language/Haskell/Tools/AST/Instances/Generic.hs +4/−2
- Language/Haskell/Tools/AST/Instances/SemanticTraversal.hs +3/−2
- Language/Haskell/Tools/AST/Instances/Show.hs +3/−1
- Language/Haskell/Tools/AST/Instances/SourceInfoTraversal.hs +3/−2
- Language/Haskell/Tools/AST/References.hs +4/−0
- Language/Haskell/Tools/AST/Representation/Decls.hs +22/−9
- Language/Haskell/Tools/AST/Representation/Exprs.hs +6/−0
- Language/Haskell/Tools/AST/Representation/Exprs.hs-boot +4/−1
- Language/Haskell/Tools/AST/Representation/Modules.hs +11/−10
- Language/Haskell/Tools/AST/Representation/Names.hs +1/−4
- Language/Haskell/Tools/AST/Representation/Patterns.hs +8/−4
- Language/Haskell/Tools/AST/Representation/Types.hs +2/−0
- Language/Haskell/Tools/AST/SemaInfoClasses.hs +1/−6
- Language/Haskell/Tools/AST/SemaInfoTypes.hs +12/−12
- Language/Haskell/Tools/AST/TH/SemanticTraversal.hs +4/−6
- Language/Haskell/Tools/AST/TH/SourceInfoTraversal.hs +4/−6
- Language/Haskell/Tools/AST/Utils/GHCInstances.hs +3/−2
- haskell-tools-ast.cabal +4/−4
Language/Haskell/Tools/AST/Ann.hs view
@@ -1,22 +1,10 @@-{-# LANGUAGE FlexibleInstances - , FlexibleContexts - , TemplateHaskell - , DeriveDataTypeable - , StandaloneDeriving - , KindSignatures - , TypeFamilies - , MultiParamTypeClasses - , UndecidableInstances - , AllowAmbiguousTypes - , TypeApplications - , ScopedTypeVariables - , PatternSynonyms - #-} +{-# LANGUAGE AllowAmbiguousTypes, ConstraintKinds, DeriveDataTypeable, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TypeApplications, TypeFamilies, UndecidableInstances #-} -- | Parts of AST representation for keeping extra data module Language.Haskell.Tools.AST.Ann where import Control.Reference import Data.Data +import FastString import Id as GHC import Language.Haskell.Tools.AST.SemaInfoTypes import Language.Haskell.Tools.AST.Utils.GHCInstances () @@ -101,52 +89,30 @@ type instance SemanticInfo' IdDom SameInfoWildcardCls = ImplicitFieldInfo type instance SemanticInfo' IdDom SameInfoDefaultCls = NoSemanticInfo --- | Class for domain configuration markers -class ( Typeable d - , Data d - , SemanticInfo' d SameInfoDefaultCls ~ NoSemanticInfo - , Data (SemanticInfo' d SameInfoNameCls) - , Data (SemanticInfo' d SameInfoExprCls) - , Data (SemanticInfo' d SameInfoImportCls) - , Data (SemanticInfo' d SameInfoModuleCls) - , Data (SemanticInfo' d SameInfoWildcardCls) - , Show (SemanticInfo' d SameInfoNameCls) - , Show (SemanticInfo' d SameInfoExprCls) - , Show (SemanticInfo' d SameInfoImportCls) - , Show (SemanticInfo' d SameInfoModuleCls) - , Show (SemanticInfo' d SameInfoWildcardCls) - ) => Domain d where - -- | A semantic domain for the AST. The semantic domain maps semantic information for -- the different types of nodes in the AST. The kind of semantic domain for an AST -- depends on which stages of the compilation did it pass. However after transforming -- the GHC representation to our AST, the domain keeps the same. -- The domain is not applied to the AST elements that are generated while refactoring. -instance ( Typeable d - , Data d - , SemanticInfo' d SameInfoDefaultCls ~ NoSemanticInfo - , Data (SemanticInfo' d SameInfoNameCls) - , Data (SemanticInfo' d SameInfoExprCls) - , Data (SemanticInfo' d SameInfoImportCls) - , Data (SemanticInfo' d SameInfoModuleCls) - , Data (SemanticInfo' d SameInfoWildcardCls) - , Show (SemanticInfo' d SameInfoNameCls) - , Show (SemanticInfo' d SameInfoExprCls) - , Show (SemanticInfo' d SameInfoImportCls) - , Show (SemanticInfo' d SameInfoModuleCls) - , Show (SemanticInfo' d SameInfoWildcardCls) - ) => Domain d where - - -class ( Data (SemanticInfo' d (SemaInfoClassify e)) - , Show (SemanticInfo' d (SemaInfoClassify e)) - , Domain d - ) => DomainWith e d where +type Domain d = ( Typeable d + , Data d + , SemanticInfo' d SameInfoDefaultCls ~ NoSemanticInfo + , Data (SemanticInfo' d SameInfoNameCls) + , Data (SemanticInfo' d SameInfoExprCls) + , Data (SemanticInfo' d SameInfoImportCls) + , Data (SemanticInfo' d SameInfoModuleCls) + , Data (SemanticInfo' d SameInfoWildcardCls) + , Show (SemanticInfo' d SameInfoNameCls) + , Show (SemanticInfo' d SameInfoExprCls) + , Show (SemanticInfo' d SameInfoImportCls) + , Show (SemanticInfo' d SameInfoModuleCls) + , Show (SemanticInfo' d SameInfoWildcardCls) + ) -instance ( Data (SemanticInfo' d (SemaInfoClassify e)) - , Show (SemanticInfo' d (SemaInfoClassify e)) - , Domain d - ) => DomainWith e d where +type DomainWith e d = ( Data (SemanticInfo' d (SemaInfoClassify e)) + , Show (SemanticInfo' d (SemaInfoClassify e)) + , Domain d + ) -- | Extracts or modifies the concrete range corresponding to a given source info. -- In case of lists and optional elements, it may not contain the elements inside. @@ -166,8 +132,8 @@ , HasRange (SpanInfo stage) , HasRange (ListInfo stage) , HasRange (OptionalInfo stage) - ) - => SourceInfo stage where + ) => SourceInfo stage where + -- | UType of source info for normal AST elements data SpanInfo stage :: * -- | UType of source info for lists of AST elements @@ -231,6 +197,11 @@ shortShowSpan (UnhelpfulSpan _) = "??-??" shortShowSpan sp@(RealSrcSpan _) = shortShowLoc (srcSpanStart sp) ++ "-" ++ shortShowLoc (srcSpanEnd sp) + +shortShowSpanWithFile :: SrcSpan -> String +shortShowSpanWithFile (UnhelpfulSpan _) = "?? ??-??" +shortShowSpanWithFile sp@(RealSrcSpan rsp) + = unpackFS (srcSpanFile rsp) ++ " " ++ shortShowLoc (srcSpanStart sp) ++ "-" ++ shortShowLoc (srcSpanEnd sp) -- | A short form of showing a range, without file name, for debugging purposes. shortShowLoc :: SrcLoc -> String
Language/Haskell/Tools/AST/Helpers.hs view
@@ -1,12 +1,4 @@-{-# LANGUAGE FlexibleContexts - , LambdaCase - , RankNTypes - , ScopedTypeVariables - , TypeFamilies - , FlexibleInstances - , UndecidableInstances - , PatternSynonyms - #-} +{-# LANGUAGE FlexibleContexts, PatternSynonyms, RankNTypes, ScopedTypeVariables, TypeFamilies, TypeSynonymInstances, UndecidableInstances #-} -- | Helper functions for using the AST. module Language.Haskell.Tools.AST.Helpers where @@ -118,6 +110,7 @@ &+& (declTypeFamily & tfHead & declHeadNames) &+& (declValBind & bindingName) &+& (declName & simpleName) + &+& (declTypeSig & tsName & annList & simpleName) &+& (declPatSyn & patLhs & (patName & simpleName &+& patSynOp & operatorName)) instance NamedElement ULocalBind where
Language/Haskell/Tools/AST/Instances/Data.hs view
@@ -1,8 +1,8 @@ -- | Data instances for Haskell AST (used for generics) -{-# LANGUAGE FlexibleContexts, StandaloneDeriving, DeriveDataTypeable #-} -module Language.Haskell.Tools.AST.Instances.Data where +{-# LANGUAGE DeriveDataTypeable, FlexibleContexts, StandaloneDeriving, TypeFamilies, UndecidableInstances #-} +module Language.Haskell.Tools.AST.Instances.Data () where -import Data.Data (Data(..), Typeable(..)) +import Data.Data import Language.Haskell.Tools.AST.Ann import Language.Haskell.Tools.AST.Representation.Binds @@ -17,11 +17,40 @@ import Language.Haskell.Tools.AST.Representation.TH import Language.Haskell.Tools.AST.Representation.Types --- Annotations -deriving instance (DomainWith e dom, SourceInfo stage, Typeable e, Data (e dom stage)) => Data (Ann e dom stage) -deriving instance (DomainWith e dom, SourceInfo stage, Typeable e, Data (e dom stage)) => Data (AnnMaybeG e dom stage) -deriving instance (DomainWith e dom, SourceInfo stage, Typeable e, Data (e dom stage)) => Data (AnnListG e dom stage) +-- Making the annotation an opaque attribute in annotated elements. +-- Needed because otherwise uniplate traverses the annotations, resulting in unnecessary +-- evaluation and storage. +instance (DomainWith e dom, SourceInfo stage, Typeable e, Data (e dom stage)) + => Data (Ann e dom stage) where + gfoldl k z (Ann annot elem) = z (Ann annot) `k` elem -- ANNOT IS HIDDEN + gunfold k z c = case constrIndex c of 1 -> k (k (z Ann)) + toConstr (Ann{}) = con_Ann + dataTypeOf _ = ty_Ann + +con_Ann = mkConstr ty_Ann "Ann" [] Prefix +ty_Ann = mkDataType "Language.Haskell.Tools.AST.Ann.Ann" [con_Ann] + +instance (DomainWith e dom, SourceInfo stage, Typeable e, Data (e dom stage)) + => Data (AnnMaybeG e dom stage) where + gfoldl k z (AnnMaybeG annot elem) = z (AnnMaybeG annot) `k` elem -- ANNOT IS HIDDEN + gunfold k z c = case constrIndex c of 1 -> k (k (z AnnMaybeG)) + toConstr (AnnMaybeG{}) = con_AnnMaybeG + dataTypeOf _ = ty_AnnMaybeG + +con_AnnMaybeG = mkConstr ty_AnnMaybeG "AnnMaybeG" [] Prefix +ty_AnnMaybeG = mkDataType "Language.Haskell.Tools.AST.Ann.AnnMaybeG" [con_AnnMaybeG] + +instance (DomainWith e dom, SourceInfo stage, Typeable e, Data (e dom stage)) + => Data (AnnListG e dom stage) where + gfoldl k z (AnnListG annot elem) = z (AnnListG annot) `k` elem -- ANNOT IS HIDDEN + gunfold k z c = case constrIndex c of 1 -> k (k (z AnnListG)) + toConstr (AnnListG{}) = con_AnnListG + dataTypeOf _ = ty_AnnListG + +con_AnnListG = mkConstr ty_AnnListG "AnnListG" [] Prefix +ty_AnnListG = mkDataType "Language.Haskell.Tools.AST.Ann.AnnListG" [con_AnnListG] + -- Modules deriving instance (Domain dom, SourceInfo stage) => Data (UModule dom stage) deriving instance (Domain dom, SourceInfo stage) => Data (UModuleHead dom stage) @@ -55,6 +84,7 @@ deriving instance (Domain dom, SourceInfo stage) => Data (UConDecl dom stage) deriving instance (Domain dom, SourceInfo stage) => Data (UFieldDecl dom stage) deriving instance (Domain dom, SourceInfo stage) => Data (UDeriving dom stage) +deriving instance (Domain dom, SourceInfo stage) => Data (UDeriveStrategy dom stage) deriving instance (Domain dom, SourceInfo stage) => Data (UInstanceRule dom stage) deriving instance (Domain dom, SourceInfo stage) => Data (UInstanceHead dom stage) deriving instance (Domain dom, SourceInfo stage) => Data (UTypeEqn dom stage) @@ -110,6 +140,7 @@ deriving instance (Domain dom, SourceInfo stage) => Data (UMatchLhs dom stage) deriving instance (Domain dom, SourceInfo stage) => Data (UInlinePragma dom stage) deriving instance (Domain dom, SourceInfo stage) => Data (USpecializePragma dom stage) +deriving instance (Domain dom, SourceInfo stage) => Data (UUnboxedSumPlaceHolder dom stage) -- ULiteral deriving instance (Domain dom, SourceInfo stage) => Data (ULiteral dom stage)
Language/Haskell/Tools/AST/Instances/Eq.hs view
@@ -1,6 +1,6 @@ -- | Equality check of AST nodes that ignore the source and semantic information. {-# LANGUAGE FlexibleContexts, StandaloneDeriving #-} -module Language.Haskell.Tools.AST.Instances.Eq where +module Language.Haskell.Tools.AST.Instances.Eq () where import Language.Haskell.Tools.AST.Ann (Ann(..), AnnListG(..), AnnMaybeG(..)) import Language.Haskell.Tools.AST.Representation.Binds @@ -58,6 +58,7 @@ deriving instance Eq (UConDecl dom stage) deriving instance Eq (UFieldDecl dom stage) deriving instance Eq (UDeriving dom stage) +deriving instance Eq (UDeriveStrategy dom stage) deriving instance Eq (UInstanceRule dom stage) deriving instance Eq (UInstanceHead dom stage) deriving instance Eq (UTypeEqn dom stage) @@ -113,6 +114,7 @@ deriving instance Eq (UMatchLhs dom stage) deriving instance Eq (UInlinePragma dom stage) deriving instance Eq (USpecializePragma dom stage) +deriving instance Eq (UUnboxedSumPlaceHolder dom stage) -- ULiteral deriving instance Eq (ULiteral dom stage)
Language/Haskell/Tools/AST/Instances/Generic.hs view
@@ -1,6 +1,6 @@ -- | Generic instance for Haskell AST representation -{-# LANGUAGE FlexibleContexts, StandaloneDeriving, DeriveGeneric #-} -module Language.Haskell.Tools.AST.Instances.Generic where +{-# LANGUAGE DeriveGeneric, FlexibleContexts, StandaloneDeriving, TypeFamilies, UndecidableInstances #-} +module Language.Haskell.Tools.AST.Instances.Generic () where import GHC.Generics (Generic(..)) @@ -55,6 +55,7 @@ deriving instance Domain dom => Generic (UConDecl dom stage) deriving instance Domain dom => Generic (UFieldDecl dom stage) deriving instance Domain dom => Generic (UDeriving dom stage) +deriving instance Domain dom => Generic (UDeriveStrategy dom stage) deriving instance Domain dom => Generic (UInstanceRule dom stage) deriving instance Domain dom => Generic (UInstanceHead dom stage) deriving instance Domain dom => Generic (UTypeEqn dom stage) @@ -110,6 +111,7 @@ deriving instance Domain dom => Generic (UMatchLhs dom stage) deriving instance Domain dom => Generic (UInlinePragma dom stage) deriving instance Domain dom => Generic (USpecializePragma dom stage) +deriving instance Domain dom => Generic (UUnboxedSumPlaceHolder dom stage) -- Literal
Language/Haskell/Tools/AST/Instances/SemanticTraversal.hs view
@@ -2,12 +2,11 @@ {-# OPTIONS_GHC -fno-warn-unused-matches #-} {-# LANGUAGE TemplateHaskell #-} -- | Generating instances for traversing the semantic information of the Haskell Representation -module Language.Haskell.Tools.AST.Instances.SemanticTraversal where +module Language.Haskell.Tools.AST.Instances.SemanticTraversal () where import Control.Applicative import Language.Haskell.Tools.AST.TH.SemanticTraversal -import Language.Haskell.Tools.AST.Ann import Language.Haskell.Tools.AST.Representation.Binds import Language.Haskell.Tools.AST.Representation.Decls import Language.Haskell.Tools.AST.Representation.Exprs @@ -54,6 +53,7 @@ deriveSemanticTraversal ''UConDecl deriveSemanticTraversal ''UFieldDecl deriveSemanticTraversal ''UDeriving +deriveSemanticTraversal ''UDeriveStrategy deriveSemanticTraversal ''UInstanceRule deriveSemanticTraversal ''UInstanceHead deriveSemanticTraversal ''UTypeEqn @@ -109,6 +109,7 @@ deriveSemanticTraversal ''UGuardedCaseRhs' deriveSemanticTraversal ''UInlinePragma deriveSemanticTraversal ''USpecializePragma +deriveSemanticTraversal ''UUnboxedSumPlaceHolder -- ULiteral deriveSemanticTraversal ''ULiteral
Language/Haskell/Tools/AST/Instances/Show.hs view
@@ -1,6 +1,6 @@ -- | Show instance for Haskell AST representation ignoring source and semantic information {-# LANGUAGE FlexibleContexts, StandaloneDeriving #-} -module Language.Haskell.Tools.AST.Instances.Show where +module Language.Haskell.Tools.AST.Instances.Show () where import Language.Haskell.Tools.AST.Ann (Ann(..), AnnListG(..), AnnMaybeG(..)) import Language.Haskell.Tools.AST.Representation.Binds @@ -58,6 +58,7 @@ deriving instance Show (UConDecl dom stage) deriving instance Show (UFieldDecl dom stage) deriving instance Show (UDeriving dom stage) +deriving instance Show (UDeriveStrategy dom stage) deriving instance Show (UInstanceRule dom stage) deriving instance Show (UInstanceHead dom stage) deriving instance Show (UTypeEqn dom stage) @@ -113,6 +114,7 @@ deriving instance Show (UMatchLhs dom stage) deriving instance Show (UInlinePragma dom stage) deriving instance Show (USpecializePragma dom stage) +deriving instance Show (UUnboxedSumPlaceHolder dom stage) -- ULiteral
Language/Haskell/Tools/AST/Instances/SourceInfoTraversal.hs view
@@ -2,12 +2,11 @@ {-# OPTIONS_GHC -fno-warn-unused-matches #-} {-# LANGUAGE TemplateHaskell #-} -- | Generating instances for traversing the semantic information of the Haskell Representation -module Language.Haskell.Tools.AST.Instances.SourceInfoTraversal where +module Language.Haskell.Tools.AST.Instances.SourceInfoTraversal () where import Control.Applicative import Language.Haskell.Tools.AST.TH.SourceInfoTraversal -import Language.Haskell.Tools.AST.Ann import Language.Haskell.Tools.AST.Representation.Binds import Language.Haskell.Tools.AST.Representation.Decls import Language.Haskell.Tools.AST.Representation.Exprs @@ -54,6 +53,7 @@ deriveSourceInfoTraversal ''UConDecl deriveSourceInfoTraversal ''UFieldDecl deriveSourceInfoTraversal ''UDeriving +deriveSourceInfoTraversal ''UDeriveStrategy deriveSourceInfoTraversal ''UInstanceRule deriveSourceInfoTraversal ''UInstanceHead deriveSourceInfoTraversal ''UTypeEqn @@ -109,6 +109,7 @@ deriveSourceInfoTraversal ''UGuardedCaseRhs' deriveSourceInfoTraversal ''UInlinePragma deriveSourceInfoTraversal ''USpecializePragma +deriveSourceInfoTraversal ''UUnboxedSumPlaceHolder -- ULiteral deriveSourceInfoTraversal ''ULiteral
Language/Haskell/Tools/AST/References.hs view
@@ -63,6 +63,7 @@ $(toASTReferences (makeReferences ''UConDecl)) $(toASTReferences (makeReferences ''UFieldDecl)) $(toASTReferences (makeReferences ''UDeriving)) +$(toASTReferences (makeReferences ''UDeriveStrategy)) $(toASTReferences (makeReferences ''UInstanceRule)) $(toASTReferences (makeReferences ''UInstanceHead)) $(toASTReferences (makeReferences ''UTypeEqn)) @@ -79,6 +80,8 @@ $(toASTReferences (makeReferences ''UMinimalFormula)) $(toASTReferences (makeReferences ''USourceRange)) $(toASTReferences (makeReferences ''Number)) +$(toASTReferences (makeReferences ''UUnboxedSumPlaceHolder)) +$(toASTReferences (makeReferences ''USpecializePragma)) -- * Binds @@ -120,6 +123,7 @@ $(toASTReferences (makeReferences ''UCompStmt)) $(toASTReferences (makeReferences ''UListCompBody)) $(toASTReferences (makeReferences ''UDoKind)) +$(toASTReferences (makeReferences ''UCmd)) -- * Patterns $(toASTReferences (makeReferences ''UPattern))
Language/Haskell/Tools/AST/Representation/Decls.hs view
@@ -28,7 +28,7 @@ , _declCtx :: AnnMaybeG UContext dom stage , _declHead :: Ann UDeclHead dom stage , _declCons :: AnnListG UConDecl dom stage - , _declDeriving :: AnnMaybeG UDeriving dom stage + , _declDeriving :: AnnListG UDeriving dom stage } -- ^ A data or newtype declaration. Empty data type declarations without -- where keyword are always belong to DataDecl. | UGDataDecl { _declNewtype :: Ann UDataOrNewtypeKeyword dom stage @@ -36,7 +36,7 @@ , _declHead :: Ann UDeclHead dom stage , _declKind :: AnnMaybeG UKindConstraint dom stage , _declGadt :: AnnListG UGadtConDecl dom stage - , _declDeriving :: AnnMaybeG UDeriving dom stage + , _declDeriving :: AnnListG UDeriving dom stage } -- ^ A GADT-style data or newtype declaration. | UTypeInstDecl { _declInstance :: Ann UInstanceRule dom stage , _declAssignedType :: Ann UType dom stage @@ -44,7 +44,7 @@ | UDataInstDecl { _declNewtype :: Ann UDataOrNewtypeKeyword dom stage , _declInstance :: Ann UInstanceRule dom stage , _declCons :: AnnListG UConDecl dom stage - , _declDeriving :: AnnMaybeG UDeriving dom stage + , _declDeriving :: AnnListG UDeriving dom stage } -- ^ Data instance declaration (@ data instance Fam T = Con1 | Con2 @) | UGDataInstDecl { _declNewtype :: Ann UDataOrNewtypeKeyword dom stage , _declInstance :: Ann UInstanceRule dom stage @@ -62,7 +62,8 @@ } -- ^ Instance declaration (@ instance X T [where f = ...] @) | UPatternSynonymDecl { _declPatSyn :: Ann UPatternSynonym dom stage } -- ^ Pattern synonyms (@ pattern Arrow t1 t2 = App "->" [t1, t2] @) - | UDerivDecl { _declOverlap :: AnnMaybeG UOverlapPragma dom stage + | UDerivDecl { _declDerivStrat :: AnnMaybeG UDeriveStrategy dom stage + , _declOverlap :: AnnMaybeG UOverlapPragma dom stage , _declInstRule :: Ann UInstanceRule dom stage } -- ^ Standalone deriving declaration (@ deriving instance X T @) | UFixityDecl { _declFixity :: Ann UFixitySignature dom stage @@ -175,13 +176,13 @@ | UInstBodyDataDecl { _instBodyDataNew :: Ann UDataOrNewtypeKeyword dom stage , _instBodyLhsType :: Ann UInstanceRule dom stage , _instBodyDataCons :: AnnListG UConDecl dom stage - , _instBodyDerivings :: AnnMaybeG UDeriving dom stage + , _instBodyDerivings :: AnnListG UDeriving dom stage } -- ^ An associated data type implementation (@ data A X = C1 | C2 @) | UInstBodyGadtDataDecl { _instBodyDataNew :: Ann UDataOrNewtypeKeyword dom stage , _instBodyLhsType :: Ann UInstanceRule dom stage , _instBodyDataKind :: AnnMaybeG UKindConstraint dom stage , _instBodyGadtCons :: AnnListG UGadtConDecl dom stage - , _instBodyDerivings :: AnnMaybeG UDeriving dom stage + , _instBodyDerivings :: AnnListG UDeriving dom stage } -- ^ An associated data type implemented using GADT style | USpecializeInstance { _specializeInstanceType :: Ann UType dom stage } -- ^ Specialize instance pragma (no phase selection is allowed) @@ -295,14 +296,23 @@ -- | A deriving clause following a data type declaration. (@ deriving Show @ or @ deriving (Show, Eq) @) data UDeriving dom stage - = UDerivingOne { _oneDerived :: Ann UInstanceHead dom stage } - | UDerivings { _allDerived :: AnnListG UInstanceHead dom stage } + = UDerivingOne { _deriveStrategy :: AnnMaybeG UDeriveStrategy dom stage + , _oneDerived :: Ann UInstanceHead dom stage + } + | UDerivings { _deriveStrategy :: AnnMaybeG UDeriveStrategy dom stage + , _allDerived :: AnnListG UInstanceHead dom stage + } +data UDeriveStrategy dom stage + = UStockStrategy + | UAnyClassStrategy + | UNewtypeStrategy + -- * Pattern synonyms -- | Pattern type signature declaration (@ pattern Succ :: Int -> Int @) data UPatternTypeSignature dom stage - = UPatternTypeSignature { _patSigName :: Ann UName dom stage + = UPatternTypeSignature { _patSigName :: AnnListG UName dom stage , _patSigType :: Ann UType dom stage } @@ -387,6 +397,9 @@ , _pragmaFileName :: AnnMaybeG UStringNode dom stage } -- ^ A pragma for maintaining line numbers in generated sources (@ {-# LINE 123 "somefile" #-} @) | USpecializeDecl { _specializePragma :: Ann USpecializePragma dom stage } + | UCompletePragma { _pragmaObjects :: AnnListG UName dom stage + , _pragmaSignature :: AnnMaybeG UName dom stage + } -- ^ The COMPLETE pragma is used to inform the pattern match checker that a certain set of patterns is complete (@ {-# COMPLETE T :: [] #-} @). data USpecializePragma dom stage = USpecializePragma { _pragmaPhase :: AnnMaybeG UPhaseControl dom stage
Language/Haskell/Tools/AST/Representation/Exprs.hs view
@@ -115,6 +115,10 @@ } -- ^ Lambda case ( @\case 0 -> 1; 1 -> 2@ ) | UStaticPtr { _exprInner :: Ann UExpr dom stage } -- ^ Static pointer expression (@ static e @). The inner expression must be closed (cannot have variables bound outside) + | UUnboxedSum { _exprSumPlaceholdersBefore :: AnnListG UUnboxedSumPlaceHolder dom stage + , _exprInner :: Ann UExpr dom stage + , _exprSumPlaceholdersAfter :: AnnListG UUnboxedSumPlaceHolder dom stage + } -- ^ Unboxed sum expression (@ (# | True #) @). -- XML expressions omitted -- | Field update expressions @@ -225,3 +229,5 @@ | URightAppl -- ^ Right arrow application: @>-@ | ULeftHighApp -- ^ Left arrow high application: @-<<@ | URightHighApp -- ^ Right arrow high application: @>>-@ + +data UUnboxedSumPlaceHolder dom stage = UUnboxedSumPlaceHolder
Language/Haskell/Tools/AST/Representation/Exprs.hs-boot view
@@ -8,4 +8,7 @@ data UCmd dom stage type role UFieldWildcard phantom phantom -data UFieldWildcard dom stage+data UFieldWildcard dom stage + +type role UUnboxedSumPlaceHolder phantom phantom +data UUnboxedSumPlaceHolder dom stage
Language/Haskell/Tools/AST/Representation/Modules.hs view
@@ -24,14 +24,14 @@ -- | A list of export specifications surrounded by parentheses data UExportSpecs dom stage = UExportSpecs { _espExports :: AnnListG UExportSpec dom stage } - + -- | Export specifier data UExportSpec dom stage = UDeclExport { _exportDecl :: Ann UIESpec dom stage } -- ^ Export a name and related names | UModuleExport { _exportModuleName :: Ann UModuleName dom stage } -- ^ The export of an imported module (@ module A @) - + -- | Marks a name to be imported or exported with related names (subspecifier) data UIESpec dom stage = UIESpec { _ieModifier :: AnnMaybeG UImportModifier dom stage @@ -42,21 +42,22 @@ -- | Specifies the imported element data UImportModifier dom stage = UImportPattern -- ^ @pattern@: modifier for importing pattern synonyms - + | UImportType -- ^ @type@: modifier for importing types + -- | Marks how related names will be imported or exported with a given name data USubSpec dom stage = USubSpecAll -- ^ @(..)@: a class exported with all of its methods, or a datatype exported with all of its constructors. - | USubSpecList { _essList :: AnnListG UName dom stage + | USubSpecList { _essList :: AnnListG UName dom stage } -- ^ @(a,b,c)@: a class exported with some of its methods, or a datatype exported with some of its constructors. - --- | Pragmas that must be used before defining the module + +-- | Pragmas that must be used before defining the module data UFilePragma dom stage = ULanguagePragma { _lpPragmas :: AnnListG ULanguageExtension dom stage } -- ^ @LANGUAGE@ pragma, listing the enabled language extensions in that file | UOptionsPragma { _opStr :: Ann UStringNode dom stage } -- ^ @OPTIONS@ pragma, possibly qualified with a tool, e.g. OPTIONS_GHC - --- | Pragmas that must be used after the module head + +-- | Pragmas that must be used after the module head data UModulePragma dom stage = UModuleWarningPragma { _modWarningStr :: AnnListG UStringNode dom stage } -- ^ A warning pragma attached to the module @@ -66,7 +67,7 @@ -- | The name of the enabled language extension, for example (@ LambdaCase @) data ULanguageExtension dom stage = ULanguageExtension { _langExt :: String } --- | An import declaration: @import Module.Name@ +-- | An import declaration: @import Module.Name@ data UImportDecl dom stage = UImportDecl { _importSource :: AnnMaybeG UImportSource dom stage , _importQualified :: AnnMaybeG UImportQualified dom stage @@ -83,7 +84,7 @@ } -- ^ Restrict the import definition to ONLY import the listed names | UImportSpecHiding { _importSpecHiding :: AnnListG UIESpec dom stage } -- ^ Restrict the import definition to DONT import the listed names - + -- | Marks the import as qualified: @qualified@ data UImportQualified dom stage = UImportQualified
Language/Haskell/Tools/AST/Representation/Names.hs view
@@ -1,8 +1,5 @@ -{-# LANGUAGE TypeFamilies - , MultiParamTypeClasses - , FlexibleInstances - #-} +{-# LANGUAGE MultiParamTypeClasses, TypeFamilies, TypeSynonymInstances #-} -- | Simple AST elements of Haskell module Language.Haskell.Tools.AST.Representation.Names where
Language/Haskell/Tools/AST/Representation/Patterns.hs view
@@ -1,14 +1,14 @@ -- | Representation of Haskell patterns module Language.Haskell.Tools.AST.Representation.Patterns where - + import Language.Haskell.Tools.AST.Ann (Ann, AnnListG) -import {-# SOURCE #-} Language.Haskell.Tools.AST.Representation.Exprs (UExpr, UFieldWildcard) +import {-# SOURCE #-} Language.Haskell.Tools.AST.Representation.Exprs (UExpr, UFieldWildcard, UUnboxedSumPlaceHolder) import Language.Haskell.Tools.AST.Representation.Literals (ULiteral) import Language.Haskell.Tools.AST.Representation.Names (UName, UOperator) import {-# SOURCE #-} Language.Haskell.Tools.AST.Representation.TH (UQuasiQuote, USplice) import Language.Haskell.Tools.AST.Representation.Types (UType) - + -- | Representation of patterns for pattern bindings data UPattern dom stage = UVarPat { _patternName :: Ann UName dom stage @@ -58,7 +58,11 @@ | UNPlusKPat { _patternName :: Ann UName dom stage , _patternLit :: Ann ULiteral dom stage } - + | UUnboxedSumPat { _patternSumPlaceholdersBefore :: AnnListG UUnboxedSumPlaceHolder dom stage + , _patternInner :: Ann UPattern dom stage + , _patternSumPlaceholdersAfter :: AnnListG UUnboxedSumPlaceHolder dom stage + } -- ^ Unboxed sum pattern (@ (# | expr #) @). + -- Field specification of a record pattern data UPatternField dom stage = UNormalFieldPattern { _fieldPatternName :: Ann UName dom stage
Language/Haskell/Tools/AST/Representation/Types.hs view
@@ -62,6 +62,8 @@ | UTyWildcard -- ^ A wildcard type (@ _ @) with @-XPartialTypeSignatures@ | UTyNamedWildc { _typeWildcardName :: Ann UName dom stage } -- ^ A named wildcard type (@ _t @) with @-XPartialTypeSignatures@ + | UUnbSumType { _typeElements :: AnnListG UType dom stage + } -- ^ An unboxed sum type (@ (# Bool | Int | String #) @) -- One or more assertions data UContext dom stage
Language/Haskell/Tools/AST/SemaInfoClasses.hs view
@@ -1,9 +1,4 @@-{-# LANGUAGE FlexibleInstances - , FlexibleContexts - , ConstraintKinds - , TypeFamilies - , UndecidableInstances - #-} +{-# LANGUAGE ConstraintKinds, FlexibleContexts, FlexibleInstances, TypeFamilies, UndecidableInstances #-} module Language.Haskell.Tools.AST.SemaInfoClasses (module Language.Haskell.Tools.AST.SemaInfoClasses, UsageSpec(..)) where import GHC
Language/Haskell/Tools/AST/SemaInfoTypes.hs view
@@ -1,10 +1,4 @@-{-# LANGUAGE DeriveDataTypeable - , StandaloneDeriving - , TemplateHaskell - , UndecidableInstances - , FlexibleContexts - , FlexibleInstances - #-} +{-# LANGUAGE BangPatterns, DeriveDataTypeable, FlexibleContexts, StandaloneDeriving, TemplateHaskell, TypeSynonymInstances, UndecidableInstances #-} module Language.Haskell.Tools.AST.SemaInfoTypes ( -- types NoSemanticInfo, ScopeInfo, NameInfo, CNameInfo, ModuleInfo, ImportInfo, ImplicitFieldInfo @@ -33,7 +27,7 @@ import RdrName as GHC import SrcLoc as GHC -import Data.Data +import Data.Data as Data import Data.List import Control.Reference @@ -135,11 +129,14 @@ dataTypeOf _ = dynFlagsType dynFlagsType = mkDataType "DynFlags.DynFlags" [dynFlagsCon] -dynFlagsCon = mkConstr dynFlagsType "DynFlags" [] Prefix +dynFlagsCon = mkConstr dynFlagsType "DynFlags" [] Data.Prefix --- | Creates semantic information for the module element +-- | Creates semantic information for the module element. +-- Strict in the list of implicitely imported, orphan and family instances. mkModuleInfo :: GHC.Module -> DynFlags -> Bool -> [PName n] -> [ClsInst] -> [FamInst] -> ModuleInfo n -mkModuleInfo = ModuleInfo +-- the calculate of these fields involves a big parts of the GHC state and it causes a space leak +-- if not evaluated strictly +mkModuleInfo mod dfs boot !imported !orphan !family = ModuleInfo mod dfs boot imported orphan family -- | Info corresponding to an import declaration data ImportInfo n = ImportInfo { _importedModule :: GHC.Module -- ^ The name and package of the imported module @@ -154,8 +151,11 @@ deriving instance Data FamFlavor -- | Creates semantic information for an import declaration +-- Strict in the list of the used and imported declarations, orphan and family instances. mkImportInfo :: GHC.Module -> [n] -> [PName n] -> [ClsInst] -> [FamInst] -> ImportInfo n -mkImportInfo = ImportInfo +-- the calculate of these fields involves a big parts of the GHC state and it causes a space leak +-- if not evaluated strictly +mkImportInfo mod !names !imported !orphan !family = ImportInfo mod names imported orphan family -- | Info corresponding to an record-wildcard data ImplicitFieldInfo = ImplicitFieldInfo { _implicitFieldBindings :: [(Name, Name)] -- ^ The implicitly bounded names
Language/Haskell/Tools/AST/TH/SemanticTraversal.hs view
@@ -1,13 +1,11 @@-{-# LANGUAGE LambdaCase - , TemplateHaskell - #-} +{-# LANGUAGE LambdaCase, TemplateHaskellQuotes #-} -- | Generating instances for traversal on semantic information module Language.Haskell.Tools.AST.TH.SemanticTraversal where -import Control.Monad -import Language.Haskell.TH.Ppr +import Control.Monad (Monad(..), mapM, replicateM) +import Language.Haskell.TH.Ppr (pprint) import Language.Haskell.TH.Syntax -import Language.Haskell.Tools.AST.Ann +import Language.Haskell.Tools.AST.Ann (SemanticTraversal(..)) -- | Generate the instances for semantic information deriveSemanticTraversal :: Name -> Q [Dec]
Language/Haskell/Tools/AST/TH/SourceInfoTraversal.hs view
@@ -1,13 +1,11 @@-{-# LANGUAGE LambdaCase - , TemplateHaskell - #-} +{-# LANGUAGE LambdaCase, TemplateHaskellQuotes #-} -- | Generating instances for traversal on semantic information module Language.Haskell.Tools.AST.TH.SourceInfoTraversal where -import Control.Monad -import Language.Haskell.TH.Ppr +import Control.Monad (Monad(..), mapM, replicateM) +import Language.Haskell.TH.Ppr (pprint) import Language.Haskell.TH.Syntax -import Language.Haskell.Tools.AST.Ann +import Language.Haskell.Tools.AST.Ann (SourceInfoTraversal(..)) -- | Generate the instances for semantic information deriveSourceInfoTraversal :: Name -> Q [Dec]
Language/Haskell/Tools/AST/Utils/GHCInstances.hs view
@@ -1,11 +1,12 @@-{-# LANGUAGE StandaloneDeriving, DeriveDataTypeable #-} +{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving, TypeFamilies #-} + module Language.Haskell.Tools.AST.Utils.GHCInstances where import Data.Data import SrcLoc deriving instance Data SrcLoc - + instance Data RealSrcLoc where gfoldl k z rsl = z mkRealSrcLoc `k` srcLocFile rsl `k` srcLocLine rsl `k` srcLocCol rsl
haskell-tools-ast.cabal view
@@ -1,5 +1,5 @@ name: haskell-tools-ast -version: 0.9.0.0 +version: 1.0.0.0 synopsis: Haskell AST for efficient tooling description: A representation of a Haskell Syntax tree that contain source-related and semantic annotations. These annotations help developer tools to work with the defined program. The source information enables refactoring and program transformation tools to change the source code without losing the original format (layout, comments) of the source. Semantic information helps analyzing the program. The representation is different from the GHC's syntax tree. It contains information from all representations in GHC (different version of syntax trees, lexical and module-level information). The module is split up to put the representation of different language elements into different modules. Additionally, it contains the representation of semantic and source annotations, helper functions and generated instances for the representation of language elements. Because langauge elements may refer each other (there can be a pattern inside an expression in case of a pattern match and an expression inside a pattern if view patterns are enabled), we use hs-boot files to break up dependency cycles. @@ -46,10 +46,10 @@ , Language.Haskell.Tools.AST.TH.SemanticTraversal , Language.Haskell.Tools.AST.TH.SourceInfoTraversal - build-depends: base >= 4.9 && < 4.10 - , ghc >= 8.0 && < 8.1 + build-depends: base >= 4.10 && < 4.11 + , ghc >= 8.2 && < 8.3 , references >= 0.3 && < 0.4 , uniplate >= 1.6 && < 1.7 , mtl >= 2.2 && < 2.3 - , template-haskell >= 2.11 && < 2.12 + , template-haskell >= 2.12 && < 2.13 default-language: Haskell2010