2016-03-06 05:17:58 +08:00
|
|
|
//===--- FixItHintUtils.cpp - clang-tidy-----------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-03-06 05:17:58 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#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();
|
2018-10-05 22:15:19 +08:00
|
|
|
auto Token = utils::lexer::getPreviousToken(
|
|
|
|
AmpLocation, Context.getSourceManager(), Context.getLangOpts());
|
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
|