17#include "llvm/ADT/StringSwitch.h"
23 if (!Fragments.empty()) {
28 if (
Last.Spelling.back() !=
' ') {
29 Last.Spelling.push_back(
' ');
55 return "typeIdentifier";
57 return "genericParameter";
59 return "externalParam";
61 return "internalParam";
66 llvm_unreachable(
"Unhandled FragmentKind");
71 return llvm::StringSwitch<FragmentKind>(S)
77 .Case(
"typeIdentifier",
79 .Case(
"genericParameter",
120 Fragments.
append(Alias->getName(),
145 Fragments.
append(getFragmentsForType(T, Context, After));
158 assert(T &&
"invalid type");
190 getFragmentsForType(LRT->getPointeeTypeAsWritten(), Context, After))
198 getFragmentsForType(RRT->getPointeeTypeAsWritten(), Context, After))
211 switch (AT->getSizeModifier()) {
228 CAT->getSize().toStringUnsigned(Size);
235 getFragmentsForType(AT->getElementType(), Context, After));
251 Fragments.
append(getFragmentsForNNS(NNS, Context, After));
255 return Fragments.
append(getFragmentsForType(ET->desugar(), Context, After));
263 if (
const TypedefType *TypedefTy = dyn_cast<TypedefType>(T)) {
266 std::string USR = TypedefResolver.getUSRForType(
QualType(T, 0));
275 USR, TypedefResolver.getUnderlyingTypeDecl(
QualType(T, 0)));
284 if (
const TagType *TagTy = dyn_cast<TagType>(
Base)) {
287 if (
Decl->getName().empty())
298 if (
const auto *ObjCIT = dyn_cast<ObjCInterfaceType>(
Base)) {
299 const auto *
Decl = ObjCIT->getDecl();
317DeclarationFragmentsBuilder::getFragmentsForQualifiers(
const Qualifiers Quals) {
331 assert(!QT.
isNull() &&
"invalid type");
333 if (
const ParenType *PT = dyn_cast<ParenType>(QT)) {
335 return getFragmentsForType(PT->getInnerType(), Context, After)
342 getFragmentsForType(SQT.
Ty, Context, After);
344 return TypeFragments;
364 return TypeFragments.appendSpace().append(std::move(QualsFragments));
392 .
append(std::move(After));
396DeclarationFragmentsBuilder::getFragmentsForParam(
const ParmVarDecl *Param) {
409 .
append(std::move(TypeFragments))
417 .
append(std::move(After));
438 llvm_unreachable(
"invalid for functions");
449 .
append(std::move(After));
452 for (
unsigned i = 0, end = Func->
getNumParams(); i != end; ++i) {
483 if (!IntegerType.
isNull())
487 .
append(std::move(After));
495 return getFragmentsForType(Field->getType(), Field->getASTContext(), After)
498 .
append(std::move(After));
509 if (!Record->getName().empty())
526 if (MI->isFunctionLike()) {
528 unsigned numParameters = MI->getNumParams();
529 if (MI->isC99Varargs())
531 for (
unsigned i = 0; i < numParameters; ++i) {
534 Fragments.
append(MI->params()[i]->getName(),
537 if (MI->isVariadic()) {
538 if (numParameters && MI->isC99Varargs())
551 auto *Interface =
Category->getClassInterface();
582 .
append(SuperClass->getName(),
616 for (
unsigned i = 0, end = Method->
param_size(); i != end; ++i) {
628 Fragments.
append(getFragmentsForParam(Param));
641 const auto Attributes =
Property->getPropertyAttributesAsWritten();
648 auto RenderAttribute =
654 if ((Attributes & Kind) && !Spelling.empty()) {
659 Fragments.
append(Spelling,
682 "unsafe_unretained");
686 Property->getGetterName().getAsString());
688 Property->getSetterName().getAsString());
693 if (
const auto Nullability =
699 Fragments.
append(
"null_resettable",
719 .
append(std::move(After));
728 .
append(Protocol->getName(),
732 if (!Protocol->protocols().empty()) {
735 It != Protocol->protocol_end(); It++) {
737 if (It != Protocol->protocol_begin())
742 Fragments.
append((*It)->getName(),
757 .
append(getFragmentsForType(
Decl->getUnderlyingType(),
766template <
typename FunctionT>
773 .
append(getFragmentsForType(Function->getReturnType(),
774 Function->getASTContext(), After))
775 .
append(std::move(After));
778 for (
const auto *Param : Function->parameters())
796 if (!
Decl->getName().empty())
This file defines the Declaration Fragments related classes.
This file defines the UnderlyingTypeResolver which is a helper type for resolving the undelrying type...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
Represents an array type, per C99 6.7.5.2 - Array Declarators.
static std::optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
Represents the canonical version of C arrays with a specified constant size.
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
TypeSourceInfo * getTypeSourceInfo() const
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
An instance of this object exists for each enum constant that is defined.
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Represents a member of a struct/union/class.
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
QualType getReturnType() const
StorageClass getStorageClass() const
Returns the storage class as written in the source.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
StringRef getName() const
Return the actual identifier string.
An lvalue reference type, per C++11 [dcl.ref].
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
const MacroInfo * getMacroInfo() const
This represents a decl that may have a name.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
Represents a C++ namespace alias.
Represent a C++ namespace.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
ObjCCategoryDecl - Represents a category declaration.
Represents an ObjC class declaration.
ObjCInterfaceDecl * getSuperClass() const
ObjCMethodDecl - Represents an instance or class method declaration.
unsigned param_size() const
Selector getSelector() const
bool isInstanceMethod() const
ParmVarDecl * getParamDecl(unsigned Idx)
QualType getReturnType() const
bool isClassMethod() const
Represents a pointer to an Objective C object.
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
bool isObjCIdOrClassType() const
True if this is equivalent to the 'id' or 'Class' type,.
Represents one property declaration in an Objective-C interface.
Represents an Objective-C protocol declaration.
ObjCProtocolList::iterator protocol_iterator
Sugar for parentheses used when specifying types.
Represents a parameter to a function.
bool isObjCMethodParameter() const
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
The collection of all-type qualifiers we support.
An rvalue reference type, per C++11 [dcl.ref].
Represents a struct/union/class.
Smart pointer class that efficiently represents Objective-C method names.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
unsigned getNumArgs() const
Represents the declaration of a struct/union/class/enum.
TypedefNameDecl * getTypedefNameForAnonDecl() const
QualType getType() const
Return the type wrapped by this type source info.
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
The base class of the type hierarchy.
bool isPointerType() const
CanQualType getCanonicalTypeUnqualified() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isObjCIdType() const
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isObjCObjectPointerType() const
bool isAnyPointerType() const
const T * getAs() const
Member-template getAs<specific type>'.
Base class for declarations which introduce a typedef-name.
Represents a variable declaration or definition.
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
@ kind_nullability
Indicates that the nullability of the type was spelled with a property attribute rather than a type q...
@ After
Like System, but searched after the system directories.
bool generateUSRForType(QualType T, ASTContext &Ctx, SmallVectorImpl< char > &Buf)
Generates a USR for a type.
bool generateUSRForDecl(const Decl *D, SmallVectorImpl< char > &Buf)
Generate a USR for a Decl, including the USR prefix.
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
StorageClass
Storage classes.
@ Property
The type of a property.
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
@ ETK_None
No keyword precedes the qualified type name.
YAML serialization mapping.
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
const Type * Ty
The locally-unqualified type.
Qualifiers Quals
The local qualifiers.