// Append a CharSourceRange argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
                                        clang::CharSourceRange Value) {
  if (Value.isInvalid()) {
    appendArgument(Name, "(invalid)");
    return;
  }
  appendArgument(Name, getSourceString(Value).str().c_str());
}
Exemplo n.º 2
0
void PPIncludeCallback::InclusionDirective(
  clang::SourceLocation hashLoc_,
  const clang::Token&,
  clang::StringRef fileName_,
  bool,
  clang::CharSourceRange filenameRange_,
  const clang::FileEntry*,
  clang::StringRef searchPath_,
  clang::StringRef,
  const clang::Module*,
  clang::SrcMgr::CharacteristicKind)
{
  if (searchPath_.empty())
    return;

  clang::SourceLocation expLoc = _clangSrcMgr.getExpansionLoc(hashLoc_);
  clang::PresumedLoc presLoc = _clangSrcMgr.getPresumedLoc(expLoc);

  //--- Included file ---//

  std::string includedPath = searchPath_.str() + '/' + fileName_.str();
  model::FilePtr included = _ctx.srcMgr.getFile(includedPath);
  included->parseStatus = model::File::PSFullyParsed;
  if (included->type != model::File::DIRECTORY_TYPE &&
      included->type != _cppSourceType)
  {
    included->type = _cppSourceType;
    _ctx.srcMgr.updateFile(*included);
  }

  //--- Includer file ---//

  std::string includerPath = presLoc.getFilename();
  model::FilePtr includer = _ctx.srcMgr.getFile(includerPath);
  includer->parseStatus = model::File::PSFullyParsed;
  if (includer->type != model::File::DIRECTORY_TYPE &&
      includer->type != _cppSourceType)
  {
    includer->type = _cppSourceType;
    _ctx.srcMgr.updateFile(*includer);
  }

  //--- CppAstNode ---//

  model::CppAstNodePtr fileNode =
    createFileAstNode(included, filenameRange_.getAsRange());

  if (_mangledNameCache.insert(*fileNode))
    _astNodes.push_back(fileNode);

  model::CppHeaderInclusionPtr inclusion(new model::CppHeaderInclusion);
  inclusion->includer = includer;
  inclusion->included = included;

  _headerIncs.push_back(inclusion);
}
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);
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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);
  }
}
Exemplo n.º 6
0
void RewriterASTConsumer::InclusionDirective(clang::SourceLocation HashLoc,
                                             const clang::Token& IncludeTok,
                                             clang::StringRef FileName,
                                             bool IsAngled,
                                             clang::CharSourceRange FilenameRange,
                                             const clang::FileEntry* File,
                                             clang::StringRef SearchPath,
                                             clang::StringRef RelativePath,
                                             const clang::Module* Imported)
{

    if ("ParallelForEach.h" == FileName) {
        SourceManager& SM = TheGpuRewriter.getSourceMgr();
        SourceRange Range;
        Range.setBegin(HashLoc);
        Range.setEnd(SM.getSpellingLoc(FilenameRange.getEnd()));
        TheGpuRewriter.RemoveText(Range);
    }
}
// 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);
}