clang-tools 10.0.0

PragmaCommentHandler.cpp
Go to the documentation of this file.
1 //===-- PragmaCommentHandler.cpp - find all symbols -----------------------===//
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 "PragmaCommentHandler.h"
10 #include "FindAllSymbols.h"
11 #include "HeaderMapCollector.h"
12 #include "clang/Lex/Preprocessor.h"
13 #include "llvm/Support/Regex.h"
14
15 namespace clang {
16 namespace find_all_symbols {
17 namespace {
18 const char IWYUPragma[] = "// IWYU pragma: private, include ";
19 } // namespace
20
21 bool PragmaCommentHandler::HandleComment(Preprocessor &PP, SourceRange Range) {
22 StringRef Text =
23 Lexer::getSourceText(CharSourceRange::getCharRange(Range),
24 PP.getSourceManager(), PP.getLangOpts());
25 size_t Pos = Text.find(IWYUPragma);
26 if (Pos == StringRef::npos)
27 return false;
28 StringRef RemappingFilePath = Text.substr(Pos + std::strlen(IWYUPragma));
29 Collector->addHeaderMapping(
30 PP.getSourceManager().getFilename(Range.getBegin()),
31 RemappingFilePath.trim("\"<>"));
32 return false;
33 }
34
35 } // namespace find_all_symbols
36 } // namespace clang
clang::find_all_symbols::HeaderMapCollector::addHeaderMapping
void addHeaderMapping(llvm::StringRef OrignalHeaderPath, llvm::StringRef MappingHeaderPath)
Definition: HeaderMapCollector.h:30
Text
std::string Text
Definition: HTMLGenerator.cpp:80
clang::find_all_symbols::PragmaCommentHandler::HandleComment
bool HandleComment(Preprocessor &PP, SourceRange Range) override
Definition: PragmaCommentHandler.cpp:21
HeaderMapCollector.h
PragmaCommentHandler.h
FindAllSymbols.h
Pos
Position Pos
Definition: SourceCode.cpp:772
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::bugprone::PP
static Preprocessor * PP
Definition: BadSignalToKillThreadCheck.cpp:28
Range
CharSourceRange Range
SourceRange for the file name.
Definition: IncludeOrderCheck.cpp:38