properties <- lCommaSep parseFortranParamProperty
return $ FortranParameter properties
-parseFortranParamProperty :: OFLParser FortranParameterProperty
+parseFortranParamProperty :: OFLParser FortranParamProperty
parseFortranParamProperty =
parseNameProperty
<|> parseTypeProperty
module OFC.SecondLevel where
import OFC.Common
import OFC.TargetMapping (MappingTable, FortranFunction)
-import qualified OFC.TargetMapping as TargetMapping
+import qualified OFC.TargetMapping as TM
import OFC.TopLevel (OFL)
import qualified OFC.TopLevel as TopLevel
import Data.Complex
valueType = getTargetValueType $ TopLevel.getTargetType ofl name
indexTypes = TopLevel.getIndices ofl name
-getTargetValueType :: TargetMapping.TargetType -> ValueType
-getTargetValueType (TargetMapping.PPDFunctionSet _) = Psinc 1
-getTargetValueType t = error $ "Not implemented translation of " ++ show t ++ " to second-level value type."
+getTargetValueType :: TM.TargetType -> ValueType
+getTargetValueType (TM.PPDFunctionSet _) = Psinc 1
+getTargetValueType (TM.FortranParameter properties) = case TM.findSpace properties of
+ Just (TM.CoarsePsinc _) -> Psinc 1
+ Just (TM.FinePsinc _) -> Psinc 2
+ Nothing -> case TM.findParamType properties of
+ Just fortranType -> fortranToValueType fortranType
+ Nothing -> error $ "Unable to infer type from supplied properties: " ++ show properties
+ where
+ fortranToValueType TM.SPAM3 = RealType
+ fortranToValueType TM.Double = RealType
+ fortranToValueType TM.FunctionBasis = error "ONETEP function basis cannot be mapped to value types."
+ fortranToValueType TM.Integer = IntegerType
+ fortranToValueType (TM.Array t _) = fortranToValueType t
module OFC.TargetMapping where
import Data.Map (Map)
+import Data.Maybe (catMaybes)
type MappingTable = Map String TargetType
data TargetType =
- FortranParameter [FortranParameterProperty] |
+ FortranParameter [FortranParamProperty] |
PPDFunctionSet [PPDFunctionSetProperty]
deriving Show
FinePsinc [String]
deriving Show
-data FortranParameterProperty =
+data FortranParamProperty =
ParamName String |
ParamType FortranType |
Space SpaceInfo |
FortranFunctionName String |
FortranFunctionParams [String]
deriving Show
+
+findSpace :: [FortranParamProperty] -> Maybe SpaceInfo
+findSpace properties = getProperty toSpaceInfo properties
+ where
+ toSpaceInfo (Space info) = Just info
+ toSpaceInfo _ = Nothing
+
+findParamType :: [FortranParamProperty] -> Maybe FortranType
+findParamType properties = getProperty toFortranType properties
+ where
+ toFortranType (ParamType t) = Just t
+ toFortranType _ = Nothing
+
+
+getProperty :: (Show a) => (FortranParamProperty -> Maybe a) -> [FortranParamProperty] -> Maybe a
+getProperty getter properties = case catMaybes $ map getter properties of
+ [] -> Nothing
+ [x] -> Just x
+ dups -> error $ "Duplicate properties found: " ++ show dups
+