clang 19.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
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclCXX.h"
18#include "clang/AST/Type.h"
19#include "clang/AST/TypeLoc.h"
23#include "llvm/ADT/StringSwitch.h"
24#include <typeinfo>
25
26using namespace clang::extractapi;
27using namespace llvm;
28
29namespace {
30
31void findTypeLocForBlockDecl(const clang::TypeSourceInfo *TSInfo,
33 clang::FunctionProtoTypeLoc &BlockProto) {
34 if (!TSInfo)
35 return;
36
38 while (true) {
39 // Look through qualified types
40 if (auto QualifiedTL = TL.getAs<clang::QualifiedTypeLoc>()) {
41 TL = QualifiedTL.getUnqualifiedLoc();
42 continue;
43 }
44
45 if (auto AttrTL = TL.getAs<clang::AttributedTypeLoc>()) {
46 TL = AttrTL.getModifiedLoc();
47 continue;
48 }
49
50 // Try to get the function prototype behind the block pointer type,
51 // then we're done.
52 if (auto BlockPtr = TL.getAs<clang::BlockPointerTypeLoc>()) {
53 TL = BlockPtr.getPointeeLoc().IgnoreParens();
55 BlockProto = TL.getAs<clang::FunctionProtoTypeLoc>();
56 }
57 break;
58 }
59}
60
61} // namespace
62
64 if (!Fragments.empty()) {
65 Fragment &Last = Fragments.back();
66 if (Last.Kind == FragmentKind::Text) {
67 // Merge the extra space into the last fragment if the last fragment is
68 // also text.
69 if (Last.Spelling.back() != ' ') { // avoid extra trailing spaces.
70 Last.Spelling.push_back(' ');
71 }
72 } else {
74 }
75 }
76
77 return *this;
78}
79
82 switch (Kind) {
84 return "none";
86 return "keyword";
88 return "attribute";
90 return "number";
92 return "string";
94 return "identifier";
96 return "typeIdentifier";
98 return "genericParameter";
100 return "externalParam";
102 return "internalParam";
104 return "text";
105 }
106
107 llvm_unreachable("Unhandled FragmentKind");
108}
109
112 return llvm::StringSwitch<FragmentKind>(S)
118 .Case("typeIdentifier",
120 .Case("genericParameter",
126}
127
129 ExceptionSpecificationType ExceptionSpec) {
130 DeclarationFragments Fragments;
131 switch (ExceptionSpec) {
133 return Fragments;
140 // FIXME: throw(int), get types of inner expression
141 return Fragments;
146 // FIXME: throw(conditional-expression), get expression
147 break;
160 default:
161 return Fragments;
162 }
163
164 llvm_unreachable("Unhandled exception specification");
165}
166
169 DeclarationFragments Fragments;
170 if (Record->isStruct())
172 else if (Record->isUnion())
174 else
176
177 return Fragments;
178}
179
180// NNS stores C++ nested name specifiers, which are prefixes to qualified names.
181// Build declaration fragments for NNS recursively so that we have the USR for
182// every part in a qualified name, and also leaves the actual underlying type
183// cleaner for its own fragment.
185DeclarationFragmentsBuilder::getFragmentsForNNS(const NestedNameSpecifier *NNS,
186 ASTContext &Context,
187 DeclarationFragments &After) {
188 DeclarationFragments Fragments;
189 if (NNS->getPrefix())
190 Fragments.append(getFragmentsForNNS(NNS->getPrefix(), Context, After));
191
192 switch (NNS->getKind()) {
194 Fragments.append(NNS->getAsIdentifier()->getName(),
196 break;
197
199 const NamespaceDecl *NS = NNS->getAsNamespace();
200 if (NS->isAnonymousNamespace())
201 return Fragments;
204 Fragments.append(NS->getName(),
206 break;
207 }
208
210 const NamespaceAliasDecl *Alias = NNS->getAsNamespaceAlias();
212 index::generateUSRForDecl(Alias, USR);
213 Fragments.append(Alias->getName(),
215 Alias);
216 break;
217 }
218
220 // The global specifier `::` at the beginning. No stored value.
221 break;
222
224 // Microsoft's `__super` specifier.
226 break;
227
229 // A type prefixed by the `template` keyword.
231 Fragments.appendSpace();
232 // Fallthrough after adding the keyword to handle the actual type.
233 [[fallthrough]];
234
236 const Type *T = NNS->getAsType();
237 // FIXME: Handle C++ template specialization type
238 Fragments.append(getFragmentsForType(T, Context, After));
239 break;
240 }
241 }
242
243 // Add the separator text `::` for this segment.
244 return Fragments.append("::", DeclarationFragments::FragmentKind::Text);
245}
246
247// Recursively build the declaration fragments for an underlying `Type` with
248// qualifiers removed.
249DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
250 const Type *T, ASTContext &Context, DeclarationFragments &After) {
251 assert(T && "invalid type");
252
253 DeclarationFragments Fragments;
254
255 // An ElaboratedType is a sugar for types that are referred to using an
256 // elaborated keyword, e.g., `struct S`, `enum E`, or (in C++) via a
257 // qualified name, e.g., `N::M::type`, or both.
258 if (const ElaboratedType *ET = dyn_cast<ElaboratedType>(T)) {
259 ElaboratedTypeKeyword Keyword = ET->getKeyword();
260 if (Keyword != ElaboratedTypeKeyword::None) {
261 Fragments
264 .appendSpace();
265 }
266
267 if (const NestedNameSpecifier *NNS = ET->getQualifier())
268 Fragments.append(getFragmentsForNNS(NNS, Context, After));
269
270 // After handling the elaborated keyword or qualified name, build
271 // declaration fragments for the desugared underlying type.
272 return Fragments.append(getFragmentsForType(ET->desugar(), Context, After));
273 }
274
275 // If the type is a typedefed type, get the underlying TypedefNameDecl for a
276 // direct reference to the typedef instead of the wrapped type.
277
278 // 'id' type is a typedef for an ObjCObjectPointerType
279 // we treat it as a typedef
280 if (const TypedefType *TypedefTy = dyn_cast<TypedefType>(T)) {
281 const TypedefNameDecl *Decl = TypedefTy->getDecl();
282 TypedefUnderlyingTypeResolver TypedefResolver(Context);
283 std::string USR = TypedefResolver.getUSRForType(QualType(T, 0));
284
285 if (T->isObjCIdType()) {
286 return Fragments.append(Decl->getName(),
288 }
289
290 return Fragments.append(
292 USR, TypedefResolver.getUnderlyingTypeDecl(QualType(T, 0)));
293 }
294
295 // Declaration fragments of a pointer type is the declaration fragments of
296 // the pointee type followed by a `*`,
297 if (T->isPointerType() && !T->isFunctionPointerType())
298 return Fragments
299 .append(getFragmentsForType(T->getPointeeType(), Context, After))
301
302 // For Objective-C `id` and `Class` pointers
303 // we do not spell out the `*`.
304 if (T->isObjCObjectPointerType() &&
306
307 Fragments.append(getFragmentsForType(T->getPointeeType(), Context, After));
308
309 // id<protocol> is an qualified id type
310 // id<protocol>* is not an qualified id type
313 }
314
315 return Fragments;
316 }
317
318 // Declaration fragments of a lvalue reference type is the declaration
319 // fragments of the underlying type followed by a `&`.
320 if (const LValueReferenceType *LRT = dyn_cast<LValueReferenceType>(T))
321 return Fragments
322 .append(
323 getFragmentsForType(LRT->getPointeeTypeAsWritten(), Context, After))
325
326 // Declaration fragments of a rvalue reference type is the declaration
327 // fragments of the underlying type followed by a `&&`.
328 if (const RValueReferenceType *RRT = dyn_cast<RValueReferenceType>(T))
329 return Fragments
330 .append(
331 getFragmentsForType(RRT->getPointeeTypeAsWritten(), Context, After))
333
334 // Declaration fragments of an array-typed variable have two parts:
335 // 1. the element type of the array that appears before the variable name;
336 // 2. array brackets `[(0-9)?]` that appear after the variable name.
337 if (const ArrayType *AT = T->getAsArrayTypeUnsafe()) {
338 // Build the "after" part first because the inner element type might also
339 // be an array-type. For example `int matrix[3][4]` which has a type of
340 // "(array 3 of (array 4 of ints))."
341 // Push the array size part first to make sure they are in the right order.
343
344 switch (AT->getSizeModifier()) {
346 break;
349 break;
352 break;
353 }
354
355 if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) {
356 // FIXME: right now this would evaluate any expressions/macros written in
357 // the original source to concrete values. For example
358 // `int nums[MAX]` -> `int nums[100]`
359 // `char *str[5 + 1]` -> `char *str[6]`
361 CAT->getSize().toStringUnsigned(Size);
363 }
364
366
367 return Fragments.append(
368 getFragmentsForType(AT->getElementType(), Context, After));
369 }
370
371 // Everything we care about has been handled now, reduce to the canonical
372 // unqualified base type.
374
375 // If the base type is a TagType (struct/interface/union/class/enum), let's
376 // get the underlying Decl for better names and USRs.
377 if (const TagType *TagTy = dyn_cast<TagType>(Base)) {
378 const TagDecl *Decl = TagTy->getDecl();
379 // Anonymous decl, skip this fragment.
380 if (Decl->getName().empty())
381 return Fragments;
382 SmallString<128> TagUSR;
384 return Fragments.append(Decl->getName(),
386 TagUSR, Decl);
387 }
388
389 // If the base type is an ObjCInterfaceType, use the underlying
390 // ObjCInterfaceDecl for the true USR.
391 if (const auto *ObjCIT = dyn_cast<ObjCInterfaceType>(Base)) {
392 const auto *Decl = ObjCIT->getDecl();
395 return Fragments.append(Decl->getName(),
397 USR, Decl);
398 }
399
400 // Default fragment builder for other kinds of types (BuiltinType etc.)
403 Fragments.append(Base.getAsString(),
405
406 return Fragments;
407}
408
410DeclarationFragmentsBuilder::getFragmentsForQualifiers(const Qualifiers Quals) {
411 DeclarationFragments Fragments;
412 if (Quals.hasConst())
414 if (Quals.hasVolatile())
416 if (Quals.hasRestrict())
418
419 return Fragments;
420}
421
422DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
423 const QualType QT, ASTContext &Context, DeclarationFragments &After) {
424 assert(!QT.isNull() && "invalid type");
425
426 if (const ParenType *PT = dyn_cast<ParenType>(QT)) {
428 return getFragmentsForType(PT->getInnerType(), Context, After)
430 }
431
432 const SplitQualType SQT = QT.split();
433 DeclarationFragments QualsFragments = getFragmentsForQualifiers(SQT.Quals),
434 TypeFragments =
435 getFragmentsForType(SQT.Ty, Context, After);
436 if (QT.getAsString() == "_Bool")
437 TypeFragments.replace("bool", 0);
438
439 if (QualsFragments.getFragments().empty())
440 return TypeFragments;
441
442 // Use east qualifier for pointer types
443 // For example:
444 // ```
445 // int * const
446 // ^---- ^----
447 // type qualifier
448 // ^-----------------
449 // const pointer to int
450 // ```
451 // should not be reconstructed as
452 // ```
453 // const int *
454 // ^---- ^--
455 // qualifier type
456 // ^---------------- ^
457 // pointer to const int
458 // ```
459 if (SQT.Ty->isAnyPointerType())
460 return TypeFragments.appendSpace().append(std::move(QualsFragments));
461
462 return QualsFragments.appendSpace().append(std::move(TypeFragments));
463}
464
466 const NamespaceDecl *Decl) {
467 DeclarationFragments Fragments;
469 if (!Decl->isAnonymousNamespace())
470 Fragments.appendSpace().append(
473}
474
477 DeclarationFragments Fragments;
478 if (Var->isConstexpr())
480 .appendSpace();
481
482 StorageClass SC = Var->getStorageClass();
483 if (SC != SC_None)
484 Fragments
487 .appendSpace();
488
489 // Capture potential fragments that needs to be placed after the variable name
490 // ```
491 // int nums[5];
492 // char (*ptr_to_array)[6];
493 // ```
495 FunctionTypeLoc BlockLoc;
496 FunctionProtoTypeLoc BlockProtoLoc;
497 findTypeLocForBlockDecl(Var->getTypeSourceInfo(), BlockLoc, BlockProtoLoc);
498
499 if (!BlockLoc) {
500 QualType T = Var->getTypeSourceInfo()
501 ? Var->getTypeSourceInfo()->getType()
503 Var->getType());
504
505 Fragments.append(getFragmentsForType(T, Var->getASTContext(), After))
506 .appendSpace();
507 } else {
508 Fragments.append(getFragmentsForBlock(Var, BlockLoc, BlockProtoLoc, After));
509 }
510
511 return Fragments
513 .append(std::move(After))
515}
516
519 DeclarationFragments Fragments;
520 if (Var->isConstexpr())
522 .appendSpace();
523 QualType T =
524 Var->getTypeSourceInfo()
525 ? Var->getTypeSourceInfo()->getType()
527
528 // Might be a member, so might be static.
529 if (Var->isStaticDataMember())
531 .appendSpace();
532
534 DeclarationFragments ArgumentFragment =
535 getFragmentsForType(T, Var->getASTContext(), After);
536 if (StringRef(ArgumentFragment.begin()->Spelling)
537 .starts_with("type-parameter")) {
538 std::string ProperArgName = getNameForTemplateArgument(
540 ArgumentFragment.begin()->Spelling);
541 ArgumentFragment.begin()->Spelling.swap(ProperArgName);
542 }
543 Fragments.append(std::move(ArgumentFragment))
544 .appendSpace()
547 return Fragments;
548}
549
551DeclarationFragmentsBuilder::getFragmentsForParam(const ParmVarDecl *Param) {
552 DeclarationFragments Fragments, After;
553
554 auto *TSInfo = Param->getTypeSourceInfo();
555
556 QualType T = TSInfo ? TSInfo->getType()
558 Param->getType());
559
560 FunctionTypeLoc BlockLoc;
561 FunctionProtoTypeLoc BlockProtoLoc;
562 findTypeLocForBlockDecl(TSInfo, BlockLoc, BlockProtoLoc);
563
564 DeclarationFragments TypeFragments;
565 if (BlockLoc)
566 TypeFragments.append(
567 getFragmentsForBlock(Param, BlockLoc, BlockProtoLoc, After));
568 else
569 TypeFragments.append(getFragmentsForType(T, Param->getASTContext(), After));
570
571 if (StringRef(TypeFragments.begin()->Spelling)
572 .starts_with("type-parameter")) {
573 std::string ProperArgName = getNameForTemplateArgument(
574 dyn_cast<FunctionDecl>(Param->getDeclContext())
575 ->getDescribedFunctionTemplate()
576 ->getTemplateParameters()
577 ->asArray(),
578 TypeFragments.begin()->Spelling);
579 TypeFragments.begin()->Spelling.swap(ProperArgName);
580 }
581
582 if (Param->isObjCMethodParameter()) {
584 .append(std::move(TypeFragments))
585 .append(std::move(After))
587 .append(Param->getName(),
589 } else {
590 Fragments.append(std::move(TypeFragments));
591 if (!T->isBlockPointerType())
592 Fragments.appendSpace();
593 Fragments
594 .append(Param->getName(),
596 .append(std::move(After));
597 }
598 return Fragments;
599}
600
601DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForBlock(
603 FunctionProtoTypeLoc &BlockProto, DeclarationFragments &After) {
604 DeclarationFragments Fragments;
605
606 DeclarationFragments RetTyAfter;
607 auto ReturnValueFragment = getFragmentsForType(
608 Block.getTypePtr()->getReturnType(), BlockDecl->getASTContext(), After);
609
610 Fragments.append(std::move(ReturnValueFragment))
611 .append(std::move(RetTyAfter))
612 .appendSpace()
614
616 unsigned NumParams = Block.getNumParams();
617
618 if (!BlockProto || NumParams == 0) {
619 if (BlockProto && BlockProto.getTypePtr()->isVariadic())
621 else
623 } else {
625 for (unsigned I = 0; I != NumParams; ++I) {
626 if (I)
628 After.append(getFragmentsForParam(Block.getParam(I)));
629 if (I == NumParams - 1 && BlockProto.getTypePtr()->isVariadic())
631 }
633 }
634
635 return Fragments;
636}
637
640 DeclarationFragments Fragments;
641 // FIXME: Handle template specialization
642 switch (Func->getStorageClass()) {
643 case SC_None:
644 case SC_PrivateExtern:
645 break;
646 case SC_Extern:
648 .appendSpace();
649 break;
650 case SC_Static:
652 .appendSpace();
653 break;
654 case SC_Auto:
655 case SC_Register:
656 llvm_unreachable("invalid for functions");
657 }
658 if (Func->isConsteval()) // if consteval, it is also constexpr
660 .appendSpace();
661 else if (Func->isConstexpr())
663 .appendSpace();
664
665 // FIXME: Is `after` actually needed here?
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 =
672 getNameForTemplateArgument(Func->getDescribedFunctionTemplate()
673 ->getTemplateParameters()
674 ->asArray(),
675 ReturnValueFragment.begin()->Spelling);
676 ReturnValueFragment.begin()->Spelling.swap(ProperArgName);
677 }
678
679 Fragments.append(std::move(ReturnValueFragment))
680 .appendSpace()
682
683 if (Func->getTemplateSpecializationInfo()) {
685
686 for (unsigned i = 0, end = Func->getNumParams(); i != end; ++i) {
687 if (i)
689 Fragments.append(
690 getFragmentsForType(Func->getParamDecl(i)->getType(),
691 Func->getParamDecl(i)->getASTContext(), After));
692 }
694 }
695 Fragments.append(std::move(After));
696
698 unsigned NumParams = Func->getNumParams();
699 for (unsigned i = 0; i != NumParams; ++i) {
700 if (i)
702 Fragments.append(getFragmentsForParam(Func->getParamDecl(i)));
703 }
704
705 if (Func->isVariadic()) {
706 if (NumParams > 0)
709 }
711
713 Func->getExceptionSpecType()));
714
716}
717
719 const EnumConstantDecl *EnumConstDecl) {
720 DeclarationFragments Fragments;
721 return Fragments.append(EnumConstDecl->getName(),
723}
724
729
730 DeclarationFragments Fragments, After;
732
733 if (!EnumDecl->getName().empty())
734 Fragments.appendSpace().append(
736
737 QualType IntegerType = EnumDecl->getIntegerType();
738 if (!IntegerType.isNull())
740 .append(
741 getFragmentsForType(IntegerType, EnumDecl->getASTContext(), After))
742 .append(std::move(After));
743
745}
746
750 DeclarationFragments Fragments;
751 if (Field->isMutable())
753 .appendSpace();
754 return Fragments
755 .append(
756 getFragmentsForType(Field->getType(), Field->getASTContext(), After))
757 .appendSpace()
759 .append(std::move(After))
761}
762
764 const RecordDecl *Record) {
765 if (const auto *TypedefNameDecl = Record->getTypedefNameForAnonDecl())
767
768 DeclarationFragments Fragments;
769 if (Record->isUnion())
771 else
773
774 if (!Record->getName().empty())
775 Fragments.appendSpace().append(
777
779}
780
782 const CXXRecordDecl *Record) {
783 if (const auto *TypedefNameDecl = Record->getTypedefNameForAnonDecl())
785
786 DeclarationFragments Fragments;
788
789 if (!Record->getName().empty())
790 Fragments.appendSpace().append(
792
794}
795
798 const CXXMethodDecl *Method) {
799 DeclarationFragments Fragments;
800 std::string Name;
801 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(Method)) {
802 Name = Method->getNameAsString();
803 if (Constructor->isExplicit())
805 .appendSpace();
806 } else if (isa<CXXDestructorDecl>(Method))
807 Name = Method->getNameAsString();
808
811 .append(std::move(After));
813 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
814 if (i)
816 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
817 }
819
821 Method->getExceptionSpecType()));
822
824}
825
827 const CXXMethodDecl *Method) {
828 DeclarationFragments Fragments;
829 StringRef Name = Method->getName();
830 if (Method->isStatic())
832 .appendSpace();
833 if (Method->isConstexpr())
835 .appendSpace();
836 if (Method->isVolatile())
838 .appendSpace();
839
840 // Build return type
842 Fragments
843 .append(getFragmentsForType(Method->getReturnType(),
844 Method->getASTContext(), After))
845 .appendSpace()
847 .append(std::move(After));
849 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
850 if (i)
852 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
853 }
855
856 if (Method->isConst())
857 Fragments.appendSpace().append("const",
859
861 Method->getExceptionSpecType()));
862
864}
865
868 const CXXConversionDecl *ConversionFunction) {
869 DeclarationFragments Fragments;
870
871 if (ConversionFunction->isExplicit())
873 .appendSpace();
874
876 .appendSpace();
877
878 Fragments
879 .append(ConversionFunction->getConversionType().getAsString(),
882 for (unsigned i = 0, end = ConversionFunction->getNumParams(); i != end;
883 ++i) {
884 if (i)
886 Fragments.append(getFragmentsForParam(ConversionFunction->getParamDecl(i)));
887 }
889
890 if (ConversionFunction->isConst())
891 Fragments.appendSpace().append("const",
893
895}
896
899 const CXXMethodDecl *Method) {
900 DeclarationFragments Fragments;
901
902 // Build return type
904 Fragments
905 .append(getFragmentsForType(Method->getReturnType(),
906 Method->getASTContext(), After))
907 .appendSpace()
908 .append(Method->getNameAsString(),
910 .append(std::move(After));
912 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
913 if (i)
915 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
916 }
918
919 if (Method->isConst())
920 Fragments.appendSpace().append("const",
922
924 Method->getExceptionSpecType()));
925
927}
928
929// Get fragments for template parameters, e.g. T in tempalte<typename T> ...
932 ArrayRef<NamedDecl *> ParameterArray) {
933 DeclarationFragments Fragments;
934 for (unsigned i = 0, end = ParameterArray.size(); i != end; ++i) {
935 if (i)
937 .appendSpace();
938
939 const auto *TemplateParam =
940 dyn_cast<TemplateTypeParmDecl>(ParameterArray[i]);
941 if (!TemplateParam)
942 continue;
943 if (TemplateParam->hasTypeConstraint())
944 Fragments.append(TemplateParam->getTypeConstraint()
945 ->getNamedConcept()
946 ->getName()
947 .str(),
949 else if (TemplateParam->wasDeclaredWithTypename())
951 else
953
954 if (TemplateParam->isParameterPack())
956
957 Fragments.appendSpace().append(
958 TemplateParam->getName(),
960 }
961 return Fragments;
962}
963
964// Find the name of a template argument from the template's parameters.
966 const ArrayRef<NamedDecl *> TemplateParameters, std::string TypeParameter) {
967 // The arg is a generic parameter from a partial spec, e.g.
968 // T in template<typename T> Foo<T, int>.
969 //
970 // Those names appear as "type-parameter-<index>-<depth>", so we must find its
971 // name from the template's parameter list.
972 for (unsigned i = 0; i < TemplateParameters.size(); ++i) {
973 const auto *Parameter =
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());
979 }
980 llvm_unreachable("Could not find the name of a template argument.");
981}
982
983// Get fragments for template arguments, e.g. int in template<typename T>
984// Foo<int>;
985//
986// Note: TemplateParameters is only necessary if the Decl is a
987// PartialSpecialization, where we need the parameters to deduce the name of the
988// generic arguments.
991 const ArrayRef<TemplateArgument> TemplateArguments, ASTContext &Context,
992 const std::optional<ArrayRef<NamedDecl *>> TemplateParameters) {
993 DeclarationFragments Fragments;
994 for (unsigned i = 0, end = TemplateArguments.size(); i != end; ++i) {
995 if (i)
997 .appendSpace();
998
999 std::string Type = TemplateArguments[i].getAsType().getAsString();
1001 DeclarationFragments ArgumentFragment =
1002 getFragmentsForType(TemplateArguments[i].getAsType(), Context, After);
1003
1004 if (StringRef(ArgumentFragment.begin()->Spelling)
1005 .starts_with("type-parameter")) {
1006 std::string ProperArgName = getNameForTemplateArgument(
1007 TemplateParameters.value(), ArgumentFragment.begin()->Spelling);
1008 ArgumentFragment.begin()->Spelling.swap(ProperArgName);
1009 }
1010 Fragments.append(std::move(ArgumentFragment));
1011
1012 if (TemplateArguments[i].isPackExpansion())
1014 }
1015 return Fragments;
1016}
1017
1019 const ConceptDecl *Concept) {
1020 DeclarationFragments Fragments;
1021 return Fragments
1025 Concept->getTemplateParameters()->asArray()))
1028 .appendSpace()
1029 .append(Concept->getName().str(),
1032}
1033
1036 const RedeclarableTemplateDecl *RedeclarableTemplate) {
1037 DeclarationFragments Fragments;
1041 RedeclarableTemplate->getTemplateParameters()->asArray()))
1043 .appendSpace();
1044
1045 if (isa<TypeAliasTemplateDecl>(RedeclarableTemplate))
1046 Fragments.appendSpace()
1048 .appendSpace()
1049 .append(RedeclarableTemplate->getName(),
1051 // the templated records will be resposbible for injecting their templates
1052 return Fragments.appendSpace();
1053}
1054
1058 DeclarationFragments Fragments;
1059 return Fragments
1063 .appendSpace()
1065 cast<CXXRecordDecl>(Decl)))
1066 .pop_back() // there is an extra semicolon now
1068 .append(
1069 getFragmentsForTemplateArguments(Decl->getTemplateArgs().asArray(),
1070 Decl->getASTContext(), std::nullopt))
1073}
1074
1078 DeclarationFragments Fragments;
1079 return Fragments
1083 Decl->getTemplateParameters()->asArray()))
1085 .appendSpace()
1087 cast<CXXRecordDecl>(Decl)))
1088 .pop_back() // there is an extra semicolon now
1091 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1092 Decl->getTemplateParameters()->asArray()))
1095}
1096
1100 DeclarationFragments Fragments;
1101 return Fragments
1105 .appendSpace()
1107 .pop_back() // there is an extra semicolon now
1109 .append(
1110 getFragmentsForTemplateArguments(Decl->getTemplateArgs().asArray(),
1111 Decl->getASTContext(), std::nullopt))
1114}
1115
1119 DeclarationFragments Fragments;
1120 return Fragments
1123 // Partial specs may have new params.
1125 Decl->getTemplateParameters()->asArray()))
1127 .appendSpace()
1129 .pop_back() // there is an extra semicolon now
1132 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1133 Decl->getTemplateParameters()->asArray()))
1136}
1137
1140 const FunctionTemplateDecl *Decl) {
1141 DeclarationFragments Fragments;
1142 return Fragments
1145 // Partial specs may have new params.
1147 Decl->getTemplateParameters()->asArray()))
1149 .appendSpace()
1151 Decl->getAsFunction()));
1152}
1153
1156 const FunctionDecl *Decl) {
1157 DeclarationFragments Fragments;
1158 return Fragments
1161 .appendSpace()
1163}
1164
1167 const MacroDirective *MD) {
1168 DeclarationFragments Fragments;
1170 .appendSpace();
1172
1173 auto *MI = MD->getMacroInfo();
1174
1175 if (MI->isFunctionLike()) {
1177 unsigned numParameters = MI->getNumParams();
1178 if (MI->isC99Varargs())
1179 --numParameters;
1180 for (unsigned i = 0; i < numParameters; ++i) {
1181 if (i)
1183 Fragments.append(MI->params()[i]->getName(),
1185 }
1186 if (MI->isVariadic()) {
1187 if (numParameters && MI->isC99Varargs())
1190 }
1192 }
1193 return Fragments;
1194}
1195
1197 const ObjCCategoryDecl *Category) {
1198 DeclarationFragments Fragments;
1199
1200 auto *Interface = Category->getClassInterface();
1201 SmallString<128> InterfaceUSR;
1202 index::generateUSRForDecl(Interface, InterfaceUSR);
1203
1205 .appendSpace()
1206 .append(Category->getClassInterface()->getName(),
1208 Interface)
1210 .append(Category->getName(),
1213
1214 return Fragments;
1215}
1216
1219 DeclarationFragments Fragments;
1220 // Build the base of the Objective-C interface declaration.
1222 .appendSpace()
1223 .append(Interface->getName(),
1225
1226 // Build the inheritance part of the declaration.
1227 if (const ObjCInterfaceDecl *SuperClass = Interface->getSuperClass()) {
1228 SmallString<128> SuperUSR;
1229 index::generateUSRForDecl(SuperClass, SuperUSR);
1231 .append(SuperClass->getName(),
1233 SuperClass);
1234 }
1235
1236 return Fragments;
1237}
1238
1240 const ObjCMethodDecl *Method) {
1241 DeclarationFragments Fragments, After;
1242 // Build the instance/class method indicator.
1243 if (Method->isClassMethod())
1245 else if (Method->isInstanceMethod())
1247
1248 // Build the return type.
1250 .append(getFragmentsForType(Method->getReturnType(),
1251 Method->getASTContext(), After))
1252 .append(std::move(After))
1254
1255 // Build the selector part.
1256 Selector Selector = Method->getSelector();
1257 if (Selector.getNumArgs() == 0)
1258 // For Objective-C methods that don't take arguments, the first (and only)
1259 // slot of the selector is the method name.
1260 Fragments.appendSpace().append(
1263
1264 // For Objective-C methods that take arguments, build the selector slots.
1265 for (unsigned i = 0, end = Method->param_size(); i != end; ++i) {
1266 // Objective-C method selector parts are considered as identifiers instead
1267 // of "external parameters" as in Swift. This is because Objective-C method
1268 // symbols are referenced with the entire selector, instead of just the
1269 // method name in Swift.
1271 ParamID.append(":");
1272 Fragments.appendSpace().append(
1274
1275 // Build the internal parameter.
1276 const ParmVarDecl *Param = Method->getParamDecl(i);
1277 Fragments.append(getFragmentsForParam(Param));
1278 }
1279
1280 return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
1281}
1282
1284 const ObjCPropertyDecl *Property) {
1285 DeclarationFragments Fragments, After;
1286
1287 // Build the Objective-C property keyword.
1289
1290 const auto Attributes = Property->getPropertyAttributesAsWritten();
1291 // Build the attributes if there is any associated with the property.
1292 if (Attributes != ObjCPropertyAttribute::kind_noattr) {
1293 // No leading comma for the first attribute.
1294 bool First = true;
1296 // Helper function to render the attribute.
1297 auto RenderAttribute =
1298 [&](ObjCPropertyAttribute::Kind Kind, StringRef Spelling,
1299 StringRef Arg = "",
1302 // Check if the `Kind` attribute is set for this property.
1303 if ((Attributes & Kind) && !Spelling.empty()) {
1304 // Add a leading comma if this is not the first attribute rendered.
1305 if (!First)
1307 // Render the spelling of this attribute `Kind` as a keyword.
1308 Fragments.append(Spelling,
1310 // If this attribute takes in arguments (e.g. `getter=getterName`),
1311 // render the arguments.
1312 if (!Arg.empty())
1314 .append(Arg, ArgKind);
1315 First = false;
1316 }
1317 };
1318
1319 // Go through all possible Objective-C property attributes and render set
1320 // ones.
1321 RenderAttribute(ObjCPropertyAttribute::kind_class, "class");
1322 RenderAttribute(ObjCPropertyAttribute::kind_direct, "direct");
1323 RenderAttribute(ObjCPropertyAttribute::kind_nonatomic, "nonatomic");
1324 RenderAttribute(ObjCPropertyAttribute::kind_atomic, "atomic");
1325 RenderAttribute(ObjCPropertyAttribute::kind_assign, "assign");
1326 RenderAttribute(ObjCPropertyAttribute::kind_retain, "retain");
1327 RenderAttribute(ObjCPropertyAttribute::kind_strong, "strong");
1328 RenderAttribute(ObjCPropertyAttribute::kind_copy, "copy");
1329 RenderAttribute(ObjCPropertyAttribute::kind_weak, "weak");
1331 "unsafe_unretained");
1332 RenderAttribute(ObjCPropertyAttribute::kind_readwrite, "readwrite");
1333 RenderAttribute(ObjCPropertyAttribute::kind_readonly, "readonly");
1334 RenderAttribute(ObjCPropertyAttribute::kind_getter, "getter",
1335 Property->getGetterName().getAsString());
1336 RenderAttribute(ObjCPropertyAttribute::kind_setter, "setter",
1337 Property->getSetterName().getAsString());
1338
1339 // Render nullability attributes.
1340 if (Attributes & ObjCPropertyAttribute::kind_nullability) {
1341 QualType Type = Property->getType();
1342 if (const auto Nullability =
1344 if (!First)
1346 if (*Nullability == NullabilityKind::Unspecified &&
1348 Fragments.append("null_resettable",
1350 else
1351 Fragments.append(
1352 getNullabilitySpelling(*Nullability, /*isContextSensitive=*/true),
1354 First = false;
1355 }
1356 }
1357
1359 }
1360
1361 Fragments.appendSpace();
1362
1363 FunctionTypeLoc BlockLoc;
1364 FunctionProtoTypeLoc BlockProtoLoc;
1365 findTypeLocForBlockDecl(Property->getTypeSourceInfo(), BlockLoc,
1366 BlockProtoLoc);
1367
1368 auto PropType = Property->getType();
1369 if (!BlockLoc)
1370 Fragments
1371 .append(getFragmentsForType(PropType, Property->getASTContext(), After))
1372 .appendSpace();
1373 else
1374 Fragments.append(
1375 getFragmentsForBlock(Property, BlockLoc, BlockProtoLoc, After));
1376
1377 return Fragments
1378 .append(Property->getName(),
1380 .append(std::move(After))
1382}
1383
1385 const ObjCProtocolDecl *Protocol) {
1386 DeclarationFragments Fragments;
1387 // Build basic protocol declaration.
1389 .appendSpace()
1390 .append(Protocol->getName(),
1392
1393 // If this protocol conforms to other protocols, build the conformance list.
1394 if (!Protocol->protocols().empty()) {
1396 for (ObjCProtocolDecl::protocol_iterator It = Protocol->protocol_begin();
1397 It != Protocol->protocol_end(); It++) {
1398 // Add a leading comma if this is not the first protocol rendered.
1399 if (It != Protocol->protocol_begin())
1401
1402 SmallString<128> USR;
1403 index::generateUSRForDecl(*It, USR);
1404 Fragments.append((*It)->getName(),
1406 *It);
1407 }
1409 }
1410
1411 return Fragments;
1412}
1413
1415 const TypedefNameDecl *Decl) {
1416 DeclarationFragments Fragments, After;
1418 .appendSpace()
1419 .append(getFragmentsForType(Decl->getUnderlyingType(),
1420 Decl->getASTContext(), After))
1421 .append(std::move(After))
1422 .appendSpace()
1424
1425 return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
1426}
1427
1428// Instantiate template for FunctionDecl.
1429template FunctionSignature
1431
1432// Instantiate template for ObjCMethodDecl.
1433template FunctionSignature
1435
1436// Subheading of a symbol defaults to its name.
1439 DeclarationFragments Fragments;
1440 if (isa<CXXConstructorDecl>(Decl) || isa<CXXDestructorDecl>(Decl))
1441 Fragments.append(cast<CXXRecordDecl>(Decl->getDeclContext())->getName(),
1443 else if (isa<CXXConversionDecl>(Decl)) {
1444 Fragments.append(
1445 cast<CXXConversionDecl>(Decl)->getConversionType().getAsString(),
1447 } else if (isa<CXXMethodDecl>(Decl) &&
1448 cast<CXXMethodDecl>(Decl)->isOverloadedOperator()) {
1449 Fragments.append(Decl->getNameAsString(),
1451 } else if (!Decl->getName().empty())
1452 Fragments.append(Decl->getName(),
1454 return Fragments;
1455}
1456
1457// Subheading of an Objective-C method is a `+` or `-` sign indicating whether
1458// it's a class method or an instance method, followed by the selector name.
1461 DeclarationFragments Fragments;
1462 if (Method->isClassMethod())
1464 else if (Method->isInstanceMethod())
1466
1467 return Fragments.append(Method->getNameAsString(),
1469}
1470
1471// Subheading of a symbol defaults to its name.
1474 DeclarationFragments Fragments;
1476 return Fragments;
1477}
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines the Declaration Fragments related classes.
int Category
Definition: Format.cpp:2980
const CFGBlock * Block
Definition: HTMLLogger.cpp:153
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 ...
Definition: ASTContext.h:182
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
Definition: ASTContext.h:2176
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3146
Type source information for an attributed type.
Definition: TypeLoc.h:875
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:4671
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4455
Wrapper for source info for block pointers.
Definition: TypeLoc.h:1288
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2855
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2053
bool isVolatile() const
Definition: DeclCXX.h:2106
bool isConst() const
Definition: DeclCXX.h:2105
bool isStatic() const
Definition: DeclCXX.cpp:2183
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
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.
Definition: Type.h:3185
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition: DeclBase.cpp:227
DeclContext * getDeclContext()
Definition: DeclBase.h:453
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:799
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:5913
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3265
Represents an enum.
Definition: Decl.h:3832
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:3992
Represents a member of a struct/union/class.
Definition: Decl.h:3025
Represents a function declaration or definition.
Definition: Decl.h:1959
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2674
ExceptionSpecificationType getExceptionSpecType() const
Gets the ExceptionSpecificationType as declared.
Definition: Decl.h:2746
QualType getReturnType() const
Definition: Decl.h:2722
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition: Decl.h:2407
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3647
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:4554
Declaration of a template function.
Definition: DeclTemplate.h:958
Wrapper for source info for functions.
Definition: TypeLoc.h:1402
StringRef getName() const
Return the actual identifier string.
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:514
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3052
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:416
This represents a decl that may have a name.
Definition: Decl.h:249
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
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:292
Represents a C++ namespace alias.
Definition: DeclCXX.h:3113
Represent a C++ namespace.
Definition: Decl.h:547
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
Definition: Decl.h:605
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:2323
Represents an ObjC class declaration.
Definition: DeclObjC.h:1150
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
unsigned param_size() const
Definition: DeclObjC.h:347
Selector getSelector() const
Definition: DeclObjC.h:327
bool isInstanceMethod() const
Definition: DeclObjC.h:426
ParmVarDecl * getParamDecl(unsigned Idx)
Definition: DeclObjC.h:377
QualType getReturnType() const
Definition: DeclObjC.h:329
bool isClassMethod() const
Definition: DeclObjC.h:434
Represents a pointer to an Objective C object.
Definition: Type.h:6550
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
Definition: Type.h:6625
bool isObjCIdOrClassType() const
True if this is equivalent to the 'id' or 'Class' type,.
Definition: Type.h:6619
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:729
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2079
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2152
Sugar for parentheses used when specifying types.
Definition: Type.h:2871
Represents a parameter to a function.
Definition: Decl.h:1749
bool isObjCMethodParameter() const
Definition: Decl.h:1792
A (possibly-)qualified type.
Definition: Type.h:737
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:804
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:6922
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition: Type.h:1124
Wrapper of type source information for a type with non-trivial direct qualifiers.
Definition: TypeLoc.h:289
The collection of all-type qualifiers we support.
Definition: Type.h:147
bool hasConst() const
Definition: Type.h:264
bool hasRestrict() const
Definition: Type.h:284
bool hasVolatile() const
Definition: Type.h:274
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3070
Represents a struct/union/class.
Definition: Decl.h:4133
Declaration of a redeclarable template.
Definition: DeclTemplate.h:717
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:3549
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3777
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:413
ArrayRef< NamedDecl * > asArray()
Definition: DeclTemplate.h:139
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:59
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
Definition: TypeLoc.h:338
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:89
TypeLoc IgnoreParens() const
Definition: TypeLoc.h:1199
A container of type source information.
Definition: Type.h:6872
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:256
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6883
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Definition: Type.cpp:3138
The base class of the type hierarchy.
Definition: Type.h:1606
bool isBlockPointerType() const
Definition: Type.h:7161
bool isFunctionPointerType() const
Definition: Type.h:7187
bool isPointerType() const
Definition: Type.h:7153
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:651
bool isObjCIdType() const
Definition: Type.h:7314
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition: Type.h:7705
bool isObjCObjectPointerType() const
Definition: Type.h:7281
bool isAnyPointerType() const
Definition: Type.h:7157
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7652
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3399
QualType getType() const
Definition: Decl.h:717
Represents a variable declaration or definition.
Definition: Decl.h:918
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition: Decl.cpp:2777
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1546
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
Definition: Decl.cpp:2118
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition: Decl.h:1267
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1152
Represents a variable template specialization, which refers to a variable template with a given set o...
static DeclarationFragments getFragmentsForRedeclarableTemplate(const RedeclarableTemplateDecl *)
static DeclarationFragments getFragmentsForCXXClass(const CXXRecordDecl *)
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 getFragmentsForConversionFunction(const CXXConversionDecl *)
static DeclarationFragments getFragmentsForClassTemplateSpecialization(const ClassTemplateSpecializationDecl *)
static DeclarationFragments getFragmentsForTemplateParameters(ArrayRef< NamedDecl * >)
static DeclarationFragments getFragmentsForObjCProtocol(const ObjCProtocolDecl *)
Build DeclarationFragments for an Objective-C protocol declaration ObjCProtocolDecl.
static DeclarationFragments getFragmentsForConcept(const ConceptDecl *)
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 getFragmentsForClassTemplatePartialSpecialization(const ClassTemplatePartialSpecializationDecl *)
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 getFragmentsForSpecialCXXMethod(const CXXMethodDecl *)
static DeclarationFragments getFragmentsForCXXMethod(const CXXMethodDecl *)
static DeclarationFragments getFragmentsForNamespace(const NamespaceDecl *Decl)
static DeclarationFragments getFragmentsForTemplateArguments(const ArrayRef< TemplateArgument >, ASTContext &, const std::optional< ArrayRef< NamedDecl * > >)
static DeclarationFragments getFragmentsForVarTemplatePartialSpecialization(const VarTemplatePartialSpecializationDecl *)
static DeclarationFragments getFragmentsForFunctionTemplate(const FunctionTemplateDecl *Decl)
static DeclarationFragments getFragmentsForVarTemplateSpecialization(const VarTemplateSpecializationDecl *)
static FunctionSignature getFunctionSignature(const FunctionT *Function)
Build FunctionSignature for a function-like declaration FunctionT like FunctionDecl,...
static DeclarationFragments getSubHeading(const NamedDecl *)
Build sub-heading fragments for a NamedDecl.
static DeclarationFragments getFragmentsForVarTemplate(const VarDecl *)
static std::string getNameForTemplateArgument(const ArrayRef< NamedDecl * >, std::string)
static DeclarationFragments getFragmentsForOverloadedOperator(const CXXMethodDecl *)
static DeclarationFragments getFragmentsForFunctionTemplateSpecialization(const FunctionDecl *Decl)
static DeclarationFragments getFragmentsForMacro(StringRef Name, const MacroDirective *MD)
Build DeclarationFragments for a macro.
static DeclarationFragments getFragmentsForRecordDecl(const RecordDecl *)
Build DeclarationFragments for a struct/union record declaration RecordDecl.
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.
static DeclarationFragments getExceptionSpecificationString(ExceptionSpecificationType ExceptionSpec)
@ 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 DeclarationFragments getStructureTypeFragment(const RecordDecl *Decl)
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.
@ 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:245
@ SC_Auto
Definition: Specifiers.h:253
@ SC_PrivateExtern
Definition: Specifiers.h:250
@ SC_Extern
Definition: Specifiers.h:248
@ SC_Register
Definition: Specifiers.h:254
@ SC_Static
Definition: Specifiers.h:249
@ SC_None
Definition: Specifiers.h:247
@ 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)
Definition: SyncScope.h:60
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:5816
@ 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_DynamicNone
throw()
@ 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.
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:670
const Type * Ty
The locally-unqualified type.
Definition: Type.h:672
Qualifiers Quals
The local qualifiers.
Definition: Type.h:675
Fragment holds information of a single fragment.