Quellcode durchsuchen

added class_kind access

Nicolas Cannasse vor 13 Jahren
Ursprung
Commit
21247e5029
2 geänderte Dateien mit 27 neuen und 2 gelöschten Zeilen
  1. 16 1
      interp.ml
  2. 11 1
      std/haxe/macro/Type.hx

+ 16 - 1
interp.ml

@@ -2927,6 +2927,7 @@ type enum_index =
 	| IMethodKind
 	| IVarAccess
 	| IAccess
+	| IClassKind
 
 let enum_name = function
 	| IExpr -> "ExprDef"
@@ -2941,9 +2942,10 @@ let enum_name = function
 	| IMethodKind -> "MethodKind"
 	| IVarAccess -> "VarAccess"
 	| IAccess -> "Access"
+	| IClassKind -> "ClassKind"
 
 let init ctx =
-	let enums = [IExpr;IBinop;IUnop;IConst;ITParam;ICType;IField;IType;IFieldKind;IMethodKind;IVarAccess;IAccess] in
+	let enums = [IExpr;IBinop;IUnop;IConst;ITParam;ICType;IField;IType;IFieldKind;IMethodKind;IVarAccess;IAccess;IClassKind] in
 	let get_enum_proto e =
 		match get_path ctx ["haxe";"macro";enum_name e] null_pos with
 		| VObject e ->
@@ -3619,8 +3621,21 @@ and encode_method_kind m =
 	) in
 	enc_enum IMethodKind tag pl
 
+and encode_class_kind k =
+	let tag, pl = (match k with
+		| KNormal -> 0, []
+		| KTypeParameter -> 1, []
+		| KExtension (cl, params) -> 2, [encode_tclass cl; encode_tparams params]
+		| KExpr e -> 3, [encode_expr e]
+		| KGeneric -> 4, []
+		| KGenericInstance (cl, params) -> 5, [encode_tclass cl; encode_tparams params]
+		| KMacroType -> 6, []
+	) in
+	enc_enum IClassKind tag pl
+
 and encode_tclass c =
 	encode_mtype (TClassDecl c) [
+		"kind", encode_class_kind c.cl_kind;
 		"isExtern", VBool c.cl_extern;
 		"exclude", VFunction (Fun0 (fun() -> c.cl_extern <- true; c.cl_init <- None; VNull));
 		"params", enc_array (List.map (fun (n,t) -> enc_obj ["name",enc_string n;"t",encode_type t]) c.cl_types);

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

@@ -70,8 +70,18 @@ typedef ClassField = {
 	var doc : Null<String>;
 }
 
+enum ClassKind {
+	KNormal;
+	KTypeParameter;
+	KExtension(cl:Type, params:Array<Type>);
+	KExpr(expr:Expr);
+	KGeneric;
+	KGenericInstance(cl:Type, params:Array<Type>);
+	KMacroType;
+}
+
 typedef ClassType = {> BaseType,
-	//var kind : ClassKind;
+	var kind : ClassKind;
 	var isInterface : Bool;
 	var superClass : Null<{ t : Ref<ClassType>, params : Array<Type> }>;
 	var interfaces : Array<{ t : Ref<ClassType>, params : Array<Type> }>;