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"
17#include "clang/AST/Type.h"
18#include "clang/AST/TypeLoc.h"
21#include "llvm/ADT/StringSwitch.h"
22
23using namespace clang::extractapi;
24using namespace llvm;
25
26namespace {
27
28void findTypeLocForBlockDecl(const clang::TypeSourceInfo *TSInfo,
30 clang::FunctionProtoTypeLoc &BlockProto) {
31 if (!TSInfo)
32 return;
33
35 while (true) {
36 // Look through qualified types
37 if (auto QualifiedTL = TL.getAs<clang::QualifiedTypeLoc>()) {
38 TL = QualifiedTL.getUnqualifiedLoc();
39 continue;
40 }
41
42 if (auto AttrTL = TL.getAs<clang::AttributedTypeLoc>()) {
43 TL = AttrTL.getModifiedLoc();
44 continue;
45 }
46
47 // Try to get the function prototype behind the block pointer type,
48 // then we're done.
49 if (auto BlockPtr = TL.getAs<clang::BlockPointerTypeLoc>()) {
50 TL = BlockPtr.getPointeeLoc().IgnoreParens();
52 BlockProto = TL.getAs<clang::FunctionProtoTypeLoc>();
53 }
54 break;
55 }
56}
57
58} // namespace
59
61DeclarationFragments::appendUnduplicatedTextCharacter(char Character) {
62 if (!Fragments.empty()) {
63 Fragment &Last = Fragments.back();
64 if (Last.Kind == FragmentKind::Text) {
65 // Merge the extra space into the last fragment if the last fragment is
66 // also text.
67 if (Last.Spelling.back() != Character) { // avoid duplicates at end
68 Last.Spelling.push_back(Character);
69 }
70 } else {
72 Fragments.back().Spelling.push_back(Character);
73 }
74 }
75
76 return *this;
77}
78
80 return appendUnduplicatedTextCharacter(' ');
81}
82
84 return appendUnduplicatedTextCharacter(';');
85}
86
88 if (Fragments.empty())
89 return *this;
90
91 Fragment &Last = Fragments.back();
92 if (Last.Kind == FragmentKind::Text && Last.Spelling.back() == ';')
93 Last.Spelling.pop_back();
94
95 return *this;
96}
97
100 switch (Kind) {
102 return "none";
104 return "keyword";
106 return "attribute";
108 return "number";
110 return "string";
112 return "identifier";
114 return "typeIdentifier";
116 return "genericParameter";
118 return "externalParam";
120 return "internalParam";
122 return "text";
123 }
124
125 llvm_unreachable("Unhandled FragmentKind");
126}
127
130 return llvm::StringSwitch<FragmentKind>(S)
136 .Case("typeIdentifier",
138 .Case("genericParameter",
144}
145
147 ExceptionSpecificationType ExceptionSpec) {
148 DeclarationFragments Fragments;
149 switch (ExceptionSpec) {
151 return Fragments;
158 // FIXME: throw(int), get types of inner expression
159 return Fragments;
164 // FIXME: throw(conditional-expression), get expression
165 break;
178 default:
179 return Fragments;
180 }
181
182 llvm_unreachable("Unhandled exception specification");
183}
184
187 DeclarationFragments Fragments;
188 if (Record->isStruct())
190 else if (Record->isUnion())
192 else
194
195 return Fragments;
196}
197
198// NNS stores C++ nested name specifiers, which are prefixes to qualified names.
199// Build declaration fragments for NNS recursively so that we have the USR for
200// every part in a qualified name, and also leaves the actual underlying type
201// cleaner for its own fragment.
203DeclarationFragmentsBuilder::getFragmentsForNNS(const NestedNameSpecifier *NNS,
204 ASTContext &Context,
205 DeclarationFragments &After) {
206 DeclarationFragments Fragments;
207 if (NNS->getPrefix())
208 Fragments.append(getFragmentsForNNS(NNS->getPrefix(), Context, After));
209
210 switch (NNS->getKind()) {
212 Fragments.append(NNS->getAsIdentifier()->getName(),
214 break;
215
217 const NamespaceDecl *NS = NNS->getAsNamespace();
218 if (NS->isAnonymousNamespace())
219 return Fragments;
222 Fragments.append(NS->getName(),
224 break;
225 }
226
228 const NamespaceAliasDecl *Alias = NNS->getAsNamespaceAlias();
230 index::generateUSRForDecl(Alias, USR);
231 Fragments.append(Alias->getName(),
233 Alias);
234 break;
235 }
236
238 // The global specifier `::` at the beginning. No stored value.
239 break;
240
242 // Microsoft's `__super` specifier.
244 break;
245
247 // A type prefixed by the `template` keyword.
249 Fragments.appendSpace();
250 // Fallthrough after adding the keyword to handle the actual type.
251 [[fallthrough]];
252
254 const Type *T = NNS->getAsType();
255 // FIXME: Handle C++ template specialization type
256 Fragments.append(getFragmentsForType(T, Context, After));
257 break;
258 }
259 }
260
261 // Add the separator text `::` for this segment.
262 return Fragments.append("::", DeclarationFragments::FragmentKind::Text);
263}
264
265// Recursively build the declaration fragments for an underlying `Type` with
266// qualifiers removed.
267DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
268 const Type *T, ASTContext &Context, DeclarationFragments &After) {
269 assert(T && "invalid type");
270
271 DeclarationFragments Fragments;
272
273 // An ElaboratedType is a sugar for types that are referred to using an
274 // elaborated keyword, e.g., `struct S`, `enum E`, or (in C++) via a
275 // qualified name, e.g., `N::M::type`, or both.
276 if (const ElaboratedType *ET = dyn_cast<ElaboratedType>(T)) {
277 ElaboratedTypeKeyword Keyword = ET->getKeyword();
278 if (Keyword != ElaboratedTypeKeyword::None) {
279 Fragments
282 .appendSpace();
283 }
284
285 if (const NestedNameSpecifier *NNS = ET->getQualifier())
286 Fragments.append(getFragmentsForNNS(NNS, Context, After));
287
288 // After handling the elaborated keyword or qualified name, build
289 // declaration fragments for the desugared underlying type.
290 return Fragments.append(getFragmentsForType(ET->desugar(), Context, After));
291 }
292
293 // If the type is a typedefed type, get the underlying TypedefNameDecl for a
294 // direct reference to the typedef instead of the wrapped type.
295
296 // 'id' type is a typedef for an ObjCObjectPointerType
297 // we treat it as a typedef
298 if (const TypedefType *TypedefTy = dyn_cast<TypedefType>(T)) {
299 const TypedefNameDecl *Decl = TypedefTy->getDecl();
300 TypedefUnderlyingTypeResolver TypedefResolver(Context);
301 std::string USR = TypedefResolver.getUSRForType(QualType(T, 0));
302
303 if (T->isObjCIdType()) {
304 return Fragments.append(Decl->getName(),
306 }
307
308 return Fragments.append(
310 USR, TypedefResolver.getUnderlyingTypeDecl(QualType(T, 0)));
311 }
312
313 // Declaration fragments of a pointer type is the declaration fragments of
314 // the pointee type followed by a `*`,
316 return Fragments
317 .append(getFragmentsForType(T->getPointeeType(), Context, After))
319
320 // For Objective-C `id` and `Class` pointers
321 // we do not spell out the `*`.
322 if (T->isObjCObjectPointerType() &&
324
325 Fragments.append(getFragmentsForType(T->getPointeeType(), Context, After));
326
327 // id<protocol> is an qualified id type
328 // id<protocol>* is not an qualified id type
331 }
332
333 return Fragments;
334 }
335
336 // Declaration fragments of a lvalue reference type is the declaration
337 // fragments of the underlying type followed by a `&`.
338 if (const LValueReferenceType *LRT = dyn_cast<LValueReferenceType>(T))
339 return Fragments
340 .append(
341 getFragmentsForType(LRT->getPointeeTypeAsWritten(), Context, After))
343
344 // Declaration fragments of a rvalue reference type is the declaration
345 // fragments of the underlying type followed by a `&&`.
346 if (const RValueReferenceType *RRT = dyn_cast<RValueReferenceType>(T))
347 return Fragments
348 .append(
349 getFragmentsForType(RRT->getPointeeTypeAsWritten(), Context, After))
351
352 // Declaration fragments of an array-typed variable have two parts:
353 // 1. the element type of the array that appears before the variable name;
354 // 2. array brackets `[(0-9)?]` that appear after the variable name.
355 if (const ArrayType *AT = T->getAsArrayTypeUnsafe()) {
356 // Build the "after" part first because the inner element type might also
357 // be an array-type. For example `int matrix[3][4]` which has a type of
358 // "(array 3 of (array 4 of ints))."
359 // Push the array size part first to make sure they are in the right order.
361
362 switch (AT->getSizeModifier()) {
364 break;
367 break;
370 break;
371 }
372
373 if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) {
374 // FIXME: right now this would evaluate any expressions/macros written in
375 // the original source to concrete values. For example
376 // `int nums[MAX]` -> `int nums[100]`
377 // `char *str[5 + 1]` -> `char *str[6]`
379 CAT->getSize().toStringUnsigned(Size);
381 }
382
384
385 return Fragments.append(
386 getFragmentsForType(AT->getElementType(), Context, After));
387 }
388
389 // Everything we care about has been handled now, reduce to the canonical
390 // unqualified base type.
392
393 // If the base type is a TagType (struct/interface/union/class/enum), let's
394 // get the underlying Decl for better names and USRs.
395 if (const TagType *TagTy = dyn_cast<TagType>(Base)) {
396 const TagDecl *Decl = TagTy->getDecl();
397 // Anonymous decl, skip this fragment.
398 if (Decl->getName().empty())
399 return Fragments.append("{ ... }",
401 SmallString<128> TagUSR;
403 return Fragments.append(Decl->getName(),
405 TagUSR, Decl);
406 }
407
408 // If the base type is an ObjCInterfaceType, use the underlying
409 // ObjCInterfaceDecl for the true USR.
410 if (const auto *ObjCIT = dyn_cast<ObjCInterfaceType>(Base)) {
411 const auto *Decl = ObjCIT->getDecl();
414 return Fragments.append(Decl->getName(),
416 USR, Decl);
417 }
418
419 // Default fragment builder for other kinds of types (BuiltinType etc.)
422 Fragments.append(Base.getAsString(),
424
425 return Fragments;
426}
427
429DeclarationFragmentsBuilder::getFragmentsForQualifiers(const Qualifiers Quals) {
430 DeclarationFragments Fragments;
431 if (Quals.hasConst())
433 if (Quals.hasVolatile())
435 if (Quals.hasRestrict())
437
438 return Fragments;
439}
440
441DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
442 const QualType QT, ASTContext &Context, DeclarationFragments &After) {
443 assert(!QT.isNull() && "invalid type");
444
445 if (const ParenType *PT = dyn_cast<ParenType>(QT)) {
447 return getFragmentsForType(PT->getInnerType(), Context, After)
449 }
450
451 const SplitQualType SQT = QT.split();
452 DeclarationFragments QualsFragments = getFragmentsForQualifiers(SQT.Quals),
453 TypeFragments =
454 getFragmentsForType(SQT.Ty, Context, After);
455 if (QT.getAsString() == "_Bool")
456 TypeFragments.replace("bool", 0);
457
458 if (QualsFragments.getFragments().empty())
459 return TypeFragments;
460
461 // Use east qualifier for pointer types
462 // For example:
463 // ```
464 // int * const
465 // ^---- ^----
466 // type qualifier
467 // ^-----------------
468 // const pointer to int
469 // ```
470 // should not be reconstructed as
471 // ```
472 // const int *
473 // ^---- ^--
474 // qualifier type
475 // ^---------------- ^
476 // pointer to const int
477 // ```
478 if (SQT.Ty->isAnyPointerType())
479 return TypeFragments.appendSpace().append(std::move(QualsFragments));
480
481 return QualsFragments.appendSpace().append(std::move(TypeFragments));
482}
483
485 const NamespaceDecl *Decl) {
486 DeclarationFragments Fragments;
488 if (!Decl->isAnonymousNamespace())
489 Fragments.appendSpace().append(
491 return Fragments.appendSemicolon();
492}
493
496 DeclarationFragments Fragments;
497 if (Var->isConstexpr())
499 .appendSpace();
500
501 StorageClass SC = Var->getStorageClass();
502 if (SC != SC_None)
503 Fragments
506 .appendSpace();
507
508 // Capture potential fragments that needs to be placed after the variable name
509 // ```
510 // int nums[5];
511 // char (*ptr_to_array)[6];
512 // ```
514 FunctionTypeLoc BlockLoc;
515 FunctionProtoTypeLoc BlockProtoLoc;
516 findTypeLocForBlockDecl(Var->getTypeSourceInfo(), BlockLoc, BlockProtoLoc);
517
518 if (!BlockLoc) {
520 ? Var->getTypeSourceInfo()->getType()
522 Var->getType());
523
524 Fragments.append(getFragmentsForType(T, Var->getASTContext(), After))
525 .appendSpace();
526 } else {
527 Fragments.append(getFragmentsForBlock(Var, BlockLoc, BlockProtoLoc, After));
528 }
529
530 return Fragments
532 .append(std::move(After))
534}
535
538 DeclarationFragments Fragments;
539 if (Var->isConstexpr())
541 .appendSpace();
542 QualType T =
543 Var->getTypeSourceInfo()
544 ? Var->getTypeSourceInfo()->getType()
546
547 // Might be a member, so might be static.
548 if (Var->isStaticDataMember())
550 .appendSpace();
551
553 DeclarationFragments ArgumentFragment =
554 getFragmentsForType(T, Var->getASTContext(), After);
555 if (StringRef(ArgumentFragment.begin()->Spelling)
556 .starts_with("type-parameter")) {
557 std::string ProperArgName = T.getAsString();
558 ArgumentFragment.begin()->Spelling.swap(ProperArgName);
559 }
560 Fragments.append(std::move(ArgumentFragment))
561 .appendSpace()
564 return Fragments;
565}
566
568DeclarationFragmentsBuilder::getFragmentsForParam(const ParmVarDecl *Param) {
569 DeclarationFragments Fragments, After;
570
571 auto *TSInfo = Param->getTypeSourceInfo();
572
573 QualType T = TSInfo ? TSInfo->getType()
575 Param->getType());
576
577 FunctionTypeLoc BlockLoc;
578 FunctionProtoTypeLoc BlockProtoLoc;
579 findTypeLocForBlockDecl(TSInfo, BlockLoc, BlockProtoLoc);
580
581 DeclarationFragments TypeFragments;
582 if (BlockLoc)
583 TypeFragments.append(
584 getFragmentsForBlock(Param, BlockLoc, BlockProtoLoc, After));
585 else
586 TypeFragments.append(getFragmentsForType(T, Param->getASTContext(), After));
587
588 if (StringRef(TypeFragments.begin()->Spelling)
589 .starts_with("type-parameter")) {
590 std::string ProperArgName = Param->getOriginalType().getAsString();
591 TypeFragments.begin()->Spelling.swap(ProperArgName);
592 }
593
594 if (Param->isObjCMethodParameter()) {
596 .append(std::move(TypeFragments))
597 .append(std::move(After))
599 .append(Param->getName(),
601 } else {
602 Fragments.append(std::move(TypeFragments));
603 if (!T->isBlockPointerType())
604 Fragments.appendSpace();
605 Fragments
606 .append(Param->getName(),
608 .append(std::move(After));
609 }
610 return Fragments;
611}
612
613DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForBlock(
615 FunctionProtoTypeLoc &BlockProto, DeclarationFragments &After) {
616 DeclarationFragments Fragments;
617
618 DeclarationFragments RetTyAfter;
619 auto ReturnValueFragment = getFragmentsForType(
620 Block.getTypePtr()->getReturnType(), BlockDecl->getASTContext(), After);
621
622 Fragments.append(std::move(ReturnValueFragment))
623 .append(std::move(RetTyAfter))
624 .appendSpace()
626
628 unsigned NumParams = Block.getNumParams();
629
630 if (!BlockProto || NumParams == 0) {
631 if (BlockProto && BlockProto.getTypePtr()->isVariadic())
633 else
635 } else {
637 for (unsigned I = 0; I != NumParams; ++I) {
638 if (I)
640 After.append(getFragmentsForParam(Block.getParam(I)));
641 if (I == NumParams - 1 && BlockProto.getTypePtr()->isVariadic())
643 }
645 }
646
647 return Fragments;
648}
649
652 DeclarationFragments Fragments;
653 // FIXME: Handle template specialization
654 switch (Func->getStorageClass()) {
655 case SC_None:
656 case SC_PrivateExtern:
657 break;
658 case SC_Extern:
660 .appendSpace();
661 break;
662 case SC_Static:
664 .appendSpace();
665 break;
666 case SC_Auto:
667 case SC_Register:
668 llvm_unreachable("invalid for functions");
669 }
670 if (Func->isConsteval()) // if consteval, it is also constexpr
672 .appendSpace();
673 else if (Func->isConstexpr())
675 .appendSpace();
676
677 // FIXME: Is `after` actually needed here?
679 auto ReturnValueFragment =
680 getFragmentsForType(Func->getReturnType(), Func->getASTContext(), After);
681 if (StringRef(ReturnValueFragment.begin()->Spelling)
682 .starts_with("type-parameter")) {
683 std::string ProperArgName = Func->getReturnType().getAsString();
684 ReturnValueFragment.begin()->Spelling.swap(ProperArgName);
685 }
686
687 Fragments.append(std::move(ReturnValueFragment))
688 .appendSpace()
690
691 if (Func->getTemplateSpecializationInfo()) {
693
694 for (unsigned i = 0, end = Func->getNumParams(); i != end; ++i) {
695 if (i)
697 Fragments.append(
698 getFragmentsForType(Func->getParamDecl(i)->getType(),
699 Func->getParamDecl(i)->getASTContext(), After));
700 }
702 }
703 Fragments.append(std::move(After));
704
706 unsigned NumParams = Func->getNumParams();
707 for (unsigned i = 0; i != NumParams; ++i) {
708 if (i)
710 Fragments.append(getFragmentsForParam(Func->getParamDecl(i)));
711 }
712
713 if (Func->isVariadic()) {
714 if (NumParams > 0)
717 }
719
721 Func->getExceptionSpecType()));
722
723 return Fragments.appendSemicolon();
724}
725
727 const EnumConstantDecl *EnumConstDecl) {
728 DeclarationFragments Fragments;
729 return Fragments.append(EnumConstDecl->getName(),
731}
732
737
738 DeclarationFragments Fragments, After;
740
741 if (!EnumDecl->getName().empty())
742 Fragments.appendSpace().append(
744
745 QualType IntegerType = EnumDecl->getIntegerType();
746 if (!IntegerType.isNull())
747 Fragments.appendSpace()
749 .append(
750 getFragmentsForType(IntegerType, EnumDecl->getASTContext(), After))
751 .append(std::move(After));
752
753 if (EnumDecl->getName().empty())
754 Fragments.appendSpace().append("{ ... }",
756
757 return Fragments.appendSemicolon();
758}
759
763 DeclarationFragments Fragments;
764 if (Field->isMutable())
766 .appendSpace();
767 return Fragments
768 .append(
769 getFragmentsForType(Field->getType(), Field->getASTContext(), After))
770 .appendSpace()
772 .append(std::move(After))
774}
775
777 const RecordDecl *Record) {
778 if (const auto *TypedefNameDecl = Record->getTypedefNameForAnonDecl())
780
781 DeclarationFragments Fragments;
782 if (Record->isUnion())
784 else
786
787 Fragments.appendSpace();
788 if (!Record->getName().empty())
789 Fragments.append(Record->getName(),
791 else
793
794 return Fragments.appendSemicolon();
795}
796
798 const CXXRecordDecl *Record) {
799 if (const auto *TypedefNameDecl = Record->getTypedefNameForAnonDecl())
801
802 DeclarationFragments Fragments;
804
805 if (!Record->getName().empty())
806 Fragments.appendSpace().append(
808
809 return Fragments.appendSemicolon();
810}
811
814 const CXXMethodDecl *Method) {
815 DeclarationFragments Fragments;
816 std::string Name;
817 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(Method)) {
818 Name = Method->getNameAsString();
819 if (Constructor->isExplicit())
821 .appendSpace();
822 } else if (isa<CXXDestructorDecl>(Method))
823 Name = Method->getNameAsString();
824
827 .append(std::move(After));
829 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
830 if (i)
832 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
833 }
835
837 Method->getExceptionSpecType()));
838
839 return Fragments.appendSemicolon();
840}
841
843 const CXXMethodDecl *Method) {
844 DeclarationFragments Fragments;
845 StringRef Name = Method->getName();
846 if (Method->isStatic())
848 .appendSpace();
849 if (Method->isConstexpr())
851 .appendSpace();
852 if (Method->isVolatile())
854 .appendSpace();
855
856 // Build return type
858 Fragments
859 .append(getFragmentsForType(Method->getReturnType(),
860 Method->getASTContext(), After))
861 .appendSpace()
863 .append(std::move(After));
865 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
866 if (i)
868 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
869 }
871
872 if (Method->isConst())
873 Fragments.appendSpace().append("const",
875
877 Method->getExceptionSpecType()));
878
879 return Fragments.appendSemicolon();
880}
881
884 const CXXConversionDecl *ConversionFunction) {
885 DeclarationFragments Fragments;
886
887 if (ConversionFunction->isExplicit())
889 .appendSpace();
890
892 .appendSpace();
893
894 Fragments
895 .append(ConversionFunction->getConversionType().getAsString(),
898 for (unsigned i = 0, end = ConversionFunction->getNumParams(); i != end;
899 ++i) {
900 if (i)
902 Fragments.append(getFragmentsForParam(ConversionFunction->getParamDecl(i)));
903 }
905
906 if (ConversionFunction->isConst())
907 Fragments.appendSpace().append("const",
909
910 return Fragments.appendSemicolon();
911}
912
915 const CXXMethodDecl *Method) {
916 DeclarationFragments Fragments;
917
918 // Build return type
920 Fragments
921 .append(getFragmentsForType(Method->getReturnType(),
922 Method->getASTContext(), After))
923 .appendSpace()
924 .append(Method->getNameAsString(),
926 .append(std::move(After));
928 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
929 if (i)
931 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
932 }
934
935 if (Method->isConst())
936 Fragments.appendSpace().append("const",
938
940 Method->getExceptionSpecType()));
941
942 return Fragments.appendSemicolon();
943}
944
945// Get fragments for template parameters, e.g. T in tempalte<typename T> ...
948 ArrayRef<NamedDecl *> ParameterArray) {
949 DeclarationFragments Fragments;
950 for (unsigned i = 0, end = ParameterArray.size(); i != end; ++i) {
951 if (i)
953 .appendSpace();
954
955 const auto *TemplateParam =
956 dyn_cast<TemplateTypeParmDecl>(ParameterArray[i]);
957 if (!TemplateParam)
958 continue;
959 if (TemplateParam->hasTypeConstraint())
960 Fragments.append(TemplateParam->getTypeConstraint()
961 ->getNamedConcept()
962 ->getName()
963 .str(),
965 else if (TemplateParam->wasDeclaredWithTypename())
967 else
969
970 if (TemplateParam->isParameterPack())
972
973 Fragments.appendSpace().append(
974 TemplateParam->getName(),
976 }
977 return Fragments;
978}
979
980// Get fragments for template arguments, e.g. int in template<typename T>
981// Foo<int>;
982//
983// Note: TemplateParameters is only necessary if the Decl is a
984// PartialSpecialization, where we need the parameters to deduce the name of the
985// generic arguments.
988 const ArrayRef<TemplateArgument> TemplateArguments, ASTContext &Context,
989 const std::optional<ArrayRef<TemplateArgumentLoc>> TemplateArgumentLocs) {
990 DeclarationFragments Fragments;
991 for (unsigned i = 0, end = TemplateArguments.size(); i != end; ++i) {
992 if (i)
994 .appendSpace();
995
996 std::string Type = TemplateArguments[i].getAsType().getAsString();
998 DeclarationFragments ArgumentFragment =
999 getFragmentsForType(TemplateArguments[i].getAsType(), Context, After);
1000
1001 if (StringRef(ArgumentFragment.begin()->Spelling)
1002 .starts_with("type-parameter")) {
1003 std::string ProperArgName = TemplateArgumentLocs.value()[i]
1004 .getTypeSourceInfo()
1005 ->getType()
1006 .getAsString();
1007 ArgumentFragment.begin()->Spelling.swap(ProperArgName);
1008 }
1009 Fragments.append(std::move(ArgumentFragment));
1010
1011 if (TemplateArguments[i].isPackExpansion())
1013 }
1014 return Fragments;
1015}
1016
1018 const ConceptDecl *Concept) {
1019 DeclarationFragments Fragments;
1020 return Fragments
1024 Concept->getTemplateParameters()->asArray()))
1027 .appendSpace()
1028 .append(Concept->getName().str(),
1030 .appendSemicolon();
1031}
1032
1035 const RedeclarableTemplateDecl *RedeclarableTemplate) {
1036 DeclarationFragments Fragments;
1040 RedeclarableTemplate->getTemplateParameters()->asArray()))
1042 .appendSpace();
1043
1044 if (isa<TypeAliasTemplateDecl>(RedeclarableTemplate))
1045 Fragments.appendSpace()
1047 .appendSpace()
1048 .append(RedeclarableTemplate->getName(),
1050 // the templated records will be resposbible for injecting their templates
1051 return Fragments.appendSpace();
1052}
1053
1057 DeclarationFragments Fragments;
1058 return Fragments
1062 .appendSpace()
1064 cast<CXXRecordDecl>(Decl)))
1065 .pop_back() // there is an extra semicolon now
1067 .append(
1068 getFragmentsForTemplateArguments(Decl->getTemplateArgs().asArray(),
1069 Decl->getASTContext(), std::nullopt))
1071 .appendSemicolon();
1072}
1073
1077 DeclarationFragments Fragments;
1078 return Fragments
1082 Decl->getTemplateParameters()->asArray()))
1084 .appendSpace()
1086 cast<CXXRecordDecl>(Decl)))
1087 .pop_back() // there is an extra semicolon now
1090 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1091 Decl->getTemplateArgsAsWritten()->arguments()))
1093 .appendSemicolon();
1094}
1095
1099 DeclarationFragments Fragments;
1100 return Fragments
1104 .appendSpace()
1106 .pop_back() // there is an extra semicolon now
1108 .append(
1109 getFragmentsForTemplateArguments(Decl->getTemplateArgs().asArray(),
1110 Decl->getASTContext(), std::nullopt))
1112 .appendSemicolon();
1113}
1114
1118 DeclarationFragments Fragments;
1119 return Fragments
1122 // Partial specs may have new params.
1124 Decl->getTemplateParameters()->asArray()))
1126 .appendSpace()
1128 .pop_back() // there is an extra semicolon now
1131 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1132 Decl->getTemplateArgsAsWritten()->arguments()))
1134 .appendSemicolon();
1135}
1136
1139 const FunctionTemplateDecl *Decl) {
1140 DeclarationFragments Fragments;
1141 return Fragments
1144 // Partial specs may have new params.
1146 Decl->getTemplateParameters()->asArray()))
1148 .appendSpace()
1150 Decl->getAsFunction()));
1151}
1152
1155 const FunctionDecl *Decl) {
1156 DeclarationFragments Fragments;
1157 return Fragments
1160 .appendSpace()
1162}
1163
1166 const MacroDirective *MD) {
1167 DeclarationFragments Fragments;
1169 .appendSpace();
1171
1172 auto *MI = MD->getMacroInfo();
1173
1174 if (MI->isFunctionLike()) {
1176 unsigned numParameters = MI->getNumParams();
1177 if (MI->isC99Varargs())
1178 --numParameters;
1179 for (unsigned i = 0; i < numParameters; ++i) {
1180 if (i)
1182 Fragments.append(MI->params()[i]->getName(),
1184 }
1185 if (MI->isVariadic()) {
1186 if (numParameters && MI->isC99Varargs())
1189 }
1191 }
1192 return Fragments;
1193}
1194
1196 const ObjCCategoryDecl *Category) {
1197 DeclarationFragments Fragments;
1198
1199 auto *Interface = Category->getClassInterface();
1200 SmallString<128> InterfaceUSR;
1201 index::generateUSRForDecl(Interface, InterfaceUSR);
1202
1204 .appendSpace()
1205 .append(Interface->getName(),
1207 Interface)
1209 .append(Category->getName(),
1212
1213 return Fragments;
1214}
1215
1218 DeclarationFragments Fragments;
1219 // Build the base of the Objective-C interface declaration.
1221 .appendSpace()
1222 .append(Interface->getName(),
1224
1225 // Build the inheritance part of the declaration.
1226 if (const ObjCInterfaceDecl *SuperClass = Interface->getSuperClass()) {
1227 SmallString<128> SuperUSR;
1228 index::generateUSRForDecl(SuperClass, SuperUSR);
1230 .append(SuperClass->getName(),
1232 SuperClass);
1233 }
1234
1235 return Fragments;
1236}
1237
1239 const ObjCMethodDecl *Method) {
1240 DeclarationFragments Fragments, After;
1241 // Build the instance/class method indicator.
1242 if (Method->isClassMethod())
1244 else if (Method->isInstanceMethod())
1246
1247 // Build the return type.
1249 .append(getFragmentsForType(Method->getReturnType(),
1250 Method->getASTContext(), After))
1251 .append(std::move(After))
1253
1254 // Build the selector part.
1255 Selector Selector = Method->getSelector();
1256 if (Selector.getNumArgs() == 0)
1257 // For Objective-C methods that don't take arguments, the first (and only)
1258 // slot of the selector is the method name.
1259 Fragments.appendSpace().append(
1262
1263 // For Objective-C methods that take arguments, build the selector slots.
1264 for (unsigned i = 0, end = Method->param_size(); i != end; ++i) {
1265 // Objective-C method selector parts are considered as identifiers instead
1266 // of "external parameters" as in Swift. This is because Objective-C method
1267 // symbols are referenced with the entire selector, instead of just the
1268 // method name in Swift.
1270 ParamID.append(":");
1271 Fragments.appendSpace().append(
1273
1274 // Build the internal parameter.
1275 const ParmVarDecl *Param = Method->getParamDecl(i);
1276 Fragments.append(getFragmentsForParam(Param));
1277 }
1278
1279 return Fragments.appendSemicolon();
1280}
1281
1283 const ObjCPropertyDecl *Property) {
1284 DeclarationFragments Fragments, After;
1285
1286 // Build the Objective-C property keyword.
1288
1289 const auto Attributes = Property->getPropertyAttributesAsWritten();
1290 // Build the attributes if there is any associated with the property.
1291 if (Attributes != ObjCPropertyAttribute::kind_noattr) {
1292 // No leading comma for the first attribute.
1293 bool First = true;
1295 // Helper function to render the attribute.
1296 auto RenderAttribute =
1297 [&](ObjCPropertyAttribute::Kind Kind, StringRef Spelling,
1298 StringRef Arg = "",
1301 // Check if the `Kind` attribute is set for this property.
1302 if ((Attributes & Kind) && !Spelling.empty()) {
1303 // Add a leading comma if this is not the first attribute rendered.
1304 if (!First)
1306 // Render the spelling of this attribute `Kind` as a keyword.
1307 Fragments.append(Spelling,
1309 // If this attribute takes in arguments (e.g. `getter=getterName`),
1310 // render the arguments.
1311 if (!Arg.empty())
1313 .append(Arg, ArgKind);
1314 First = false;
1315 }
1316 };
1317
1318 // Go through all possible Objective-C property attributes and render set
1319 // ones.
1320 RenderAttribute(ObjCPropertyAttribute::kind_class, "class");
1321 RenderAttribute(ObjCPropertyAttribute::kind_direct, "direct");
1322 RenderAttribute(ObjCPropertyAttribute::kind_nonatomic, "nonatomic");
1323 RenderAttribute(ObjCPropertyAttribute::kind_atomic, "atomic");
1324 RenderAttribute(ObjCPropertyAttribute::kind_assign, "assign");
1325 RenderAttribute(ObjCPropertyAttribute::kind_retain, "retain");
1326 RenderAttribute(ObjCPropertyAttribute::kind_strong, "strong");
1327 RenderAttribute(ObjCPropertyAttribute::kind_copy, "copy");
1328 RenderAttribute(ObjCPropertyAttribute::kind_weak, "weak");
1330 "unsafe_unretained");
1331 RenderAttribute(ObjCPropertyAttribute::kind_readwrite, "readwrite");
1332 RenderAttribute(ObjCPropertyAttribute::kind_readonly, "readonly");
1333 RenderAttribute(ObjCPropertyAttribute::kind_getter, "getter",
1334 Property->getGetterName().getAsString());
1335 RenderAttribute(ObjCPropertyAttribute::kind_setter, "setter",
1336 Property->getSetterName().getAsString());
1337
1338 // Render nullability attributes.
1339 if (Attributes & ObjCPropertyAttribute::kind_nullability) {
1340 QualType Type = Property->getType();
1341 if (const auto Nullability =
1343 if (!First)
1345 if (*Nullability == NullabilityKind::Unspecified &&
1347 Fragments.append("null_resettable",
1349 else
1350 Fragments.append(
1351 getNullabilitySpelling(*Nullability, /*isContextSensitive=*/true),
1353 First = false;
1354 }
1355 }
1356
1358 }
1359
1360 Fragments.appendSpace();
1361
1362 FunctionTypeLoc BlockLoc;
1363 FunctionProtoTypeLoc BlockProtoLoc;
1364 findTypeLocForBlockDecl(Property->getTypeSourceInfo(), BlockLoc,
1365 BlockProtoLoc);
1366
1367 auto PropType = Property->getType();
1368 if (!BlockLoc)
1369 Fragments
1370 .append(getFragmentsForType(PropType, Property->getASTContext(), After))
1371 .appendSpace();
1372 else
1373 Fragments.append(
1374 getFragmentsForBlock(Property, BlockLoc, BlockProtoLoc, After));
1375
1376 return Fragments
1377 .append(Property->getName(),
1379 .append(std::move(After))
1380 .appendSemicolon();
1381}
1382
1384 const ObjCProtocolDecl *Protocol) {
1385 DeclarationFragments Fragments;
1386 // Build basic protocol declaration.
1388 .appendSpace()
1389 .append(Protocol->getName(),
1391
1392 // If this protocol conforms to other protocols, build the conformance list.
1393 if (!Protocol->protocols().empty()) {
1395 for (ObjCProtocolDecl::protocol_iterator It = Protocol->protocol_begin();
1396 It != Protocol->protocol_end(); It++) {
1397 // Add a leading comma if this is not the first protocol rendered.
1398 if (It != Protocol->protocol_begin())
1400
1401 SmallString<128> USR;
1402 index::generateUSRForDecl(*It, USR);
1403 Fragments.append((*It)->getName(),
1405 *It);
1406 }
1408 }
1409
1410 return Fragments;
1411}
1412
1414 const TypedefNameDecl *Decl) {
1415 DeclarationFragments Fragments, After;
1417 .appendSpace()
1418 .append(getFragmentsForType(Decl->getUnderlyingType(),
1419 Decl->getASTContext(), After))
1420 .append(std::move(After))
1421 .appendSpace()
1423
1424 return Fragments.appendSemicolon();
1425}
1426
1427// Instantiate template for FunctionDecl.
1428template FunctionSignature
1430
1431// Instantiate template for ObjCMethodDecl.
1432template FunctionSignature
1434
1435// Subheading of a symbol defaults to its name.
1438 DeclarationFragments Fragments;
1439 if (isa<CXXConstructorDecl>(Decl) || isa<CXXDestructorDecl>(Decl))
1440 Fragments.append(cast<CXXRecordDecl>(Decl->getDeclContext())->getName(),
1442 else if (isa<CXXConversionDecl>(Decl)) {
1443 Fragments.append(
1444 cast<CXXConversionDecl>(Decl)->getConversionType().getAsString(),
1446 } else if (isa<CXXMethodDecl>(Decl) &&
1447 cast<CXXMethodDecl>(Decl)->isOverloadedOperator()) {
1448 Fragments.append(Decl->getNameAsString(),
1450 } else if (!Decl->getName().empty())
1451 Fragments.append(Decl->getName(),
1453 return Fragments;
1454}
1455
1456// Subheading of an Objective-C method is a `+` or `-` sign indicating whether
1457// it's a class method or an instance method, followed by the selector name.
1460 DeclarationFragments Fragments;
1461 if (Method->isClassMethod())
1463 else if (Method->isInstanceMethod())
1465
1466 return Fragments.append(Method->getNameAsString(),
1468}
1469
1470// Subheading of a symbol defaults to its name.
1473 DeclarationFragments Fragments;
1475 return Fragments;
1476}
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:2974
const CFGBlock * Block
Definition: HTMLLogger.cpp:153
llvm::MachO::Record Record
Definition: MachO.h:31
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:2191
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3518
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:4789
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4495
Wrapper for source info for block pointers.
Definition: TypeLoc.h:1314
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2862
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2060
bool isVolatile() const
Definition: DeclCXX.h:2113
bool isConst() const
Definition: DeclCXX.h:2112
bool isStatic() const
Definition: DeclCXX.cpp:2186
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:3556
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
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:454
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:6371
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3298
Represents an enum.
Definition: Decl.h:3868
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:4028
Represents a member of a struct/union/class.
Definition: Decl.h:3058
Represents a function declaration or definition.
Definition: Decl.h:1971
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2707
ExceptionSpecificationType getExceptionSpecType() const
Gets the ExceptionSpecificationType as declared.
Definition: Decl.h:2779
QualType getReturnType() const
Definition: Decl.h:2755
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition: Decl.h:2433
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3692
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:5012
Declaration of a template function.
Definition: DeclTemplate.h:958
Wrapper for source info for functions.
Definition: TypeLoc.h:1428
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:3424
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:3120
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:2326
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
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:7008
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
Definition: Type.h:7083
bool isObjCIdOrClassType() const
True if this is equivalent to the 'id' or 'Class' type,.
Definition: Type.h:7077
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:730
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2082
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2155
Sugar for parentheses used when specifying types.
Definition: Type.h:3113
Represents a parameter to a function.
Definition: Decl.h:1761
bool isObjCMethodParameter() const
Definition: Decl.h:1804
QualType getOriginalType() const
Definition: Decl.cpp:2924
A (possibly-)qualified type.
Definition: Type.h:940
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1007
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:7380
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition: Type.h:1327
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:318
bool hasConst() const
Definition: Type.h:443
bool hasRestrict() const
Definition: Type.h:463
bool hasVolatile() const
Definition: Type.h:453
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3442
Represents a struct/union/class.
Definition: Decl.h:4169
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:3585
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3813
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:1225
A container of type source information.
Definition: Type.h:7330
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:7341
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Definition: Type.cpp:3203
The base class of the type hierarchy.
Definition: Type.h:1813
bool isBlockPointerType() const
Definition: Type.h:7620
bool isFunctionPointerType() const
Definition: Type.h:7646
bool isPointerType() const
Definition: Type.h:7612
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:694
bool isObjCIdType() const
Definition: Type.h:7777
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition: Type.h:8176
bool isObjCObjectPointerType() const
Definition: Type.h:7744
bool isAnyPointerType() const
Definition: Type.h:7616
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8123
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3433
QualType getType() const
Definition: Decl.h:717
Represents a variable declaration or definition.
Definition: Decl.h:918
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1549
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:1270
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1155
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 getFragmentsForTemplateArguments(const ArrayRef< TemplateArgument >, ASTContext &, const std::optional< ArrayRef< TemplateArgumentLoc > >)
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 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 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.
DeclarationFragments & append(DeclarationFragments Other)
Append another DeclarationFragments to the end.
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.
DeclarationFragments & removeTrailingSemicolon()
Removes a trailing semicolon character if present.
static StringRef getFragmentKindString(FragmentKind Kind)
Get the string description of a FragmentKind Kind.
static DeclarationFragments getStructureTypeFragment(const RecordDecl *Decl)
DeclarationFragments & appendSemicolon()
Append a text Fragment of a semicolon character.
static FragmentKind parseFragmentKindFromString(StringRef S)
Get the corresponding FragmentKind from string S.
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.
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
const FunctionProtoType * T
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:6274
@ 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)
Diagnostic wrappers for TextAPI types for error reporting.
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:873
const Type * Ty
The locally-unqualified type.
Definition: Type.h:875
Qualifiers Quals
The local qualifiers.
Definition: Type.h:878
Fragment holds information of a single fragment.