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 { |
| 17 | namespace create_fix_it { |
| 18 | |
| 19 | FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context) { |
| 20 | SourceLocation AmpLocation = Var.getLocation(); |
| 21 | auto Token = lexer_utils::getPreviousNonCommentToken(Context, AmpLocation); |
| 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 create_fix_it |
| 34 | } // namespace utils |
| 35 | } // namespace tidy |
| 36 | } // namespace clang |