Browse Source

Expose TAnonymous status for macros.

Dan Korostelev 11 years ago
parent
commit
b9a905744a
2 changed files with 33 additions and 6 deletions
  1. 23 5
      interp.ml
  2. 10 1
      std/haxe/macro/Type.hx

+ 23 - 5
interp.ml

@@ -265,7 +265,7 @@ let constants =
 	"constructs";"names";"superClass";"interfaces";"fields";"statics";"constructor";"init";"t";
 	"gid";"uid";"atime";"mtime";"ctime";"dev";"ino";"nlink";"rdev";"size";"mode";"pos";"len";
 	"binops";"unops";"from";"to";"array";"op";"isPostfix";"impl";
-	"id";"capture";"extra";"v";"ids";"vars";"en";"overrides"];
+	"id";"capture";"extra";"v";"ids";"vars";"en";"overrides";"status"];
 	h
 
 let h_get = hash "__get" and h_set = hash "__set"
@@ -3533,6 +3533,7 @@ type enum_index =
 	| ITConstant
 	| IModuleType
 	| IFieldAccess
+	| IAnonStatus
 
 let enum_name = function
 	| IExpr -> "ExprDef"
@@ -3552,9 +3553,10 @@ let enum_name = function
 	| ITConstant -> "TConstant"
 	| IModuleType -> "ModuleType"
 	| IFieldAccess -> "FieldAccess"
+	| IAnonStatus -> "AnonStatus"
 
 let init ctx =
-	let enums = [IExpr;IBinop;IUnop;IConst;ITParam;ICType;IField;IType;IFieldKind;IMethodKind;IVarAccess;IAccess;IClassKind;ITypedExpr;ITConstant;IModuleType;IFieldAccess] in
+	let enums = [IExpr;IBinop;IUnop;IConst;ITParam;ICType;IField;IType;IFieldKind;IMethodKind;IVarAccess;IAccess;IClassKind;ITypedExpr;ITConstant;IModuleType;IFieldAccess;IAnonStatus] in
 	let get_enum_proto e =
 		match get_path ctx ["haxe";"macro";enum_name e] null_pos with
 		| VObject e ->
@@ -4290,7 +4292,7 @@ and encode_class_kind k =
 		| KGeneric -> 4, []
 		| KGenericInstance (cl, params) -> 5, [encode_clref cl; encode_tparams params]
 		| KMacroType -> 6, []
-		| KAbstractImpl a -> 7, [encode_ref a encode_tabstract (fun() -> s_type_path a.a_path)]
+		| KAbstractImpl a -> 7, [encode_abref a]
 		| KGenericBuild cfl -> 8, []
 	) in
 	enc_enum IClassKind tag pl
@@ -4324,8 +4326,21 @@ and encode_ttype t =
 and encode_tanon a =
 	enc_obj [
 		"fields", encode_pmap_array encode_cfield a.a_fields;
+		"status", encode_anon_status !(a.a_status);
 	]
 
+and encode_anon_status s =
+	let tag, pl = (match s with
+		| Closed -> 0, []
+		| Opened -> 1, []
+		| Const -> 2, []
+		| Statics cl -> 3, [encode_clref cl]
+		| EnumStatics en -> 4, [encode_enref en]
+		| AbstractStatics ab -> 5, [encode_abref ab]
+	)
+	in
+	enc_enum IAnonStatus tag pl
+
 and encode_tparams pl =
 	enc_array (List.map encode_type pl)
 
@@ -4338,6 +4353,9 @@ and encode_enref en =
 and encode_cfref cf =
 	encode_ref cf encode_cfield (fun() -> cf.cf_name)
 
+and encode_abref ab =
+	encode_ref ab encode_tabstract (fun() -> s_type_path ab.a_path)
+
 and encode_type t =
 	let rec loop = function
 		| TMono r ->
@@ -4369,7 +4387,7 @@ and encode_type t =
 		| TLazy f ->
 			loop (!f())
 		| TAbstract (a, pl) ->
-			8, [encode_ref a encode_tabstract (fun() -> s_type_path a.a_path); encode_tparams pl]
+			8, [encode_abref a; encode_tparams pl]
 	in
 	let tag, pl = loop t in
 	enc_enum IType tag pl
@@ -4449,7 +4467,7 @@ and encode_module_type mt =
 		| TClassDecl c -> 0,[encode_clref c]
 		| TEnumDecl e -> 1,[encode_enref e]
 		| TTypeDecl t -> 2,[encode_ref t encode_ttype (fun () -> s_type_path t.t_path)]
-		| TAbstractDecl a -> 3,[encode_ref a encode_tabstract (fun () -> s_type_path a.a_path)]
+		| TAbstractDecl a -> 3,[encode_abref a]
 	in
 	enc_enum IModuleType tag pl
 

+ 10 - 1
std/haxe/macro/Type.hx

@@ -40,7 +40,16 @@ enum Type {
 
 typedef AnonType = {
 	var fields : Array<ClassField>;
-	//var status : AnonStatus;
+	var status : AnonStatus;
+}
+
+enum AnonStatus {
+	AClosed;
+	AOpened;
+	AConst;
+	AClassStatics( t : Ref<ClassType> );
+	AEnumStatics( t : Ref<EnumType> );
+	AAbstractStatics( t : Ref<AbstractType> );
 }
 
 typedef TypeParameter = {