Skip to content
This repository
Newer
Older
100644 61 lines (51 sloc) 2.141 kb
fccc6851 »
2011-06-21 Initial open-source release
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
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
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (* CF mli *)
19
20 (* alias *)
21 module JsIdent = Qmljs_Serializer.JsIdent
22
23 (* shorthands *)
24 module Q = QmlAst
25
26 (* TODO - Merge it on JavaScriptCompilation *)
27 let resolve annotmap code =
28 QmlAstWalk.CodeExpr.fold_map
29 (QmlAstWalk.Expr.foldmap
30 (fun annotmap expr ->
31 match expr with
32 | Q.Directive (_, `js_ident, [Q.Const (_, Q.String name)], []) ->
33 (try
34 let name =
35 try Hashtbl.find Opacapi.table name
36 with Not_found ->
37 QmlError.error (QmlError.Context.annoted_expr annotmap expr)
38 "Not registered in Opacapi"
39 in
40 let jsident =
41 let ident = OpaMapToIdent.val_ ~side:`client name in
42 JsIdent.resolve ident
43 in
44 QmlAstCons.TypedExpr.ident annotmap jsident QmlAstCons.TypedExpr.ty_string
45 with Not_found ->
46 QmlError.error (QmlError.Context.annoted_expr annotmap expr)
47 "Doesn't exists on client side")
48
49 | Q.Directive (_, `js_ident, _, _) ->
50 QmlError.i_serror None (QmlError.Context.annoted_expr annotmap expr) "Malformed directive";
51 (annotmap, expr)
52 | _ -> (annotmap, expr)
53 )
54 )
55 annotmap code
56
57 let perform annotmap code =
58 let annotmap, code = resolve annotmap code in
59 let decls = JsIdent.get_toplevel_declarations () in
60 annotmap, (decls @ code)
Something went wrong with that request. Please try again.