コード例 #1
0
ファイル: mocppcallbacks.cpp プロジェクト: gmrehbein/moc-ng
void MocPPCallbacks::InclusionDirective(clang::SourceLocation HashLoc, const clang::Token& IncludeTok, llvm::StringRef FileName, bool IsAngled, clang::CharSourceRange FilenameRange, const clang::FileEntry* File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const clang::Module* Imported)
{
    if (!File && ShouldWarnHeaderNotFound) {
        /* This happens when we are not running as a plugin
         * We want to transform the "include not found" error in a warning.
         */
        PP.getDiagnostics().Report(FilenameRange.getBegin(),
                                   PP.getDiagnostics().getCustomDiagID(clang::DiagnosticsEngine::Warning,
                                           "'%0' file not found"))
                << FileName << FilenameRange;
    }
    ShouldWarnHeaderNotFound = false;
}
コード例 #2
0
ファイル: utils.cpp プロジェクト: R1tschY/refactor-cpp
void printRenaming(
  clang::ASTContext* context,
  clang::CharSourceRange range,
  llvm::StringRef replacement)
{
  auto& diag = context->getDiagnostics();
  static unsigned diagID = diag.getCustomDiagID(
    DiagnosticsEngine::Warning,
    "Will be replace with %0.");
  {
    auto builder = diag.Report(range.getBegin(), diagID);
    builder.AddString(replacement);
    builder.AddSourceRange(range);
  }
}
コード例 #3
0
void PreprocessorCallback::InclusionDirective(clang::SourceLocation HashLoc, const clang::Token& IncludeTok,
                                              llvm::StringRef FileName, bool IsAngled,
                                              clang::CharSourceRange FilenameRange, const clang::FileEntry* File,
                                              llvm::StringRef SearchPath, llvm::StringRef RelativePath,
                                              const clang::Module* Imported)
{
    if (!HashLoc.isValid() || !HashLoc.isFileID() || !File)
        return;
    clang::SourceManager &sm = annotator.getSourceMgr();
    clang::FileID FID = sm.getFileID(HashLoc);
    if (!annotator.shouldProcess(FID))
        return;

    std::string link = annotator.pathTo(FID, File);
    if (link.empty())
      return;

    auto B = sm.getFileOffset(FilenameRange.getBegin());
    auto E = sm.getFileOffset(FilenameRange.getEnd());

    annotator.generator(FID).addTag("a", "href=\"" % link % "\"", B, E-B);
}
コード例 #4
0
// Get the raw source string of the range.
llvm::StringRef
PPCallbacksTracker::getSourceString(clang::CharSourceRange Range) {
  const char *B = PP.getSourceManager().getCharacterData(Range.getBegin());
  const char *E = PP.getSourceManager().getCharacterData(Range.getEnd());
  return llvm::StringRef(B, E - B);
}