Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIdent #6424

Merged
merged 8 commits into from
Jun 30, 2017
Merged

TIdent #6424

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/context/meta.ml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ type strict_meta =
| TemplatedCall
| ValueUsed
| Volatile
| Unbound
| UnifyMinDynamic
| Unreflective
| Unsafe
Expand Down Expand Up @@ -360,7 +359,6 @@ let get_info = function
| Transient -> ":transient",("Adds the 'transient' flag to the class field",[Platform Java; UsedOn TClassField])
| ValueUsed -> ":valueUsed",("Internally used by DCE to mark an abstract value as used",[UsedInternally])
| Volatile -> ":volatile",("",[Platforms [Java;Cs]])
| Unbound -> ":unbound", ("Compiler internal to denote unbounded global variable",[UsedInternally])
| UnifyMinDynamic -> ":unifyMinDynamic",("Allows a collection of types to unify to Dynamic",[UsedOn TClassField])
| Unreflective -> ":unreflective",("",[Platform Cpp])
| Unsafe -> ":unsafe",("Declares a class, or a method with the C#'s 'unsafe' flag",[Platform Cs; UsedOnEither [TClass;TClassField]])
Expand Down
4 changes: 2 additions & 2 deletions src/display/display.ml
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,9 @@ module Diagnostics = struct
had_effect := true;
| TLocal v when not (Meta.has Meta.UserVariable v.v_meta) ->
()
| TConst _ | TLocal _ | TTypeExpr _ | TFunction _ when not in_value ->
| TConst _ | TLocal _ | TTypeExpr _ | TFunction _ | TIdent _ when not in_value ->
no_effect e.epos;
| TConst _ | TLocal _ | TTypeExpr _ | TEnumParameter _ | TEnumIndex _ | TVar _ ->
| TConst _ | TLocal _ | TTypeExpr _ | TEnumParameter _ | TEnumIndex _ | TVar _ | TIdent _ ->
()
| TFunction tf ->
loop false tf.tf_expr
Expand Down
6 changes: 3 additions & 3 deletions src/filters/tryCatchWrapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,19 @@ let configure_cs com =
| TInst (cl,_) -> is_parent base_exception cl
| _ -> false
in
let v_rethrow = alloc_unbound_var "__rethrow__" t_dynamic null_pos in
let e_rethrow = mk (TIdent "__rethrow__") t_dynamic null_pos in
let should_wrap t = not (is_exception t) in
let wrap_throw expr =
match expr.eexpr with
| TLocal { v_name = "__rethrow__" } ->
| TIdent "__rethrow__" ->
make_throw expr expr.epos
| _ ->
let e_hxexception = make_static_this hx_exception expr.epos in
let e_wrap = fcall e_hxexception "wrap" [expr] base_exception_t expr.epos in
make_throw e_wrap expr.epos
in
let unwrap_expr local_to_unwrap = Codegen.field (mk_cast local_to_unwrap hx_exception_t local_to_unwrap.epos) "obj" t_dynamic local_to_unwrap.epos in
let rethrow_expr rethrow = make_throw (make_local v_rethrow rethrow.epos) rethrow.epos in
let rethrow_expr rethrow = make_throw e_rethrow rethrow.epos in
let catch_map v e =
let e_exc = make_static_this exc_cl e.epos in
let e_field = Codegen.field e_exc "exception" base_exception_t e.epos in
Expand Down
2 changes: 1 addition & 1 deletion src/generators/codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ let rec constructor_side_effects e =
| TBinop _ | TTry _ | TIf _ | TBlock _ | TVar _
| TFunction _ | TArrayDecl _ | TObjectDecl _
| TParenthesis _ | TTypeExpr _ | TLocal _ | TMeta _
| TConst _ | TContinue | TBreak | TCast _ ->
| TConst _ | TContinue | TBreak | TCast _ | TIdent _ ->
try
Type.iter (fun e -> if constructor_side_effects e then raise Exit) e;
false;
Expand Down
35 changes: 19 additions & 16 deletions src/generators/genas3.ml
Original file line number Diff line number Diff line change
Expand Up @@ -430,71 +430,71 @@ let rec gen_call ctx e el r =
spr ctx "(";
concat ctx "," (gen_value ctx) el;
spr ctx ")";
| TLocal { v_name = "__is__" } , [e1;e2] ->
| TIdent "__is__" , [e1;e2] ->
gen_value ctx e1;
spr ctx " is ";
gen_value ctx e2;
| TLocal { v_name = "__in__" } , [e1;e2] ->
| TIdent "__in__" , [e1;e2] ->
spr ctx "(";
gen_value ctx e1;
spr ctx " in ";
gen_value ctx e2;
spr ctx ")"
| TLocal { v_name = "__as__" }, [e1;e2] ->
| TIdent "__as__", [e1;e2] ->
gen_value ctx e1;
spr ctx " as ";
gen_value ctx e2;
| TLocal { v_name = "__int__" }, [e] ->
| TIdent "__int__", [e] ->
spr ctx "int(";
gen_value ctx e;
spr ctx ")";
| TLocal { v_name = "__float__" }, [e] ->
| TIdent "__float__", [e] ->
spr ctx "Number(";
gen_value ctx e;
spr ctx ")";
| TLocal { v_name = "__typeof__" }, [e] ->
| TIdent "__typeof__", [e] ->
spr ctx "typeof ";
gen_value ctx e;
| TLocal { v_name = "__keys__" }, [e] ->
| TIdent "__keys__", [e] ->
let ret = (match ctx.in_value with None -> assert false | Some r -> r) in
print ctx "%s = new Array()" ret.v_name;
newline ctx;
let tmp = gen_local ctx "$k" in
print ctx "for(var %s : String in " tmp;
gen_value ctx e;
print ctx ") %s.push(%s)" ret.v_name tmp;
| TLocal { v_name = "__hkeys__" }, [e] ->
| TIdent "__hkeys__", [e] ->
let ret = (match ctx.in_value with None -> assert false | Some r -> r) in
print ctx "%s = new Array()" ret.v_name;
newline ctx;
let tmp = gen_local ctx "$k" in
print ctx "for(var %s : String in " tmp;
gen_value ctx e;
print ctx ") %s.push(%s.substr(1))" ret.v_name tmp;
| TLocal { v_name = "__foreach__" }, [e] ->
| TIdent "__foreach__", [e] ->
let ret = (match ctx.in_value with None -> assert false | Some r -> r) in
print ctx "%s = new Array()" ret.v_name;
newline ctx;
let tmp = gen_local ctx "$k" in
print ctx "for each(var %s : * in " tmp;
gen_value ctx e;
print ctx ") %s.push(%s)" ret.v_name tmp;
| TLocal { v_name = "__new__" }, e :: args ->
| TIdent "__new__", e :: args ->
spr ctx "new ";
gen_value ctx e;
spr ctx "(";
concat ctx "," (gen_value ctx) args;
spr ctx ")";
| TLocal { v_name = "__delete__" }, [e;f] ->
| TIdent "__delete__", [e;f] ->
spr ctx "delete(";
gen_value ctx e;
spr ctx "[";
gen_value ctx f;
spr ctx "]";
spr ctx ")";
| TLocal { v_name = "__unprotect__" }, [e] ->
| TIdent "__unprotect__", [e] ->
gen_value ctx e
| TLocal { v_name = "__vector__" }, [e] ->
| TIdent "__vector__", [e] ->
spr ctx (type_str ctx r e.epos);
spr ctx "(";
gen_value ctx e;
Expand Down Expand Up @@ -592,7 +592,7 @@ and gen_expr ctx e =
gen_constant ctx e.epos c
| TLocal v ->
spr ctx (s_ident v.v_name)
| TArray ({ eexpr = TLocal { v_name = "__global__" } },{ eexpr = TConst (TString s) }) ->
| TArray ({ eexpr = TIdent "__global__" },{ eexpr = TConst (TString s) }) ->
let path = Ast.parse_path s in
spr ctx (s_path ctx false path e.epos)
| TArray (e1,e2) ->
Expand Down Expand Up @@ -811,6 +811,8 @@ and gen_expr ctx e =
end
| TCast (e1,Some t) ->
gen_expr ctx (Codegen.default_cast ctx.inf.com e1 t e.etype e.epos)
| TIdent s ->
spr ctx s

and gen_block_element ctx e = match e.eexpr with
| TObjectDecl fl ->
Expand Down Expand Up @@ -872,7 +874,7 @@ and gen_value ctx e =
)
in
match e.eexpr with
| TCall ({ eexpr = TLocal { v_name = "__keys__" } },_) | TCall ({ eexpr = TLocal { v_name = "__hkeys__" } },_) ->
| TCall ({ eexpr = TIdent "__keys__" },_) | TCall ({ eexpr = TIdent "__hkeys__" },_) ->
let v = value true in
gen_expr ctx e;
v()
Expand All @@ -890,7 +892,8 @@ and gen_value ctx e =
| TCall _
| TNew _
| TUnop _
| TFunction _ ->
| TFunction _
| TIdent _ ->
gen_expr ctx e
| TMeta (_,e1) ->
gen_value ctx e1
Expand Down
6 changes: 2 additions & 4 deletions src/generators/gencommon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ let mk_local = ExprBuilder.make_local

(* the undefined is a special var that works like null, but can have special meaning *)
let undefined =
let v_undefined = alloc_var "__undefined__" t_dynamic in
(fun pos -> ExprBuilder.make_local v_undefined pos)
(fun pos -> mk (TIdent "__undefined__") t_dynamic pos)

let path_of_md_def md_def =
match md_def.m_types with
Expand Down Expand Up @@ -986,9 +985,8 @@ let get_real_fun gen t =
| TFun(args,t) -> TFun(List.map (fun (n,o,t) -> n,o,gen.greal_type t) args, gen.greal_type t)
| _ -> t

let v_nativearray = alloc_var "__array__" t_dynamic
let mk_nativearray_decl gen t el pos =
mk (TCall (mk_local v_nativearray pos, el)) (gen.gclasses.nativearray t) pos
mk (TCall (mk (TIdent "__array__") t_dynamic pos, el)) (gen.gclasses.nativearray t) pos

let ensure_local com block name e =
match e.eexpr with
Expand Down
8 changes: 4 additions & 4 deletions src/generators/gencommon/castDetect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ let handle_type_parameter gen e e1 ef ~clean_ef ~overloads_cast_to_base f elist
let pos = (!ef).epos in
ef := {
eexpr = TCall(
{ eexpr = TLocal(alloc_var "__as__" t_dynamic); etype = t_dynamic; epos = pos },
{ eexpr = TIdent "__as__"; etype = t_dynamic; epos = pos },
[!ef]);
etype = TInst(declared_cl,List.map (apply_params cl.cl_params params) tl);
epos = pos
Expand Down Expand Up @@ -1029,7 +1029,7 @@ let configure gen ?(overloads_cast_to_base = false) maybe_empty_t calls_paramete
handle e t real_t
| TCast( { eexpr = TConst TNull }, _ ) ->
{ e with eexpr = TConst TNull }
| TCast( { eexpr = TCall( { eexpr = TLocal { v_name = "__delegate__" } } as local, [del] ) } as e2, _) ->
| TCast( { eexpr = TCall( { eexpr = TIdent "__delegate__" } as local, [del] ) } as e2, _) ->
{ e with eexpr = TCast({ e2 with eexpr = TCall(local, [Type.map_expr run del]) }, None) }

| TBinop ( (Ast.OpAssign | Ast.OpAssignOp _ as op), e1, e2 ) ->
Expand Down Expand Up @@ -1060,15 +1060,15 @@ let configure gen ?(overloads_cast_to_base = false) maybe_empty_t calls_paramete
in
let base_type = List.hd base_type in
{ e with eexpr = TArrayDecl( List.map (fun e -> handle (run e) base_type e.etype) el ); etype = et }
| TCall ({ eexpr = TLocal { v_name = "__array__" } } as arr_local, el) ->
| TCall ({ eexpr = TIdent "__array__" } as arr_local, el) ->
let et = e.etype in
let base_type = match follow et with
| TInst(cl, bt) -> gen.greal_type_param (TClassDecl cl) bt
| _ -> assert false
in
let base_type = List.hd base_type in
{ e with eexpr = TCall(arr_local, List.map (fun e -> handle (run e) base_type e.etype) el ); etype = et }
| TCall( ({ eexpr = TLocal v } as local), params ) when String.get v.v_name 0 = '_' && String.get v.v_name 1 = '_' && Hashtbl.mem gen.gspecial_vars v.v_name ->
| TCall( ({ eexpr = TIdent s } as local), params ) when String.get s 0 = '_' && String.get s 1 = '_' && Hashtbl.mem gen.gspecial_vars s ->
{ e with eexpr = TCall(local, List.map (fun e -> (match e.eexpr with TBlock _ -> in_value := false | _ -> ()); run e) params) }
| TCall( ({ eexpr = TField(ef, f) }) as e1, elist ) ->
handle_type_parameter gen (Some e) (e1) (run ef) ~clean_ef:ef ~overloads_cast_to_base:overloads_cast_to_base f (List.map run elist) calls_parameters_explicitly
Expand Down
5 changes: 2 additions & 3 deletions src/generators/gencommon/classInstance.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ open Gencommon
var x = typeof(MyClass);
*)
let add_typeof =
let v_typeof = alloc_var "__typeof__" t_dynamic in
let rec run e =
match e.eexpr with
| TCall (({ eexpr = TLocal { v_name = ("__is__" | "__as__" | "__typeof__") } } as elocal), args) ->
| TCall (({ eexpr = TIdent ("__is__" | "__as__" | "__typeof__") } as elocal), args) ->
let args = List.map (fun e -> match e.eexpr with TTypeExpr _ -> e | _ -> run e) args in
{ e with eexpr = TCall (elocal, args) }
| TField ({ eexpr = TTypeExpr _ }, _) ->
Expand All @@ -45,7 +44,7 @@ let add_typeof =
| None -> Type.map_expr run e
| Some t -> { e with eexpr = TField ({ ef with eexpr = TTypeExpr t }, f)})
| TTypeExpr _ ->
{ e with eexpr = TCall (mk_local v_typeof e.epos, [e]) }
{ e with eexpr = TCall (mk (TIdent "__typeof__") t_dynamic e.epos, [e]) }
| _ ->
Type.map_expr run e
in
Expand Down
8 changes: 4 additions & 4 deletions src/generators/gencommon/closuresToClass.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ let traverse gen ?tparam_anon_decl ?tparam_anon_acc (handle_anon_func:texpr->tfu
let info = ref null_map_info in
let rec run e =
match e.eexpr with
| TCast({ eexpr = TCall({ eexpr = TLocal{ v_name = "__delegate__" } } as local, [del] ) } as e2, _) ->
| TCast({ eexpr = TCall({ eexpr = TIdent "__delegate__" } as local, [del] ) } as e2, _) ->
let e2 = { e2 with etype = e.etype } in
let replace_delegate ex =
{ e with eexpr = TCast({ e2 with eexpr = TCall(local, [ex]) }, None) }
Expand Down Expand Up @@ -174,7 +174,7 @@ let traverse gen ?tparam_anon_decl ?tparam_anon_acc (handle_anon_func:texpr->tfu
gen.gcon.error "This delegate construct is unsupported" e.epos;
replace_delegate (run clean))

| TCall(({ eexpr = TLocal{ v_name = "__unsafe__" } } as local), [arg]) ->
| TCall(({ eexpr = TIdent "__unsafe__" } as local), [arg]) ->
let old = !info in
info := { !info with in_unsafe = true };
let arg2 = run arg in
Expand All @@ -186,7 +186,7 @@ let traverse gen ?tparam_anon_decl ?tparam_anon_acc (handle_anon_func:texpr->tfu
| Some tparam_anon_decl ->
(match (vv, ve) with
| ({ v_extra = Some( _ :: _, _) } as v), Some ({ eexpr = TFunction tf } as f)
| ({ v_extra = Some( _ :: _, _) } as v), Some { eexpr = TArrayDecl([{ eexpr = TFunction tf } as f]) | TCall({ eexpr = TLocal { v_name = "__array__" } }, [{ eexpr = TFunction tf } as f]) } -> (* captured transformation *)
| ({ v_extra = Some( _ :: _, _) } as v), Some { eexpr = TArrayDecl([{ eexpr = TFunction tf } as f]) | TCall({ eexpr = TIdent "__array__" }, [{ eexpr = TFunction tf } as f]) } -> (* captured transformation *)
ignore(tparam_anon_decl v f { tf with tf_expr = run tf.tf_expr });
{ e with eexpr = TBlock([]) }
| _ ->
Expand Down Expand Up @@ -234,7 +234,7 @@ let traverse gen ?tparam_anon_decl ?tparam_anon_acc (handle_anon_func:texpr->tfu
handle_anon_func e { tf with tf_expr = run tf.tf_expr } !info None
| TCall({ eexpr = TConst(TSuper) }, _) ->
Type.map_expr run e
| TCall({ eexpr = TLocal(v) }, args) when String.get v.v_name 0 = '_' && Hashtbl.mem gen.gspecial_vars v.v_name ->
| TCall({ eexpr = TIdent s }, args) when String.get s 0 = '_' && Hashtbl.mem gen.gspecial_vars s ->
Type.map_expr run e
| TCall(tc,params) ->
let i = ref 0 in
Expand Down
5 changes: 2 additions & 3 deletions src/generators/gencommon/enumToClass2.ml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ module EnumToClass2Modf = struct
begin
let other_v = alloc_var "other" t_dynamic in
let eother_local = mk_local other_v pos in
let eas = mk_local (alloc_var "__as__" t_dynamic) pos in
let eas = mk (TIdent "__as__") t_dynamic pos in
let ecast = mk (TCall(eas,[eother_local])) cl_ctor_t pos in

let equals_exprs = ref (List.rev [
Expand Down Expand Up @@ -338,7 +338,6 @@ end;;

module EnumToClass2Exprf = struct
let init com ec_tbl mk_enum_index_call =
let v_as = alloc_var "__as__" t_dynamic in
let rec run e =
let get_converted_enum_classes et =
let en = match follow et with
Expand Down Expand Up @@ -374,7 +373,7 @@ module EnumToClass2Exprf = struct
let f = { f with etype = TInst(cl_enum, []) } in

let cl_ctor = PMap.find ef.ef_name classes.ctors in
let ecast = mk (TCall (mk_local v_as f.epos, [f])) (TInst (cl_ctor, [])) f.epos in
let ecast = mk (TCall (mk (TIdent "__as__") t_dynamic f.epos, [f])) (TInst (cl_ctor, [])) f.epos in

(match ef.ef_type with
| TFun (params, _) ->
Expand Down
6 changes: 4 additions & 2 deletions src/generators/gencommon/expressionUnwrap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ let rec shallow_expr_type expr : shallow_expr_type =
| _ -> Both expr)
| TConst _
| TLocal _
| TIdent _
| TArray _
| TBinop _
| TField _
Expand Down Expand Up @@ -257,7 +258,8 @@ and expr_kind expr =
| TConst _
| TLocal _
| TFunction _
| TTypeExpr _ ->
| TTypeExpr _
| TIdent _ ->
KNoSideEffects
| TCall (ecall, params) ->
aggregate false (ecall :: params)
Expand Down Expand Up @@ -575,7 +577,7 @@ let configure gen =
let rec process_statement e =
let e = no_paren e in
match e.eexpr, shallow_expr_type e with
| TCall( { eexpr = TLocal v } as elocal, elist ), _ when String.get v.v_name 0 = '_' && Hashtbl.mem gen.gspecial_vars v.v_name ->
| TCall( { eexpr = TIdent s } as elocal, elist ), _ when String.get s 0 = '_' && Hashtbl.mem gen.gspecial_vars s ->
new_block := { e with eexpr = TCall( elocal, List.map (fun e ->
match e.eexpr with
| TBlock _ -> traverse e
Expand Down
2 changes: 1 addition & 1 deletion src/generators/gencommon/filterClosures.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let configure gen (should_change:texpr->string->bool) (filter:texpr->texpr->stri
(match clos with
| Some (clos, e1, s) -> { e with eexpr = TCall({ clos with eexpr = TClosure(run e1, s) }, List.map run args ) }
| None -> Type.map_expr run e)*)
| TCall({ eexpr = TLocal{ v_name = "__delegate__" } } as local, [del]) ->
| TCall({ eexpr = TIdent "__delegate__" } as local, [del]) ->
{ e with eexpr = TCall(local, [Type.map_expr run del]) }
| TCall(({ eexpr = TField(_, _) } as ef), params) ->
{ e with eexpr = TCall(Type.map_expr run ef, List.map run params) }
Expand Down
2 changes: 1 addition & 1 deletion src/generators/gencommon/initFunction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let ensure_simple_expr com e =
match e.eexpr with
| TConst _ | TLocal _ | TArray _ | TBinop _
| TField _ | TTypeExpr _ | TParenthesis _ | TCast _ | TMeta _
| TCall _ | TNew _ | TUnop _ ->
| TCall _ | TNew _ | TUnop _ | TIdent _ ->
Type.iter iter e
| _ ->
print_endline (debug_expr e);
Expand Down
3 changes: 1 addition & 2 deletions src/generators/gencommon/realTypeParams.ml
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,7 @@ struct
in

let mk_typehandle =
let thandle = alloc_var "__typeof__" t_dynamic in
(fun cl -> mk (TCall (mk_local thandle pos, [ExprBuilder.make_static_this cl pos])) t_dynamic pos)
(fun cl -> mk (TCall (mk (TIdent "__typeof__") t_dynamic pos, [ExprBuilder.make_static_this cl pos])) t_dynamic pos)
in
let mk_eq cl1 cl2 =
binop OpEq (mk_typehandle cl1) (mk_typehandle cl2) basic.tbool pos
Expand Down
4 changes: 2 additions & 2 deletions src/generators/gencommon/reflectionCFs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ let implement_dynamic_object_ctor ctx cl =
tf_args = [];
tf_expr = {
eexpr = TBlock(List.map (fun (f,t) ->
{ eexpr = TBinop(Ast.OpAssign, mk_this f t,{ eexpr = TCall(mk_local v_nativearray pos, []); etype = t; epos = pos; }); etype = t; epos = pos }
{ eexpr = TBinop(Ast.OpAssign, mk_this f t,{ eexpr = TCall(mk (TIdent "__array__") t_dynamic pos, []); etype = t; epos = pos; }); etype = t; epos = pos }
) fields);
etype = basic.tvoid;
epos = pos;
Expand Down Expand Up @@ -766,7 +766,7 @@ let implement_dynamics ctx cl =
] in

(if cl.cl_path <> (["haxe"; "lang"], "DynamicObject") then
List.iter (fun cf -> cf.cf_expr <- Some { eexpr = TCall(mk_local v_nativearray pos, []); etype = cf.cf_type; epos = cf.cf_pos }) new_fields
List.iter (fun cf -> cf.cf_expr <- Some { eexpr = TCall(mk (TIdent "__array__") t_dynamic pos, []); etype = cf.cf_type; epos = cf.cf_pos }) new_fields
);

let new_fields =
Expand Down
Loading