diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2014-11-24 09:15:30 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2014-11-24 09:15:30 +0000 |
| commit | 9f4dbff6669c8037f3b036bcf580d14f1a4f12a5 (patch) | |
| tree | 47df2c12b57214af6c31e47404b005675b8b7ffc /lib/AST/TypePrinter.cpp | |
| parent | f73d5f23a889b93d89ddef61ac0995df40286bb8 (diff) | |
Notes
Diffstat (limited to 'lib/AST/TypePrinter.cpp')
| -rw-r--r-- | lib/AST/TypePrinter.cpp | 93 |
1 files changed, 56 insertions, 37 deletions
diff --git a/lib/AST/TypePrinter.cpp b/lib/AST/TypePrinter.cpp index 571e3db0289f..061473eb848d 100644 --- a/lib/AST/TypePrinter.cpp +++ b/lib/AST/TypePrinter.cpp @@ -204,6 +204,7 @@ bool TypePrinter::canPrefixQualifiers(const Type *T, NeedARCStrongQualifier = true; // Fall through + case Type::Adjusted: case Type::Decayed: case Type::Pointer: case Type::BlockPointer: @@ -429,7 +430,16 @@ void TypePrinter::printConstantArrayBefore(const ConstantArrayType *T, } void TypePrinter::printConstantArrayAfter(const ConstantArrayType *T, raw_ostream &OS) { - OS << '[' << T->getSize().getZExtValue() << ']'; + OS << '['; + if (T->getIndexTypeQualifiers().hasQualifiers()) { + AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers()); + OS << ' '; + } + + if (T->getSizeModifier() == ArrayType::Static) + OS << "static "; + + OS << T->getSize().getZExtValue() << ']'; printAfter(T->getElementType(), OS); } @@ -460,23 +470,32 @@ void TypePrinter::printVariableArrayAfter(const VariableArrayType *T, } if (T->getSizeModifier() == VariableArrayType::Static) - OS << "static"; + OS << "static "; else if (T->getSizeModifier() == VariableArrayType::Star) OS << '*'; if (T->getSizeExpr()) - T->getSizeExpr()->printPretty(OS, 0, Policy); + T->getSizeExpr()->printPretty(OS, nullptr, Policy); OS << ']'; printAfter(T->getElementType(), OS); } +void TypePrinter::printAdjustedBefore(const AdjustedType *T, raw_ostream &OS) { + // Print the adjusted representation, otherwise the adjustment will be + // invisible. + printBefore(T->getAdjustedType(), OS); +} +void TypePrinter::printAdjustedAfter(const AdjustedType *T, raw_ostream &OS) { + printAfter(T->getAdjustedType(), OS); +} + void TypePrinter::printDecayedBefore(const DecayedType *T, raw_ostream &OS) { // Print as though it's a pointer. - printBefore(T->getDecayedType(), OS); + printAdjustedBefore(T, OS); } void TypePrinter::printDecayedAfter(const DecayedType *T, raw_ostream &OS) { - printAfter(T->getDecayedType(), OS); + printAdjustedAfter(T, OS); } void TypePrinter::printDependentSizedArrayBefore( @@ -491,7 +510,7 @@ void TypePrinter::printDependentSizedArrayAfter( raw_ostream &OS) { OS << '['; if (T->getSizeExpr()) - T->getSizeExpr()->printPretty(OS, 0, Policy); + T->getSizeExpr()->printPretty(OS, nullptr, Policy); OS << ']'; printAfter(T->getElementType(), OS); } @@ -506,7 +525,7 @@ void TypePrinter::printDependentSizedExtVectorAfter( raw_ostream &OS) { OS << " __attribute__((ext_vector_type("; if (T->getSizeExpr()) - T->getSizeExpr()->printPretty(OS, 0, Policy); + T->getSizeExpr()->printPretty(OS, nullptr, Policy); OS << ")))"; printAfter(T->getElementType(), OS); } @@ -583,7 +602,8 @@ FunctionProtoType::printExceptionSpecification(raw_ostream &OS, OS << " noexcept"; if (getExceptionSpecType() == EST_ComputedNoexcept) { OS << '('; - getNoexceptExpr()->printPretty(OS, 0, Policy); + if (getNoexceptExpr()) + getNoexceptExpr()->printPretty(OS, nullptr, Policy); OS << ')'; } } @@ -598,7 +618,7 @@ void TypePrinter::printFunctionProtoBefore(const FunctionProtoType *T, } else { // If needed for precedence reasons, wrap the inner part in grouping parens. SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder, false); - printBefore(T->getResultType(), OS); + printBefore(T->getReturnType(), OS); if (!PrevPHIsEmpty.get()) OS << '('; } @@ -614,17 +634,17 @@ void TypePrinter::printFunctionProtoAfter(const FunctionProtoType *T, OS << '('; { ParamPolicyRAII ParamPolicy(Policy); - for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { + for (unsigned i = 0, e = T->getNumParams(); i != e; ++i) { if (i) OS << ", "; - print(T->getArgType(i), OS, StringRef()); + print(T->getParamType(i), OS, StringRef()); } } if (T->isVariadic()) { - if (T->getNumArgs()) + if (T->getNumParams()) OS << ", "; OS << "..."; - } else if (T->getNumArgs() == 0 && !Policy.LangOpts.CPlusPlus) { + } else if (T->getNumParams() == 0 && !Policy.LangOpts.CPlusPlus) { // Do not emit int() if we have a proto, emit 'int(void)'. OS << "void"; } @@ -703,17 +723,17 @@ void TypePrinter::printFunctionProtoAfter(const FunctionProtoType *T, T->printExceptionSpecification(OS, Policy); if (T->hasTrailingReturn()) { - OS << " -> "; - print(T->getResultType(), OS, StringRef()); + OS << " -> "; + print(T->getReturnType(), OS, StringRef()); } else - printAfter(T->getResultType(), OS); + printAfter(T->getReturnType(), OS); } void TypePrinter::printFunctionNoProtoBefore(const FunctionNoProtoType *T, raw_ostream &OS) { // If needed for precedence reasons, wrap the inner part in grouping parens. SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder, false); - printBefore(T->getResultType(), OS); + printBefore(T->getReturnType(), OS); if (!PrevPHIsEmpty.get()) OS << '('; } @@ -727,7 +747,7 @@ void TypePrinter::printFunctionNoProtoAfter(const FunctionNoProtoType *T, OS << "()"; if (T->getNoReturnAttr()) OS << " __attribute__((noreturn))"; - printAfter(T->getResultType(), OS); + printAfter(T->getReturnType(), OS); } void TypePrinter::printTypeSpec(const NamedDecl *D, raw_ostream &OS) { @@ -751,7 +771,8 @@ void TypePrinter::printTypedefAfter(const TypedefType *T, raw_ostream &OS) { } void TypePrinter::printTypeOfExprBefore(const TypeOfExprType *T, raw_ostream &OS) { OS << "typeof "; - T->getUnderlyingExpr()->printPretty(OS, 0, Policy); + if (T->getUnderlyingExpr()) + T->getUnderlyingExpr()->printPretty(OS, nullptr, Policy); spaceBeforePlaceHolder(OS); } void TypePrinter::printTypeOfExprAfter(const TypeOfExprType *T, @@ -767,7 +788,8 @@ void TypePrinter::printTypeOfAfter(const TypeOfType *T, raw_ostream &OS) { } void TypePrinter::printDecltypeBefore(const DecltypeType *T, raw_ostream &OS) { OS << "decltype("; - T->getUnderlyingExpr()->printPretty(OS, 0, Policy); + if (T->getUnderlyingExpr()) + T->getUnderlyingExpr()->printPretty(OS, nullptr, Policy); OS << ')'; spaceBeforePlaceHolder(OS); } @@ -838,7 +860,7 @@ void TypePrinter::AppendScope(DeclContext *DC, raw_ostream &OS) { if (NS->getIdentifier()) OS << NS->getName() << "::"; else - OS << "<anonymous>::"; + OS << "(anonymous namespace)::"; } else if (ClassTemplateSpecializationDecl *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) { IncludeStrongLifetimeRAII Strong(Policy); @@ -890,13 +912,13 @@ void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) { OS << Typedef->getIdentifier()->getName(); } else { // Make an unambiguous representation for anonymous types, e.g. - // <anonymous enum at /usr/include/string.h:120:9> + // (anonymous enum at /usr/include/string.h:120:9) if (isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda()) { - OS << "<lambda"; + OS << "(lambda"; HasKindDecoration = true; } else { - OS << "<anonymous"; + OS << "(anonymous"; } if (Policy.AnonymousTagLocations) { @@ -915,7 +937,7 @@ void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) { } } - OS << '>'; + OS << ')'; } // If this is a class template specialization, print the template @@ -1249,13 +1271,12 @@ void TypePrinter::printObjCObjectBefore(const ObjCObjectType *T, print(T->getBaseType(), OS, StringRef()); OS << '<'; bool isFirst = true; - for (ObjCObjectType::qual_iterator - I = T->qual_begin(), E = T->qual_end(); I != E; ++I) { + for (const auto *I : T->quals()) { if (isFirst) isFirst = false; else OS << ','; - OS << (*I)->getName(); + OS << I->getName(); } OS << '>'; spaceBeforePlaceHolder(OS); @@ -1271,12 +1292,12 @@ void TypePrinter::printObjCObjectPointerBefore(const ObjCObjectPointerType *T, T->getPointeeType().getLocalQualifiers().print(OS, Policy, /*appendSpaceIfNonEmpty=*/true); + assert(!T->isObjCSelType()); + if (T->isObjCIdType() || T->isObjCQualifiedIdType()) OS << "id"; else if (T->isObjCClassType() || T->isObjCQualifiedClassType()) OS << "Class"; - else if (T->isObjCSelType()) - OS << "SEL"; else OS << T->getInterfaceDecl()->getName(); @@ -1292,7 +1313,8 @@ void TypePrinter::printObjCObjectPointerBefore(const ObjCObjectPointerType *T, OS << '>'; } - if (!T->isObjCIdType() && !T->isObjCQualifiedIdType()) { + if (!T->isObjCIdType() && !T->isObjCQualifiedIdType() && + !T->isObjCClassType() && !T->isObjCQualifiedClassType()) { OS << " *"; // Don't forget the implicit pointer. } else { spaceBeforePlaceHolder(OS); @@ -1413,13 +1435,10 @@ void QualType::dump(const char *msg) const { print(llvm::errs(), PrintingPolicy(LO), "identifier"); llvm::errs() << '\n'; } -void QualType::dump() const { - dump(0); -} -void Type::dump() const { - QualType(this, 0).dump(); -} +LLVM_DUMP_METHOD void QualType::dump() const { dump(nullptr); } + +LLVM_DUMP_METHOD void Type::dump() const { QualType(this, 0).dump(); } std::string Qualifiers::getAsString() const { LangOptions LO; |
