blob: 9da93653dc01fad8ec41450a98eea24de72b235d [file] [log] [blame]
Felix Bergeradfdc142016-03-05 21:17:58 +00001//===--- FixItHintUtils.cpp - clang-tidy-----------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "FixItHintUtils.h"
11#include "LexerUtils.h"
12#include "clang/AST/ASTContext.h"
13
14namespace clang {
15namespace tidy {
16namespace utils {
Etienne Bergeron2a4c00f2016-05-03 02:54:05 +000017namespace fixit {
Felix Bergeradfdc142016-03-05 21:17:58 +000018
19FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context) {
20 SourceLocation AmpLocation = Var.getLocation();
Jonas Totha78c2492018-10-05 14:15:19 +000021 auto Token = utils::lexer::getPreviousToken(
22 AmpLocation, Context.getSourceManager(), Context.getLangOpts());
Felix Bergeradfdc142016-03-05 21:17:58 +000023 if (!Token.is(tok::unknown))
24 AmpLocation = Lexer::getLocForEndOfToken(Token.getLocation(), 0,
25 Context.getSourceManager(),
26 Context.getLangOpts());
27 return FixItHint::CreateInsertion(AmpLocation, "&");
28}
29
30FixItHint changeVarDeclToConst(const VarDecl &Var) {
31 return FixItHint::CreateInsertion(Var.getTypeSpecStartLoc(), "const ");
32}
33
Etienne Bergeron2a4c00f2016-05-03 02:54:05 +000034} // namespace fixit
Felix Bergeradfdc142016-03-05 21:17:58 +000035} // namespace utils
36} // namespace tidy
37} // namespace clang