clang 17.0.0git
DeclarationFragments.cpp
Go to the documentation of this file.
1//===- ExtractAPI/DeclarationFragments.cpp ----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file implements Declaration Fragments related classes.
11///
12//===----------------------------------------------------------------------===//
13
17#include "llvm/ADT/StringSwitch.h"
18
19using namespace clang::extractapi;
20using namespace llvm;
21
23 if (!Fragments.empty()) {
24 Fragment &Last = Fragments.back();
25 if (Last.Kind == FragmentKind::Text) {
26 // Merge the extra space into the last fragment if the last fragment is
27 // also text.
28 if (Last.Spelling.back() != ' ') { // avoid extra trailing spaces.
29 Last.Spelling.push_back(' ');
30 }
31 } else {
33 }
34 }
35
36 return *this;
37}
38
41 switch (Kind) {
43 return "none";
45 return "keyword";
47 return "attribute";
49 return "number";
51 return "string";
53 return "identifier";
55 return "typeIdentifier";
57 return "genericParameter";
59 return "externalParam";
61 return "internalParam";
63 return "text";
64 }
65
66 llvm_unreachable("Unhandled FragmentKind");
67}
68
71 return llvm::StringSwitch<FragmentKind>(S)
77 .Case("typeIdentifier",
79 .Case("genericParameter",
85}
86
87// NNS stores C++ nested name specifiers, which are prefixes to qualified names.
88// Build declaration fragments for NNS recursively so that we have the USR for
89// every part in a qualified name, and also leaves the actual underlying type
90// cleaner for its own fragment.
92DeclarationFragmentsBuilder::getFragmentsForNNS(const NestedNameSpecifier *NNS,
93 ASTContext &Context,
94 DeclarationFragments &After) {
95 DeclarationFragments Fragments;
96 if (NNS->getPrefix())
97 Fragments.append(getFragmentsForNNS(NNS->getPrefix(), Context, After));
98
99 switch (NNS->getKind()) {
101 Fragments.append(NNS->getAsIdentifier()->getName(),
103 break;
104
106 const NamespaceDecl *NS = NNS->getAsNamespace();
107 if (NS->isAnonymousNamespace())
108 return Fragments;
111 Fragments.append(NS->getName(),
113 break;
114 }
115
117 const NamespaceAliasDecl *Alias = NNS->getAsNamespaceAlias();
119 index::generateUSRForDecl(Alias, USR);
120 Fragments.append(Alias->getName(),
122 Alias);
123 break;
124 }
125
127 // The global specifier `::` at the beginning. No stored value.
128 break;
129
131 // Microsoft's `__super` specifier.
133 break;
134
136 // A type prefixed by the `template` keyword.
138 Fragments.appendSpace();
139 // Fallthrough after adding the keyword to handle the actual type.
140 [[fallthrough]];
141
143 const Type *T = NNS->getAsType();
144 // FIXME: Handle C++ template specialization type
145 Fragments.append(getFragmentsForType(T, Context, After));
146 break;
147 }
148 }
149
150 // Add the separator text `::` for this segment.
151 return Fragments.append("::", DeclarationFragments::FragmentKind::Text);
152}
153
154// Recursively build the declaration fragments for an underlying `Type` with
155// qualifiers removed.
156DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
157 const Type *T, ASTContext &Context, DeclarationFragments &After) {
158 assert(T && "invalid type");
159
160 DeclarationFragments Fragments;
161
162 // Declaration fragments of a pointer type is the declaration fragments of
163 // the pointee type followed by a `*`,
164 if (T->isPointerType())
165 return Fragments
166 .append(getFragmentsForType(T->getPointeeType(), Context, After))
168
169 // For Objective-C `id` and `Class` pointers
170 // we do not spell out the `*`.
171 if (T->isObjCObjectPointerType() &&
173
174 Fragments.append(getFragmentsForType(T->getPointeeType(), Context, After));
175
176 // id<protocol> is an qualified id type
177 // id<protocol>* is not an qualified id type
180 }
181
182 return Fragments;
183 }
184
185 // Declaration fragments of a lvalue reference type is the declaration
186 // fragments of the underlying type followed by a `&`.
187 if (const LValueReferenceType *LRT = dyn_cast<LValueReferenceType>(T))
188 return Fragments
189 .append(
190 getFragmentsForType(LRT->getPointeeTypeAsWritten(), Context, After))
192
193 // Declaration fragments of a rvalue reference type is the declaration
194 // fragments of the underlying type followed by a `&&`.
195 if (const RValueReferenceType *RRT = dyn_cast<RValueReferenceType>(T))
196 return Fragments
197 .append(
198 getFragmentsForType(RRT->getPointeeTypeAsWritten(), Context, After))
200
201 // Declaration fragments of an array-typed variable have two parts:
202 // 1. the element type of the array that appears before the variable name;
203 // 2. array brackets `[(0-9)?]` that appear after the variable name.
204 if (const ArrayType *AT = T->getAsArrayTypeUnsafe()) {
205 // Build the "after" part first because the inner element type might also
206 // be an array-type. For example `int matrix[3][4]` which has a type of
207 // "(array 3 of (array 4 of ints))."
208 // Push the array size part first to make sure they are in the right order.
210
211 switch (AT->getSizeModifier()) {
213 break;
216 break;
217 case ArrayType::Star:
219 break;
220 }
221
222 if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) {
223 // FIXME: right now this would evaluate any expressions/macros written in
224 // the original source to concrete values. For example
225 // `int nums[MAX]` -> `int nums[100]`
226 // `char *str[5 + 1]` -> `char *str[6]`
228 CAT->getSize().toStringUnsigned(Size);
230 }
231
233
234 return Fragments.append(
235 getFragmentsForType(AT->getElementType(), Context, After));
236 }
237
238 // An ElaboratedType is a sugar for types that are referred to using an
239 // elaborated keyword, e.g., `struct S`, `enum E`, or (in C++) via a
240 // qualified name, e.g., `N::M::type`, or both.
241 if (const ElaboratedType *ET = dyn_cast<ElaboratedType>(T)) {
242 ElaboratedTypeKeyword Keyword = ET->getKeyword();
243 if (Keyword != ETK_None) {
244 Fragments
247 .appendSpace();
248 }
249
250 if (const NestedNameSpecifier *NNS = ET->getQualifier())
251 Fragments.append(getFragmentsForNNS(NNS, Context, After));
252
253 // After handling the elaborated keyword or qualified name, build
254 // declaration fragments for the desugared underlying type.
255 return Fragments.append(getFragmentsForType(ET->desugar(), Context, After));
256 }
257
258 // If the type is a typedefed type, get the underlying TypedefNameDecl for a
259 // direct reference to the typedef instead of the wrapped type.
260
261 // 'id' type is a typedef for an ObjCObjectPointerType
262 // we treat it as a typedef
263 if (const TypedefType *TypedefTy = dyn_cast<TypedefType>(T)) {
264 const TypedefNameDecl *Decl = TypedefTy->getDecl();
265 TypedefUnderlyingTypeResolver TypedefResolver(Context);
266 std::string USR = TypedefResolver.getUSRForType(QualType(T, 0));
267
268 if (T->isObjCIdType()) {
269 return Fragments.append(Decl->getName(),
271 }
272
273 return Fragments.append(
275 USR, TypedefResolver.getUnderlyingTypeDecl(QualType(T, 0)));
276 }
277
278 // Everything we care about has been handled now, reduce to the canonical
279 // unqualified base type.
281
282 // If the base type is a TagType (struct/interface/union/class/enum), let's
283 // get the underlying Decl for better names and USRs.
284 if (const TagType *TagTy = dyn_cast<TagType>(Base)) {
285 const TagDecl *Decl = TagTy->getDecl();
286 // Anonymous decl, skip this fragment.
287 if (Decl->getName().empty())
288 return Fragments;
289 SmallString<128> TagUSR;
291 return Fragments.append(Decl->getName(),
293 TagUSR, Decl);
294 }
295
296 // If the base type is an ObjCInterfaceType, use the underlying
297 // ObjCInterfaceDecl for the true USR.
298 if (const auto *ObjCIT = dyn_cast<ObjCInterfaceType>(Base)) {
299 const auto *Decl = ObjCIT->getDecl();
302 return Fragments.append(Decl->getName(),
304 USR, Decl);
305 }
306
307 // Default fragment builder for other kinds of types (BuiltinType etc.)
310 Fragments.append(Base.getAsString(),
312
313 return Fragments;
314}
315
317DeclarationFragmentsBuilder::getFragmentsForQualifiers(const Qualifiers Quals) {
318 DeclarationFragments Fragments;
319 if (Quals.hasConst())
321 if (Quals.hasVolatile())
323 if (Quals.hasRestrict())
325
326 return Fragments;
327}
328
329DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
330 const QualType QT, ASTContext &Context, DeclarationFragments &After) {
331 assert(!QT.isNull() && "invalid type");
332
333 if (const ParenType *PT = dyn_cast<ParenType>(QT)) {
335 return getFragmentsForType(PT->getInnerType(), Context, After)
337 }
338
339 const SplitQualType SQT = QT.split();
340 DeclarationFragments QualsFragments = getFragmentsForQualifiers(SQT.Quals),
341 TypeFragments =
342 getFragmentsForType(SQT.Ty, Context, After);
343 if (QualsFragments.getFragments().empty())
344 return TypeFragments;
345
346 // Use east qualifier for pointer types
347 // For example:
348 // ```
349 // int * const
350 // ^---- ^----
351 // type qualifier
352 // ^-----------------
353 // const pointer to int
354 // ```
355 // should not be reconstructed as
356 // ```
357 // const int *
358 // ^---- ^--
359 // qualifier type
360 // ^---------------- ^
361 // pointer to const int
362 // ```
363 if (SQT.Ty->isAnyPointerType())
364 return TypeFragments.appendSpace().append(std::move(QualsFragments));
365
366 return QualsFragments.appendSpace().append(std::move(TypeFragments));
367}
368
371 DeclarationFragments Fragments;
372 StorageClass SC = Var->getStorageClass();
373 if (SC != SC_None)
374 Fragments
377 .appendSpace();
378 QualType T =
379 Var->getTypeSourceInfo()
380 ? Var->getTypeSourceInfo()->getType()
382
383 // Capture potential fragments that needs to be placed after the variable name
384 // ```
385 // int nums[5];
386 // char (*ptr_to_array)[6];
387 // ```
389 return Fragments.append(getFragmentsForType(T, Var->getASTContext(), After))
390 .appendSpace()
392 .append(std::move(After));
393}
394
396DeclarationFragmentsBuilder::getFragmentsForParam(const ParmVarDecl *Param) {
397 DeclarationFragments Fragments, After;
398
399 QualType T = Param->getTypeSourceInfo()
400 ? Param->getTypeSourceInfo()->getType()
402 Param->getType());
403
404 DeclarationFragments TypeFragments =
405 getFragmentsForType(T, Param->getASTContext(), After);
406
407 if (Param->isObjCMethodParameter())
409 .append(std::move(TypeFragments))
411 else
412 Fragments.append(std::move(TypeFragments)).appendSpace();
413
414 return Fragments
415 .append(Param->getName(),
417 .append(std::move(After));
418}
419
422 DeclarationFragments Fragments;
423 // FIXME: Handle template specialization
424 switch (Func->getStorageClass()) {
425 case SC_None:
426 case SC_PrivateExtern:
427 break;
428 case SC_Extern:
430 .appendSpace();
431 break;
432 case SC_Static:
434 .appendSpace();
435 break;
436 case SC_Auto:
437 case SC_Register:
438 llvm_unreachable("invalid for functions");
439 }
440 // FIXME: Handle C++ function specifiers: constexpr, consteval, explicit, etc.
441
442 // FIXME: Is `after` actually needed here?
444 Fragments
445 .append(getFragmentsForType(Func->getReturnType(), Func->getASTContext(),
446 After))
447 .appendSpace()
449 .append(std::move(After));
450
452 for (unsigned i = 0, end = Func->getNumParams(); i != end; ++i) {
453 if (i)
455 Fragments.append(getFragmentsForParam(Func->getParamDecl(i)));
456 }
458
459 // FIXME: Handle exception specifiers: throw, noexcept
461}
462
464 const EnumConstantDecl *EnumConstDecl) {
465 DeclarationFragments Fragments;
466 return Fragments.append(EnumConstDecl->getName(),
468}
469
474
475 DeclarationFragments Fragments, After;
477
478 if (!EnumDecl->getName().empty())
479 Fragments.appendSpace().append(
481
482 QualType IntegerType = EnumDecl->getIntegerType();
483 if (!IntegerType.isNull())
485 .append(
486 getFragmentsForType(IntegerType, EnumDecl->getASTContext(), After))
487 .append(std::move(After));
488
490}
491
495 return getFragmentsForType(Field->getType(), Field->getASTContext(), After)
496 .appendSpace()
498 .append(std::move(After));
499}
500
503 if (const auto *TypedefNameDecl = Record->getTypedefNameForAnonDecl())
505
506 DeclarationFragments Fragments;
508
509 if (!Record->getName().empty())
510 Fragments.appendSpace().append(
512
514}
515
518 const MacroDirective *MD) {
519 DeclarationFragments Fragments;
521 .appendSpace();
523
524 auto *MI = MD->getMacroInfo();
525
526 if (MI->isFunctionLike()) {
528 unsigned numParameters = MI->getNumParams();
529 if (MI->isC99Varargs())
530 --numParameters;
531 for (unsigned i = 0; i < numParameters; ++i) {
532 if (i)
534 Fragments.append(MI->params()[i]->getName(),
536 }
537 if (MI->isVariadic()) {
538 if (numParameters && MI->isC99Varargs())
541 }
543 }
544 return Fragments;
545}
546
548 const ObjCCategoryDecl *Category) {
549 DeclarationFragments Fragments;
550
551 auto *Interface = Category->getClassInterface();
552 SmallString<128> InterfaceUSR;
553 index::generateUSRForDecl(Interface, InterfaceUSR);
554
556 .appendSpace()
557 .append(Category->getClassInterface()->getName(),
559 Interface)
561 .append(Category->getName(),
564
565 return Fragments;
566}
567
569 const ObjCInterfaceDecl *Interface) {
570 DeclarationFragments Fragments;
571 // Build the base of the Objective-C interface declaration.
573 .appendSpace()
574 .append(Interface->getName(),
576
577 // Build the inheritance part of the declaration.
578 if (const ObjCInterfaceDecl *SuperClass = Interface->getSuperClass()) {
579 SmallString<128> SuperUSR;
580 index::generateUSRForDecl(SuperClass, SuperUSR);
582 .append(SuperClass->getName(),
584 SuperClass);
585 }
586
587 return Fragments;
588}
589
591 const ObjCMethodDecl *Method) {
592 DeclarationFragments Fragments, After;
593 // Build the instance/class method indicator.
594 if (Method->isClassMethod())
596 else if (Method->isInstanceMethod())
598
599 // Build the return type.
601 .append(getFragmentsForType(Method->getReturnType(),
602 Method->getASTContext(), After))
603 .append(std::move(After))
605
606 // Build the selector part.
607 Selector Selector = Method->getSelector();
608 if (Selector.getNumArgs() == 0)
609 // For Objective-C methods that don't take arguments, the first (and only)
610 // slot of the selector is the method name.
611 Fragments.appendSpace().append(
614
615 // For Objective-C methods that take arguments, build the selector slots.
616 for (unsigned i = 0, end = Method->param_size(); i != end; ++i) {
617 // Objective-C method selector parts are considered as identifiers instead
618 // of "external parameters" as in Swift. This is because Objective-C method
619 // symbols are referenced with the entire selector, instead of just the
620 // method name in Swift.
622 ParamID.append(":");
623 Fragments.appendSpace().append(
625
626 // Build the internal parameter.
627 const ParmVarDecl *Param = Method->getParamDecl(i);
628 Fragments.append(getFragmentsForParam(Param));
629 }
630
632}
633
635 const ObjCPropertyDecl *Property) {
636 DeclarationFragments Fragments, After;
637
638 // Build the Objective-C property keyword.
640
641 const auto Attributes = Property->getPropertyAttributesAsWritten();
642 // Build the attributes if there is any associated with the property.
643 if (Attributes != ObjCPropertyAttribute::kind_noattr) {
644 // No leading comma for the first attribute.
645 bool First = true;
647 // Helper function to render the attribute.
648 auto RenderAttribute =
649 [&](ObjCPropertyAttribute::Kind Kind, StringRef Spelling,
650 StringRef Arg = "",
653 // Check if the `Kind` attribute is set for this property.
654 if ((Attributes & Kind) && !Spelling.empty()) {
655 // Add a leading comma if this is not the first attribute rendered.
656 if (!First)
658 // Render the spelling of this attribute `Kind` as a keyword.
659 Fragments.append(Spelling,
661 // If this attribute takes in arguments (e.g. `getter=getterName`),
662 // render the arguments.
663 if (!Arg.empty())
665 .append(Arg, ArgKind);
666 First = false;
667 }
668 };
669
670 // Go through all possible Objective-C property attributes and render set
671 // ones.
672 RenderAttribute(ObjCPropertyAttribute::kind_class, "class");
673 RenderAttribute(ObjCPropertyAttribute::kind_direct, "direct");
674 RenderAttribute(ObjCPropertyAttribute::kind_nonatomic, "nonatomic");
675 RenderAttribute(ObjCPropertyAttribute::kind_atomic, "atomic");
676 RenderAttribute(ObjCPropertyAttribute::kind_assign, "assign");
677 RenderAttribute(ObjCPropertyAttribute::kind_retain, "retain");
678 RenderAttribute(ObjCPropertyAttribute::kind_strong, "strong");
679 RenderAttribute(ObjCPropertyAttribute::kind_copy, "copy");
680 RenderAttribute(ObjCPropertyAttribute::kind_weak, "weak");
682 "unsafe_unretained");
683 RenderAttribute(ObjCPropertyAttribute::kind_readwrite, "readwrite");
684 RenderAttribute(ObjCPropertyAttribute::kind_readonly, "readonly");
685 RenderAttribute(ObjCPropertyAttribute::kind_getter, "getter",
686 Property->getGetterName().getAsString());
687 RenderAttribute(ObjCPropertyAttribute::kind_setter, "setter",
688 Property->getSetterName().getAsString());
689
690 // Render nullability attributes.
692 QualType Type = Property->getType();
693 if (const auto Nullability =
695 if (!First)
697 if (*Nullability == NullabilityKind::Unspecified &&
699 Fragments.append("null_resettable",
701 else
702 Fragments.append(
703 getNullabilitySpelling(*Nullability, /*isContextSensitive=*/true),
705 First = false;
706 }
707 }
708
710 }
711
712 // Build the property type and name, and return the completed fragments.
713 return Fragments.appendSpace()
714 .append(getFragmentsForType(Property->getType(),
715 Property->getASTContext(), After))
716 .appendSpace()
717 .append(Property->getName(),
719 .append(std::move(After));
720}
721
723 const ObjCProtocolDecl *Protocol) {
724 DeclarationFragments Fragments;
725 // Build basic protocol declaration.
727 .appendSpace()
728 .append(Protocol->getName(),
730
731 // If this protocol conforms to other protocols, build the conformance list.
732 if (!Protocol->protocols().empty()) {
734 for (ObjCProtocolDecl::protocol_iterator It = Protocol->protocol_begin();
735 It != Protocol->protocol_end(); It++) {
736 // Add a leading comma if this is not the first protocol rendered.
737 if (It != Protocol->protocol_begin())
739
742 Fragments.append((*It)->getName(),
744 *It);
745 }
747 }
748
749 return Fragments;
750}
751
753 const TypedefNameDecl *Decl) {
754 DeclarationFragments Fragments, After;
756 .appendSpace()
757 .append(getFragmentsForType(Decl->getUnderlyingType(),
758 Decl->getASTContext(), After))
759 .append(std::move(After))
760 .appendSpace()
762
764}
765
766template <typename FunctionT>
769 FunctionSignature Signature;
770
771 DeclarationFragments ReturnType, After;
772 ReturnType
773 .append(getFragmentsForType(Function->getReturnType(),
774 Function->getASTContext(), After))
775 .append(std::move(After));
776 Signature.setReturnType(ReturnType);
777
778 for (const auto *Param : Function->parameters())
779 Signature.addParameter(Param->getName(), getFragmentsForParam(Param));
780
781 return Signature;
782}
783
784// Instantiate template for FunctionDecl.
785template FunctionSignature
787
788// Instantiate template for ObjCMethodDecl.
789template FunctionSignature
791
792// Subheading of a symbol defaults to its name.
795 DeclarationFragments Fragments;
796 if (!Decl->getName().empty())
797 Fragments.append(Decl->getName(),
799 return Fragments;
800}
801
802// Subheading of an Objective-C method is a `+` or `-` sign indicating whether
803// it's a class method or an instance method, followed by the selector name.
806 DeclarationFragments Fragments;
807 if (Method->isClassMethod())
809 else if (Method->isInstanceMethod())
811
812 return Fragments.append(Method->getNameAsString(),
814}
815
816// Subheading of a symbol defaults to its name.
819 DeclarationFragments Fragments;
821 return Fragments;
822}
This file defines the Declaration Fragments related classes.
int Category
Definition: Format.cpp:2798
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 ...
Definition: ASTContext.h:182
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
Definition: ASTContext.h:2157
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3043
static std::optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
Definition: Type.cpp:4475
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3091
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:429
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:794
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:5674
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3174
Represents an enum.
Definition: Decl.h:3734
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:3894
Represents a member of a struct/union/class.
Definition: Decl.h:2945
Represents a function declaration or definition.
Definition: Decl.h:1917
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2609
QualType getReturnType() const
Definition: Decl.h:2640
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2683
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3542
StringRef getName() const
Return the actual identifier string.
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2955
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
Definition: MacroInfo.h:313
const MacroInfo * getMacroInfo() const
Definition: MacroInfo.h:413
This represents a decl that may have a name.
Definition: Decl.h:247
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274
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...
Definition: Decl.h:290
Represents a C++ namespace alias.
Definition: DeclCXX.h:3074
Represent a C++ namespace.
Definition: Decl.h:542
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
Definition: Decl.h:600
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.
Definition: DeclObjC.h:2312
Represents an ObjC class declaration.
Definition: DeclObjC.h:1147
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:351
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:138
unsigned param_size() const
Definition: DeclObjC.h:349
Selector getSelector() const
Definition: DeclObjC.h:329
bool isInstanceMethod() const
Definition: DeclObjC.h:428
ParmVarDecl * getParamDecl(unsigned Idx)
Definition: DeclObjC.h:379
QualType getReturnType() const
Definition: DeclObjC.h:331
bool isClassMethod() const
Definition: DeclObjC.h:436
Represents a pointer to an Objective C object.
Definition: Type.h:6312
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
Definition: Type.h:6387
bool isObjCIdOrClassType() const
True if this is equivalent to the 'id' or 'Class' type,.
Definition: Type.h:6381
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:729
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2069
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2141
Sugar for parentheses used when specifying types.
Definition: Type.h:2774
Represents a parameter to a function.
Definition: Decl.h:1722
bool isObjCMethodParameter() const
Definition: Decl.h:1765
A (possibly-)qualified type.
Definition: Type.h:736
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:803
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:6685
The collection of all-type qualifiers we support.
Definition: Type.h:146
bool hasConst() const
Definition: Type.h:263
bool hasRestrict() const
Definition: Type.h:283
bool hasVolatile() const
Definition: Type.h:273
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2973
Represents a struct/union/class.
Definition: Decl.h:4012
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.
Definition: Decl.h:3454
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3680
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6646
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Definition: Type.cpp:3040
The base class of the type hierarchy.
Definition: Type.h:1568
bool isPointerType() const
Definition: Type.h:6916
CanQualType getCanonicalTypeUnqualified() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:631
bool isObjCIdType() const
Definition: Type.h:7077
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition: Type.h:7483
bool isObjCObjectPointerType() const
Definition: Type.h:7044
bool isAnyPointerType() const
Definition: Type.h:6920
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7430
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3304
QualType getType() const
Definition: Decl.h:712
Represents a variable declaration or definition.
Definition: Decl.h:913
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
Definition: Decl.cpp:2066
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1125
static DeclarationFragments getFragmentsForEnumConstant(const EnumConstantDecl *)
Build DeclarationFragments for an enum constant declaration EnumConstantDecl.
static DeclarationFragments getFragmentsForObjCCategory(const ObjCCategoryDecl *)
Build DeclarationFragments for an Objective-C category declaration ObjCCategoryDecl.
static DeclarationFragments getFragmentsForTypedef(const TypedefNameDecl *Decl)
Build DeclarationFragments for a typedef TypedefNameDecl.
static DeclarationFragments getFragmentsForEnum(const EnumDecl *)
Build DeclarationFragments for an enum declaration EnumDecl.
static DeclarationFragments getFragmentsForObjCProtocol(const ObjCProtocolDecl *)
Build DeclarationFragments for an Objective-C protocol declaration ObjCProtocolDecl.
static DeclarationFragments getFragmentsForField(const FieldDecl *)
Build DeclarationFragments for a field declaration FieldDecl.
static DeclarationFragments getFragmentsForVar(const VarDecl *)
Build DeclarationFragments for a variable declaration VarDecl.
static DeclarationFragments getFragmentsForObjCMethod(const ObjCMethodDecl *)
Build DeclarationFragments for an Objective-C method declaration ObjCMethodDecl.
static DeclarationFragments getSubHeadingForMacro(StringRef Name)
Build a sub-heading for macro Name.
static DeclarationFragments getFragmentsForFunction(const FunctionDecl *)
Build DeclarationFragments for a function declaration FunctionDecl.
static DeclarationFragments getFragmentsForObjCProperty(const ObjCPropertyDecl *)
Build DeclarationFragments for an Objective-C property declaration ObjCPropertyDecl.
static DeclarationFragments getFragmentsForStruct(const RecordDecl *)
Build DeclarationFragments for a struct record declaration RecordDecl.
static DeclarationFragments getSubHeading(const NamedDecl *)
Build sub-heading fragments for a NamedDecl.
static DeclarationFragments getFragmentsForMacro(StringRef Name, const MacroDirective *MD)
Build DeclarationFragments for a macro.
static FunctionSignature getFunctionSignature(const FunctionT *)
Build FunctionSignature for a function-like declaration FunctionT like FunctionDecl or ObjCMethodDecl...
static DeclarationFragments getFragmentsForObjCInterface(const ObjCInterfaceDecl *)
Build DeclarationFragments for an Objective-C interface declaration ObjCInterfaceDecl.
DeclarationFragments is a vector of tagged important parts of a symbol's declaration.
const std::vector< Fragment > & getFragments() const
DeclarationFragments & appendSpace()
Append a text Fragment of a space character.
@ GenericParameter
Parameter that's used as generics in the context.
@ ExternalParam
External parameters in Objective-C methods.
@ TypeIdentifier
Identifier that refers to a type in the context.
@ InternalParam
Internal/local parameters in Objective-C methods.
static StringRef getFragmentKindString(FragmentKind Kind)
Get the string description of a FragmentKind Kind.
static FragmentKind parseFragmentKindFromString(StringRef S)
Get the corresponding FragmentKind from string S.
DeclarationFragments & append(StringRef Spelling, FragmentKind Kind, StringRef PreciseIdentifier="", const Decl *Declaration=nullptr)
Append a new Fragment to the end of the Fragments.
Store function signature information with DeclarationFragments of the return type and parameters.
FunctionSignature & addParameter(StringRef Name, DeclarationFragments Fragments)
void setReturnType(DeclarationFragments RT)
@ 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.
Definition: Specifiers.h:239
@ SC_Auto
Definition: Specifiers.h:247
@ SC_PrivateExtern
Definition: Specifiers.h:244
@ SC_Extern
Definition: Specifiers.h:242
@ SC_Register
Definition: Specifiers.h:248
@ SC_Static
Definition: Specifiers.h:243
@ SC_None
Definition: Specifiers.h:241
@ 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...
Definition: Type.h:5595
@ ETK_None
No keyword precedes the qualified type name.
Definition: Type.h:5616
YAML serialization mapping.
Definition: Dominators.h:30
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:669
const Type * Ty
The locally-unqualified type.
Definition: Type.h:671
Qualifiers Quals
The local qualifiers.
Definition: Type.h:674
Fragment holds information of a single fragment.