clang-tools 3.8.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

LexerUtils.cpp
Go to the documentation of this file.
1 //===--- LexerUtils.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 "LexerUtils.h"
11
12 namespace clang {
13 namespace tidy {
14 namespace lexer_utils {
15
16 Token getPreviousNonCommentToken(const ASTContext &Context,
17 SourceLocation Location) {
18 const auto &SourceManager = Context.getSourceManager();
19 Token Token;
20 Token.setKind(tok::unknown);
21 Location = Location.getLocWithOffset(-1);
22 auto StartOfFile =
23 SourceManager.getLocForStartOfFile(SourceManager.getFileID(Location));
24 while (Location != StartOfFile) {
25 Location = Lexer::GetBeginningOfToken(Location, SourceManager,
26 Context.getLangOpts());
27 if (!Lexer::getRawToken(Location, Token, SourceManager,
28 Context.getLangOpts()) &&
29 !Token.is(tok::comment)) {
30 break;
31 }
32 Location = Location.getLocWithOffset(-1);
33 }
34 return Token;
35 }
36
37 } // namespace lexer_utils
38 } // namespace tidy
39 } // namespace clang
clang::tidy::lexer_utils::getPreviousNonCommentToken
Token getPreviousNonCommentToken(const ASTContext &Context, SourceLocation Location)
Definition: LexerUtils.cpp:16
LexerUtils.h
Context
ClangTidyContext & Context
Definition: ClangTidy.cpp:93
Location
Definition: Modularize.cpp:386