diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-02-17 06:52:25 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-02-17 06:52:25 +0000 |
commit | c6daf0b29d6c48a99cb1ad707973a7e6dfcafd58 (patch) | |
tree | 857832d4d4283bd0e16d721bd6ef119f15179a1a /lib | |
parent | 6810630bb00ba2944cbeb54834f38f69dbddfd7f (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125729 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/TypePrinter.cpp | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/lib/AST/TypePrinter.cpp b/lib/AST/TypePrinter.cpp index c0ce1f25bf..5e6046acdc 100644 --- a/lib/AST/TypePrinter.cpp +++ b/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; |