소스 검색

Merge pull request #3186 from Atry/type-definition-on-non-macro-platform

Allow building TypeDefinition on non-macro platform
Simon Krajewski 11 년 전
부모
커밋
bcbd44a734
4개의 변경된 파일47개의 추가작업 그리고 4개의 파일을 삭제
  1. 1 1
      std/haxe/macro/ExprTools.hx
  2. 3 2
      std/haxe/macro/MacroStringTools.hx
  3. 41 0
      std/haxe/macro/PositionTools.hx
  4. 2 1
      std/haxe/macro/Tools.hx

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

@@ -303,4 +303,4 @@ class ExprArrayTools {
 		for (e in el)
 			f(e);
 	}
-}
+}

+ 3 - 2
std/haxe/macro/MacroStringTools.hx

@@ -52,6 +52,8 @@ class MacroStringTools {
 		return Context.load("is_fmt_string", 1)(e.pos);
 	}
 
+	#end
+
 	/**
 		Converts an array of Strings `sl` to a field expression.
 
@@ -87,5 +89,4 @@ class MacroStringTools {
 		return TPath( { pack : pack, name : pack.pop(), params : [] } );
 	}
 
-	#end
-}
+}

+ 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;