소스 검색

[display] add @type mode

Dan Korostelev 10 년 전
부모
커밋
2cbbe727a6

+ 1 - 0
common.ml

@@ -107,6 +107,7 @@ type display_mode =
 	| DMPosition
 	| DMToplevel
 	| DMResolve of string
+	| DMType
 
 type context = {
 	(* config *)

+ 4 - 1
main.ml

@@ -1194,6 +1194,9 @@ try
 					| "usage" ->
 						activate_special_display_mode();
 						DMUsage
+					| "type" ->
+						activate_special_display_mode();
+						DMType
 					| "toplevel" ->
 						activate_special_display_mode();
 						DMToplevel
@@ -1460,7 +1463,7 @@ try
 		t();
 		if ctx.has_error then raise Abort;
 		begin match com.display with
-			| DMNone | DMUsage | DMPosition | DMResolve _ ->
+			| DMNone | DMUsage | DMPosition | DMType | DMResolve _ ->
 				()
 			| _ ->
 				if ctx.has_next then raise Abort;

BIN
tests/misc/projects/Issue3129/test.n


+ 1 - 0
tests/misc/projects/display-type/Main.hx

@@ -0,0 +1 @@
+class Main { static function main() { var a = ""; a; } }

+ 2 - 0
tests/misc/projects/display-type/compile.hxml

@@ -0,0 +1,2 @@
+-main Main
+--display Main.hx@52@type

+ 3 - 0
tests/misc/projects/display-type/compile.hxml.stderr

@@ -0,0 +1,3 @@
+<type>
+String
+</type>

+ 1 - 1
typeload.ml

@@ -1300,7 +1300,7 @@ let type_function ctx args ret fmode f do_display p =
 	else begin
 		let e = match ctx.com.display with
 			| DMToplevel -> find_enclosing ctx.com e
-			| DMPosition | DMUsage -> find_before_pos ctx.com e
+			| DMPosition | DMUsage | DMType -> find_before_pos ctx.com e
 			| _ -> e
 		in
 		try

+ 2 - 0
typer.ml

@@ -3513,6 +3513,8 @@ and handle_display ctx e_ast iscall p =
 	match ctx.com.display with
 	| DMResolve _ ->
 		assert false
+	| DMType ->
+		raise (DisplayTypes [e.etype])
 	| DMUsage | DMPosition ->
 		begin match e.eexpr with
 		| TField(_,FEnum(_,ef)) ->