aboutsummaryrefslogtreecommitdiffstats
path: root/src/FixItUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/FixItUtils.cpp')
-rw-r--r--src/FixItUtils.cpp68
1 files changed, 34 insertions, 34 deletions
diff --git a/src/FixItUtils.cpp b/src/FixItUtils.cpp
index d6f11d2f..f6c05081 100644
--- a/src/FixItUtils.cpp
+++ b/src/FixItUtils.cpp
@@ -29,11 +29,11 @@
#include <clang/Lex/Lexer.h>
#include <StringUtils.h>
-using namespace FixItUtils;
+using namespace clazy;
using namespace clang;
using namespace std;
-clang::FixItHint FixItUtils::createReplacement(clang::SourceRange range, const std::string &replacement)
+clang::FixItHint clazy::createReplacement(clang::SourceRange range, const std::string &replacement)
{
if (range.getBegin().isInvalid()) {
return {};
@@ -42,7 +42,7 @@ clang::FixItHint FixItUtils::createReplacement(clang::SourceRange range, const s
}
}
-clang::FixItHint FixItUtils::createInsertion(clang::SourceLocation start, const std::string &insertion)
+clang::FixItHint clazy::createInsertion(clang::SourceLocation start, const std::string &insertion)
{
if (start.isInvalid()) {
return {};
@@ -51,7 +51,7 @@ clang::FixItHint FixItUtils::createInsertion(clang::SourceLocation start, const
}
}
-SourceRange FixItUtils::rangeForLiteral(const ASTContext *context, StringLiteral *lt)
+SourceRange clazy::rangeForLiteral(const ASTContext *context, StringLiteral *lt)
{
if (!lt)
return {};
@@ -63,11 +63,11 @@ SourceRange FixItUtils::rangeForLiteral(const ASTContext *context, StringLiteral
}
SourceRange range;
- range.setBegin(lt->getLocStart());
+ range.setBegin(getLocStart(lt));
SourceLocation end = Lexer::getLocForEndOfToken(lastTokenLoc, 0,
context->getSourceManager(),
- context->getLangOpts()); // For some reason lt->getLocStart() is == to lt->getLocEnd()
+ context->getLangOpts()); // For some reason getLocStart(lt) is == to getLocEnd(lt)
if (!end.isValid()) {
return {};
@@ -77,13 +77,13 @@ SourceRange FixItUtils::rangeForLiteral(const ASTContext *context, StringLiteral
return range;
}
-void FixItUtils::insertParentMethodCall(const std::string &method, SourceRange range, std::vector<FixItHint> &fixits)
+void clazy::insertParentMethodCall(const std::string &method, SourceRange range, std::vector<FixItHint> &fixits)
{
- fixits.push_back(FixItUtils::createInsertion(range.getEnd(), ")"));
- fixits.push_back(FixItUtils::createInsertion(range.getBegin(), method + '('));
+ fixits.push_back(clazy::createInsertion(range.getEnd(), ")"));
+ fixits.push_back(clazy::createInsertion(range.getBegin(), method + '('));
}
-bool FixItUtils::insertParentMethodCallAroundStringLiteral(const ASTContext *context,
+bool clazy::insertParentMethodCallAroundStringLiteral(const ASTContext *context,
const std::string &method,
StringLiteral *lt,
std::vector<FixItHint> &fixits)
@@ -99,7 +99,7 @@ bool FixItUtils::insertParentMethodCallAroundStringLiteral(const ASTContext *con
return true;
}
-SourceLocation FixItUtils::locForNextToken(const ASTContext *context, SourceLocation start, tok::TokenKind kind)
+SourceLocation clazy::locForNextToken(const ASTContext *context, SourceLocation start, tok::TokenKind kind)
{
if (!start.isValid())
return {};
@@ -117,12 +117,12 @@ SourceLocation FixItUtils::locForNextToken(const ASTContext *context, SourceLoca
return locForNextToken(context, nextStart, kind);
}
-SourceLocation FixItUtils::biggestSourceLocationInStmt(const SourceManager &sm, Stmt *stmt)
+SourceLocation clazy::biggestSourceLocationInStmt(const SourceManager &sm, Stmt *stmt)
{
if (!stmt)
return {};
- SourceLocation biggestLoc = stmt->getLocEnd();
+ SourceLocation biggestLoc = getLocEnd(stmt);
for (auto child : stmt->children()) {
SourceLocation candidateLoc = biggestSourceLocationInStmt(sm, child);
@@ -133,25 +133,25 @@ SourceLocation FixItUtils::biggestSourceLocationInStmt(const SourceManager &sm,
return biggestLoc;
}
-SourceLocation FixItUtils::locForEndOfToken(const ASTContext *context, SourceLocation start, int offset)
+SourceLocation clazy::locForEndOfToken(const ASTContext *context, SourceLocation start, int offset)
{
return Lexer::getLocForEndOfToken(start, offset, context->getSourceManager(), context->getLangOpts());
}
-bool FixItUtils::transformTwoCallsIntoOne(const ASTContext *context, CallExpr *call1, CXXMemberCallExpr *call2,
+bool clazy::transformTwoCallsIntoOne(const ASTContext *context, CallExpr *call1, CXXMemberCallExpr *call2,
const string &replacement, vector<FixItHint> &fixits)
{
Expr *implicitArgument = call2->getImplicitObjectArgument();
if (!implicitArgument)
return false;
- const SourceLocation start1 = call1->getLocStart();
- const SourceLocation end1 = FixItUtils::locForEndOfToken(context, start1, -1); // -1 of offset, so we don't need to insert '('
+ const SourceLocation start1 = getLocStart(call1);
+ const SourceLocation end1 = clazy::locForEndOfToken(context, start1, -1); // -1 of offset, so we don't need to insert '('
if (end1.isInvalid())
return false;
- const SourceLocation start2 = implicitArgument->getLocEnd();
- const SourceLocation end2 = call2->getLocEnd();
+ const SourceLocation start2 = getLocEnd(implicitArgument);
+ const SourceLocation end2 = getLocEnd(call2);
if (start2.isInvalid() || end2.isInvalid())
return false;
@@ -160,43 +160,43 @@ bool FixItUtils::transformTwoCallsIntoOne(const ASTContext *context, CallExpr *c
// ^ end1
// ^ start2
// ^ end2
- fixits.push_back(FixItUtils::createReplacement({ start1, end1 }, replacement));
- fixits.push_back(FixItUtils::createReplacement({ start2, end2 }, ")"));
+ fixits.push_back(clazy::createReplacement({ start1, end1 }, replacement));
+ fixits.push_back(clazy::createReplacement({ start2, end2 }, ")"));
return true;
}
-bool FixItUtils::transformTwoCallsIntoOneV2(const ASTContext *context, CXXMemberCallExpr *call2,
+bool clazy::transformTwoCallsIntoOneV2(const ASTContext *context, CXXMemberCallExpr *call2,
const string &replacement, std::vector<FixItHint> &fixits)
{
Expr *implicitArgument = call2->getImplicitObjectArgument();
if (!implicitArgument)
return false;
- SourceLocation start = implicitArgument->getLocStart();
- start = FixItUtils::locForEndOfToken(context, start, 0);
- const SourceLocation end = call2->getLocEnd();
+ SourceLocation start = getLocStart(implicitArgument);
+ start = clazy::locForEndOfToken(context, start, 0);
+ const SourceLocation end = getLocEnd(call2);
if (start.isInvalid() || end.isInvalid())
return false;
- fixits.push_back(FixItUtils::createReplacement({ start, end }, replacement));
+ fixits.push_back(clazy::createReplacement({ start, end }, replacement));
return true;
}
-FixItHint FixItUtils::fixItReplaceWordWithWord(const ASTContext *context, clang::Stmt *begin,
+FixItHint clazy::fixItReplaceWordWithWord(const ASTContext *context, clang::Stmt *begin,
const string &replacement, const string &replacee)
{
auto &sm = context->getSourceManager();
- SourceLocation rangeStart = begin->getLocStart();
+ SourceLocation rangeStart = getLocStart(begin);
SourceLocation rangeEnd = Lexer::getLocForEndOfToken(rangeStart, -1, sm, context->getLangOpts());
if (rangeEnd.isInvalid()) {
// Fallback. Have seen a case in the wild where the above would fail, it's very rare
rangeEnd = rangeStart.getLocWithOffset(replacee.size() - 2);
if (rangeEnd.isInvalid()) {
- StringUtils::printLocation(sm, rangeStart);
- StringUtils::printLocation(sm, rangeEnd);
- StringUtils::printLocation(sm, Lexer::getLocForEndOfToken(rangeStart, 0, sm, context->getLangOpts()));
+ clazy::printLocation(sm, rangeStart);
+ clazy::printLocation(sm, rangeEnd);
+ clazy::printLocation(sm, Lexer::getLocForEndOfToken(rangeStart, 0, sm, context->getLangOpts()));
return {};
}
}
@@ -204,9 +204,9 @@ FixItHint FixItUtils::fixItReplaceWordWithWord(const ASTContext *context, clang:
return FixItHint::CreateReplacement(SourceRange(rangeStart, rangeEnd), replacement);
}
-vector<FixItHint> FixItUtils::fixItRemoveToken(const ASTContext *context, Stmt *stmt, bool removeParenthesis)
+vector<FixItHint> clazy::fixItRemoveToken(const ASTContext *context, Stmt *stmt, bool removeParenthesis)
{
- SourceLocation start = stmt->getLocStart();
+ SourceLocation start = getLocStart(stmt);
SourceLocation end = Lexer::getLocForEndOfToken(start, removeParenthesis ? 0 : -1,
context->getSourceManager(), context->getLangOpts());
@@ -217,7 +217,7 @@ vector<FixItHint> FixItUtils::fixItRemoveToken(const ASTContext *context, Stmt *
if (removeParenthesis) {
// Remove the last parenthesis
- fixits.push_back(FixItHint::CreateRemoval(SourceRange(stmt->getLocEnd(), stmt->getLocEnd())));
+ fixits.push_back(FixItHint::CreateRemoval(SourceRange(getLocEnd(stmt), getLocEnd(stmt))));
}
}