[clang] Make sl_file store source file instead of string

Summary:
Make sl_file field strongly typed in the AST - store SourceFile.t instead of string. This will make it harder
to access raw string which shouldn't really be accessed before going through `SourceFile` module

Reviewed By: jvillard

Differential Revision: D4299468

fbshipit-source-id: e8ff87e
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent 831786240a
commit 78dfe85468

@ -1 +1 @@
Subproject commit 0de6a068f2a70a09eebe7364017ce3fe8d8652ab
Subproject commit 7d55695bb0cbd821ae0acc33db5a6982abd2da3a

@ -67,7 +67,7 @@ let run_clang_frontend ast_source => {
switch ast_decl {
| Clang_ast_t.TranslationUnitDecl (_, _, _, info) =>
Config.arc_mode := info.Clang_ast_t.tudi_arc_enabled;
let source_file = SourceFile.from_abs_path info.Clang_ast_t.tudi_input_path;
let source_file = info.Clang_ast_t.tudi_input_path;
init_global_state_for_capture_and_linters source_file;
let lang =
switch info.Clang_ast_t.tudi_input_kind {

@ -24,10 +24,8 @@ let is_in_main_file translation_unit_context an =
match file_opt with
| None ->
false
| Some file ->
SourceFile.equal
(SourceFile.from_abs_path file)
translation_unit_context.CFrontend_config.source_file
| Some source_file ->
SourceFile.equal source_file translation_unit_context.CFrontend_config.source_file
let is_ck_context (context: CLintersContext.context) an =
context.is_ck_translation_unit

@ -654,18 +654,13 @@ struct
| _ -> assert false)
let mk_procname_from_function translation_unit_context name function_decl_info_opt =
let get_rel_file_path file_opt =
match file_opt with
| Some file ->
SourceFile.to_string (SourceFile.from_abs_path file)
| None -> "" in
let file =
match function_decl_info_opt with
| Some (decl_info, function_decl_info) ->
(match function_decl_info.Clang_ast_t.fdi_storage_class with
| Some "static" ->
let file_opt = (fst decl_info.Clang_ast_t.di_source_range).Clang_ast_t.sl_file in
get_rel_file_path file_opt
Option.map_default SourceFile.to_string "" file_opt
| _ -> "")
| None -> "" in
let mangled_opt = match function_decl_info_opt with

@ -14,8 +14,8 @@ open! Utils
let clang_to_sil_location trans_unit_ctx clang_loc =
let line = Option.default (-1) clang_loc.Clang_ast_t.sl_line in
let col = Option.default (-1) clang_loc.Clang_ast_t.sl_column in
let file = Option.map_default SourceFile.from_abs_path
trans_unit_ctx.CFrontend_config.source_file clang_loc.Clang_ast_t.sl_file in
let file =
Option.default trans_unit_ctx.CFrontend_config.source_file clang_loc.Clang_ast_t.sl_file in
Location.{line; col; file}
let source_file_in_project source_file =
@ -29,8 +29,7 @@ let source_file_in_project source_file =
let should_do_frontend_check trans_unit_ctx (loc_start, _) =
match loc_start.Clang_ast_t.sl_file with
| Some file ->
let source_file = (SourceFile.from_abs_path file) in
| Some source_file ->
SourceFile.equal source_file trans_unit_ctx.CFrontend_config.source_file ||
(source_file_in_project source_file && not Config.testing_mode)
| None -> false
@ -40,15 +39,11 @@ let should_do_frontend_check trans_unit_ctx (loc_start, _) =
translate the headers because the dot files in the frontend tests should contain nothing else
than the source file to avoid conflicts between different versions of the libraries. *)
let should_translate trans_unit_ctx (loc_start, loc_end) decl_trans_context ~translate_when_used =
let map_path_of pred loc =
let map_file_of pred loc =
match loc.Clang_ast_t.sl_file with
| Some f -> pred f
| None -> false
in
let map_file_of pred loc =
let path_pred path = pred (SourceFile.from_abs_path path) in
map_path_of path_pred loc
in
(* it's not necessary to compare inodes here because both files come from
the same context - they are produced by the same invocation of ASTExporter
which uses same logic to produce both files *)

@ -55,3 +55,12 @@ let pointer_to_type_ptr raw = `TPtr raw
let type_ptr_to_pointer type_ptr = match type_ptr with
| `TPtr raw -> raw
| _ -> 0 (* invalid pointer *)
(* Source files *)
type src_file = SourceFile.t
let source_file_of_string = SourceFile.from_abs_path
let string_of_source_file = SourceFile.to_abs_path

Loading…
Cancel
Save