Bladeren bron

Add PositionTools.hx

杨博 11 jaren geleden
bovenliggende
commit
10cfd1723f
3 gewijzigde bestanden met toevoegingen van 43 en 13 verwijderingen
  1. 0 12
      std/haxe/macro/ExprTools.hx
  2. 41 0
      std/haxe/macro/PositionTools.hx
  3. 2 1
      std/haxe/macro/Tools.hx

+ 0 - 12
std/haxe/macro/ExprTools.hx

@@ -35,18 +35,6 @@ using Lambda;
 **/
 class ExprTools {
 
-	/**
-		Returns the `Position` where the caller of `here` is.
-	**/
-	macro public static function here():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.
 

+ 41 - 0
std/haxe/macro/PositionTools.hx

@@ -0,0 +1,41 @@
+package haxe.macro;
+
+import haxe.macro.Expr;
+
+class PositionTools {
+
+	/**
+		Returns the `Position` where the caller of `here` is.
+	**/
+	macro public static function here():ExprOf<Position> {
+		var positionExpr = Context.makeExpr(Context.getPosInfos(Context.currentPos()), Context.currentPos());
+		if (Context.defined("macro")) {
+			return macro Context.makePosition($positionExpr);
+		} else {
+			return positionExpr;
+		}
+	}
+
+	/**
+		Like `Context.getPosInfos`, except this method is available on all platforms.
+	**/
+	public static function getInfos( p : Position ) : { min : Int, max : Int, file : String } {
+		#if macro
+		return Context.getPosInfos(p);
+		#else
+		return p;
+		#end
+	}
+
+	/**
+		Like `Context.makePosition`, except this method is available on all platforms.
+	**/
+	public static function make( inf : { min : Int, max : Int, file : String } ) : Position {
+		#if macro
+		return Context.makePosition(inf);
+		#else
+		return inf;
+		#end
+	}
+
+}

+ 2 - 1
std/haxe/macro/Tools.hx

@@ -29,4 +29,5 @@ typedef TExprTools = ExprTools;
 typedef TComplexTypeTools = ComplexTypeTools;
 typedef TTypeTools = TypeTools;
 typedef TMacroStringTools = MacroStringTools;
-typedef TTypedExprTools = TypedExprTools;
+typedef TTypedExprTools = TypedExprTools;
+typedef TPositionTools = PositionTools;