فهرست منبع

[typer] add `before_typer_create` callback

Simon Krajewski 6 سال پیش
والد
کامیت
d57fe29766
2فایلهای تغییر یافته به همراه6 افزوده شده و 0 حذف شده
  1. 1 0
      src/compiler/main.ml
  2. 5 0
      src/context/common.ml

+ 1 - 0
src/compiler/main.ml

@@ -881,6 +881,7 @@ try
 		Common.log com ("Defines: " ^ (String.concat ";" (PMap.foldi (fun k v acc -> (match v with "1" -> k | _ -> k ^ "=" ^ v) :: acc) com.defines.Define.values [])));
 		let t = Timer.timer ["typing"] in
 		Typecore.type_expr_ref := (fun ?(mode=MGet) ctx e with_type -> Typer.type_expr ~mode ctx e with_type);
+		List.iter (fun f -> f ()) (List.rev com.callbacks#get_before_typer_create);
 		let tctx = Typer.create com in
 		let add_signature desc =
 			Option.may (fun cs -> CompilationServer.maybe_add_context_sign cs com desc) (CompilationServer.get ());

+ 5 - 0
src/context/common.ml

@@ -108,6 +108,7 @@ type platform_config = {
 }
 
 class compiler_callbacks = object(self)
+	val mutable before_typer_create = [];
 	val mutable after_init_macros = [];
 	val mutable after_typing = [];
 	val mutable before_save = [];
@@ -116,6 +117,9 @@ class compiler_callbacks = object(self)
 	val mutable after_generation = [];
 	val mutable null_safety_report = [];
 
+	method add_before_typer_create (f : unit -> unit) : unit =
+		before_typer_create <- f :: before_typer_create
+
 	method add_after_init_macros (f : unit -> unit) : unit =
 		after_init_macros <- f :: after_init_macros
 
@@ -137,6 +141,7 @@ class compiler_callbacks = object(self)
 	method add_null_safety_report (f : (string*pos) list -> unit) : unit =
 		null_safety_report <- f :: null_safety_report
 
+	method get_before_typer_create = before_typer_create
 	method get_after_init_macros = after_init_macros
 	method get_after_typing = after_typing
 	method get_before_save = before_save