Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* this function will receive the original function argument, the applied function argument and the original function parameters. *)
- (* from this info, it will infer the applied tparams for the function *)
- (* this function is used by CastDetection module *)
- let infer_params gen pos (original_args:((string * bool * t) list * t)) (applied_args:((string * bool * t) list * t)) (params:(string * t) list) : tparams =
- let args_list args = ( List.map (fun (_,_,t) -> t) (fst args) ) @ [snd args] in
- let params_tbl = Hashtbl.create (List.length params) in
- (*List.iter (fun (s,t) -> match t with | TInst(cl,[]) -> Hashtbl.add params_tbl cl.cl_path cl | _ -> assert false) params;*)
- let rec get_arg is_follow original applied =
- match (original, applied) with
- | TInst( ({ cl_kind = KTypeParameter } as cl ), []), _ ->
- Hashtbl.replace params_tbl cl.cl_path applied
- | TInst(cl, params), TInst(cl2, params2) ->
- iter2 (get_arg is_follow) params params2
- | TEnum(e, params), TEnum(e2, params2) ->
- iter2 (get_arg is_follow) params params2
- | TFun(params, ret), TFun(params2, ret2) ->
- iter2 (get_arg false) ( args_list (params, ret) ) ( args_list (params2, ret2) )
- | _ -> if not(is_follow) then get_arg true (follow original) (follow applied)
- in
- let original = args_list original_args in
- let applied = args_list applied_args in
- iter2 (fun original applied ->
- get_arg false original applied
- ) original applied;
- List.map (fun (_,t) ->
- match follow t with
- | TInst(cl,_) ->
- (try Hashtbl.find params_tbl cl.cl_path with | Not_found -> (gen.gcon.error ("Error: function argument " ^ (snd cl.cl_path) ^ " not applied.") pos); assert false)
- | _ ->
- assert false
- ) params
Advertisement
Add Comment
Please, Sign In to add comment