Skip to content

Commit 81a5081

Browse files
authored
Remove unused code from Location and Rescript_cpp modules (#7150)
* Remove unused stuff from Location and Rescript_cpp modules * Remove unused stuff from Syntaxerr module * CHANGELOG
1 parent 04f4e27 commit 81a5081

10 files changed

+8
-258
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
- AST cleanup: first-class expression and patterns for records with optional fields. https://github.com/rescript-lang/rescript/pull/7192
2727
- AST cleanup: Represent the arity of uncurried function definitions directly in the AST. https://github.com/rescript-lang/rescript/pull/7197
2828
- AST cleanup: Remove Pexp_function from the AST. https://github.com/rescript-lang/rescript/pull/7198
29-
29+
- Remove unused code from Location and Rescript_cpp modules. https://github.com/rescript-lang/rescript/pull/7150
3030

3131
# 12.0.0-alpha.5
3232

compiler/bsc/rescript_compiler_main.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
(* *)
1111
(***********************************************************************)
1212

13+
let absname = ref false
14+
1315
let set_abs_input_name sourcefile =
1416
let sourcefile =
15-
if !Location.absname && Filename.is_relative sourcefile then
17+
if !absname && Filename.is_relative sourcefile then
1618
Ext_path.absolute_cwd_path sourcefile
1719
else sourcefile
1820
in
@@ -394,7 +396,7 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
394396
string_optional_set Clflags.preprocessor,
395397
"*internal* <command> Pipe sources through preprocessor <command>" );
396398
( "-absname",
397-
set Location.absname,
399+
set absname,
398400
"*internal* Show absolute filenames in error messages" );
399401
(* Not used, the build system did the expansion *)
400402
( "-bs-no-bin-annot",

compiler/jsoo/jsoo_playground_main.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ module Compile = struct
375375
let reset_compiler () =
376376
warning_infos := [||];
377377
flush_warning_buffer () |> ignore;
378-
Location.reset ();
379378
Warnings.reset_fatal ();
380379
Env.reset_cache_toplevel ()
381380

compiler/ml/env.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,10 +1035,6 @@ let rec lookup_module_descr_aux ?loc lid env =
10351035
and lookup_module_descr ?loc lid env =
10361036
let ((p, comps) as res) = lookup_module_descr_aux ?loc lid env in
10371037
mark_module_used env (Path.last p) comps.loc;
1038-
(*
1039-
Format.printf "USE module %s at %a@." (Path.last p)
1040-
Location.print comps.loc;
1041-
*)
10421038
report_deprecated ?loc p comps.deprecated;
10431039
res
10441040

compiler/ml/location.ml

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515

1616
open Lexing
1717

18-
let absname = ref false
19-
(* This reference should be in Clflags, but it would create an additional
20-
dependency and make bootstrapping Camlp4 more difficult. *)
21-
2218
type t = Warnings.loc = {
2319
loc_start: position;
2420
loc_end: position;
@@ -31,72 +27,18 @@ let in_file name =
3127

3228
let none = in_file "_none_"
3329

34-
let curr lexbuf =
35-
{
36-
loc_start = lexbuf.lex_start_p;
37-
loc_end = lexbuf.lex_curr_p;
38-
loc_ghost = false;
39-
}
40-
41-
let init lexbuf fname =
42-
lexbuf.lex_curr_p <-
43-
{pos_fname = fname; pos_lnum = 1; pos_bol = 0; pos_cnum = 0}
44-
45-
let symbol_rloc () =
46-
{
47-
loc_start = Parsing.symbol_start_pos ();
48-
loc_end = Parsing.symbol_end_pos ();
49-
loc_ghost = false;
50-
}
51-
52-
let symbol_gloc () =
53-
{
54-
loc_start = Parsing.symbol_start_pos ();
55-
loc_end = Parsing.symbol_end_pos ();
56-
loc_ghost = true;
57-
}
58-
59-
let rhs_loc n =
60-
{
61-
loc_start = Parsing.rhs_start_pos n;
62-
loc_end = Parsing.rhs_end_pos n;
63-
loc_ghost = false;
64-
}
65-
6630
let input_name = ref "_none_"
67-
let input_lexbuf = ref (None : lexbuf option)
6831
let set_input_name name = if name <> "" then input_name := name
6932
(* Terminal info *)
7033

71-
let num_loc_lines = ref 0 (* number of lines already printed after input *)
72-
7334
(* Print the location in some way or another *)
7435

7536
open Format
7637

77-
let absolute_path s =
78-
(* This function could go into Filename *)
79-
let open Filename in
80-
let s = if is_relative s then concat (Sys.getcwd ()) s else s in
81-
(* Now simplify . and .. components *)
82-
let rec aux s =
83-
let base = basename s in
84-
let dir = dirname s in
85-
if dir = s then dir
86-
else if base = current_dir_name then aux dir
87-
else if base = parent_dir_name then dirname (aux dir)
88-
else concat (aux dir) base
89-
in
90-
aux s
91-
92-
let show_filename file =
93-
let file = if file = "_none_" then !input_name else file in
94-
if !absname then absolute_path file else file
38+
let show_filename file = if file = "_none_" then !input_name else file
9539

9640
let print_filename ppf file = Format.fprintf ppf "%s" (show_filename file)
9741

98-
let reset () = num_loc_lines := 0
99-
10042
(* return file, line, char from the given position *)
10143
let get_pos_info pos = (pos.pos_fname, pos.pos_lnum, pos.pos_cnum - pos.pos_bol)
10244

@@ -206,21 +148,6 @@ let print ?(src = None) ~message_kind intro ppf (loc : t) =
206148
| Sys_error _ ->
207149
())
208150

209-
let error_prefix = "Error"
210-
211-
let print_error_prefix ppf =
212-
setup_colors ();
213-
fprintf ppf "@{<error>%s@}" error_prefix
214-
215-
let print_compact ppf loc =
216-
let file, line, startchar = get_pos_info loc.loc_start in
217-
let endchar = loc.loc_end.pos_cnum - loc.loc_start.pos_cnum + startchar in
218-
fprintf ppf "%a:%i" print_filename file line;
219-
if startchar >= 0 then fprintf ppf ",%i--%i" startchar endchar
220-
221-
let print_error intro ppf loc =
222-
fprintf ppf "%a%t:" (print ~message_kind:`error intro) loc print_error_prefix
223-
224151
let default_warning_printer loc ppf w =
225152
match Warnings.report w with
226153
| `Inactive -> ()
@@ -241,10 +168,6 @@ let print_warning loc ppf w = !warning_printer loc ppf w
241168
let formatter_for_warnings = ref err_formatter
242169
let prerr_warning loc w = print_warning loc !formatter_for_warnings w
243170

244-
let echo_eof () =
245-
print_newline ();
246-
incr num_loc_lines
247-
248171
type 'a loc = {txt: 'a; loc: t}
249172

250173
let mkloc txt loc = {txt; loc}

compiler/ml/location.mli

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,13 @@ val none : t
3636
val in_file : string -> t
3737
(** Return an empty ghost range located in a given file. *)
3838

39-
val init : Lexing.lexbuf -> string -> unit
40-
(** Set the file name and line number of the [lexbuf] to be the start
41-
of the named file. *)
42-
43-
val curr : Lexing.lexbuf -> t
44-
(** Get the location of the current token from the [lexbuf]. *)
45-
46-
val symbol_rloc : unit -> t
47-
val symbol_gloc : unit -> t
48-
49-
val rhs_loc : int -> t
50-
(** [rhs_loc n] returns the location of the symbol at position [n], starting
51-
at 1, in the current parser rule. *)
52-
5339
val input_name : string ref
5440
val set_input_name : string -> unit
55-
val input_lexbuf : Lexing.lexbuf option ref
5641

5742
val get_pos_info : Lexing.position -> string * int * int (* file, line, char *)
5843
val print_loc : formatter -> t -> unit
59-
val print_error : tag -> formatter -> t -> unit
6044

6145
val prerr_warning : t -> Warnings.t -> unit
62-
val echo_eof : unit -> unit
63-
val reset : unit -> unit
6446

6547
val warning_printer : (t -> formatter -> Warnings.t -> unit) ref
6648
(** Hook for intercepting warnings. *)
@@ -75,23 +57,9 @@ type 'a loc = {txt: 'a; loc: t}
7557
val mknoloc : 'a -> 'a loc
7658
val mkloc : 'a -> t -> 'a loc
7759

78-
val print :
79-
?src:string option ->
80-
message_kind:[< `error | `warning | `warning_as_error > `warning] ->
81-
string ->
82-
formatter ->
83-
t ->
84-
unit
85-
val print_compact : formatter -> t -> unit
8660
val print_filename : formatter -> string -> unit
8761

88-
val absolute_path : string -> string
89-
9062
val show_filename : string -> string
91-
(** In -absname mode, return the absolute path for this filename.
92-
Otherwise, returns the filename unchanged. *)
93-
94-
val absname : bool ref
9563

9664
(** Support for located errors *)
9765

@@ -107,13 +75,6 @@ exception Error of error
10775

10876
val error : ?loc:t -> ?sub:error list -> ?if_highlight:string -> string -> error
10977

110-
val print_error_prefix : Format.formatter -> unit
111-
val pp_ksprintf :
112-
?before:(formatter -> unit) ->
113-
(string -> 'a) ->
114-
('b, formatter, unit, 'a) format4 ->
115-
'b
116-
11778
val errorf :
11879
?loc:t ->
11980
?sub:error list ->

compiler/ml/rescript_cpp.ml

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,13 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
type pp_error = Unterminated_if | Unterminated_else
26-
27-
exception Pp_error of pp_error * Location.t
28-
2925
type directive_value =
3026
| Dir_bool of bool
3127
| Dir_float of float
3228
| Dir_int of int
3329
| Dir_string of string
3430
| Dir_null
3531

36-
let prepare_pp_error loc = function
37-
| Unterminated_if -> Location.errorf ~loc "#if not terminated"
38-
| Unterminated_else -> Location.errorf ~loc "#else not terminated"
39-
40-
let () =
41-
Location.register_error_of_exn (function
42-
| Pp_error (err, loc) -> Some (prepare_pp_error loc err)
43-
| _ -> None)
44-
4532
let directive_built_in_values = Hashtbl.create 51
4633

4734
let replace_directive_built_in_value k v =
@@ -117,38 +104,3 @@ let define_key_value key v =
117104
try Dir_float (float_of_string v) with _ -> Dir_string v)));
118105
true)
119106
else false
120-
121-
type dir_conditional = Dir_if_true | Dir_out
122-
123-
(* let string_of_dir_conditional (x : dir_conditional) = *)
124-
(* match x with *)
125-
(* | Dir_if_true -> "Dir_if_true" *)
126-
(* | Dir_if_false -> "Dir_if_false" *)
127-
(* | Dir_out -> "Dir_out" *)
128-
129-
let if_then_else = ref Dir_out
130-
131-
(* store the token after hash, [# token]
132-
when we see `#if` we do the processing immediately
133-
when we see #method, we produce `HASH` token and save `method`
134-
token so that the next lexing produce the right one.
135-
*)
136-
let sharp_look_ahead = ref None
137-
138-
let update_if_then_else v =
139-
(* Format.fprintf Format.err_formatter "@[update %s \n@]@." (string_of_dir_conditional v); *)
140-
if_then_else := v
141-
142-
let at_bol lexbuf =
143-
let pos = Lexing.lexeme_start_p lexbuf in
144-
pos.pos_cnum = pos.pos_bol
145-
146-
let eof_check lexbuf =
147-
if !if_then_else <> Dir_out then
148-
if !if_then_else = Dir_if_true then
149-
raise (Pp_error (Unterminated_if, Location.curr lexbuf))
150-
else raise (Pp_error (Unterminated_else, Location.curr lexbuf))
151-
152-
let init () =
153-
sharp_look_ahead := None;
154-
update_if_then_else Dir_out

compiler/ml/rescript_cpp.mli

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
val at_bol : Lexing.lexbuf -> bool
26-
27-
val eof_check : Lexing.lexbuf -> unit
28-
29-
val init : unit -> unit
30-
3125
(* Methods below are used for cpp, they are not needed by the compiler patches*)
3226
val remove_directive_built_in_value : string -> unit
3327

compiler/ml/syntaxerr.ml

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -15,66 +15,6 @@
1515

1616
(* Auxiliary type for reporting syntax errors *)
1717

18-
type error =
19-
| Unclosed of Location.t * string * Location.t * string
20-
| Expecting of Location.t * string
21-
| Not_expecting of Location.t * string
22-
| Applicative_path of Location.t
23-
| Variable_in_scope of Location.t * string
24-
| Other of Location.t
25-
| Ill_formed_ast of Location.t * string
26-
| Invalid_package_type of Location.t * string
18+
type error = Variable_in_scope of Location.t * string
2719

2820
exception Error of error
29-
exception Escape_error
30-
31-
let prepare_error = function
32-
| Unclosed (opening_loc, opening, closing_loc, closing) ->
33-
Location.errorf ~loc:closing_loc
34-
~sub:
35-
[
36-
Location.errorf ~loc:opening_loc "This '%s' might be unmatched" opening;
37-
]
38-
~if_highlight:
39-
(Printf.sprintf
40-
"Syntax error: '%s' expected, the highlighted '%s' might be \
41-
unmatched"
42-
closing opening)
43-
"Syntax error: '%s' expected" closing
44-
| Expecting (loc, nonterm) ->
45-
Location.errorf ~loc "Syntax error: %s expected." nonterm
46-
| Not_expecting (loc, nonterm) ->
47-
Location.errorf ~loc "Syntax error: %s not expected." nonterm
48-
| Applicative_path loc ->
49-
Location.errorf ~loc
50-
"Syntax error: applicative paths of the form F(X).t are not supported \
51-
when the option -no-app-func is set."
52-
| Variable_in_scope (loc, var) ->
53-
Location.errorf ~loc
54-
"In this scoped type, variable '%s is reserved for the local type %s." var
55-
var
56-
| Other loc -> Location.errorf ~loc "Syntax error"
57-
| Ill_formed_ast (loc, s) ->
58-
Location.errorf ~loc "broken invariant in parsetree: %s" s
59-
| Invalid_package_type (loc, s) ->
60-
Location.errorf ~loc "invalid package type: %s" s
61-
62-
let () =
63-
Location.register_error_of_exn (function
64-
| Error err -> Some (prepare_error err)
65-
| _ -> None)
66-
67-
let report_error ppf err = Location.report_error ppf (prepare_error err)
68-
69-
let location_of_error = function
70-
| Unclosed (l, _, _, _)
71-
| Applicative_path l
72-
| Variable_in_scope (l, _)
73-
| Other l
74-
| Not_expecting (l, _)
75-
| Ill_formed_ast (l, _)
76-
| Invalid_package_type (l, _)
77-
| Expecting (l, _) ->
78-
l
79-
80-
let ill_formed_ast loc s = raise (Error (Ill_formed_ast (loc, s)))

0 commit comments

Comments
 (0)