From: Eli Friedman Date: Sat, 30 May 2009 00:10:16 +0000 (+0000) Subject: Add support for PrintingPolicy::SuppressTypeSpecifiers to type printing. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=22b61e937dcd8ba2e14764c367f975a392ec7da0;p=clang Add support for PrintingPolicy::SuppressTypeSpecifiers to type printing. (I have a work-in-progress patch which uses this.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72598 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index beca7088be..15c6b6654f 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -484,6 +484,10 @@ public: /// 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; diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 64433cd89b..e63e12b3d6 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -896,6 +896,19 @@ bool Type::isNullPtrType() const { 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 @@ QualType::getAsStringInternal(std::string &S, 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 @@ void FunctionProtoType::getAsStringInternal(std::string &S, const PrintingPolicy 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(); }