Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

Commit

Permalink
[clang_ast_proj] add {get,update}_cxx_construct_expr_tuple
Browse files Browse the repository at this point in the history
Summary:
* I'm adding a new Infer predicate that needs to extract cxx_construct_expr info from the nodes which have it
* This would seem to be the cleanest most general method
* Also added some unit test coverage

Test Plan:
* `make clang_plugin_test` (includes new unit tests)
* Testing of dependent diff

Reviewers: jrm, ddino, jul

Reviewed By: jul

Subscribers: mcl

Differential Revision: https://phabricator.intern.facebook.com/D14378138

Signature: 14378138:1552057300:eac78c0bc274d73083f1cd56b739fd8e6e7a11a7
  • Loading branch information
David Lively committed Mar 8, 2019
1 parent ee66e72 commit 36266f6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
15 changes: 15 additions & 0 deletions clang-ocaml/clang_ast_proj.ml.p
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ let update_expr_tuple __f = function
#include <clang/AST/StmtNodes.inc>
| x -> x

let get_cxx_construct_expr_tuple = function
#define STMT(CLASS, PARENT)
#define CXXCONSTRUCTEXPR(CLASS, PARENT) | CLASS (@CLASS@_tuple) -> Some (cxx_construct_expr_tuple)
#define ABSTRACT_STMT(STMT)
#include <clang/AST/StmtNodes.inc>
| _ -> None

let update_cxx_construct_expr_tuple __f = function
#define STMT(CLASS, PARENT)
#define CXXCONSTRUCTEXPR(CLASS, PARENT) | CLASS (@CLASS@_tuple) -> \
let (cxx_construct_expr_tuple) = __f (cxx_construct_expr_tuple) in CLASS (@CLASS@_tuple)
#define ABSTRACT_STMT(STMT)
#include <clang/AST/StmtNodes.inc>
| x -> x

let get_type_tuple = function
#define TYPE(DERIVED, BASE) | DERIVED@@Type (@DERIVED@_type_tuple) -> (type_tuple)
#define ABSTRACT_TYPE(DERIVED, BASE)
Expand Down
2 changes: 2 additions & 0 deletions clang-ocaml/clang_ast_proj.mli.p
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ val get_decl_context_tuple : decl -> (decl_context_tuple) option
val get_decl_kind_string : decl -> string
val get_decl_tuple : decl -> (decl_tuple)
val get_expr_tuple : stmt -> (expr_tuple) option
val get_cxx_construct_expr_tuple : stmt -> (cxx_construct_expr_tuple) option
val get_named_decl_tuple : decl -> (named_decl_tuple) option
val get_stmt_kind_string : stmt -> string
val get_stmt_tuple : stmt -> (stmt_tuple)
Expand All @@ -28,6 +29,7 @@ val string_of_binop_kind : binary_operator_kind -> string
val string_of_cast_kind : cast_kind -> string
val string_of_unop_kind : unary_operator_kind -> string

val update_cxx_construct_expr_tuple : ((cxx_construct_expr_tuple) -> (cxx_construct_expr_tuple)) -> stmt -> stmt
val update_decl_context_tuple : ((decl_context_tuple) -> (decl_context_tuple)) -> decl -> decl
val update_decl_tuple : ((decl_tuple) -> (decl_tuple)) -> decl -> decl
val update_expr_tuple : ((expr_tuple) -> (expr_tuple)) -> stmt -> stmt
Expand Down
38 changes: 38 additions & 0 deletions clang-ocaml/clang_ast_proj_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ let var_decl_info ~is_global =
; vdi_parm_index_in_function= None
; vdi_storage_class= None }

let stmt_info pointer =
{ si_pointer= pointer
; si_source_range= (empty_source_location, empty_source_location) }

let expr_info qual_type =
{ ei_qual_type= qual_type
; ei_value_kind= `RValue
; ei_object_kind= `Ordinary }

let cxx_construct_expr_info decl_ref is_copy_constructor =
{ xcei_decl_ref= decl_ref
; xcei_is_elidable= false
; xcei_requires_zero_initialization= false
; xcei_is_copy_constructor= is_copy_constructor }


let () =
let di = decl_info empty_source_location empty_source_location in
Expand Down Expand Up @@ -82,3 +97,26 @@ let () =
var_decl in
assert_equal "update_var_decl_tuple" (get_var_decl_tuple updated_var_decl)
(Some (di, name_info "fooey-mod", qt, var_decl_info ~is_global:false)) ;

let stmt = DoStmt(stmt_info 0, []) in
assert_equal "get_cxx_construct_expr_tuple_from_stmt"
(get_cxx_construct_expr_tuple stmt) None ;
let ei = expr_info qt in
let dr = { dr_kind= `CXXConstructor
; dr_decl_pointer= 0
; dr_name= None
; dr_is_hidden= false
; dr_qual_type= None } in
let xcei = cxx_construct_expr_info dr true in
let xcei2 = cxx_construct_expr_info dr false in
let cxx_ctor_expr = CXXConstructExpr(stmt_info 1, [], ei, xcei) in
assert_equal "get_cxx_construct_expr_tuple"
(get_cxx_construct_expr_tuple cxx_ctor_expr)
(Some (stmt_info 1, [], ei, xcei)) ;
let updated_cxx_ctor_expr = update_cxx_construct_expr_tuple
(fun (si, sl, ei, xcei) ->
(stmt_info (si.si_pointer + 1)), sl, ei, xcei2)
cxx_ctor_expr in
assert_equal "update_cxx_construct_expr_tuple"
(get_cxx_construct_expr_tuple updated_cxx_ctor_expr)
(Some (stmt_info 2, [], ei, xcei2)) ;

0 comments on commit 36266f6

Please sign in to comment.