21#include "llvm/ADT/StringSwitch.h"
28 if (!Fragments.empty()) {
33 if (
Last.Spelling.back() !=
' ') {
34 Last.Spelling.push_back(
' ');
60 return "typeIdentifier";
62 return "genericParameter";
64 return "externalParam";
66 return "internalParam";
71 llvm_unreachable(
"Unhandled FragmentKind");
76 return llvm::StringSwitch<FragmentKind>(S)
82 .Case(
"typeIdentifier",
84 .Case(
"genericParameter",
95 switch (ExceptionSpec) {
128 llvm_unreachable(
"Unhandled exception specification");
134 if (Record->isStruct())
136 else if (Record->isUnion())
154 Fragments.
append(getFragmentsForNNS(NNS->
getPrefix(), Context, After));
177 Fragments.
append(Alias->getName(),
202 Fragments.
append(getFragmentsForType(T, Context, After));
215 assert(T &&
"invalid type");
247 getFragmentsForType(LRT->getPointeeTypeAsWritten(), Context, After))
255 getFragmentsForType(RRT->getPointeeTypeAsWritten(), Context, After))
268 switch (AT->getSizeModifier()) {
285 CAT->getSize().toStringUnsigned(Size);
292 getFragmentsForType(AT->getElementType(), Context, After));
308 Fragments.
append(getFragmentsForNNS(NNS, Context, After));
312 return Fragments.
append(getFragmentsForType(ET->desugar(), Context, After));
320 if (
const TypedefType *TypedefTy = dyn_cast<TypedefType>(T)) {
323 std::string USR = TypedefResolver.getUSRForType(
QualType(T, 0));
332 USR, TypedefResolver.getUnderlyingTypeDecl(
QualType(T, 0)));
341 if (
const TagType *TagTy = dyn_cast<TagType>(
Base)) {
344 if (
Decl->getName().empty())
355 if (
const auto *ObjCIT = dyn_cast<ObjCInterfaceType>(
Base)) {
356 const auto *
Decl = ObjCIT->getDecl();
374DeclarationFragmentsBuilder::getFragmentsForQualifiers(
const Qualifiers Quals) {
388 assert(!QT.
isNull() &&
"invalid type");
390 if (
const ParenType *PT = dyn_cast<ParenType>(QT)) {
392 return getFragmentsForType(PT->getInnerType(), Context, After)
399 getFragmentsForType(SQT.
Ty, Context, After);
401 TypeFragments.replace(
"bool", 0);
404 return TypeFragments;
424 return TypeFragments.appendSpace().append(std::move(QualsFragments));
433 if (!
Decl->isAnonymousNamespace())
489 if (ArgumentFragment.
begin()->Spelling.substr(0, 14).compare(
490 "type-parameter") == 0) {
493 ArgumentFragment.
begin()->Spelling);
494 ArgumentFragment.
begin()->Spelling.swap(ProperArgName);
496 Fragments.
append(std::move(ArgumentFragment))
504DeclarationFragmentsBuilder::getFragmentsForParam(
const ParmVarDecl *Param) {
514 if (TypeFragments.
begin()->Spelling.substr(0, 14).compare(
"type-parameter") ==
518 ->getDescribedFunctionTemplate()
519 ->getTemplateParameters()
521 TypeFragments.
begin()->Spelling);
522 TypeFragments.
begin()->Spelling.swap(ProperArgName);
527 .
append(std::move(TypeFragments))
535 .
append(std::move(After));
556 llvm_unreachable(
"invalid for functions");
567 auto ReturnValueFragment =
569 if (ReturnValueFragment.begin()->Spelling.substr(0, 14).compare(
570 "type-parameter") == 0) {
571 std::string ProperArgName =
575 ReturnValueFragment.begin()->Spelling);
576 ReturnValueFragment.begin()->Spelling.swap(ProperArgName);
579 Fragments.
append(std::move(ReturnValueFragment))
586 for (
unsigned i = 0, end = Func->
getNumParams(); i != end; ++i) {
595 Fragments.
append(std::move(After));
598 for (
unsigned i = 0, end = Func->
getNumParams(); i != end; ++i) {
631 if (!IntegerType.
isNull())
635 .
append(std::move(After));
644 if (Field->isMutable())
649 getFragmentsForType(Field->getType(), Field->getASTContext(), After))
664 if (!Record->getName().empty())
679 if (!Record->getName().empty())
691 if (
const auto *Constructor = dyn_cast<CXXConstructorDecl>(Method)) {
693 if (Constructor->isExplicit())
696 }
else if (isa<CXXDestructorDecl>(Method))
701 .
append(std::move(After));
703 for (
unsigned i = 0, end = Method->
getNumParams(); i != end; ++i) {
719 StringRef Name = Method->
getName();
737 .
append(std::move(After));
739 for (
unsigned i = 0, end = Method->
getNumParams(); i != end; ++i) {
761 if (ConversionFunction->isExplicit())
769 .
append(ConversionFunction->getConversionType().getAsString(),
772 for (
unsigned i = 0, end = ConversionFunction->getNumParams(); i != end;
776 Fragments.
append(getFragmentsForParam(ConversionFunction->getParamDecl(i)));
780 if (ConversionFunction->isConst())
800 .
append(std::move(After));
802 for (
unsigned i = 0, end = Method->
getNumParams(); i != end; ++i) {
824 for (
unsigned i = 0, end = ParameterArray.size(); i != end; ++i) {
830 dyn_cast<TemplateTypeParmDecl>(ParameterArray[i]);
862 for (
unsigned i = 0; i < TemplateParameters.size(); ++i) {
864 dyn_cast<TemplateTypeParmDecl>(TemplateParameters[i]);
865 if (TypeParameter.compare(
"type-parameter-" +
866 std::to_string(
Parameter->getDepth()) +
"-" +
867 std::to_string(
Parameter->getIndex())) == 0)
868 return std::string(TemplateParameters[i]->
getName());
870 llvm_unreachable(
"Could not find the name of a template argument.");
884 for (
unsigned i = 0, end = TemplateArguments.size(); i != end; ++i) {
889 std::string
Type = TemplateArguments[i].getAsType().getAsString();
892 getFragmentsForType(TemplateArguments[i].getAsType(), Context, After);
894 if (ArgumentFragment.
begin()->Spelling.substr(0, 14).compare(
895 "type-parameter") == 0) {
897 TemplateParameters.value(), ArgumentFragment.
begin()->Spelling);
898 ArgumentFragment.
begin()->Spelling.swap(ProperArgName);
900 Fragments.
append(std::move(ArgumentFragment));
902 if (TemplateArguments[i].isPackExpansion())
915 Concept->getTemplateParameters()->asArray()))
919 .
append(Concept->getName().str(),
935 if (isa<TypeAliasTemplateDecl>(RedeclarableTemplate))
955 cast<CXXRecordDecl>(
Decl)))
973 Decl->getTemplateParameters()->asArray()))
977 cast<CXXRecordDecl>(
Decl)))
982 Decl->getTemplateParameters()->asArray()))
1015 Decl->getTemplateParameters()->asArray()))
1023 Decl->getTemplateParameters()->asArray()))
1037 Decl->getTemplateParameters()->asArray()))
1065 if (MI->isFunctionLike()) {
1067 unsigned numParameters = MI->getNumParams();
1068 if (MI->isC99Varargs())
1070 for (
unsigned i = 0; i < numParameters; ++i) {
1073 Fragments.
append(MI->params()[i]->getName(),
1076 if (MI->isVariadic()) {
1077 if (numParameters && MI->isC99Varargs())
1090 auto *Interface =
Category->getClassInterface();
1121 .
append(SuperClass->getName(),
1142 .
append(std::move(After))
1155 for (
unsigned i = 0, end = Method->
param_size(); i != end; ++i) {
1161 ParamID.append(
":");
1167 Fragments.
append(getFragmentsForParam(Param));
1180 const auto Attributes =
Property->getPropertyAttributesAsWritten();
1187 auto RenderAttribute =
1193 if ((Attributes & Kind) && !Spelling.empty()) {
1198 Fragments.
append(Spelling,
1221 "unsafe_unretained");
1225 Property->getGetterName().getAsString());
1227 Property->getSetterName().getAsString());
1232 if (
const auto Nullability =
1238 Fragments.
append(
"null_resettable",
1258 .
append(std::move(After));
1267 .
append(Protocol->getName(),
1271 if (!Protocol->protocols().empty()) {
1274 It != Protocol->protocol_end(); It++) {
1276 if (It != Protocol->protocol_begin())
1281 Fragments.
append((*It)->getName(),
1296 .
append(getFragmentsForType(
Decl->getUnderlyingType(),
1298 .
append(std::move(After))
1317 if (isa<CXXConstructorDecl>(
Decl) || isa<CXXDestructorDecl>(
Decl))
1320 else if (isa<CXXConversionDecl>(
Decl)) {
1324 }
else if (isa<CXXMethodDecl>(
Decl) &&
1325 cast<CXXMethodDecl>(
Decl)->isOverloadedOperator()) {
1328 }
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.
Defines an enumeration for C++ overloaded operators.
static std::string getName(const CallEvent &Call)
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 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.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
QualType getReturnType() const
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
StorageClass getStorageClass() const
Returns the storage class as written in the source.
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.
Declaration of a template function.
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.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
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()
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.
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...
@ ETK_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.