Browse Source

changed Anonymous to _hx_anonymous
fixed issue with Xml prolog in PHP

Franco Ponticelli 17 years ago
parent
commit
f25ac7b3cb
5 changed files with 25 additions and 44 deletions
  1. 0 14
      genphp.ml
  2. 1 1
      std/Reflect.hx
  3. 2 2
      std/Type.hx
  4. 3 21
      std/php/Boot.hx
  5. 19 6
      std/php/PhpXml__.hx

+ 0 - 14
genphp.ml

@@ -914,16 +914,10 @@ and gen_inline_function ctx f params p =
 	) old_li;
 
 	print ctx "), null, array(";
-(*	ctx.quotes <- ctx.quotes + 1; *)
 	concat ctx "," (fun (arg,o,t) ->
 		let arg = define_local ctx arg in
 		print ctx "'%s'" arg;
-	(*
-		let arg = define_local ctx arg in
-		s_funarg ctx arg t p o;
-		*)
 	) f.tf_args;
-(*	ctx.quotes <- ctx.quotes - 1; *)
 	print ctx "), %s\"" pq;
 	ctx.quotes <- ctx.quotes + 1;
 	gen_expr ctx (fun_block ctx f p);
@@ -1213,17 +1207,10 @@ and gen_expr ctx e =
 				match f.cf_expr with
 				| Some { eexpr = TFunction fd } ->
 					print ctx "$this->%s = php_Boot::__closure(array(), $this, array(" name;
-(*					ctx.quotes <- ctx.quotes + 1; *)
 					concat ctx "," (fun (arg,o,t) ->
 						let arg = define_local ctx arg in
 						print ctx "'%s'" arg;
-					(*
-					let arg = define_local ctx arg in
-					  s_funarg ctx arg t e.epos o;
-					  *)
 					) fd.tf_args;
-(*					ctx.quotes <- ctx.quotes - 1; *)
-
 					print ctx "), \"";
 					let old = ctx.in_value in
 					ctx.in_value <- Some name;
@@ -1936,7 +1923,6 @@ let generate com =
 				let ctx = init com "lib" c.cl_path (if c.cl_interface then 2 else 0) in
 				ctx.extern_classes_with_init <- !extern_classes_with_init;
 				ctx.all_dynamic_methods <- !all_dynamic_methods;
-				(*let cp = s_path ctx c.cl_path c.cl_extern c.cl_pos in*)
 				generate_class ctx c;
 				(match c.cl_init with
 				| None -> ()

+ 1 - 1
std/Reflect.hx

@@ -278,7 +278,7 @@ class Reflect {
 			if( v == null )
 				return false;
 			if(__call__("is_object", v))
-				return __php__("$v instanceof Anonymous") || Type.getClass(v) != null;
+				return __php__("$v instanceof _hx_anonymous") || Type.getClass(v) != null;
 			if(__php__("is_string($v) && !php_Boot::__is_lambda($v)")) return true;
 			if(__php__("is_array($v) && !is_callable($v)")) return true;
 			return false;

+ 2 - 2
std/Type.hx

@@ -62,7 +62,7 @@ class Type {
 				return __php__("php_Boot::__ttype('String')");
 			}
 			var c = __php__("get_class")(o);
-			if(c == false || c == 'Anonymous' || __call__("is_subclass_of", c, "enum"))
+			if(c == false || c == '_hx_anonymous' || __call__("is_subclass_of", c, "enum"))
 				return null;
 			else
 				return __php__("php_Boot::__ttype($c)");
@@ -595,7 +595,7 @@ class Type {
 			if(__call__("is_bool", v)) return TBool;
 			if(__call__("is_int", v)) return TInt;
 			if(__call__("is_float", v)) return TFloat;
-			if(__php__("$v instanceof Anonymous"))  return TObject;
+			if(__php__("$v instanceof _hx_anonymous"))  return TObject;
 			if(__php__("$v instanceof __enumtype__"))  return TObject;
 			if(__php__("$v instanceof __classtype__"))  return TObject;
 

+ 3 - 21
std/php/Boot.hx

@@ -7,7 +7,7 @@ class Boot {
 	}
 
 	static public function __anonymous(?p : Dynamic) : Dynamic {
-		untyped __php__("$o = new Anonymous();
+		untyped __php__("$o = new _hx_anonymous();
 		if(is_array($p))
 			foreach($p as $k => $v)
 				$o->$k = $v;
@@ -388,33 +388,15 @@ class Boot {
 		return untyped __php__("is_array($o) ? count($o) : (is_string($o) ? strlen($o) : $o->length)");
 	}
 
-//	public static var __REGISTERED_CLASSES : Array<Dynamic>;
-
 	static function __init__() untyped {
 		__php__("//error_reporting(0);
 set_error_handler(array('php_Boot', '__error_handler'), E_ALL);
 set_exception_handler(array('php_Boot', '__exception_handler'));
 
-class Anonymous extends stdClass{
+class _hx_anonymous extends stdClass {
 	public function __call($m, $a) {
 		$v = $this->$m;
-/*
-		if(is_array($v) && is_a($v[0], '_lambda') && $v[0]->scope == null) {
-			$v[0]->scope =& $this;
-		}
-*/
-		/*
-		if(is_string($v) && substr($v, 0, 8) == chr(0).'lambda_') {
-			$nl = '__'.substr($v, 1).'__';
-			php_Boot::$__scopes[$nl]['scope'] =& $this;
-		}
-		*/
 		try {
-			/*
-			if(is_array($v) && is_a($v[0], '_lambda') && is_callable($v)) {
-				return call_user_func_array($v[1], $a);
-			}
-			*/
 			return call_user_func_array($v, $a);
 		} catch(Exception $e) {
 			throw new HException('Unable to call «'.$m.'»');
@@ -753,7 +735,7 @@ spl_autoload_register('__haxe_autoload')");
 					b += ')';
 				}
 				return b;
-			} else if(untyped __php__("$o instanceof Anonymous")) {
+			} else if(untyped __php__("$o instanceof _hx_anonymous")) {
 				var rfl = untyped __php__("new ReflectionObject($o)");
 				var b = "{\n";
 				s += "\t";

+ 19 - 6
std/php/PhpXml__.hx

@@ -75,6 +75,8 @@ class PhpXml__ {
 		build.addChild(createPCData(data));
 	}
 
+	static var xmlChecker = new EReg("\\s*(<\\?xml|<!DOCTYPE)", "mi");
+
 	public static function parse( str : String ) : PhpXml__ {
 		build = createDocument();
 		var xml_parser = untyped __call__("xml_parser_create");
@@ -84,15 +86,26 @@ class PhpXml__ {
 		untyped __call__("xml_parser_set_option", xml_parser, __php__("XML_OPTION_CASE_FOLDING"), 0);
 		untyped __call__("xml_parser_set_option", xml_parser, __php__("XML_OPTION_SKIP_WHITE"), 0);
 
-		if(untyped __call__("xml_parse", xml_parser, "<doc>"+str+"</doc>", true) != 1) {
+		var isComplete = xmlChecker.match(str);
+
+		if(!isComplete)
+			str = "<doc>"+str+"</doc>";
+
+		if(untyped __call__("xml_parse", xml_parser, str, true) != 1) {
 			throw "Xml parse error ("+untyped __call__("xml_error_string", xml_parser) + ") line #" + __call__("xml_get_current_line_number", xml_parser);
 		}
+
 		untyped __call__("xml_parser_free", xml_parser);
-		build = build._children[0];
-		build._parent = null;
-		build._nodeName = null;
-		build.nodeType = Document;
-		return build;
+
+		if(isComplete) {
+			return build;
+		} else {
+			build = build._children[0];
+			build._parent = null;
+			build._nodeName = null;
+			build.nodeType = Document;
+			return build;
+		}
 	}
 
 	private function new(){