[cfe-commits] r49777 - in /cfe/trunk: Driver/ASTConsumers.h Driver/HTMLPrint.cpp Driver/clang.cpp clang.xcodeproj/project.pbxproj

Chris Lattner sabre at nondot.org
Tue Apr 15 22:21:09 PDT 2008


Author: lattner
Date: Wed Apr 16 00:21:09 2008
New Revision: 49777

URL: http://llvm.org/viewvc/llvm-project?rev=49777&view=rev
Log:
Add -o support for -emit-html, make it not produce a file on an error.

Modified:
    cfe/trunk/Driver/ASTConsumers.h
    cfe/trunk/Driver/HTMLPrint.cpp
    cfe/trunk/Driver/clang.cpp
    cfe/trunk/clang.xcodeproj/project.pbxproj

Modified: cfe/trunk/Driver/ASTConsumers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.h?rev=49777&r1=49776&r2=49777&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.h (original)
+++ cfe/trunk/Driver/ASTConsumers.h Wed Apr 16 00:21:09 2008
@@ -57,7 +57,7 @@
                                     Diagnostic &Diags,
                                     const LangOptions &LOpts);
 
-ASTConsumer* CreateHTMLPrinter();
+  ASTConsumer* CreateHTMLPrinter(const std::string &OutFile, Diagnostic &D);
 
 ASTConsumer *CreateSerializationTest(Diagnostic &Diags,
                                      FileManager& FMgr, 

Modified: cfe/trunk/Driver/HTMLPrint.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/HTMLPrint.cpp?rev=49777&r1=49776&r2=49777&view=diff

==============================================================================
--- cfe/trunk/Driver/HTMLPrint.cpp (original)
+++ cfe/trunk/Driver/HTMLPrint.cpp Wed Apr 16 00:21:09 2008
@@ -15,6 +15,7 @@
 #include "clang/AST/ASTConsumer.h"
 #include "clang/Rewrite/Rewriter.h"
 #include "clang/Rewrite/HTMLRewrite.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/AST/ASTContext.h"
 
@@ -27,33 +28,54 @@
 namespace {
   class HTMLPrinter : public ASTConsumer {
     Rewriter R;
+    std::string OutFilename;
+    Diagnostic &Diags;
   public:
-    HTMLPrinter() {}
+    HTMLPrinter(const std::string &OutFile, Diagnostic &D)
+      : OutFilename(OutFile), Diags(D) {}
     virtual ~HTMLPrinter();
     
     void Initialize(ASTContext &context);
   };
 }
 
-ASTConsumer* clang::CreateHTMLPrinter() { return new HTMLPrinter(); }
+ASTConsumer* clang::CreateHTMLPrinter(const std::string &OutFile, 
+                                      Diagnostic &D) {
+  return new HTMLPrinter(OutFile, D);
+}
 
 void HTMLPrinter::Initialize(ASTContext &context) {
   R.setSourceMgr(context.getSourceManager());
 }
 
 HTMLPrinter::~HTMLPrinter() {
-  
+  if (Diags.hasErrorOccurred())
+    return;
+
+  // Format the file.
   unsigned FileID = R.getSourceMgr().getMainFileID();
   html::EscapeText(R, FileID, false, true);
   html::AddLineNumbers(R, FileID);
   html::AddHeaderFooterInternalBuiltinCSS(R, FileID);
+
+  // Open the output.
+  FILE *OutputFILE;
+  if (OutFilename.empty() || OutFilename == "-")
+    OutputFILE = stdout;
+  else {
+    OutputFILE = fopen(OutFilename.c_str(), "w+");
+    if (OutputFILE == 0) {
+      fprintf(stderr, "Error opening output file '%s'.\n", OutFilename.c_str());
+      exit(1);
+    }
+  }
   
   // Emit the HTML.
+  const RewriteBuffer &RewriteBuf = R.getEditBuffer(FileID);
+  char *Buffer = (char*)malloc(RewriteBuf.size());
+  std::copy(RewriteBuf.begin(), RewriteBuf.end(), Buffer);
+  fwrite(Buffer, 1, RewriteBuf.size(), OutputFILE);
+  free(Buffer);
   
-  if (const RewriteBuffer *RewriteBuf = R.getRewriteBufferFor(FileID)) {
-    char *Buffer = (char*)malloc(RewriteBuf->size());
-    std::copy(RewriteBuf->begin(), RewriteBuf->end(), Buffer);
-    fwrite(Buffer, 1, RewriteBuf->size(), stdout);
-    free(Buffer);
-  }
+  if (OutputFILE != stdout) fclose(OutputFILE);
 }

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=49777&r1=49776&r2=49777&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Wed Apr 16 00:21:09 2008
@@ -918,8 +918,10 @@
 
       // Fedora 8
       AddPath("/usr/include/c++/4.1.2", System, true, false, false, Headers);
-      AddPath("/usr/include/c++/4.1.2/i386-redhat-linux", System, true, false, false, Headers);
-      AddPath("/usr/include/c++/4.1.2/backward", System, true, false, false, Headers);
+      AddPath("/usr/include/c++/4.1.2/i386-redhat-linux", System, true, false,
+              false, Headers);
+      AddPath("/usr/include/c++/4.1.2/backward", System, true, false, false, 
+              Headers);
     }
     
     AddPath("/usr/local/include", System, false, false, false, Headers);
@@ -1046,7 +1048,7 @@
       return CreateASTViewer();   
       
     case EmitHTML:
-      return CreateHTMLPrinter();
+      return CreateHTMLPrinter(OutputFile, Diag);
       
     case ParseCFGDump:
     case ParseCFGView:

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=49777&r1=49776&r2=49777&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Wed Apr 16 00:21:09 2008
@@ -720,7 +720,6 @@
 		DEAEECAE0A5AF0FA0045101B /* Driver */ = {
 			isa = PBXGroup;
 			children = (
-				035611E10DB40C8100D2EF2A /* RewriteObjC.cpp */,
 				DE5932CD0AD60FF400BC794C /* clang.cpp */,
 				DE5932CE0AD60FF400BC794C /* clang.h */,
 				DE3985780CB8ADC800223765 /* ASTConsumers.h */,
@@ -732,6 +731,7 @@
 				3574BC290D9B531D00DF491A /* HTMLDiagnostics.h */,
 				3574BC2A0D9B531D00DF491A /* HTMLDiagnostics.cpp */,
 				72D16C210D9975EA00E6DA4A /* HTMLPrint.cpp */,
+				035611E10DB40C8100D2EF2A /* RewriteObjC.cpp */,
 				DEB0AEBA0C2087AB00718A22 /* TextDiagnostics.cpp */,
 				DEB0AEB80C2087A700718A22 /* TextDiagnostics.h */,
 				F0226FD00C18084500141F42 /* TextDiagnosticPrinter.cpp */,





More information about the cfe-commits mailing list