Safe Haskell | None |
---|
TemplateHaskell helper for Ganeti Haskell code.
As TemplateHaskell require that splices be defined in a separate module, we combine all the TemplateHaskell functionality that HTools needs in this module (except the one for unittests).
- class DictObject a where
- toDict :: a -> [(String, JSValue)]
- data OptionalType
- data Field = Field {
- fieldName :: String
- fieldType :: Q Type
- fieldRead :: Maybe (Q Exp)
- fieldShow :: Maybe (Q Exp)
- fieldExtraKeys :: [String]
- fieldDefault :: Maybe (Q Exp)
- fieldConstr :: Maybe String
- fieldIsOptional :: OptionalType
- simpleField :: String -> Q Type -> Field
- renameField :: String -> Field -> Field
- defaultField :: Q Exp -> Field -> Field
- optionalField :: Field -> Field
- optionalNullSerField :: Field -> Field
- customField :: Name -> Name -> [String] -> Field -> Field
- fieldRecordName :: Field -> String
- fieldVariable :: Field -> String
- actualFieldType :: Field -> Q Type
- checkNonOptDef :: Monad m => Field -> m ()
- loadFn :: Field -> Q Exp -> Q Exp -> Q Exp
- timeStampFields :: [Field]
- serialFields :: [Field]
- uuidFields :: [Field]
- type TagSet = Set String
- tagsFields :: [Field]
- type SimpleField = (String, Q Type)
- type SimpleConstructor = (String, [SimpleField])
- type SimpleObject = [SimpleConstructor]
- type Constructor = (String, [Field])
- ensureLower :: String -> String
- ensureUpper :: String -> String
- varNameE :: String -> Q Exp
- showJSONE :: Q Exp
- makeObjE :: Q Exp
- fromObjE :: Q Exp
- toRawName :: String -> Name
- fromRawName :: String -> Name
- reprE :: Either String Name -> Q Exp
- appFn :: Exp -> Exp -> Exp
- buildConsField :: Q Type -> StrictTypeQ
- buildSimpleCons :: Name -> SimpleObject -> Q Dec
- genSaveSimpleObj :: Name -> String -> SimpleObject -> (SimpleConstructor -> Q Clause) -> Q (Dec, Dec)
- strADTDecl :: Name -> [String] -> Dec
- genToRaw :: Name -> Name -> Name -> [(String, Either String Name)] -> Q [Dec]
- genFromRaw :: Name -> Name -> Name -> [(String, Name)] -> Q [Dec]
- declareADT :: Name -> String -> [(String, Name)] -> Q [Dec]
- declareIADT :: String -> [(String, Name)] -> Q [Dec]
- declareSADT :: String -> [(String, Name)] -> Q [Dec]
- genShowJSON :: String -> Q Dec
- genReadJSON :: String -> Q Dec
- makeJSONInstance :: Name -> Q [Dec]
- deCamelCase :: String -> String
- camelCase :: String -> String
- constructorName :: Con -> Q Name
- reifyConsNames :: Name -> Q [String]
- genConstrToStr :: (String -> String) -> Name -> String -> Q [Dec]
- genOpID :: Name -> String -> Q [Dec]
- genAllConstr :: (String -> String) -> Name -> String -> Q [Dec]
- genAllOpIDs :: Name -> String -> Q [Dec]
- type OpParam = (String, Q Type, Q Exp)
- genOpCode :: String -> [Constructor] -> Q [Dec]
- genOpConsFields :: Constructor -> Clause
- genAllOpFields :: String -> [Constructor] -> (Dec, Dec)
- saveConstructor :: String -> [Field] -> Q Clause
- genSaveOpCode :: Name -> String -> String -> [Constructor] -> (Constructor -> Q Clause) -> Bool -> Q [Dec]
- loadConstructor :: String -> [Field] -> Q Exp
- genLoadOpCode :: [Constructor] -> Q (Dec, Dec)
- genStrOfOp :: Name -> String -> Q [Dec]
- genStrOfKey :: Name -> String -> Q [Dec]
- genLuxiOp :: String -> [Constructor] -> Q [Dec]
- saveLuxiConstructor :: Constructor -> Q Clause
- fieldTypeInfo :: String -> Field -> Q (Name, Strict, Type)
- buildObject :: String -> String -> [Field] -> Q [Dec]
- buildObjectSerialisation :: String -> [Field] -> Q [Dec]
- toDictName :: String -> Name
- genSaveObject :: (Name -> Field -> Q Exp) -> String -> [Field] -> Q [Dec]
- saveObjectField :: Name -> Field -> Q Exp
- objectShowJSON :: String -> Q Dec
- genLoadObject :: (Field -> Q (Name, Stmt)) -> String -> [Field] -> Q (Dec, Dec)
- loadObjectField :: Field -> Q (Name, Stmt)
- objectReadJSON :: String -> Q Dec
- paramTypeNames :: String -> (String, String)
- paramFieldTypeInfo :: String -> Field -> Q (Name, Strict, Type)
- buildParam :: String -> String -> [Field] -> Q [Dec]
- buildParamAllFields :: String -> [Field] -> [Dec]
- buildDictObjectInst :: Name -> String -> [Dec]
- buildPParamSerialisation :: String -> [Field] -> Q [Dec]
- savePParamField :: Name -> Field -> Q Exp
- loadPParamField :: Field -> Q (Name, Stmt)
- buildFromMaybe :: String -> Q Dec
- fillParam :: String -> String -> [Field] -> Q [Dec]
- excErrMsg :: (String, Q Type)
- genException :: String -> SimpleObject -> Q [Dec]
- saveExcCons :: String -> [SimpleField] -> Q Clause
- loadExcConstructor :: Name -> String -> [SimpleField] -> Q Exp
- genLoadExc :: Name -> String -> SimpleObject -> Q (Dec, Dec)
Exported types
class DictObject a whereSource
Class of objects that can be converted to JSObject
lists-format.
data OptionalType Source
Eq OptionalType | |
Show OptionalType |
Serialised field data type.
Field | |
|
simpleField :: String -> Q Type -> FieldSource
Generates a simple field.
renameField :: String -> Field -> FieldSource
Sets the renamed constructor field.
defaultField :: Q Exp -> Field -> FieldSource
Sets the default value on a field (makes it optional with a default value).
optionalField :: Field -> FieldSource
Marks a field optional (turning its base type into a Maybe).
optionalNullSerField :: Field -> FieldSource
Marks a field optional (turning its base type into a Maybe), but
with Nothing
serialised explicitly as null.
:: Name | The name of the read function |
-> Name | The name of the show function |
-> [String] | The name of extra field keys |
-> Field | The original field |
-> Field | Updated field |
Sets custom functions on a field.
fieldRecordName :: Field -> StringSource
fieldVariable :: Field -> StringSource
actualFieldType :: Field -> Q TypeSource
checkNonOptDef :: Monad m => Field -> m ()Source
Common field declarations
timeStampFields :: [Field]Source
Timestamp fields description.
serialFields :: [Field]Source
Serial number fields description.
uuidFields :: [Field]Source
UUID fields description.
tagsFields :: [Field]Source
Tag field description.
Internal types
type SimpleField = (String, Q Type)Source
type SimpleConstructor = (String, [SimpleField])Source
type SimpleObject = [SimpleConstructor]Source
type Constructor = (String, [Field])Source
Helper functions
ensureLower :: String -> StringSource
ensureUpper :: String -> StringSource
fromRawName :: String -> NameSource
buildConsField :: Q Type -> StrictTypeQSource
buildSimpleCons :: Name -> SimpleObject -> Q DecSource
genSaveSimpleObj :: Name -> String -> SimpleObject -> (SimpleConstructor -> Q Clause) -> Q (Dec, Dec)Source
Template code for simple raw type-equivalent ADTs
strADTDecl :: Name -> [String] -> DecSource
genFromRaw :: Name -> Name -> Name -> [(String, Name)] -> Q [Dec]Source
declareADT :: Name -> String -> [(String, Name)] -> Q [Dec]Source
declareIADT :: String -> [(String, Name)] -> Q [Dec]Source
declareSADT :: String -> [(String, Name)] -> Q [Dec]Source
genShowJSON :: String -> Q DecSource
genReadJSON :: String -> Q DecSource
makeJSONInstance :: Name -> Q [Dec]Source
Generates a JSON instance for a given type.
This assumes that the nameToRaw and nameFromRaw functions
have been defined as by the declareSADT
function.
Template code for opcodes
deCamelCase :: String -> StringSource
constructorName :: Con -> Q NameSource
reifyConsNames :: Name -> Q [String]Source
genConstrToStr :: (String -> String) -> Name -> String -> Q [Dec]Source
genAllConstr :: (String -> String) -> Name -> String -> Q [Dec]Source
Builds a list with all defined constructor names for a type.
vstr :: String vstr = [...]
Where the actual values of the string are the constructor names
mapped via trans_fun
.
genAllOpIDs :: Name -> String -> Q [Dec]Source
Generates a list of all defined opcode IDs.
:: String | Type name to use |
-> [Constructor] | Constructor name and parameters |
-> Q [Dec] |
Generates the OpCode data type.
This takes an opcode logical definition, and builds both the datatype and the JSON serialisation out of it. We can't use a generic serialisation since we need to be compatible with Ganeti's own, so we have a few quirks to work around.
genOpConsFields :: Constructor -> ClauseSource
genAllOpFields :: String -> [Constructor] -> (Dec, Dec)Source
saveConstructor :: String -> [Field] -> Q ClauseSource
genSaveOpCode :: Name -> String -> String -> [Constructor] -> (Constructor -> Q Clause) -> Bool -> Q [Dec]Source
loadConstructor :: String -> [Field] -> Q ExpSource
genLoadOpCode :: [Constructor] -> Q (Dec, Dec)Source
Template code for luxi
genStrOfOp :: Name -> String -> Q [Dec]Source
Constructor-to-string for LuxiOp.
genStrOfKey :: Name -> String -> Q [Dec]Source
Constructor-to-string for MsgKeys.
genLuxiOp :: String -> [Constructor] -> Q [Dec]Source
Generates the LuxiOp data type.
This takes a Luxi operation definition and builds both the datatype and the function transforming the arguments to JSON. We can't use anything less generic, because the way different operations are serialized differs on both parameter- and top-level.
There are two things to be defined for each parameter:
- name
- type
saveLuxiConstructor :: Constructor -> Q ClauseSource
Objects functionality
fieldTypeInfo :: String -> Field -> Q (Name, Strict, Type)Source
buildObject :: String -> String -> [Field] -> Q [Dec]Source
Build an object declaration.
buildObjectSerialisation :: String -> [Field] -> Q [Dec]Source
Generates an object definition: data type and its JSON instance.
toDictName :: String -> NameSource
genSaveObject :: (Name -> Field -> Q Exp) -> String -> [Field] -> Q [Dec]Source
saveObjectField :: Name -> Field -> Q ExpSource
objectShowJSON :: String -> Q DecSource
genLoadObject :: (Field -> Q (Name, Stmt)) -> String -> [Field] -> Q (Dec, Dec)Source
loadObjectField :: Field -> Q (Name, Stmt)Source
objectReadJSON :: String -> Q DecSource
Inheritable parameter tables implementation
paramTypeNames :: String -> (String, String)Source
paramFieldTypeInfo :: String -> Field -> Q (Name, Strict, Type)Source
buildParam :: String -> String -> [Field] -> Q [Dec]Source
Build a parameter declaration.
This function builds two different data structures: a filled one, in which all fields are required, and a partial one, in which all fields are optional. Due to the current record syntax issues, the fields need to be named differrently for the two structures, so the partial ones get a P suffix.
buildParamAllFields :: String -> [Field] -> [Dec]Source
buildDictObjectInst :: Name -> String -> [Dec]Source
buildPParamSerialisation :: String -> [Field] -> Q [Dec]Source
savePParamField :: Name -> Field -> Q ExpSource
loadPParamField :: Field -> Q (Name, Stmt)Source
buildFromMaybe :: String -> Q DecSource
Template code for exceptions
:: String | Name of new type |
-> SimpleObject | Constructor name and parameters |
-> Q [Dec] |
Builds an exception type definition.
saveExcCons :: String -> [SimpleField] -> Q ClauseSource
loadExcConstructor :: Name -> String -> [SimpleField] -> Q ExpSource
genLoadExc :: Name -> String -> SimpleObject -> Q (Dec, Dec)Source