Kaydet (Commit) 5585bc2f authored tarafından Noel Grandin's avatar Noel Grandin

rename loplugin::Plugin::parentStmt

to getParentStmt and rename parentFunctionDecl to getParentFunctionDecl,
so I don't keep using accidentally naming my variables the same as the
functions.

Change-Id: I66f9452458c8b439e5132191ac5219fb6d420708
üst 13c26e56
...@@ -132,7 +132,7 @@ void CheckUnusedParams::checkForFunctionDecl(Expr const * expr, bool bCheckOnly) ...@@ -132,7 +132,7 @@ void CheckUnusedParams::checkForFunctionDecl(Expr const * expr, bool bCheckOnly)
if (!functionDecl) if (!functionDecl)
return; return;
if (bCheckOnly) if (bCheckOnly)
parentStmt(expr)->dump(); getParentStmt(expr)->dump();
else else
m_addressOfSet.insert(functionDecl->getCanonicalDecl()); m_addressOfSet.insert(functionDecl->getCanonicalDecl());
} }
......
...@@ -289,7 +289,7 @@ bool ConstParams::VisitDeclRefExpr( const DeclRefExpr* declRefExpr ) ...@@ -289,7 +289,7 @@ bool ConstParams::VisitDeclRefExpr( const DeclRefExpr* declRefExpr )
// related ParamVarDecl can be const. // related ParamVarDecl can be const.
bool ConstParams::checkIfCanBeConst(const Stmt* stmt, const ParmVarDecl* parmVarDecl) bool ConstParams::checkIfCanBeConst(const Stmt* stmt, const ParmVarDecl* parmVarDecl)
{ {
const Stmt* parent = parentStmt( stmt ); const Stmt* parent = getParentStmt( stmt );
if (!parent) if (!parent)
{ {
// check if we're inside a CXXCtorInitializer // check if we're inside a CXXCtorInitializer
......
...@@ -62,13 +62,13 @@ bool DodgySwitch::VisitCaseStmt(CaseStmt const * caseStmt) ...@@ -62,13 +62,13 @@ bool DodgySwitch::VisitCaseStmt(CaseStmt const * caseStmt)
bool DodgySwitch::IsParentSwitch(Stmt const * stmt) bool DodgySwitch::IsParentSwitch(Stmt const * stmt)
{ {
auto parent = parentStmt(stmt); auto parent = getParentStmt(stmt);
if (isa<CaseStmt>(parent) || isa<DefaultStmt>(parent)) // daisy chain if (isa<CaseStmt>(parent) || isa<DefaultStmt>(parent)) // daisy chain
return true; return true;
auto compoundStmt = dyn_cast<CompoundStmt>(parent); auto compoundStmt = dyn_cast<CompoundStmt>(parent);
if (!compoundStmt) if (!compoundStmt)
return false; return false;
return isa<SwitchStmt>(parentStmt(compoundStmt)); return isa<SwitchStmt>(getParentStmt(compoundStmt));
} }
loplugin::Plugin::Registration< DodgySwitch > X("dodgyswitch", false); loplugin::Plugin::Registration< DodgySwitch > X("dodgyswitch", false);
......
...@@ -272,7 +272,7 @@ void ExpandableMethods::functionTouchedFromExpr( const FunctionDecl* calleeFunct ...@@ -272,7 +272,7 @@ void ExpandableMethods::functionTouchedFromExpr( const FunctionDecl* calleeFunct
calledFromSet.emplace(toString(expr->getLocStart()), niceName(canonicalFunctionDecl)); calledFromSet.emplace(toString(expr->getLocStart()), niceName(canonicalFunctionDecl));
if (const UnaryOperator* unaryOp = dyn_cast_or_null<UnaryOperator>(parentStmt(expr))) { if (const UnaryOperator* unaryOp = dyn_cast_or_null<UnaryOperator>(getParentStmt(expr))) {
if (unaryOp->getOpcode() == UO_AddrOf) { if (unaryOp->getOpcode() == UO_AddrOf) {
addressOfSet.insert(niceName(canonicalFunctionDecl)); addressOfSet.insert(niceName(canonicalFunctionDecl));
} }
......
...@@ -184,7 +184,7 @@ bool InlineFields::VisitBinAssign(const BinaryOperator * binaryOp) ...@@ -184,7 +184,7 @@ bool InlineFields::VisitBinAssign(const BinaryOperator * binaryOp)
if (!fieldDecl || !fieldDecl->getType()->isPointerType()) { if (!fieldDecl || !fieldDecl->getType()->isPointerType()) {
return true; return true;
} }
const FunctionDecl* parentFunction = parentFunctionDecl(binaryOp); const FunctionDecl* parentFunction = getParentFunctionDecl(binaryOp);
if (!parentFunction) { if (!parentFunction) {
return true; return true;
} }
...@@ -227,7 +227,7 @@ bool InlineFields::VisitCXXDeleteExpr(const CXXDeleteExpr * deleteExpr) ...@@ -227,7 +227,7 @@ bool InlineFields::VisitCXXDeleteExpr(const CXXDeleteExpr * deleteExpr)
} }
// TODO for some reason, this part is not working properly, it doesn't find the parent // TODO for some reason, this part is not working properly, it doesn't find the parent
// function for delete statements properly // function for delete statements properly
const FunctionDecl* parentFunction = parentFunctionDecl(deleteExpr); const FunctionDecl* parentFunction = getParentFunctionDecl(deleteExpr);
if (!parentFunction) { if (!parentFunction) {
return true; return true;
} }
......
...@@ -145,7 +145,7 @@ bool MemoryVar::VisitCXXNewExpr(const CXXNewExpr *newExpr) ...@@ -145,7 +145,7 @@ bool MemoryVar::VisitCXXNewExpr(const CXXNewExpr *newExpr)
if (ignoreLocation(newExpr)) { if (ignoreLocation(newExpr)) {
return true; return true;
} }
const Stmt* stmt = parentStmt(newExpr); const Stmt* stmt = getParentStmt(newExpr);
const DeclStmt* declStmt = dyn_cast<DeclStmt>(stmt); const DeclStmt* declStmt = dyn_cast<DeclStmt>(stmt);
if (declStmt) { if (declStmt) {
......
...@@ -118,7 +118,7 @@ void Plugin::registerPlugin( Plugin* (*create)( const InstantiationData& ), cons ...@@ -118,7 +118,7 @@ void Plugin::registerPlugin( Plugin* (*create)( const InstantiationData& ), cons
std::unordered_map< const Stmt*, const Stmt* > Plugin::parents; std::unordered_map< const Stmt*, const Stmt* > Plugin::parents;
const Stmt* Plugin::parentStmt( const Stmt* stmt ) const Stmt* Plugin::getParentStmt( const Stmt* stmt )
{ {
if( parents.empty()) if( parents.empty())
buildParents( compiler ); buildParents( compiler );
...@@ -127,7 +127,7 @@ const Stmt* Plugin::parentStmt( const Stmt* stmt ) ...@@ -127,7 +127,7 @@ const Stmt* Plugin::parentStmt( const Stmt* stmt )
return parents[ stmt ]; return parents[ stmt ];
} }
Stmt* Plugin::parentStmt( Stmt* stmt ) Stmt* Plugin::getParentStmt( Stmt* stmt )
{ {
if( parents.empty()) if( parents.empty())
buildParents( compiler ); buildParents( compiler );
...@@ -153,7 +153,7 @@ static const Decl* getDeclContext(ASTContext& context, const Stmt* stmt) ...@@ -153,7 +153,7 @@ static const Decl* getDeclContext(ASTContext& context, const Stmt* stmt)
return nullptr; return nullptr;
} }
const FunctionDecl* Plugin::parentFunctionDecl( const Stmt* stmt ) const FunctionDecl* Plugin::getParentFunctionDecl( const Stmt* stmt )
{ {
const Decl *decl = getDeclContext(compiler.getASTContext(), stmt); const Decl *decl = getDeclContext(compiler.getASTContext(), stmt);
if (decl) if (decl)
......
...@@ -67,9 +67,9 @@ protected: ...@@ -67,9 +67,9 @@ protected:
Returns the parent of the given AST node. Clang's internal AST representation doesn't provide this information, Returns the parent of the given AST node. Clang's internal AST representation doesn't provide this information,
it can only provide children, but getting the parent is often useful for inspecting a part of the AST. it can only provide children, but getting the parent is often useful for inspecting a part of the AST.
*/ */
const Stmt* parentStmt( const Stmt* stmt ); const Stmt* getParentStmt( const Stmt* stmt );
Stmt* parentStmt( Stmt* stmt ); Stmt* getParentStmt( Stmt* stmt );
const FunctionDecl* parentFunctionDecl( const Stmt* stmt ); const FunctionDecl* getParentFunctionDecl( const Stmt* stmt );
/** /**
Checks if the location is inside an UNO file, more specifically, if it forms part of the URE stable interface, Checks if the location is inside an UNO file, more specifically, if it forms part of the URE stable interface,
which is not allowed to be changed. which is not allowed to be changed.
......
...@@ -245,21 +245,21 @@ bool SingleValFields::VisitMemberExpr( const MemberExpr* memberExpr ) ...@@ -245,21 +245,21 @@ bool SingleValFields::VisitMemberExpr( const MemberExpr* memberExpr )
if (ignoreLocation(memberExpr) || !isInterestingType(fieldDecl->getType())) if (ignoreLocation(memberExpr) || !isInterestingType(fieldDecl->getType()))
return true; return true;
const FunctionDecl* parentFunction = parentFunctionDecl(memberExpr); const FunctionDecl* parentFunction = getParentFunctionDecl(memberExpr);
const CXXMethodDecl* methodDecl = dyn_cast_or_null<CXXMethodDecl>(parentFunction); const CXXMethodDecl* methodDecl = dyn_cast_or_null<CXXMethodDecl>(parentFunction);
if (methodDecl && (methodDecl->isCopyAssignmentOperator() || methodDecl->isMoveAssignmentOperator())) if (methodDecl && (methodDecl->isCopyAssignmentOperator() || methodDecl->isMoveAssignmentOperator()))
return true; return true;
// walk up the tree until we find something interesting // walk up the tree until we find something interesting
const Stmt* child = memberExpr; const Stmt* child = memberExpr;
const Stmt* parent = parentStmt(memberExpr); const Stmt* parent = getParentStmt(memberExpr);
bool bPotentiallyAssignedTo = false; bool bPotentiallyAssignedTo = false;
bool bDump = false; bool bDump = false;
std::string assignValue; std::string assignValue;
// check for field being returned by non-const ref eg. Foo& getFoo() { return f; } // check for field being returned by non-const ref eg. Foo& getFoo() { return f; }
if (parentFunction && parent && isa<ReturnStmt>(parent)) { if (parentFunction && parent && isa<ReturnStmt>(parent)) {
const Stmt* parent2 = parentStmt(parent); const Stmt* parent2 = getParentStmt(parent);
if (parent2 && isa<CompoundStmt>(parent2)) { if (parent2 && isa<CompoundStmt>(parent2)) {
QualType qt = compat::getReturnType(*parentFunction).getDesugaredType(compiler.getASTContext()); QualType qt = compat::getReturnType(*parentFunction).getDesugaredType(compiler.getASTContext());
if (!qt.isConstQualified() && qt->isReferenceType()) { if (!qt.isConstQualified() && qt->isReferenceType()) {
...@@ -292,7 +292,7 @@ bool SingleValFields::VisitMemberExpr( const MemberExpr* memberExpr ) ...@@ -292,7 +292,7 @@ bool SingleValFields::VisitMemberExpr( const MemberExpr* memberExpr )
|| isa<ExprWithCleanups>(parent)) || isa<ExprWithCleanups>(parent))
{ {
child = parent; child = parent;
parent = parentStmt(parent); parent = getParentStmt(parent);
} }
else if (isa<UnaryOperator>(parent)) else if (isa<UnaryOperator>(parent))
{ {
...@@ -304,7 +304,7 @@ bool SingleValFields::VisitMemberExpr( const MemberExpr* memberExpr ) ...@@ -304,7 +304,7 @@ bool SingleValFields::VisitMemberExpr( const MemberExpr* memberExpr )
break; break;
} }
child = parent; child = parent;
parent = parentStmt(parent); parent = getParentStmt(parent);
} }
else if (isa<CXXOperatorCallExpr>(parent)) else if (isa<CXXOperatorCallExpr>(parent))
{ {
......
...@@ -144,7 +144,7 @@ bool UnusedEnumConstants::VisitDeclRefExpr( const DeclRefExpr* declRefExpr ) ...@@ -144,7 +144,7 @@ bool UnusedEnumConstants::VisitDeclRefExpr( const DeclRefExpr* declRefExpr )
const Stmt * parent = declRefExpr; const Stmt * parent = declRefExpr;
try_again: try_again:
parent = parentStmt(parent); parent = getParentStmt(parent);
bool bWrite = false; bool bWrite = false;
bool bRead = false; bool bRead = false;
bool bDump = false; bool bDump = false;
......
...@@ -930,7 +930,7 @@ bool UnusedFields::VisitDeclRefExpr( const DeclRefExpr* declRefExpr ) ...@@ -930,7 +930,7 @@ bool UnusedFields::VisitDeclRefExpr( const DeclRefExpr* declRefExpr )
} }
void UnusedFields::checkTouchedFromOutside(const FieldDecl* fieldDecl, const Expr* memberExpr) { void UnusedFields::checkTouchedFromOutside(const FieldDecl* fieldDecl, const Expr* memberExpr) {
const FunctionDecl* memberExprParentFunction = parentFunctionDecl(memberExpr); const FunctionDecl* memberExprParentFunction = getParentFunctionDecl(memberExpr);
const CXXMethodDecl* methodDecl = dyn_cast_or_null<CXXMethodDecl>(memberExprParentFunction); const CXXMethodDecl* methodDecl = dyn_cast_or_null<CXXMethodDecl>(memberExprParentFunction);
MyFieldInfo fieldInfo = niceName(fieldDecl); MyFieldInfo fieldInfo = niceName(fieldDecl);
......
...@@ -230,13 +230,13 @@ bool UnusedMethods::VisitCallExpr(CallExpr* expr) ...@@ -230,13 +230,13 @@ bool UnusedMethods::VisitCallExpr(CallExpr* expr)
gotfunc: gotfunc:
logCallToRootMethods(calleeFunctionDecl, callSet); logCallToRootMethods(calleeFunctionDecl, callSet);
const Stmt* parent = parentStmt(expr); const Stmt* parent = getParentStmt(expr);
// Now do the checks necessary for the "can be private" analysis // Now do the checks necessary for the "can be private" analysis
CXXMethodDecl* calleeMethodDecl = dyn_cast<CXXMethodDecl>(calleeFunctionDecl); CXXMethodDecl* calleeMethodDecl = dyn_cast<CXXMethodDecl>(calleeFunctionDecl);
if (calleeMethodDecl && calleeMethodDecl->getAccess() != AS_private) if (calleeMethodDecl && calleeMethodDecl->getAccess() != AS_private)
{ {
const FunctionDecl* parentFunctionOfCallSite = parentFunctionDecl(expr); const FunctionDecl* parentFunctionOfCallSite = getParentFunctionDecl(expr);
if (parentFunctionOfCallSite != calleeFunctionDecl) { if (parentFunctionOfCallSite != calleeFunctionDecl) {
if (!parentFunctionOfCallSite || !ignoreLocation(parentFunctionOfCallSite)) { if (!parentFunctionOfCallSite || !ignoreLocation(parentFunctionOfCallSite)) {
calledFromOutsideSet.insert(niceName(calleeFunctionDecl)); calledFromOutsideSet.insert(niceName(calleeFunctionDecl));
...@@ -333,7 +333,7 @@ bool UnusedMethods::VisitDeclRefExpr( const DeclRefExpr* declRefExpr ) ...@@ -333,7 +333,7 @@ bool UnusedMethods::VisitDeclRefExpr( const DeclRefExpr* declRefExpr )
const CXXMethodDecl* methodDecl = dyn_cast<CXXMethodDecl>(functionDecl); const CXXMethodDecl* methodDecl = dyn_cast<CXXMethodDecl>(functionDecl);
if (methodDecl && methodDecl->getAccess() != AS_private) if (methodDecl && methodDecl->getAccess() != AS_private)
{ {
const FunctionDecl* parentFunctionOfCallSite = parentFunctionDecl(declRefExpr); const FunctionDecl* parentFunctionOfCallSite = getParentFunctionDecl(declRefExpr);
if (parentFunctionOfCallSite != functionDecl) { if (parentFunctionOfCallSite != functionDecl) {
if (!parentFunctionOfCallSite || !ignoreLocation(parentFunctionOfCallSite)) { if (!parentFunctionOfCallSite || !ignoreLocation(parentFunctionOfCallSite)) {
calledFromOutsideSet.insert(niceName(functionDecl)); calledFromOutsideSet.insert(niceName(functionDecl));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment