Browse Source

added s_type_path
genxml now use :real path instead of :native one

Nicolas Cannasse 15 years ago
parent
commit
124ba7b28d
8 changed files with 30 additions and 20 deletions
  1. 5 0
      ast.ml
  2. 6 5
      codegen.ml
  3. 2 0
      doc/CHANGES.txt
  4. 1 4
      genas3.ml
  5. 1 1
      genswf.ml
  6. 1 1
      genswf9.ml
  7. 11 3
      genxml.ml
  8. 3 6
      main.ml

+ 5 - 0
ast.ml

@@ -270,6 +270,11 @@ let punion p p2 =
 
 let s_type_path (p,s) = match p with [] -> s | _ -> String.concat "." p ^ "." ^ s
 
+let s_parse_path s = 
+	match List.rev (ExtString.String.nsplit s ".") with
+	| [] -> failwith "Invalid empty path"
+	| x :: l -> List.rev l, x
+
 let s_escape s =
 	let b = Buffer.create (String.length s) in
 	for i = 0 to (String.length s) - 1 do

+ 6 - 5
codegen.ml

@@ -351,14 +351,15 @@ let rec has_rtti c =
 let on_generate ctx t =
 	match t with
 	| TClassDecl c ->
+		let meta = ref (c.cl_meta()) in
 		List.iter (fun m ->
 			match m with
-			| ":native",[{ eexpr = TConst (TString name) }] ->
-				(match List.rev (ExtString.String.nsplit name ".") with
-				| [] -> assert false
-				| name :: path -> c.cl_path <- (List.rev path,name))
+			| ":native",[{ eexpr = TConst (TString name) } as e] ->				
+				meta := (":real",[{ e with eexpr = TConst (TString (s_type_path c.cl_path)) }]) :: !meta;
+				c.cl_meta <- (fun() -> !meta);
+				c.cl_path <- s_parse_path name;
 			| _ -> ()
-		) (c.cl_meta());
+		) (!meta);
 		if has_rtti c && not (PMap.mem "__rtti" c.cl_statics) then begin
 			let f = mk_field "__rtti" ctx.api.tstring in
 			let str = Genxml.gen_type_string ctx.com t in

+ 2 - 0
doc/CHANGES.txt

@@ -3,6 +3,8 @@
 	all : added macros, added --interp
 	all : removed 'here' special identifier
 	neko : fixed neko.Web.getParamsString() returning "null" instead of ""
+	flash9 : fixed issue with @:bind
+	flash9 : added some missing errors
 
 2010-08-14: 2.06
 	neko : change serializer to be able to handle instances of basic classes from other modules

+ 1 - 4
genas3.ml

@@ -451,10 +451,7 @@ and gen_expr ctx e =
 	| TEnumField (en,s) ->
 		print ctx "%s.%s" (s_path ctx true en.e_path e.epos) (s_ident s)
 	| TArray ({ eexpr = TLocal "__global__" },{ eexpr = TConst (TString s) }) ->
-		let path = (match List.rev (ExtString.String.nsplit s ".") with
-			| [] -> assert false
-			| x :: l -> List.rev l , x
-		) in
+		let path = Ast.s_parse_path s in
 		spr ctx (s_path ctx false path e.epos)
 	| TArray (e1,e2) ->
 		gen_value ctx e1;

+ 1 - 1
genswf.ml

@@ -750,7 +750,7 @@ let merge com file priority (h1,tags1) (h2,tags2) =
 		| TSetBgColor _ -> priority
 		| TExport el when !nframe = 0 && com.flash_version >= 9 ->
 			let el = List.filter (fun e ->
-				let path = (match List.rev (ExtString.String.nsplit e.exp_name ".") with [] -> assert false | name :: l -> List.rev l, name) in
+				let path = s_parse_path e.exp_name in
 				List.exists (fun t -> t_path t = path) com.types
 			) el in
 			classes := !classes @ List.map (fun e -> { f9_cid = Some e.exp_id; f9_classname = e.exp_name }) el;

+ 1 - 1
genswf9.ml

@@ -777,7 +777,7 @@ let gen_access ctx e (forset : 'a) : 'a access =
 				VCast (id,classify ctx e.etype)
 		)
 	| TArray ({ eexpr = TLocal "__global__" },{ eexpr = TConst (TString s) }) ->
-		let path = (match List.rev (ExtString.String.nsplit s ".") with [] -> assert false | x :: l -> List.rev l, x) in
+		let path = s_parse_path s in
 		let id = type_path ctx path in
 		if is_set forset then write ctx HGetGlobalScope;
 		VGlobal id

+ 11 - 3
genxml.ml

@@ -49,6 +49,14 @@ let gen_doc_opt d =
 let gen_arg_name (name,opt,_) =
 	(if opt then "?" else "") ^ name
 
+let cpath c =
+	let rec loop = function
+		| [] -> c.cl_path
+		| (":real",[{ eexpr = TConst (TString s) }]) :: _ -> s_parse_path s
+		| _ :: l -> loop l
+	in
+	loop (c.cl_meta())
+
 let rec follow_param t =
 	match t with
 	| TMono r ->
@@ -64,7 +72,7 @@ let rec gen_type t =
 	match t with
 	| TMono m -> (match !m with None -> tag "unknown" | Some t -> gen_type t)
 	| TEnum (e,params) -> node "e" [gen_path e.e_path e.e_private] (List.map gen_type params)
-	| TInst (c,params) -> node "c" [gen_path c.cl_path c.cl_private] (List.map gen_type params)
+	| TInst (c,params) -> node "c" [gen_path (cpath c) c.cl_private] (List.map gen_type params)
 	| TType (t,params) -> node "t" [gen_path t.t_path t.t_private] (List.map gen_type params)
 	| TFun (args,r) -> node "f" ["a",String.concat ":" (List.map gen_arg_name args)] (List.map gen_type (List.map (fun (_,opt,t) -> if opt then follow_param t else t) args @ [r]))
 	| TAnon a -> node "a" [] (pmap (fun f -> gen_field [] { f with cf_public = false }) a.a_fields)
@@ -108,7 +116,7 @@ let gen_type_params priv path params pos m =
 	gen_path path priv :: ("params", String.concat ":" (List.map fst params)) :: ("file",if pos == null_pos then "" else pos.pfile) :: (mpriv @ mpath)
 
 let gen_class_path name (c,pl) =
-	node name [("path",s_type_path c.cl_path)] (List.map gen_type pl)
+	node name [("path",s_type_path (cpath c))] (List.map gen_type pl)
 
 let rec exists f c =
 	PMap.exists f.cf_name c.cl_fields ||
@@ -139,7 +147,7 @@ let gen_type_decl com t =
 			| None -> []
 			| Some t -> [node "haxe_dynamic" [] [gen_type t]]
 		) in
-		node "class" (gen_type_params c.cl_private c.cl_path c.cl_types c.cl_pos m @ ext @ interf) (tree @ stats @ fields @ constr @ doc @ dynamic)
+		node "class" (gen_type_params c.cl_private (cpath c) c.cl_types c.cl_pos m @ ext @ interf) (tree @ stats @ fields @ constr @ doc @ dynamic)
 	| TEnumDecl e ->
 		let doc = gen_doc_opt e.e_doc in
 		node "enum" (gen_type_params e.e_private e.e_path e.e_types e.e_pos m) (pmap gen_constr e.e_constrs @ doc)

+ 3 - 6
main.ml

@@ -377,11 +377,8 @@ try
 			let lines = Std.input_list ch in
 			close_in ch;
 			excludes := (List.map (fun l ->
-				let len = String.length l in
-				let l = (if len > 0 && l.[len-1] = '\r' then String.sub l 0 (len - 1) else l) in
-				match List.rev (ExtString.String.nsplit l ".") with
-				| [] -> ([],"")
-				| x :: l -> (List.rev l,x)
+				let l = ExtString.String.strip l in
+				if l = "" then ([],"") else Ast.s_parse_path l
 			) lines) @ !excludes;
 		),"<filename> : don't generate code for classes listed in this file");
 		("-prompt", Arg.Unit (fun() -> prompt := true),": prompt on error");
@@ -504,7 +501,7 @@ try
 				com.platform <- Flash9;
 				add_std "flash9";
 			end else
-				add_std "flash";			
+				add_std "flash";
 			"swf"
 		| Neko -> add_std "neko"; "n"
 		| Js -> add_std "js"; "js"