[linters] Fix the computing of the successors of method declarations

Reviewed By: ddino

Differential Revision: D5814233

fbshipit-source-id: 84fae71
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent d7057ece2b
commit b99b653ffa

@ -67,6 +67,18 @@ let get_bug_hash (kind: string) (type_str: string) (procedure_id: string) (filen
(node_key: int) (error_desc: Localise.error_desc) =
let qualifier_tag_call_procedure = Localise.error_desc_get_tag_call_procedure error_desc in
let qualifier_tag_value = Localise.error_desc_get_tag_value error_desc in
Logging.progress
"\nCreating hash from kind=%s, type_str=%s, \
procedure_id=%s, filename=%s, node_key=%d, \
qualifier_tag_call_procedure=%s, qualifier_tag_value=%s @."
kind
type_str
procedure_id
filename
node_key
qualifier_tag_call_procedure
qualifier_tag_value
;
Hashtbl.hash
( kind
, type_str

@ -282,6 +282,9 @@ let generate_key_decl decl =
let name = full_name_of_decl_opt (Some decl) in
Buffer.add_string buffer (string_of_int (get_tag decl)) ;
Buffer.add_string buffer (QualifiedCppName.to_qual_string name) ;
Logging.(debug Capture Medium)
"Generated key for decl with name %s and tag %d is %s" (QualifiedCppName.to_qual_string name)
(get_tag decl) (Buffer.contents buffer) ;
Buffer.contents buffer
let rec get_super_if decl =

@ -431,10 +431,7 @@ let log_frontend_issue translation_unit_context method_decl_opt key (issue_desc:
let exn = Exceptions.Frontend_warning ((issue_desc.id, issue_desc.name), err_desc, __POS__) in
let trace = [Errlog.make_trace_element 0 issue_desc.loc "" []] in
let err_kind = issue_desc.severity in
let method_name =
CAst_utils.full_name_of_decl_opt method_decl_opt |> QualifiedCppName.to_qual_string
in
let key = Hashtbl.hash (key ^ method_name) in
let key = Hashtbl.hash key in
Reporting.log_issue_from_errlog err_kind errlog exn ~loc:issue_desc.loc ~ltr:trace
~node_id:(0, key) ?linters_def_file ?doc_url:issue_desc.doc_url

@ -132,7 +132,24 @@ let get_successor_decls_of_stmt stmt =
-> []
let get_successor_decls_of_decl decl =
match Clang_ast_proj.get_decl_context_tuple decl with Some (decls, _) -> decls | None -> []
let open Clang_ast_t in
match Clang_ast_proj.get_decl_context_tuple decl with
| Some (decls, _)
-> decls
| None ->
match decl with
| FunctionDecl (_, _, _, fdi)
| CXXMethodDecl (_, _, _, fdi, _)
| CXXConstructorDecl (_, _, _, fdi, _)
| CXXConversionDecl (_, _, _, fdi, _)
| CXXDestructorDecl (_, _, _, fdi, _)
-> fdi.Clang_ast_t.fdi_parameters
| ObjCMethodDecl (_, _, mdi)
-> mdi.Clang_ast_t.omdi_parameters
| BlockDecl (_, block_decl_info)
-> block_decl_info.Clang_ast_t.bdi_parameters
| _
-> []
let get_successor_stmts_of_decl decl =
let open Clang_ast_t in

@ -0,0 +1,62 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#import <Foundation/NSObject.h>
class FBMemImage;
class FBMemQuery;
@interface FBMemModelUsed1 : NSObject
// NEW_COMPONENT_USING_MEM_MODEL bug
+ (instancetype)newImage:(FBMemImage*)image;
// no NEW_COMPONENT_USING_MEM_MODEL bug
+ (instancetype)newInt:(int)size;
// no NEW_COMPONENT_USING_MEM_MODEL bug
+ (int)newReturnInt:(FBMemImage*)size;
// NEW_COMPONENT_USING_MEM_MODEL bug
+ (instancetype)newMultiParams:(int)size
image:(FBMemImage*)image
query:(FBMemQuery*)query;
@end
@implementation FBMemModelUsed1
// NEW_COMPONENT_USING_MEM_MODEL bug
+ (instancetype)newImage:(FBMemImage*)image {
return nil;
}
// no NEW_COMPONENT_USING_MEM_MODEL bug
+ (instancetype)newInt:(int)size {
return nil;
}
// no NEW_COMPONENT_USING_MEM_MODEL bug
+ (int)newReturnInt:(FBMemImage*)size {
return 0;
}
// NEW_COMPONENT_USING_MEM_MODEL bug
+ (instancetype)newMultiParams:(int)size
image:(FBMemImage*)image
query:(FBMemQuery*)query {
return nil;
}
@end
@interface FBMemModelUsed2 : NSObject
+ (instancetype)newQuery:(FBMemQuery*)query;
@end
@implementation FBMemModelUsed2
+ (instancetype)newQuery:(FBMemQuery*)query {
return nil;
}
@end

@ -4,6 +4,12 @@ codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWi
codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithActionRef:, 40, TEST_REFERENCE, []
codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithConstAction:, 21, TEST_REFERENCE, []
codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithConstAction:, 36, TEST_REFERENCE, []
codetoanalyze/objcpp/linters-for-test-only/TestParameterMemModels.mm, FBMemModelUsed1_newImage:, 12, NEW_COMPONENT_USING_MEM_MODEL, []
codetoanalyze/objcpp/linters-for-test-only/TestParameterMemModels.mm, FBMemModelUsed1_newImage:, 27, NEW_COMPONENT_USING_MEM_MODEL, []
codetoanalyze/objcpp/linters-for-test-only/TestParameterMemModels.mm, FBMemModelUsed1_newMultiParams:image:query:, 20, NEW_COMPONENT_USING_MEM_MODEL, []
codetoanalyze/objcpp/linters-for-test-only/TestParameterMemModels.mm, FBMemModelUsed1_newMultiParams:image:query:, 44, NEW_COMPONENT_USING_MEM_MODEL, []
codetoanalyze/objcpp/linters-for-test-only/TestParameterMemModels.mm, FBMemModelUsed2_newQuery:, 52, NEW_COMPONENT_USING_MEM_MODEL, []
codetoanalyze/objcpp/linters-for-test-only/TestParameterMemModels.mm, FBMemModelUsed2_newQuery:, 58, NEW_COMPONENT_USING_MEM_MODEL, []
codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, anotherButtonComponent, 41, PARAMETER_TRANS_TYPE, []
codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, anotherButtonComponent, 41, TEST_PARAMETER_LABEL, []
codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, anotherButtonComponent, 41, TEST_PARAMETER_LABEL_REGEXP, []

@ -139,3 +139,13 @@ DEFINE-CHECKER TEST_PARAMETER_SELECTOR_BY_TYPE = {
HOLDS-IN-NODE ObjCMessageExpr;
SET message = "Do not construct the Component action with a selector only...`";
};
DEFINE-CHECKER NEW_COMPONENT_USING_MEM_MODEL = {
SET report_when =
WHEN method_return_type("instancetype")
AND HOLDS-NEXT WITH-TRANSITION Parameters (has_type("REGEXP('FBMem.*')*"))
AND declaration_has_name(REGEXP("^new.*:$"))
HOLDS-IN-NODE ObjCMethodDecl;
SET message = "Consider using fragment models instead.";
};

Loading…
Cancel
Save