|
@@ -44,11 +44,6 @@ type class_init_ctx = {
|
|
|
mutable uninitialized_final : tclass_field list;
|
|
|
}
|
|
|
|
|
|
-type field_kind =
|
|
|
- | FKNormal
|
|
|
- | FKConstructor
|
|
|
- | FKInit
|
|
|
-
|
|
|
type field_init_ctx = {
|
|
|
is_inline : bool;
|
|
|
is_final : bool;
|
|
@@ -63,7 +58,7 @@ type field_init_ctx = {
|
|
|
is_display_field : bool;
|
|
|
is_field_debug : bool;
|
|
|
is_generic : bool;
|
|
|
- field_kind : field_kind;
|
|
|
+ field_kind : class_field_ref_kind;
|
|
|
display_modifier : placed_access option;
|
|
|
mutable do_bind : bool;
|
|
|
(* If true, cf_expr = None makes a difference in the logic. We insert a dummy expression in
|
|
@@ -117,11 +112,6 @@ let dump_class_context cctx =
|
|
|
"force_constructor",string_of_bool cctx.force_constructor;
|
|
|
]
|
|
|
|
|
|
-let s_field_kind = function
|
|
|
- | FKNormal -> "FKNormal"
|
|
|
- | FKConstructor -> "FKConstructor"
|
|
|
- | FKInit -> "FKInit"
|
|
|
-
|
|
|
let dump_field_context fctx =
|
|
|
Printer.s_record_fields "" [
|
|
|
"is_inline",string_of_bool fctx.is_inline;
|
|
@@ -131,7 +121,7 @@ let dump_field_context fctx =
|
|
|
"is_abstract_member",string_of_bool fctx.is_abstract_member;
|
|
|
"is_display_field",string_of_bool fctx.is_display_field;
|
|
|
"is_field_debug",string_of_bool fctx.is_field_debug;
|
|
|
- "field_kind",s_field_kind fctx.field_kind;
|
|
|
+ "field_kind",s_class_field_ref_kind fctx.field_kind;
|
|
|
"do_bind",string_of_bool fctx.do_bind;
|
|
|
"expr_presence_matters",string_of_bool fctx.expr_presence_matters;
|
|
|
]
|
|
@@ -602,9 +592,9 @@ let create_field_context ctx cctx cff is_display_file display_modifier =
|
|
|
let overload = try Some (List.assoc AOverload cff.cff_access) with Not_found -> None in
|
|
|
let is_macro = List.mem_assoc AMacro cff.cff_access in
|
|
|
let field_kind = match fst cff.cff_name with
|
|
|
- | "new" -> FKConstructor
|
|
|
- | "__init__" when is_static -> FKInit
|
|
|
- | _ -> FKNormal
|
|
|
+ | "new" -> CfrConstructor
|
|
|
+ | "__init__" when is_static -> CfrInit
|
|
|
+ | _ -> if is_static then CfrStatic else CfrMember
|
|
|
in
|
|
|
let default = try
|
|
|
let (_,_,p) = Meta.get Meta.JavaDefault cff.cff_meta in
|
|
@@ -629,7 +619,7 @@ let create_field_context ctx cctx cff is_display_file display_modifier =
|
|
|
is_abstract_member = is_abstract_member;
|
|
|
is_generic = Meta.has Meta.Generic cff.cff_meta;
|
|
|
field_kind = field_kind;
|
|
|
- do_bind = (((not ((has_class_flag c CExtern) || !is_extern) || is_inline) && not is_abstract && not (has_class_flag c CInterface)) || field_kind = FKInit);
|
|
|
+ do_bind = (((not ((has_class_flag c CExtern) || !is_extern) || is_inline) && not is_abstract && not (has_class_flag c CInterface)) || field_kind = CfrInit);
|
|
|
expr_presence_matters = false;
|
|
|
had_error = false;
|
|
|
} in
|
|
@@ -746,7 +736,7 @@ let check_field_display ctx fctx c cf =
|
|
|
| _ ->
|
|
|
(if fctx.is_static then
|
|
|
CFSStatic
|
|
|
- else if fctx.field_kind = FKConstructor then
|
|
|
+ else if fctx.field_kind = CfrConstructor then
|
|
|
CFSConstructor
|
|
|
else
|
|
|
CFSMember), cf;
|
|
@@ -940,7 +930,7 @@ module TypeBinding = struct
|
|
|
| Some _ ->
|
|
|
if fctx.is_abstract_member then FunMemberAbstract else FunStatic
|
|
|
| None ->
|
|
|
- if fctx.field_kind = FKConstructor then FunConstructor else if fctx.is_static then FunStatic else FunMember
|
|
|
+ if fctx.field_kind = CfrConstructor then FunConstructor else if fctx.is_static then FunStatic else FunMember
|
|
|
) in
|
|
|
begin match ctx.com.platform with
|
|
|
| Java when is_java_native_function ctx cf.cf_meta cf.cf_pos ->
|
|
@@ -951,7 +941,7 @@ module TypeBinding = struct
|
|
|
| _ ->
|
|
|
if Meta.has Meta.DisplayOverride cf.cf_meta then DisplayEmitter.check_field_modifiers ctx c cf fctx.override fctx.display_modifier;
|
|
|
let f_check = match fctx.field_kind with
|
|
|
- | FKNormal when not fctx.is_static ->
|
|
|
+ | CfrMember ->
|
|
|
begin match TypeloadCheck.check_overriding ctx c cf with
|
|
|
| NothingToDo ->
|
|
|
(fun () -> ())
|
|
@@ -976,10 +966,10 @@ module TypeBinding = struct
|
|
|
tf_type = ret;
|
|
|
tf_expr = e;
|
|
|
} in
|
|
|
- if fctx.field_kind = FKInit then
|
|
|
+ if fctx.field_kind = CfrInit then
|
|
|
(match e.eexpr with
|
|
|
| TBlock [] | TBlock [{ eexpr = TConst _ }] | TConst _ | TObjectDecl [] -> ()
|
|
|
- | _ -> c.cl_init <- Some e);
|
|
|
+ | _ -> TClass.set_cl_init c e);
|
|
|
cf.cf_expr <- Some (mk (TFunction tf) t p);
|
|
|
cf.cf_type <- t;
|
|
|
check_field_display ctx fctx c cf;
|
|
@@ -1268,7 +1258,7 @@ let setup_args_ret ctx cctx fctx name fd p =
|
|
|
else
|
|
|
def()
|
|
|
in
|
|
|
- let ret = if fctx.field_kind = FKConstructor then
|
|
|
+ let ret = if fctx.field_kind = CfrConstructor then
|
|
|
ctx.t.tvoid
|
|
|
else begin
|
|
|
let def () =
|
|
@@ -1339,12 +1329,12 @@ let create_method (ctx,cctx,fctx) c f fd p =
|
|
|
}
|
|
|
end in
|
|
|
begin match (has_class_flag c CInterface),fctx.field_kind with
|
|
|
- | true,FKConstructor ->
|
|
|
+ | true,CfrConstructor ->
|
|
|
raise_typing_error "An interface cannot have a constructor" p;
|
|
|
| true,_ ->
|
|
|
if not fctx.is_static && fd.f_expr <> None then unexpected_expression ctx.com fctx ("An interface method cannot have a body") p;
|
|
|
if fctx.is_inline && (has_class_flag c CInterface) then invalid_modifier ctx.com fctx "inline" "method of interface" p;
|
|
|
- | false,FKConstructor ->
|
|
|
+ | false,CfrConstructor ->
|
|
|
if fctx.is_static then invalid_modifier ctx.com fctx "static" "constructor" p;
|
|
|
begin match fd.f_type with
|
|
|
| None -> ()
|
|
@@ -1379,7 +1369,7 @@ let create_method (ctx,cctx,fctx) c f fd p =
|
|
|
if fctx.is_final then add_class_field_flag cf CfFinal;
|
|
|
if fctx.is_extern then add_class_field_flag cf CfExtern;
|
|
|
if fctx.is_abstract then begin
|
|
|
- if fctx.field_kind = FKConstructor then begin
|
|
|
+ if fctx.field_kind = CfrConstructor then begin
|
|
|
let p =
|
|
|
try List.assoc AAbstract f.cff_access
|
|
|
with Not_found -> p
|
|
@@ -1406,7 +1396,7 @@ let create_method (ctx,cctx,fctx) c f fd p =
|
|
|
| Some p ->
|
|
|
if ctx.com.config.pf_overload then
|
|
|
add_class_field_flag cf CfOverload
|
|
|
- else if fctx.field_kind = FKConstructor then
|
|
|
+ else if fctx.field_kind = CfrConstructor then
|
|
|
invalid_modifier ctx.com fctx "overload" "constructor" p
|
|
|
else begin
|
|
|
add_class_field_flag cf CfOverload;
|
|
@@ -1791,22 +1781,22 @@ let init_class ctx c p herits fields =
|
|
|
let ctx = create_typer_context_for_field ctx cctx fctx f in
|
|
|
if fctx.is_field_debug then print_endline ("Created field context: " ^ dump_field_context fctx);
|
|
|
let cf = init_field (ctx,cctx,fctx) f in
|
|
|
- if fctx.field_kind = FKInit then begin
|
|
|
+ if fctx.field_kind = CfrInit then begin
|
|
|
if !has_init then
|
|
|
display_error ctx.com ("Duplicate class field declaration : " ^ (s_type_path c.cl_path) ^ "." ^ cf.cf_name) cf.cf_name_pos
|
|
|
else
|
|
|
has_init := true
|
|
|
end;
|
|
|
if fctx.is_field_debug then print_endline ("Created field: " ^ Printer.s_tclass_field "" cf);
|
|
|
- if fctx.is_static && (has_class_flag c CInterface) && fctx.field_kind <> FKInit && not cctx.is_lib && not ((has_class_flag c CExtern)) then
|
|
|
+ if fctx.is_static && (has_class_flag c CInterface) && fctx.field_kind <> CfrInit && not cctx.is_lib && not ((has_class_flag c CExtern)) then
|
|
|
raise_typing_error "You can only declare static fields in extern interfaces" p;
|
|
|
let req = check_require f.cff_meta in
|
|
|
- let req = (match req with None -> if fctx.is_static || fctx.field_kind = FKConstructor then cl_req else None | _ -> req) in
|
|
|
+ let req = (match req with None -> if fctx.is_static || fctx.field_kind = CfrConstructor then cl_req else None | _ -> req) in
|
|
|
(match req with
|
|
|
| None -> ()
|
|
|
| Some r -> cf.cf_kind <- Var { v_read = AccRequire (fst r, snd r); v_write = AccRequire (fst r, snd r) });
|
|
|
begin match fctx.field_kind with
|
|
|
- | FKConstructor ->
|
|
|
+ | CfrConstructor ->
|
|
|
begin match c.cl_super with
|
|
|
| Some ({ cl_constructor = Some ctor_sup } as c, _) when not (has_class_flag c CExtern) && has_class_field_flag ctor_sup CfFinal ->
|
|
|
ctx.com.error "Cannot override final constructor" cf.cf_pos
|
|
@@ -1823,9 +1813,9 @@ let init_class ctx c p herits fields =
|
|
|
| Some ctor ->
|
|
|
display_error ctx.com "Duplicate constructor" p
|
|
|
end
|
|
|
- | FKInit ->
|
|
|
+ | CfrInit ->
|
|
|
()
|
|
|
- | FKNormal ->
|
|
|
+ | CfrStatic | CfrMember ->
|
|
|
let dup = if fctx.is_static then PMap.exists cf.cf_name c.cl_fields || has_field cf.cf_name c.cl_super else PMap.exists cf.cf_name c.cl_statics in
|
|
|
if not cctx.is_native && not (has_class_flag c CExtern) && dup then raise_typing_error ("Same field name can't be used for both static and instance : " ^ cf.cf_name) p;
|
|
|
if fctx.override <> None then
|