|
@@ -91,14 +91,37 @@ let gen_meta meta =
|
|
|
) meta in
|
|
|
[node "meta" [] nodes]
|
|
|
|
|
|
-let rec gen_type t =
|
|
|
+let rec gen_type ?(tfunc=None) t =
|
|
|
match t with
|
|
|
| TMono m -> (match !m with None -> tag "unknown" | Some t -> gen_type t)
|
|
|
| TEnum (e,params) -> gen_type_decl "e" (TEnumDecl e) params
|
|
|
| TInst (c,params) -> gen_type_decl "c" (TClassDecl c) params
|
|
|
| TAbstract (a,params) -> gen_type_decl "x" (TAbstractDecl a) params
|
|
|
| TType (t,params) -> gen_type_decl "t" (TTypeDecl t) params
|
|
|
- | TFun (args,r) -> node "f" ["a",String.concat ":" (List.map gen_arg_name args)] (List.map gen_type (List.map (fun (_,opt,t) -> if opt then follow_param t else t) args @ [r]))
|
|
|
+ | TFun (args,r) ->
|
|
|
+ let s_const ct = match ct with
|
|
|
+ | TString s -> Printf.sprintf "'%s'" (Ast.s_escape s)
|
|
|
+ | _ -> s_const ct
|
|
|
+ in
|
|
|
+ let names = String.concat ":" (List.map gen_arg_name args) in
|
|
|
+ let values = match tfunc with
|
|
|
+ | None ->
|
|
|
+ []
|
|
|
+ | Some tfunc ->
|
|
|
+ let has_value = ref false in
|
|
|
+ let values = List.map (fun (_,cto) -> match cto with
|
|
|
+ | None ->
|
|
|
+ ""
|
|
|
+ | Some ct ->
|
|
|
+ has_value := true;
|
|
|
+ s_const ct
|
|
|
+ ) tfunc.tf_args in
|
|
|
+ if !has_value then
|
|
|
+ ["v",String.concat ":" values]
|
|
|
+ else
|
|
|
+ []
|
|
|
+ in
|
|
|
+ node "f" (("a",names) :: values) (List.map gen_type (List.map (fun (_,opt,t) -> if opt then follow_param t else t) args @ [r]))
|
|
|
| TAnon a -> node "a" [] (pmap (fun f -> gen_field [] { f with cf_public = false }) a.a_fields)
|
|
|
| TDynamic t2 -> node "d" [] (if t == t2 then [] else [gen_type t2])
|
|
|
| TLazy f -> gen_type (!f())
|
|
@@ -129,7 +152,11 @@ and gen_field att f =
|
|
|
| [] -> []
|
|
|
| nl -> [node "overloads" [] nl]
|
|
|
in
|
|
|
- node f.cf_name (if f.cf_public then ("public","1") :: att else att) (gen_type f.cf_type :: gen_meta f.cf_meta @ gen_doc_opt f.cf_doc @ overloads)
|
|
|
+ let tfunc = match f.cf_expr with
|
|
|
+ | Some ({eexpr = TFunction tf}) -> Some tf
|
|
|
+ | _ -> None
|
|
|
+ in
|
|
|
+ node f.cf_name (if f.cf_public then ("public","1") :: att else att) (gen_type ~tfunc:tfunc f.cf_type :: gen_meta f.cf_meta @ gen_doc_opt f.cf_doc @ overloads)
|
|
|
|
|
|
let gen_constr e =
|
|
|
let doc = gen_doc_opt e.ef_doc in
|