Selaa lähdekoodia

[java/cs] Added Xml implementation. Fixes Issue #912

Caue Waneck 13 vuotta sitten
vanhempi
commit
9d865d91b7
4 muutettua tiedostoa jossa 76 lisäystä ja 147 poistoa
  1. 43 9
      gencommon.ml
  2. 3 1
      std/StringTools.hx
  3. 1 0
      std/haxe/xml/Parser.hx
  4. 29 137
      std/java/_std/Xml.hx

+ 43 - 9
gencommon.ml

@@ -840,13 +840,11 @@ let run_filters gen =
     let rec loop processed not_processed =
     let rec loop processed not_processed =
       match not_processed with
       match not_processed with
         | hd :: tl ->
         | hd :: tl ->
-          trace ("type " ^ (snd (t_path hd)));
           let new_hd = filter#run_f hd in
           let new_hd = filter#run_f hd in
           
           
           let added_types_new = !added_types in
           let added_types_new = !added_types in
           added_types := [];
           added_types := [];
           let added_types = List.map (fun (t,p) -> 
           let added_types = List.map (fun (t,p) -> 
-            trace ("added type " ^ (snd (t_path t)));
             get (filter#run_from p t)
             get (filter#run_from p t)
           ) added_types_new in
           ) added_types_new in
           
           
@@ -2618,8 +2616,6 @@ struct
         let captured_ht, tparams = get_captured fexpr in
         let captured_ht, tparams = get_captured fexpr in
         let captured = Hashtbl.fold (fun _ e acc -> e :: acc) captured_ht [] in
         let captured = Hashtbl.fold (fun _ e acc -> e :: acc) captured_ht [] in
         
         
-        List.iter (fun e -> trace (debug_expr e)) captured;
-        
         (*let cltypes = List.map (fun cl -> (snd cl.cl_path, TInst(map_param cl, []) )) tparams in*)
         (*let cltypes = List.map (fun cl -> (snd cl.cl_path, TInst(map_param cl, []) )) tparams in*)
         let cltypes = List.map (fun cl -> (snd cl.cl_path, TInst(cl, []) )) tparams in
         let cltypes = List.map (fun cl -> (snd cl.cl_path, TInst(cl, []) )) tparams in
         
         
@@ -5106,6 +5102,16 @@ struct
             let e1 = problematic_expression_unwrap false e1 (expr_kind e1) in
             let e1 = problematic_expression_unwrap false e1 (expr_kind e1) in
             let e2 = problematic_expression_unwrap false e2 (expr_kind e2) in
             let e2 = problematic_expression_unwrap false e2 (expr_kind e2) in
             { expr with eexpr = TArray(e1, e2) }
             { expr with eexpr = TArray(e1, e2) }
+          | KExprWithStatement, TCall(( { eexpr = TField (ef_left, f) } as ef ), eargs) ->
+            { expr with eexpr = TCall(
+              { ef with eexpr = TField(problematic_expression_unwrap false ef_left (expr_kind ef_left), f) },
+              List.map (fun e -> problematic_expression_unwrap false e (expr_kind e)) eargs)
+            }
+          | KExprWithStatement, TCall(( { eexpr = TEnumField _ } as ef ), eargs) ->
+            { expr with eexpr = TCall(
+              ef,
+              List.map (fun e -> problematic_expression_unwrap false e (expr_kind e)) eargs)
+            }
           | KExprWithStatement, _ -> Type.map_expr (fun e -> problematic_expression_unwrap false e (expr_kind e)) expr
           | KExprWithStatement, _ -> Type.map_expr (fun e -> problematic_expression_unwrap false e (expr_kind e)) expr
       in
       in
       problematic_expression_unwrap true expr e_type
       problematic_expression_unwrap true expr e_type
@@ -5127,9 +5133,9 @@ struct
                     | Some { eexpr = TConst(TNull) } (* no op *) ->
                     | Some { eexpr = TConst(TNull) } (* no op *) ->
                       ()
                       ()
                     | Some e -> 
                     | Some e -> 
-                      if has_problematic_expressions (get_kinds e) then 
+                      if has_problematic_expressions (get_kinds e) then begin
                         process_statement e
                         process_statement e
-                      else
+                      end else
                         new_block := (traverse e) :: !new_block
                         new_block := (traverse e) :: !new_block
                     | None ->
                     | None ->
                     (
                     (
@@ -5138,9 +5144,9 @@ struct
                         match !acc with
                         match !acc with
                           | hd :: tl ->
                           | hd :: tl ->
                             acc := tl;
                             acc := tl;
-                            if has_problematic_expressions (hd :: tl) then 
+                            if has_problematic_expressions (hd :: tl) then begin
                               problematic_expression_unwrap add_statement e hd
                               problematic_expression_unwrap add_statement e hd
-                            else
+                            end else
                               e
                               e
                           | [] -> assert false
                           | [] -> assert false
                       ) e in
                       ) e in
@@ -8086,7 +8092,35 @@ struct
           (match op with
           (match op with
             | Ast.OpAssign
             | Ast.OpAssign
             | Ast.OpAssignOp _ ->
             | Ast.OpAssignOp _ ->
-              Type.map_expr run e (* casts are already dealt with normal CastDetection module *)
+              (match e1_t, e2_t with
+                | Some t1, Some t2 ->
+                  (match op with
+                    | Ast.OpAssign -> 
+                      { e with eexpr = TBinop( op, run e1, handle_wrap ( handle_unwrap t2 (run e2) ) t1 ) }
+                    | Ast.OpAssignOp op ->
+                      (match e1.eexpr with
+                        | TLocal _ ->
+                          { e with eexpr = TBinop( Ast.OpAssign, e1, handle_wrap { e with eexpr = TBinop (op, handle_unwrap t1 e1, handle_unwrap t2 (run e2) ) } t1 ) }
+                        | _ ->
+                          let v, e1, evars = match e1.eexpr with
+                            | TField(ef, f) ->
+                              let v = mk_temp gen "nullbinop" ef.etype in
+                              v, { e1 with eexpr = TField(mk_local v ef.epos, f) }, ef
+                            | _ -> 
+                              let v = mk_temp gen "nullbinop" e1.etype in
+                              v, mk_local v e1.epos, e1
+                          in
+                          { e with eexpr = TBlock([
+                            { eexpr = TVars([v, Some evars ]); etype = gen.gcon.basic.tvoid; epos = e.epos };
+                            { e with eexpr = TBinop( Ast.OpAssign, e1, handle_wrap { e with eexpr = TBinop (op, handle_unwrap t1 e1, handle_unwrap t2 (run e2) ) } t1 ) }
+                          ]) }
+                      )
+                    | _ -> assert false
+                  )
+                  
+                | _ ->
+                  Type.map_expr run e (* casts are already dealt with normal CastDetection module *)
+              )
             | Ast.OpEq | Ast.OpNotEq when not handle_opeq ->
             | Ast.OpEq | Ast.OpNotEq when not handle_opeq ->
               Type.map_expr run e
               Type.map_expr run e
             | _ ->
             | _ ->

+ 3 - 1
std/StringTools.hx

@@ -293,7 +293,7 @@ class StringTools {
 		#elseif flash
 		#elseif flash
 		return s["cca"](index);
 		return s["cca"](index);
 		#elseif java
 		#elseif java
-		return s.charCodeAt(index);
+		return cast s.charCodeAt(index);
 		#elseif cs
 		#elseif cs
 		if (cast(index, UInt) >= s.length)
 		if (cast(index, UInt) >= s.length)
 			return 0;
 			return 0;
@@ -324,6 +324,8 @@ class StringTools {
 		return c == null;
 		return c == null;
 		#elseif cs
 		#elseif cs
 		return c == 0;
 		return c == 0;
+		#elseif java
+		return c == 0;
 		#else
 		#else
 		return false;
 		return false;
 		#end
 		#end

+ 1 - 0
std/haxe/xml/Parser.hx

@@ -35,6 +35,7 @@ class Parser
 	
 	
 	static function doParse(str:String, ?p:Int = 0, ?parent:Xml):Int
 	static function doParse(str:String, ?p:Int = 0, ?parent:Xml):Int
 	{
 	{
+		var p:Int = p;
 		var xml:Xml = null;
 		var xml:Xml = null;
 		var state = S.BEGIN;
 		var state = S.BEGIN;
 		var next = S.BEGIN;
 		var next = S.BEGIN;

+ 29 - 137
std/java/_std/Xml.hx

@@ -43,20 +43,6 @@ enum XmlType {
 	public static var Prolog(default,null) : XmlType;
 	public static var Prolog(default,null) : XmlType;
 	public static var Document(default,null) : XmlType;
 	public static var Document(default,null) : XmlType;
 
 
-	static var enode = ~/^<([a-zA-Z0-9:_-]+)/;
-	static var ecdata = ~/^<!\[CDATA\[/i;
-	static var edoctype = ~/^<!DOCTYPE /i;
-	static var eend = ~/^<\/([a-zA-Z0-9:_-]+)>/;
-	static var epcdata = ~/^[^<]+/;
-	static var ecomment = ~/^<!--/;
-	static var eprolog = ~/^<\?[^\?]+\?>/;
-
-	static var eattribute = ~/^\s*([a-zA-Z0-9:_-]+)\s*=\s*(["'])([^$2]*?)$2/; //"
-	static var eclose = ~/^[ \r\n\t]*(>|(\/>))/;
-	static var ecdata_end = ~/\]\]>/;
-	static var edoctype_elt = ~/[\[|\]>]/;
-	static var ecomment_end = ~/-->/;
-
 	public var nodeType(default,null) : XmlType;
 	public var nodeType(default,null) : XmlType;
 	public var nodeName(getNodeName,setNodeName) : String;
 	public var nodeName(getNodeName,setNodeName) : String;
 	public var nodeValue(getNodeValue,setNodeValue) : String;
 	public var nodeValue(getNodeValue,setNodeValue) : String;
@@ -69,103 +55,7 @@ enum XmlType {
 	var _parent : Xml;
 	var _parent : Xml;
 
 
 	public static function parse( str : String ) : Xml {
 	public static function parse( str : String ) : Xml {
-		var rules = [enode,epcdata,eend,ecdata,edoctype,ecomment,eprolog];
-		var nrules = rules.length;
-		var current = Xml.createDocument();
-
-		var stack = new List();
-		while( str.length > 0 ) {
-			var i = 0;
-			while( i < nrules ) {
-				var r = rules[i];
-				if( r.match(str) ) {
-					switch( i ) {
-					case 0: // Node
-						var x = Xml.createElement(r.matched(1));
-						current.addChild(x);
-						str = r.matchedRight();
-						while( eattribute.match(str) ) {
-							x.set(eattribute.matched(1),eattribute.matched(3));
-							str = eattribute.matchedRight();
-						}
-						if( !eclose.match(str) ) {
-							i = nrules;
-							break;
-						}
-						if( eclose.matched(1) == ">" ) {
-							stack.push(current);
-							current = x;
-						}
-						str = eclose.matchedRight();
-					case 1: // PCData
-						var x = Xml.createPCData(r.matched(0));
-						current.addChild(x);
-						str = r.matchedRight();
-					case 2: // End Node
-						untyped if( current._children != null && current._children.length == 0 ) {
-							var e = Xml.createPCData("");
-							current.addChild(e);
-						}
-						untyped if( r.matched(1) != current._nodeName || stack.isEmpty() ) {
-							i = nrules;
-							break;
-						}
-						current = stack.pop();
-						str = r.matchedRight();
-					case 3: // CData
-						str = r.matchedRight();
-						if( !ecdata_end.match(str) )
-							throw "End of CDATA section not found";
-						var x = Xml.createCData(ecdata_end.matchedLeft());
-						current.addChild(x);
-						str = ecdata_end.matchedRight();
-					case 4: // DocType
-						var pos = 0;
-						var count = 0;
-						var old = str;
-						while( true ) {
-							if( !edoctype_elt.match(str) )
-								throw "End of DOCTYPE section not found";
-							var p = edoctype_elt.matchedPos();
-							pos += p.pos + p.len;
-							str = edoctype_elt.matchedRight();
-							switch( edoctype_elt.matched(0) ) {
-							case "[": count++;
-							case "]": count--; if( count < 0 ) throw "Invalid ] found in DOCTYPE declaration";
-							default:
-								if( count == 0 )
-									break;
-							}
-						}
-						var x = Xml.createDocType(old.substr(10,pos-11));
-						current.addChild(x);
-					case 5: // Comment
-						if( !ecomment_end.match(str) )
-							throw "Unclosed Comment";
-						var p = ecomment_end.matchedPos();
-						var x = Xml.createComment(str.substr(4,p.pos+p.len-7));
-						current.addChild(x);
-						str = ecomment_end.matchedRight();
-					case 6: // Prolog
-						var prolog = r.matched(0);
-						var x = Xml.createProlog(prolog.substr(2,prolog.length - 4));
-						current.addChild(x);
-						str = r.matchedRight();
-					}
-					break;
-				}
-				i += 1;
-			}
-			if( i == nrules ) {
-				if( str.length > 10 )
-					throw ("Xml parse error : Unexpected "+str.substr(0,10)+"...");
-				else
-					throw ("Xml parse error : Unexpected "+str);
-			}
-		}
-		if( !stack.isEmpty() )
-			throw "Xml parse error : Unclosed "+stack.last().nodeName;
-		untyped return current;
+		return haxe.xml.Parser.parse(str);
 	}
 	}
 
 
 	private function new() : Void {
 	private function new() : Void {
@@ -281,43 +171,43 @@ enum XmlType {
 	}
 	}
 
 
 	public function iterator() : Iterator<Xml> {
 	public function iterator() : Iterator<Xml> {
-		if( _children == null ) throw "bad nodetype";
-		return untyped {
-			cur: 0,
-			x: this._children,
+		if ( _children == null ) throw "bad nodetype";
+		var cur = 0;
+		var x = this._children;
+		return {
 			hasNext : function(){
 			hasNext : function(){
-				return __this__.cur < __this__.x.length;
+				return cur < x.length;
 			},
 			},
 			next : function(){
 			next : function(){
-				return __this__.x[__this__.cur++];
+				return x[cur++];
 			}
 			}
 		}
 		}
 	}
 	}
 
 
 	public function elements() : Iterator<Xml> {
 	public function elements() : Iterator<Xml> {
-		if( _children == null ) throw "bad nodetype";
+		if ( _children == null ) throw "bad nodetype";
+		var cur = 0;
+		var x = _children;
 		return untyped {
 		return untyped {
-			cur: 0,
-			x: this._children,
 			hasNext : function() {
 			hasNext : function() {
-				var k = __this__.cur;
-				var l = __this__.x.length;
+				var k = cur;
+				var l = x.length;
 				while( k < l ) {
 				while( k < l ) {
-					if( __this__.x[k].nodeType == Xml.Element )
+					if( x[k].nodeType == Xml.Element )
 						break;
 						break;
 					k += 1;
 					k += 1;
 				}
 				}
-				__this__.cur = k;
+				cur = k;
 				return k < l;
 				return k < l;
 			},
 			},
 			next : function() {
 			next : function() {
-				var k = __this__.cur;
-				var l = __this__.x.length;
+				var k = cur;
+				var l = x.length;
 				while( k < l ) {
 				while( k < l ) {
-					var n = __this__.x[k];
+					var n = x[k];
 					k += 1;
 					k += 1;
 					if( n.nodeType == Xml.Element ) {
 					if( n.nodeType == Xml.Element ) {
-						__this__.cur = k;
+						cur = k;
 						return n;
 						return n;
 					}
 					}
 				}
 				}
@@ -327,30 +217,32 @@ enum XmlType {
 	}
 	}
 
 
 	public function elementsNamed( name : String ) : Iterator<Xml> {
 	public function elementsNamed( name : String ) : Iterator<Xml> {
-		if( _children == null ) throw "bad nodetype";
+		if ( _children == null ) throw "bad nodetype";
+		var x = _children;
+		var cur = 0;
 		return untyped {
 		return untyped {
 			cur: 0,
 			cur: 0,
 			x: this._children,
 			x: this._children,
 			hasNext : function() {
 			hasNext : function() {
-				var k = __this__.cur;
-				var l = __this__.x.length;
+				var k = cur;
+				var l = x.length;
 				while( k < l ) {
 				while( k < l ) {
-					var n = __this__.x[k];
+					var n = x[k];
 					if( n.nodeType == Xml.Element && n._nodeName == name )
 					if( n.nodeType == Xml.Element && n._nodeName == name )
 						break;
 						break;
 					k++;
 					k++;
 				}
 				}
-				__this__.cur = k;
+				cur = k;
 				return k < l;
 				return k < l;
 			},
 			},
 			next : function() {
 			next : function() {
-				var k = __this__.cur;
-				var l = __this__.x.length;
+				var k = cur;
+				var l = x.length;
 				while( k < l ) {
 				while( k < l ) {
-					var n = __this__.x[k];
+					var n = x[k];
 					k++;
 					k++;
 					if( n.nodeType == Xml.Element && n._nodeName == name ) {
 					if( n.nodeType == Xml.Element && n._nodeName == name ) {
-						__this__.cur = k;
+						cur = k;
 						return n;
 						return n;
 					}
 					}
 				}
 				}