r183849 - Port HTMLDiagnostics to PathV2. No intended functionality change.

Rafael EspĂ­ndola rafael.espindola at gmail.com
Wed Jun 12 12:09:01 PDT 2013


thanks!

On 12 June 2013 14:13, Benjamin Kramer <benny.kra at googlemail.com> wrote:
> Author: d0k
> Date: Wed Jun 12 13:13:05 2013
> New Revision: 183849
>
> URL: http://llvm.org/viewvc/llvm-project?rev=183849&view=rev
> Log:
> Port HTMLDiagnostics to PathV2. No intended functionality change.
>
> Modified:
>     cfe/trunk/include/clang/Rewrite/Core/HTMLRewrite.h
>     cfe/trunk/lib/Rewrite/Core/HTMLRewrite.cpp
>     cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
>
> Modified: cfe/trunk/include/clang/Rewrite/Core/HTMLRewrite.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/Core/HTMLRewrite.h?rev=183849&r1=183848&r2=183849&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Rewrite/Core/HTMLRewrite.h (original)
> +++ cfe/trunk/include/clang/Rewrite/Core/HTMLRewrite.h Wed Jun 12 13:13:05 2013
> @@ -57,7 +57,7 @@ namespace html {
>    ///  in 's' are not interpreted as HTML tags.  Unlike the version of
>    ///  EscapeText that rewrites a file, this version by default replaces tabs
>    ///  with spaces.
> -  std::string EscapeText(const std::string& s,
> +  std::string EscapeText(StringRef s,
>                           bool EscapeSpaces = false, bool ReplaceTabs = false);
>
>    void AddLineNumbers(Rewriter& R, FileID FID);
>
> Modified: cfe/trunk/lib/Rewrite/Core/HTMLRewrite.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Core/HTMLRewrite.cpp?rev=183849&r1=183848&r2=183849&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Rewrite/Core/HTMLRewrite.cpp (original)
> +++ cfe/trunk/lib/Rewrite/Core/HTMLRewrite.cpp Wed Jun 12 13:13:05 2013
> @@ -164,8 +164,7 @@ void html::EscapeText(Rewriter &R, FileI
>    }
>  }
>
> -std::string html::EscapeText(const std::string& s, bool EscapeSpaces,
> -                             bool ReplaceTabs) {
> +std::string html::EscapeText(StringRef s, bool EscapeSpaces, bool ReplaceTabs) {
>
>    unsigned len = s.size();
>    std::string Str;
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp?rev=183849&r1=183848&r2=183849&view=diff
> ==============================================================================
> --- cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp Wed Jun 12 13:13:05 2013
> @@ -24,7 +24,6 @@
>  #include "llvm/Support/FileSystem.h"
>  #include "llvm/Support/MemoryBuffer.h"
>  #include "llvm/Support/Path.h"
> -#include "llvm/Support/PathV1.h"
>  #include "llvm/Support/raw_ostream.h"
>
>  using namespace clang;
> @@ -37,7 +36,7 @@ using namespace ento;
>  namespace {
>
>  class HTMLDiagnostics : public PathDiagnosticConsumer {
> -  llvm::sys::Path Directory, FilePrefix;
> +  std::string Directory;
>    bool createdDir, noDir;
>    const Preprocessor &PP;
>  public:
> @@ -71,10 +70,7 @@ public:
>
>  HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix,
>                                   const Preprocessor &pp)
> -  : Directory(prefix), FilePrefix(prefix), createdDir(false), noDir(false),
> -    PP(pp) {
> -  // All html files begin with "report"
> -  FilePrefix.appendComponent("report");
> +  : Directory(prefix), createdDir(false), noDir(false), PP(pp) {
>  }
>
>  void ento::createHTMLDiagnosticConsumer(AnalyzerOptions &AnalyzerOpts,
> @@ -103,15 +99,11 @@ void HTMLDiagnostics::ReportDiag(const P
>    // Create the HTML directory if it is missing.
>    if (!createdDir) {
>      createdDir = true;
> -    std::string ErrorMsg;
> -    Directory.createDirectoryOnDisk(true, &ErrorMsg);
> -
> -    bool IsDirectory;
> -    if (llvm::sys::fs::is_directory(Directory.str(), IsDirectory) ||
> -        !IsDirectory) {
> +    bool existed;
> +    if (llvm::error_code ec =
> +            llvm::sys::fs::create_directories(Directory, existed)) {
>        llvm::errs() << "warning: could not create directory '"
> -                   << Directory.str() << "'\n"
> -                   << "reason: " << ErrorMsg << '\n';
> +                   << Directory << "': " << ec.message() << '\n';
>
>        noDir = true;
>
> @@ -166,11 +158,11 @@ void HTMLDiagnostics::ReportDiag(const P
>    // working directory if we have no directory information.  This is
>    // a work in progress.
>
> -  std::string DirName = "";
> +  llvm::SmallString<0> DirName;
>
>    if (llvm::sys::path::is_relative(Entry->getName())) {
> -    llvm::sys::Path P = llvm::sys::Path::GetCurrentDirectory();
> -    DirName = P.str() + "/";
> +    llvm::sys::fs::current_path(DirName);
> +    DirName += '/';
>    }
>
>    // Add the name of the file as an <h1> tag.
> @@ -251,26 +243,22 @@ void HTMLDiagnostics::ReportDiag(const P
>    }
>
>    // Create a path for the target HTML file.
> -  llvm::sys::Path F(FilePrefix);
> -  F.makeUnique(false, NULL);
> -
> -  // Rename the file with an HTML extension.
> -  llvm::sys::Path H(F);
> -  H.appendSuffix("html");
> -  F.renamePathOnDisk(H, NULL);
> -
> -  std::string ErrorMsg;
> -  llvm::raw_fd_ostream os(H.c_str(), ErrorMsg);
> -
> -  if (!ErrorMsg.empty()) {
> -    llvm::errs() << "warning: could not create file '" << F.str()
> -                 << "'\n";
> +  int FD;
> +  SmallString<128> Model, ResultPath;
> +  llvm::sys::path::append(Model, Directory, "report-%%%%%%.html");
> +
> +  if (llvm::error_code EC =
> +          llvm::sys::fs::unique_file(Model.str(), FD, ResultPath)) {
> +    llvm::errs() << "warning: could not create file in '" << Directory
> +                 << "': " << EC.message() << '\n';
>      return;
>    }
>
> -  if (filesMade) {
> -    filesMade->addDiagnostic(D, getName(), llvm::sys::path::filename(H.str()));
> -  }
> +  llvm::raw_fd_ostream os(FD, true);
> +
> +  if (filesMade)
> +    filesMade->addDiagnostic(D, getName(),
> +                             llvm::sys::path::filename(ResultPath));
>
>    // Emit the HTML to disk.
>    for (RewriteBuffer::iterator I = Buf->begin(), E = Buf->end(); I!=E; ++I)
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list