[cfe-commits] r72598 - in /cfe/trunk: include/clang/AST/Type.h lib/AST/Type.cpp

Eli Friedman eli.friedman at gmail.com
Fri May 29 17:10:16 PDT 2009


Author: efriedma
Date: Fri May 29 19:10:16 2009
New Revision: 72598

URL: http://llvm.org/viewvc/llvm-project?rev=72598&view=rev
Log:
Add support for PrintingPolicy::SuppressTypeSpecifiers to type printing.  
(I have a work-in-progress patch which uses this.)


Modified:
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/lib/AST/Type.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri May 29 19:10:16 2009
@@ -484,6 +484,10 @@
   /// incomplete types.
   bool isConstantSizeType() const;
 
+  /// isSpecifierType - Returns true if this type can be represented by some
+  /// set of type specifiers.
+  bool isSpecifierType() const;
+
   QualType getCanonicalTypeInternal() const { return CanonicalType; }
   void dump() const;
   virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const = 0;

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

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Fri May 29 19:10:16 2009
@@ -896,6 +896,19 @@
   return false;
 }
 
+bool Type::isSpecifierType() const {
+  // Note that this intentionally does not use the canonical type.
+  switch (getTypeClass()) {
+  case Builtin:
+  case Record:
+  case Enum:
+  case Typedef:
+    return true;
+  default:
+    return false;
+  }
+}
+
 const char *BuiltinType::getName(bool CPlusPlus) const {
   switch (getKind()) {
   default: assert(0 && "Unknown builtin type!");
@@ -1144,7 +1157,10 @@
     S += "NULL TYPE";
     return;
   }
-  
+
+  if (Policy.SuppressTypeSpecifiers && getTypePtr()->isSpecifierType())
+    return;
+
   // Print qualifiers as appropriate.
   if (unsigned Tq = getCVRQualifiers()) {
     std::string TQS;
@@ -1371,9 +1387,11 @@
   
   S += "(";
   std::string Tmp;
+  PrintingPolicy ParamPolicy(Policy);
+  ParamPolicy.SuppressTypeSpecifiers = false;
   for (unsigned i = 0, e = getNumArgs(); i != e; ++i) {
     if (i) S += ", ";
-    getArgType(i).getAsStringInternal(Tmp, Policy);
+    getArgType(i).getAsStringInternal(Tmp, ParamPolicy);
     S += Tmp;
     Tmp.clear();
   }





More information about the cfe-commits mailing list