Add --clang-yojson-file flag

Summary:
:
New flag (equivalent to --clang-biniou-file) to pass in AST to
frontend.

Passing in json files has the big advantage of emitting line numbers
on frontend AST errors.

Reviewed By: jvillard

Differential Revision: D23814358

fbshipit-source-id: 0ad0452ff
master
Martin Trojer 4 years ago committed by Facebook GitHub Bot
parent 8c40ed53d7
commit 671d9fa291

@ -223,7 +223,9 @@ CLANG LINTERS OPTIONS
--no-linters-validate-syntax-only)
CLANG OPTIONS
--clang-biniou-file file
Specify a file containing the AST of the program, in biniou format
Specify a file containing the AST of the program, in biniou
format. Please note you still need to provide a compilation
command.
--clang-blacklisted-flags +string
Clang flags to filter out
@ -236,6 +238,11 @@ CLANG OPTIONS
arrays) is not done element by element but using a builtin
function that each analysis has to model.
--clang-yojson-file file
Specify a file containing the AST of the program, in yojson
format. Please note you still need to provide a compilation
command.
--compilation-database +path
File that contain compilation commands (can be specified multiple
times)

@ -220,8 +220,9 @@ OPTIONS
relative to project root or be absolute See also infer-analyze(1).
--clang-biniou-file file
Specify a file containing the AST of the program, in biniou format
See also infer-capture(1).
Specify a file containing the AST of the program, in biniou
format. Please note you still need to provide a compilation
command. See also infer-capture(1).
--clang-blacklisted-flags +string
Clang flags to filter out See also infer-capture(1).
@ -234,6 +235,11 @@ OPTIONS
arrays) is not done element by element but using a builtin
function that each analysis has to model. See also infer-analyze(1) and infer-capture(1).
--clang-yojson-file file
Specify a file containing the AST of the program, in yojson
format. Please note you still need to provide a compilation
command. See also infer-capture(1).
--compilation-database +path
File that contain compilation commands (can be specified multiple
times) See also infer-capture(1).
@ -1371,6 +1377,9 @@ INTERNAL OPTIONS
--clang-libcxx-include-to-override-regex-reset
Cancel the effect of --clang-libcxx-include-to-override-regex.
--clang-yojson-file-reset
Cancel the effect of --clang-yojson-file.
--classpath string
Specify the Java classpath

@ -220,8 +220,9 @@ OPTIONS
relative to project root or be absolute See also infer-analyze(1).
--clang-biniou-file file
Specify a file containing the AST of the program, in biniou format
See also infer-capture(1).
Specify a file containing the AST of the program, in biniou
format. Please note you still need to provide a compilation
command. See also infer-capture(1).
--clang-blacklisted-flags +string
Clang flags to filter out See also infer-capture(1).
@ -234,6 +235,11 @@ OPTIONS
arrays) is not done element by element but using a builtin
function that each analysis has to model. See also infer-analyze(1) and infer-capture(1).
--clang-yojson-file file
Specify a file containing the AST of the program, in yojson
format. Please note you still need to provide a compilation
command. See also infer-capture(1).
--compilation-database +path
File that contain compilation commands (can be specified multiple
times) See also infer-capture(1).

@ -824,7 +824,9 @@ and check_version =
and clang_biniou_file =
CLOpt.mk_path_opt ~long:"clang-biniou-file"
~in_help:InferCommand.[(Capture, manual_clang)]
~meta:"file" "Specify a file containing the AST of the program, in biniou format"
~meta:"file"
"Specify a file containing the AST of the program, in biniou format. Please note you still \
need to provide a compilation command."
and clang_compound_literal_init_limit =
@ -894,6 +896,14 @@ and clang_libcxx_include_to_override_regex =
$(b,-I /path/to/infer/facebook-clang-plugins/clang/install/include/c++/v1)."
and clang_yojson_file =
CLOpt.mk_path_opt ~long:"clang-yojson-file"
~in_help:InferCommand.[(Capture, manual_clang)]
~meta:"file"
"Specify a file containing the AST of the program, in yojson format. Please note you still \
need to provide a compilation command."
and classpath = CLOpt.mk_string_opt ~long:"classpath" "Specify the Java classpath"
and compilation_database =
@ -2737,7 +2747,17 @@ and check_version = !check_version
and checkers = List.map !all_checkers ~f:(fun (checker, _, var) -> (checker, !var))
and clang_biniou_file = !clang_biniou_file
and clang_ast_file =
match (!clang_biniou_file, !clang_yojson_file) with
| Some _, Some _ ->
L.die UserError "Please provide only one of --clang-biniou-file and --clang-yojson-file"
| Some b, _ ->
Some (`Biniou b)
| _, Some y ->
Some (`Yojson y)
| _ ->
None
and clang_compilation_dbs = !clang_compilation_dbs

@ -200,7 +200,7 @@ val changed_files_index : string option
val check_version : string option
val clang_biniou_file : string option
val clang_ast_file : [`Biniou of string | `Yojson of string] option
val clang_compound_literal_init_limit : int

@ -14,9 +14,13 @@ let debug_mode = Config.debug_mode || Config.frontend_stats
(** This function reads the json file in fname, validates it, and encodes in the AST data structure
defined in Clang_ast_t. *)
let validate_decl_from_file fname =
let validate_decl_from_file file =
match file with
| `Biniou fname ->
Atdgen_runtime.Util.Biniou.from_file ~len:CFrontend_config.biniou_buffer_size
Clang_ast_b.read_decl fname
| `Yojson fname ->
Atdgen_runtime.Util.Json.from_file Clang_ast_j.read_decl fname
let validate_decl_from_channel chan =
@ -38,9 +42,9 @@ let run_clang_frontend ast_source =
in
let ast_decl =
match ast_source with
| `File path ->
validate_decl_from_file path
| `Pipe chan ->
| `File file ->
validate_decl_from_file file
| `BiniouPipe chan ->
validate_decl_from_channel chan
in
let trans_unit_ctx =
@ -76,9 +80,9 @@ let run_clang_frontend ast_source =
in
let pp_ast_filename fmt ast_source =
match ast_source with
| `File path ->
| `File (`Biniou path) | `File (`Yojson path) ->
Format.pp_print_string fmt path
| `Pipe _ ->
| `BiniouPipe _ ->
Format.fprintf fmt "stdin of %a" SourceFile.pp trans_unit_ctx.CFrontend_config.source_file
in
ClangPointers.populate_all_tables ast_decl ;
@ -176,12 +180,12 @@ let cc1_capture clang_cmd =
L.(debug Capture Quiet) "@\n Skip compilation and analysis of source file %s@\n@\n" source_path ;
() )
else
match Config.clang_biniou_file with
match Config.clang_ast_file with
| Some fname ->
run_and_validate_clang_frontend (`File fname)
| None ->
run_plugin_and_frontend source_path
(fun chan_in -> run_and_validate_clang_frontend (`Pipe chan_in))
(fun chan_in -> run_and_validate_clang_frontend (`BiniouPipe chan_in))
clang_cmd

Loading…
Cancel
Save