瀏覽代碼

special_identifier_files

wtf is this anyway?
Simon Krajewski 5 月之前
父節點
當前提交
328c2d23f6
共有 6 個文件被更改,包括 13 次插入11 次删除
  1. 1 1
      src/compiler/server.ml
  2. 2 0
      src/context/common.ml
  3. 1 1
      src/macro/eval/evalDebugSocket.ml
  4. 4 4
      src/syntax/grammar.ml
  5. 3 3
      src/syntax/parser.ml
  6. 2 2
      src/syntax/parserConfig.ml

+ 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 = Hashtbl.find Parser.special_identifier_files fkey in
+							let ident = ThreadSafeHashtbl.find com.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;

+ 2 - 0
src/context/common.ml

@@ -254,6 +254,7 @@ type context = {
 	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;
 	(* communication *)
 	mutable print : string -> unit;
 	mutable error : Gctx.error_function;
@@ -777,6 +778,7 @@ let create timer_ctx compilation_step cs version args display_mode =
 		was_auto_triggered = false;
 		had_parser_resume = false;
 		delayed_syntax_completion = Atomic.make None;
+		special_identifier_files = ThreadSafeHashtbl.create 0;
 	} in
 	com
 

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

@@ -481,7 +481,7 @@ 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 in
+		let config = Parser.create_config com.Common.defines true true DMDefault com.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

+ 4 - 4
src/syntax/grammar.ml

@@ -1788,8 +1788,8 @@ let rec validate_macro_cond ctx s e = match fst e with
 	| ECall ((EConst (Ident _),_) as i, args) -> (ECall (i,List.map (validate_macro_cond ctx s) args),snd e)
 	| _ -> syntax_error ctx (Custom ("Invalid conditional expression")) ~pos:(Some (pos e)) s ((EConst (Ident "false"),(pos e)))
 
-let parse_macro_ident t p s =
-	if t = "display" then Hashtbl.replace special_identifier_files (Path.UniqueKey.create p.pfile) t;
+let parse_macro_ident ctx t p s =
+	if t = "display" then Option.may (fun h -> ThreadSafeHashtbl.replace h (Path.UniqueKey.create p.pfile) t) ctx.config.special_identifier_files;
 	let e = (EConst (Ident t),p) in
 	None, e
 
@@ -1798,7 +1798,7 @@ let rec parse_macro_cond ctx s =
 	try
 		let cond = (match%parser s with
 			| [ (Const (Ident t),p) ] ->
-				parse_macro_ident t p s
+				parse_macro_ident ctx t p s
 			| [ (Const (String(s,qs)),p) ] ->
 				None, (EConst (String(s,qs)),p)
 			| [ (Const (Int (i, s)),p) ] ->
@@ -1806,7 +1806,7 @@ let rec parse_macro_cond ctx s =
 			| [ (Const (Float (f, s)),p) ] ->
 				None, (EConst (Float (f, s)),p)
 			| [ (Kwd k,p) ] ->
-				parse_macro_ident (s_keyword k) p s
+				parse_macro_ident ctx (s_keyword k) p s
 			| [ (Unop op,p); [%let tk, e = parse_macro_cond ctx] ] ->
 				tk, make_unop op e p
 			| [ (POpen,p1); [%let (e,p) = expr ctx]; (PClose,p2) ] ->

+ 3 - 3
src/syntax/parser.ml

@@ -78,6 +78,7 @@ type parser_config = {
 	in_display_file : bool;
 	display_mode : DisplayTypes.DisplayMode.t;
 	was_auto_triggered : bool;
+	special_identifier_files : (Path.UniqueKey.t,string) ThreadSafeHashtbl.t option;
 }
 
 type parser_ctx = {
@@ -139,12 +140,13 @@ let create_context lexer_ctx config in_macro code = {
 	config;
 }
 
-let create_config defines in_display in_display_file display_mode was_auto_triggered = {
+let create_config defines in_display in_display_file display_mode was_auto_triggered special_identifier_files = {
 	defines;
 	in_display;
 	in_display_file;
 	display_mode;
 	was_auto_triggered;
+	special_identifier_files;
 }
 
 let s_decl_flag = function
@@ -163,8 +165,6 @@ let syntax_completion kind so p =
 
 let error m p = raise (Error (m,p))
 
-let special_identifier_files : (Path.UniqueKey.t,string) Hashtbl.t = Hashtbl.create 0
-
 module TokenCache = struct
 	let cache = ref (DynArray.create ())
 	let add (token : (token * pos)) = DynArray.add (!cache) token

+ 2 - 2
src/syntax/parserConfig.ml

@@ -3,10 +3,10 @@ open Common
 open DisplayPosition
 
 let default_config defines =
-	Parser.create_config defines false false DMNone false
+	Parser.create_config defines false false DMNone false None
 
 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
+	Parser.create_config com.defines in_display in_display_file com.display.dms_kind com.was_auto_triggered (Some com.special_identifier_files)