Browse Source

rename `Context.getConstructorArguments` to `getCallArguments` (closes #3833)

Simon Krajewski 10 years ago
parent
commit
eaa62aab92
6 changed files with 20 additions and 21 deletions
  1. 3 3
      interp.ml
  2. 9 10
      std/haxe/macro/Context.hx
  3. 1 1
      tests/unit/src/unit/issues/misc/Issue3183Macro.hx
  4. 1 1
      typecore.ml
  5. 1 1
      typeload.ml
  6. 5 5
      typer.ml

+ 3 - 3
interp.ml

@@ -111,7 +111,7 @@ type extern_api = {
 	set_js_generator : (value -> unit) -> unit;
 	get_local_type : unit -> t option;
 	get_expected_type : unit -> t option;
-	get_constructor_arguments : unit -> Ast.expr list option;
+	get_call_arguments : unit -> Ast.expr list option;
 	get_local_method : unit -> string;
 	get_local_using : unit -> tclass list;
 	get_local_vars : unit -> (string, Type.tvar) PMap.t;
@@ -2478,8 +2478,8 @@ let macro_lib =
 			| None -> VNull
 			| Some t -> encode_type t
 		);
-		"constructor_arguments", Fun0 (fun() ->
-			match (get_ctx()).curapi.get_constructor_arguments() with
+		"call_arguments", Fun0 (fun() ->
+			match (get_ctx()).curapi.get_call_arguments() with
 			| None -> VNull
 			| Some el -> enc_array (List.map encode_expr el)
 		);

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

@@ -114,15 +114,14 @@ class Context {
 	}
 
 	/**
-		Returns the constructor arguments that are used to construct the
-		current `@:genericBuild` class, if available.
+		Returns the call arguments that lead to the invocation of the current
+		`@:genericBuild` macro, if available.
 
-		Returns `null` if the current macro is not a build-macro which was
-		called from constructing a `@:genericBuild` instance.
+		Returns `null` if the current macro is not a `@:genericBuild` macro.
 	**/
 	@:require(haxe_ver >= 3.2)
-	public static function getConstructorArguments():Null<Array<Expr>> {
-		return load("constructor_arguments", 0)();
+	public static function getCallArguments():Null<Array<Expr>> {
+		return load("call_arguments", 0)();
 	}
 
 	/**
@@ -225,19 +224,19 @@ class Context {
 		var d = load("defined_value", 1)(untyped key.__s);
 		return d == null ? null : new String(d);
 	}
-	
+
 	/**
 		Returns a map of all compiler directives that have been set.
-		
+
 		Compiler directives are set using the `-D` command line parameter, or
 		by calling `haxe.macro.Compiler.define`.
-		
+
 		Modifying the returned map has no effect on the compiler.
 	 */
 	public static function getDefines() : Map<String,String> {
 		return load("get_defines", 0)();
 	}
-	
+
 	/**
 		Resolves a type identified by `name`.
 

+ 1 - 1
tests/unit/src/unit/issues/misc/Issue3183Macro.hx

@@ -14,7 +14,7 @@ class Issue3183Macro {
 			case TInst(c, args):
 				var arity = args.length;
 				if (arity == 0) {
-					var el = Context.getConstructorArguments();
+					var el = Context.getCallArguments();
 					if (el != null && el.length > 0) {
 						args = [for (e in el) Context.typeof(e)];
 						arity = args.length;

+ 1 - 1
typecore.ml

@@ -97,7 +97,7 @@ and typer = {
 	mutable meta : metadata;
 	mutable this_stack : texpr list;
 	mutable with_type_stack : with_type list;
-	mutable constructor_argument_stack : Ast.expr list list;
+	mutable call_argument_stack : Ast.expr list list;
 	(* variable *)
 	mutable pass : typer_pass;
 	(* per-module *)

+ 1 - 1
typeload.ml

@@ -2782,7 +2782,7 @@ let type_module ctx m file ?(is_extern=false) tdecls p =
 		meta = [];
 		this_stack = [];
 		with_type_stack = [];
-		constructor_argument_stack = [];
+		call_argument_stack = [];
 		pass = PBuildModule;
 		on_error = (fun ctx msg p -> ctx.com.error msg p);
 		macro_depth = ctx.macro_depth;

+ 5 - 5
typer.ml

@@ -3282,9 +3282,9 @@ and type_expr ctx (e,p) (with_type:with_type) =
 				error "Constructor is not a function" p
 		in
 		let t = try
-			ctx.constructor_argument_stack <- el :: ctx.constructor_argument_stack;
+			ctx.call_argument_stack <- el :: ctx.call_argument_stack;
 			let t = follow (Typeload.load_instance ctx t p true) in
-			ctx.constructor_argument_stack <- List.tl ctx.constructor_argument_stack;
+			ctx.call_argument_stack <- List.tl ctx.call_argument_stack;
 			(* Try to properly build @:generic classes here (issue #2016) *)
 			begin match t with
 				| TInst({cl_kind = KGeneric } as c,tl) -> follow (Codegen.build_generic ctx c p tl)
@@ -4358,8 +4358,8 @@ let make_macro_api ctx p =
 				| (WithType t | WithTypeResume t) :: _ -> Some t
 				| _ -> None
 		);
-		Interp.get_constructor_arguments = (fun() ->
-			match ctx.constructor_argument_stack with
+		Interp.get_call_arguments = (fun() ->
+			match ctx.call_argument_stack with
 				| [] -> None
 				| el :: _ -> Some el
 		);
@@ -4823,7 +4823,7 @@ let rec create com =
 		meta = [];
 		this_stack = [];
 		with_type_stack = [];
-		constructor_argument_stack = [];
+		call_argument_stack = [];
 		pass = PBuildModule;
 		macro_depth = 0;
 		untyped = false;