2016-03-06 05:17:58 +08:00
|
|
|
//===--- FixItHintUtils.cpp - clang-tidy-----------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "FixItHintUtils.h"
|
|
|
|
#include "LexerUtils.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace utils {
|
2016-05-03 10:54:05 +08:00
|
|
|
namespace fixit {
|
2016-03-06 05:17:58 +08:00
|
|
|
|
|
|
|
FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context) {
|
|
|
|
SourceLocation AmpLocation = Var.getLocation();
|
2017-02-06 23:46:33 +08:00
|
|
|
auto Token = utils::lexer::getPreviousToken(Context, AmpLocation);
|
2016-03-06 05:17:58 +08:00
|
|
|
if (!Token.is(tok::unknown))
|
|
|
|
AmpLocation = Lexer::getLocForEndOfToken(Token.getLocation(), 0,
|
|
|
|
Context.getSourceManager(),
|
|
|
|
Context.getLangOpts());
|
|
|
|
return FixItHint::CreateInsertion(AmpLocation, "&");
|
|
|
|
}
|
|
|
|
|
|
|
|
FixItHint changeVarDeclToConst(const VarDecl &Var) {
|
|
|
|
return FixItHint::CreateInsertion(Var.getTypeSpecStartLoc(), "const ");
|
|
|
|
}
|
|
|
|
|
2016-05-03 10:54:05 +08:00
|
|
|
} // namespace fixit
|
2016-03-06 05:17:58 +08:00
|
|
|
} // namespace utils
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|