2
0
Эх сурвалжийг харах

added @:fakeEnum (fixed issue #276)

Nicolas Cannasse 14 жил өмнө
parent
commit
9405ae4b5d
35 өөрчлөгдсөн 74 нэмэгдсэн , 50 устгасан
  1. 1 1
      doc/extract.hxml
  2. 11 2
      genas3.ml
  3. 5 2
      genswf.ml
  4. 21 13
      genswf9.ml
  5. 1 1
      std/flash9/display/ActionScriptVersion.hx
  6. 1 1
      std/flash9/display/BlendMode.hx
  7. 1 1
      std/flash9/display/CapsStyle.hx
  8. 1 1
      std/flash9/display/ColorCorrection.hx
  9. 1 1
      std/flash9/display/ColorCorrectionSupport.hx
  10. 1 1
      std/flash9/display/GradientType.hx
  11. 1 1
      std/flash9/display/GraphicsPathWinding.hx
  12. 1 1
      std/flash9/display/InterpolationMethod.hx
  13. 1 1
      std/flash9/display/JointStyle.hx
  14. 1 1
      std/flash9/display/LineScaleMode.hx
  15. 1 1
      std/flash9/display/SWFVersion.hx
  16. 1 1
      std/flash9/display/ShaderPrecision.hx
  17. 1 1
      std/flash9/display/SpreadMethod.hx
  18. 1 1
      std/flash9/display/StageAlign.hx
  19. 1 1
      std/flash9/display/StageDisplayState.hx
  20. 1 1
      std/flash9/display/StageQuality.hx
  21. 1 1
      std/flash9/display/StageScaleMode.hx
  22. 1 1
      std/flash9/display/TriangleCulling.hx
  23. 1 1
      std/flash9/events/EventPhase.hx
  24. 1 1
      std/flash9/geom/Orientation3D.hx
  25. 1 1
      std/flash9/media/MicrophoneEnhancedMode.hx
  26. 1 1
      std/flash9/media/SoundCodec.hx
  27. 1 1
      std/flash9/net/NetStreamAppendBytesAction.hx
  28. 1 1
      std/flash9/text/AntiAliasType.hx
  29. 1 1
      std/flash9/text/GridFitType.hx
  30. 1 1
      std/flash9/text/TextFieldAutoSize.hx
  31. 1 1
      std/flash9/text/TextFieldType.hx
  32. 1 1
      std/flash9/text/TextFormatAlign.hx
  33. 1 1
      std/flash9/text/TextFormatDisplay.hx
  34. 1 1
      std/flash9/utils/Endian.hx
  35. 6 2
      typer.ml

+ 1 - 1
doc/extract.hxml

@@ -1,6 +1,6 @@
 -debug
 -swf-lib library102.swf
 -swf9 test.swf
--swf-version 10
+-swf-version 10.2
 --macro patchTypes("../doc/extract.patch")
 --gen-hx-classes

+ 11 - 2
genas3.ml

@@ -200,8 +200,17 @@ let rec type_str ctx t p =
 		if e.e_extern then (match e.e_path with
 			| [], "Void" -> "void"
 			| [], "Bool" -> "Boolean"
-			| "flash" :: _ , _ -> "String"
-			| _ -> "Object"
+			| _ -> 
+				let rec loop = function
+					| [] -> "Object"
+					| (":fakeEnum",[Ast.EConst (Ast.Type n),_],_) :: _ ->
+						(match n with
+						| "Int" -> "int"
+						| "UInt" -> "uint"
+						| _ -> n)
+					| _ :: l -> loop l
+				in
+				loop e.e_meta
 		) else
 			s_path ctx true e.e_path p
 	| TInst ({ cl_path = ["flash"],"Vector" },[pt]) ->

+ 5 - 2
genswf.ml

@@ -378,11 +378,14 @@ let build_class com c file =
 		(*
 			If the class only contains static String constants, make it an enum
 		*)
+		let real_type = ref "" in
 		let rec loop = function
 			| [] -> []
 			| f :: l ->
 				match f.cff_kind with
-				| FVar (Some (CTPath { tpackage = []; tname = "String" | "Int" | "UInt" }),None) when List.mem AStatic f.cff_access -> (f.cff_name,None,[],[],pos) :: loop l
+				| FVar (Some (CTPath { tpackage = []; tname = ("String" | "Int" | "UInt") as tname }),None) when List.mem AStatic f.cff_access ->
+					if !real_type = "" then real_type := tname else if !real_type <> tname then raise Exit;
+					(f.cff_name,None,[],[],pos) :: loop l
 				| FFun (_,{ f_args = [] }) when f.cff_name = "new" -> loop l
 				| _ -> raise Exit
 		in
@@ -398,7 +401,7 @@ let build_class com c file =
 			d_name = path.tname;
 			d_doc = None;
 			d_params = [];
-			d_meta = [];
+			d_meta = [(":fakeEnum",[EConst (Type !real_type),pos],pos)];
 			d_flags = [EExtern];
 			d_data = constr;
 		} in

+ 21 - 13
genswf9.ml

@@ -159,10 +159,6 @@ let type_path ctx path =
 	let pack, name = real_path path in
 	HMPath (pack,name)
 
-let is_int_enum = function
-	| "ActionScriptVersion" | "SWFVersion" | "EventPhase" | "KeyLocation" | "XmlNodeType" -> true
-	| _ -> false
-
 let rec follow_basic t =
 	match t with
 	| TMono r ->
@@ -189,8 +185,6 @@ let rec follow_basic t =
 
 let rec type_id ctx t =
 	match follow_basic t with
-	| TEnum ({ e_path = path; e_extern = false },_) ->
-		type_path ctx path
 	| TInst ({ cl_path = ["haxe"],"Int32" },_) ->
 		type_path ctx ([],"Int")
 	| TInst ({ cl_path = ["flash"],"Vector" } as c,pl) ->
@@ -207,14 +201,17 @@ let rec type_id ctx t =
 			type_path ctx c.cl_path)
 	| TFun _ ->
 		type_path ctx ([],"Function")
-	| TEnum ({ e_path = ([],"Class") as path },_)
-	| TEnum ({ e_path = ([],"Bool") as path },_)
 	| TType ({ t_path = ([],"UInt") as path },_) ->
 		type_path ctx path
-	| TEnum ({ e_path = ("flash" :: _,name); e_extern = true },_) ->
-		HMPath ([],if is_int_enum name then "int" else "String")
 	| TEnum ({ e_path = [],"XmlType"; e_extern = true },_) ->
 		HMPath ([],"String")
+	| TEnum (e,_) ->
+		let rec loop = function
+			| [] -> type_path ctx e.e_path
+			| (":fakeEnum",[Ast.EConst (Ast.Type n),_],_) :: _ -> type_path ctx ([],n)
+			| _ :: l -> loop l
+		in
+		loop e.e_meta
 	| _ ->
 		HMPath ([],"Object")
 
@@ -236,9 +233,20 @@ let classify ctx t =
 		KFloat
 	| TEnum ({ e_path = [],"Bool" },_) ->
 		KBool
-	| TEnum ({ e_extern = true; e_path = "flash" :: _ , name },[]) ->
-		if is_int_enum name then KInt else KType (HMPath ([],"String"))
-	| TEnum _
+	| TEnum ({ e_path = [],"XmlType"; e_extern = true },_) ->
+		KType (HMPath ([],"String"))
+	| TEnum (e,_) ->
+		let rec loop = function
+			| [] -> KType (type_id ctx t)
+			| (":fakeEnum",[Ast.EConst (Type n),_],_) :: _ ->				
+				(match n with
+				| "Int" -> KInt
+				| "UInt" -> KUInt
+				| "String" -> KType (HMPath ([],"String"))
+				| _ -> assert false)
+			| _ :: l -> loop l
+		in
+		loop e.e_meta
 	| TInst _ ->
 		KType (type_id ctx t)
 	| TType ({ t_path = [],"UInt" },_) ->

+ 1 - 1
std/flash9/display/ActionScriptVersion.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum ActionScriptVersion {
+@:fakeEnum(UInt) extern enum ActionScriptVersion {
 	ACTIONSCRIPT2;
 	ACTIONSCRIPT3;
 }

+ 1 - 1
std/flash9/display/BlendMode.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum BlendMode {
+@:fakeEnum(String) extern enum BlendMode {
 	ADD;
 	ALPHA;
 	DARKEN;

+ 1 - 1
std/flash9/display/CapsStyle.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum CapsStyle {
+@:fakeEnum(String) extern enum CapsStyle {
 	NONE;
 	ROUND;
 	SQUARE;

+ 1 - 1
std/flash9/display/ColorCorrection.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum ColorCorrection {
+@:fakeEnum(String) extern enum ColorCorrection {
 	DEFAULT;
 	OFF;
 	ON;

+ 1 - 1
std/flash9/display/ColorCorrectionSupport.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum ColorCorrectionSupport {
+@:fakeEnum(String) extern enum ColorCorrectionSupport {
 	DEFAULT_OFF;
 	DEFAULT_ON;
 	UNSUPPORTED;

+ 1 - 1
std/flash9/display/GradientType.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum GradientType {
+@:fakeEnum(String) extern enum GradientType {
 	LINEAR;
 	RADIAL;
 }

+ 1 - 1
std/flash9/display/GraphicsPathWinding.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum GraphicsPathWinding {
+@:fakeEnum(String) extern enum GraphicsPathWinding {
 	EVEN_ODD;
 	NON_ZERO;
 }

+ 1 - 1
std/flash9/display/InterpolationMethod.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum InterpolationMethod {
+@:fakeEnum(String) extern enum InterpolationMethod {
 	LINEAR_RGB;
 	RGB;
 }

+ 1 - 1
std/flash9/display/JointStyle.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum JointStyle {
+@:fakeEnum(String) extern enum JointStyle {
 	BEVEL;
 	MITER;
 	ROUND;

+ 1 - 1
std/flash9/display/LineScaleMode.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum LineScaleMode {
+@:fakeEnum(String) extern enum LineScaleMode {
 	HORIZONTAL;
 	NONE;
 	NORMAL;

+ 1 - 1
std/flash9/display/SWFVersion.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum SWFVersion {
+@:fakeEnum(UInt) extern enum SWFVersion {
 	FLASH1;
 	FLASH10;
 	FLASH2;

+ 1 - 1
std/flash9/display/ShaderPrecision.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum ShaderPrecision {
+@:fakeEnum(String) extern enum ShaderPrecision {
 	FAST;
 	FULL;
 }

+ 1 - 1
std/flash9/display/SpreadMethod.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum SpreadMethod {
+@:fakeEnum(String) extern enum SpreadMethod {
 	PAD;
 	REFLECT;
 	REPEAT;

+ 1 - 1
std/flash9/display/StageAlign.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum StageAlign {
+@:fakeEnum(String) extern enum StageAlign {
 	BOTTOM;
 	BOTTOM_LEFT;
 	BOTTOM_RIGHT;

+ 1 - 1
std/flash9/display/StageDisplayState.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum StageDisplayState {
+@:fakeEnum(String) extern enum StageDisplayState {
 	FULL_SCREEN;
 	FULL_SCREEN_INTERACTIVE;
 	NORMAL;

+ 1 - 1
std/flash9/display/StageQuality.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum StageQuality {
+@:fakeEnum(String) extern enum StageQuality {
 	BEST;
 	HIGH;
 	LOW;

+ 1 - 1
std/flash9/display/StageScaleMode.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum StageScaleMode {
+@:fakeEnum(String) extern enum StageScaleMode {
 	EXACT_FIT;
 	NO_BORDER;
 	NO_SCALE;

+ 1 - 1
std/flash9/display/TriangleCulling.hx

@@ -1,6 +1,6 @@
 package flash.display;
 
-extern enum TriangleCulling {
+@:fakeEnum(String) extern enum TriangleCulling {
 	NEGATIVE;
 	NONE;
 	POSITIVE;

+ 1 - 1
std/flash9/events/EventPhase.hx

@@ -1,6 +1,6 @@
 package flash.events;
 
-extern enum EventPhase {
+@:fakeEnum(UInt) extern enum EventPhase {
 	AT_TARGET;
 	BUBBLING_PHASE;
 	CAPTURING_PHASE;

+ 1 - 1
std/flash9/geom/Orientation3D.hx

@@ -1,6 +1,6 @@
 package flash.geom;
 
-extern enum Orientation3D {
+@:fakeEnum(String) extern enum Orientation3D {
 	AXIS_ANGLE;
 	EULER_ANGLES;
 	QUATERNION;

+ 1 - 1
std/flash9/media/MicrophoneEnhancedMode.hx

@@ -1,6 +1,6 @@
 package flash.media;
 
-extern enum MicrophoneEnhancedMode {
+@:fakeEnum(String) extern enum MicrophoneEnhancedMode {
 	FULL_DUPLEX;
 	HALF_DUPLEX;
 	HEADSET;

+ 1 - 1
std/flash9/media/SoundCodec.hx

@@ -1,6 +1,6 @@
 package flash.media;
 
-extern enum SoundCodec {
+@:fakeEnum(String) extern enum SoundCodec {
 	NELLYMOSER;
 	SPEEX;
 }

+ 1 - 1
std/flash9/net/NetStreamAppendBytesAction.hx

@@ -1,6 +1,6 @@
 package flash.net;
 
-extern enum NetStreamAppendBytesAction {
+@:fakeEnum(String) extern enum NetStreamAppendBytesAction {
 	END_SEQUENCE;
 	RESET_BEGIN;
 	RESET_SEEK;

+ 1 - 1
std/flash9/text/AntiAliasType.hx

@@ -1,6 +1,6 @@
 package flash.text;
 
-extern enum AntiAliasType {
+@:fakeEnum(String) extern enum AntiAliasType {
 	ADVANCED;
 	NORMAL;
 }

+ 1 - 1
std/flash9/text/GridFitType.hx

@@ -1,6 +1,6 @@
 package flash.text;
 
-extern enum GridFitType {
+@:fakeEnum(String) extern enum GridFitType {
 	NONE;
 	PIXEL;
 	SUBPIXEL;

+ 1 - 1
std/flash9/text/TextFieldAutoSize.hx

@@ -1,6 +1,6 @@
 package flash.text;
 
-extern enum TextFieldAutoSize {
+@:fakeEnum(String) extern enum TextFieldAutoSize {
 	CENTER;
 	LEFT;
 	NONE;

+ 1 - 1
std/flash9/text/TextFieldType.hx

@@ -1,6 +1,6 @@
 package flash.text;
 
-extern enum TextFieldType {
+@:fakeEnum(String) extern enum TextFieldType {
 	DYNAMIC;
 	INPUT;
 }

+ 1 - 1
std/flash9/text/TextFormatAlign.hx

@@ -1,6 +1,6 @@
 package flash.text;
 
-extern enum TextFormatAlign {
+@:fakeEnum(String) extern enum TextFormatAlign {
 	CENTER;
 	JUSTIFY;
 	LEFT;

+ 1 - 1
std/flash9/text/TextFormatDisplay.hx

@@ -1,6 +1,6 @@
 package flash.text;
 
-extern enum TextFormatDisplay {
+@:fakeEnum(String) extern enum TextFormatDisplay {
 	BLOCK;
 	INLINE;
 }

+ 1 - 1
std/flash9/utils/Endian.hx

@@ -1,6 +1,6 @@
 package flash.utils;
 
-extern enum Endian {
+@:fakeEnum(String) extern enum Endian {
 	BIG_ENDIAN;
 	LITTLE_ENDIAN;
 }

+ 6 - 2
typer.ml

@@ -906,9 +906,11 @@ and type_switch ctx e cases def need_val p =
 	let old = ctx.local_types in
 	let enum = ref None in
 	let used_cases = Hashtbl.create 0 in
+	let is_fake_enum e =
+		e.e_path = ([],"Bool") || has_meta ":fakeEnum" e.e_meta
+	in
 	(match follow eval.etype with
-	| TEnum ({ e_path = [],"Bool" },_)
-	| TEnum ({ e_path = ["flash"],_ ; e_extern = true },_) -> ()
+	| TEnum (e,_) when is_fake_enum e -> ()
 	| TEnum (e,params) ->
 		enum := Some (Some (e,params));
 		ctx.local_types <- TEnumDecl e :: ctx.local_types
@@ -928,6 +930,8 @@ and type_switch ctx e cases def need_val p =
 		let params = (match !enum with
 			| None ->
 				assert false
+			| Some None when is_fake_enum en ->
+				raise Exit
 			| Some None ->
 				let params = List.map (fun _ -> mk_mono()) en.e_types in
 				enum := Some (Some (en,params));