From 6122fba46948938fd615a600c9de160ee9f0a15b Mon Sep 17 00:00:00 2001 From: Francis Russell Date: Wed, 5 Dec 2012 19:36:33 +0000 Subject: [PATCH] Reformat ADT declarations. --- OFC/Common.hs | 8 ++--- OFC/SecondLevel.hs | 80 ++++++++++++++++++++++---------------------- OFC/TargetMapping.hs | 52 ++++++++++++++-------------- OFC/TopLevel.hs | 57 ++++++++++++++++--------------- 4 files changed, 100 insertions(+), 97 deletions(-) diff --git a/OFC/Common.hs b/OFC/Common.hs index aeb8e65..e4d0684 100644 --- a/OFC/Common.hs +++ b/OFC/Common.hs @@ -8,10 +8,10 @@ import Text.PrettyPrint , integer, int, parens) import Data.Complex (Complex(..), realPart, imagPart) -data IndexType = - FunctionIndex | - SpinIndex | - SpatialIndex +data IndexType + = FunctionIndex + | SpinIndex + | SpatialIndex deriving (Show, Eq, Enum, Bounded) class PrettyPrintable a where diff --git a/OFC/SecondLevel.hs b/OFC/SecondLevel.hs index 3069e3e..137e35c 100644 --- a/OFC/SecondLevel.hs +++ b/OFC/SecondLevel.hs @@ -30,26 +30,26 @@ maxPsincDensity = 2 type SymbolTable = Map String SymbolType -data Quantification = - Forall | - Bound +data Quantification + = Forall + | Bound deriving Show -data SymbolType = - ValueTag ValueType [IndexType] | - IndexTag IndexType Quantification +data SymbolType + = ValueTag ValueType [IndexType] + | IndexTag IndexType Quantification deriving Show -data ValueType = - ScalarT ScalarType | - PositionT PositionFieldType | - MomentumT MomentumFieldType +data ValueType + = ScalarT ScalarType + | PositionT PositionFieldType + | MomentumT MomentumFieldType deriving (Eq, Show) -data ScalarType = - RealType | - ComplexType | - IntegerType +data ScalarType + = RealType + | ComplexType + | IntegerType deriving (Eq, Show) instance Monoid ScalarType where @@ -60,14 +60,14 @@ instance Monoid ScalarType where mappend ComplexType _ = ComplexType mappend _ ComplexType = ComplexType -data PositionFieldType = - Psinc Integer | - AnalyticPositionType +data PositionFieldType + = Psinc Integer + | AnalyticPositionType deriving (Eq, Show) -data MomentumFieldType = - PsincReciprocal Integer | - AnalyticMomentumType +data MomentumFieldType + = PsincReciprocal Integer + | AnalyticMomentumType deriving (Eq, Show) data PsincE @@ -78,16 +78,16 @@ deriving instance Show PsincE deriving instance Show PsincReciprocalE deriving instance Show ScalarE -data OperatorExpr num terminal = - OpAdd (OperatorExpr num terminal) (OperatorExpr num terminal) | - OpSub (OperatorExpr num terminal) (OperatorExpr num terminal) | - OpMul (OperatorExpr num terminal) (OperatorExpr num terminal) | - OpDiv (OperatorExpr num terminal) (OperatorExpr num terminal) | - OpPow (OperatorExpr num terminal) (OperatorExpr num terminal) | - OpNeg (OperatorExpr num terminal) | - OpIndexedScalarIdentifier String [String] | - OpConstant num | - OpTerminal terminal +data OperatorExpr num terminal + = OpAdd (OperatorExpr num terminal) (OperatorExpr num terminal) + | OpSub (OperatorExpr num terminal) (OperatorExpr num terminal) + | OpMul (OperatorExpr num terminal) (OperatorExpr num terminal) + | OpDiv (OperatorExpr num terminal) (OperatorExpr num terminal) + | OpPow (OperatorExpr num terminal) (OperatorExpr num terminal) + | OpNeg (OperatorExpr num terminal) + | OpIndexedScalarIdentifier String [String] + | OpConstant num + | OpTerminal terminal deriving Show instance (PrettyPrintable num, PrettyPrintable terminal) => PrettyPrintable (OperatorExpr num terminal) where @@ -106,15 +106,15 @@ instance (PrettyPrintable num, PrettyPrintable terminal) => PrettyPrintable (Ope where binaryToDoc op lhs rhs = parens $ hcat [toDoc lhs, text op, toDoc rhs] -data PositionTerminal = - PositionComponent String +data PositionTerminal + = PositionComponent String deriving Show instance PrettyPrintable PositionTerminal where toDoc (PositionComponent index) = text $ "r[" ++ index ++ "]" -data MomentumTerminal = - MomentumComponent String +data MomentumTerminal + = MomentumComponent String deriving Show instance PrettyPrintable MomentumTerminal where @@ -370,9 +370,9 @@ generateVariants ofl2 expr = case expr of Left _ -> [] Right _ -> resampled ofl2 e -data Assignment = - AssignPsinc (Expression PsincE) (Expression PsincE) | - AssignScalar (Expression ScalarE) (Expression ScalarE) +data Assignment + = AssignPsinc (Expression PsincE) (Expression PsincE) + | AssignScalar (Expression ScalarE) (Expression ScalarE) deriving Show instance PrettyPrintable Assignment where @@ -555,9 +555,9 @@ buildPositionOperator _ _ e = error $ "Unhandled expression: " ++ prettyPrint e -- Frequency fixup -data Bandwidth = - GMaxMultiple Integer | - Infinite +data Bandwidth + = GMaxMultiple Integer + | Infinite deriving (Eq, Show) instance Ord Bandwidth where diff --git a/OFC/TargetMapping.hs b/OFC/TargetMapping.hs index d8feb92..907f729 100644 --- a/OFC/TargetMapping.hs +++ b/OFC/TargetMapping.hs @@ -17,48 +17,48 @@ import Data.Maybe (catMaybes) type MappingTable = Map String TargetType -data TargetType = - FortranParameter [FortranParamProperty] | - PPDFunctionSet [PPDFunctionSetProperty] +data TargetType + = FortranParameter [FortranParamProperty] + | PPDFunctionSet [PPDFunctionSetProperty] deriving Show -data FortranType = - Array FortranType [ArrayIndex] | - SPAM3 | - FunctionBasis | - Double | - Integer +data FortranType + = Array FortranType [ArrayIndex] + | SPAM3 + | FunctionBasis + | Double + | Integer deriving Show -data ArrayIndex = - UnnamedIndex | - NamedIndex String +data ArrayIndex + = UnnamedIndex + | NamedIndex String deriving Show -data SpaceInfo = - CoarsePsinc [String] | - FinePsinc [String] +data SpaceInfo + = CoarsePsinc [String] + | FinePsinc [String] deriving Show -data FortranParamProperty = - ParamName String | - ParamType FortranType | - Space SpaceInfo | - Indexed [String] +data FortranParamProperty + = ParamName String + | ParamType FortranType + | Space SpaceInfo + | Indexed [String] deriving Show -data PPDFunctionSetProperty = - PPDData String | - PPDBasis String +data PPDFunctionSetProperty + = PPDData String + | PPDBasis String deriving Show data FortranFunction = FortranFunction String [FortranFunctionProperty] deriving Show -data FortranFunctionProperty = - FortranFunctionName String | - FortranFunctionParams [String] +data FortranFunctionProperty + = FortranFunctionName String + | FortranFunctionParams [String] deriving Show findSpace :: [FortranParamProperty] -> Maybe SpaceInfo diff --git a/OFC/TopLevel.hs b/OFC/TopLevel.hs index 850e89d..0c923ff 100644 --- a/OFC/TopLevel.hs +++ b/OFC/TopLevel.hs @@ -44,15 +44,15 @@ import Data.Set (Set) import qualified Data.Set as Set -- The top-level types -data BaseType = - RealType | - FunctionType | - IntegerType +data BaseType + = RealType + | FunctionType + | IntegerType deriving (Show, Eq, Enum, Bounded) -data GeneralType = - FieldType | - ScalarType +data GeneralType + = FieldType + | ScalarType deriving Show baseToGeneralType :: BaseType -> GeneralType @@ -61,20 +61,20 @@ baseToGeneralType FunctionType = FieldType baseToGeneralType IntegerType = ScalarType -- Expressions -data Expression = - IndexedIdentifier String [String] | - ConstReal Double | - ConstInteger Integer | - Negate Expression | - Integrate Expression | - Sum Expression String | - Multiply Expression Expression | - Divide Expression Expression | - Add Expression Expression | - Sub Expression Expression | - Power Expression Expression | - PositionComponent String | - SpatialDerivative Expression String Integer +data Expression + = IndexedIdentifier String [String] + | ConstReal Double + | ConstInteger Integer + | Negate Expression + | Integrate Expression + | Sum Expression String + | Multiply Expression Expression + | Divide Expression Expression + | Add Expression Expression + | Sub Expression Expression + | Power Expression Expression + | PositionComponent String + | SpatialDerivative Expression String Integer deriving Show instance PrettyPrintable Expression where @@ -98,8 +98,8 @@ instance PrettyPrintable Expression where binaryToDoc op lhs rhs = parens $ hcat [toDoc lhs, text op, toDoc rhs] functionToDoc name params = text name <> (parens $ hcat (intersperse (text ", ") params)) -data Assignment = - Assign Expression Expression +data Assignment + = Assign Expression Expression deriving Show instance PrettyPrintable Assignment where @@ -117,9 +117,9 @@ instance OFLKeyword IndexType where toOFLString indexType = show indexType -- The symbol table -data SymbolType = - ValueTag BaseType [IndexType] | - IndexTag IndexType +data SymbolType + = ValueTag BaseType [IndexType] + | IndexTag IndexType deriving Show type SymbolTable = Map String SymbolType @@ -278,7 +278,10 @@ emptyOFL = OFL { } -- Validation -data ValidationError = Message String deriving Show +data ValidationError + = Message String + deriving Show + type ValidationResult = Either ValidationError () validationSuccess :: ValidationResult -- 2.47.3