diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/ExtractAPI/DeclarationFragments.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/ExtractAPI/DeclarationFragments.cpp | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/contrib/llvm-project/clang/lib/ExtractAPI/DeclarationFragments.cpp b/contrib/llvm-project/clang/lib/ExtractAPI/DeclarationFragments.cpp index 12c91c582aa9..1e52f221c798 100644 --- a/contrib/llvm-project/clang/lib/ExtractAPI/DeclarationFragments.cpp +++ b/contrib/llvm-project/clang/lib/ExtractAPI/DeclarationFragments.cpp @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/ExtractAPI/DeclarationFragments.h" -#include "TypedefUnderlyingTypeResolver.h" +#include "clang/ExtractAPI/TypedefUnderlyingTypeResolver.h" #include "clang/Index/USRGeneration.h" #include "llvm/ADT/StringSwitch.h" @@ -160,14 +160,26 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType( DeclarationFragments Fragments; // Declaration fragments of a pointer type is the declaration fragments of - // the pointee type followed by a `*`, except for Objective-C `id` and `Class` - // pointers, where we do not spell out the `*`. - if (T->isPointerType() || - (T->isObjCObjectPointerType() && - !T->getAs<ObjCObjectPointerType>()->isObjCIdOrClassType())) { + // the pointee type followed by a `*`, + if (T->isPointerType()) return Fragments .append(getFragmentsForType(T->getPointeeType(), Context, After)) .append(" *", DeclarationFragments::FragmentKind::Text); + + // For Objective-C `id` and `Class` pointers + // we do not spell out the `*`. + if (T->isObjCObjectPointerType() && + !T->getAs<ObjCObjectPointerType>()->isObjCIdOrClassType()) { + + Fragments.append(getFragmentsForType(T->getPointeeType(), Context, After)); + + // id<protocol> is an qualified id type + // id<protocol>* is not an qualified id type + if (!T->getAs<ObjCObjectPointerType>()->isObjCQualifiedIdType()) { + Fragments.append(" *", DeclarationFragments::FragmentKind::Text); + } + + return Fragments; } // Declaration fragments of a lvalue reference type is the declaration @@ -243,26 +255,30 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType( return Fragments.append(getFragmentsForType(ET->desugar(), Context, After)); } - // Everything we care about has been handled now, reduce to the canonical - // unqualified base type. - QualType Base = T->getCanonicalTypeUnqualified(); - - // Render Objective-C `id`/`instancetype` as keywords. - if (T->isObjCIdType()) - return Fragments.append(Base.getAsString(), - DeclarationFragments::FragmentKind::Keyword); - // If the type is a typedefed type, get the underlying TypedefNameDecl for a // direct reference to the typedef instead of the wrapped type. + + // 'id' type is a typedef for an ObjCObjectPointerType + // we treat it as a typedef if (const TypedefType *TypedefTy = dyn_cast<TypedefType>(T)) { const TypedefNameDecl *Decl = TypedefTy->getDecl(); TypedefUnderlyingTypeResolver TypedefResolver(Context); std::string USR = TypedefResolver.getUSRForType(QualType(T, 0)); + + if (T->isObjCIdType()) { + return Fragments.append(Decl->getName(), + DeclarationFragments::FragmentKind::Keyword); + } + return Fragments.append( Decl->getName(), DeclarationFragments::FragmentKind::TypeIdentifier, USR, TypedefResolver.getUnderlyingTypeDecl(QualType(T, 0))); } + // Everything we care about has been handled now, reduce to the canonical + // unqualified base type. + QualType Base = T->getCanonicalTypeUnqualified(); + // If the base type is a TagType (struct/interface/union/class/enum), let's // get the underlying Decl for better names and USRs. if (const TagType *TagTy = dyn_cast<TagType>(Base)) { @@ -441,7 +457,7 @@ DeclarationFragmentsBuilder::getFragmentsForFunction(const FunctionDecl *Func) { Fragments.append(")", DeclarationFragments::FragmentKind::Text); // FIXME: Handle exception specifiers: throw, noexcept - return Fragments; + return Fragments.append(";", DeclarationFragments::FragmentKind::Text); } DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForEnumConstant( @@ -470,7 +486,7 @@ DeclarationFragmentsBuilder::getFragmentsForEnum(const EnumDecl *EnumDecl) { getFragmentsForType(IntegerType, EnumDecl->getASTContext(), After)) .append(std::move(After)); - return Fragments; + return Fragments.append(";", DeclarationFragments::FragmentKind::Text); } DeclarationFragments @@ -493,7 +509,8 @@ DeclarationFragmentsBuilder::getFragmentsForStruct(const RecordDecl *Record) { if (!Record->getName().empty()) Fragments.appendSpace().append( Record->getName(), DeclarationFragments::FragmentKind::Identifier); - return Fragments; + + return Fragments.append(";", DeclarationFragments::FragmentKind::Text); } DeclarationFragments @@ -621,7 +638,7 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForObjCProperty( // Build the Objective-C property keyword. Fragments.append("@property", DeclarationFragments::FragmentKind::Keyword); - const auto Attributes = Property->getPropertyAttributes(); + const auto Attributes = Property->getPropertyAttributesAsWritten(); // Build the attributes if there is any associated with the property. if (Attributes != ObjCPropertyAttribute::kind_noattr) { // No leading comma for the first attribute. @@ -743,7 +760,7 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForTypedef( .appendSpace() .append(Decl->getName(), DeclarationFragments::FragmentKind::Identifier); - return Fragments; + return Fragments.append(";", DeclarationFragments::FragmentKind::Text); } template <typename FunctionT> |