From 7c9612b06ba73f3f9cc8bb45113c487968127c4f Mon Sep 17 00:00:00 2001 From: Martino Luca Date: Tue, 22 Nov 2016 09:16:14 -0800 Subject: [PATCH] [CTL] Add support for is_unop_with_kind/is_binop_with_kind predicates to check correctness of their inputs Summary: This will help during the creation of new checkers, and will prevent errors like misspelling of operators' kinds. It will also make it possible to fail immediately during the parsing of CTL inputs. Reviewed By: ddino Differential Revision: D4212956 fbshipit-source-id: c3c7fe7 --- facebook-clang-plugins | 2 +- infer/src/clang/predicates.ml | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/facebook-clang-plugins b/facebook-clang-plugins index 189047104..e13e1ecab 160000 --- a/facebook-clang-plugins +++ b/facebook-clang-plugins @@ -1 +1 @@ -Subproject commit 18904710494629ff27a5350d715f3a2a228970b6 +Subproject commit e13e1ecabe333209fabebedb1f80f1325669fcec diff --git a/infer/src/clang/predicates.ml b/infer/src/clang/predicates.ml index 3ce155dee..d1c36d1c0 100644 --- a/infer/src/clang/predicates.ml +++ b/infer/src/clang/predicates.ml @@ -172,20 +172,19 @@ let captures_cxx_references stmt = IList.length (captured_variables_cxx_ref stmt) > 0 let is_binop_with_kind stmt str_kind = - let kind = match str_kind with - | "EQ" -> `EQ - | "NE" -> `NE - | _ -> failwith ("Kind " ^ str_kind ^ " is invalid or not yet supported") in + if not (Clang_ast_proj.is_valid_binop_kind_name str_kind) then + failwith ("Binary operator kind " ^ str_kind ^ " is not valid"); match stmt with - | Clang_ast_t.BinaryOperator (_, _, _, boi) when boi.boi_kind = kind -> true + | Clang_ast_t.BinaryOperator (_, _, _, boi) -> + Clang_ast_proj.string_of_binop_kind boi.boi_kind = str_kind | _ -> false let is_unop_with_kind stmt str_kind = - let kind = match str_kind with - | "LNot" -> `LNot - | _ -> failwith ("Kind " ^ str_kind ^ " is invalid or not yet supported") in + if not (Clang_ast_proj.is_valid_unop_kind_name str_kind) then + failwith ("Unary operator kind " ^ str_kind ^ " is not valid"); match stmt with - | Clang_ast_t.UnaryOperator (_, _, _, uoi) when uoi.uoi_kind = kind -> true + | Clang_ast_t.UnaryOperator (_, _, _, uoi) -> + Clang_ast_proj.string_of_unop_kind uoi.uoi_kind = str_kind | _ -> false let is_stmt stmt stmt_name =