Exemplo n.º 1
0
void RemoveFunction(clang::Rewriter& TheRewriter, const FunctionDecl* F)
{
    ExpandSourceRange SourceRange{TheRewriter};
    TheRewriter.RemoveText(SourceRange(F->getSourceRange()));
    if (FunctionTemplateDecl* D = F->getDescribedFunctionTemplate()) {
        TheRewriter.RemoveText(SourceRange(D->getSourceRange()));
    }
}
Exemplo n.º 2
0
std::string RefactoringTool::writeReplacements(clang::Rewriter &rewriter)
{
  std::ostringstream oss;
  for ( auto i  = rewriter.buffer_begin(),
             e  = rewriter.buffer_end();
             i != e;
           ++i ) {
    llvm::raw_os_ostream stream(oss);
    i->second.write(stream);
    stream.flush();
  }
  return oss.str();
}
bool writeFiles(const clang::Rewriter &Rewrites) {

  for (Rewriter::const_buffer_iterator BufferI = Rewrites.buffer_begin(),
                                       BufferE = Rewrites.buffer_end();
       BufferI != BufferE; ++BufferI) {
    const char *FileName =
        Rewrites.getSourceMgr().getFileEntryForID(BufferI->first)->getName();

    std::error_code EC;
    llvm::raw_fd_ostream FileStream(FileName, EC, llvm::sys::fs::F_Text);
    if (EC) {
      errs() << "Warning: Could not write to " << EC.message() << "\n";
      continue;
    }
    BufferI->second.write(FileStream);
  }

  return true;
}
bool writeFiles(const clang::Rewriter &Rewrites) {

  for (Rewriter::const_buffer_iterator BufferI = Rewrites.buffer_begin(),
                                       BufferE = Rewrites.buffer_end();
       BufferI != BufferE; ++BufferI) {
    const char *FileName =
        Rewrites.getSourceMgr().getFileEntryForID(BufferI->first)->getName();

    std::string ErrorInfo;

    llvm::raw_fd_ostream FileStream(FileName, ErrorInfo);
    if (!ErrorInfo.empty()) {
      errs() << "Warning: Could not write to " << FileName << "\n";
      continue;
    }
    BufferI->second.write(FileStream);
  }

  return true;
}
Exemplo n.º 5
0
void RemoveStatement(clang::Rewriter& TheRewriter, clang::CallExpr const * const Statement)
{
    ExpandSourceRange SourceRange{TheRewriter};
    TheRewriter.RemoveText(SourceRange(Statement->getSourceRange()));
}