浏览代码

added Context.getLocalMethod (fixed issue #704)

Simon Krajewski 13 年之前
父节点
当前提交
4fb7021809
共有 3 个文件被更改,包括 16 次插入0 次删除
  1. 4 0
      interp.ml
  2. 9 0
      std/haxe/macro/Context.hx
  3. 3 0
      typer.ml

+ 4 - 0
interp.ml

@@ -98,6 +98,7 @@ type extern_api = {
 	meta_patch : string -> string -> string option -> bool -> unit;
 	set_js_generator : (value -> unit) -> unit;
 	get_local_type : unit -> t option;
+	get_local_method : unit -> string;
 	get_build_fields : unit -> value;
 	define_type : value -> unit;
 	module_dependency : string -> string -> bool -> unit;
@@ -1936,6 +1937,9 @@ let macro_lib =
 			| None -> VNull
 			| Some t -> encode_type t
 		);
+		"local_method", Fun0 (fun() ->
+			VString ((get_ctx()).curapi.get_local_method())
+		);
 		"follow", Fun2 (fun v once ->
 			let t = decode_type v in
 			let follow_once t =

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

@@ -91,6 +91,15 @@ class Context {
 		return l;
 	}
 
+	/**
+		Returns the name of the method from which the macro was called
+	**/	
+	public static function getLocalMethod() : Null<String> {
+		var l : String = load("local_method", 0)();
+		if (l == "") return null;
+		return l;
+	}
+	
 	/**
 		Tells is the given compiler directive has been defined with -D
 	**/

+ 3 - 0
typer.ml

@@ -2417,6 +2417,9 @@ let make_macro_api ctx p =
 				else
 					Some (TInst (ctx.curclass,[]))
 		);
+		Interp.get_local_method = (fun() ->
+			ctx.curmethod;
+		);
 		Interp.get_build_fields = (fun() ->
 			match ctx.g.get_build_infos() with
 			| None -> Interp.VNull