Browse Source

move more display data types to display.ml

Dan Korostelev 9 years ago
parent
commit
a798583245
3 changed files with 41 additions and 42 deletions
  1. 18 0
      src/display/display.ml
  2. 16 16
      src/main.ml
  3. 7 26
      src/typing/typer.ml

+ 18 - 0
src/display/display.ml

@@ -2,10 +2,28 @@ open Ast
 open Common
 open Type
 
+(* order of these variants affects output sorting *)
+type display_field_kind =
+	| FKVar
+	| FKMethod
+	| FKType
+	| FKPackage
+
+type identifier_type =
+	| ITLocal of tvar
+	| ITMember of tclass * tclass_field
+	| ITStatic of tclass * tclass_field
+	| ITEnum of tenum * tenum_field
+	| ITGlobal of module_type * string * t
+	| ITType of module_type
+	| ITPackage of string
+
 exception DocumentSymbols of string
 exception DisplayTypes of t list
 exception DisplayPosition of Ast.pos list
 exception DisplaySubExpression of Ast.expr
+exception DisplayFields of (string * t * display_field_kind option * documentation) list
+exception DisplayToplevel of identifier_type list
 
 let is_display_file p =
 	Common.unique_full_path p.pfile = (!Parser.resume_display).pfile

+ 16 - 16
src/main.ml

@@ -176,10 +176,10 @@ let complete_fields com fields =
 	List.iter (fun (n,t,k,d) ->
 		let s_kind = match k with
 			| Some k -> (match k with
-				| Typer.FKVar -> "var"
-				| Typer.FKMethod -> "method"
-				| Typer.FKType -> "type"
-				| Typer.FKPackage -> "package")
+				| Display.FKVar -> "var"
+				| Display.FKMethod -> "method"
+				| Display.FKType -> "type"
+				| Display.FKPackage -> "package")
 			| None -> ""
 		in
 		if details then
@@ -1697,7 +1697,7 @@ with
 		error ctx ("Error: " ^ msg) Ast.null_pos
 	| Arg.Help msg ->
 		message ctx msg Ast.null_pos
-	| Typer.DisplayFields fields ->
+	| Display.DisplayFields fields ->
 		let ctx = print_context() in
 		let fields = List.map (fun (name,t,kind,doc) -> name, s_type ctx t, kind, (match doc with None -> "" | Some d -> d)) fields in
 		let fields = if !measure_times then begin
@@ -1735,19 +1735,19 @@ with
 		) pl;
 		Buffer.add_string b "</list>";
 		raise (Completion (Buffer.contents b))
-	| Typer.DisplayToplevel il ->
+	| Display.DisplayToplevel il ->
 		let b = Buffer.create 0 in
 		Buffer.add_string b "<il>\n";
 		let ctx = print_context() in
 		let s_type t = htmlescape (s_type ctx t) in
 		List.iter (fun id -> match id with
-			| Typer.ITLocal v -> Buffer.add_string b (Printf.sprintf "<i k=\"local\" t=\"%s\">%s</i>\n" (s_type v.v_type) v.v_name);
-			| Typer.ITMember(c,cf) -> Buffer.add_string b (Printf.sprintf "<i k=\"member\" t=\"%s\">%s</i>\n" (s_type cf.cf_type) cf.cf_name);
-			| Typer.ITStatic(c,cf) -> Buffer.add_string b (Printf.sprintf "<i k=\"static\" t=\"%s\">%s</i>\n" (s_type cf.cf_type) cf.cf_name);
-			| Typer.ITEnum(en,ef) -> Buffer.add_string b (Printf.sprintf "<i k=\"enum\" t=\"%s\">%s</i>\n" (s_type ef.ef_type) ef.ef_name);
-			| Typer.ITGlobal(mt,s,t) -> Buffer.add_string b (Printf.sprintf "<i k=\"global\" p=\"%s\" t=\"%s\">%s</i>\n" (s_type_path (t_infos mt).mt_path) (s_type t) s);
-			| Typer.ITType(mt) -> Buffer.add_string b (Printf.sprintf "<i k=\"type\" p=\"%s\">%s</i>\n" (s_type_path (t_infos mt).mt_path) (snd (t_infos mt).mt_path));
-			| Typer.ITPackage s -> Buffer.add_string b (Printf.sprintf "<i k=\"package\">%s</i>\n" s)
+			| Display.ITLocal v -> Buffer.add_string b (Printf.sprintf "<i k=\"local\" t=\"%s\">%s</i>\n" (s_type v.v_type) v.v_name);
+			| Display.ITMember(c,cf) -> Buffer.add_string b (Printf.sprintf "<i k=\"member\" t=\"%s\">%s</i>\n" (s_type cf.cf_type) cf.cf_name);
+			| Display.ITStatic(c,cf) -> Buffer.add_string b (Printf.sprintf "<i k=\"static\" t=\"%s\">%s</i>\n" (s_type cf.cf_type) cf.cf_name);
+			| Display.ITEnum(en,ef) -> Buffer.add_string b (Printf.sprintf "<i k=\"enum\" t=\"%s\">%s</i>\n" (s_type ef.ef_type) ef.ef_name);
+			| Display.ITGlobal(mt,s,t) -> Buffer.add_string b (Printf.sprintf "<i k=\"global\" p=\"%s\" t=\"%s\">%s</i>\n" (s_type_path (t_infos mt).mt_path) (s_type t) s);
+			| Display.ITType(mt) -> Buffer.add_string b (Printf.sprintf "<i k=\"type\" p=\"%s\">%s</i>\n" (s_type_path (t_infos mt).mt_path) (snd (t_infos mt).mt_path));
+			| Display.ITPackage s -> Buffer.add_string b (Printf.sprintf "<i k=\"package\">%s</i>\n" s)
 		) il;
 		Buffer.add_string b "</il>";
 		raise (Completion (Buffer.contents b))
@@ -1760,7 +1760,7 @@ with
 			else
 				complete_fields com (
 					let convert k f = (f,"",Some k,"") in
-					(List.map (convert Typer.FKPackage) packs) @ (List.map (convert Typer.FKType) classes)
+					(List.map (convert Display.FKPackage) packs) @ (List.map (convert Display.FKType) classes)
 				)
 		| Some (c,cur_package) ->
 			try
@@ -1793,12 +1793,12 @@ with
 					end;
 					not tinfos.mt_private
 				) m.m_types in
-				let types = if c <> s_module then [] else List.map (fun t -> snd (t_path t),"",Some Typer.FKType,"") public_types in
+				let types = if c <> s_module then [] else List.map (fun t -> snd (t_path t),"",Some Display.FKType,"") public_types in
 				let ctx = print_context() in
 				let make_field_doc cf =
 					cf.cf_name,
 					s_type ctx cf.cf_type,
-					Some (match cf.cf_kind with Method _ -> Typer.FKMethod | Var _ -> Typer.FKVar),
+					Some (match cf.cf_kind with Method _ -> Display.FKMethod | Var _ -> Display.FKVar),
 					(match cf.cf_doc with Some s -> s | None -> "")
 				in
 				let types = match !statics with

+ 7 - 26
src/typing/typer.ml

@@ -34,25 +34,6 @@ type access_mode =
 	| MSet
 	| MCall
 
-type identifier_type =
-	| ITLocal of tvar
-	| ITMember of tclass * tclass_field
-	| ITStatic of tclass * tclass_field
-	| ITEnum of tenum * tenum_field
-	| ITGlobal of module_type * string * t
-	| ITType of module_type
-	| ITPackage of string
-
-(* order of these variants affects output sorting *)
-type display_field_kind =
-	| FKVar
-	| FKMethod
-	| FKType
-	| FKPackage
-
-exception DisplayFields of (string * t * display_field_kind option * documentation) list
-exception DisplayToplevel of identifier_type list
-
 type access_kind =
 	| AKNo of string
 	| AKExpr of texpr
@@ -391,7 +372,7 @@ let collect_toplevel_identifiers ctx =
 	(* locals *)
 	PMap.iter (fun _ v ->
 		if not (is_gen_local v) then
-			DynArray.add acc (ITLocal v)
+			DynArray.add acc (Display.ITLocal v)
 	) ctx.locals;
 
 	(* member vars *)
@@ -521,7 +502,7 @@ let collect_toplevel_identifiers ctx =
 		DynArray.add acc (ITType mt)
 	) !module_types;
 
-	raise (DisplayToplevel (DynArray.to_list acc))
+	raise (Display.DisplayToplevel (DynArray.to_list acc))
 
 (* ---------------------------------------------------------------------- *)
 (* PASS 3 : type expression & check structure *)
@@ -3757,7 +3738,7 @@ and handle_display ctx e_ast iscall with_type p =
 		let tl = List.filter (fun t -> path <> (t_infos t).mt_path && not (t_infos t).mt_private) m.m_types in
 		let tl = List.map (fun mt ->
 			let infos = t_infos mt in
-			(snd infos.mt_path),type_of_module_type mt,Some FKType,infos.mt_doc
+			(snd infos.mt_path),type_of_module_type mt,Some Display.FKType,infos.mt_doc
 		) tl in
 		tl
 	in
@@ -3769,7 +3750,7 @@ and handle_display ctx e_ast iscall with_type p =
 		raise (Display.DisplayTypes [tfun [t_dynamic] ctx.com.basic.tvoid])
 	| Error (Type_not_found (path,_),_) as err ->
 		begin try
-			raise (DisplayFields (get_submodule_fields path))
+			raise (Display.DisplayFields (get_submodule_fields path))
 		with Not_found ->
 			raise err
 		end
@@ -4004,7 +3985,7 @@ and handle_display ctx e_ast iscall with_type p =
 		else
 			let get_field acc f =
 				List.fold_left (fun acc f ->
-					let kind = match f.cf_kind with Method _ -> FKMethod | Var _ -> FKVar in
+					let kind = match f.cf_kind with Method _ -> Display.FKMethod | Var _ -> Display.FKVar in
 					if f.cf_public then (f.cf_name,f.cf_type,Some kind,f.cf_doc) :: acc else acc
 				) acc (f :: f.cf_overloads)
 			in
@@ -4018,7 +3999,7 @@ and handle_display ctx e_ast iscall with_type p =
 			if fields = [] then
 				e.etype
 			else
-				raise (DisplayFields fields)
+				raise (Display.DisplayFields fields)
 		in
 		(match follow t with
 		| TMono _ | TDynamic _ when ctx.in_macro -> mk (TConst TNull) t p
@@ -4619,7 +4600,7 @@ let make_macro_api ctx p =
 				let e = Optimizer.optimize_completion_expr e in
 				ignore (type_expr ctx e Value);
 				"NO COMPLETION"
-			with DisplayFields fields ->
+			with Display.DisplayFields fields ->
 				let pctx = print_context() in
 				String.concat "," (List.map (fun (f,t,_,_) -> f ^ ":" ^ s_type pctx t) fields)
 			| Display.DisplayTypes tl ->