]> granicus.if.org Git - clang/commitdiff
Port HTMLDiagnostics to PathV2. No intended functionality change.
authorBenjamin Kramer <benny.kra@googlemail.com>
Wed, 12 Jun 2013 18:13:05 +0000 (18:13 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Wed, 12 Jun 2013 18:13:05 +0000 (18:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183849 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Rewrite/Core/HTMLRewrite.h
lib/Rewrite/Core/HTMLRewrite.cpp
lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp

index 88caf85e601046e85f3fe1e115f0d8daffcfc082..3cd04615d8261bd5091820dd79972fd7fa4552c0 100644 (file)
@@ -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);
index 2a5442afcd5122bbc50bc495e35ea58d24f9b55d..4da00a8cc97bba4543c0029c7dd27e8f07af23bc 100644 (file)
@@ -164,8 +164,7 @@ void html::EscapeText(Rewriter &R, FileID FID,
   }
 }
 
-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;
index 434183b52f1a5281c64abc29dbdf6eaa14f62b27..120a63e7a240aa75cfea5e93095cb9350bc95c65 100644 (file)
@@ -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 PathDiagnostic& D,
   // 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 PathDiagnostic& D,
   // 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 PathDiagnostic& D,
   }
 
   // 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)