[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [clazy] checks: readability++
From:       Sergio Martins <smartins () kde ! org>
Date:       2016-01-31 19:01:03
Message-ID: E1aPxF9-0002Un-Ir () scm ! kde ! org
[Download RAW message or body]

Git commit e9959dec5e32ae5592b09a4eb1d5d691f9481edb by Sergio Martins.
Committed on 31/01/2016 at 19:00.
Pushed by smartins into branch 'master'.

readability++

M  +6    -9    checks/qstringuneededheapallocations.cpp

http://commits.kde.org/clazy/e9959dec5e32ae5592b09a4eb1d5d691f9481edb

diff --git a/checks/qstringuneededheapallocations.cpp \
b/checks/qstringuneededheapallocations.cpp index 8a61804..1ed14cb 100644
--- a/checks/qstringuneededheapallocations.cpp
+++ b/checks/qstringuneededheapallocations.cpp
@@ -185,7 +185,7 @@ void QStringUneededHeapAllocations::VisitCtor(Stmt *stm)
         vector<FixItHint> fixits;
         if (isFixitEnabled(QLatin1StringAllocations)) {
             if (!qlatin1Ctor->getLocStart().isMacroID()) {
-                if (ternary == nullptr) {
+                if (!ternary) {
                     fixits = fixItReplaceWordWithWord(qlatin1Ctor, "QStringLiteral", \
"QLatin1String", QLatin1StringAllocations);  bool shouldRemoveQString = \
qlatin1Ctor->getLocStart().getRawEncoding() != stm->getLocStart().getRawEncoding() && \
dyn_cast_or_null<CXXBindTemporaryExpr>(HierarchyUtils::parent(m_parentMap, \
ctorExpr));  if (shouldRemoveQString) {
@@ -208,9 +208,9 @@ void QStringUneededHeapAllocations::VisitCtor(Stmt *stm)
         emitWarning(stm->getLocStart(), msg, fixits);
     } else {
         vector<FixItHint> fixits;
-        if (ctorExpr->child_begin() != ctorExpr->child_end()) {
+        if (clazy_std::hasChildren(ctorExpr)) {
             auto pointerDecay = \
                dyn_cast<ImplicitCastExpr>(*(ctorExpr->child_begin()));
-            if (pointerDecay && pointerDecay->child_begin() != \
pointerDecay->child_end()) { +            if (clazy_std::hasChildren(pointerDecay)) {
                 StringLiteral *lt = \
dyn_cast<StringLiteral>(*pointerDecay->child_begin());  if (lt && \
                isFixitEnabled(CharPtrAllocations)) {
                     Stmt *grandParent = HierarchyUtils::parent(m_parentMap, lt, 2);
@@ -218,7 +218,7 @@ void QStringUneededHeapAllocations::VisitCtor(Stmt *stm)
                     Stmt *grandGrandGrandParent = \
HierarchyUtils::parent(m_parentMap, lt, 4);  if (grandParent == ctorExpr && \
grandGrandParent && isa<CXXBindTemporaryExpr>(grandGrandParent) && \
                grandGrandGrandParent && \
                isa<CXXFunctionalCastExpr>(grandGrandGrandParent)) {
                         // This is the case of QString("foo"), replace QString
-                        //llvm::errs() << "case1\n";
+
                         const bool literalIsEmpty = lt->getLength() == 0;
                         if (literalIsEmpty && \
                HierarchyUtils::getFirstParentOfType<MemberExpr>(m_parentMap, \
                ctorExpr) == nullptr)
                             fixits = fixItReplaceWordWithWord(ctorExpr, \
"QLatin1String", "QString", CharPtrAllocations); @@ -227,7 +227,6 @@ void \
QStringUneededHeapAllocations::VisitCtor(Stmt *stm)  else
                             queueManualFixitWarning(ctorExpr->getLocStart(), \
CharPtrAllocations, "Can't use QStringLiteral in macro.");  } else {
-                        //llvm::errs() << "case2\n";
 
                         auto parentMemberCallExpr = \
HierarchyUtils::getFirstParentOfType<CXXMemberCallExpr>(m_parentMap, lt, \
/*maxDepth=*/6); // 6 seems like a nice max from the ASTs I've seen  
@@ -295,7 +294,6 @@ vector<FixItHint> \
QStringUneededHeapAllocations::fixItReplaceWordWithWordInTerna  return fixits;
 }
 
-
 // true for: QString::fromLatin1().arg()
 // false for: QString::fromLatin1("")
 // true for: QString s = QString::fromLatin1("foo")
@@ -310,7 +308,7 @@ static bool isQStringLiteralCandidate(Stmt *s, ParentMap *map, \
int currentCall =  return true;
 
     auto constructExpr = dyn_cast<CXXConstructExpr>(s);
-    if (constructExpr && isOfClass(constructExpr, "QString"))
+    if (isOfClass(constructExpr, "QString"))
         return true;
 
     if (Utils::isAssignOperator(dyn_cast<CXXOperatorCallExpr>(s), "QString", "class \
QLatin1String")) @@ -321,8 +319,7 @@ static bool isQStringLiteralCandidate(Stmt *s, \
ParentMap *map, int currentCall =  
     CallExpr *callExpr = dyn_cast<CallExpr>(s);
     StringLiteral *literal = stringLiteralForCall(callExpr);
-    CXXOperatorCallExpr *op = dyn_cast<CXXOperatorCallExpr>(s);
-    if (op)
+    if (isa<CXXOperatorCallExpr>(s))
         return false;
 
     if (currentCall > 0 && callExpr) {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic