Skip to content

Commit

Permalink
Merge branch 'development' of github.com:HaxeFoundation/haxe into genpy
Browse files Browse the repository at this point in the history
  • Loading branch information
frabbit committed Apr 3, 2014
2 parents c094468 + ce688a7 commit 1636502
Show file tree
Hide file tree
Showing 23 changed files with 1,596 additions and 1,405 deletions.
81 changes: 81 additions & 0 deletions codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1621,3 +1621,84 @@ module UnificationCallback = struct
| _ ->
check (Type.map_expr (run f) e)
end;;

module DeprecationCheck = struct

let curclass = ref null_class

let warned_positions = Hashtbl.create 0

let print_deprecation_message com meta s p_usage =
let s = match meta with
| _,[EConst(String s),_],_ -> s
| _ -> Printf.sprintf "Usage of this %s is deprecated" s
in
if not (Hashtbl.mem warned_positions p_usage) then begin
Hashtbl.replace warned_positions p_usage true;
com.warning s p_usage;
end

let check_meta com meta s p_usage =
try
print_deprecation_message com (Meta.get Meta.Deprecated meta) s p_usage;
with Not_found ->
()

let check_cf com cf p = check_meta com cf.cf_meta "field" p

let check_class com c p = if c != !curclass then check_meta com c.cl_meta "class" p

let check_enum com en p = check_meta com en.e_meta "enum" p

let check_ef com ef p = check_meta com ef.ef_meta "enum field" p

let check_typedef com t p = check_meta com t.t_meta "typedef" p

let check_module_type com mt p = match mt with
| TClassDecl c -> check_class com c p
| TEnumDecl en -> check_enum com en p
| _ -> ()

let run com =
let rec expr e = match e.eexpr with
| TField(e1,fa) ->
expr e1;
begin match fa with
| FStatic(c,cf) | FInstance(c,cf) ->
check_class com c e.epos;
check_cf com cf e.epos
| FAnon cf ->
check_cf com cf e.epos
| FClosure(co,cf) ->
(match co with None -> () | Some c -> check_class com c e.epos);
check_cf com cf e.epos
| FEnum(en,ef) ->
check_enum com en e.epos;
check_ef com ef e.epos;
| _ ->
()
end
| TNew(c,_,el) ->
List.iter expr el;
check_class com c e.epos;
(match c.cl_constructor with None -> () | Some cf -> check_cf com cf e.epos)
| TTypeExpr(mt) | TCast(_,Some mt) ->
check_module_type com mt e.epos
| TMeta((Meta.Deprecated,_,_) as meta,e1) ->
print_deprecation_message com meta "field" e1.epos;
expr e1;
| _ ->
Type.iter expr e
in
List.iter (fun t -> match t with
| TClassDecl c ->
curclass := c;
let field cf = match cf.cf_expr with None -> () | Some e -> expr e in
(match c.cl_constructor with None -> () | Some cf -> field cf);
(match c.cl_init with None -> () | Some e -> expr e);
List.iter field c.cl_ordered_statics;
List.iter field c.cl_ordered_fields;
| _ ->
()
) com.types
end
6 changes: 4 additions & 2 deletions common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ module Define = struct
| Dce
| DceDebug
| Debug
| DeprecationWarnings
| Display
| DllExport
| DllImport
Expand Down Expand Up @@ -202,7 +201,9 @@ module Define = struct
| NetTarget
| NoCompilation
| NoCOpt
| NoDeprecationWarnings
| NoFlashOverride
| NoDebug
| NoInline
| NoOpt
| NoPatternMatching
Expand Down Expand Up @@ -244,7 +245,6 @@ module Define = struct
| Dce -> ("dce","The current DCE mode")
| DceDebug -> ("dce_debug","Show DCE log")
| Debug -> ("debug","Activated when compiling with -debug")
| DeprecationWarnings -> ("deprecation-warnings","Warn if fields annotated with @:deprecated are used")
| Display -> ("display","Activated during completion")
| DllExport -> ("dll_export", "GenCPP experimental linking")
| DllImport -> ("dll_import", "GenCPP experimental linking")
Expand Down Expand Up @@ -274,6 +274,8 @@ module Define = struct
| NetworkSandbox -> ("network-sandbox","Use local network sandbox instead of local file access one")
| NoCompilation -> ("no-compilation","Disable CPP final compilation")
| NoCOpt -> ("no_copt","Disable completion optimization (for debug purposes)")
| NoDebug -> ("no_debug","Remove all debug macros from cpp output")
| NoDeprecationWarnings -> ("no-deprecation-warnings","Do not warn if fields annotated with @:deprecated are used")
| NoFlashOverride -> ("no-flash-override", "Change overrides on some basic classes into HX suffixed methods, flash only")
| NoOpt -> ("no_opt","Disable optimizations")
| NoPatternMatching -> ("no_pattern_matching","Disable pattern matching")
Expand Down
16 changes: 16 additions & 0 deletions extra/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
2014-??-??: 3.1.3

Bugfixes:

flash : ensure correct endianess in haxe.io.BytesBuffer
macro : fixed haxe.macro.Compiler.keep

General improvements and optimizations:

all : give @:deprecated warnings by default, allow -D no-deprecation-warnings

Standard Library:

all : renamed Bytes.readDouble/Float to getDouble/Float to avoid inheritance issues
all : deprecated Bytes.readString in favor of getString

2014-03-29: 3.1.2

Bugfixes:
Expand Down
70 changes: 2 additions & 68 deletions filters.ml
Original file line number Diff line number Diff line change
Expand Up @@ -797,72 +797,6 @@ let rename_local_vars com e =
loop e;
e

let check_deprecation com =
let curclass = ref null_class in
let definition_positions = (Common.defined_value_safe com Define.DeprecationWarnings) = "def-pos" in
let warned_positions = Hashtbl.create 0 in
let get_deprecation_message meta s p_usage p_definition =
try
let s = match Meta.get Meta.Deprecated meta with
| _,[EConst(String s),_],_ -> s
| _ -> Printf.sprintf "Usage of this %s is deprecated" s
in
if not (Hashtbl.mem warned_positions p_usage) then begin
Hashtbl.replace warned_positions p_usage true;
com.warning s p_usage;
end;
if definition_positions then com.warning "Defined here" p_definition
with Not_found ->
()
in
let check_cf cf p = get_deprecation_message cf.cf_meta "field" p cf.cf_pos in
let check_class c p = if c != !curclass then get_deprecation_message c.cl_meta "class" p c.cl_pos in
let check_enum en p = get_deprecation_message en.e_meta "enum" p en.e_pos in
let check_ef ef p = get_deprecation_message ef.ef_meta "enum field" p ef.ef_pos in
let check_module_type mt p = match mt with
| TClassDecl c -> check_class c p
| TEnumDecl en -> check_enum en p
| _ -> ()
in
let rec expr e = match e.eexpr with
| TField(e1,fa) ->
expr e1;
begin match fa with
| FStatic(c,cf) | FInstance(c,cf) ->
check_class c e.epos;
check_cf cf e.epos
| FAnon cf ->
check_cf cf e.epos
| FClosure(co,cf) ->
(match co with None -> () | Some c -> check_class c e.epos);
check_cf cf e.epos
| FEnum(en,ef) ->
check_enum en e.epos;
check_ef ef e.epos;
| _ ->
()
end
| TNew(c,_,el) ->
List.iter expr el;
check_class c e.epos;
(match c.cl_constructor with None -> () | Some cf -> check_cf cf e.epos)
| TTypeExpr(mt) | TCast(_,Some mt) ->
check_module_type mt e.epos
| _ ->
Type.iter expr e
in
List.iter (fun t -> match t with
| TClassDecl c ->
curclass := c;
let field cf = match cf.cf_expr with None -> () | Some e -> expr e in
(match c.cl_constructor with None -> () | Some cf -> field cf);
(match c.cl_init with None -> () | Some e -> expr e);
List.iter field c.cl_ordered_statics;
List.iter field c.cl_ordered_fields;
| _ ->
()
) com.types

let check_unification com e t =
begin match follow e.etype,follow t with
| TEnum _,TDynamic _ ->
Expand Down Expand Up @@ -1142,8 +1076,8 @@ let post_process_end() =
let run com tctx main =
if com.display = DMUsage then
Codegen.detect_usage com;
if Common.defined com Define.DeprecationWarnings then
check_deprecation com;
if not (Common.defined com Define.NoDeprecationWarnings) then
Codegen.DeprecationCheck.run com;

(* PASS 1: general expression filters *)
let filters = [
Expand Down
Loading

0 comments on commit 1636502

Please sign in to comment.