2
0
Эх сурвалжийг харах

fix issue with --display + macros

Nicolas Cannasse 14 жил өмнө
parent
commit
fd30102d81
5 өөрчлөгдсөн 19 нэмэгдсэн , 15 устгасан
  1. 3 1
      common.ml
  2. 1 1
      genswf.ml
  3. 5 4
      main.ml
  4. 7 7
      typeload.ml
  5. 3 2
      typer.ml

+ 3 - 1
common.ml

@@ -47,6 +47,7 @@ type basic_types = {
 type context = {
 	(* config *)
 	version : int;
+	mutable display : bool;
 	mutable debug : bool;
 	mutable verbose : bool;
 	mutable foptimize : bool;
@@ -79,13 +80,14 @@ type context = {
 
 exception Abort of string * Ast.pos
 
-let display = ref false
+let display_default = ref false
 
 let create v =
 	let m = Type.mk_mono() in
 	{
 		version = v;
 		debug = false;
+		display = !display_default;
 		verbose = false;
 		foptimize = true;
 		dead_code_elimination = false;

+ 1 - 1
genswf.ml

@@ -525,7 +525,7 @@ let parse_swf com file =
 			IO.close_in ch;
 			List.iter (fun t ->
 				match t.tdata with
-				| TActionScript3 (id,as3) when not com.debug && not !Common.display ->
+				| TActionScript3 (id,as3) when not com.debug && not com.display ->
 					t.tdata <- TActionScript3 (id,remove_debug_infos as3)
 				| _ -> ()
 			) tags;

+ 5 - 4
main.ml

@@ -205,7 +205,7 @@ let parse_hxml file =
 let lookup_classes com fpath =
 	let found = ref [] in
 	List.iter (fun cp ->
-		let c = Common.get_full_path cp in
+		let c = (try Common.get_full_path cp with _ -> cp) in
 		let clen = String.length c in
 		if clen < String.length fpath && String.sub fpath 0 clen = c then begin
 			let path = String.sub fpath clen (String.length fpath - clen) in
@@ -419,7 +419,8 @@ try
 			| _ ->
 				let file, pos = try ExtString.String.split file_pos "@" with _ -> failwith ("Invalid format : " ^ file_pos) in
 				let pos = try int_of_string pos with _ -> failwith ("Invalid format : "  ^ pos) in
-				Common.display := true;
+				com.display <- true;
+				Common.display_default := true;
 				Common.define com "display";
 				Parser.resume_display := {
 					Ast.pfile = Common.get_full_path file;
@@ -504,7 +505,7 @@ try
 		if ret <> Unix.WEXITED 0 then failwith (String.concat "\n" lines);
 		com.class_path <- lines @ com.class_path;
 	);
-	if !Common.display then begin
+	if com.display then begin
 		xml_out := None;
 		no_output := true;
 		com.warning <- store_message;
@@ -635,7 +636,7 @@ with
 	| Common.Abort (m,p) -> report m p
 	| Lexer.Error (m,p) -> report (Lexer.error_msg m) p
 	| Parser.Error (m,p) -> report (Parser.error_msg m) p
-	| Typecore.Error (Typecore.Forbid_package _,_) when !Common.display -> () (* assume we have a --next *)
+	| Typecore.Error (Typecore.Forbid_package _,_) when !Common.display_default -> () (* assume we have a --next *)
 	| Typecore.Error (m,p) -> report (Typecore.error_msg m) p
 	| Interp.Error (msg,p :: l) ->
 		store_message msg p;

+ 7 - 7
typeload.ml

@@ -637,7 +637,7 @@ let init_class ctx c p herits fields =
 		c.cl_extern <- true;
 		List.filter (fun f -> List.mem AStatic f.cff_access) fields, []
 	end else fields, herits in
-	if core_api && not !Common.display then delay ctx ((fun() -> init_core_api ctx c));
+	if core_api && not ctx.com.display then delay ctx ((fun() -> init_core_api ctx c));
 	let tthis = TInst (c,List.map snd c.cl_types) in
 	let rec extends_public c =
 		List.exists (fun (c,_) -> c.cl_path = (["haxe"],"Public") || extends_public c) c.cl_implements ||
@@ -721,7 +721,7 @@ let init_class ctx c p herits fields =
 	
 	(* ----------------------- COMPLETION ----------------------------- *)
 
-	let display_file = if !Common.display then String.lowercase (Common.get_full_path p.pfile) = String.lowercase (!Parser.resume_display).pfile else false in
+	let display_file = if ctx.com.display then String.lowercase (Common.get_full_path p.pfile) = String.lowercase (!Parser.resume_display).pfile else false in
 	let rec is_full_type t =
 		match t with
 		| TFun (args,ret) -> is_full_type ret && List.for_all (fun (_,_,t) -> is_full_type t) args
@@ -729,7 +729,7 @@ let init_class ctx c p herits fields =
 		| TInst _ | TEnum _ | TLazy _ | TDynamic _ | TAnon _ | TType _ -> true
 	in
 	let bind_type cf r p =
-		if !Common.display then begin
+		if ctx.com.display then begin
 			let cp = !Parser.resume_display in
 			if display_file && (cp.pmin = 0 || (p.pmin <= cp.pmin && p.pmax >= cp.pmax)) then begin
 				cf.cf_type <- TLazy r;
@@ -777,7 +777,7 @@ let init_class ctx c p herits fields =
 				cf_public = is_public f.cff_access None;
 				cf_params = [];
 			} in
-			let delay = if (ctx.com.dead_code_elimination && not !Common.display) then begin
+			let delay = if (ctx.com.dead_code_elimination && not ctx.com.display) then begin
 				(match e with
 				| None ->
 					let r = exc_protect (fun r ->
@@ -898,7 +898,7 @@ let init_class ctx c p herits fields =
 				cf.cf_expr <- Some (mk (TFunction f) t p);
 				t
 			) in
-			let delay = if (ctx.com.dead_code_elimination && not !Common.display) then begin
+			let delay = if (ctx.com.dead_code_elimination && not ctx.com.display) then begin
 				if ((c.cl_extern && not inline) || c.cl_interface) && cf.cf_name <> "__init__" then begin
 					(fun() -> ())
 				end else begin
@@ -921,7 +921,7 @@ let init_class ctx c p herits fields =
 			let check_get = ref (fun() -> ()) in
 			let check_set = ref (fun() -> ()) in
 			let check_method m t () =
-				if !Common.display then () else
+				if ctx.com.display then () else
 				try
 					let t2 = (if stat then (PMap.find m c.cl_statics).cf_type else fst (class_field c m)) in
 					unify_raise ctx t2 t p;
@@ -1227,7 +1227,7 @@ let type_module ctx m tdecls loadp =
 				ctx.local_using<- ctx.local_using @ [resolve_typedef ctx t])
 		| EClass d ->
 			let c = get_class d.d_name in
-			let checks = if not !Common.display then [check_overriding ctx c p; check_interfaces ctx c p] else [] in
+			let checks = if not ctx.com.display then [check_overriding ctx c p; check_interfaces ctx c p] else [] in
 			delays := !delays @ (checks @ init_class ctx c p d.d_flags d.d_data)
 		| EEnum d ->
 			let e = get_enum d.d_name in

+ 3 - 2
typer.ml

@@ -1916,7 +1916,7 @@ let make_macro_api ctx p =
 			tp.tp_meta <- tp.tp_meta @ m;
 		);
 		Interp.print = (fun s ->
-			if not !Common.display then print_string s
+			if not ctx.com.display then print_string s
 		);
 	}
 
@@ -1931,6 +1931,7 @@ let load_macro ctx cpath f p =
 			let com2 = Common.clone ctx.com in
 			com2.package_rules <- PMap.empty;
 			com2.main_class <- None;
+			com2.display <- false;
 			List.iter (fun p -> com2.defines <- PMap.remove (platform_name p) com2.defines) platforms;
 			com2.class_path <- List.filter (fun s -> not (ExtString.String.exists s "/_std/")) com2.class_path;
 			com2.class_path <- List.map (fun p -> p ^ "neko" ^ "/_std/") com2.std_path @ com2.class_path;
@@ -2071,7 +2072,7 @@ let rec create com =
 			constructs = Hashtbl.create 0;
 			type_patches = Hashtbl.create 0;
 			delayed = [];
-			doinline = not (Common.defined com "no_inline");
+			doinline = not (Common.defined com "no_inline" || com.display);
 			hook_generate = [];
 			std = empty;
 			do_inherit = Codegen.on_inherit;