Skip to content

Commit d12e425

Browse files
committed
conservative update input name
1 parent 591da0b commit d12e425

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

driver/compile.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,5 @@ let implementation ppf sourcefile outputprefix =
100100
raise x
101101

102102
let c_file name =
103-
Location.input_name := name;
103+
Location.set_input_name name;
104104
if Ccomp.compile_file name <> 0 then exit 2

driver/pparse.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ let read_ast magic fn =
8484
try
8585
let buffer = really_input_string ic (String.length magic) in
8686
assert(buffer = magic); (* already checked by apply_rewriter *)
87-
Location.input_name := input_value ic;
87+
Location.set_input_name @@ input_value ic;
8888
let ast = input_value ic in
8989
close_in ic;
9090
Misc.remove_file fn;
@@ -152,11 +152,11 @@ let file ppf ~tool_name inputfile parse_fun ast_magic =
152152
(* FIXME make this a proper warning *)
153153
fprintf ppf "@[Warning: %s@]@."
154154
"option -unsafe used with a preprocessor returning a syntax tree";
155-
Location.input_name := input_value ic;
155+
Location.set_input_name @@ input_value ic;
156156
input_value ic
157157
end else begin
158158
seek_in ic 0;
159-
Location.input_name := inputfile;
159+
Location.set_input_name inputfile;
160160
let lexbuf = Lexing.from_channel ic in
161161
Location.init lexbuf inputfile;
162162
parse_fun lexbuf
@@ -183,7 +183,7 @@ let () =
183183
)
184184

185185
let parse_all ~tool_name parse_fun magic ppf sourcefile =
186-
Location.input_name := sourcefile;
186+
Location.set_input_name sourcefile;
187187
let inputfile = preprocess sourcefile in
188188
let ast =
189189
try file ppf ~tool_name inputfile parse_fun magic

parsing/ast_mapper.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ let apply_lazy ~source ~target mapper =
799799
if magic <> Config.ast_impl_magic_number
800800
&& magic <> Config.ast_intf_magic_number then
801801
failwith "Ast_mapper: OCaml version mismatch or malformed input";
802-
Location.input_name := input_value ic;
802+
Location.set_input_name @@ input_value ic;
803803
let ast = input_value ic in
804804
close_in ic;
805805

parsing/location.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ let rhs_loc n = {
6565

6666
let input_name = ref "_none_"
6767
let input_lexbuf = ref (None : lexbuf option)
68-
68+
let set_input_name name =
69+
if name <> "" then input_name := name
6970
(* Terminal info *)
7071

7172
let status = ref Terminfo.Uninitialised

parsing/location.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ val symbol_gloc: unit -> t
4848
val rhs_loc: int -> t
4949

5050
val input_name: string ref
51+
val set_input_name: string -> unit
5152
val input_lexbuf: Lexing.lexbuf option ref
5253

5354
val get_pos_info: Lexing.position -> string * int * int (* file, line, char *)

0 commit comments

Comments
 (0)