[cfe-commits] r49875 - in /cfe/trunk: Driver/ASTConsumers.cpp Driver/ASTConsumers.h Driver/HTMLDiagnostics.cpp Driver/HTMLDiagnostics.h Driver/HTMLPrint.cpp Driver/clang.cpp include/clang/Lex/Preprocessor.h include/clang/Rewrite/HTMLRewrite.h lib/Lex/Preprocessor.cpp lib/Rewrite/HTMLRewrite.cpp

Ted Kremenek kremenek at apple.com
Thu Apr 17 15:31:57 PDT 2008


Author: kremenek
Date: Thu Apr 17 17:31:54 2008
New Revision: 49875

URL: http://llvm.org/viewvc/llvm-project?rev=49875&view=rev
Log:
class Preprocessor: Now owns the "predefines" char*; it deletes [] it in its dstor.

clang.cpp: InitializePreprocessor now makes a copy of the contents of PredefinesBuffer and
  passes it to the preprocessor object.
  
clang.cpp: DriverPreprocessorFactory now calls "InitializePreprocessor" instead of this being done in main().

html::HighlightMacros() now takes a PreprocessorFactory, allowing it to conjure up a new
Preprocessor to highlight macros.

class HTMLDiagnostics now takes a PreprocessorFactory* that it can use for html::HighlightMacros().
Updated clients of HTMLDiagnostics to use this new interface.

Modified:
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/Driver/ASTConsumers.h
    cfe/trunk/Driver/HTMLDiagnostics.cpp
    cfe/trunk/Driver/HTMLDiagnostics.h
    cfe/trunk/Driver/HTMLPrint.cpp
    cfe/trunk/Driver/clang.cpp
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/include/clang/Rewrite/HTMLRewrite.h
    cfe/trunk/lib/Lex/Preprocessor.cpp
    cfe/trunk/lib/Rewrite/HTMLRewrite.cpp

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=49875&r1=49874&r2=49875&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Thu Apr 17 17:31:54 2008
@@ -649,17 +649,18 @@
   Diagnostic &Diags;
   ASTContext* Ctx;
   Preprocessor* PP;
+  PreprocessorFactory* PPF;
   const std::string& HTMLDir;
   bool Visualize;
   bool TrimGraph;
   llvm::OwningPtr<PathDiagnosticClient> PD;
   bool AnalyzeAll;
 public:
-  CheckerConsumer(Diagnostic &diags, Preprocessor* pp,
+  CheckerConsumer(Diagnostic &diags, Preprocessor* pp, PreprocessorFactory* ppf,
                   const std::string& fname,
                   const std::string& htmldir,
                   bool visualize, bool trim, bool analyzeAll)
-    : CFGVisitor(fname), Diags(diags), PP(pp), HTMLDir(htmldir),
+    : CFGVisitor(fname), Diags(diags), PP(pp), PPF(ppf), HTMLDir(htmldir),
       Visualize(visualize), TrimGraph(trim), AnalyzeAll(analyzeAll) {}
   
   virtual void Initialize(ASTContext &Context) { Ctx = &Context; }    
@@ -687,7 +688,7 @@
   // Lazily create the diagnostic client.
   
   if (!HTMLDir.empty() && PD.get() == NULL)
-    PD.reset(CreateHTMLDiagnosticClient(HTMLDir, PP));
+    PD.reset(CreateHTMLDiagnosticClient(HTMLDir, PP, PPF));
   
 
   if (!Visualize) {
@@ -734,9 +735,11 @@
 class GRSimpleValsVisitor : public CheckerConsumer {
 public:
   GRSimpleValsVisitor(Diagnostic &diags, Preprocessor* pp,
+                      PreprocessorFactory* ppf,
                       const std::string& fname, const std::string& htmldir,
                       bool visualize, bool trim, bool analyzeAll)
-  : CheckerConsumer(diags, pp, fname, htmldir, visualize, trim, analyzeAll) {}
+  : CheckerConsumer(diags, pp, ppf, fname, htmldir, visualize,
+                    trim, analyzeAll) {}
 
   virtual const char* getCheckerName() { return "GRSimpleVals"; }
   
@@ -748,12 +751,13 @@
 
 ASTConsumer* clang::CreateGRSimpleVals(Diagnostic &Diags,
                                        Preprocessor* PP,
+                                       PreprocessorFactory* PPF,
                                        const std::string& FunctionName,
                                        const std::string& HTMLDir,
                                        bool Visualize, bool TrimGraph,
                                        bool AnalyzeAll) {
   
-  return new GRSimpleValsVisitor(Diags, PP, FunctionName, HTMLDir,
+  return new GRSimpleValsVisitor(Diags, PP, PPF, FunctionName, HTMLDir,
                                  Visualize, TrimGraph, AnalyzeAll);
 }
 
@@ -765,10 +769,12 @@
 class CFRefCountCheckerVisitor : public CheckerConsumer {
 public:
   CFRefCountCheckerVisitor(Diagnostic &diags, Preprocessor* pp,
+                           PreprocessorFactory* ppf,
                            const std::string& fname,
                            const std::string& htmldir,
                            bool visualize, bool trim, bool analyzeAll)
-  : CheckerConsumer(diags, pp, fname, htmldir, visualize, trim, analyzeAll) {}
+  : CheckerConsumer(diags, pp, ppf, fname, htmldir, visualize,
+                    trim, analyzeAll) {}
   
   virtual const char* getCheckerName() { return "CFRefCountChecker"; }
   
@@ -780,12 +786,13 @@
 
 ASTConsumer* clang::CreateCFRefChecker(Diagnostic &Diags,
                                        Preprocessor* PP,
+                                       PreprocessorFactory* PPF,
                                        const std::string& FunctionName,
                                        const std::string& HTMLDir,
                                        bool Visualize, bool TrimGraph,
                                        bool AnalyzeAll) {
   
-  return new CFRefCountCheckerVisitor(Diags, PP, FunctionName, HTMLDir,
+  return new CFRefCountCheckerVisitor(Diags, PP, PPF, FunctionName, HTMLDir,
                                       Visualize, TrimGraph, AnalyzeAll);
 }
 

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

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.h (original)
+++ cfe/trunk/Driver/ASTConsumers.h Thu Apr 17 17:31:54 2008
@@ -28,6 +28,8 @@
 class FileManager;
 struct LangOptions;
 class Preprocessor;
+class PreprocessorFactory;
+
 
 ASTConsumer *CreateASTPrinter(std::ostream* OS = NULL);
 
@@ -44,13 +46,13 @@
 ASTConsumer *CreateUnitValsChecker(Diagnostic &Diags);
   
 ASTConsumer *CreateGRSimpleVals(Diagnostic &Diags,
-                                Preprocessor* PP,
+                                Preprocessor* PP, PreprocessorFactory* PPF,
                                 const std::string& Function,
                                 const std::string& HTMLDir, bool Visualize,
                                 bool TrimGraph, bool AnalyzeAll);
   
 ASTConsumer *CreateCFRefChecker(Diagnostic &Diags,
-                                Preprocessor* PP,
+                                Preprocessor* PP, PreprocessorFactory* PPF,
                                 const std::string& Function,
                                 const std::string& HTMLDir, bool Visualize,
                                 bool TrimGraph, bool AnalyzeAll);
@@ -61,7 +63,7 @@
                                     const LangOptions &LOpts);
 
 ASTConsumer* CreateHTMLPrinter(const std::string &OutFile, Diagnostic &D,
-                               Preprocessor *PP);
+                               Preprocessor *PP, PreprocessorFactory* PPF);
 
 ASTConsumer *CreateSerializationTest(Diagnostic &Diags,
                                      FileManager& FMgr, 

Modified: cfe/trunk/Driver/HTMLDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/HTMLDiagnostics.cpp?rev=49875&r1=49874&r2=49875&view=diff

==============================================================================
--- cfe/trunk/Driver/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/Driver/HTMLDiagnostics.cpp Thu Apr 17 17:31:54 2008
@@ -38,8 +38,10 @@
   llvm::sys::Path Directory, FilePrefix;
   bool createdDir, noDir;
   Preprocessor* PP;
+  PreprocessorFactory* PPF;
 public:
-  HTMLDiagnostics(const std::string& prefix, Preprocessor* pp = NULL);
+  HTMLDiagnostics(const std::string& prefix, Preprocessor* pp,
+                  PreprocessorFactory* ppf);
 
   virtual ~HTMLDiagnostics() {}
   
@@ -53,18 +55,20 @@
   
 } // end anonymous namespace
 
-HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp)
+HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp,
+                                 PreprocessorFactory* ppf)
   : Directory(prefix), FilePrefix(prefix), createdDir(false), noDir(false),
-    PP(pp) {
+    PP(pp), PPF(ppf) {
   
   // All html files begin with "report" 
   FilePrefix.appendComponent("report");
 }
 
 PathDiagnosticClient*
-clang::CreateHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP) {
+clang::CreateHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP,
+                                  PreprocessorFactory* PPF) {
   
-  return new HTMLDiagnostics(prefix, PP);
+  return new HTMLDiagnostics(prefix, PP, PPF);
 }
 
 //===----------------------------------------------------------------------===//
@@ -122,10 +126,8 @@
   // We might not have a preprocessor if we come from a deserialized AST file,
   // for example.
   
-  if (PP) {
-    html::SyntaxHighlight(R, FileID, *PP);
-    // html::HighlightMacros(R, FileID, *PP);
-  }
+  if (PP) html::SyntaxHighlight(R, FileID, *PP);
+  if (PPF) html::HighlightMacros(R, FileID, *PPF);
   
   // Get the full directory name of the analyzed file.
 

Modified: cfe/trunk/Driver/HTMLDiagnostics.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/HTMLDiagnostics.h?rev=49875&r1=49874&r2=49875&view=diff

==============================================================================
--- cfe/trunk/Driver/HTMLDiagnostics.h (original)
+++ cfe/trunk/Driver/HTMLDiagnostics.h Thu Apr 17 17:31:54 2008
@@ -17,11 +17,15 @@
 #include <string>
 
 namespace clang {
-  class PathDiagnosticClient;
-  class Preprocessor;
+
+class PathDiagnosticClient;
+class Preprocessor;
+class PreprocessorFactory;
+
   
-  PathDiagnosticClient* CreateHTMLDiagnosticClient(const std::string& prefix,
-                                                   Preprocessor* PP);
+PathDiagnosticClient* CreateHTMLDiagnosticClient(const std::string& prefix,
+                                                 Preprocessor* PP,
+                                                 PreprocessorFactory* PPF);
 }
 
 #endif

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

==============================================================================
--- cfe/trunk/Driver/HTMLPrint.cpp (original)
+++ cfe/trunk/Driver/HTMLPrint.cpp Thu Apr 17 17:31:54 2008
@@ -31,9 +31,11 @@
     std::string OutFilename;
     Diagnostic &Diags;
     Preprocessor *PP;
+    PreprocessorFactory *PPF;
   public:
-    HTMLPrinter(const std::string &OutFile, Diagnostic &D, Preprocessor *pp)
-      : OutFilename(OutFile), Diags(D), PP(pp) {}
+    HTMLPrinter(const std::string &OutFile, Diagnostic &D, Preprocessor *pp,
+                PreprocessorFactory* ppf)
+      : OutFilename(OutFile), Diags(D), PP(pp), PPF(ppf) {}
     virtual ~HTMLPrinter();
     
     void Initialize(ASTContext &context);
@@ -41,8 +43,10 @@
 }
 
 ASTConsumer* clang::CreateHTMLPrinter(const std::string &OutFile, 
-                                      Diagnostic &D, Preprocessor *PP) {
-  return new HTMLPrinter(OutFile, D, PP);
+                                      Diagnostic &D, Preprocessor *PP,
+                                      PreprocessorFactory* PPF) {
+  
+  return new HTMLPrinter(OutFile, D, PP, PPF);
 }
 
 void HTMLPrinter::Initialize(ASTContext &context) {
@@ -62,13 +66,10 @@
   // We might not have a preprocessor if we come from a deserialized AST file,
   // for example.
   
-  if (PP) {
-    html::SyntaxHighlight(R, FileID, *PP);
-    html::HighlightMacros(R, FileID, *PP);
-  }
+  if (PP) html::SyntaxHighlight(R, FileID, *PP);
+  if (PPF) html::HighlightMacros(R, FileID, *PPF);  
   html::EscapeText(R, FileID, false, true);
   
-  
   // Open the output.
   FILE *OutputFILE;
   if (OutFilename.empty() || OutFilename == "-")

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

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Thu Apr 17 17:31:54 2008
@@ -48,6 +48,7 @@
 #include "llvm/System/Path.h"
 #include <memory>
 #include <fstream>
+#include <algorithm>
 using namespace clang;
 
 //===----------------------------------------------------------------------===//
@@ -586,26 +587,31 @@
 /// input file. If a failure happens, it returns 0.
 ///
 static unsigned InitializePreprocessor(Preprocessor &PP,
+                                       bool InitializeSourceMgr, 
                                        const std::string &InFile,
                                        std::vector<char> &PredefineBuffer) {
   
+
   FileManager &FileMgr = PP.getFileManager();
   
   // Figure out where to get and map in the main file.
   SourceManager &SourceMgr = PP.getSourceManager();
-  if (InFile != "-") {
-    const FileEntry *File = FileMgr.getFile(InFile);
-    if (File) SourceMgr.createMainFileID(File, SourceLocation());
-    if (SourceMgr.getMainFileID() == 0) {
-      fprintf(stderr, "Error reading '%s'!\n",InFile.c_str());
-      return 0;
-    }
-  } else {
-    llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
-    if (SB) SourceMgr.createMainFileIDForMemBuffer(SB);
-    if (SourceMgr.getMainFileID() == 0) {
-      fprintf(stderr, "Error reading standard input!  Empty?\n");
-      return 0;
+
+  if (InitializeSourceMgr) {
+    if (InFile != "-") {
+      const FileEntry *File = FileMgr.getFile(InFile);
+      if (File) SourceMgr.createMainFileID(File, SourceLocation());
+      if (SourceMgr.getMainFileID() == 0) {
+        fprintf(stderr, "Error reading '%s'!\n",InFile.c_str());
+        return 0;
+      }
+    } else {
+      llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
+      if (SB) SourceMgr.createMainFileIDForMemBuffer(SB);
+      if (SourceMgr.getMainFileID() == 0) {
+        fprintf(stderr, "Error reading standard input!  Empty?\n");
+        return 0;
+      }
     }
   }
 
@@ -625,9 +631,13 @@
   for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
     AddImplicitInclude(PredefineBuffer, ImplicitIncludes[i]);
   
-  // Null terminate PredefinedBuffer and add it.
+  // Null terminate PredefinedBuffer and add it.  We actually need to make a
+  // copy because PP will own the string.
   PredefineBuffer.push_back(0);
-  PP.setPredefines(&PredefineBuffer[0]);
+  
+  char* predefines = new char[PredefineBuffer.size()];
+  std::copy(PredefineBuffer.begin(), PredefineBuffer.end(), predefines);
+  PP.setPredefines(predefines);
   
   // Once we've read this, we're done.
   return SourceMgr.getMainFileID();
@@ -1015,23 +1025,41 @@
 
 namespace {
 class VISIBILITY_HIDDEN DriverPreprocessorFactory : public PreprocessorFactory {
+  const std::string &InFile;
   Diagnostic        &Diags;
   const LangOptions &LangInfo;
   TargetInfo        &Target;
   SourceManager     &SourceMgr;
   HeaderSearch      &HeaderInfo;
-
+  std::vector<char> PredefineBuffer;
+  bool              InitializeSourceMgr;
+  
 public:
-  DriverPreprocessorFactory(Diagnostic &diags, const LangOptions &opts,
+  DriverPreprocessorFactory(const std::string &infile,
+                            Diagnostic &diags, const LangOptions &opts,
                             TargetInfo &target, SourceManager &SM,
                             HeaderSearch &Headers)  
-  : Diags(diags), LangInfo(opts), Target(target),
-    SourceMgr(SM), HeaderInfo(Headers) {}
+  : InFile(infile), Diags(diags), LangInfo(opts), Target(target),
+    SourceMgr(SM), HeaderInfo(Headers), InitializeSourceMgr(true) {}
+  
   
   virtual ~DriverPreprocessorFactory() {}
   
   virtual Preprocessor* CreatePreprocessor() {
-    return new Preprocessor(Diags, LangInfo, Target, SourceMgr, HeaderInfo);
+    PredefineBuffer.clear();
+
+    Preprocessor* PP = new Preprocessor(Diags, LangInfo, Target,
+                                        SourceMgr, HeaderInfo);
+    
+    if (!InitializePreprocessor(*PP, InitializeSourceMgr, InFile,
+                                PredefineBuffer)) {
+      delete PP;
+      return NULL;
+    }
+    
+    InitializeSourceMgr = false;
+    
+    return PP;
   }
 };
 }
@@ -1060,6 +1088,7 @@
                                       Diagnostic& Diag, FileManager& FileMgr, 
                                       const LangOptions& LangOpts,
                                       Preprocessor *PP,
+                                      PreprocessorFactory *PPF,
                                       llvm::Module *&DestModule) {
   switch (ProgAction) {
     default:
@@ -1075,7 +1104,7 @@
       return CreateASTViewer();   
       
     case EmitHTML:
-      return CreateHTMLPrinter(OutputFile, Diag, PP);
+      return CreateHTMLPrinter(OutputFile, Diag, PP, PPF);
       
     case ParseCFGDump:
     case ParseCFGView:
@@ -1092,12 +1121,12 @@
       return CreateUnitValsChecker(Diag);
       
     case AnalysisGRSimpleVals:
-      return CreateGRSimpleVals(Diag, PP, AnalyzeSpecificFunction, OutputFile,
-                                VisualizeEG, TrimGraph, AnalyzeAll);
+      return CreateGRSimpleVals(Diag, PP, PPF, AnalyzeSpecificFunction,
+                                OutputFile, VisualizeEG, TrimGraph, AnalyzeAll);
       
     case CheckerCFRef:
-      return CreateCFRefChecker(Diag, PP, AnalyzeSpecificFunction, OutputFile,
-                                VisualizeEG, TrimGraph, AnalyzeAll);
+      return CreateCFRefChecker(Diag, PP, PPF, AnalyzeSpecificFunction,
+                                OutputFile, VisualizeEG, TrimGraph, AnalyzeAll);
       
     case TestSerialization:
       return CreateSerializationTest(Diag, FileMgr, LangOpts);
@@ -1118,7 +1147,8 @@
 
 /// ProcessInputFile - Process a single input file with the specified state.
 ///
-static void ProcessInputFile(Preprocessor &PP, const std::string &InFile) {
+static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
+                             const std::string &InFile) {
 
   ASTConsumer* Consumer = NULL;
   bool ClearSourceMgr = false;
@@ -1128,7 +1158,7 @@
   default:
     Consumer = CreateASTConsumer(InFile, PP.getDiagnostics(),
                                  PP.getFileManager(), PP.getLangOptions(), &PP,
-                                 CodeGenModule);
+                                 &PPF, CodeGenModule);
     
     if (!Consumer) {      
       fprintf(stderr, "Unexpected program action!\n");
@@ -1267,7 +1297,7 @@
   // translation unit, rather than InFile.
   llvm::Module *DestModule;
   llvm::OwningPtr<ASTConsumer>
-    Consumer(CreateASTConsumer(InFile, Diag, FileMgr, TU->getLangOpts(), 0,
+    Consumer(CreateASTConsumer(InFile, Diag, FileMgr, TU->getLangOpts(), 0, 0,
                                DestModule));
   
   if (!Consumer) {      
@@ -1320,7 +1350,7 @@
     // FIXME: The HTMLDiagnosticClient uses the Preprocessor for
     //  (optional) syntax highlighting, but we don't have a preprocessor yet.
     //  Fix this dependency later.
-    DiagClient.reset(CreateHTMLDiagnosticClient(HTMLDiag, NULL));
+    DiagClient.reset(CreateHTMLDiagnosticClient(HTMLDiag, 0, 0));
   }
   else { // Use Text diagnostics.
     if (!VerifyDiagnostics) {
@@ -1387,16 +1417,15 @@
       InitializeIncludePaths(argv[0], HeaderInfo, FileMgr, LangInfo);
       
       // Set up the preprocessor with these options.
-      DriverPreprocessorFactory PPFactory(Diags, LangInfo, *Target,
+      DriverPreprocessorFactory PPFactory(InFile, Diags, LangInfo, *Target,
                                           SourceMgr, HeaderInfo);
       
       llvm::OwningPtr<Preprocessor> PP(PPFactory.CreatePreprocessor());
             
-      std::vector<char> PredefineBuffer;
-      if (!InitializePreprocessor(*PP, InFile, PredefineBuffer))
+      if (!PP)
         continue;
       
-      ProcessInputFile(*PP, InFile);
+      ProcessInputFile(*PP, PPFactory, InFile);
       HeaderInfo.ClearFileInfo();
       
       if (Stats)

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=49875&r1=49874&r2=49875&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Thu Apr 17 17:31:54 2008
@@ -196,6 +196,8 @@
   ///
   void setMacroInfo(IdentifierInfo *II, MacroInfo *MI);
   
+  /// setPredefines - Set the predefines for this Preprocessor.
+  ///  The Preprocessor assumes ownership of this pointer.
   void setPredefines(const char *P) {
     Predefines = P;
   }

Modified: cfe/trunk/include/clang/Rewrite/HTMLRewrite.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/HTMLRewrite.h?rev=49875&r1=49874&r2=49875&view=diff

==============================================================================
--- cfe/trunk/include/clang/Rewrite/HTMLRewrite.h (original)
+++ cfe/trunk/include/clang/Rewrite/HTMLRewrite.h Thu Apr 17 17:31:54 2008
@@ -22,6 +22,7 @@
   
 class Rewriter;
 class Preprocessor;
+class PreprocessorFactory;
   
 namespace html {
   
@@ -74,7 +75,7 @@
   /// file, to reexpand macros and insert (into the HTML) information about the
   /// macro expansions.  This won't be perfectly perfect, but it will be
   /// reasonably close.
-  void HighlightMacros(Rewriter &R, unsigned FileID, Preprocessor &PP);
+  void HighlightMacros(Rewriter &R, unsigned FileID, PreprocessorFactory &PPF);
   
 
   

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=49875&r1=49874&r2=49875&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Thu Apr 17 17:31:54 2008
@@ -112,6 +112,8 @@
   delete ScratchBuf;
 
   delete Callbacks;
+  
+  delete [] Predefines;
 }
 
 /// Diag - Forwarding function for diagnostics.  This emits a diagnostic at

Modified: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/HTMLRewrite.cpp?rev=49875&r1=49874&r2=49875&view=diff

==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Thu Apr 17 17:31:54 2008
@@ -12,11 +12,13 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "clang/Lex/Preprocessor.h"
 #include "clang/Rewrite/Rewriter.h"
 #include "clang/Rewrite/HTMLRewrite.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/OwningPtr.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include <sstream>
 using namespace clang;
@@ -382,23 +384,28 @@
 /// file, to reexpand macros and insert (into the HTML) information about the
 /// macro expansions.  This won't be perfectly perfect, but it will be
 /// reasonably close.
-void html::HighlightMacros(Rewriter &R, unsigned FileID, Preprocessor &PP) {
+void html::HighlightMacros(Rewriter &R, unsigned FileID,
+                           PreprocessorFactory &PPF) {
+  
+  llvm::OwningPtr<Preprocessor> PP(PPF.CreatePreprocessor());
+  
+  
   RewriteBuffer &RB = R.getEditBuffer(FileID);
   
   // Inform the preprocessor that we don't want comments.
-  PP.SetCommentRetentionState(false, false);
+  PP->SetCommentRetentionState(false, false);
   
   // Start parsing the specified input file.
-  PP.EnterMainSourceFile();
+  PP->EnterMainSourceFile();
   
   // Lex all the tokens.
-  const SourceManager &SourceMgr = PP.getSourceManager();
+  const SourceManager &SourceMgr = PP->getSourceManager();
   Token Tok;
-  PP.Lex(Tok);
+  PP->Lex(Tok);
   while (Tok.isNot(tok::eof)) {
     // Ignore non-macro tokens.
     if (!Tok.getLocation().isMacroID()) {
-      PP.Lex(Tok);
+      PP->Lex(Tok);
       continue;
     }
     
@@ -408,7 +415,7 @@
       SourceMgr.getDecomposedFileLoc(LLoc);
     
     if (LLocInfo.first != FileID) {
-      PP.Lex(Tok);
+      PP->Lex(Tok);
       continue;
     }
     
@@ -426,11 +433,11 @@
                        strlen("<span class='macro'>"));
     RB.InsertTextBefore(TokOffs+TokLen, "</span>", strlen("</span>"));
     
-    std::string Expansion = PP.getSpelling(Tok);
+    std::string Expansion = PP->getSpelling(Tok);
     unsigned LineLen = Expansion.size();
     
     // Okay, eat this token, getting the next one.
-    PP.Lex(Tok);
+    PP->Lex(Tok);
     
     // Skip all the rest of the tokens that are part of this macro
     // instantiation.  It would be really nice to pop up a window with all the
@@ -444,9 +451,9 @@
       }
       
       LineLen -= Expansion.size();
-      Expansion += ' ' + PP.getSpelling(Tok);
+      Expansion += ' ' + PP->getSpelling(Tok);
       LineLen += Expansion.size();
-      PP.Lex(Tok);
+      PP->Lex(Tok);
     }
 
     // Insert the information about the expansion inside the macro span.





More information about the cfe-commits mailing list