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

[typer] factor out class/enum/abstract_module_type

Simon Krajewski 8 жил өмнө
parent
commit
1bd19682f7

+ 1 - 0
src/core/path.ml

@@ -171,6 +171,7 @@ let rec create_file bin ext acc = function
 		let dir = String.concat "/" (List.rev (d :: acc)) in
 		if not (Sys.file_exists (remove_trailing_slash dir)) then Unix.mkdir dir 0o755;
 		create_file bin ext (d :: acc) l
+
 let rec mkdir_recursive base dir_list =
 	match dir_list with
 	| [] -> ()

+ 42 - 0
src/core/type.ml

@@ -2677,3 +2677,45 @@ module StringError = struct
 		try string_error_raise s sl msg
 		with Not_found -> msg
 end
+
+let class_module_type c = {
+	t_path = [],"Class<" ^ (s_type_path c.cl_path) ^ ">" ;
+	t_module = c.cl_module;
+	t_doc = None;
+	t_pos = c.cl_pos;
+	t_name_pos = null_pos;
+	t_type = TAnon {
+		a_fields = c.cl_statics;
+		a_status = ref (Statics c);
+	};
+	t_private = true;
+	t_params = [];
+	t_meta = no_meta;
+}
+
+let enum_module_type m path p  = {
+	t_path = [], "Enum<" ^ (s_type_path path) ^ ">";
+	t_module = m;
+	t_doc = None;
+	t_pos = p;
+	t_name_pos = null_pos;
+	t_type = mk_mono();
+	t_private = true;
+	t_params = [];
+	t_meta = [];
+}
+
+let abstract_module_type a tl = {
+	t_path = [],Printf.sprintf "Abstract<%s%s>" (s_type_path a.a_path) (s_type_params (ref []) tl);
+	t_module = a.a_module;
+	t_doc = None;
+	t_pos = a.a_pos;
+	t_name_pos = null_pos;
+	t_type = TAnon {
+		a_fields = PMap.empty;
+		a_status = ref (AbstractStatics a);
+	};
+	t_private = true;
+	t_params = [];
+	t_meta = no_meta;
+}

+ 1 - 11
src/typing/typeload.ml

@@ -135,17 +135,7 @@ let module_pass_1 ctx m tdecls loadp =
 				e_extern = List.mem EExtern d.d_flags;
 				e_constrs = PMap.empty;
 				e_names = [];
-				e_type = {
-					t_path = [], "Enum<" ^ (s_type_path path) ^ ">";
-					t_module = m;
-					t_doc = None;
-					t_pos = p;
-					t_name_pos = null_pos;
-					t_type = mk_mono();
-					t_private = true;
-					t_params = [];
-					t_meta = [];
-				};
+				e_type = enum_module_type m path p;
 			} in
 			decls := (TEnumDecl e, decl) :: !decls;
 			acc

+ 1 - 29
src/typing/typer.ml

@@ -686,21 +686,6 @@ let fast_enum_field e ef p =
 	let et = mk (TTypeExpr (TEnumDecl e)) (TAnon { a_fields = PMap.empty; a_status = ref (EnumStatics e) }) p in
 	TField (et,FEnum (e,ef))
 
-let abstract_module_type a tl = {
-	t_path = [],Printf.sprintf "Abstract<%s%s>" (s_type_path a.a_path) (s_type_params (ref []) tl);
-	t_module = a.a_module;
-	t_doc = None;
-	t_pos = a.a_pos;
-	t_name_pos = null_pos;
-	t_type = TAnon {
-		a_fields = PMap.empty;
-		a_status = ref (AbstractStatics a);
-	};
-	t_private = true;
-	t_params = [];
-	t_meta = no_meta;
-}
-
 let rec type_module_type ctx t tparams p =
 	match t with
 	| TClassDecl {cl_kind = KGenericBuild _} ->
@@ -714,20 +699,7 @@ let rec type_module_type ctx t tparams p =
 		in
 		type_module_type ctx mt None p
 	| TClassDecl c ->
-		let t_tmp = {
-			t_path = [],"Class<" ^ (s_type_path c.cl_path) ^ ">" ;
-			t_module = c.cl_module;
-			t_doc = None;
-			t_pos = c.cl_pos;
-			t_name_pos = null_pos;
-			t_type = TAnon {
-				a_fields = c.cl_statics;
-				a_status = ref (Statics c);
-			};
-			t_private = true;
-			t_params = [];
-			t_meta = no_meta;
-		} in
+		let t_tmp = class_module_type c in
 		mk (TTypeExpr (TClassDecl c)) (TType (t_tmp,[])) p
 	| TEnumDecl e ->
 		let types = (match tparams with None -> List.map (fun _ -> mk_mono()) e.e_params | Some l -> l) in