aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergio Martins <iamsergio@gmail.com>2019-04-23 18:31:50 +0100
committerSergio Martins <iamsergio@gmail.com>2019-04-23 18:34:08 +0100
commita96b19e255665fc6429212102d40b3f69eb6ed79 (patch)
treebbce6d828a6f851a4ab1dc050f7561489a8a8707
parent616ca1aa9de2b4d43aa3d53fb11e1ac4e3ec49d7 (diff)
qstring-allocations: Refactor in preparation for a fix
CCBUG: 406799
-rw-r--r--src/checks/level2/qstring-allocations.cpp21
-rw-r--r--src/checks/level2/qstring-allocations.h3
2 files changed, 16 insertions, 8 deletions
diff --git a/src/checks/level2/qstring-allocations.cpp b/src/checks/level2/qstring-allocations.cpp
index 5f391f8b..34c0baf1 100644
--- a/src/checks/level2/qstring-allocations.cpp
+++ b/src/checks/level2/qstring-allocations.cpp
@@ -251,7 +251,7 @@ void QStringAllocations::VisitCtor(Stmt *stm)
}
}
- emitWarning(clazy::getLocStart(stm), msg, fixits);
+ maybeEmitWarning(clazy::getLocStart(stm), msg, fixits);
} else {
vector<FixItHint> fixits;
if (clazy::hasChildren(ctorExpr)) {
@@ -293,7 +293,7 @@ void QStringAllocations::VisitCtor(Stmt *stm)
}
}
- emitWarning(clazy::getLocStart(stm), msg, fixits);
+ maybeEmitWarning(clazy::getLocStart(stm), msg, fixits);
}
}
@@ -302,7 +302,7 @@ vector<FixItHint> QStringAllocations::fixItReplaceWordWithWord(clang::Stmt *begi
StringLiteral *lt = stringLiteralForCall(begin);
if (replacee == "QLatin1String") {
if (lt && !Utils::isAscii(lt)) {
- emitWarning(clazy::getLocStart(lt), "Don't use QLatin1String with non-latin1 literals");
+ maybeEmitWarning(clazy::getLocStart(lt), "Don't use QLatin1String with non-latin1 literals");
return {};
}
}
@@ -517,7 +517,7 @@ void QStringAllocations::VisitOperatorCall(Stmt *stm)
}
string msg = string("QString(const char*) being called");
- emitWarning(clazy::getLocStart(stm), msg, fixits);
+ maybeEmitWarning(clazy::getLocStart(stm), msg, fixits);
}
void QStringAllocations::VisitFromLatin1OrUtf8(Stmt *stmt)
@@ -552,7 +552,7 @@ void QStringAllocations::VisitFromLatin1OrUtf8(Stmt *stmt)
if (!ternaries.empty()) {
auto ternary = ternaries[0];
if (Utils::ternaryOperatorIsOfStringLiteral(ternary)) {
- emitWarning(clazy::getLocStart(stmt), string("QString::fromLatin1() being passed a literal"));
+ maybeEmitWarning(clazy::getLocStart(stmt), string("QString::fromLatin1() being passed a literal"));
}
return;
@@ -566,9 +566,9 @@ void QStringAllocations::VisitFromLatin1OrUtf8(Stmt *stmt)
}
if (clazy::name(functionDecl) == "fromLatin1") {
- emitWarning(clazy::getLocStart(stmt), string("QString::fromLatin1() being passed a literal"), fixits);
+ maybeEmitWarning(clazy::getLocStart(stmt), string("QString::fromLatin1() being passed a literal"), fixits);
} else {
- emitWarning(clazy::getLocStart(stmt), string("QString::fromUtf8() being passed a literal"), fixits);
+ maybeEmitWarning(clazy::getLocStart(stmt), string("QString::fromUtf8() being passed a literal"), fixits);
}
}
@@ -594,5 +594,10 @@ void QStringAllocations::VisitAssignOperatorQLatin1String(Stmt *stmt)
: fixItReplaceWordWithWordInTernary(ternary);
}
- emitWarning(clazy::getLocStart(stmt), string("QString::operator=(QLatin1String(\"literal\")"), fixits);
+ maybeEmitWarning(clazy::getLocStart(stmt), string("QString::operator=(QLatin1String(\"literal\")"), fixits);
+}
+
+void QStringAllocations::maybeEmitWarning(SourceLocation loc, string error, const std::vector<FixItHint> &fixits)
+{
+ emitWarning(loc, error, fixits);
}
diff --git a/src/checks/level2/qstring-allocations.h b/src/checks/level2/qstring-allocations.h
index 3b6c5f4e..b05be202 100644
--- a/src/checks/level2/qstring-allocations.h
+++ b/src/checks/level2/qstring-allocations.h
@@ -72,6 +72,9 @@ private:
void VisitFromLatin1OrUtf8(clang::Stmt *);
void VisitAssignOperatorQLatin1String(clang::Stmt *);
+ void maybeEmitWarning(clang::SourceLocation loc, std::string error,
+ const std::vector<clang::FixItHint> &fixits = {});
+
std::vector<clang::FixItHint> fixItReplaceWordWithWord(clang::Stmt *begin, const std::string &replacement, const std::string &replacee, int fixitType);
std::vector<clang::FixItHint> fixItReplaceWordWithWordInTernary(clang::ConditionalOperator *);
std::vector<clang::FixItHint> fixItReplaceFromLatin1OrFromUtf8(clang::CallExpr *callExpr, FromFunction);