clang-tools  8.0.0
FixItHintUtils.cpp
Go to the documentation of this file.
1 //===--- 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 
14 namespace clang {
15 namespace tidy {
16 namespace utils {
17 namespace fixit {
18 
19 FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context) {
20  SourceLocation AmpLocation = Var.getLocation();
21  auto Token = utils::lexer::getPreviousToken(
22  AmpLocation, Context.getSourceManager(), Context.getLangOpts());
23  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 
30 FixItHint changeVarDeclToConst(const VarDecl &Var) {
31  return FixItHint::CreateInsertion(Var.getTypeSpecStartLoc(), "const ");
32 }
33 
34 } // namespace fixit
35 } // namespace utils
36 } // namespace tidy
37 } // namespace clang
Token getPreviousToken(SourceLocation Location, const SourceManager &SM, const LangOptions &LangOpts, bool SkipComments)
Returns previous token or tok::unknown if not found.
Definition: LexerUtils.cpp:17
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
FixItHint changeVarDeclToConst(const VarDecl &Var)
Creates fix to make VarDecl const qualified.
FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context)
Creates fix to make VarDecl a reference by adding &.