Reviewed By: da319 Differential Revision: D8139862 fbshipit-source-id: ea79568master
parent
6769248f9b
commit
6ad971c875
@ -0,0 +1,147 @@
|
|||||||
|
(*
|
||||||
|
* Copyright (c) 2018 - present Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*)
|
||||||
|
open! IStd
|
||||||
|
|
||||||
|
(** Functions for extracting properties of functions or method declarations *)
|
||||||
|
|
||||||
|
let get_method_kind meth_decl =
|
||||||
|
let open Clang_ast_t in
|
||||||
|
match meth_decl with
|
||||||
|
| FunctionDecl _ ->
|
||||||
|
ProcAttributes.C_FUNCTION
|
||||||
|
| CXXMethodDecl (_, _, _, _, method_decl_info)
|
||||||
|
| CXXConstructorDecl (_, _, _, _, method_decl_info)
|
||||||
|
| CXXConversionDecl (_, _, _, _, method_decl_info)
|
||||||
|
| CXXDestructorDecl (_, _, _, _, method_decl_info) ->
|
||||||
|
if method_decl_info.Clang_ast_t.xmdi_is_static then ProcAttributes.CPP_CLASS
|
||||||
|
else ProcAttributes.CPP_INSTANCE
|
||||||
|
| ObjCMethodDecl (_, _, method_decl_info) ->
|
||||||
|
if method_decl_info.Clang_ast_t.omdi_is_instance_method then ProcAttributes.OBJC_INSTANCE
|
||||||
|
else ProcAttributes.OBJC_CLASS
|
||||||
|
| BlockDecl _ ->
|
||||||
|
ProcAttributes.BLOCK
|
||||||
|
| _ ->
|
||||||
|
raise CFrontend_config.Invalid_declaration
|
||||||
|
|
||||||
|
|
||||||
|
let get_return_type method_decl =
|
||||||
|
let open Clang_ast_t in
|
||||||
|
match method_decl with
|
||||||
|
| FunctionDecl (_, _, qt, _)
|
||||||
|
| CXXMethodDecl (_, _, qt, _, _)
|
||||||
|
| CXXConstructorDecl (_, _, qt, _, _)
|
||||||
|
| CXXConversionDecl (_, _, qt, _, _)
|
||||||
|
| CXXDestructorDecl (_, _, qt, _, _) ->
|
||||||
|
CType.return_type_of_function_type qt
|
||||||
|
| ObjCMethodDecl (_, _, omdi) ->
|
||||||
|
omdi.omdi_result_type
|
||||||
|
| _ ->
|
||||||
|
raise CFrontend_config.Invalid_declaration
|
||||||
|
|
||||||
|
|
||||||
|
let get_param_decls method_decl =
|
||||||
|
let open Clang_ast_t in
|
||||||
|
match method_decl with
|
||||||
|
| FunctionDecl (_, _, _, function_decl_info)
|
||||||
|
| CXXMethodDecl (_, _, _, function_decl_info, _)
|
||||||
|
| CXXConstructorDecl (_, _, _, function_decl_info, _)
|
||||||
|
| CXXConversionDecl (_, _, _, function_decl_info, _)
|
||||||
|
| CXXDestructorDecl (_, _, _, function_decl_info, _) ->
|
||||||
|
function_decl_info.fdi_parameters
|
||||||
|
| ObjCMethodDecl (_, _, method_decl_info) ->
|
||||||
|
method_decl_info.omdi_parameters
|
||||||
|
| BlockDecl (_, block_decl_info) ->
|
||||||
|
block_decl_info.bdi_parameters
|
||||||
|
| _ ->
|
||||||
|
raise CFrontend_config.Invalid_declaration
|
||||||
|
|
||||||
|
|
||||||
|
let get_method_body method_decl =
|
||||||
|
let open Clang_ast_t in
|
||||||
|
match method_decl with
|
||||||
|
| FunctionDecl (_, _, _, function_decl_info)
|
||||||
|
| CXXMethodDecl (_, _, _, function_decl_info, _)
|
||||||
|
| CXXConstructorDecl (_, _, _, function_decl_info, _)
|
||||||
|
| CXXConversionDecl (_, _, _, function_decl_info, _)
|
||||||
|
| CXXDestructorDecl (_, _, _, function_decl_info, _) ->
|
||||||
|
function_decl_info.fdi_body
|
||||||
|
| ObjCMethodDecl (_, _, method_decl_info) ->
|
||||||
|
method_decl_info.omdi_body
|
||||||
|
| BlockDecl (_, block_decl_info) ->
|
||||||
|
block_decl_info.bdi_body
|
||||||
|
| _ ->
|
||||||
|
raise CFrontend_config.Invalid_declaration
|
||||||
|
|
||||||
|
|
||||||
|
let get_language ~is_cpp method_decl =
|
||||||
|
let open Clang_ast_t in
|
||||||
|
match method_decl with
|
||||||
|
| FunctionDecl _ ->
|
||||||
|
if is_cpp then CFrontend_config.CPP else CFrontend_config.ObjC
|
||||||
|
| CXXMethodDecl _ | CXXConstructorDecl _ | CXXConversionDecl _ | CXXDestructorDecl _ ->
|
||||||
|
CFrontend_config.CPP
|
||||||
|
| ObjCMethodDecl _ | BlockDecl _ ->
|
||||||
|
CFrontend_config.ObjC
|
||||||
|
| _ ->
|
||||||
|
raise CFrontend_config.Invalid_declaration
|
||||||
|
|
||||||
|
|
||||||
|
let is_cpp_virtual method_decl =
|
||||||
|
let open Clang_ast_t in
|
||||||
|
match method_decl with
|
||||||
|
| CXXMethodDecl (_, _, _, _, mdi)
|
||||||
|
| CXXConstructorDecl (_, _, _, _, mdi)
|
||||||
|
| CXXConversionDecl (_, _, _, _, mdi)
|
||||||
|
| CXXDestructorDecl (_, _, _, _, mdi) ->
|
||||||
|
mdi.xmdi_is_virtual
|
||||||
|
| _ ->
|
||||||
|
false
|
||||||
|
|
||||||
|
|
||||||
|
let is_cpp_nothrow method_decl =
|
||||||
|
let open Clang_ast_t in
|
||||||
|
match method_decl with
|
||||||
|
| FunctionDecl (_, _, _, fdi)
|
||||||
|
| CXXMethodDecl (_, _, _, fdi, _)
|
||||||
|
| CXXConstructorDecl (_, _, _, fdi, _)
|
||||||
|
| CXXConversionDecl (_, _, _, fdi, _)
|
||||||
|
| CXXDestructorDecl (_, _, _, fdi, _) ->
|
||||||
|
fdi.fdi_is_no_throw
|
||||||
|
| _ ->
|
||||||
|
false
|
||||||
|
|
||||||
|
|
||||||
|
let get_init_list_instrs method_decl =
|
||||||
|
let open Clang_ast_t in
|
||||||
|
match method_decl with
|
||||||
|
| CXXMethodDecl (_, _, _, _, mdi)
|
||||||
|
| CXXConstructorDecl (_, _, _, _, mdi)
|
||||||
|
| CXXConversionDecl (_, _, _, _, mdi)
|
||||||
|
| CXXDestructorDecl (_, _, _, _, mdi) ->
|
||||||
|
let create_custom_instr construct_instr = `CXXConstructorInit construct_instr in
|
||||||
|
List.map ~f:create_custom_instr mdi.xmdi_cxx_ctor_initializers
|
||||||
|
| _ ->
|
||||||
|
[]
|
||||||
|
|
||||||
|
|
||||||
|
let get_pointer_to_property method_decl =
|
||||||
|
let open Clang_ast_t in
|
||||||
|
match method_decl with
|
||||||
|
| ObjCMethodDecl (_, _, mdi) -> (
|
||||||
|
match mdi.Clang_ast_t.omdi_property_decl with
|
||||||
|
| Some decl_ref ->
|
||||||
|
Some decl_ref.Clang_ast_t.dr_decl_pointer
|
||||||
|
| None ->
|
||||||
|
None )
|
||||||
|
| _ ->
|
||||||
|
None
|
||||||
|
|
||||||
|
|
||||||
|
let is_objc_method method_decl =
|
||||||
|
match method_decl with Clang_ast_t.ObjCMethodDecl _ -> true | _ -> false
|
@ -0,0 +1,33 @@
|
|||||||
|
(*
|
||||||
|
* Copyright (c) 2018 - present Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*)
|
||||||
|
|
||||||
|
open! IStd
|
||||||
|
|
||||||
|
(** Functions for extracting properties of functions or method declarations *)
|
||||||
|
|
||||||
|
val get_method_kind : Clang_ast_t.decl -> ProcAttributes.clang_method_kind
|
||||||
|
|
||||||
|
val get_return_type : Clang_ast_t.decl -> Clang_ast_t.qual_type
|
||||||
|
|
||||||
|
val get_param_decls : Clang_ast_t.decl -> Clang_ast_t.decl list
|
||||||
|
|
||||||
|
val get_method_body : Clang_ast_t.decl -> Clang_ast_t.stmt option
|
||||||
|
|
||||||
|
val get_language : is_cpp:bool -> Clang_ast_t.decl -> CFrontend_config.clang_lang
|
||||||
|
|
||||||
|
val is_cpp_virtual : Clang_ast_t.decl -> bool
|
||||||
|
|
||||||
|
val is_cpp_nothrow : Clang_ast_t.decl -> bool
|
||||||
|
|
||||||
|
val get_init_list_instrs :
|
||||||
|
Clang_ast_t.decl -> [> `CXXConstructorInit of Clang_ast_t.cxx_ctor_initializer] list
|
||||||
|
|
||||||
|
val get_pointer_to_property : Clang_ast_t.decl -> Clang_ast_t.pointer option
|
||||||
|
|
||||||
|
val is_objc_method : Clang_ast_t.decl -> bool
|
Loading…
Reference in new issue