Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tools/compiler_version.ml
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,15 @@ let known_versions =

let is_known v = List.mem v known_versions

let is_known_release {major; minor; _} =
List.exists (fun { major = major'; minor = minor'; _ } ->
major = major' && minor = minor') known_versions

let is_development _ = false

let make x y z extra_info =
let v = mk x y z in
if is_known v then { v with extra_info } else raise Not_found
{ v with extra_info }

let to_string { major; minor; patch_level; extra_info } =
let printer = Printf.sprintf in
Expand Down
2 changes: 2 additions & 0 deletions tools/compiler_version.mli
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ val known_versions : t list

val is_known : t -> bool

val is_known_release : t -> bool

val is_development : t -> bool

val major : t -> int
Expand Down
23 changes: 15 additions & 8 deletions tools/stdcompatpp.mll
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type options = {
debug : bool;
}

let init_options () = {
compiler_version = Compiler_version.of_string Sys.ocaml_version;
let init_options compiler_version = {
compiler_version;
source_type = OCaml;
debug = false;
}
Expand All @@ -40,11 +40,11 @@ let dprintf options fmt =
printer stderr fmt

let set_compiler_version opts version =
let compiler_version =
try Compiler_version.of_string version with
_ -> unknown "compiler version" version
in
opts := { !opts with compiler_version }
let compiler_version = Compiler_version.of_string version in
if Compiler_version.is_known compiler_version then
opts := { !opts with compiler_version }
else
unknown "compiler version" version

let set_source_type opts source_type =
let source_type =
Expand Down Expand Up @@ -339,7 +339,14 @@ and c_lexer options state = parse
{

let main () =
let options = init_options () |> parse_commandline in
let compiler_version = Compiler_version.of_string Sys.ocaml_version in
let compiler_version =
if Compiler_version.is_known_release compiler_version then
compiler_version
else
List.hd (List.rev Compiler_version.known_versions)
in
let options = init_options compiler_version |> parse_commandline in
let lexer = match options.source_type with
| OCaml -> ocaml_lexer
| C -> c_lexer
Expand Down