[cfe-commits] r74493 - in /cfe/trunk: include/clang/AST/ include/clang/Basic/ lib/AST/ lib/Analysis/ lib/Basic/ lib/CodeGen/ lib/Frontend/ lib/Rewrite/ tools/clang-cc/ tools/index-test/

Chris Lattner sabre at nondot.org
Mon Jun 29 18:26:18 PDT 2009


Author: lattner
Date: Mon Jun 29 20:26:17 2009
New Revision: 74493

URL: http://llvm.org/viewvc/llvm-project?rev=74493&view=rev
Log:
Key decisions about 'bool' vs '_Bool' to be based on a new flag in langoptions.

This is simple enough, but then I thought it would be nice to make PrintingPolicy
get a LangOptions so that various things can key off "bool" and "C++" independently.
This spiraled out of control.  There are many fixme's, but I think things are slightly
better than they were before.

One thing that can be improved: CFG should probably have an ASTContext pointer in it,
which would simplify its clients.


Modified:
    cfe/trunk/include/clang/AST/CFG.h
    cfe/trunk/include/clang/AST/NestedNameSpecifier.h
    cfe/trunk/include/clang/AST/PrettyPrinter.h
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/include/clang/Basic/LangOptions.h
    cfe/trunk/include/clang/Basic/TokenKinds.def
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/AST/CFG.cpp
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/AST/NestedNameSpecifier.cpp
    cfe/trunk/lib/AST/StmtDumper.cpp
    cfe/trunk/lib/AST/StmtPrinter.cpp
    cfe/trunk/lib/AST/TemplateName.cpp
    cfe/trunk/lib/AST/Type.cpp
    cfe/trunk/lib/Analysis/GRExprEngine.cpp
    cfe/trunk/lib/Analysis/GRState.cpp
    cfe/trunk/lib/Analysis/MemRegion.cpp
    cfe/trunk/lib/Basic/IdentifierTable.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/Frontend/AnalysisConsumer.cpp
    cfe/trunk/lib/Frontend/ResolveLocation.cpp
    cfe/trunk/lib/Frontend/RewriteBlocks.cpp
    cfe/trunk/lib/Frontend/RewriteObjC.cpp
    cfe/trunk/lib/Rewrite/Rewriter.cpp
    cfe/trunk/tools/clang-cc/clang-cc.cpp
    cfe/trunk/tools/index-test/index-test.cpp

Modified: cfe/trunk/include/clang/AST/CFG.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CFG.h?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/CFG.h (original)
+++ cfe/trunk/include/clang/AST/CFG.h Mon Jun 29 20:26:17 2009
@@ -17,17 +17,20 @@
 
 #include "llvm/ADT/GraphTraits.h"
 #include "llvm/Support/Allocator.h"
-#include "llvm/Support/raw_ostream.h"
 #include <list>
 #include <vector>
 #include <cassert>
 
+namespace llvm {
+  class raw_ostream;
+}
 namespace clang {
   class Stmt;
   class Expr;
   class CFG;
   class PrinterHelper;
   class BlockEdge;
+  class LangOptions;
   
 /// CFGBlock - Represents a single basic block in a source-level CFG.
 ///  It consists of:
@@ -181,9 +184,9 @@
   
   unsigned getBlockID() const { return BlockID; }
   
-  void dump(const CFG* cfg) const;
-  void print(llvm::raw_ostream& OS, const CFG* cfg) const;
-  void printTerminator(llvm::raw_ostream& OS) const;
+  void dump(const CFG *cfg, const LangOptions &LO) const;
+  void print(llvm::raw_ostream &OS, const CFG* cfg, const LangOptions &LO) const;
+  void printTerminator(llvm::raw_ostream &OS, const LangOptions &LO) const;
 };
   
 
@@ -283,9 +286,9 @@
   // CFG Debugging: Pretty-Printing and Visualization.
   //===--------------------------------------------------------------------===//
 
-  void viewCFG() const;
-  void print(llvm::raw_ostream& OS) const;
-  void dump() const;
+  void viewCFG(const LangOptions &LO) const;
+  void print(llvm::raw_ostream& OS, const LangOptions &LO) const;
+  void dump(const LangOptions &LO) const;
 
   //===--------------------------------------------------------------------===//
   // Internal: constructors and data.

Modified: cfe/trunk/include/clang/AST/NestedNameSpecifier.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/NestedNameSpecifier.h?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/NestedNameSpecifier.h (original)
+++ cfe/trunk/include/clang/AST/NestedNameSpecifier.h Mon Jun 29 20:26:17 2009
@@ -28,6 +28,7 @@
 class IdentifierInfo;
 class PrintingPolicy;
 class Type;
+class LangOptions;
 
 /// \brief Represents a C++ nested name specifier, such as
 /// "::std::vector<int>::".
@@ -175,7 +176,7 @@
 
   /// \brief Dump the nested name specifier to standard output to aid
   /// in debugging.
-  void dump();
+  void dump(const LangOptions &LO);
 };
 
 }

Modified: cfe/trunk/include/clang/AST/PrettyPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/PrettyPrinter.h?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/PrettyPrinter.h (original)
+++ cfe/trunk/include/clang/AST/PrettyPrinter.h Mon Jun 29 20:26:17 2009
@@ -22,6 +22,7 @@
 
 class Stmt;
 class TagDecl;
+class LangOptions;
 
 class PrinterHelper {
 public:
@@ -33,16 +34,15 @@
 /// declarations should be printed.
 struct PrintingPolicy {
   /// \brief Create a default printing policy for C.
-  PrintingPolicy() 
-    : Indentation(2), CPlusPlus(false), SuppressSpecifiers(false),
+  PrintingPolicy(const LangOptions &LO) 
+    : Indentation(2), LangOpts(LO), SuppressSpecifiers(false),
       SuppressTag(false), SuppressTagKind(false), Dump(false) { }
 
   /// \brief The number of spaces to use to indent each line.
   unsigned Indentation : 8;
 
-  /// \brief Whether we're printing C++ code (otherwise, we're
-  /// printing C code).
-  bool CPlusPlus : 1;
+  /// \brief What language we're printing.
+  const LangOptions &LangOpts;
 
   /// \brief Whether we should suppress printing of the actual specifiers for
   /// the given type or declaration.

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Mon Jun 29 20:26:17 2009
@@ -187,14 +187,14 @@
   /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
   /// back to its original source language syntax.
   void dumpPretty(ASTContext& Context) const;
-  void printPretty(llvm::raw_ostream &OS, PrinterHelper *Helper = 0, 
-                   const PrintingPolicy &Policy = PrintingPolicy(),
+  void printPretty(llvm::raw_ostream &OS, PrinterHelper *Helper, 
+                   const PrintingPolicy &Policy,
                    unsigned Indentation = 0) const {
     printPretty(OS, *(ASTContext*)0, Helper, Policy, Indentation);
   }
-  void printPretty(llvm::raw_ostream &OS, ASTContext& Context,
-                   PrinterHelper *Helper = 0, 
-                   const PrintingPolicy &Policy = PrintingPolicy(),
+  void printPretty(llvm::raw_ostream &OS, ASTContext &Context,
+                   PrinterHelper *Helper, 
+                   const PrintingPolicy &Policy,
                    unsigned Indentation = 0) const;
   
   /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Jun 29 20:26:17 2009
@@ -188,7 +188,8 @@
     getAsStringInternal(S, Policy);
     return S;
   }
-  void getAsStringInternal(std::string &Str, const PrintingPolicy &Policy) const;
+  void getAsStringInternal(std::string &Str,
+                           const PrintingPolicy &Policy) const;
   
   void dump(const char *s) const;
   void dump() const;
@@ -585,7 +586,7 @@
       TypeKind(K) {}
   
   Kind getKind() const { return TypeKind; }
-  const char *getName(bool CPlusPlus) const;
+  const char *getName(const LangOptions &LO) const;
   
   virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const;
   

Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Mon Jun 29 20:26:17 2009
@@ -22,6 +22,7 @@
 public:
   unsigned Trigraphs         : 1;  // Trigraphs in source files.
   unsigned BCPLComment       : 1;  // BCPL-style '//' comments.
+  unsigned Bool              : 1;  // 'bool', 'true', 'false' keywords.
   unsigned DollarIdents      : 1;  // '$' allowed in identifiers.
   unsigned AsmPreprocessor   : 1;  // Preprocessor in asm mode.
   unsigned GNUMode           : 1;  // True in gnu99 mode false in c99 mode (etc)
@@ -112,7 +113,7 @@
   };
   
   LangOptions() {
-    Trigraphs = BCPLComment = DollarIdents = AsmPreprocessor = 0;
+    Trigraphs = BCPLComment = Bool = DollarIdents = AsmPreprocessor = 0;
     GNUMode = ImplicitInt = Digraphs = 0;
     HexFloats = 0;
     GC = ObjC1 = ObjC2 = ObjCNonFragileABI = 0;

Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Mon Jun 29 20:26:17 2009
@@ -224,7 +224,7 @@
 
 // C++ 2.11p1: Keywords.
 KEYWORD(asm                         , KEYCXX|KEYGNU)
-KEYWORD(bool                        , KEYCXX|BOOLSUPPORT)
+KEYWORD(bool                        , BOOLSUPPORT)
 KEYWORD(catch                       , KEYCXX)
 KEYWORD(class                       , KEYCXX)
 KEYWORD(const_cast                  , KEYCXX)
@@ -232,7 +232,7 @@
 KEYWORD(dynamic_cast                , KEYCXX)
 KEYWORD(explicit                    , KEYCXX)
 KEYWORD(export                      , KEYCXX)
-KEYWORD(false                       , KEYCXX|BOOLSUPPORT)
+KEYWORD(false                       , BOOLSUPPORT)
 KEYWORD(friend                      , KEYCXX)
 KEYWORD(mutable                     , KEYCXX)
 KEYWORD(namespace                   , KEYCXX)
@@ -246,7 +246,7 @@
 KEYWORD(template                    , KEYCXX)
 KEYWORD(this                        , KEYCXX)
 KEYWORD(throw                       , KEYCXX)
-KEYWORD(true                        , KEYCXX|BOOLSUPPORT)
+KEYWORD(true                        , BOOLSUPPORT)
 KEYWORD(try                         , KEYCXX)
 KEYWORD(typename                    , KEYCXX)
 KEYWORD(typeid                      , KEYCXX)

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Jun 29 20:26:17 2009
@@ -38,11 +38,10 @@
   GlobalNestedNameSpecifier(0), CFConstantStringTypeDecl(0), 
   ObjCFastEnumerationStateTypeDecl(0), SourceMgr(SM), LangOpts(LOpts), 
   FreeMemory(FreeMem), Target(t), Idents(idents), Selectors(sels),
-  BuiltinInfo(builtins), ExternalSource(0) {  
+  BuiltinInfo(builtins), ExternalSource(0), PrintingPolicy(LOpts) {  
   if (size_reserve > 0) Types.reserve(size_reserve);    
   InitBuiltinTypes();
   TUDecl = TranslationUnitDecl::Create(*this);
-  PrintingPolicy.CPlusPlus = LangOpts.CPlusPlus;
 }
 
 ASTContext::~ASTContext() {

Modified: cfe/trunk/lib/AST/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CFG.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/AST/CFG.cpp (original)
+++ cfe/trunk/lib/AST/CFG.cpp Mon Jun 29 20:26:17 2009
@@ -1484,10 +1484,11 @@
   StmtMapTy StmtMap;
   signed CurrentBlock;
   unsigned CurrentStmt;
-
+  const LangOptions &LangOpts;
 public:
 
-  StmtPrinterHelper(const CFG* cfg) : CurrentBlock(0), CurrentStmt(0) {
+  StmtPrinterHelper(const CFG* cfg, const LangOptions &LO)
+    : CurrentBlock(0), CurrentStmt(0), LangOpts(LO) {
     for (CFG::const_iterator I = cfg->begin(), E = cfg->end(); I != E; ++I ) {
       unsigned j = 1;
       for (CFGBlock::const_iterator BI = I->begin(), BEnd = I->end() ;
@@ -1498,6 +1499,7 @@
             
   virtual ~StmtPrinterHelper() {}
   
+  const LangOptions &getLangOpts() const { return LangOpts; }
   void setBlockID(signed i) { CurrentBlock = i; }
   void setStmtID(unsigned i) { CurrentStmt = i; }
   
@@ -1516,7 +1518,10 @@
     return true;
   }
 };
+} // end anonymous namespace
+
 
+namespace {
 class VISIBILITY_HIDDEN CFGBlockTerminatorPrint
   : public StmtVisitor<CFGBlockTerminatorPrint,void> {
   
@@ -1526,7 +1531,7 @@
 
 public:
   CFGBlockTerminatorPrint(llvm::raw_ostream& os, StmtPrinterHelper* helper,
-                          const PrintingPolicy &Policy = PrintingPolicy())
+                          const PrintingPolicy &Policy)
     : OS(os), Helper(helper), Policy(Policy) {}
   
   void VisitIfStmt(IfStmt* I) {
@@ -1602,9 +1607,11 @@
     E->printPretty(OS, Helper, Policy);
   }                                                       
 };
+} // end anonymous namespace
+
   
-  
-void print_stmt(llvm::raw_ostream&OS, StmtPrinterHelper* Helper, Stmt* Terminator) {    
+static void print_stmt(llvm::raw_ostream &OS, StmtPrinterHelper* Helper,
+                       Stmt* Terminator) {
   if (Helper) {
     // special printing for statement-expressions.
     if (StmtExpr* SE = dyn_cast<StmtExpr>(Terminator)) {
@@ -1629,14 +1636,15 @@
     }  
   }
   
-  Terminator->printPretty(OS, Helper, /*FIXME:*/PrintingPolicy());
+  Terminator->printPretty(OS, Helper, PrintingPolicy(Helper->getLangOpts()));
   
   // Expressions need a newline.
   if (isa<Expr>(Terminator)) OS << '\n';
 }
   
-void print_block(llvm::raw_ostream& OS, const CFG* cfg, const CFGBlock& B,
-                 StmtPrinterHelper* Helper, bool print_edges) {
+static void print_block(llvm::raw_ostream& OS, const CFG* cfg,
+                        const CFGBlock& B,
+                        StmtPrinterHelper* Helper, bool print_edges) {
  
   if (Helper) Helper->setBlockID(B.getBlockID());
   
@@ -1662,10 +1670,12 @@
       OS << L->getName();
     else if (CaseStmt* C = dyn_cast<CaseStmt>(Terminator)) {
       OS << "case ";
-      C->getLHS()->printPretty(OS, Helper, /*FIXME:*/PrintingPolicy());
+      C->getLHS()->printPretty(OS, Helper,
+                               PrintingPolicy(Helper->getLangOpts()));
       if (C->getRHS()) {
         OS << " ... ";
-        C->getRHS()->printPretty(OS, Helper, /*FIXME:*/PrintingPolicy());
+        C->getRHS()->printPretty(OS, Helper,
+                                 PrintingPolicy(Helper->getLangOpts()));
       }
     }  
     else if (isa<DefaultStmt>(Terminator))
@@ -1703,7 +1713,8 @@
     
     if (Helper) Helper->setBlockID(-1);
     
-    CFGBlockTerminatorPrint TPrinter(OS, Helper, /*FIXME*/PrintingPolicy());
+    CFGBlockTerminatorPrint TPrinter(OS, Helper,
+                                     PrintingPolicy(Helper->getLangOpts()));
     TPrinter.Visit(const_cast<Stmt*>(B.getTerminator()));
     OS << '\n';
   }
@@ -1741,15 +1752,13 @@
   }
 }                   
 
-} // end anonymous namespace
 
 /// dump - A simple pretty printer of a CFG that outputs to stderr.
-void CFG::dump() const { print(llvm::errs()); }
+void CFG::dump(const LangOptions &LO) const { print(llvm::errs(), LO); }
 
 /// print - A simple pretty printer of a CFG that outputs to an ostream.
-void CFG::print(llvm::raw_ostream& OS) const {
-  
-  StmtPrinterHelper Helper(this);
+void CFG::print(llvm::raw_ostream &OS, const LangOptions &LO) const {
+  StmtPrinterHelper Helper(this, LO);
   
   // Print the entry block.
   print_block(OS, this, getEntry(), &Helper, true);
@@ -1769,18 +1778,22 @@
 }  
 
 /// dump - A simply pretty printer of a CFGBlock that outputs to stderr.
-void CFGBlock::dump(const CFG* cfg) const { print(llvm::errs(), cfg); }
+void CFGBlock::dump(const CFG* cfg, const LangOptions &LO) const {
+  print(llvm::errs(), cfg, LO);
+}
 
 /// print - A simple pretty printer of a CFGBlock that outputs to an ostream.
 ///   Generally this will only be called from CFG::print.
-void CFGBlock::print(llvm::raw_ostream& OS, const CFG* cfg) const {
-  StmtPrinterHelper Helper(cfg);
+void CFGBlock::print(llvm::raw_ostream& OS, const CFG* cfg,
+                     const LangOptions &LO) const {
+  StmtPrinterHelper Helper(cfg, LO);
   print_block(OS, cfg, *this, &Helper, true);
 }
 
 /// printTerminator - A simple pretty printer of the terminator of a CFGBlock.
-void CFGBlock::printTerminator(llvm::raw_ostream& OS) const {  
-  CFGBlockTerminatorPrint TPrinter(OS,NULL);
+void CFGBlock::printTerminator(llvm::raw_ostream &OS,
+                               const LangOptions &LO) const {  
+  CFGBlockTerminatorPrint TPrinter(OS, NULL, PrintingPolicy(LO));
   TPrinter.Visit(const_cast<Stmt*>(getTerminator()));
 }
 
@@ -1872,9 +1885,9 @@
 static StmtPrinterHelper* GraphHelper;  
 #endif
 
-void CFG::viewCFG() const {
+void CFG::viewCFG(const LangOptions &LO) const {
 #ifndef NDEBUG
-  StmtPrinterHelper H(this);
+  StmtPrinterHelper H(this, LO);
   GraphHelper = &H;
   llvm::ViewGraph(this,"CFG");
   GraphHelper = NULL;

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Mon Jun 29 20:26:17 2009
@@ -226,8 +226,7 @@
     if (const ClassTemplateSpecializationDecl *Spec 
           = dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) {
       const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
-      PrintingPolicy Policy;
-      Policy.CPlusPlus = true;
+      PrintingPolicy Policy(getASTContext().getLangOptions());
       std::string TemplateArgsStr
         = TemplateSpecializationType::PrintTemplateArgumentList(
                                            TemplateArgs.getFlatArgumentList(),

Modified: cfe/trunk/lib/AST/NestedNameSpecifier.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/NestedNameSpecifier.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/AST/NestedNameSpecifier.cpp (original)
+++ cfe/trunk/lib/AST/NestedNameSpecifier.cpp Mon Jun 29 20:26:17 2009
@@ -153,8 +153,6 @@
   Context.Deallocate((void *)this);
 }
 
-void NestedNameSpecifier::dump() {
-  PrintingPolicy Policy;
-  Policy.CPlusPlus = true;
-  print(llvm::errs(), Policy);
+void NestedNameSpecifier::dump(const LangOptions &LO) {
+  print(llvm::errs(), PrintingPolicy(LO));
 }

Modified: cfe/trunk/lib/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtDumper.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/AST/StmtDumper.cpp (original)
+++ cfe/trunk/lib/AST/StmtDumper.cpp Mon Jun 29 20:26:17 2009
@@ -41,7 +41,6 @@
     const char *LastLocFilename;
     unsigned LastLocLine;
 
-    PrintingPolicy Policy;
   public:
     StmtDumper(SourceManager *sm, FILE *f, unsigned maxDepth)
       : SM(sm), F(f), IndentLevel(0-1), MaxDepth(maxDepth) {
@@ -226,7 +225,8 @@
     }
     
     std::string Name = VD->getNameAsString();
-    VD->getType().getAsStringInternal(Name, Policy);
+    VD->getType().getAsStringInternal(Name, 
+                          PrintingPolicy(VD->getASTContext().getLangOptions()));
     fprintf(F, "%s", Name.c_str());
     
     // If this is a vardecl with an initializer, emit it.

Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Mon Jun 29 20:26:17 2009
@@ -35,7 +35,7 @@
 
   public:
     StmtPrinter(llvm::raw_ostream &os, ASTContext &C, PrinterHelper* helper, 
-                const PrintingPolicy &Policy = PrintingPolicy(),
+                const PrintingPolicy &Policy,
                 unsigned Indentation = 0)
       : OS(os), Context(C), IndentLevel(Indentation), Helper(helper),
         Policy(Policy) {}
@@ -861,7 +861,7 @@
 }
 
 void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
-  if (Policy.CPlusPlus)
+  if (Policy.LangOpts.CPlusPlus)
     OS << "/*implicit*/" << Node->getType().getAsString(Policy) << "()";
   else {
     OS << "/*implicit*/(" << Node->getType().getAsString(Policy) << ")";
@@ -1216,7 +1216,8 @@
 //===----------------------------------------------------------------------===//
 
 void Stmt::dumpPretty(ASTContext& Context) const {
-  printPretty(llvm::errs(), Context, 0, PrintingPolicy());
+  printPretty(llvm::errs(), Context, 0,
+              PrintingPolicy(Context.getLangOptions()));
 }
 
 void Stmt::printPretty(llvm::raw_ostream &OS, ASTContext& Context,

Modified: cfe/trunk/lib/AST/TemplateName.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TemplateName.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/AST/TemplateName.cpp (original)
+++ cfe/trunk/lib/AST/TemplateName.cpp Mon Jun 29 20:26:17 2009
@@ -15,6 +15,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/PrettyPrinter.h"
+#include "clang/Basic/LangOptions.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace clang;
 
@@ -59,7 +60,8 @@
 }
 
 void TemplateName::dump() const {
-  PrintingPolicy Policy;
-  Policy.CPlusPlus = true;
-  print(llvm::errs(), Policy);
+  LangOptions LO;  // FIXME!
+  LO.CPlusPlus = true;
+  LO.Bool = true;
+  print(llvm::errs(), PrintingPolicy(LO));
 }

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Mon Jun 29 20:26:17 2009
@@ -938,11 +938,11 @@
   }
 }
 
-const char *BuiltinType::getName(bool CPlusPlus) const {
+const char *BuiltinType::getName(const LangOptions &LO) const {
   switch (getKind()) {
   default: assert(0 && "Unknown builtin type!");
   case Void:              return "void";
-  case Bool:              return CPlusPlus? "bool" : "_Bool";
+  case Bool:              return LO.Bool ? "bool" : "_Bool";
   case Char_S:            return "char";
   case Char_U:            return "char";
   case SChar:             return "signed char";
@@ -1160,9 +1160,9 @@
 //===----------------------------------------------------------------------===//
 
 void QualType::dump(const char *msg) const {
-  PrintingPolicy Policy;
   std::string R = "identifier";
-  getAsStringInternal(R, Policy);
+  LangOptions LO;
+  getAsStringInternal(R, PrintingPolicy(LO));
   if (msg)
     fprintf(stderr, "%s: %s\n", msg, R.c_str());
   else
@@ -1174,7 +1174,8 @@
 
 void Type::dump() const {
   std::string S = "identifier";
-  getAsStringInternal(S, PrintingPolicy());
+  LangOptions LO;
+  getAsStringInternal(S, PrintingPolicy(LO));
   fprintf(stderr, "%s\n", S.c_str());
 }
 
@@ -1193,7 +1194,8 @@
 
 std::string QualType::getAsString() const {
   std::string S;
-  getAsStringInternal(S, PrintingPolicy());
+  LangOptions LO;
+  getAsStringInternal(S, PrintingPolicy(LO));
   return S;
 }
 
@@ -1224,11 +1226,11 @@
 void BuiltinType::getAsStringInternal(std::string &S, 
                                       const PrintingPolicy &Policy) const {
   if (S.empty()) {
-    S = getName(Policy.CPlusPlus);
+    S = getName(Policy.LangOpts);
   } else {
     // Prefix the basic type, e.g. 'int X'.
     S = ' ' + S;
-    S = getName(Policy.CPlusPlus) + S;
+    S = getName(Policy.LangOpts) + S;
   }
 }
 
@@ -1470,7 +1472,7 @@
     if (getNumArgs())
       S += ", ";
     S += "...";
-  } else if (getNumArgs() == 0 && !Policy.CPlusPlus) {
+  } else if (getNumArgs() == 0 && !Policy.LangOpts.CPlusPlus) {
     // Do not emit int() if we have a proto, emit 'int(void)'.
     S += "void";
   }

Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Mon Jun 29 20:26:17 2009
@@ -3154,7 +3154,8 @@
           SourceLocation SLoc = S->getLocStart();
 
           Out << S->getStmtClassName() << ' ' << (void*) S << ' ';        
-          S->printPretty(Out);
+          LangOptions LO; // FIXME.
+          S->printPretty(Out, 0, PrintingPolicy(LO));
           
           if (SLoc.isFileID()) {        
             Out << "\\lline="
@@ -3208,7 +3209,8 @@
           SourceLocation SLoc = T->getLocStart();
          
           Out << "\\|Terminator: ";
-          E.getSrc()->printTerminator(Out);
+          LangOptions LO; // FIXME.
+          E.getSrc()->printTerminator(Out, LO);
           
           if (SLoc.isFileID()) {
             Out << "\\lline="
@@ -3223,11 +3225,12 @@
             if (Label) {                        
               if (CaseStmt* C = dyn_cast<CaseStmt>(Label)) {
                 Out << "\\lcase ";
-                C->getLHS()->printPretty(Out);
+                LangOptions LO; // FIXME.
+                C->getLHS()->printPretty(Out, 0, PrintingPolicy(LO));
               
                 if (Stmt* RHS = C->getRHS()) {
                   Out << " .. ";
-                  RHS->printPretty(Out);
+                  RHS->printPretty(Out, 0, PrintingPolicy(LO));
                 }
                 
                 Out << ":";

Modified: cfe/trunk/lib/Analysis/GRState.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRState.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRState.cpp (original)
+++ cfe/trunk/lib/Analysis/GRState.cpp Mon Jun 29 20:26:17 2009
@@ -166,7 +166,8 @@
     else { Out << nl; }
     
     Out << " (" << (void*) I.getKey() << ") ";
-    I.getKey()->printPretty(Out);
+    LangOptions LO; // FIXME.
+    I.getKey()->printPretty(Out, 0, PrintingPolicy(LO));
     Out << " : ";
     I.getData().print(Out);
   }
@@ -183,7 +184,8 @@
     else { Out << nl; }
     
     Out << " (" << (void*) I.getKey() << ") ";
-    I.getKey()->printPretty(Out);
+    LangOptions LO; // FIXME.
+    I.getKey()->printPretty(Out, 0, PrintingPolicy(LO));
     Out << " : ";
     I.getData().print(Out);
   }

Modified: cfe/trunk/lib/Analysis/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/MemRegion.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/MemRegion.cpp (original)
+++ cfe/trunk/lib/Analysis/MemRegion.cpp Mon Jun 29 20:26:17 2009
@@ -184,7 +184,8 @@
 }
 
 void StringRegion::print(llvm::raw_ostream& os) const {
-  Str->printPretty(os);
+  LangOptions LO; // FIXME.
+  Str->printPretty(os, 0, PrintingPolicy(LO));
 }
 
 void SymbolicRegion::print(llvm::raw_ostream& os) const {

Modified: cfe/trunk/lib/Basic/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/IdentifierTable.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/IdentifierTable.cpp (original)
+++ cfe/trunk/lib/Basic/IdentifierTable.cpp Mon Jun 29 20:26:17 2009
@@ -89,7 +89,7 @@
   else if (LangOpts.C99 && (Flags & KEYC99)) AddResult = 2;
   else if (LangOpts.GNUMode && (Flags & KEYGNU)) AddResult = 1;
   else if (LangOpts.Microsoft && (Flags & KEYMS)) AddResult = 1;
-  else if (LangOpts.OpenCL && (Flags & BOOLSUPPORT)) AddResult = 2;
+  else if (LangOpts.Bool && (Flags & BOOLSUPPORT)) AddResult = 2;
 
   // Don't add this keyword if disabled in this language.
   if (AddResult == 0) return;

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Jun 29 20:26:17 2009
@@ -151,7 +151,7 @@
   uint64_t Offset = 0;
   
   return DebugFactory.CreateBasicType(Unit, 
-                      BT->getName(M->getContext().getLangOptions().CPlusPlus),
+                                  BT->getName(M->getContext().getLangOptions()),
                                       Unit, 0, Size, Align,
                                       Offset, /*flags*/ 0, Encoding);
 }

Modified: cfe/trunk/lib/Frontend/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/AnalysisConsumer.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/AnalysisConsumer.cpp (original)
+++ cfe/trunk/lib/Frontend/AnalysisConsumer.cpp Mon Jun 29 20:26:17 2009
@@ -479,14 +479,16 @@
 static void ActionCFGDump(AnalysisManager& mgr) {
   if (CFG* c = mgr.getCFG()) {
     mgr.DisplayFunction();
-    c->dump();
+    LangOptions LO;  // FIXME!
+    c->dump(LO);
   }
 }
 
 static void ActionCFGView(AnalysisManager& mgr) {
   if (CFG* c = mgr.getCFG()) {
     mgr.DisplayFunction();
-    c->viewCFG();  
+    LangOptions LO; // FIXME!
+    c->viewCFG(LO);
   }
 }
 

Modified: cfe/trunk/lib/Frontend/ResolveLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ResolveLocation.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/ResolveLocation.cpp (original)
+++ cfe/trunk/lib/Frontend/ResolveLocation.cpp Mon Jun 29 20:26:17 2009
@@ -299,7 +299,7 @@
 void LocResolverBase::print(Stmt *Node) {
   llvm::raw_ostream &OS = llvm::outs();
   OS << "#### STMT ####\n";
-  Node->printPretty(OS, Ctx);
+  Node->printPretty(OS, Ctx, 0, PrintingPolicy(Ctx.getLangOptions()));
   OS << " <";
   Node->getLocStart().print(OS, Ctx.getSourceManager());
   OS << " > - <";

Modified: cfe/trunk/lib/Frontend/RewriteBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteBlocks.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/RewriteBlocks.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteBlocks.cpp Mon Jun 29 20:26:17 2009
@@ -724,7 +724,8 @@
   BlockCall += "((struct __block_impl *)";
   std::string closureExprBufStr;
   llvm::raw_string_ostream closureExprBuf(closureExprBufStr);
-  Exp->getCallee()->printPretty(closureExprBuf, *Context);
+  Exp->getCallee()->printPretty(closureExprBuf, *Context, 0,
+                                PrintingPolicy(LangOpts));
   BlockCall += closureExprBuf.str();
   BlockCall += ")->FuncPtr)";
   
@@ -735,7 +736,7 @@
        E = Exp->arg_end(); I != E; ++I) {
     std::string syncExprBufS;
     llvm::raw_string_ostream Buf(syncExprBufS);
-    (*I)->printPretty(Buf, *Context);
+    (*I)->printPretty(Buf, *Context, 0, PrintingPolicy(LangOpts));
     BlockCall += ", " + Buf.str();
   }
   return BlockCall;

Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Mon Jun 29 20:26:17 2009
@@ -171,7 +171,7 @@
       // Get the new text.
       std::string SStr;
       llvm::raw_string_ostream S(SStr);
-      New->printPretty(S, *Context);
+      New->printPretty(S, *Context, 0, PrintingPolicy(LangOpts));
       const std::string &Str = S.str();
 
       // If replacement succeeded or warning disabled return with no warning.
@@ -1514,7 +1514,8 @@
                                                 SourceLocation());
   std::string syncExprBufS;
   llvm::raw_string_ostream syncExprBuf(syncExprBufS);
-  syncExpr->printPretty(syncExprBuf, *Context);
+  syncExpr->printPretty(syncExprBuf, *Context, 0,
+                        PrintingPolicy(LangOpts));
   buf += syncExprBuf.str();
   buf += ");\n";
   buf += "  if (_rethrow) objc_exception_throw(_rethrow);\n";
@@ -2143,7 +2144,8 @@
   // The pretty printer for StringLiteral handles escape characters properly.
   std::string prettyBufS;
   llvm::raw_string_ostream prettyBuf(prettyBufS);
-  Exp->getString()->printPretty(prettyBuf, *Context);
+  Exp->getString()->printPretty(prettyBuf, *Context, 0,
+                                PrintingPolicy(LangOpts));
   Preamble += prettyBuf.str();
   Preamble += ",";
   // The minus 2 removes the begin/end double quotes.

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

==============================================================================
--- cfe/trunk/lib/Rewrite/Rewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/Rewriter.cpp Mon Jun 29 20:26:17 2009
@@ -218,7 +218,7 @@
   // Get the new text.
   std::string SStr;
   llvm::raw_string_ostream S(SStr);
-  To->printPretty(S);
+  To->printPretty(S, 0, PrintingPolicy(*LangOpts));
   const std::string &Str = S.str();
 
   ReplaceText(From->getLocStart(), Size, &Str[0], Str.size());

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Mon Jun 29 20:26:17 2009
@@ -784,6 +784,9 @@
   if (AccessControl)
     Options.AccessControl = 1;
   
+  // OpenCL and C++ both have bool, true, false keywords.
+  Options.Bool = Options.OpenCL | Options.CPlusPlus;
+  
   Options.MathErrno = MathErrno;
 
   Options.InstantiationDepth = TemplateDepth;

Modified: cfe/trunk/tools/index-test/index-test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/index-test/index-test.cpp?rev=74493&r1=74492&r2=74493&view=diff

==============================================================================
--- cfe/trunk/tools/index-test/index-test.cpp (original)
+++ cfe/trunk/tools/index-test/index-test.cpp Mon Jun 29 20:26:17 2009
@@ -133,7 +133,8 @@
     if (Point.Node) {
       OS << "Statement node at point: " << Point.Node->getStmtClassName()
          << " ";
-      Point.Node->printPretty(OS, AST->getASTContext());
+      Point.Node->printPretty(OS, AST->getASTContext(), 0,
+                        PrintingPolicy(AST->getASTContext().getLangOptions()));
       OS << "\n";
     }
   }





More information about the cfe-commits mailing list