Browse Source

Add makeMacroPosition

杨博 11 years ago
parent
commit
d46d782c98
1 changed files with 17 additions and 1 deletions
  1. 17 1
      std/haxe/macro/ExprTools.hx

+ 17 - 1
std/haxe/macro/ExprTools.hx

@@ -35,6 +35,22 @@ using Lambda;
 **/
 class ExprTools {
 
+	/**
+		Returns the `Position` where the caller of `makeMacroPosition` is.
+	**/
+	macro static function makeMacroPosition():ExprOf<Position>
+	{
+		var positionExpr = Context.makeExpr(Context.getPosInfos(Context.currentPos()), Context.currentPos());
+		if (Context.defined("macro"))
+		{
+			return macro Context.makePosition($positionExpr);
+		}
+		else
+		{
+			return positionExpr;
+		}
+	}
+
 	/**
 		Converts expression [e] to a human-readable String representation.
 
@@ -303,4 +319,4 @@ class ExprArrayTools {
 		for (e in el)
 			f(e);
 	}
-}
+}