Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 258 lines (197 sloc) 10.322 kb
fccc685 Initial open-source release
MLstate authored
1 (*
4b041c8 @BourgerieQuentin [fix] compiler, database: Adding all database ident to gamma, even if no...
BourgerieQuentin authored
2 Copyright © 2011, 2012 MLstate
fccc685 Initial open-source release
MLstate authored
3
5bb0f1a @Aqua-Ye [cleanup] compiler: typo on Opa
Aqua-Ye authored
4 This file is part of Opa.
fccc685 Initial open-source release
MLstate authored
5
5bb0f1a @Aqua-Ye [cleanup] compiler: typo on Opa
Aqua-Ye authored
6 Opa is free software: you can redistribute it and/or modify it under the
fccc685 Initial open-source release
MLstate authored
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
5bb0f1a @Aqua-Ye [cleanup] compiler: typo on Opa
Aqua-Ye authored
10 Opa is distributed in the hope that it will be useful, but WITHOUT ANY
fccc685 Initial open-source release
MLstate authored
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
5bb0f1a @Aqua-Ye [cleanup] compiler: typo on Opa
Aqua-Ye authored
16 along with Opa. If not, see <http://www.gnu.org/licenses/>.
fccc685 Initial open-source release
MLstate authored
17 *)
127d16d @BourgerieQuentin [feature] dbGen: Command line to swicth backend
BourgerieQuentin authored
18
6581c14 @BourgerieQuentin [fix] typo: OCaml documentation
BourgerieQuentin authored
19 (** {6 Command line arguments } *)
127d16d @BourgerieQuentin [feature] dbGen: Command line to swicth backend
BourgerieQuentin authored
20
21 (** Describes different backend that dbgen handle. *)
7acaaf1 @cedricss [feature] compiler, database, dropbox: introducing a new db backend base...
cedricss authored
22 type engine = [`db3 | `mongo | `dropbox]
127d16d @BourgerieQuentin [feature] dbGen: Command line to swicth backend
BourgerieQuentin authored
23
24 (** Command line specification provides necessary options for switch
25 database backend. *)
26 module Args : sig
27
28 (** The command line specifications. *)
29 val options : (string * Base.Arg.spec * string) list
30
e337a3b @BourgerieQuentin [enhance] compiler, database: typing + code generation for the new way t...
BourgerieQuentin authored
31 (** Get command line backend.*)
32 val get_engine : unit -> engine option
127d16d @BourgerieQuentin [feature] dbGen: Command line to swicth backend
BourgerieQuentin authored
33
34 end
fccc685 Initial open-source release
MLstate authored
35
5393694 @BourgerieQuentin [fix] compiler, database: Take the default or command line backend for d...
BourgerieQuentin authored
36 (** Get command line backend or default*)
37 val get_engine : unit -> engine
38
6581c14 @BourgerieQuentin [fix] typo: OCaml documentation
BourgerieQuentin authored
39 (** {6 Initialization } **)
13f7390 @BourgerieQuentin [fix] DbGen: Since database runtime was moved of outside stdlib.core tyi...
BourgerieQuentin authored
40
41 (** Set the translation function beetween string and renamed type
42 ident.*)
43 val settyp : (string -> QmlAst.typeident) -> unit
fccc685 Initial open-source release
MLstate authored
44
45 (* =============== *)
46 (** DbGen Main API *)
47
48 module Schema: sig
49
50 (** The type of the database schema. Purely functional structure *)
51 type t = Schema_private.meta_schema
52
28521d4 @BourgerieQuentin [enhance] compiler: (big) Added Update Ast, Added plain node, Added more...
BourgerieQuentin authored
53 type database = {
54 name : string;
55 ident : Ident.t;
4b041c8 @BourgerieQuentin [fix] compiler, database: Adding all database ident to gamma, even if no...
BourgerieQuentin authored
56 dbty : QmlAst.ty;
121d046 @BourgerieQuentin [enhance] compiler, database: Just change type of database options
BourgerieQuentin authored
57 options : QmlAst.Db.options;
28521d4 @BourgerieQuentin [enhance] compiler: (big) Added Update Ast, Added plain node, Added more...
BourgerieQuentin authored
58 package : ObjectFiles.package_name;
59 }
60
53b5fad @BourgerieQuentin [enhance] compiler, database: Added query options
BourgerieQuentin authored
61 type query = QmlAst.expr QmlAst.Db.query * QmlAst.expr QmlAst.Db.query_options
c197c0f @BourgerieQuentin [enhance] compiler: (big) Added more update and query node + added typin...
BourgerieQuentin authored
62
63 type set_kind =
64 | Map of QmlAst.ty * QmlAst.ty
65 | DbSet of QmlAst.ty
66
67 type node_kind =
68 | Compose of (string * string list) list
69 | Plain
ea57f3d @BourgerieQuentin [fix] mongo: (big) Fixes on mongo behind dbgen, default values, parser e...
BourgerieQuentin authored
70 | Partial of bool * string list * string list
fb519cd @BourgerieQuentin [enhance] compiler, database: Added sub path of multi node
BourgerieQuentin authored
71 | SetAccess of set_kind * string list * (bool * query) option (*bool == unique*) * QmlAst.path option
c197c0f @BourgerieQuentin [enhance] compiler: (big) Added more update and query node + added typin...
BourgerieQuentin authored
72
28521d4 @BourgerieQuentin [enhance] compiler: (big) Added Update Ast, Added plain node, Added more...
BourgerieQuentin authored
73 type node = {
74 ty : QmlAst.ty;
75 kind : node_kind;
76 database : database;
1aa37e7 @BourgerieQuentin [feature] compiler, database: Default values generator take care of sele...
BourgerieQuentin authored
77 default : ?select:QmlAst.expr QmlAst.Db.select -> QmlAst.annotmap -> (QmlAst.annotmap * QmlAst.expr);
28521d4 @BourgerieQuentin [enhance] compiler: (big) Added Update Ast, Added plain node, Added more...
BourgerieQuentin authored
78 }
79
80
fccc685 Initial open-source release
MLstate authored
81 (** Maps the idents of the different database schemas and their respective
82 options in a multi-schema *)
83 val mapi:
121d046 @BourgerieQuentin [enhance] compiler, database: Just change type of database options
BourgerieQuentin authored
84 (string list -> QmlAst.ident * QmlAst.Db.options -> QmlAst.ident * QmlAst.Db.options)
fccc685 Initial open-source release
MLstate authored
85 -> t -> t
86
87 (** Initial empty schema *)
88 val initial: t
89
90 (** Returns true if no definitions have been recorded into the schema *)
91 val is_empty: t -> bool
92
93 (**
94 Registers a path (given as string list) with a given type and default
95 value in a schema. The Env.t is only used for looking up typenames
96 Hack: until the refactoring of positions is done, we must pass to this
97 function an error context.
98 *)
99 val register_path:
100 context:QmlError.context ->
101 t -> QmlTypes.Env.t -> QmlAst.Db.path_decl -> QmlAst.ty -> t
102
103 val register_path:
104 context:QmlError.context ->
105 t -> QmlTypes.Env.t -> QmlAst.Db.path_decl -> QmlAst.ty -> t
106
107 (**
108 Registers the default value for a given path; puts the coerced default
109 expression into the schema to type-check later.
110 Hack: until the refactoring of positions is done, we must pass to this
111 function an error context.
112 If name_default_values is true, then this function returns a binding
113 (the name and definition of the default value) and the new expression
114 inside the default value (which is just the name=
115 if name_default_values is false, then the second return value is always None
116 *)
117 val register_default:
118 name_default_values:bool ->
119 context:QmlError.context -> t -> QmlAst.Db.path_decl -> QmlAst.expr -> t * ((Ident.t * QmlAst.expr) * QmlAst.expr) option
120
121 (** Registers database declarations *)
122 val register_db_declaration:
121d046 @BourgerieQuentin [enhance] compiler, database: Just change type of database options
BourgerieQuentin authored
123 t -> Annot.label * Ident.t * QmlAst.Db.path_decl * QmlAst.Db.options
4b041c8 @BourgerieQuentin [fix] compiler, database: Adding all database ident to gamma, even if no...
BourgerieQuentin authored
124 -> t
fccc685 Initial open-source release
MLstate authored
125
126 (** Registers db-related declarations (paths & default & constraints)
127 See register_default for the meaning of the name_default_values parameter
128 and the second return value
129 *)
130 val register_new_db_value:
131 name_default_values:bool ->
132 t -> QmlTypes.Env.t
133 -> Annot.label * (QmlAst.expr, QmlAst.ty) QmlAst.Db.db_def
134 -> t * ((Ident.t * QmlAst.expr) * (QmlAst.expr, QmlAst.ty) QmlAst.Db.db_def) option
135
136 (** Map any prepath to its coerced expression equivalent within the
137 expressions. Additionally, returns a assoc list of old annots to new
138 generated annots that can be used eg. to keep track of positions *)
5fdc6b9 @BourgerieQuentin [enhance] compiler: (big) Common path typing beetween several backend + ...
BourgerieQuentin authored
139 val preprocess_paths_expr: ?val_:(string -> QmlAst.ident) -> t -> QmlTypes.gamma -> QmlAst.expr -> (Annot.t * Annot.t) list * QmlAst.expr
140 val preprocess_paths_code_elt: ?val_:(string -> QmlAst.ident) -> t -> QmlTypes.gamma ->QmlAst.code_elt -> (Annot.t * Annot.t) list * QmlAst.code_elt
2b94068 @BourgerieQuentin [enhance] compiler/lib: (big) default value on bson unserialize + fix up...
BourgerieQuentin authored
141 val preprocess_paths_ast: ?val_:(string -> QmlAst.ident) -> t -> QmlTypes.gamma -> QmlAst.code_elt list -> (Annot.t * Annot.t) list * QmlAst.code_elt list
fccc685 Initial open-source release
MLstate authored
142
143 (** Finalization of the schema, to use before initialisation below, and before
144 code generation. Returns None if no database content is actually defined.
145 Only touches the part of the schema belonging to the current package *)
146 val finalize: t -> t option
147
148 val of_package : t -> ObjectFiles.package_name -> t
149
150 (** Merge two schemas.*)
151 (* Temporary assumption: schemas should be compatible *)
152 (* When each compilation unit will stored ONLY its own schema part (and not the merged one as now),
153 merge will be done only with disjoint schemas (except for the root). *)
154 val merge : t -> t -> t
155
156 (** Folds the given function on all types contained in the schema *)
157 val map_types : (QmlAst.ty -> QmlAst.ty) -> t -> t
158
159 (** Folds the given function on all expressions contained in the schema *)
160 val map_expr : (QmlAst.expr -> QmlAst.expr) -> t -> t
161
162 (** Folds the given function on all expressions contained in the schema
163 (e.g. default values). Use this for typing (before or after finalize *)
164 val fold_expr: ('a -> QmlAst.expr -> 'a) -> 'a -> t -> 'a
165
166 (** Same but also rewrites these definitions *)
167 val foldmap_expr: ('a -> QmlAst.expr -> 'a * QmlAst.expr) -> 'a -> t -> 'a * t
168
169 (** Exports the database schema as dot data, useful for debugging. Display for
170 example with [dot -Tps |display] *)
171 val to_dot: t -> out_channel -> unit
172
173 (** Exports the database schema for the given database as dot data, useful for
174 debugging. Display for example with [dot -Tps |display]. Raises Not_found
175 if the database does not exist, or you didn't specify one and there are
176 several *)
177 val db_to_dot: t -> string option -> out_channel -> unit
178
179 (** As [db_to_dot], but exports as a gml file, that can be used to manipulate
180 live databases with [opa-db-tool] *)
181 val db_to_gml: t -> string option -> out_channel -> unit
182
183 (** Parses a schema saved in the GML format (like in the run-time db) *)
184 val from_gml: string -> t
185
4b041c8 @BourgerieQuentin [fix] compiler, database: Adding all database ident to gamma, even if no...
BourgerieQuentin authored
186 val get_db_declaration: t -> database list
28521d4 @BourgerieQuentin [enhance] compiler: (big) Added Update Ast, Added plain node, Added more...
BourgerieQuentin authored
187
2b94068 @BourgerieQuentin [enhance] compiler/lib: (big) default value on bson unserialize + fix up...
BourgerieQuentin authored
188 val get_node: t -> QmlAst.path -> node
28521d4 @BourgerieQuentin [enhance] compiler: (big) Added Update Ast, Added plain node, Added more...
BourgerieQuentin authored
189
190 val pp_node: node BaseFormat.pprinter
191
fccc685 Initial open-source release
MLstate authored
192 (**
193 Hackish module, should be removed after the refactoring of positions in the AST.
194 *)
195 module HacksForPositions :
196 sig
197 (**
198 Special Hackish annotmap, used for finding positions for error messages.
199 Used for having an annotmap when the module fails, without changing every
200 interfaces by adding an annotmap in argument.
201 *)
202 val set_annotmap : QmlAst.annotmap -> unit
203 val free_annotmap : unit -> unit
204 end
205 end
206
1aa37e7 @BourgerieQuentin [feature] compiler, database: Default values generator take care of sele...
BourgerieQuentin authored
207 module Utils : sig
208
209 val type_of_selected : QmlTypes.gamma -> QmlAst.ty -> 'a QmlAst.Db.select -> QmlAst.ty
210
211 end
212
fccc685 Initial open-source release
MLstate authored
213 module type S = sig include DbGenByPass.S end
214
215 (** Internal type used to handle bindings in code generation *)
216 type dbinfo
217 val merge_dbinfo : dbinfo -> dbinfo -> dbinfo
218
219 module DbGen: functor ( Arg: S ) -> sig
220 (** [initialize schema] initialises database code on a given schema. It
221 returns the dbinfo needed for further access to this database, the gamma
222 corresponding to defined idents and the initial code that opens the
223 database and defines the specialised access functions. The returned annotmap
224 contains only added annots.
225
226 The Arg module must give access to identifiers linked to "some", "none",
227 "map_empty", "map_add"...
228
229 The returned code should be put _after_ declarations of these
230 identifiers and _before_ any access to the DB *)
28521d4 @BourgerieQuentin [enhance] compiler: (big) Added Update Ast, Added plain node, Added more...
BourgerieQuentin authored
231 val initialize: ?annotmap:(QmlAst.annotmap option) -> ?valinitial_env:(Arg.ValInitial.env) -> QmlTypes.gamma -> Schema.t -> dbinfo StringListMap.t * QmlTypes.Env.t * (QmlAst.annotmap option) * QmlAst.code * QmlAst.code
fccc685 Initial open-source release
MLstate authored
232
233 (** Replaces all path accesses in an expression by calls to Db3. The resulting
234 expression is guaranteed not to contain any Path or Transaction.
235
236 The annotmap must be provided for the resulting code to be typed. Returns the
237 annotmap of created annots or IntMap.empty. *)
238 val replace_path_exprs: Schema.t -> dbinfo StringListMap.t -> QmlTypes.gamma -> ?annotmap:(QmlAst.annotmap option) -> ?valinitial_env:(Arg.ValInitial.env) -> QmlAst.expr -> QmlAst.annotmap option * QmlAst.expr
239
240 (** Same as [replace_path_exprs] but maps on a code_elt *)
241 val replace_path_code_elt: Schema.t -> dbinfo StringListMap.t -> QmlTypes.gamma -> ?annotmap:(QmlAst.annotmap option) -> ?valinitial_env:(Arg.ValInitial.env) -> QmlAst.code_elt -> QmlAst.annotmap option * QmlAst.code_elt * QmlTypes.gamma
242
243 (** Same as [replace_path_exprs] but maps on a full code *)
244 val replace_path_ast: Schema.t -> dbinfo StringListMap.t -> QmlTypes.gamma -> ?annotmap:(QmlAst.annotmap option) -> ?valinitial_env:(Arg.ValInitial.env) -> QmlAst.code -> QmlAst.annotmap option * QmlAst.code * QmlTypes.gamma
245 end
246
247 module DbGenByPass : sig
248 module MakeS ( N : DbGenByPass.SourceInterface ) (I : DbGenByPass.I) : S with type ValInitial.env = I.env
249 module I_Unit : DbGenByPass.I
250 module I_Alpha : DbGenByPass.I
251 module BSLDbGen : S
252 module BSLDbGenAlpha : S
253 module BSLDbGenAlphaOpa : S with type ValInitial.env = QmlAlphaConv.t option
254 end
255
256 (** Warnings that can be triggered by DbGen and schema processing *)
257 val warning_set: WarningClass.Set.t
Something went wrong with that request. Please try again.