summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-02-17 06:52:25 +0000
committerDouglas Gregor <dgregor@apple.com>2011-02-17 06:52:25 +0000
commitb0f2ea9e9ecb87ce0f4f59b8b49be5dc9391aa41 (patch)
tree58961bbceea5092a0693b7c78d215d418e5bf398 /clang/lib
parent83f4cee1999d5fd8cc866b26d6eefe1a131870aa (diff)
downloadbcm5719-llvm-b0f2ea9e9ecb87ce0f4f59b8b49be5dc9391aa41.tar.gz
bcm5719-llvm-b0f2ea9e9ecb87ce0f4f59b8b49be5dc9391aa41.zip
When printing a qualified type, look through a substituted template
parameter type to see what's behind it, so that we don't end up printing silly things like "float const *" when "const float *" would make more sense. Also, replace the pile of "isa" tests with a simple switch enumerating all of the cases, making a few more obvious cases use prefix qualifiers. llvm-svn: 125729
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/TypePrinter.cpp60
1 files changed, 55 insertions, 5 deletions
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index c0ce1f25bf5..5e6046acdc5 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -77,11 +77,61 @@ void TypePrinter::print(const Type *T, Qualifiers Quals, std::string &buffer) {
// the type is complex. For example if the type is "int*", we *must* print
// "int * const", printing "const int *" is different. Only do this when the
// type expands to a simple string.
- bool CanPrefixQualifiers =
- isa<BuiltinType>(T) || isa<TypedefType>(T) || isa<TagType>(T) ||
- isa<ComplexType>(T) || isa<TemplateSpecializationType>(T) ||
- isa<ObjCObjectType>(T) || isa<ObjCInterfaceType>(T) ||
- T->isObjCIdType() || T->isObjCQualifiedIdType();
+ bool CanPrefixQualifiers = false;
+
+ Type::TypeClass TC = T->getTypeClass();
+ if (const SubstTemplateTypeParmType *Subst
+ = dyn_cast<SubstTemplateTypeParmType>(T))
+ TC = Subst->getReplacementType()->getTypeClass();
+
+ switch (TC) {
+ case Type::Builtin:
+ case Type::Complex:
+ case Type::UnresolvedUsing:
+ case Type::Typedef:
+ case Type::TypeOfExpr:
+ case Type::TypeOf:
+ case Type::Decltype:
+ case Type::Record:
+ case Type::Enum:
+ case Type::Elaborated:
+ case Type::TemplateTypeParm:
+ case Type::SubstTemplateTypeParmPack:
+ case Type::TemplateSpecialization:
+ case Type::InjectedClassName:
+ case Type::DependentName:
+ case Type::DependentTemplateSpecialization:
+ case Type::ObjCObject:
+ case Type::ObjCInterface:
+ CanPrefixQualifiers = true;
+ break;
+
+ case Type::ObjCObjectPointer:
+ CanPrefixQualifiers = T->isObjCIdType() || T->isObjCClassType() ||
+ T->isObjCQualifiedIdType() || T->isObjCQualifiedClassType();
+ break;
+
+ case Type::Pointer:
+ case Type::BlockPointer:
+ case Type::LValueReference:
+ case Type::RValueReference:
+ case Type::MemberPointer:
+ case Type::ConstantArray:
+ case Type::IncompleteArray:
+ case Type::VariableArray:
+ case Type::DependentSizedArray:
+ case Type::DependentSizedExtVector:
+ case Type::Vector:
+ case Type::ExtVector:
+ case Type::FunctionProto:
+ case Type::FunctionNoProto:
+ case Type::Paren:
+ case Type::Attributed:
+ case Type::PackExpansion:
+ case Type::SubstTemplateTypeParm:
+ CanPrefixQualifiers = false;
+ break;
+ }
if (!CanPrefixQualifiers && !Quals.empty()) {
std::string qualsBuffer;
OpenPOWER on IntegriCloud