23#include "llvm/ADT/StringSwitch.h"
46 TL = AttrTL.getModifiedLoc();
64 if (!Fragments.empty()) {
69 if (
Last.Spelling.back() !=
' ') {
70 Last.Spelling.push_back(
' ');
96 return "typeIdentifier";
98 return "genericParameter";
100 return "externalParam";
102 return "internalParam";
107 llvm_unreachable(
"Unhandled FragmentKind");
112 return llvm::StringSwitch<FragmentKind>(S)
118 .Case(
"typeIdentifier",
120 .Case(
"genericParameter",
131 switch (ExceptionSpec) {
164 llvm_unreachable(
"Unhandled exception specification");
172 else if (
Record->isUnion())
190 Fragments.
append(getFragmentsForNNS(NNS->
getPrefix(), Context, After));
213 Fragments.
append(Alias->getName(),
238 Fragments.
append(getFragmentsForType(T, Context, After));
251 assert(T &&
"invalid type");
268 Fragments.
append(getFragmentsForNNS(NNS, Context, After));
272 return Fragments.
append(getFragmentsForType(ET->desugar(), Context, After));
280 if (
const TypedefType *TypedefTy = dyn_cast<TypedefType>(T)) {
283 std::string USR = TypedefResolver.getUSRForType(
QualType(T, 0));
292 USR, TypedefResolver.getUnderlyingTypeDecl(
QualType(T, 0)));
323 getFragmentsForType(LRT->getPointeeTypeAsWritten(), Context, After))
331 getFragmentsForType(RRT->getPointeeTypeAsWritten(), Context, After))
344 switch (AT->getSizeModifier()) {
361 CAT->getSize().toStringUnsigned(Size);
368 getFragmentsForType(AT->getElementType(), Context, After));
377 if (
const TagType *TagTy = dyn_cast<TagType>(
Base)) {
380 if (
Decl->getName().empty())
391 if (
const auto *ObjCIT = dyn_cast<ObjCInterfaceType>(
Base)) {
392 const auto *
Decl = ObjCIT->getDecl();
410DeclarationFragmentsBuilder::getFragmentsForQualifiers(
const Qualifiers Quals) {
424 assert(!QT.
isNull() &&
"invalid type");
426 if (
const ParenType *PT = dyn_cast<ParenType>(QT)) {
428 return getFragmentsForType(PT->getInnerType(), Context, After)
435 getFragmentsForType(SQT.
Ty, Context, After);
437 TypeFragments.replace(
"bool", 0);
440 return TypeFragments;
460 return TypeFragments.appendSpace().append(std::move(QualsFragments));
469 if (!
Decl->isAnonymousNamespace())
508 Fragments.
append(getFragmentsForBlock(Var, BlockLoc, BlockProtoLoc, After));
536 if (StringRef(ArgumentFragment.
begin()->Spelling)
537 .starts_with(
"type-parameter")) {
540 ArgumentFragment.
begin()->Spelling);
541 ArgumentFragment.
begin()->Spelling.swap(ProperArgName);
543 Fragments.
append(std::move(ArgumentFragment))
551DeclarationFragmentsBuilder::getFragmentsForParam(
const ParmVarDecl *Param) {
562 findTypeLocForBlockDecl(TSInfo, BlockLoc, BlockProtoLoc);
567 getFragmentsForBlock(Param, BlockLoc, BlockProtoLoc, After));
571 if (StringRef(TypeFragments.
begin()->Spelling)
572 .starts_with(
"type-parameter")) {
575 ->getDescribedFunctionTemplate()
576 ->getTemplateParameters()
578 TypeFragments.
begin()->Spelling);
579 TypeFragments.
begin()->Spelling.swap(ProperArgName);
584 .
append(std::move(TypeFragments))
590 Fragments.
append(std::move(TypeFragments));
596 .
append(std::move(After));
607 auto ReturnValueFragment = getFragmentsForType(
610 Fragments.
append(std::move(ReturnValueFragment))
611 .
append(std::move(RetTyAfter))
616 unsigned NumParams =
Block.getNumParams();
618 if (!BlockProto || NumParams == 0) {
625 for (
unsigned I = 0; I != NumParams; ++I) {
628 After.append(getFragmentsForParam(
Block.getParam(I)));
642 switch (
Func->getStorageClass()) {
656 llvm_unreachable(
"invalid for functions");
658 if (
Func->isConsteval())
661 else if (
Func->isConstexpr())
667 auto ReturnValueFragment =
668 getFragmentsForType(
Func->getReturnType(),
Func->getASTContext(), After);
669 if (StringRef(ReturnValueFragment.begin()->Spelling)
670 .starts_with(
"type-parameter")) {
671 std::string ProperArgName =
673 ->getTemplateParameters()
675 ReturnValueFragment.begin()->Spelling);
676 ReturnValueFragment.begin()->Spelling.swap(ProperArgName);
679 Fragments.
append(std::move(ReturnValueFragment))
683 if (
Func->getTemplateSpecializationInfo()) {
686 for (
unsigned i = 0, end =
Func->getNumParams(); i != end; ++i) {
690 getFragmentsForType(
Func->getParamDecl(i)->getType(),
691 Func->getParamDecl(i)->getASTContext(), After));
695 Fragments.
append(std::move(After));
698 unsigned NumParams =
Func->getNumParams();
699 for (
unsigned i = 0; i != NumParams; ++i) {
702 Fragments.
append(getFragmentsForParam(
Func->getParamDecl(i)));
705 if (
Func->isVariadic()) {
713 Func->getExceptionSpecType()));
738 if (!IntegerType.
isNull())
742 .
append(std::move(After));
751 if (Field->isMutable())
756 getFragmentsForType(Field->getType(), Field->getASTContext(), After))
774 if (!
Record->getName().empty())
789 if (!
Record->getName().empty())
801 if (
const auto *Constructor = dyn_cast<CXXConstructorDecl>(Method)) {
803 if (Constructor->isExplicit())
806 }
else if (isa<CXXDestructorDecl>(Method))
811 .
append(std::move(After));
813 for (
unsigned i = 0, end = Method->
getNumParams(); i != end; ++i) {
829 StringRef Name = Method->
getName();
847 .
append(std::move(After));
849 for (
unsigned i = 0, end = Method->
getNumParams(); i != end; ++i) {
871 if (ConversionFunction->isExplicit())
879 .
append(ConversionFunction->getConversionType().getAsString(),
882 for (
unsigned i = 0, end = ConversionFunction->getNumParams(); i != end;
886 Fragments.
append(getFragmentsForParam(ConversionFunction->getParamDecl(i)));
890 if (ConversionFunction->isConst())
910 .
append(std::move(After));
912 for (
unsigned i = 0, end = Method->
getNumParams(); i != end; ++i) {
934 for (
unsigned i = 0, end = ParameterArray.size(); i != end; ++i) {
940 dyn_cast<TemplateTypeParmDecl>(ParameterArray[i]);
972 for (
unsigned i = 0; i < TemplateParameters.size(); ++i) {
974 dyn_cast<TemplateTypeParmDecl>(TemplateParameters[i]);
975 if (TypeParameter.compare(
"type-parameter-" +
976 std::to_string(
Parameter->getDepth()) +
"-" +
977 std::to_string(
Parameter->getIndex())) == 0)
978 return std::string(TemplateParameters[i]->
getName());
980 llvm_unreachable(
"Could not find the name of a template argument.");
994 for (
unsigned i = 0, end = TemplateArguments.size(); i != end; ++i) {
999 std::string
Type = TemplateArguments[i].getAsType().getAsString();
1002 getFragmentsForType(TemplateArguments[i].getAsType(), Context, After);
1004 if (StringRef(ArgumentFragment.
begin()->Spelling)
1005 .starts_with(
"type-parameter")) {
1007 TemplateParameters.value(), ArgumentFragment.
begin()->Spelling);
1008 ArgumentFragment.
begin()->Spelling.swap(ProperArgName);
1010 Fragments.
append(std::move(ArgumentFragment));
1012 if (TemplateArguments[i].isPackExpansion())
1025 Concept->getTemplateParameters()->asArray()))
1029 .
append(Concept->getName().str(),
1045 if (isa<TypeAliasTemplateDecl>(RedeclarableTemplate))
1065 cast<CXXRecordDecl>(
Decl)))
1083 Decl->getTemplateParameters()->asArray()))
1087 cast<CXXRecordDecl>(
Decl)))
1092 Decl->getTemplateParameters()->asArray()))
1125 Decl->getTemplateParameters()->asArray()))
1133 Decl->getTemplateParameters()->asArray()))
1147 Decl->getTemplateParameters()->asArray()))
1175 if (MI->isFunctionLike()) {
1177 unsigned numParameters = MI->getNumParams();
1178 if (MI->isC99Varargs())
1180 for (
unsigned i = 0; i < numParameters; ++i) {
1183 Fragments.
append(MI->params()[i]->getName(),
1186 if (MI->isVariadic()) {
1187 if (numParameters && MI->isC99Varargs())
1231 .
append(SuperClass->getName(),
1252 .
append(std::move(After))
1265 for (
unsigned i = 0, end = Method->
param_size(); i != end; ++i) {
1271 ParamID.append(
":");
1277 Fragments.
append(getFragmentsForParam(Param));
1290 const auto Attributes =
Property->getPropertyAttributesAsWritten();
1297 auto RenderAttribute =
1303 if ((Attributes & Kind) && !Spelling.empty()) {
1308 Fragments.
append(Spelling,
1331 "unsafe_unretained");
1335 Property->getGetterName().getAsString());
1337 Property->getSetterName().getAsString());
1342 if (
const auto Nullability =
1348 Fragments.
append(
"null_resettable",
1365 findTypeLocForBlockDecl(
Property->getTypeSourceInfo(), BlockLoc,
1368 auto PropType =
Property->getType();
1371 .
append(getFragmentsForType(PropType,
Property->getASTContext(), After))
1375 getFragmentsForBlock(
Property, BlockLoc, BlockProtoLoc, After));
1380 .
append(std::move(After))
1390 .
append(Protocol->getName(),
1394 if (!Protocol->protocols().empty()) {
1397 It != Protocol->protocol_end(); It++) {
1399 if (It != Protocol->protocol_begin())
1404 Fragments.
append((*It)->getName(),
1419 .
append(getFragmentsForType(
Decl->getUnderlyingType(),
1421 .
append(std::move(After))
1440 if (isa<CXXConstructorDecl>(
Decl) || isa<CXXDestructorDecl>(
Decl))
1443 else if (isa<CXXConversionDecl>(
Decl)) {
1447 }
else if (isa<CXXMethodDecl>(
Decl) &&
1448 cast<CXXMethodDecl>(
Decl)->isOverloadedOperator()) {
1451 }
else if (!
Decl->getName().empty())
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines the Declaration Fragments related classes.
llvm::MachO::Record Record
Defines an enumeration for C++ overloaded operators.
static std::string getName(const CallEvent &Call)
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
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.
Type source information for an attributed type.
static std::optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Wrapper for source info for block pointers.
Represents a C++ conversion function within a class.
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
Represents a class template specialization, which refers to a class template with a given set of temp...
Declaration of a C++20 concept.
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
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
DeclContext * getDeclContext()
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
ExceptionSpecificationType getExceptionSpecType() const
Gets the ExceptionSpecificationType as declared.
QualType getReturnType() const
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
bool isVariadic() const
Whether this function prototype is variadic.
Declaration of a template function.
Wrapper for source info for functions.
StringRef getName() const
Return the actual identifier string.
const TypeClass * getTypePtr() const
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.
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.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Wrapper of type source information for a type with non-trivial direct qualifiers.
The collection of all-type qualifiers we support.
An rvalue reference type, per C++11 [dcl.ref].
Represents a struct/union/class.
Declaration of a redeclarable template.
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
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
ArrayRef< NamedDecl * > asArray()
Base wrapper for a particular "section" of type source info.
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
TypeLoc IgnoreParens() const
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
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 isBlockPointerType() const
bool isFunctionPointerType() const
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.
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
bool isStaticDataMember() const
Determines whether this is a static data member.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Represents a variable template specialization, which refers to a variable template with a given set o...
@ 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.
@ Parameter
The parameter type of a method or function.
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
llvm::StringRef getAsString(SyncScope S)
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
@ None
No keyword precedes the qualified type name.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_DependentNoexcept
noexcept(expression), value-dependent
@ EST_None
no exception specification
@ EST_BasicNoexcept
noexcept
@ EST_NoexceptFalse
noexcept(expression), evals to 'false'
@ EST_NoexceptTrue
noexcept(expression), evals to 'true'
@ EST_Dynamic
throw(T1, T2)
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.