Felix Berger | adfdc14 | 2016-03-05 21:17:58 +0000 | [diff] [blame] | 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 { |
Etienne Bergeron | 2a4c00f | 2016-05-03 02:54:05 +0000 | [diff] [blame] | 17 | namespace fixit { |
Felix Berger | adfdc14 | 2016-03-05 21:17:58 +0000 | [diff] [blame] | 18 | |
| 19 | FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context) { |
| 20 | SourceLocation AmpLocation = Var.getLocation(); |
Jonas Toth | a78c249 | 2018-10-05 14:15:19 +0000 | [diff] [blame] | 21 | auto Token = utils::lexer::getPreviousToken( |
| 22 | AmpLocation, Context.getSourceManager(), Context.getLangOpts()); |
Felix Berger | adfdc14 | 2016-03-05 21:17:58 +0000 | [diff] [blame] | 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 | |
Etienne Bergeron | 2a4c00f | 2016-05-03 02:54:05 +0000 | [diff] [blame] | 34 | } // namespace fixit |
Felix Berger | adfdc14 | 2016-03-05 21:17:58 +0000 | [diff] [blame] | 35 | } // namespace utils |
| 36 | } // namespace tidy |
| 37 | } // namespace clang |