Permalink
Browse files

[feature] dbGen: Import database runtime corresponding to the selecte…

…d backedn
  • Loading branch information...
1 parent 127d16d commit 6019e3a32d3aabed9464f209665f3d75bf5efe1e @BourgerieQuentin BourgerieQuentin committed Nov 25, 2011
Showing with 85 additions and 0 deletions.
  1. +1 −0 opa/_tags
  2. +2 −0 opa/main.ml
  3. +37 −0 opa/pass_DbEngineImportation.ml
  4. +22 −0 opa/pass_DbEngineImportation.mli
  5. +15 −0 opa/s3Passes.ml
  6. +8 −0 opa/s3Passes.mli
View
@@ -35,6 +35,7 @@
<pass_JavascriptCompilation.{ml,mli}>: use_libqmlcompil, use_libbsl, use_opalib, use_qml2js, use_opalang, use_jslang, use_qml2ocaml, use_qmljsimp
<pass_RegisterAppSrcCode.{ml,mli}>: use_libqmlcompil, use_opapasses, use_opalang
<pass_TreatNoClientCalls.{ml,mli}>: use_libqmlcompil, use_opapasses, use_opalang
+<pass_DbEngineImportation.{ml,mli}>: use_libqmlcompil, use_opalang
<reordering.{ml,mli}>: use_graph, use_libqmlcompil, use_opalib
View
@@ -67,6 +67,8 @@ let () =
|+> ("RegisterAppSrcCode", S3.pass_RegisterAppSrcCode)
+ |+> ("DbEngineImportation", S3.pass_DbEngineImportation)
+
(**********************************************)
(* SURFACE AST PASSES *************************)
|> PH.handler ~count_time:false "LoadObjects" (S3.pass_LoadObjects (fun e -> e
@@ -0,0 +1,37 @@
+(*
+ Copyright © 2011 MLstate
+
+ This file is part of OPA.
+
+ OPA is free software: you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License, version 3, as published by
+ the Free Software Foundation.
+
+ OPA is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
+ more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with OPA. If not, see <http://www.gnu.org/licenses/>.
+*)
+
+(* shorthands *)
+module S = SurfaceAst
+module Db = QmlDbGen
+
+let builtinpos = FilePos.nopos "Built in pass DbEngineImportation"
+
+let process_code code =
+ if List.exists
+ (function
+ | (S.Database _), _ | (S.NewDbDef _), _ -> true
+ | _ -> false)
+ code then
+ ObjectFiles.import_package
+ (match QmlDbGen.Args.get_engine () with
+ | Db.Db3 -> "stdlib.database.db3"
+ | Db.Mongo -> "stdlib.database.mongo")
+ builtinpos
+ ;
+ code
@@ -0,0 +1,22 @@
+(*
+ Copyright © 2011 MLstate
+
+ This file is part of OPA.
+
+ OPA is free software: you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License, version 3, as published by
+ the Free Software Foundation.
+
+ OPA is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
+ more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with OPA. If not, see <http://www.gnu.org/licenses/>.
+*)
+
+(**
+ This pass import the database runtime if needed.
+*)
+val process_code : ('ident, 'dir) SurfaceAst.code -> ('ident, 'dir) SurfaceAst.code
View
@@ -489,6 +489,20 @@ let pass_Print =
e
)
+let pass_DbEngineImportation =
+ PassHandler.make_pass
+ (fun e ->
+ let (a, user_files) = e.PH.env in
+ let user_files = List.map
+ (fun pfile ->
+ {pfile with SurfaceAstPassesTypes.parsedFile_lcode =
+ Pass_DbEngineImportation.process_code
+ pfile.SurfaceAstPassesTypes.parsedFile_lcode}
+ ) user_files in
+ { e with PH.env = (a, user_files) }
+ )
+
+
let pass_LoadObjects k =
PH.make_pass
(fun env ->
@@ -875,6 +889,7 @@ let pass_DbSchemaGeneration =
in
PassHandler.make_pass ~precond ~postcond ~invariant
(fun e ->
+ QmlDbGen.settyp OpaMapToIdent.typ;
let env = ( e.PH.env : 'tmp_env Passes.env_Gen ) in
let typerEnv = env.Passes.typerEnv in
let code = env.Passes.qmlAst in
View
@@ -121,6 +121,14 @@ val pass_RegisterAppSrcCode :
'parsed_files
) opa_pass
+val pass_DbEngineImportation :
+ ((
+ ( SurfaceAst.parsing_directive SurfaceAstPassesTypes.parsed_file list
+ * SurfaceAst.parsing_directive SurfaceAstPassesTypes.parsed_file list
+ ) as 'parsed_files)
+ ,
+ 'parsed_files)
+ opa_pass
val pass_BslLoading :
((((SurfaceAst.nonuid, SurfaceAst.parsing_directive)

0 comments on commit 6019e3a

Please sign in to comment.