Browse Source

php : added --php-prefix
php : fixed issue 409
php : fixed issue 444
php : fixed issue 445
php : fixed issue 446
php : fixed issue 455
php : fixed issue 463
php : fixed issue with ' in Xml.get()
php : applied optimization for loops in _hx_anonymous and Xml.parse

Franco Ponticelli 14 years ago
parent
commit
0f2fbcfcb9
11 changed files with 170 additions and 598 deletions
  1. 2 0
      common.ml
  2. 1 0
      doc/CHANGES.txt
  3. 137 17
      genphp.ml
  4. 5 0
      main.ml
  5. 19 10
      std/php/Boot.hx
  6. 0 98
      std/php/PhpDate__.hx
  7. 0 64
      std/php/PhpMath__.hx
  8. 0 405
      std/php/PhpXml__.hx
  9. 2 1
      std/php/_std/EReg.hx
  10. 1 1
      std/php/_std/Reflect.hx
  11. 3 2
      std/php/_std/Xml.hx

+ 2 - 0
common.ml

@@ -72,6 +72,7 @@ type context = {
 	mutable resources : (string,string) Hashtbl.t;
 	mutable resources : (string,string) Hashtbl.t;
 	mutable php_front : string option;
 	mutable php_front : string option;
 	mutable php_lib : string option;
 	mutable php_lib : string option;
+	mutable php_prefix : string option;
 	mutable swf_libs : (string * (unit -> Swf.swf) * (unit -> ((string list * string),As3hl.hl_class) Hashtbl.t)) list;
 	mutable swf_libs : (string * (unit -> Swf.swf) * (unit -> ((string list * string),As3hl.hl_class) Hashtbl.t)) list;
 	mutable js_gen : (unit -> unit) option;
 	mutable js_gen : (unit -> unit) option;
 	(* typing *)
 	(* typing *)
@@ -108,6 +109,7 @@ let create v =
 		php_lib = None;
 		php_lib = None;
 		swf_libs = [];
 		swf_libs = [];
 		js_namespace = None;
 		js_namespace = None;
+		php_prefix = None;
 		js_gen = None;
 		js_gen = None;
 		load_extern_type = [];
 		load_extern_type = [];
 		warning = (fun _ _ -> assert false);
 		warning = (fun _ _ -> assert false);

+ 1 - 0
doc/CHANGES.txt

@@ -37,6 +37,7 @@
 	neko : neko.Lib.serialize/unserialize now returns bytes
 	neko : neko.Lib.serialize/unserialize now returns bytes
 	neko : added sys.db package (crossplatform with -D spod_macro support)
 	neko : added sys.db package (crossplatform with -D spod_macro support)
 		spod_macro now uses wrappers for Bytes (require neko 1.8.2)
 		spod_macro now uses wrappers for Bytes (require neko 1.8.2)
+	php : added --php-prefix for prefixing generated files and class names
 
 
 2011-01-30: 2.07
 2011-01-30: 2.07
 	all : fixed completion support with --remap
 	all : fixed completion support with --remap

+ 137 - 17
genphp.ml

@@ -201,14 +201,28 @@ let is_string_expr e = is_string_type e.etype
 let spr ctx s = Buffer.add_string ctx.buf s
 let spr ctx s = Buffer.add_string ctx.buf s
 let print ctx = Printf.kprintf (fun s -> Buffer.add_string ctx.buf s)
 let print ctx = Printf.kprintf (fun s -> Buffer.add_string ctx.buf s)
 
 
+(*--php-prefix - added by skial bainn*)
+let prefix_class com name = 
+	match com.php_prefix with
+	| Some prefix_class (* when not (String.length name <= 2 || String.sub name 0 2 = "__") *) -> 
+		prefix_class ^ name
+	| _ ->
+		name
+
+let prefix_init_replace com code = 
+	let r = Str.regexp "php_Boot" in
+	Str.global_replace r ("php_" ^ (prefix_class com "Boot")) code
+
 let s_path ctx path isextern p =
 let s_path ctx path isextern p =
 	if isextern then begin
 	if isextern then begin
 		register_extern_required_path ctx path;
 		register_extern_required_path ctx path;
 		snd path
 		snd path
 	end else begin
 	end else begin
 		(match path with
 		(match path with
-		| ([],"List")			-> "HList"
-		| ([],name)				-> name
+		(*--php-prefix*)
+		| ([],"List")			-> (prefix_class ctx.com "HList")
+		(*--php-prefix*)
+		| ([],name)				-> (prefix_class ctx.com name)
 		| (pack,name) ->
 		| (pack,name) ->
 			(try
 			(try
 				(match Hashtbl.find ctx.imports name with
 				(match Hashtbl.find ctx.imports name with
@@ -218,7 +232,8 @@ let s_path ctx path isextern p =
 					if not (List.mem pack packs) then Hashtbl.replace ctx.imports name (pack :: packs))
 					if not (List.mem pack packs) then Hashtbl.replace ctx.imports name (pack :: packs))
 			with Not_found ->
 			with Not_found ->
 				Hashtbl.add ctx.imports name [pack]);
 				Hashtbl.add ctx.imports name [pack]);
-			String.concat "_" pack ^ "_" ^ name);
+			(*--php-prefix*)
+			String.concat "_" pack ^ "_" ^ (prefix_class ctx.com name))
 	end
 	end
 
 
 let s_path_haxe path =
 let s_path_haxe path =
@@ -283,9 +298,10 @@ let init com cwd path def_type =
 	let dir = if cwd <> "" then com.file :: (cwd :: fst path) else com.file :: fst path; in
 	let dir = if cwd <> "" then com.file :: (cwd :: fst path) else com.file :: fst path; in
 	create [] dir;
 	create [] dir;
 	let filename path =
 	let filename path =
-		(match path with
+		prefix_class com (match path with
 		| [], "List" -> "HList";
 		| [], "List" -> "HList";
 		| _, s -> s) in
 		| _, s -> s) in
+	(*--php-prefix*)
 	let ch = open_out_bin (String.concat "/" dir ^ "/" ^ (filename path) ^ (if def_type = 0 then ".class" else if def_type = 1 then ".enum"  else if def_type = 2 then ".interface" else ".extern") ^ ".php") in
 	let ch = open_out_bin (String.concat "/" dir ^ "/" ^ (filename path) ^ (if def_type = 0 then ".class" else if def_type = 1 then ".enum"  else if def_type = 2 then ".interface" else ".extern") ^ ".php") in
 	let imports = Hashtbl.create 0 in
 	let imports = Hashtbl.create 0 in
 	Hashtbl.add imports (snd path) [fst path];
 	Hashtbl.add imports (snd path) [fst path];
@@ -351,14 +367,14 @@ let inc_extern_path ctx path =
 	let pre = if ctx.cwd = "" then ctx.lib_path ^ "/" else "" in
 	let pre = if ctx.cwd = "" then ctx.lib_path ^ "/" else "" in
 	match path with
 	match path with
 		| ([],name) ->
 		| ([],name) ->
-		pre ^ (slashes (List.length (fst ctx.path))) ^ name ^ ".extern.php"
+		pre ^ (slashes (List.length (fst ctx.path))) ^ (prefix_class ctx.com name) ^ ".extern.php"
 		| (pack,name) ->
 		| (pack,name) ->
-		pre ^ (slashes (List.length (fst ctx.path))) ^ String.concat "/" pack ^ "/" ^ name ^ ".extern.php"
+		pre ^ (slashes (List.length (fst ctx.path))) ^ String.concat "/" pack ^ "/" ^ (prefix_class ctx.com name) ^ ".extern.php"
 
 
 let close ctx =
 let close ctx =
 	output_string ctx.ch "<?php\n";
 	output_string ctx.ch "<?php\n";
 	List.iter (fun path ->
 	List.iter (fun path ->
-		if path <> ctx.path then output_string ctx.ch ("require_once dirname(__FILE__).'/" ^ inc_extern_path ctx path ^ "';\n");
+		if path <> ctx.path then output_string ctx.ch ("require_once dirname(__FILE__).'/" ^ (inc_extern_path ctx path) ^ "';\n");
 	) (List.rev ctx.extern_required_paths);
 	) (List.rev ctx.extern_required_paths);
 	output_string ctx.ch "\n";
 	output_string ctx.ch "\n";
 	output_string ctx.ch (Buffer.contents ctx.buf);
 	output_string ctx.ch (Buffer.contents ctx.buf);
@@ -498,6 +514,12 @@ and gen_call ctx e el =
 		spr ctx "->";
 		spr ctx "->";
 		gen_value ctx f;
 		gen_value ctx f;
 		gen_array_args ctx el;
 		gen_array_args ctx el;
+	| TLocal { v_name = "__prefix__" }, [] ->
+		(match ctx.com.php_prefix with
+		| Some prefix -> 
+			print ctx "\"%s\"" prefix
+		| None ->
+			spr ctx "null")
 	| TLocal { v_name = "__var__" }, { eexpr = TConst (TString code) } :: el ->
 	| TLocal { v_name = "__var__" }, { eexpr = TConst (TString code) } :: el ->
 		print ctx "$%s" code;
 		print ctx "$%s" code;
 		gen_array_args ctx el;
 		gen_array_args ctx el;
@@ -510,14 +532,17 @@ and gen_call ctx e el =
 		concat ctx ", " (gen_value ctx) el;
 		concat ctx ", " (gen_value ctx) el;
 		spr ctx ")";
 		spr ctx ")";
 	| TLocal { v_name = "__php__" }, [{ eexpr = TConst (TString code) }] ->
 	| TLocal { v_name = "__php__" }, [{ eexpr = TConst (TString code) }] ->
-		spr ctx code
+		(*--php-prefix*)
+		spr ctx (prefix_init_replace ctx.com code)
 	| TLocal { v_name = "__instanceof__" },  [e1;{ eexpr = TConst (TString t) }] ->
 	| TLocal { v_name = "__instanceof__" },  [e1;{ eexpr = TConst (TString t) }] ->
 		gen_value ctx e1;
 		gen_value ctx e1;
 		print ctx " instanceof %s" t;
 		print ctx " instanceof %s" t;
 	| TLocal { v_name = "__physeq__" },  [e1;e2] ->
 	| TLocal { v_name = "__physeq__" },  [e1;e2] ->
+		spr ctx "(";
 		gen_value ctx e1;
 		gen_value ctx e1;
 		spr ctx " === ";
 		spr ctx " === ";
-		gen_value ctx e2
+		gen_value ctx e2;
+		spr ctx ")"
 	| TLocal _, []
 	| TLocal _, []
 	| TFunction _, []
 	| TFunction _, []
 	| TCall _, []
 	| TCall _, []
@@ -991,7 +1016,8 @@ and gen_expr ctx e =
 					gen_value ctx f;
 					gen_value ctx f;
 					print ctx ", \"%s\")" s;
 					print ctx ", \"%s\")" s;
 				| _ ->
 				| _ ->
-					gen_field_op ctx e1);
+					gen_field_op ctx e1;
+				);
 
 
 				spr ctx s_phop;
 				spr ctx s_phop;
 
 
@@ -1282,16 +1308,43 @@ and gen_expr ctx e =
 			restore_in_block ctx in_block;
 			restore_in_block ctx in_block;
 			gen_expr ctx (mk_block e));
 			gen_expr ctx (mk_block e));
 	| TUnop (op,Ast.Prefix,e) ->
 	| TUnop (op,Ast.Prefix,e) ->
-		spr ctx (Ast.s_unop op);
 		(match e.eexpr with
 		(match e.eexpr with
 		| TArray(te1, te2) ->
 		| TArray(te1, te2) ->
-			gen_value ctx te1;
-			spr ctx "[";
-			gen_value ctx te2;
-			spr ctx "]";
+			(match op with
+			| Increment ->
+				spr ctx "_hx_array_increment(";
+				gen_value ctx te1;
+				spr ctx ",";
+				gen_value ctx te2;
+				spr ctx ")";
+			| Decrement ->
+				spr ctx "_hx_array_decrement(";
+				gen_value ctx te1;
+				spr ctx ",";
+				gen_value ctx te2;
+				spr ctx ")";
+(*
+				let t = define_local ctx "»t" in
+				gen_value ctx te1;
+				print ctx "[%s = " t;
+				gen_value ctx te2;
+				spr ctx "] = ";
+				gen_value ctx te1;
+				print ctx "[%s]" t;
+				print ctx "[%s]" t;
+*)
+			| _ ->
+				spr ctx (Ast.s_unop op);
+				gen_value ctx te1;
+				spr ctx "[";
+				gen_value ctx te2;
+				spr ctx "]";
+			);
 		| TField (e1,s) ->
 		| TField (e1,s) ->
+			spr ctx (Ast.s_unop op);
 			gen_field_access ctx true e1 s
 			gen_field_access ctx true e1 s
 		| _ ->
 		| _ ->
+			spr ctx (Ast.s_unop op);
 			gen_value ctx e)
 			gen_value ctx e)
 	| TUnop (op,Ast.Postfix,e) ->
 	| TUnop (op,Ast.Postfix,e) ->
 		(match e.eexpr with
 		(match e.eexpr with
@@ -1564,6 +1617,34 @@ and inline_function ctx args hasthis e =
 
 
 		ctx.inline_methods <- ctx.inline_methods @ [block];
 		ctx.inline_methods <- ctx.inline_methods @ [block];
 		block.iname
 		block.iname
+
+and canbe_ternary_param e =
+	match e.eexpr with
+	| TTypeExpr _
+	| TConst _
+	| TLocal _
+	| TEnumField _
+	| TParenthesis _
+	| TObjectDecl _
+	| TArrayDecl _
+	| TCall _
+	| TUnop _
+	| TNew _
+	| TCast (_, _)
+	| TBlock [_] ->
+		true
+	| TIf (_,e,eelse) ->
+		cangen_ternary e eelse
+	| _ ->
+		false
+		
+and cangen_ternary e eelse =
+	match eelse with 
+	| Some other ->
+		(canbe_ternary_param e) && (canbe_ternary_param other)
+	| _ -> 
+		false
+		
 and gen_value ctx e =
 and gen_value ctx e =
 	match e.eexpr with
 	match e.eexpr with
 	| TTypeExpr _
 	| TTypeExpr _
@@ -1587,6 +1668,34 @@ and gen_value ctx e =
 	| TCast (e, _)
 	| TCast (e, _)
 	| TBlock [e] ->
 	| TBlock [e] ->
 		gen_value ctx e
 		gen_value ctx e
+	| TIf (cond,e,eelse) when (cangen_ternary e eelse) ->
+		spr ctx "(";
+		gen_value ctx cond;
+		spr ctx " ? ";
+		gen_value ctx e;
+		
+		(match eelse with
+		| Some e ->
+			spr ctx " : ";
+			gen_value ctx e
+		| _ ->());
+		spr ctx ")";
+	
+(*
+	| TIf (cond,e,eelse) ->
+		spr ctx "if";
+		gen_value ctx (parent cond);
+		spr ctx " ";
+		restore_in_block ctx in_block;
+		gen_expr ctx (mk_block e);
+		(match eelse with
+		| None -> ()
+		| Some e when e.eexpr = TConst(TNull) -> ()
+		| Some e ->
+			spr ctx " else ";
+			restore_in_block ctx in_block;
+			gen_expr ctx (mk_block e));
+*)
 	| TBlock _
 	| TBlock _
 	| TBreak
 	| TBreak
 	| TContinue
 	| TContinue
@@ -1779,11 +1888,21 @@ let generate_inline_method ctx c m =
 
 
 	(* blocks *)
 	(* blocks *)
 	if ctx.com.debug then begin
 	if ctx.com.debug then begin
+		(*--php-prefix*)
+		print_endline (s_path_haxe c.cl_path);
+		spr ctx "$»spos = $GLOBALS['%s']->length";
+		newline ctx;
+	end;
+(*
+	if ctx.com.debug then begin
+		(*--php-prefix*)
+		print_endline (s_path_haxe c.cl_path);
 		print ctx "\t$GLOBALS['%s']->push('%s:lambda_%d')" "%s" (s_path_haxe c.cl_path) m.iindex;
 		print ctx "\t$GLOBALS['%s']->push('%s:lambda_%d')" "%s" (s_path_haxe c.cl_path) m.iindex;
 		newline ctx;
 		newline ctx;
 		spr ctx "\t$»spos = $GLOBALS['%s']->length";
 		spr ctx "\t$»spos = $GLOBALS['%s']->length";
 		newline ctx;
 		newline ctx;
 	end;
 	end;
+*)
 	gen_expr ctx m.iexpr;
 	gen_expr ctx m.iexpr;
 	block();
 	block();
 	old();
 	old();
@@ -1855,7 +1974,7 @@ let generate_class ctx c =
 		print ctx "\tfunction __toString() { return $this->toString(); }";
 		print ctx "\tfunction __toString() { return $this->toString(); }";
 		newline ctx
 		newline ctx
 	end else if (not c.cl_interface) && (not c.cl_extern) then begin
 	end else if (not c.cl_interface) && (not c.cl_extern) then begin
-		print ctx "\tfunction __toString() { return '%s'; }" ((s_path_haxe c.cl_path)) ;
+		print ctx "\tfunction __toString() { return '%s'; }" (s_path_haxe c.cl_path) ;
 		newline ctx
 		newline ctx
 	end;
 	end;
 
 
@@ -1900,7 +2019,7 @@ let createmain com e =
 }";
 }";
 	newline ctx;
 	newline ctx;
 	newline ctx;
 	newline ctx;
-	spr ctx ("require_once dirname(__FILE__).'/" ^ ctx.lib_path ^ "/php/Boot.class.php';\n\n");
+	spr ctx ("require_once dirname(__FILE__).'/" ^ ctx.lib_path ^ "/php/" ^ (prefix_class com "Boot.class.php';\n\n"));
 	gen_value ctx e;
 	gen_value ctx e;
 	newline ctx;
 	newline ctx;
 	spr ctx "\n?>";
 	spr ctx "\n?>";
@@ -2064,6 +2183,7 @@ let generate com =
 				| Some e ->
 				| Some e ->
 					let ctx = init com php_lib_path c.cl_path 3 in
 					let ctx = init com php_lib_path c.cl_path 3 in
 					gen_expr ctx e;
 					gen_expr ctx e;
+					newline ctx;
 					close ctx;
 					close ctx;
 					);
 					);
 			end else
 			end else

+ 5 - 0
main.ml

@@ -495,6 +495,11 @@ try
  			if com.php_lib <> None then raise (Arg.Bad "Multiple --php-lib");
  			if com.php_lib <> None then raise (Arg.Bad "Multiple --php-lib");
  			com.php_lib <- Some f;
  			com.php_lib <- Some f;
  		),"<filename> : select the name for the php lib folder");
  		),"<filename> : select the name for the php lib folder");
+		("--php-prefix", Arg.String (fun f ->
+			if com.php_prefix <> None then raise (Arg.Bad "Multiple --php-prefix");
+			com.php_prefix <- Some f;
+			Common.define com "php_prefix";
+		),"<name> : prefix all classes with given name");
 		("--js-namespace",Arg.String (fun f ->
 		("--js-namespace",Arg.String (fun f ->
 			if com.js_namespace <> None then raise (Arg.Bad "Multiple --js-namespace");
 			if com.js_namespace <> None then raise (Arg.Bad "Multiple --js-namespace");
 			com.js_namespace <- Some f;
 			com.js_namespace <- Some f;

+ 19 - 10
std/php/Boot.hx

@@ -6,6 +6,7 @@ class Boot {
 	static var tpaths;
 	static var tpaths;
 	static var skip_constructor = false;
 	static var skip_constructor = false;
 	static function __init__() : Void {
 	static function __init__() : Void {
+		var _hx_class_prefix = untyped __prefix__();
 		untyped __php__("
 		untyped __php__("
 function _hx_add($a, $b) {
 function _hx_add($a, $b) {
 	if (!_hx_is_numeric($a) || !_hx_is_numeric($b)) {
 	if (!_hx_is_numeric($a) || !_hx_is_numeric($b)) {
@@ -17,8 +18,7 @@ function _hx_add($a, $b) {
 		
 		
 function _hx_anonymous($arr = array()) {
 function _hx_anonymous($arr = array()) {
 	$o = new _hx_anonymous();
 	$o = new _hx_anonymous();
-	reset($arr);
-	while(list($k, $v) = each($arr))
+	foreach($arr as $k => $v)
 		$o->$k = $v;
 		$o->$k = $v;
 	return $o;
 	return $o;
 }
 }
@@ -196,6 +196,9 @@ class _hx_array_iterator implements Iterator {
 
 
 function _hx_array_get($a, $pos) { return $a[$pos]; }
 function _hx_array_get($a, $pos) { return $a[$pos]; }
 
 
+function _hx_array_increment($a, $pos) { return $a[$pos] += 1; }
+function _hx_array_decrement($a, $pos) { return $a[$pos] -= 1; }
+
 function _hx_array_assign($a, $i, $v) { return $a[$i] = $v; }
 function _hx_array_assign($a, $i, $v) { return $a[$i] = $v; }
 
 
 class _hx_break_exception extends Exception {}
 class _hx_break_exception extends Exception {}
@@ -279,8 +282,8 @@ function _hx_explode2($s, $delimiter) {
 function _hx_field($o, $field) {
 function _hx_field($o, $field) {
 	if(_hx_has_field($o, $field)) {
 	if(_hx_has_field($o, $field)) {
 		if($o instanceof _hx_type) {
 		if($o instanceof _hx_type) {
-			if(is_callable(array($o->__tname__, $field))) {
-				return array($o->__tname__, $field);
+			if(is_callable($c = array($o->__tname__, $field)) && !property_exists($o->__tname__, $field)) {
+				return $c;
 			} else {
 			} else {
 				$name = $o->__tname__;
 				$name = $o->__tname__;
 				return eval('return '.$name.'::$'.$field.';');
 				return eval('return '.$name.'::$'.$field.';');
@@ -768,14 +771,20 @@ _hx_register_type(new _hx_enum('Void',     'Void'));
 $_hx_libdir = dirname(__FILE__) . '/..';
 $_hx_libdir = dirname(__FILE__) . '/..';
 $_hx_autload_cache_file = $_hx_libdir . '/../cache/haxe_autoload.php';
 $_hx_autload_cache_file = $_hx_libdir . '/../cache/haxe_autoload.php';
 if(!file_exists($_hx_autload_cache_file)) {
 if(!file_exists($_hx_autload_cache_file)) {
-	function _hx_build_paths($d, &$_hx_types_array, $pack) {
+	function _hx_build_paths($d, &$_hx_types_array, $pack, $prefix) {
 		$h = opendir($d);
 		$h = opendir($d);
 		while(false !== ($f = readdir($h))) {
 		while(false !== ($f = readdir($h))) {
 			$p = $d.'/'.$f;
 			$p = $d.'/'.$f;
 			if($f == '.' || $f == '..')
 			if($f == '.' || $f == '..')
 				continue;
 				continue;
-			if(is_file($p) && substr($f, -4) == '.php') {
+				if (is_file($p) && substr($f, -4) == '.php') {
 				$bn = basename($f, '.php');
 				$bn = basename($f, '.php');
+				if ($prefix)
+				{
+					if ($prefix != substr($bn, 0, $lenprefix = strlen($prefix)))
+						continue;
+					$bn = substr($bn, $lenprefix);
+				}
 				if(substr($bn, -6) == '.class') {
 				if(substr($bn, -6) == '.class') {
 					$bn = substr($bn, 0, -6);
 					$bn = substr($bn, 0, -6);
 					$t = 0;
 					$t = 0;
@@ -793,13 +802,13 @@ if(!file_exists($_hx_autload_cache_file)) {
 				$qname = ($bn == 'HList' && empty($pack)) ? 'List' : join(array_merge($pack, array($bn)), '.');
 				$qname = ($bn == 'HList' && empty($pack)) ? 'List' : join(array_merge($pack, array($bn)), '.');
 				$_hx_types_array[] = array(
 				$_hx_types_array[] = array(
 					'path' => $p,
 					'path' => $p,
-					'name' => $bn,
+					'name' => $prefix . $bn,
 					'type' => $t,
 					'type' => $t,
 					'qname' => $qname,
 					'qname' => $qname,
-					'phpname' => join(array_merge($pack, array($bn)), '_')
+					'phpname' => join(array_merge($pack, array($prefix . $bn)), '_')
 				);
 				);
 			} else if(is_dir($p))
 			} else if(is_dir($p))
-				_hx_build_paths($p, $_hx_types_array, array_merge($pack, array($f)));
+				_hx_build_paths($p, $_hx_types_array, array_merge($pack, array($f)), $prefix);
 		}
 		}
 		closedir($h);
 		closedir($h);
 	}
 	}
@@ -807,7 +816,7 @@ if(!file_exists($_hx_autload_cache_file)) {
 	$_hx_cache_content = '<?php\n\n';
 	$_hx_cache_content = '<?php\n\n';
 	$_hx_types_array = array();
 	$_hx_types_array = array();
 
 
-	_hx_build_paths($_hx_libdir, $_hx_types_array, array());
+	_hx_build_paths($_hx_libdir, $_hx_types_array, array(), $_hx_class_prefix);
 
 
 	for($i=0;$i<count($_hx_types_array);$i++) {
 	for($i=0;$i<count($_hx_types_array);$i++) {
 		$_hx_cache_content .= '_hx_register_type(new ';
 		$_hx_cache_content .= '_hx_register_type(new ';

+ 0 - 98
std/php/PhpDate__.hx

@@ -1,98 +0,0 @@
-/*
- * Copyright (c) 2005, 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 php;
-
-class PhpDate__ //implements Date
-{
-	static var __name__ = ["Date"];
-	private var __t : Float;
-
-	public function new(year : Int, month : Int, day : Int, hour : Int, min : Int, sec : Int ) {
-		__t = untyped __call__("mktime", hour, min, sec, month+1, day, year);
-	}
-
-	public function getTime() : Float {
-		return __t*1000;
-	}
-
-	public function getPhpTime() : Float {
-		return __t;
-	}
-
-	public function getFullYear() : Int {
-		return untyped __call__("intval", __call__("date", "Y", this.__t));
-	}
-
-	public function getMonth() : Int {
-		var m : Int = untyped __call__("intval", __call__("date", "n", this.__t));
-		return -1 + m;
-	}
-
-	public function getDate() : Int {
-		return untyped __call__("intval", __call__("date", "j", this.__t));
-	}
-
-	public function getHours() : Int {
-		return untyped __call__("intval", __call__("date", "G", this.__t));
-	}
-
-	public function getMinutes() : Int {
-		return untyped __call__("intval", __call__("date", "i", this.__t));
-	}
-
-	public function getSeconds() : Int {
-		return untyped __call__("intval", __call__("date", "s", this.__t));
-	}
-
-	public function getDay() : Int {
-		return untyped __call__("intval", __call__("date", "w", this.__t));
-	}
-
-	public function toString():String {
-		return untyped __call__("date", "Y-m-d H:i:s", this.__t);
-	}
-
-	public static function now() {
-		return fromPhpTime(untyped __call__("time"));
-	}
-
-	public static function fromPhpTime( t : Float ){
-		var d = new PhpDate__(2000,1,1,0,0,0);
-		d.__t = t;
-		return d;
-	}
-
-	public static function fromTime( t : Float ){
-		var d = new PhpDate__(2000,1,1,0,0,0);
-		d.__t = t/1000;
-		return d;
-	}
-
-	public static function fromString( s : String ) {
-		return fromPhpTime(untyped __call__("strtotime", s));
-	}
-}
-
-

+ 0 - 64
std/php/PhpMath__.hx

@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2005, 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 php;
-
-class PhpMath__
-{
-	public static var PI;
-	public static var NaN;
-	public static var POSITIVE_INFINITY;
-	public static var NEGATIVE_INFINITY;
-
-	public static function abs(v)      { return untyped __call__("abs", v); }
-	public static function min(a,b)    { return untyped __call__("min", a, b); }
-	public static function max(a,b)    { return untyped __call__("max", a, b); }
-	public static function sin(v)      { return untyped __call__("sin", v); }
-	public static function cos(v)      { return untyped __call__("cos", v); }
-	public static function atan2(y,x)  { return untyped __call__("atan2", y, x); }
-	public static function tan(v)      { return untyped __call__("tan", v); }
-	public static function exp(v)      { return untyped __call__("exp", v); }
-	public static function log(v)      { return untyped __call__("log", v); }
-	public static function sqrt(v)     { return untyped __call__("sqrt", v); }
-	public static function round(v)    { return untyped __call__("(int) floor", v + 0.5); }
-	public static function floor(v)    { return untyped __call__("(int) floor", v); }
-	public static function ceil(v)     { return untyped __call__("(int) ceil", v); }
-	public static function atan(v)     { return untyped __call__("atan", v); }
-	public static function asin(v)     { return untyped __call__("asin", v); }
-	public static function acos(v)     { return untyped __call__("acos", v); }
-	public static function pow(b,e)    { return untyped __call__("pow", b, e); }
-	public static function random()    { return untyped __call__("mt_rand") / __call__("mt_getrandmax"); }
-	public static function isNaN(f)    { return untyped __call__("is_nan", f); }
-	public static function isFinite(f) { return untyped __call__("is_finite", f); }
-
-	static function __init__() {
-	 	PI = untyped __php__("M_PI");
-	 	NaN = untyped __php__("acos(1.01)");
-	 	NEGATIVE_INFINITY = untyped __php__("log(0)");
-	 	POSITIVE_INFINITY = -NEGATIVE_INFINITY;
-	}
-
-}
-
-

+ 0 - 405
std/php/PhpXml__.hx

@@ -1,405 +0,0 @@
-/*
- * Copyright (c) 2005, 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 php;
-import Xml;
-
-class PhpXml__ {
-
-	public static var Element(default,null) : XmlType;
-	public static var PCData(default,null) : XmlType;
-	public static var CData(default,null) : XmlType;
-	public static var Comment(default,null) : XmlType;
-	public static var DocType(default,null) : XmlType;
-	public static var Prolog(default,null) : XmlType;
-	public static var Document(default,null) : XmlType;
-
-	public var nodeType(default,null) : XmlType;
-	public var nodeName(getNodeName,setNodeName) : String;
-	public var nodeValue(getNodeValue,setNodeValue) : String;
-	public var parent(getParent,null) : PhpXml__;
-
-	public var _nodeName : String;
-	public var _nodeValue : String;
-	public var _attributes : Hash<String>;
-	public var _children : Array<PhpXml__>;
-	public var _parent : PhpXml__;
-
-	private static var build : PhpXml__;
-	private static function __start_element_handler(parser : Dynamic, name : String, attribs : ArrayAccess<String>) {
-		var node = createElement(name);
-		untyped __php__("while(list($k, $v) = each($attribs)) $node->set($k, $v)");
-		build.addChild(node);
-		build = node;
-	}
-
-	private static function __end_element_handler(parser : Dynamic, name : String) {
-		build = build.getParent();
-	}
-
-	private static function __character_data_handler(parser : Dynamic, data : String) {
-		// TODO: this function can probably be simplified
-//		var lc : PhpXml__ = (build._children == null || build._children.length == 0) ? null : build._children[build._children.length-1];
-//		if(lc != null && Xml.PCData == lc.nodeType) {
-//			lc.nodeValue = lc.nodeValue + untyped __call__("htmlentities", data);
-//		} else
-		if((untyped __call__("strlen", data) == 1 && __call__("htmlentities", data) != data) || untyped __call__("htmlentities", data) == data) {
-			build.addChild(createPCData(untyped __call__("htmlentities", data)));
-		} else
-			build.addChild(createCData(data));
-	}
-
-	private static function __default_handler(parser : Dynamic, data : String) {
-		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");
-		untyped __call__("xml_set_element_handler", xml_parser, __start_element_handler, __end_element_handler);
-		untyped __call__("xml_set_character_data_handler", xml_parser, __character_data_handler);
-		untyped __call__("xml_set_default_handler", xml_parser, __default_handler);
-		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);
-
-		var isComplete = xmlChecker.match(str);
-
-		if(!isComplete)
-			str = "<doc>"+str+"</doc>";
-
-		if(1 != untyped __call__("xml_parse", xml_parser, str, true)) {
-			throw "Xml parse error ("+untyped __call__("xml_error_string", __call__("xml_get_error_code", xml_parser)) + ") line #" + __call__("xml_get_current_line_number", xml_parser);
-		}
-
-		untyped __call__("xml_parser_free", xml_parser);
-
-		if(isComplete) {
-			return build;
-		} else {
-			build = build._children[0];
-			build._parent = null;
-			build._nodeName = null;
-			build.nodeType = Document;
-			return build;
-		}
-	}
-
-	private function new() {
-	}
-
-	public static function createElement( name : String ) : PhpXml__ {
-		var r = new PhpXml__();
-		r.nodeType = Xml.Element;
-		r._children = new Array();
-		r._attributes = new Hash();
-		r.setNodeName( name );
-		return r;
-	}
-
-	public static function createPCData( data : String ) : PhpXml__ {
-		var r = new PhpXml__();
-		r.nodeType = Xml.PCData;
-		r.setNodeValue( data );
-		return r;
-	}
-
-	public static function createCData( data : String ) : PhpXml__ {
-		var r = new PhpXml__();
-		r.nodeType = Xml.CData;
-		r.setNodeValue( data );
-		return r;
-	}
-
-	public static function createComment( data : String ) : PhpXml__ {
-		var r = new PhpXml__();
-		r.nodeType = Xml.Comment;
-		r.setNodeValue( data );
-		return r;
-	}
-
-	public static function createDocType( data : String ) : PhpXml__ {
-		var r = new PhpXml__();
-		r.nodeType = Xml.DocType;
-		r.setNodeValue( data );
-		return r;
-	}
-
-	public static function createProlog( data : String ) : PhpXml__ {
-		var r = new PhpXml__();
-		r.nodeType = Xml.Prolog;
-		r.setNodeValue( data );
-		return r;
-	}
-
-	public static function createDocument() : PhpXml__ {
-		var r = new PhpXml__();
-		r.nodeType = Xml.Document;
-		r._children = new Array();
-		return r;
-	}
-
-	private function getNodeName() : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName;
-	}
-
-	private function setNodeName( n : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName = n;
-	}
-
-	private function getNodeValue() : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue;
-	}
-
-	private function setNodeValue( v : String ) : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue = v;
-	}
-
-	private function getParent() {
-		return _parent;
-	}
-
-	public function get( att : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.get( att );
-	}
-
-	public function set( att : String, value : String ) : Void {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		_attributes.set( att, untyped __call__("htmlspecialchars", value, __php__('ENT_COMPAT'), 'UTF-8'));
-	}
-
-	public function remove( att : String ) : Void{
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		_attributes.remove( att );
-	}
-
-	public function exists( att : String ) : Bool {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.exists( att );
-	}
-
-	public function attributes() : Iterator<String> {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.keys();
-	}
-
-	public function iterator() : Iterator<PhpXml__> {
-		if( _children == null ) throw "bad nodetype";
-		var me = this;
-		var it = null;
-		it = untyped {
-			cur: 0,
-			x: me._children,
-			hasNext : function(){
-				return it.cur < it.x.length;
-			},
-			next : function(){
-				return it.x[it.cur++];
-			}
-		}
-		return cast it;
-	}
-
-	public function elements() : Iterator<PhpXml__> {
-		if( _children == null ) throw "bad nodetype";
-		var me = this;
-		var it = null;
-		it =  untyped {
-			cur: 0,
-			x: me._children,
-			hasNext : function() {
-				var k = it.cur;
-				var l = it.x.length;
-				while( k < l ) {
-
-					if( it.x[k].nodeType == Xml.Element )
-						__php__("break");
-					k += 1;
-				}
-				it.cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = it.cur;
-				var l = it.x.length;
-				while( k < l ) {
-					var n = it.x[k];
-					k += 1;
-					if( n.nodeType == Xml.Element ) {
-						it.cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-		return cast it;
-	}
-
-	public function elementsNamed( name : String ) : Iterator<PhpXml__> {
-		if( _children == null ) throw "bad nodetype";
-
-		var me = this;
-		var it = null;
-		it =  untyped {
-			cur: 0,
-			x: me._children,
-			hasNext : function() {
-				var k = it.cur;
-				var l = it.x.length;
-				while( k < l ) {
-					var n = it.x[k];
-					if( n.nodeType == Xml.Element && n._nodeName == name )
-						__php__("break");
-					k++;
-				}
-				it.cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = it.cur;
-				var l = it.x.length;
-				while( k < l ) {
-					var n = it.x[k];
-					k++;
-					if( n.nodeType == Xml.Element && n._nodeName == name ) {
-						it.cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-		return cast it;
-	}
-
-	public function firstChild() : PhpXml__ {
-		if( _children == null ) throw "bad nodetype";
-		if( _children.length == 0 ) return null;
-		return _children[0];
-	}
-
-	public function firstElement() : PhpXml__ {
-		if( _children == null ) throw "bad nodetype";
-		var cur = 0;
-		var l = _children.length;
-		while( cur < l ) {
-			var n = _children[cur];
-			if( n.nodeType == Xml.Element )
-				return n;
-			cur++;
-		}
-		return null;
-	}
-
-	public function addChild( x : PhpXml__ ) : Void {
-		if( _children == null ) throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.push( x );
-	}
-
-	public function removeChild( x : PhpXml__ ) : Bool {
-		if( _children == null ) throw "bad nodetype";
-		var b = _children.remove( x );
-		if( b )
-			x._parent = null;
-		return b;
-	}
-
-	public function insertChild( x : PhpXml__, pos : Int ) : Void {
-		if( _children == null ) throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.insert( pos, x );
-	}
-
-	public function toString() {
-		if( nodeType == Xml.PCData )
-			return _nodeValue;
-
-		var s = "";
-
-		if( nodeType == Xml.Element ) {
-			s += "<";
-			s += _nodeName;
-			for( k in _attributes.keys() ){
-				s += " ";
-				s += k;
-				s += "=\""; // \"
-				s += _attributes.get(k);
-				s += "\""; // \"
-			}
-			if( _children.length == 0 ) {
-				s += "/>";
-				return s;
-			}
-			s += ">";
-		} else if( nodeType == Xml.CData )
-			return "<![CDATA["+_nodeValue+"]]>";
-		else if( nodeType == Xml.Comment )
-			return "<!--"+_nodeValue+"-->";
-		else if( nodeType == Xml.DocType )
-			return "<!DOCTYPE "+_nodeValue+">";
-		else if( nodeType == Xml.Prolog )
-			return "<?"+_nodeValue+"?>";
-		
-
-		for( x in iterator() )
-			s += x.toString();
-
-		if( nodeType == Xml.Element ) {
-			s += "</";
-			s += _nodeName;
-			s += ">";
-		}
-		return s;
-	}
-
-	static function __init__() : Void untyped {
-		PhpXml__.Element = "element";
-		PhpXml__.PCData = "pcdata";
-		PhpXml__.CData = "cdata";
-		PhpXml__.Comment = "comment";
-		PhpXml__.DocType = "doctype";
-		PhpXml__.Prolog = "prolog";
-		PhpXml__.Document = "document";
-	}
-
-}

+ 2 - 1
std/php/_std/EReg.hx

@@ -45,6 +45,7 @@
 
 
 	public function match( s : String ) : Bool {
 	public function match( s : String ) : Bool {
 		var p : Int = untyped __call__("preg_match", re, s, matches, __php__("PREG_OFFSET_CAPTURE"));
 		var p : Int = untyped __call__("preg_match", re, s, matches, __php__("PREG_OFFSET_CAPTURE"));
+		
 		if(p > 0)
 		if(p > 0)
 			last = s;
 			last = s;
 		else
 		else
@@ -53,7 +54,7 @@
 	}
 	}
 
 
 	public function matched( n : Int ) : String {
 	public function matched( n : Int ) : String {
-		if( n < 0 ) throw "EReg::matched";
+		if ( n < 0 ) throw "EReg::matched";
 		// we can't differenciate between optional groups at the end of a match
 		// we can't differenciate between optional groups at the end of a match
 		// that have not been matched and invalid groups
 		// that have not been matched and invalid groups
 		if( n >= untyped __call__("count", matches)) return null;
 		if( n >= untyped __call__("count", matches)) return null;

+ 1 - 1
std/php/_std/Reflect.hx

@@ -84,7 +84,7 @@
 	}
 	}
 
 
 	public static function copy<T>( o : T ) : T {
 	public static function copy<T>( o : T ) : T {
-		if(untyped __call__("is_string", o)) return o;
+		if (untyped __call__("is_string", o)) return o;
 		var o2 : Dynamic = {};
 		var o2 : Dynamic = {};
 		for( f in Reflect.fields(o) )
 		for( f in Reflect.fields(o) )
 			Reflect.setField(o2,f,Reflect.field(o,f));
 			Reflect.setField(o2,f,Reflect.field(o,f));

+ 3 - 2
std/php/_std/Xml.hx

@@ -51,7 +51,7 @@ enum XmlType {
 	private static var build : Xml;
 	private static var build : Xml;
 	private static function __start_element_handler(parser : Dynamic, name : String, attribs : ArrayAccess<String>) : Void {
 	private static function __start_element_handler(parser : Dynamic, name : String, attribs : ArrayAccess<String>) : Void {
 		var node = createElement(name);
 		var node = createElement(name);
-		untyped __php__("while(list($k, $v) = each($attribs)) $node->set($k, $v)");
+		untyped __php__("foreach($attribs as $k => $v) $node->set($k, $v)");
 		build.addChild(node);
 		build.addChild(node);
 		build = node;
 		build = node;
 	}
 	}
@@ -198,10 +198,11 @@ enum XmlType {
 		return _attributes.get( att );
 		return _attributes.get( att );
 	}
 	}
 
 
+	// TODO: check correct transform function
 	public function set( att : String, value : String ) : Void {
 	public function set( att : String, value : String ) : Void {
 		if( nodeType != Xml.Element )
 		if( nodeType != Xml.Element )
 			throw "bad nodeType";
 			throw "bad nodeType";
-		_attributes.set( att, untyped __call__("htmlspecialchars", value, __php__('ENT_COMPAT'), 'UTF-8'));
+		_attributes.set( att, untyped __call__("str_replace", "'", '&apos;', __call__("htmlspecialchars", value, __php__('ENT_COMPAT'), 'UTF-8')));
 	}
 	}
 
 
 	public function remove( att : String ) : Void{
 	public function remove( att : String ) : Void{