[linters] Predicate for checking enum constants

Reviewed By: akotulski

Differential Revision: D5423574

fbshipit-source-id: c1deb13
master
Dulma Churchill 8 years ago committed by Facebook Github Bot
parent be0c53ddf3
commit 416478d453

@ -216,6 +216,13 @@ let call_function an name =
| _ | _
-> false -> false
let is_enum_constant an name =
match an with
| Ctl_parser_types.Stmt st
-> decl_ref_name ~kind:`EnumConstant name st
| _
-> false
let is_strong_property an = let is_strong_property an =
match an with match an with
| Ctl_parser_types.Decl Clang_ast_t.ObjCPropertyDecl (_, _, pdi) | Ctl_parser_types.Decl Clang_ast_t.ObjCPropertyDecl (_, _, pdi)

@ -21,6 +21,8 @@ val call_class_method : Ctl_parser_types.ast_node -> ALVar.alexp -> ALVar.alexp
val call_instance_method : Ctl_parser_types.ast_node -> ALVar.alexp -> ALVar.alexp -> bool val call_instance_method : Ctl_parser_types.ast_node -> ALVar.alexp -> ALVar.alexp -> bool
val is_enum_constant : Ctl_parser_types.ast_node -> ALVar.alexp -> bool
val is_objc_interface_named : Ctl_parser_types.ast_node -> ALVar.alexp -> bool val is_objc_interface_named : Ctl_parser_types.ast_node -> ALVar.alexp -> bool
val is_objc_extension : CLintersContext.context -> bool val is_objc_extension : CLintersContext.context -> bool

@ -760,6 +760,8 @@ let rec eval_Atomic _pred_name args an lcxt =
-> CPredicates.is_class an cname -> CPredicates.is_class an cname
| "is_const_var", [], an | "is_const_var", [], an
-> CPredicates.is_const_expr_var an -> CPredicates.is_const_expr_var an
| "is_enum_constant", [cname], an
-> CPredicates.is_enum_constant an cname
| "is_global_var", [], an | "is_global_var", [], an
-> CPredicates.is_syntactically_global_var an -> CPredicates.is_syntactically_global_var an
| "is_ivar_atomic", [], an | "is_ivar_atomic", [], an

@ -0,0 +1,20 @@
/*
* Copyright (c) 2017 - 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.
*/
#import <Foundation/NSObject.h>
typedef NS_ENUM(NSUInteger, MyName) {
MyNameUndefined,
};
int test() { return MyNameUndefined; }
enum { RANDOM, IMMEDIATE, SEARCH } strategy;
int test_c_style_enum() { return IMMEDIATE; }

@ -1,3 +1,5 @@
codetoanalyze/objc/linters-for-test-only/enums.m, test, 16, ENUM_CONSTANTS, []
codetoanalyze/objc/linters-for-test-only/enums.m, test_c_style_enum, 20, ENUM_CONSTANTS, []
codetoanalyze/objc/linters-for-test-only/filter_by_path/include_file.m, main, 9, ALL_PATH_NO_FILTER_EXAMPLE, [] codetoanalyze/objc/linters-for-test-only/filter_by_path/include_file.m, main, 9, ALL_PATH_NO_FILTER_EXAMPLE, []
codetoanalyze/objc/linters-for-test-only/filter_by_path/include_file.m, main, 9, FILTER_BY_ALL_PATH_EXAMPLE, [] codetoanalyze/objc/linters-for-test-only/filter_by_path/include_file.m, main, 9, FILTER_BY_ALL_PATH_EXAMPLE, []
codetoanalyze/objc/linters-for-test-only/filter_by_path/include_file.m, main, 9, FILTER_BY_PATH_EXAMPLE, [] codetoanalyze/objc/linters-for-test-only/filter_by_path/include_file.m, main, 9, FILTER_BY_PATH_EXAMPLE, []

@ -338,3 +338,8 @@ DEFINE-CHECKER WHITE_BLACKLIST_PATH_EXAMPLE = {
SET blacklist_path = { filtered_files }; SET blacklist_path = { filtered_files };
SET doc_url = "www.example.com"; SET doc_url = "www.example.com";
}; };
DEFINE-CHECKER ENUM_CONSTANTS = {
SET report_when = is_enum_constant(REGEXP("MyName.*")) OR is_enum_constant("IMMEDIATE");
SET message = "Do not use the enum MyName or strategy";
};

Loading…
Cancel
Save