Przeglądaj źródła

temporarily enter display mode for macros

Simon Krajewski 9 lat temu
rodzic
commit
3cacc81d88
3 zmienionych plików z 16 dodań i 3 usunięć
  1. 1 1
      src/typing/typecore.ml
  2. 1 1
      src/typing/typeload.ml
  3. 14 1
      src/typing/typer.ml

+ 1 - 1
src/typing/typecore.ml

@@ -43,7 +43,7 @@ type macro_mode =
 	| MExpr
 	| MBuild
 	| MMacroType
-
+	| MDisplay
 
 type typer_pass =
 	| PBuildModule			(* build the module structure and setup module type parameters *)

+ 1 - 1
src/typing/typeload.ml

@@ -2094,7 +2094,7 @@ module ClassInitializer = struct
 			if fctx.is_display_field then begin
 				if fctx.is_macro && not ctx.in_macro then
 					(* force macro system loading of this class in order to get completion *)
-					delay ctx PTypeField (fun() -> ignore(ctx.g.do_macro ctx MExpr c.cl_path cf.cf_name [] p))
+					delay ctx PTypeField (fun() -> ignore(ctx.g.do_macro ctx MDisplay c.cl_path cf.cf_name [] p))
 				else begin
 					cf.cf_type <- TLazy r;
 					cctx.delayed_expr <- (ctx,Some r) :: cctx.delayed_expr;

+ 14 - 1
src/typing/typer.ml

@@ -4934,6 +4934,8 @@ let load_macro ctx cpath f p =
 		| name :: pack when name.[0] >= 'A' && name.[0] <= 'Z' -> (List.rev pack,name), Some (snd cpath)
 		| _ -> cpath, None
 	) in
+	(* Temporarily enter display mode while typing the macro. *)
+	if ctx.in_display then mctx.com.display <- ctx.com.display;
 	let m = (try Hashtbl.find ctx.g.types_module cpath with Not_found -> cpath) in
 	let mloaded = Typeload.load_module mctx m p in
 	api.Interp.current_macro_module <- (fun() -> mloaded);
@@ -4954,6 +4956,7 @@ let load_macro ctx cpath f p =
 		| _ -> error "Macro should be called on a class" p
 	) in
 	let meth = (match follow meth.cf_type with TFun (args,ret) -> args,ret,cl,meth | _ -> error "Macro call should be a method" p) in
+	mctx.com.display <- DMNone;
 	if not ctx.in_macro then flush_macro_context mint ctx;
 	t();
 	let call args =
@@ -4971,11 +4974,21 @@ type macro_arg_type =
 	| MAOther
 
 let type_macro ctx mode cpath f (el:Ast.expr list) p =
+	let reset = if mode = MDisplay then begin
+		let old = ctx.in_display in
+		ctx.in_display <- true;
+		(fun () -> ctx.in_display <- old)
+	end else
+		(fun () -> ())
+	in
 	let mctx, (margs,mret,mclass,mfield), call_macro = load_macro ctx cpath f p in
+	reset();
 	let mpos = mfield.cf_pos in
 	let ctexpr = { tpackage = ["haxe";"macro"]; tname = "Expr"; tparams = []; tsub = None } in
 	let expr = Typeload.load_instance mctx (ctexpr,p) false in
 	(match mode with
+	| MDisplay ->
+		()
 	| MExpr ->
 		unify mctx mret expr mpos;
 	| MBuild ->
@@ -5091,7 +5104,7 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
 		| Some v ->
 			try
 				Some (match mode with
-				| MExpr -> Interp.decode_expr v
+				| MExpr | MDisplay -> Interp.decode_expr v
 				| MBuild ->
 					let fields = (match v with
 						| Interp.VNull ->