[clang] Get translation unit language from AST dump

Summary:
New version of clang plugin exports `-x` arg information as a part of
TranslationUnitDecl. Get it from there instead of reading it from
clang argv

Reviewed By: jvillard

Differential Revision: D4112652

fbshipit-source-id: 5c3af1f
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent b876364340
commit 28827b461a

@ -1 +1 @@
Subproject commit cfc10b4671001d4006500e3074e2ef4143dfaa56
Subproject commit 51d94e94e376f185914e4d041d2cf5dce8735726

@ -57,19 +57,38 @@ let init_global_state_for_capture_and_linters source_file => {
CFrontend_config.reset_global_state ()
};
let run_clang_frontend trans_unit_ctx ast_source => {
let run_clang_frontend ast_source => {
let init_time = Unix.gettimeofday ();
let print_elapsed () => {
let elapsed = Unix.gettimeofday () -. init_time;
Logging.out "Elapsed: %07.3f seconds.@\n" elapsed
};
let (ast_filename, ast_decl) =
let ast_decl =
switch ast_source {
| `File path => (path, validate_decl_from_file path)
| `Pipe chan => (
"stdin of " ^ DB.source_file_to_string trans_unit_ctx.CFrontend_config.source_file,
validate_decl_from_channel chan
)
| `File path => validate_decl_from_file path
| `Pipe chan => validate_decl_from_channel chan
};
let trans_unit_ctx =
switch ast_decl {
| Clang_ast_t.TranslationUnitDecl (_, _, _, info) =>
Config.arc_mode := info.Clang_ast_t.tudi_arc_enabled;
let source_file = CLocation.source_file_from_path 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 {
| `IK_C => CFrontend_config.C
| `IK_CXX => CFrontend_config.CPP
| `IK_ObjC => CFrontend_config.ObjC
| `IK_ObjCXX => CFrontend_config.ObjCPP
| _ => assert false
};
{CFrontend_config.source_file: source_file, lang}
| _ => assert false
};
let ast_filename =
switch ast_source {
| `File path => path
| `Pipe _ => "stdin of " ^ DB.source_file_to_string trans_unit_ctx.CFrontend_config.source_file
};
let (decl_index, stmt_index, type_index, ivar_to_property_index) = Clang_ast_main.index_node_pointers ast_decl;
CFrontend_config.pointer_decl_index := decl_index;
@ -150,31 +169,11 @@ let cc1_capture clang_cmd => {
/* We still need to run clang, but we don't have to attach the plugin. */
run_clang (ClangCommand.command_to_run clang_cmd) consume_in
} else {
let source_file = CLocation.source_file_from_path source_path;
init_global_state_for_capture_and_linters source_file;
let trans_unit_ctx = {
let clang_langs =
CFrontend_config.[
("c", C),
("objective-c", ObjC),
("c++", CPP),
("objective-c++", ObjCPP)
];
let lang =
switch (ClangCommand.value_of_option clang_cmd "-x") {
| Some lang_opt when IList.mem_assoc string_equal lang_opt clang_langs =>
IList.assoc string_equal lang_opt clang_langs
| _ => assert false
};
{CFrontend_config.source_file: source_file, lang}
};
Config.arc_mode := ClangCommand.has_flag clang_cmd "-fobjc-arc";
try (
switch Config.clang_biniou_file {
| Some fname => run_clang_frontend trans_unit_ctx (`File fname)
| Some fname => run_clang_frontend (`File fname)
| None =>
run_plugin_and_frontend
(fun chan_in => run_clang_frontend trans_unit_ctx (`Pipe chan_in)) clang_cmd
run_plugin_and_frontend (fun chan_in => run_clang_frontend (`Pipe chan_in)) clang_cmd
}
) {
| exc =>

@ -1,16 +1,5 @@
/* @generated */
digraph iCFG {
"binary_conditional::X_operator_bool().26194e934cee38706ccb5138bd5b3320_3" [label="3: Return Stmt \n *&return:_Bool =1 [line 13]\n " shape="box"]
"binary_conditional::X_operator_bool().26194e934cee38706ccb5138bd5b3320_3" -> "binary_conditional::X_operator_bool().26194e934cee38706ccb5138bd5b3320_2" ;
"binary_conditional::X_operator_bool().26194e934cee38706ccb5138bd5b3320_2" [label="2: Exit binary_conditional::X_operator_bool \n " color=yellow style=filled]
"binary_conditional::X_operator_bool().26194e934cee38706ccb5138bd5b3320_1" [label="1: Start binary_conditional::X_operator_bool\nFormals: this:class binary_conditional::X *\nLocals: \n DECLARE_LOCALS(&return); [line 13]\n " color=yellow style=filled]
"binary_conditional::X_operator_bool().26194e934cee38706ccb5138bd5b3320_1" -> "binary_conditional::X_operator_bool().26194e934cee38706ccb5138bd5b3320_3" ;
"binary_conditional::X_X{_ZN18binary_conditional1XC1EOS0_}.4bd5b5f6d082e3a4895874a95aa2bc28_2" [label="2: Exit binary_conditional::X_X \n " color=yellow style=filled]
@ -124,6 +113,17 @@ digraph iCFG {
"binary_conditional::binaryConditional{d41d8cd98f00b204e9800998ecf8427e_ZN18binary_conditional17binar.09917000e376be5dfbf0e2b7b90db84c_1" -> "binary_conditional::binaryConditional{d41d8cd98f00b204e9800998ecf8427e_ZN18binary_conditional17binar.09917000e376be5dfbf0e2b7b90db84c_11" ;
"binary_conditional::X_operator_bool(_ZN18binary_conditional1XcvbEv).ac4783c70fd7f052bb11fb683aec2300_3" [label="3: Return Stmt \n *&return:_Bool =1 [line 13]\n " shape="box"]
"binary_conditional::X_operator_bool(_ZN18binary_conditional1XcvbEv).ac4783c70fd7f052bb11fb683aec2300_3" -> "binary_conditional::X_operator_bool(_ZN18binary_conditional1XcvbEv).ac4783c70fd7f052bb11fb683aec2300_2" ;
"binary_conditional::X_operator_bool(_ZN18binary_conditional1XcvbEv).ac4783c70fd7f052bb11fb683aec2300_2" [label="2: Exit binary_conditional::X_operator_bool \n " color=yellow style=filled]
"binary_conditional::X_operator_bool(_ZN18binary_conditional1XcvbEv).ac4783c70fd7f052bb11fb683aec2300_1" [label="1: Start binary_conditional::X_operator_bool\nFormals: this:class binary_conditional::X *\nLocals: \n DECLARE_LOCALS(&return); [line 13]\n " color=yellow style=filled]
"binary_conditional::X_operator_bool(_ZN18binary_conditional1XcvbEv).ac4783c70fd7f052bb11fb683aec2300_1" -> "binary_conditional::X_operator_bool(_ZN18binary_conditional1XcvbEv).ac4783c70fd7f052bb11fb683aec2300_3" ;
"binary_conditional::X_X{_ZN18binary_conditional1XC1ERKS0_}.0e1cd4b0d7172e9f75221a1b50d4832a_2" [label="2: Exit binary_conditional::X_X \n " color=yellow style=filled]

@ -1,16 +1,5 @@
/* @generated */
digraph iCFG {
"conversion_operator::X_operator_bool().00e540367bff1fbadaa13ac2454e80d7_3" [label="3: Return Stmt \n n$0=*&this:class conversion_operator::X * [line 14]\n n$1=*n$0.b_:_Bool [line 14]\n *&return:_Bool =n$1 [line 14]\n " shape="box"]
"conversion_operator::X_operator_bool().00e540367bff1fbadaa13ac2454e80d7_3" -> "conversion_operator::X_operator_bool().00e540367bff1fbadaa13ac2454e80d7_2" ;
"conversion_operator::X_operator_bool().00e540367bff1fbadaa13ac2454e80d7_2" [label="2: Exit conversion_operator::X_operator_bool \n " color=yellow style=filled]
"conversion_operator::X_operator_bool().00e540367bff1fbadaa13ac2454e80d7_1" [label="1: Start conversion_operator::X_operator_bool\nFormals: this:class conversion_operator::X *\nLocals: \n DECLARE_LOCALS(&return); [line 14]\n " color=yellow style=filled]
"conversion_operator::X_operator_bool().00e540367bff1fbadaa13ac2454e80d7_1" -> "conversion_operator::X_operator_bool().00e540367bff1fbadaa13ac2454e80d7_3" ;
"conversion_operator::branch_div1{d41d8cd98f00b204e9800998ecf8427e_ZN19conversion_operator11branch_di.49bb4aa865fa63a218f0c61093e085ce_10" [label="10: DeclStmt \n _fun_conversion_operator::X_X(&x:class conversion_operator::X *,1:int ,1:_Bool ) [line 64]\n " shape="box"]
@ -51,17 +40,6 @@ digraph iCFG {
"conversion_operator::branch_div1{d41d8cd98f00b204e9800998ecf8427e_ZN19conversion_operator11branch_di.49bb4aa865fa63a218f0c61093e085ce_1" -> "conversion_operator::branch_div1{d41d8cd98f00b204e9800998ecf8427e_ZN19conversion_operator11branch_di.49bb4aa865fa63a218f0c61093e085ce_10" ;
"conversion_operator::Y_operator_X().40149ec18131e01f9ee1290714a1eb8a_3" [label="3: Return Stmt \n n$0=*&__return_param:class conversion_operator::X * [line 29]\n n$2=*&this:class conversion_operator::Y * [line 29]\n n$3=*n$2.f:int [line 29]\n n$4=*&this:class conversion_operator::Y * [line 29]\n n$5=*n$4.b:int [line 29]\n _fun_conversion_operator::X_X(&0$?%__sil_tmpSIL_materialize_temp__n$1:class conversion_operator::X *,n$3:int ,n$5:_Bool ) [line 29]\n _fun_conversion_operator::X_X(n$0:class conversion_operator::X *,&0$?%__sil_tmpSIL_materialize_temp__n$1:class conversion_operator::X &) [line 29]\n " shape="box"]
"conversion_operator::Y_operator_X().40149ec18131e01f9ee1290714a1eb8a_3" -> "conversion_operator::Y_operator_X().40149ec18131e01f9ee1290714a1eb8a_2" ;
"conversion_operator::Y_operator_X().40149ec18131e01f9ee1290714a1eb8a_2" [label="2: Exit conversion_operator::Y_operator_X \n " color=yellow style=filled]
"conversion_operator::Y_operator_X().40149ec18131e01f9ee1290714a1eb8a_1" [label="1: Start conversion_operator::Y_operator_X\nFormals: this:class conversion_operator::Y * __return_param:class conversion_operator::X *\nLocals: 0$?%__sil_tmpSIL_materialize_temp__n$1:class conversion_operator::X \n DECLARE_LOCALS(&return,&0$?%__sil_tmpSIL_materialize_temp__n$1); [line 29]\n " color=yellow style=filled]
"conversion_operator::Y_operator_X().40149ec18131e01f9ee1290714a1eb8a_1" -> "conversion_operator::Y_operator_X().40149ec18131e01f9ee1290714a1eb8a_3" ;
"conversion_operator::X_X{_ZN19conversion_operator1XC1Eib}.aec165e5824e20faf9037780940ace67_4" [label="4: BinaryOperatorStmt: Assign \n n$2=*&this:class conversion_operator::X * [line 18]\n n$3=*&f:int [line 18]\n *n$2.f_:int =n$3 [line 18]\n " shape="box"]
@ -84,17 +62,6 @@ digraph iCFG {
"conversion_operator::Y_Y{_ZN19conversion_operator1YC1Ev}.1f3cad4203d46e6505f777a349285227_1" -> "conversion_operator::Y_Y{_ZN19conversion_operator1YC1Ev}.1f3cad4203d46e6505f777a349285227_2" ;
"conversion_operator::X_operator_int().f7081daa0c82e83b0049729091530a89_3" [label="3: Return Stmt \n n$0=*&this:class conversion_operator::X * [line 13]\n n$1=*n$0.f_:int [line 13]\n *&return:int =n$1 [line 13]\n " shape="box"]
"conversion_operator::X_operator_int().f7081daa0c82e83b0049729091530a89_3" -> "conversion_operator::X_operator_int().f7081daa0c82e83b0049729091530a89_2" ;
"conversion_operator::X_operator_int().f7081daa0c82e83b0049729091530a89_2" [label="2: Exit conversion_operator::X_operator_int \n " color=yellow style=filled]
"conversion_operator::X_operator_int().f7081daa0c82e83b0049729091530a89_1" [label="1: Start conversion_operator::X_operator_int\nFormals: this:class conversion_operator::X *\nLocals: \n DECLARE_LOCALS(&return); [line 13]\n " color=yellow style=filled]
"conversion_operator::X_operator_int().f7081daa0c82e83b0049729091530a89_1" -> "conversion_operator::X_operator_int().f7081daa0c82e83b0049729091530a89_3" ;
"conversion_operator::X_X{_ZN19conversion_operator1XC1ERKS0_}.fe390674b98626da24bd8250d67e0242_4" [label="4: BinaryOperatorStmt: Assign \n n$3=*&this:class conversion_operator::X * [line 22]\n n$4=*&x:class conversion_operator::X & [line 22]\n n$5=*n$4.f_:int [line 22]\n *n$3.f_:int =n$5 [line 22]\n " shape="box"]
@ -150,6 +117,28 @@ digraph iCFG {
"conversion_operator::branch_div0{d41d8cd98f00b204e9800998ecf8427e_ZN19conversion_operator11branch_di.aa14f8ff40589026a7de7bcf7f056961_1" -> "conversion_operator::branch_div0{d41d8cd98f00b204e9800998ecf8427e_ZN19conversion_operator11branch_di.aa14f8ff40589026a7de7bcf7f056961_10" ;
"conversion_operator::Y_operator_X(_ZN19conversion_operator1YcvNS_1XEEv).7fbfbd377b227fbeead158d94909d990_3" [label="3: Return Stmt \n n$0=*&__return_param:class conversion_operator::X * [line 29]\n n$2=*&this:class conversion_operator::Y * [line 29]\n n$3=*n$2.f:int [line 29]\n n$4=*&this:class conversion_operator::Y * [line 29]\n n$5=*n$4.b:int [line 29]\n _fun_conversion_operator::X_X(&0$?%__sil_tmpSIL_materialize_temp__n$1:class conversion_operator::X *,n$3:int ,n$5:_Bool ) [line 29]\n _fun_conversion_operator::X_X(n$0:class conversion_operator::X *,&0$?%__sil_tmpSIL_materialize_temp__n$1:class conversion_operator::X &) [line 29]\n " shape="box"]
"conversion_operator::Y_operator_X(_ZN19conversion_operator1YcvNS_1XEEv).7fbfbd377b227fbeead158d94909d990_3" -> "conversion_operator::Y_operator_X(_ZN19conversion_operator1YcvNS_1XEEv).7fbfbd377b227fbeead158d94909d990_2" ;
"conversion_operator::Y_operator_X(_ZN19conversion_operator1YcvNS_1XEEv).7fbfbd377b227fbeead158d94909d990_2" [label="2: Exit conversion_operator::Y_operator_X \n " color=yellow style=filled]
"conversion_operator::Y_operator_X(_ZN19conversion_operator1YcvNS_1XEEv).7fbfbd377b227fbeead158d94909d990_1" [label="1: Start conversion_operator::Y_operator_X\nFormals: this:class conversion_operator::Y * __return_param:class conversion_operator::X *\nLocals: 0$?%__sil_tmpSIL_materialize_temp__n$1:class conversion_operator::X \n DECLARE_LOCALS(&return,&0$?%__sil_tmpSIL_materialize_temp__n$1); [line 29]\n " color=yellow style=filled]
"conversion_operator::Y_operator_X(_ZN19conversion_operator1YcvNS_1XEEv).7fbfbd377b227fbeead158d94909d990_1" -> "conversion_operator::Y_operator_X(_ZN19conversion_operator1YcvNS_1XEEv).7fbfbd377b227fbeead158d94909d990_3" ;
"conversion_operator::X_operator_int(_ZN19conversion_operator1XcviEv).5fd445c29c23d75d880cde3646c3c635_3" [label="3: Return Stmt \n n$0=*&this:class conversion_operator::X * [line 13]\n n$1=*n$0.f_:int [line 13]\n *&return:int =n$1 [line 13]\n " shape="box"]
"conversion_operator::X_operator_int(_ZN19conversion_operator1XcviEv).5fd445c29c23d75d880cde3646c3c635_3" -> "conversion_operator::X_operator_int(_ZN19conversion_operator1XcviEv).5fd445c29c23d75d880cde3646c3c635_2" ;
"conversion_operator::X_operator_int(_ZN19conversion_operator1XcviEv).5fd445c29c23d75d880cde3646c3c635_2" [label="2: Exit conversion_operator::X_operator_int \n " color=yellow style=filled]
"conversion_operator::X_operator_int(_ZN19conversion_operator1XcviEv).5fd445c29c23d75d880cde3646c3c635_1" [label="1: Start conversion_operator::X_operator_int\nFormals: this:class conversion_operator::X *\nLocals: \n DECLARE_LOCALS(&return); [line 13]\n " color=yellow style=filled]
"conversion_operator::X_operator_int(_ZN19conversion_operator1XcviEv).5fd445c29c23d75d880cde3646c3c635_1" -> "conversion_operator::X_operator_int(_ZN19conversion_operator1XcviEv).5fd445c29c23d75d880cde3646c3c635_3" ;
"conversion_operator::y_branch_div0{d41d8cd98f00b204e9800998ecf8427e_ZN19conversion_operator13y_branc.7a76ee17fb27e50abb4de1e42987b12a_12" [label="12: DeclStmt \n _fun_conversion_operator::Y_Y(&y:class conversion_operator::Y *) [line 44]\n " shape="box"]
@ -198,6 +187,17 @@ digraph iCFG {
"conversion_operator::y_branch_div0{d41d8cd98f00b204e9800998ecf8427e_ZN19conversion_operator13y_branc.7a76ee17fb27e50abb4de1e42987b12a_1" -> "conversion_operator::y_branch_div0{d41d8cd98f00b204e9800998ecf8427e_ZN19conversion_operator13y_branc.7a76ee17fb27e50abb4de1e42987b12a_12" ;
"conversion_operator::X_operator_bool(_ZN19conversion_operator1XcvbEv).07ddb8d49a563ab5f06ea9514f6d1fc2_3" [label="3: Return Stmt \n n$0=*&this:class conversion_operator::X * [line 14]\n n$1=*n$0.b_:_Bool [line 14]\n *&return:_Bool =n$1 [line 14]\n " shape="box"]
"conversion_operator::X_operator_bool(_ZN19conversion_operator1XcvbEv).07ddb8d49a563ab5f06ea9514f6d1fc2_3" -> "conversion_operator::X_operator_bool(_ZN19conversion_operator1XcvbEv).07ddb8d49a563ab5f06ea9514f6d1fc2_2" ;
"conversion_operator::X_operator_bool(_ZN19conversion_operator1XcvbEv).07ddb8d49a563ab5f06ea9514f6d1fc2_2" [label="2: Exit conversion_operator::X_operator_bool \n " color=yellow style=filled]
"conversion_operator::X_operator_bool(_ZN19conversion_operator1XcvbEv).07ddb8d49a563ab5f06ea9514f6d1fc2_1" [label="1: Start conversion_operator::X_operator_bool\nFormals: this:class conversion_operator::X *\nLocals: \n DECLARE_LOCALS(&return); [line 14]\n " color=yellow style=filled]
"conversion_operator::X_operator_bool(_ZN19conversion_operator1XcvbEv).07ddb8d49a563ab5f06ea9514f6d1fc2_1" -> "conversion_operator::X_operator_bool(_ZN19conversion_operator1XcvbEv).07ddb8d49a563ab5f06ea9514f6d1fc2_3" ;
"conversion_operator::branch_no_div{d41d8cd98f00b204e9800998ecf8427e_ZN19conversion_operator13branch_.3ae06ed300032a64309733e89d1480e2_10" [label="10: DeclStmt \n _fun_conversion_operator::X_X(&x:class conversion_operator::X *,0:int ,0:_Bool ) [line 55]\n " shape="box"]

@ -62,17 +62,6 @@ digraph iCFG {
"std::nested_exception_nested_ptr(_ZNKSt16nested_exception10nested_ptrEv).12828a0743e5fd75c5b689210764dac7_1" -> "std::nested_exception_nested_ptr(_ZNKSt16nested_exception10nested_ptrEv).12828a0743e5fd75c5b689210764dac7_3" ;
"std::exception_ptr_operator_bool().9300441b9a37203c88b8a46c108119d0_3" [label="3: Return Stmt \n n$0=*&this:class std::exception_ptr * [line 138]\n n$1=*n$0.__ptr_:void * [line 138]\n *&return:_Bool =(n$1 != null) [line 138]\n " shape="box"]
"std::exception_ptr_operator_bool().9300441b9a37203c88b8a46c108119d0_3" -> "std::exception_ptr_operator_bool().9300441b9a37203c88b8a46c108119d0_2" ;
"std::exception_ptr_operator_bool().9300441b9a37203c88b8a46c108119d0_2" [label="2: Exit std::exception_ptr_operator_bool \n " color=yellow style=filled]
"std::exception_ptr_operator_bool().9300441b9a37203c88b8a46c108119d0_1" [label="1: Start std::exception_ptr_operator_bool\nFormals: this:class std::exception_ptr *\nLocals: \n DECLARE_LOCALS(&return); [line 136]\n " color=yellow style=filled]
"std::exception_ptr_operator_bool().9300441b9a37203c88b8a46c108119d0_1" -> "std::exception_ptr_operator_bool().9300441b9a37203c88b8a46c108119d0_3" ;
"std::__1::__convert_to_integral{d41d8cd98f00b204e9800998ecf8427e_ZNSt3__121__convert_to_integralEi}.65bc03ff4b5c7c87c05f0ddf70269c40_3" [label="3: Return Stmt \n n$0=*&__val:int [line 4310]\n *&return:int =n$0 [line 4310]\n " shape="box"]
@ -326,6 +315,17 @@ digraph iCFG {
"std::__1::__convert_to_integral{d41d8cd98f00b204e9800998ecf8427e_ZNSt3__121__convert_to_integralEo}.ea63971267d44b573f5b71db4f63f67c_1" -> "std::__1::__convert_to_integral{d41d8cd98f00b204e9800998ecf8427e_ZNSt3__121__convert_to_integralEo}.ea63971267d44b573f5b71db4f63f67c_3" ;
"std::exception_ptr_operator_bool(_ZNKSt13exception_ptrcvbEv).c9db5a2ded6ab67a25c6ff043ae93f6b_3" [label="3: Return Stmt \n n$0=*&this:class std::exception_ptr * [line 138]\n n$1=*n$0.__ptr_:void * [line 138]\n *&return:_Bool =(n$1 != null) [line 138]\n " shape="box"]
"std::exception_ptr_operator_bool(_ZNKSt13exception_ptrcvbEv).c9db5a2ded6ab67a25c6ff043ae93f6b_3" -> "std::exception_ptr_operator_bool(_ZNKSt13exception_ptrcvbEv).c9db5a2ded6ab67a25c6ff043ae93f6b_2" ;
"std::exception_ptr_operator_bool(_ZNKSt13exception_ptrcvbEv).c9db5a2ded6ab67a25c6ff043ae93f6b_2" [label="2: Exit std::exception_ptr_operator_bool \n " color=yellow style=filled]
"std::exception_ptr_operator_bool(_ZNKSt13exception_ptrcvbEv).c9db5a2ded6ab67a25c6ff043ae93f6b_1" [label="1: Start std::exception_ptr_operator_bool\nFormals: this:class std::exception_ptr *\nLocals: \n DECLARE_LOCALS(&return); [line 136]\n " color=yellow style=filled]
"std::exception_ptr_operator_bool(_ZNKSt13exception_ptrcvbEv).c9db5a2ded6ab67a25c6ff043ae93f6b_1" -> "std::exception_ptr_operator_bool(_ZNKSt13exception_ptrcvbEv).c9db5a2ded6ab67a25c6ff043ae93f6b_3" ;
"std::exception_ptr_exception_ptr{_ZNSt13exception_ptrC1Ev}.b75c8b23eb693a539de1c8e713bd6159_3" [label="3: Constructor Init \n n$0=*&this:class std::exception_ptr * [line 130]\n *n$0.__ptr_:void *=null [line 130]\n " shape="box"]

Loading…
Cancel
Save