CloogleDBFactory.dcl 3.04 KB
Newer Older
Camil Staps's avatar
Camil Staps committed
1
definition module CloogleDBFactory
2

Camil Staps's avatar
Camil Staps committed
3 4 5
/**
 * Functions to populate a database using the Clean compiler frontend
 */
6

Camil Staps's avatar
Camil Staps committed
7 8
from Data.Set import :: Set

Camil Staps's avatar
Camil Staps committed
9
import CloogleDB
10

11 12
:: TemporaryDB

13 14
newTemporaryDB :: TemporaryDB
finaliseDB :: ![CloogleEntry] !TemporaryDB -> *CloogleDB
15

Camil Staps's avatar
Camil Staps committed
16 17 18 19 20 21 22
/**
 * Find all modules that could be indexed
 *
 * @param Excluded modules. If the path contains any of the strings in this
 *   parameter, a module will not be considered.
 * @param The root of the library directory (typically $CLEAN_HOME/lib).
 * @param The library to look in.
23
 * @param Some auxiliary value to store with the modules.
Camil Staps's avatar
Camil Staps committed
24 25 26 27
 * @param A part of the module hierarchy to look for. The empty string to look
 *   in the whole library, otherwise e.g. Crypto.Hash to only include modules
 *   in that hierarchy.
 * @param The World.
28 29
 * @result A list of modules found (library, module, whether it is part of the
 *   library core, whether it is an app).
Camil Staps's avatar
Camil Staps committed
30
 */
31 32
findModules :: ![String] !String !Library !a !String !*World
	-> *(![(Library, Module, a)], !*World)
Camil Staps's avatar
Camil Staps committed
33 34 35 36

/**
 * Update a database with all the information found in a module
 *
37
 * @param Whether local definitions (that only exist in the icl) should be indexed.
Camil Staps's avatar
Camil Staps committed
38 39 40
 * @param The root of the library directory (typically $CLEAN_HOME/lib).
 * @param The module to index.
 * @param The library the module to index is in.
41
 * @param A function to update module information (to set me_is_core, me_is_app).
Camil Staps's avatar
Camil Staps committed
42 43 44
 * @param The old database.
 * @result The new database.
 */
45 46
indexModule :: !Bool !String !Module !Library
	!(String ModuleEntry -> ModuleEntry) !TemporaryDB !*World
47
	-> *(!TemporaryDB, !*World)
48

49
:: LocationInModule =
Camil Staps's avatar
Camil Staps committed
50 51 52 53 54 55 56 57
	{ dcl_line :: Maybe Int
	, icl_line :: Maybe Int
	, name     :: Maybe String
	}

/**
 * Parse a module and get its contents
 *
58
 * @param Whether local definitions (that only exist in the icl) should be indexed.
Camil Staps's avatar
Camil Staps committed
59 60
 * @param The path to the module, without .icl or .dcl
 * @result A tuple of:
61 62
 *   - Function type specifications
 *   - Macro definitions and other functions that do not have a type
Camil Staps's avatar
Camil Staps committed
63 64 65 66 67 68 69 70 71 72
 *   - Generic function definitions
 *   - Constructor function definitions
 *   - Record field function definitions
 *   - Type definitions
 *   - Class definitions
 *   - Instances
 *   - Derivations
 *   - Class derivations
 *   - The module
 */
73
findModuleContents :: !Bool !String !*World
Camil Staps's avatar
Camil Staps committed
74 75 76
	-> *( ![(LocationInModule, FunctionEntry, Set String)]
	    , ![(LocationInModule, FunctionEntry, Set String)]
	    , ![(LocationInModule, FunctionEntry, Set String)]
77
	    , ![(LocationInModule, TypeDefEntry)]
Camil Staps's avatar
Camil Staps committed
78
	    , ![(LocationInModule, ClassEntry, [(String, FunctionEntry, Set String)])]
79 80 81
	    , ![(Name, [(Type, String)], LocationInModule)]
	    , ![(Name, [(Type, String, LocationInModule)])]
	    , ![(Name, Type, String, LocationInModule)]
Camil Staps's avatar
Camil Staps committed
82
	    , !(Name, ModuleEntry, Set String)
Camil Staps's avatar
Camil Staps committed
83 84 85
	    , !*World
	    )

Camil Staps's avatar
Camil Staps committed
86 87 88
/**
 * Transform the constructors of an algebraic data type into plain functions.
 */
Camil Staps's avatar
Camil Staps committed
89
constructor_functions :: TypeDefEntry -> [FunctionEntry]
Camil Staps's avatar
Camil Staps committed
90 91 92 93

/**
 * Transform the record fields of a record type into plain functions.
 */
Camil Staps's avatar
Camil Staps committed
94
record_functions :: TypeDefEntry -> [FunctionEntry]