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