clang-tools  9.0.0
FixItHintUtils.cpp
Go to the documentation of this file.
1 //===--- FixItHintUtils.cpp - clang-tidy-----------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "FixItHintUtils.h"
10 #include "LexerUtils.h"
11 #include "clang/AST/ASTContext.h"
12 
13 namespace clang {
14 namespace tidy {
15 namespace utils {
16 namespace fixit {
17 
18 FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context) {
19  SourceLocation AmpLocation = Var.getLocation();
20  auto Token = utils::lexer::getPreviousToken(
21  AmpLocation, Context.getSourceManager(), Context.getLangOpts());
22  if (!Token.is(tok::unknown))
23  AmpLocation = Lexer::getLocForEndOfToken(Token.getLocation(), 0,
24  Context.getSourceManager(),
25  Context.getLangOpts());
26  return FixItHint::CreateInsertion(AmpLocation, "&");
27 }
28 
29 FixItHint changeVarDeclToConst(const VarDecl &Var) {
30  return FixItHint::CreateInsertion(Var.getTypeSpecStartLoc(), "const ");
31 }
32 
33 } // namespace fixit
34 } // namespace utils
35 } // namespace tidy
36 } // 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:16
===– 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 &.