Parcourir la source

added Context.getLocalUsing (fixed issue #1129)

Simon Krajewski il y a 13 ans
Parent
commit
799043fc69
3 fichiers modifiés avec 18 ajouts et 1 suppressions
  1. 8 1
      interp.ml
  2. 7 0
      std/haxe/macro/Context.hx
  3. 3 0
      typer.ml

+ 8 - 1
interp.ml

@@ -101,6 +101,7 @@ type extern_api = {
 	set_js_generator : (value -> unit) -> unit;
 	get_local_type : unit -> t option;
 	get_local_method : unit -> string;
+	get_local_using : unit -> tclass list;
 	get_build_fields : unit -> value;
 	define_type : value -> unit;
 	module_dependency : string -> string -> bool -> unit;
@@ -175,6 +176,7 @@ let encode_type_ref = ref (fun t -> assert false)
 let decode_type_ref = ref (fun t -> assert false)
 let encode_expr_ref = ref (fun e -> assert false)
 let decode_expr_ref = ref (fun e -> assert false)
+let encode_clref_ref = ref (fun c -> assert false)
 let enc_array_ref = ref (fun l -> assert false)
 let make_ast_ref = ref (fun _ -> assert false)
 let make_complex_type_ref = ref (fun _ -> assert false)
@@ -185,6 +187,7 @@ let encode_type (t:Type.t) : value = (!encode_type_ref) t
 let decode_type (v:value) : Type.t = (!decode_type_ref) v
 let encode_expr (e:Ast.expr) : value = (!encode_expr_ref) e
 let decode_expr (e:value) : Ast.expr = (!decode_expr_ref) e
+let encode_clref (c:tclass) : value = (!encode_clref_ref) c
 let make_ast (e:texpr) : Ast.expr = (!make_ast_ref) e
 let make_complex_type (t:Type.t) : Ast.complex_type = (!make_complex_type_ref) t
 
@@ -2225,6 +2228,9 @@ let macro_lib =
 		"local_method", Fun0 (fun() ->
 			VString ((get_ctx()).curapi.get_local_method())
 		);
+		"local_using", Fun0 (fun() ->
+			enc_array (List.map encode_clref ((get_ctx()).curapi.get_local_using()))
+		);
 		"follow", Fun2 (fun v once ->
 			let t = decode_type v in
 			let follow_once t =
@@ -4250,4 +4256,5 @@ enc_array_ref := enc_array;
 encode_type_ref := encode_type;
 decode_type_ref := decode_type;
 encode_expr_ref := encode_expr;
-decode_expr_ref := decode_expr
+decode_expr_ref := decode_expr;
+encode_clref_ref := encode_clref

+ 7 - 0
std/haxe/macro/Context.hx

@@ -101,6 +101,13 @@ class Context {
 		return l;
 	}
 
+	/**
+		Returns classes which are available for "using" where the macro was called
+	**/	
+	public static function getLocalUsing() :  Null<Type.Ref<Type.ClassType>> {
+		return load("local_using", 0)();
+	}
+
 	/**
 		Tells is the given compiler directive has been defined with -D
 	**/

+ 3 - 0
typer.ml

@@ -2712,6 +2712,9 @@ let make_macro_api ctx p =
 		Interp.get_local_method = (fun() ->
 			ctx.curmethod;
 		);
+		Interp.get_local_using = (fun() ->
+			ctx.local_using;
+		);
 		Interp.get_build_fields = (fun() ->
 			match ctx.g.get_build_infos() with
 			| None -> Interp.VNull