@ -36,28 +36,49 @@ let clang_proc_of_decl decl =
None
let process_ast ast default_source_file =
let rec process_block_decls_in_stmts default_source_file ast_range stmts =
let open Clang_ast_t in
let rec extract_location ast_range decl =
match decl with
| ObjCMethodDecl ( di , _ , _ )
| CXXConversionDecl ( di , _ , _ , _ , _ )
| FunctionDecl ( di , _ , _ , _ )
| CXXMethodDecl ( di , _ , _ , _ , _ )
| CXXConstructorDecl ( di , _ , _ , _ , _ )
| CXXDestructorDecl ( di , _ , _ , _ , _ )
| BlockDecl ( di , _ ) ->
let range = CLocation . location_of_decl_info default_source_file di in
let procname = CType_decl . CProcname . from_decl decl in
let clang_proc = clang_proc_of_decl decl in
Typ . Procname . Map . add procname ( range , clang_proc ) ast_range
| _ -> (
match Clang_ast_proj . get_decl_context_tuple decl with
| Some ( decls , _ ) ->
List . fold decls ~ f : extract_location ~ init : ast_range
| None ->
ast_range )
let process_decls_in_stmt ast_range stmt =
let _ , stmts = Clang_ast_proj . get_stmt_tuple stmt in
let ast_range' = process_block_decls_in_stmts default_source_file ast_range stmts in
match stmt with
| BlockExpr ( _ , _ , _ , decl ) ->
process_proc_decl default_source_file ast_range' decl
| _ ->
ast_range'
in
List . fold ~ f : process_decls_in_stmt ~ init : ast_range stmts
and process_proc_decl default_source_file ast_range decl =
let open Clang_ast_t in
match decl with
| ObjCMethodDecl ( di , _ , _ )
| CXXConversionDecl ( di , _ , _ , _ , _ )
| FunctionDecl ( di , _ , _ , _ )
| CXXMethodDecl ( di , _ , _ , _ , _ )
| CXXConstructorDecl ( di , _ , _ , _ , _ )
| CXXDestructorDecl ( di , _ , _ , _ , _ )
| BlockDecl ( di , _ ) -> (
let range = CLocation . location_of_decl_info default_source_file di in
let procname = CType_decl . CProcname . from_decl decl in
let clang_proc = clang_proc_of_decl decl in
let ast_range' = Typ . Procname . Map . add procname ( range , clang_proc ) ast_range in
match CAst_utils . get_method_body_opt decl with
| Some stmt ->
process_block_decls_in_stmts default_source_file ast_range' [ stmt ]
| None ->
ast_range' )
| _ -> (
match Clang_ast_proj . get_decl_context_tuple decl with
| Some ( decls , _ ) ->
List . fold ~ f : ( process_proc_decl default_source_file ) ~ init : ast_range decls
| None ->
ast_range )
let process_ast ast default_source_file =
let open Clang_ast_t in
match ast with
| TranslationUnitDecl ( _ , decl_list , _ , _ ) ->
List . fold decl_list ~ init : Typ . Procname . Map . empty ~ f : ( fun map decl ->
@ -66,7 +87,7 @@ let process_ast ast default_source_file =
if
CLocation . should_translate_lib default_source_file source_range ` DeclTraversal
~ translate_when_used : true
then extract_location map decl
then process_proc_decl default_source_file map decl
else map )
| _ ->
assert false