From 0c8a583cb090d3d16da7edcf17a9d25290141ede Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Tue, 29 Nov 2016 16:41:52 -0800 Subject: [PATCH] ppx_compare CFrontend_utils Reviewed By: cristianoc Differential Revision: D4232412 fbshipit-source-id: 1f3c5bc --- infer/src/clang/cFrontend_utils.ml | 47 +++++------------------------ infer/src/clang/cFrontend_utils.mli | 4 +-- infer/src/clang/predicates.ml | 2 +- 3 files changed, 11 insertions(+), 42 deletions(-) diff --git a/infer/src/clang/cFrontend_utils.ml b/infer/src/clang/cFrontend_utils.ml index 4f55e8409..f6d4876fe 100644 --- a/infer/src/clang/cFrontend_utils.ml +++ b/infer/src/clang/cFrontend_utils.ml @@ -108,45 +108,14 @@ struct } | _ -> make_name_decl property_name.Clang_ast_t.ni_name - let property_attribute_compare att1 att2 = - match att1, att2 with - `Readonly, `Readonly -> 0 - | `Readonly, _ -> -1 - | _, `Readonly -> 1 - | `Assign, `Assign -> 0 - | `Assign, _ -> -1 - | _, `Assign -> 1 - | `Readwrite, `Readwrite -> 0 - | `Readwrite, _ -> -1 - | _, `Readwrite -> 1 - | `Retain, `Retain -> 0 - | `Retain, _ -> -1 - | _, `Retain -> 1 - | `Copy, `Copy -> 0 - | `Copy, _ -> -1 - | _, `Copy -> 1 - | `Nonatomic, `Nonatomic -> 0 - | `Nonatomic, _ -> -1 - | _, `Nonatomic -> 1 - | `Atomic, `Atomic -> 0 - | `Atomic, _ -> 1 - | _, `Atomic -> 1 - | `Weak, `Weak -> 0 - | `Weak, _ -> -1 - | _, `Weak -> 1 - | `Strong, `Strong -> 0 - | `Strong, _ -> -1 - | _, `Strong -> 1 - | `Unsafe_unretained, `Unsafe_unretained -> 0 - | `Unsafe_unretained, _ -> -1 - | _, `Unsafe_unretained -> 1 - | `ExplicitGetter, `ExplicitGetter -> 0 - | `ExplicitGetter, _ -> -1 - | _, `ExplicitGetter -> 1 - | `ExplicitSetter, `ExplicitSetter -> 0 - - let property_attribute_eq att1 att2 = - property_attribute_compare att1 att2 = 0 + let compare_property_attribute = + [%compare: [ + `Readonly | `Assign | `Readwrite | `Retain | `Copy | `Nonatomic | `Atomic + | `Weak | `Strong | `Unsafe_unretained | `ExplicitGetter | `ExplicitSetter + ]] + + let equal_property_attribute att1 att2 = + compare_property_attribute att1 att2 = 0 let get_memory_management_attributes () = [`Assign; `Retain; `Copy; `Weak; `Strong; `Unsafe_unretained] diff --git a/infer/src/clang/cFrontend_utils.mli b/infer/src/clang/cFrontend_utils.mli index f2f18a76c..d17e60210 100644 --- a/infer/src/clang/cFrontend_utils.mli +++ b/infer/src/clang/cFrontend_utils.mli @@ -26,13 +26,13 @@ sig val property_name : Clang_ast_t.obj_c_property_impl_decl_info -> Clang_ast_t.named_decl_info - val property_attribute_compare : + val compare_property_attribute : Clang_ast_t.property_attribute -> Clang_ast_t.property_attribute -> int val generated_ivar_name : Clang_ast_t.named_decl_info -> Clang_ast_t.named_decl_info - val property_attribute_eq : + val equal_property_attribute : Clang_ast_t.property_attribute -> Clang_ast_t.property_attribute -> bool val get_memory_management_attributes : unit -> Clang_ast_t.property_attribute list diff --git a/infer/src/clang/predicates.ml b/infer/src/clang/predicates.ml index 588c4a22f..48f44f1dc 100644 --- a/infer/src/clang/predicates.ml +++ b/infer/src/clang/predicates.ml @@ -122,7 +122,7 @@ let is_ivar_atomic stmt = (match Ast_utils.get_decl ivar_pointer with | Some d -> let attributes = get_ivar_attributes d in - IList.exists (Ast_utils.property_attribute_eq `Atomic) attributes + IList.exists (Ast_utils.equal_property_attribute `Atomic) attributes | _ -> false) | _ -> false