Skip to content

Commit

Permalink
Don't suggest changing methods of point classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jbytheway committed Apr 28, 2020
1 parent 454eb0b commit fb99486
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
9 changes: 2 additions & 7 deletions tools/clang-tidy-plugin/UsePointArithmeticCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,8 @@ static void CheckConstructor( UsePointArithmeticCheck &Check,
}

// Don't mess with the methods of point and tripoint themselves
if( const FunctionDecl *ContainingFunc = getContainingFunction( Result, ConstructorCall ) ) {
if( const CXXMethodDecl *ContainingMethod = dyn_cast<CXXMethodDecl>( ContainingFunc ) ) {
const CXXRecordDecl *ContainingRecord = ContainingMethod->getParent();
if( isPointType( ContainingRecord ) ) {
return;
}
}
if( isPointMethod( getContainingFunction( Result, ConstructorCall ) ) ) {
return;
}

std::string Joined;
Expand Down
21 changes: 16 additions & 5 deletions tools/clang-tidy-plugin/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ static const FunctionDecl *getContainingFunction(
return nullptr;
}

inline bool isPointType( const CXXRecordDecl *R )
{
if( !R ) {
return false;
}
StringRef name = R->getName();
return name == "point" || name == "tripoint";
}

inline auto isPointType()
{
using namespace clang::ast_matchers;
Expand Down Expand Up @@ -110,13 +119,15 @@ inline auto isYParam()
return matchesName( "[yY]" );
}

inline bool isPointType( const CXXRecordDecl *R )
inline bool isPointMethod( const FunctionDecl *d )
{
if( !R ) {
return false;
if( const CXXMethodDecl *Method = dyn_cast_or_null<CXXMethodDecl>( d ) ) {
const CXXRecordDecl *Record = Method->getParent();
if( isPointType( Record ) ) {
return true;
}
}
StringRef name = R->getName();
return name == "point" || name == "tripoint";
return false;
}

// Struct to help identify and construct names of associated points and
Expand Down
4 changes: 4 additions & 0 deletions tools/clang-tidy-plugin/XYCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ static void CheckParam( XYCheck &Check, const MatchFinder::MatchResult &Result )
if( !XParam || !Function ) {
return;
}
// Don't mess with the methods of point and tripoint themselves
if( isPointMethod( Function ) ) {
return;
}
const NameConvention NameMatcher( XParam->getName() );

const ParmVarDecl *YParam = nullptr;
Expand Down

0 comments on commit fb99486

Please sign in to comment.