瀏覽代碼

banish to parser_state

Simon Krajewski 5 月之前
父節點
當前提交
1d90d0f672

+ 1 - 1
src/compiler/displayProcessing.ml

@@ -264,7 +264,7 @@ let maybe_load_display_file_before_typing tctx display_file_dot_path = match dis
 let handle_display_after_typing ctx tctx display_file_dot_path =
 	let com = ctx.com in
 	if ctx.com.display.dms_kind = DMNone && ctx.has_error then raise Abort;
-	begin match ctx.com.display.dms_kind,Atomic.get ctx.com.delayed_syntax_completion with
+	begin match ctx.com.display.dms_kind,Atomic.get ctx.com.parser_state.delayed_syntax_completion with
 		| DMDefault,Some(kind,subj) -> DisplayOutput.handle_syntax_completion com kind subj
 		| _ -> ()
 	end;

+ 1 - 1
src/compiler/server.ml

@@ -75,7 +75,7 @@ let parse_file cs com (rfile : ClassPaths.resolved_file) p =
 							(* We assume that when not in display mode it's okay to cache stuff that has #if display
 							checks. The reasoning is that non-display mode has more information than display mode. *)
 							if com.display.dms_full_typing then raise Not_found;
-							let ident = ThreadSafeHashtbl.find com.special_identifier_files fkey in
+							let ident = ThreadSafeHashtbl.find com.parser_state.special_identifier_files fkey in
 							Printf.sprintf "not cached, using \"%s\" define" ident,true
 						with Not_found ->
 							cc#cache_file fkey (ClassPaths.create_resolved_file ffile rfile.class_path) ftime data pdi;

+ 14 - 9
src/context/common.ml

@@ -227,6 +227,13 @@ class virtual abstract_hxb_lib = object(self)
 	method virtual get_string_pool : string -> string array option
 end
 
+type parser_state = {
+	mutable was_auto_triggered : bool;
+	mutable had_parser_resume : bool;
+	delayed_syntax_completion : Parser.syntax_completion_on option Atomic.t;
+	special_identifier_files : (Path.UniqueKey.t,string) ThreadSafeHashtbl.t;
+}
+
 type context = {
 	compilation_step : int;
 	mutable stage : compiler_stage;
@@ -250,11 +257,7 @@ type context = {
 	main : Gctx.context_main;
 	mutable package_rules : (string,package_rule) PMap.t;
 	mutable report_mode : report_mode;
-	(* parser stuff to clean up later *)
-	mutable was_auto_triggered : bool;
-	mutable had_parser_resume : bool;
-	delayed_syntax_completion : Parser.syntax_completion_on option Atomic.t;
-	special_identifier_files : (Path.UniqueKey.t,string) ThreadSafeHashtbl.t;
+	parser_state : parser_state;
 	(* communication *)
 	mutable print : string -> unit;
 	mutable error : Gctx.error_function;
@@ -775,10 +778,12 @@ let create timer_ctx compilation_step cs version args display_mode =
 		hxb_reader_api = None;
 		hxb_reader_stats = HxbReader.create_hxb_reader_stats ();
 		hxb_writer_config = None;
-		was_auto_triggered = false;
-		had_parser_resume = false;
-		delayed_syntax_completion = Atomic.make None;
-		special_identifier_files = ThreadSafeHashtbl.create 0;
+		parser_state = {
+			was_auto_triggered = false;
+			had_parser_resume = false;
+			delayed_syntax_completion = Atomic.make None;
+			special_identifier_files = ThreadSafeHashtbl.create 0;
+		}
 	} in
 	com
 

+ 2 - 2
src/context/display/display.ml

@@ -31,8 +31,8 @@ module ReferencePosition = struct
 end
 
 let preprocess_expr com e = match com.display.dms_kind with
-	| DMDefinition | DMTypeDefinition | DMUsage _ | DMImplementation | DMHover | DMDefault -> ExprPreprocessing.find_before_pos com.was_auto_triggered com.display.dms_kind e
-	| DMSignature -> ExprPreprocessing.find_display_call com.was_auto_triggered e
+	| DMDefinition | DMTypeDefinition | DMUsage _ | DMImplementation | DMHover | DMDefault -> ExprPreprocessing.find_before_pos com.parser_state.was_auto_triggered com.display.dms_kind e
+	| DMSignature -> ExprPreprocessing.find_display_call com.parser_state.was_auto_triggered e
 	| _ -> e
 
 let sort_fields l with_type tk =

+ 1 - 1
src/context/display/displayJson.ml

@@ -64,7 +64,7 @@ class display_handler (jsonrpc : jsonrpc_handler) com (cs : CompilationCache.t)
 		) None in
 
 		let pos = if requires_offset then jsonrpc#get_int_param "offset" else (-1) in
-		com.was_auto_triggered <- was_auto_triggered;
+		com.parser_state.was_auto_triggered <- was_auto_triggered;
 
 		if file <> file_input_marker then begin
 			let file_unique = com.file_keys#get file in

+ 2 - 2
src/macro/eval/evalDebugSocket.ml

@@ -481,12 +481,12 @@ module ValueCompletion = struct
 			)
 		in
 		let com = (ctx.curapi.get_com()) in
-		let config = Parser.create_config com.Common.defines true true DMDefault com.was_auto_triggered None in
+		let config = Parser.create_config com.Common.defines true true DMDefault com.parser_state.was_auto_triggered None in
 		let offset = column + (String.length "class X{static function main() ") - 1 (* this is retarded *) in
 		DisplayPosition.display_position#set {p with pmin = offset; pmax = offset};
 		begin try
 			let e = parse_expr ctx config text p in
-			let e = ExprPreprocessing.find_before_pos com.was_auto_triggered DMDefault e in
+			let e = ExprPreprocessing.find_before_pos com.parser_state.was_auto_triggered DMDefault e in
 			save();
 			let rec loop e = match fst e with
 			| EDisplay(e1,DKDot) ->

+ 1 - 1
src/syntax/parserConfig.ml

@@ -9,4 +9,4 @@ let file_parser_config com file =
 	let open DisplayPosition in
 	let in_display = display_position#get <> null_pos in
 	let in_display_file = in_display && display_position#is_in_file (Path.UniqueKey.create file) in
-	Parser.create_config com.defines in_display in_display_file com.display.dms_kind com.was_auto_triggered (Some com.special_identifier_files)
+	Parser.create_config com.defines in_display in_display_file com.display.dms_kind com.parser_state.was_auto_triggered (Some com.parser_state.special_identifier_files)

+ 1 - 1
src/typing/typeloadFunction.ml

@@ -63,7 +63,7 @@ let type_function ctx (args : function_arguments) ret e do_display p =
 	end else begin
 		let is_display_debug = Meta.has (Meta.Custom ":debug.display") ctx.f.curfield.cf_meta in
 		if is_display_debug then print_endline ("before processing:\n" ^ (Expr.dump_with_pos e));
-		let e = if ctx.com.had_parser_resume then e else Display.preprocess_expr ctx.com e in
+		let e = if ctx.com.parser_state.had_parser_resume then e else Display.preprocess_expr ctx.com e in
 		if is_display_debug then print_endline ("after processing:\n" ^ (Expr.dump_with_pos e));
 		type_expr ctx e NoValue
 	end in

+ 2 - 2
src/typing/typeloadParse.ml

@@ -47,8 +47,8 @@ let parse_file_from_lexbuf com file p lexbuf =
 			DisplayException.raise_module_symbols (DocumentSymbols.Printer.print_module_symbols com [file,ds] filter);
 		| _,ParseSuccess(_,({pd_was_display_file = true} as pdi)) ->
 			if pdi.pd_had_resume then
-				com.had_parser_resume <- true;
-			Atomic.set com.delayed_syntax_completion pdi.pd_delayed_syntax_completion
+				com.parser_state.had_parser_resume <- true;
+			Atomic.set com.parser_state.delayed_syntax_completion pdi.pd_delayed_syntax_completion
 		| _ ->
 			()
 	end;

+ 1 - 1
src/typing/typerDisplay.ml

@@ -491,7 +491,7 @@ and display_expr ctx e_ast e dk mode with_type p =
 		raise_positions pl
 	| DMTypeDefinition ->
 		raise_position_of_type ctx e.etype
-	| DMDefault when not ctx.com.had_parser_resume ->
+	| DMDefault when not ctx.com.parser_state.had_parser_resume ->
 		let display_fields e_ast e1 so =
 			let l = match so with None -> 0 | Some s -> String.length s in
 			let fields = DisplayFields.collect ctx e_ast e1 dk with_type p in