Browse Source

separated haxe.Resource by platform

Nicolas Cannasse 14 years ago
parent
commit
498f5dceb2
5 changed files with 126 additions and 48 deletions
  1. 1 1
      doc/ImportAll.hx
  2. 42 0
      std/cpp/_std/haxe/Resource.hx
  3. 1 40
      std/haxe/Resource.hx
  4. 25 7
      std/neko/db/SpodData.hx
  5. 57 0
      std/php/_std/haxe/Resource.hx

+ 1 - 1
doc/ImportAll.hx

@@ -64,7 +64,7 @@ class ImportAll {
 					if( StringTools.startsWith(cl,"flash9.") )
 						cl = "flash."+cl.substr(7);
 					switch( cl ) {
-					case "ImportAll": continue;
+					case "ImportAll", "neko.db.MacroManager": continue;
 					case "haxe.TimerQueue": if( Context.defined("neko") || Context.defined("php") ) continue;
 					case "haxe.macro.DefaultJSGenerator","haxe.macro.Context", "haxe.macro.Compiler": if( !Context.defined("neko") ) continue;
 					case "haxe.remoting.SocketWrapper": if( !Context.defined("flash") ) continue;

+ 42 - 0
std/cpp/_std/haxe/Resource.hx

@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2005-2008, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+package haxe;
+
+@:core_api
+class Resource {
+
+	public static function listNames() : Array<String> {
+		return untyped __global__.__hxcpp_resource_names();
+	}
+	public static function getString(name:String) : String {
+		return untyped __global__.__hxcpp_resource_string(name);
+	}
+	public static function getBytes(name:String) : haxe.io.Bytes {
+		var array:haxe.io.BytesData = untyped __global__.__hxcpp_resource_bytes(name);
+		if (array==null) return null;
+		return haxe.io.Bytes.ofData(array);
+	}
+
+}

+ 1 - 40
std/haxe/Resource.hx

@@ -25,46 +25,7 @@
 package haxe;
 
 class Resource {
-#if php
-	static function cleanName(name : String) : String {
-		return ~/[\\\/:?"*<>|]/.replace(name, '_');
-	}
-
-	static function getDir() {
-		return untyped __call__('dirname', __php__('__FILE__'))+"/../../res";
-	}
-
-	static function getPath(name : String) {
-		return getDir()+'/'+cleanName(name);
-	}
-
-	public static function listNames() : Array<String> {
-		var a = php.FileSystem.readDirectory(getDir());
-		if(a[0] == '.') a.shift();
-		if(a[0] == '..') a.shift();
-		return a;
-	}
 
-	public static function getString( name : String ) {
-		return php.io.File.getContent(getPath(name));
-	}
-
-	public static function getBytes( name : String ) {
-		return php.io.File.getBytes(getPath(name));
-	}
-#elseif cpp
-	public static function listNames() : Array<String> {
-		return untyped __global__.__hxcpp_resource_names();
-	}
-	public static function getString(name:String) : String {
-		return untyped __global__.__hxcpp_resource_string(name);
-	}
-	public static function getBytes(name:String) : haxe.io.Bytes {
-		var array:haxe.io.BytesData = untyped __global__.__hxcpp_resource_bytes(name);
-		if (array==null) return null;
-		return haxe.io.Bytes.ofData(array);
-	}
-#else
 	static var content : Array<{ name : String, data : String, str : String }>;
 
 	public static function listNames() : Array<String> {
@@ -113,5 +74,5 @@ class Resource {
 		content = untyped __resources__();
 		#end
 	}
-#end
+
 }

+ 25 - 7
std/neko/db/SpodData.hx

@@ -62,6 +62,24 @@ class SpodData {
 		return null;
 	}
 
+	public dynamic function typeof( e : Expr ) : haxe.macro.Type {
+		#if macro
+		return Context.typeof(e);
+		#else
+		throw "not implemented";
+		return null;
+		#end
+	}
+
+	public dynamic function follow( t : haxe.macro.Type ) : haxe.macro.Type {
+		#if macro
+		return Context.follow(t);
+		#else
+		throw "not implemented";
+		return null;
+		#end
+	}
+
 	function makeInt( t : haxe.macro.Type ) {
 		switch( t ) {
 		case TInst(c, _):
@@ -451,9 +469,9 @@ class SpodData {
 	}
 
 	function buildDefault( cond : Expr ) {
-		var t = try Context.typeof(cond) catch( e : Dynamic ) throw BuildError.EExpr(cond);
+		var t = try typeof(cond) catch( e : Dynamic ) throw BuildError.EExpr(cond);
 		isNull = false;
-		var d = try makeType(t) catch( e : Dynamic ) try makeType(Context.follow(t)) catch( e : Dynamic ) error("Unsupported type " + Std.string(t), cond.pos);
+		var d = try makeType(t) catch( e : Dynamic ) try makeType(follow(t)) catch( e : Dynamic ) error("Unsupported type " + Std.string(t), cond.pos);
 		return { sql : sqlQuoteValue(cond, d), t : d, n : isNull };
 	}
 
@@ -565,7 +583,7 @@ class SpodData {
 			case CIdent(n), CType(n):
 				var f = current.hfields.get(n);
 				if( f != null ) {
-					if( (try Context.typeof(cond) catch( e : Dynamic ) null) != null )
+					if( (try typeof(cond) catch( e : Dynamic ) null) != null )
 						error("Possible conflict between variable and database field", p);
 					return { sql : makeString(f.name, p), t : f.t, n : f.isNull };
 				}
@@ -636,7 +654,7 @@ class SpodData {
 	}
 
 	function ensureType( e : Expr, rt : SpodType ) {
-		var t = try Context.typeof(e) catch( _ : Dynamic ) throw BuildError.EExpr(e);
+		var t = try typeof(e) catch( _ : Dynamic ) throw BuildError.EExpr(e);
 		switch( t ) {
 		case TMono:
 			// pseudo-cast
@@ -645,7 +663,7 @@ class SpodData {
 				{ expr : EConst(CIdent("__tmp")), pos : e.pos },
 			]), pos : e.pos };
 		default:
-			var d = try makeType(t) catch( e : Dynamic ) try makeType(Context.follow(t)) catch( e : Dynamic ) throw BuildError.EExpr(sqlQuoteValue(e,rt)); // will produce an error
+			var d = try makeType(t) catch( e : Dynamic ) try makeType(follow(t)) catch( e : Dynamic ) throw BuildError.EExpr(sqlQuoteValue(e,rt)); // will produce an error
 			unify(d, rt, e.pos);
 			return e;
 		}
@@ -671,12 +689,12 @@ class SpodData {
 			if( current.key.length > 1 )
 				error("You can't use a single value on a table with multiple keys (" + current.key.join(",") + ")", p);
 			var fi = current.hfields.get(current.key[0]);
-			var t = try Context.typeof(econd) catch( _ : Dynamic ) throw BuildError.EExpr(econd);
+			var t = try typeof(econd) catch( _ : Dynamic ) throw BuildError.EExpr(econd);
 			switch( t ) {
 			case TMono:
 
 			default:
-				var d = try makeType(t) catch( e : Dynamic ) try makeType(Context.follow(t)) catch( e : Dynamic ) throw BuildError.EExpr(sqlQuoteValue(econd, fi.t));
+				var d = try makeType(t) catch( e : Dynamic ) try makeType(follow(t)) catch( e : Dynamic ) throw BuildError.EExpr(sqlQuoteValue(econd, fi.t));
 				unify(d, fi.t, p);
 			}
 		}

+ 57 - 0
std/php/_std/haxe/Resource.hx

@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2005-2008, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+package haxe;
+
+@:core_api
+class Resource {
+
+	static function cleanName(name : String) : String {
+		return ~/[\\\/:?"*<>|]/.replace(name, '_');
+	}
+
+	static function getDir() : String {
+		return untyped __call__('dirname', __php__('__FILE__'))+"/../../res";
+	}
+
+	static function getPath(name : String) : String {
+		return getDir()+'/'+cleanName(name);
+	}
+
+	public static function listNames() : Array<String> {
+		var a = php.FileSystem.readDirectory(getDir());
+		if(a[0] == '.') a.shift();
+		if(a[0] == '..') a.shift();
+		return a;
+	}
+
+	public static function getString( name : String ) : String {
+		return php.io.File.getContent(getPath(name));
+	}
+
+	public static function getBytes( name : String ) : haxe.io.Bytes {
+		return php.io.File.getBytes(getPath(name));
+	}
+
+}