Module RW.Generator

Implementation of the command-line interface/tool and abstract RW program generation.

Author: Lasse Züngel

Version: July 2024

Summary of exported operations:

version :: Float  Deterministic 
Implementation of the abstract ReadWrite program generation tool The codegen version.
genClass :: [CFuncDecl] -> RWM CClassDecl  Deterministic 
Generates the ReadWrite class.
genInstance :: CTypeDecl -> RWM CInstanceDecl  Deterministic 
Generates a ReadWrite instance for a type declaration.
genInstances :: [CTypeDecl] -> RWM [CInstanceDecl]  Deterministic 
gen :: RWM CurryProg  Deterministic 
Generates the complete RW curry program.
genFunction :: CTypeDecl -> FunctionLayout -> RWM CFuncDecl  Deterministic 
For a given type t and a function layout, this function generates a function declaration.
allDataDefs :: CurryProg -> [(String,String)]  Deterministic 
Analyzes the module, handles missing data definitions Returns the names of all data definitions in the given program.
allDataUsed :: CurryProg -> [(String,String)]  Deterministic 
Returns the names of all data definitions used in the program.
allPredefined :: Naming -> [CInstanceDecl] -> [(String,String)]  Deterministic 
Returns the names of all data names defined in the program.
containsFunction :: CTypeDecl -> Bool  Deterministic 
Returns true iff the type declaration contains functional types.
modules :: [(String,String)] -> [String]  Deterministic 
Returns the module names of all qualified names.
defaultStrLn :: Int  Deterministic 
CLI tool implementation The default minimum string length for extraction.
defaultAlphabetLength :: Int  Deterministic 
The default string id alphabet length.
runTool :: [String] -> [FunctionLayout] -> IO ()  Non-deterministic 
Runs the codegen tool for the given read and write generator as well as the format representation type.
toolBanner :: String  Deterministic 
Command line processing
processOptions :: [String] -> IO (CLOptions,[String])  Deterministic 
printUsage :: IO ()  Deterministic 
options :: [OptDescr (CLOptions -> CLOptions)]  Deterministic 
generateOperations :: CLOptions -> CurryProg  Deterministic 
Based on the command line options, this function generates a module containing specific parametrized versions of the write and show functions.
coding :: String  Deterministic 
FunctionGenerator implementations for the RW class instances hexadezimal coding
logI :: Int -> Int -> Int  Deterministic 
Logarithm to base b
codingI :: Int -> Int -> String  Deterministic 
Used to encode a constructor index as a list of characters (for pattern matching in the read function).
generatorShow :: CTypeDecl -> RWM [CRule]  Deterministic 
show generator implementation
generatorRead :: CTypeDecl -> RWM [CRule]  Deterministic 
read generator implementation
generatorWrite :: CTypeDecl -> RWM [CRule]  Deterministic 
write generator implementation
generatorTypeOf :: CTypeDecl -> RWM [CRule]  Deterministic 

typeOf generator implementation

For a data definition

data T a b ...

rwbaseName :: String -> (String,String)  Deterministic 
main :: IO ()  Non-deterministic 
Runs the tool
runWith :: [String] -> IO ()  Non-deterministic 

Exported operations:

version :: Float  Deterministic 

Implementation of the abstract ReadWrite program generation tool The codegen version.

Further infos:
  • solution complete, i.e., able to compute all solutions

genClass :: [CFuncDecl] -> RWM CClassDecl  Deterministic 

Generates the ReadWrite class.

genInstance :: CTypeDecl -> RWM CInstanceDecl  Deterministic 

Generates a ReadWrite instance for a type declaration. Given a type

T t1 ... tn = C1 c1_1 ... c1_k1 | ... | Cn cn_1 ... cn_kn

the function generates an instance

instance (ReadWrite t1, ..., ReadWrite tn) => ReadWrite (T t1 ... tn)
 where read  = ...
       write = ...
       ...

The concrete read and write (and/or possibly other) function generation depends on the generator functions supplied by the concrete implementation.

gen :: RWM CurryProg  Deterministic 

Generates the complete RW curry program.

genFunction :: CTypeDecl -> FunctionLayout -> RWM CFuncDecl  Deterministic 

For a given type t and a function layout, this function generates a function declaration. The function layout contains the name of the function, the type of the function and the generator function for the function body.

allDataDefs :: CurryProg -> [(String,String)]  Deterministic 

Analyzes the module, handles missing data definitions Returns the names of all data definitions in the given program.

allDataUsed :: CurryProg -> [(String,String)]  Deterministic 

Returns the names of all data definitions used in the program.

allPredefined :: Naming -> [CInstanceDecl] -> [(String,String)]  Deterministic 

Returns the names of all data names defined in the program. Used to retrieve the names of all predefined data definition instances.

containsFunction :: CTypeDecl -> Bool  Deterministic 

Returns true iff the type declaration contains functional types.

modules :: [(String,String)] -> [String]  Deterministic 

Returns the module names of all qualified names.

defaultStrLn :: Int  Deterministic 

CLI tool implementation The default minimum string length for extraction.

Further infos:
  • solution complete, i.e., able to compute all solutions

defaultAlphabetLength :: Int  Deterministic 

The default string id alphabet length.

Further infos:
  • solution complete, i.e., able to compute all solutions

runTool :: [String] -> [FunctionLayout] -> IO ()  Non-deterministic 

Runs the codegen tool for the given read and write generator as well as the format representation type.

toolBanner :: String  Deterministic 

Command line processing

Further infos:
  • solution complete, i.e., able to compute all solutions

processOptions :: [String] -> IO (CLOptions,[String])  Deterministic 

printUsage :: IO ()  Deterministic 

generateOperations :: CLOptions -> CurryProg  Deterministic 

Based on the command line options, this function generates a module containing specific parametrized versions of the write and show functions.

coding :: String  Deterministic 

FunctionGenerator implementations for the RW class instances hexadezimal coding

logI :: Int -> Int -> Int  Deterministic 

Logarithm to base b

codingI :: Int -> Int -> String  Deterministic 

Used to encode a constructor index as a list of characters (for pattern matching in the read function).

generatorShow :: CTypeDecl -> RWM [CRule]  Deterministic 

show generator implementation

generatorRead :: CTypeDecl -> RWM [CRule]  Deterministic 

read generator implementation

generatorWrite :: CTypeDecl -> RWM [CRule]  Deterministic 

write generator implementation

generatorTypeOf :: CTypeDecl -> RWM [CRule]  Deterministic 

typeOf generator implementation

For a data definition

data T a b ... = ...

this function generates the following code:

typeOf :: T a b ... -> RWType typeOf n = RWType "T" [typeOf (geta n), typeOf (getb n), ...] where geta :: T a b ... -> a geta (T a b ...) = failed ...

rwbaseName :: String -> (String,String)  Deterministic 

Further infos:
  • solution complete, i.e., able to compute all solutions

main :: IO ()  Non-deterministic 

Runs the tool

runWith :: [String] -> IO ()  Non-deterministic