|
@@ -497,24 +497,46 @@ let reduce_expression ctx e =
|
|
|
if ctx.com.foptimize then reduce_loop ctx false e else e
|
|
|
|
|
|
(* ---------------------------------------------------------------------- *)
|
|
|
-(* ELIMINATE DEAD CLASSES *)
|
|
|
+(* ELIMINATE DEAD CODE *)
|
|
|
|
|
|
(*
|
|
|
- if dead code elimination is on, any class without fields is eliminated from the output.
|
|
|
+ if dead code elimination is on, any class without fields is eliminated from the output. Also inline members
|
|
|
+ are eliminated unless marked as @:keep
|
|
|
*)
|
|
|
|
|
|
-let filter_dead_classes com =
|
|
|
+let filter_dead_code com =
|
|
|
+ let s_class c = s_type_path c.cl_path in
|
|
|
+ let s_field c cf = (s_class c) ^ "." ^ cf.cf_name in
|
|
|
+ let remove_inlines c =
|
|
|
+ let remove_inline_fields lst =
|
|
|
+ List.filter(fun cf ->
|
|
|
+ match cf.cf_kind with
|
|
|
+ | Var k when ((k.v_read = AccInline) && (not (has_meta ":keep" cf.cf_meta))) ->
|
|
|
+ if com.verbose then print_endline ("Remove inline var " ^ s_field c cf);
|
|
|
+ false;
|
|
|
+ | Method k when ((k = MethInline) && (not (has_meta ":keep" cf.cf_meta))) ->
|
|
|
+ if com.verbose then print_endline ("Remove inline method " ^ s_field c cf);
|
|
|
+ false;
|
|
|
+ | _ ->
|
|
|
+ true;
|
|
|
+ ) lst
|
|
|
+ in
|
|
|
+ c.cl_ordered_statics <- remove_inline_fields c.cl_ordered_statics;
|
|
|
+ c.cl_ordered_fields <- remove_inline_fields c.cl_ordered_fields
|
|
|
+ in
|
|
|
com.types <- List.filter (fun t ->
|
|
|
match t with
|
|
|
| TClassDecl c ->
|
|
|
if (c.cl_extern or has_meta ":keep" c.cl_meta) then
|
|
|
true
|
|
|
- else (match (c.cl_ordered_statics, c.cl_ordered_fields, c.cl_constructor) with
|
|
|
- | ([], [], None) ->
|
|
|
- if com.verbose then print_endline ("Remove class " ^ s_type_path c.cl_path);
|
|
|
- false
|
|
|
- | _ ->
|
|
|
- true)
|
|
|
+ else (
|
|
|
+ remove_inlines c;
|
|
|
+ match (c.cl_ordered_statics, c.cl_ordered_fields, c.cl_constructor) with
|
|
|
+ | ([], [], None) ->
|
|
|
+ if com.verbose then print_endline ("Remove class " ^ s_class c);
|
|
|
+ false
|
|
|
+ | _ ->
|
|
|
+ true)
|
|
|
| _ ->
|
|
|
true
|
|
|
) com.types
|