Browse Source

move signature handling to CompilationServer

Simon Krajewski 9 năm trước cách đây
mục cha
commit
96487b7284
2 tập tin đã thay đổi với 19 bổ sung7 xóa
  1. 16 1
      src/context/common.ml
  2. 3 6
      src/server.ml

+ 16 - 1
src/context/common.ml

@@ -319,7 +319,8 @@ module CompilationServer = struct
 	}
 
 	type t = {
-		cache : cache
+		cache : cache;
+		mutable signs : (string * string) list;
 	}
 
 	let instance : t option ref = ref None
@@ -333,6 +334,7 @@ module CompilationServer = struct
 	let create () =
 		let cs = {
 			cache = create_cache();
+			signs = [];
 		} in
 		instance := Some cs;
 		cs
@@ -349,6 +351,16 @@ module CompilationServer = struct
 			else acc
 		) cs.cache.c_files []
 
+	(* signatures *)
+
+	let get_sign cs sign =
+		List.assoc sign cs.signs
+
+	let add_sign cs sign =
+		let i = string_of_int (List.length cs.signs) in
+		cs.signs <- (sign,i) :: cs.signs;
+		i
+
 	(* modules *)
 
 	let find_module cs key =
@@ -371,6 +383,9 @@ module CompilationServer = struct
 	let remove_file cs key =
 		Hashtbl.remove cs.cache.c_files key
 
+	let remove_files cs file =
+		List.iter (fun (sign,_) -> remove_file cs (sign,file)) cs.signs
+
 	(* haxelibs *)
 
 	let find_haxelib cs key =

+ 3 - 6
src/server.ml

@@ -130,22 +130,19 @@ let ssend sock str =
 let rec wait_loop process_params verbose accept =
 	Sys.catch_break false;
 	let has_parse_error = ref false in
-
-	let signs = ref [] in
+	let cs = CompilationServer.create () in
 	let sign_string com =
 		let sign = get_signature com in
 		let	sign_id =
 			try
-				List.assoc sign !signs
+				CompilationServer.get_sign cs sign;
 			with Not_found ->
-				let i = string_of_int (List.length !signs) in
-				signs := (sign,i) :: !signs;
+				let i = CompilationServer.add_sign cs sign in
 				print_endline (Printf.sprintf "Found context %s:\n%s" i (dump_context com));
 				i
 		in
 		Printf.sprintf "%2s,%3s: " sign_id (short_platform_name com.platform)
 	in
-	let cs = CompilationServer.create () in
 	Typer.macro_enable_cache := true;
 	let current_stdin = ref None in
 	Typeload.parse_hook := (fun com2 file p ->