clang 24.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/ASTFwd.h"
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclCXX.h"
20#include "clang/AST/Type.h"
21#include "clang/AST/TypeLoc.h"
24#include "llvm/ADT/StringSwitch.h"
25#include "llvm/Support/ErrorHandling.h"
26#include "llvm/Support/raw_ostream.h"
27#include <optional>
28
29using namespace clang::extractapi;
30using namespace llvm;
31
32namespace {
33
34void findTypeLocForBlockDecl(const clang::TypeSourceInfo *TSInfo,
36 clang::FunctionProtoTypeLoc &BlockProto) {
37 if (!TSInfo)
38 return;
39
41 while (true) {
42 // Look through qualified types
43 if (auto QualifiedTL = TL.getAs<clang::QualifiedTypeLoc>()) {
44 TL = QualifiedTL.getUnqualifiedLoc();
45 continue;
46 }
47
48 if (auto AttrTL = TL.getAs<clang::AttributedTypeLoc>()) {
49 TL = AttrTL.getModifiedLoc();
50 continue;
51 }
52
53 // Try to get the function prototype behind the block pointer type,
54 // then we're done.
55 if (auto BlockPtr = TL.getAs<clang::BlockPointerTypeLoc>()) {
56 TL = BlockPtr.getPointeeLoc().IgnoreParens();
57 Block = TL.getAs<clang::FunctionTypeLoc>();
58 BlockProto = TL.getAs<clang::FunctionProtoTypeLoc>();
59 }
60 break;
61 }
62}
63
64} // namespace
65
67DeclarationFragments::appendUnduplicatedTextCharacter(char Character) {
68 if (!Fragments.empty()) {
69 Fragment &Last = Fragments.back();
70 if (Last.Kind == FragmentKind::Text) {
71 // Merge the extra space into the last fragment if the last fragment is
72 // also text.
73 if (Last.Spelling.back() != Character) { // avoid duplicates at end
74 Last.Spelling.push_back(Character);
75 }
76 } else {
78 Fragments.back().Spelling.push_back(Character);
79 }
80 }
81
82 return *this;
83}
84
86 return appendUnduplicatedTextCharacter(' ');
87}
88
90 return appendUnduplicatedTextCharacter(';');
91}
92
94 if (Fragments.empty())
95 return *this;
96
97 Fragment &Last = Fragments.back();
98 if (Last.Kind == FragmentKind::Text && Last.Spelling.back() == ';')
99 Last.Spelling.pop_back();
100
101 return *this;
102}
103
106 switch (Kind) {
108 return "none";
110 return "keyword";
112 return "attribute";
114 return "number";
116 return "string";
118 return "identifier";
120 return "typeIdentifier";
122 return "genericParameter";
124 return "externalParam";
126 return "internalParam";
128 return "text";
129 }
130
131 llvm_unreachable("Unhandled FragmentKind");
132}
133
151
153 ExceptionSpecificationType ExceptionSpec) {
154 DeclarationFragments Fragments;
155 switch (ExceptionSpec) {
157 return Fragments;
159 return Fragments.append(" ", DeclarationFragments::FragmentKind::Text)
164 // FIXME: throw(int), get types of inner expression
165 return Fragments;
167 return Fragments.append(" ", DeclarationFragments::FragmentKind::Text)
170 // FIXME: throw(conditional-expression), get expression
171 break;
173 return Fragments.append(" ", DeclarationFragments::FragmentKind::Text)
179 return Fragments.append(" ", DeclarationFragments::FragmentKind::Text)
184 default:
185 return Fragments;
186 }
187
188 llvm_unreachable("Unhandled exception specification");
189}
190
193 DeclarationFragments Fragments;
194 if (Record->isStruct())
195 Fragments.append("struct", DeclarationFragments::FragmentKind::Keyword);
196 else if (Record->isUnion())
197 Fragments.append("union", DeclarationFragments::FragmentKind::Keyword);
198 else
199 Fragments.append("class", DeclarationFragments::FragmentKind::Keyword);
200
201 return Fragments;
202}
203
204// NNS stores C++ nested name specifiers, which are prefixes to qualified names.
205// Build declaration fragments for NNS recursively so that we have the USR for
206// every part in a qualified name, and also leaves the actual underlying type
207// cleaner for its own fragment.
208DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForNNS(
210 DeclarationFragments Fragments;
211 switch (NNS.getKind()) {
213 return Fragments;
214
216 auto [Namespace, Prefix] = NNS.getAsNamespaceAndPrefix();
217 Fragments.append(getFragmentsForNNS(Prefix, Context, After));
218 if (const auto *NS = dyn_cast<NamespaceDecl>(Namespace);
219 NS && NS->isAnonymousNamespace())
220 return Fragments;
222 index::generateUSRForDecl(Namespace, USR);
223 Fragments.append(Namespace->getName(),
225 Namespace);
226 break;
227 }
228
230 // The global specifier `::` at the beginning. No stored value.
231 break;
232
234 // Microsoft's `__super` specifier.
236 break;
237
239 // FIXME: Handle C++ template specialization type
240 Fragments.append(getFragmentsForType(NNS.getAsType(), Context, After));
241 break;
242 }
243 }
244
245 // Add the separator text `::` for this segment.
246 return Fragments.append("::", DeclarationFragments::FragmentKind::Text);
247}
248
249// Recursively build the declaration fragments for an underlying `Type` with
250// qualifiers removed.
251DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
252 const Type *T, ASTContext &Context, DeclarationFragments &After) {
253 assert(T && "invalid type");
254
255 DeclarationFragments Fragments;
256
257 if (const MacroQualifiedType *MQT = dyn_cast<MacroQualifiedType>(T)) {
258 Fragments.append(
259 getFragmentsForType(MQT->getUnderlyingType(), Context, After));
260 return Fragments;
261 }
262
263 if (const AttributedType *AT = dyn_cast<AttributedType>(T)) {
264 Fragments.append(
265 getFragmentsForType(AT->getModifiedType(), Context, After));
266
267 // Render explicit nullability annotations after the modified type.
268 // FIXME: Other AttributedType kinds are not rendered.
269 if (auto Nullability = AT->getImmediateNullability())
270 Fragments.appendSpace().append(
271 getNullabilitySpelling(*Nullability, /*isContextSensitive=*/false),
273
274 return Fragments;
275 }
276
277 // If the type is a typedefed type, get the underlying TypedefNameDecl for a
278 // direct reference to the typedef instead of the wrapped type.
279
280 // 'id' type is a typedef for an ObjCObjectPointerType
281 // we treat it as a typedef
282 if (const TypedefType *TypedefTy = dyn_cast<TypedefType>(T)) {
283 const TypedefNameDecl *Decl = TypedefTy->getDecl();
284 TypedefUnderlyingTypeResolver TypedefResolver(Context);
285 std::string USR = TypedefResolver.getUSRForType(QualType(T, 0));
286
287 if (ElaboratedTypeKeyword Keyword = TypedefTy->getKeyword();
289 Fragments
292 .appendSpace();
293 }
294
295 Fragments.append(
296 getFragmentsForNNS(TypedefTy->getQualifier(), Context, After));
297
298 if (TypedefTy->isObjCIdType()) {
299 return Fragments.append(Decl->getName(),
301 }
302
303 return Fragments.append(
305 USR, TypedefResolver.getUnderlyingTypeDecl(QualType(T, 0)));
306 }
307
308 // Declaration fragments of a pointer type is the declaration fragments of
309 // the pointee type followed by a `*`,
310 if (T->isPointerType() && !T->isFunctionPointerType()) {
311 QualType PointeeT = T->getPointeeType();
312 Fragments.append(getFragmentsForType(PointeeT, Context, After));
313 // If the pointee is itself a pointer, we do not want to insert a space
314 // before the `*` as the preceding character in the type name is a `*`.
315 if (!PointeeT->isAnyPointerType())
316 Fragments.appendSpace();
318 }
319
320 // For Objective-C `id` and `Class` pointers
321 // we do not spell out the `*`.
322 if (T->isObjCObjectPointerType() &&
323 !T->getAs<ObjCObjectPointerType>()->isObjCIdOrClassType()) {
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
329 if (!T->getAs<ObjCObjectPointerType>()->isObjCQualifiedIdType()) {
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]`
378 SmallString<128> Size;
379 CAT->getSize().toStringUnsigned(Size);
381 }
382
384
385 return Fragments.append(
386 getFragmentsForType(AT->getElementType(), Context, After));
387 }
388
389 if (const TemplateSpecializationType *TemplSpecTy =
390 dyn_cast<TemplateSpecializationType>(T)) {
391 if (ElaboratedTypeKeyword Keyword = TemplSpecTy->getKeyword();
393 Fragments
396 .appendSpace();
397
398 auto TemplName = TemplSpecTy->getTemplateName();
399 std::string Str;
400 raw_string_ostream Stream(Str);
401 TemplName.print(Stream, Context.getPrintingPolicy(),
403 SmallString<64> USR("");
404 if (const auto *QTN = TemplName.getAsQualifiedTemplateName()) {
405 Fragments.append(getFragmentsForNNS(QTN->getQualifier(), Context, After));
406 TemplName = QTN->getUnderlyingTemplate();
407 }
408 if (const auto *TemplDecl = TemplName.getAsTemplateDecl())
409 index::generateUSRForDecl(TemplDecl, USR);
410 // FIXME: Handle other kinds of TemplateNames.
411
412 return Fragments
416 TemplSpecTy->template_arguments(), Context, std::nullopt))
418 }
419
420 // If the base type is a TagType (struct/interface/union/class/enum), let's
421 // get the underlying Decl for better names and USRs.
422 if (const TagType *TagTy = dyn_cast<TagType>(T)) {
423 if (ElaboratedTypeKeyword Keyword = TagTy->getKeyword();
425 Fragments
428 .appendSpace();
429
430 Fragments.append(getFragmentsForNNS(TagTy->getQualifier(), Context, After));
431
432 const TagDecl *Decl = TagTy->getDecl();
433 // Anonymous decl, skip this fragment.
434 if (Decl->getName().empty())
435 return Fragments.append("{ ... }",
437 SmallString<128> TagUSR;
439 return Fragments.append(Decl->getName(),
441 TagUSR, Decl);
442 }
443
444 // Everything we care about has been handled now, reduce to the canonical
445 // unqualified base type.
446 QualType Base = T->getCanonicalTypeUnqualified();
447
448 // If the base type is an ObjCInterfaceType, use the underlying
449 // ObjCInterfaceDecl for the true USR.
450 if (const auto *ObjCIT = dyn_cast<ObjCInterfaceType>(Base)) {
451 const auto *Decl = ObjCIT->getDecl();
452 SmallString<128> USR;
453 index::generateUSRForDecl(Decl, USR);
454 return Fragments.append(Decl->getName(),
456 USR, Decl);
457 }
458
459 // Default fragment builder for other kinds of types (BuiltinType etc.)
460 SmallString<128> USR;
461 clang::index::generateUSRForType(Base, Context, USR);
462 Fragments.append(Base.getAsString(),
464
465 return Fragments;
466}
467
469DeclarationFragmentsBuilder::getFragmentsForQualifiers(const Qualifiers Quals) {
470 DeclarationFragments Fragments;
471 if (Quals.hasConst())
473 if (Quals.hasVolatile())
475 if (Quals.hasRestrict())
477
478 return Fragments;
479}
480
481DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
482 const QualType QT, ASTContext &Context, DeclarationFragments &After) {
483 assert(!QT.isNull() && "invalid type");
484
485 if (const ParenType *PT = dyn_cast<ParenType>(QT)) {
487 return getFragmentsForType(PT->getInnerType(), Context, After)
489 }
490
491 const SplitQualType SQT = QT.split();
492 DeclarationFragments QualsFragments = getFragmentsForQualifiers(SQT.Quals),
493 TypeFragments =
494 getFragmentsForType(SQT.Ty, Context, After);
495 if (QT.getAsString() == "_Bool")
496 TypeFragments.replace("bool", 0);
497
498 if (QualsFragments.getFragments().empty())
499 return TypeFragments;
500
501 // Use east qualifier for pointer types
502 // For example:
503 // ```
504 // int * const
505 // ^---- ^----
506 // type qualifier
507 // ^-----------------
508 // const pointer to int
509 // ```
510 // should not be reconstructed as
511 // ```
512 // const int *
513 // ^---- ^--
514 // qualifier type
515 // ^---------------- ^
516 // pointer to const int
517 // ```
518 if (SQT.Ty->isAnyPointerType())
519 return TypeFragments.appendSpace().append(std::move(QualsFragments));
520
521 return QualsFragments.appendSpace().append(std::move(TypeFragments));
522}
523
525 const NamespaceDecl *Decl) {
526 DeclarationFragments Fragments;
528 if (!Decl->isAnonymousNamespace())
529 Fragments.appendSpace().append(
531 return Fragments.appendSemicolon();
532}
533
536 DeclarationFragments Fragments;
537 if (Var->isConstexpr())
539 .appendSpace();
540
541 StorageClass SC = Var->getStorageClass();
542 if (SC != SC_None)
543 Fragments
546 .appendSpace();
547
548 // Capture potential fragments that needs to be placed after the variable name
549 // ```
550 // int nums[5];
551 // char (*ptr_to_array)[6];
552 // ```
554 FunctionTypeLoc BlockLoc;
555 FunctionProtoTypeLoc BlockProtoLoc;
556 findTypeLocForBlockDecl(Var->getTypeSourceInfo(), BlockLoc, BlockProtoLoc);
557
558 if (!BlockLoc) {
560 ? Var->getTypeSourceInfo()->getType()
562 Var->getType());
563
564 Fragments.append(getFragmentsForType(T, Var->getASTContext(), After))
565 .appendSpace();
566 } else {
567 Fragments.append(getFragmentsForBlock(Var, BlockLoc, BlockProtoLoc, After));
568 }
569
570 return Fragments
572 .append(std::move(After))
574}
575
578 DeclarationFragments Fragments;
579 if (Var->isConstexpr())
581 .appendSpace();
582 QualType T =
583 Var->getTypeSourceInfo()
584 ? Var->getTypeSourceInfo()->getType()
586
587 // Might be a member, so might be static.
588 if (Var->isStaticDataMember())
590 .appendSpace();
591
593 DeclarationFragments ArgumentFragment =
594 getFragmentsForType(T, Var->getASTContext(), After);
595 if (StringRef(ArgumentFragment.begin()->Spelling)
596 .starts_with("type-parameter")) {
597 std::string ProperArgName = T.getAsString();
598 ArgumentFragment.begin()->Spelling.swap(ProperArgName);
599 }
600 Fragments.append(std::move(ArgumentFragment))
601 .appendSpace()
604 return Fragments;
605}
606
608DeclarationFragmentsBuilder::getFragmentsForParam(const ParmVarDecl *Param) {
609 DeclarationFragments Fragments, After;
610
611 auto *TSInfo = Param->getTypeSourceInfo();
612
613 QualType T = TSInfo ? TSInfo->getType()
614 : Param->getASTContext().getUnqualifiedObjCPointerType(
615 Param->getType());
616
617 FunctionTypeLoc BlockLoc;
618 FunctionProtoTypeLoc BlockProtoLoc;
619 findTypeLocForBlockDecl(TSInfo, BlockLoc, BlockProtoLoc);
620
621 DeclarationFragments TypeFragments;
622 if (BlockLoc)
623 TypeFragments.append(
624 getFragmentsForBlock(Param, BlockLoc, BlockProtoLoc, After));
625 else
626 TypeFragments.append(getFragmentsForType(T, Param->getASTContext(), After));
627
628 if (StringRef(TypeFragments.begin()->Spelling)
629 .starts_with("type-parameter")) {
630 std::string ProperArgName = Param->getOriginalType().getAsString();
631 TypeFragments.begin()->Spelling.swap(ProperArgName);
632 }
633
634 if (Param->isObjCMethodParameter()) {
636 .append(std::move(TypeFragments))
637 .append(std::move(After))
639 .append(Param->getName(),
641 } else {
642 // Pointer types should typically not have a space between the * and
643 // the parameter name. However, if a keyword sits in between, then
644 // a space must be inserted to avoid joining the keyword and the name.
645 bool TrailingKeyword = TypeFragments.endsWithKeyword();
646 Fragments.append(std::move(TypeFragments));
647 // If the type is a type alias, append the space
648 // even if the underlying type is a pointer type.
649 if (T->isTypedefNameType() ||
650 (!T->isAnyPointerType() && !T->isBlockPointerType()) || TrailingKeyword)
651 Fragments.appendSpace();
652 Fragments
653 .append(Param->getName(),
655 .append(std::move(After));
656 }
657 return Fragments;
658}
659
660DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForBlock(
661 const NamedDecl *BlockDecl, FunctionTypeLoc &Block,
662 FunctionProtoTypeLoc &BlockProto, DeclarationFragments &After) {
663 DeclarationFragments Fragments;
664
665 DeclarationFragments RetTyAfter;
666 auto ReturnValueFragment = getFragmentsForType(
667 Block.getTypePtr()->getReturnType(), BlockDecl->getASTContext(), After);
668
669 Fragments.append(std::move(ReturnValueFragment))
670 .append(std::move(RetTyAfter))
671 .appendSpace()
673
675 unsigned NumParams = Block.getNumParams();
676
677 if (!BlockProto || NumParams == 0) {
678 if (BlockProto && BlockProto.getTypePtr()->isVariadic())
680 else
682 } else {
684 for (unsigned I = 0; I != NumParams; ++I) {
685 if (I)
687 After.append(getFragmentsForParam(Block.getParam(I)));
688 if (I == NumParams - 1 && BlockProto.getTypePtr()->isVariadic())
690 }
692 }
693
694 return Fragments;
695}
696
699 DeclarationFragments Fragments;
700 switch (Func->getStorageClass()) {
701 case SC_None:
702 case SC_PrivateExtern:
703 break;
704 case SC_Extern:
706 .appendSpace();
707 break;
708 case SC_Static:
710 .appendSpace();
711 break;
712 case SC_Auto:
713 case SC_Register:
714 llvm_unreachable("invalid for functions");
715 }
716 if (Func->isConsteval()) // if consteval, it is also constexpr
718 .appendSpace();
719 else if (Func->isConstexpr())
721 .appendSpace();
722
723 // FIXME: Is `after` actually needed here?
725 QualType ReturnType = Func->getReturnType();
726 auto ReturnValueFragment =
727 getFragmentsForType(ReturnType, Func->getASTContext(), After);
728 if (StringRef(ReturnValueFragment.begin()->Spelling)
729 .starts_with("type-parameter")) {
730 std::string ProperArgName = ReturnType.getAsString();
731 ReturnValueFragment.begin()->Spelling.swap(ProperArgName);
732 }
733
734 // Pointer types should typically not have a space between the * and
735 // the function name. However, if a keyword sits in between, then
736 // a space must be inserted to avoid joining the keyword and the name.
737 bool ReturnTrailingKeyword = ReturnValueFragment.endsWithKeyword();
738 Fragments.append(std::move(ReturnValueFragment));
739 if (!ReturnType->isAnyPointerType() || ReturnTrailingKeyword)
740 Fragments.appendSpace();
741 Fragments.append(Func->getNameAsString(),
743
744 if (Func->getTemplateSpecializationInfo()) {
746
747 for (unsigned i = 0, end = Func->getNumParams(); i != end; ++i) {
748 if (i)
750 Fragments.append(
751 getFragmentsForType(Func->getParamDecl(i)->getType(),
752 Func->getParamDecl(i)->getASTContext(), After));
753 }
755 }
756 Fragments.append(std::move(After));
757
759 unsigned NumParams = Func->getNumParams();
760 for (unsigned i = 0; i != NumParams; ++i) {
761 if (i)
763 Fragments.append(getFragmentsForParam(Func->getParamDecl(i)));
764 }
765
766 if (Func->isVariadic()) {
767 if (NumParams > 0)
770 }
772
774 Func->getExceptionSpecType()));
775
776 return Fragments.appendSemicolon();
777}
778
785
790
791 DeclarationFragments Fragments, After;
793
794 if (!EnumDecl->getName().empty())
795 Fragments.appendSpace().append(
797
798 QualType IntegerType = EnumDecl->getIntegerType();
799 if (!IntegerType.isNull())
800 Fragments.appendSpace()
802 .append(
803 getFragmentsForType(IntegerType, EnumDecl->getASTContext(), After))
804 .append(std::move(After));
805
806 if (EnumDecl->getName().empty())
807 Fragments.appendSpace().append("{ ... }",
809
810 return Fragments.appendSemicolon();
811}
812
816 DeclarationFragments Fragments;
817 if (Field->isMutable())
819 .appendSpace();
820 return Fragments
821 .append(
822 getFragmentsForType(Field->getType(), Field->getASTContext(), After))
823 .appendSpace()
825 .append(std::move(After))
827}
828
830 const RecordDecl *Record) {
831 if (const auto *TypedefNameDecl = Record->getTypedefNameForAnonDecl())
833
834 DeclarationFragments Fragments;
835 if (Record->isUnion())
837 else
839
840 Fragments.appendSpace();
841 if (!Record->getName().empty())
842 Fragments.append(Record->getName(),
844 else
846
847 return Fragments.appendSemicolon();
848}
849
851 const CXXRecordDecl *Record) {
852 if (const auto *TypedefNameDecl = Record->getTypedefNameForAnonDecl())
854
855 DeclarationFragments Fragments;
857
858 if (!Record->getName().empty())
859 Fragments.appendSpace().append(
861
862 return Fragments.appendSemicolon();
863}
864
867 const CXXMethodDecl *Method) {
868 DeclarationFragments Fragments;
869 std::string Name;
870 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(Method)) {
871 Name = Method->getNameAsString();
872 if (Constructor->isExplicit())
874 .appendSpace();
875 } else if (isa<CXXDestructorDecl>(Method))
876 Name = Method->getNameAsString();
877
880 .append(std::move(After));
882 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
883 if (i)
885 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
886 }
888
890 Method->getExceptionSpecType()));
891
892 return Fragments.appendSemicolon();
893}
894
896 const CXXMethodDecl *Method) {
897 DeclarationFragments Fragments;
898 StringRef Name = Method->getName();
899 if (Method->isStatic())
901 .appendSpace();
902 if (Method->isConstexpr())
904 .appendSpace();
905 if (Method->isVolatile())
907 .appendSpace();
908 if (Method->isVirtual())
910 .appendSpace();
911
912 // Build return type
914 Fragments
915 .append(getFragmentsForType(Method->getReturnType(),
916 Method->getASTContext(), After))
917 .appendSpace()
919 .append(std::move(After));
921 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
922 if (i)
924 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
925 }
927
928 if (Method->isConst())
929 Fragments.appendSpace().append("const",
931
933 Method->getExceptionSpecType()));
934
935 return Fragments.appendSemicolon();
936}
937
940 const CXXConversionDecl *ConversionFunction) {
941 DeclarationFragments Fragments;
942
943 if (ConversionFunction->isExplicit())
945 .appendSpace();
946
948 .appendSpace();
949
950 Fragments
951 .append(ConversionFunction->getConversionType().getAsString(),
954 for (unsigned i = 0, end = ConversionFunction->getNumParams(); i != end;
955 ++i) {
956 if (i)
958 Fragments.append(getFragmentsForParam(ConversionFunction->getParamDecl(i)));
959 }
961
962 if (ConversionFunction->isConst())
963 Fragments.appendSpace().append("const",
965
966 return Fragments.appendSemicolon();
967}
968
971 const CXXMethodDecl *Method) {
972 DeclarationFragments Fragments;
973
974 // Build return type
976 Fragments
977 .append(getFragmentsForType(Method->getReturnType(),
978 Method->getASTContext(), After))
979 .appendSpace()
980 .append(Method->getNameAsString(),
982 .append(std::move(After));
984 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
985 if (i)
987 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
988 }
990
991 if (Method->isConst())
992 Fragments.appendSpace().append("const",
994
996 Method->getExceptionSpecType()));
997
998 return Fragments.appendSemicolon();
999}
1000
1001// Get fragments for template parameters, e.g. T in tempalte<typename T> ...
1004 ArrayRef<NamedDecl *> ParameterArray) {
1005 DeclarationFragments Fragments;
1006 for (unsigned i = 0, end = ParameterArray.size(); i != end; ++i) {
1007 if (i)
1009 .appendSpace();
1010
1011 if (const auto *TemplateParam =
1012 dyn_cast<TemplateTypeParmDecl>(ParameterArray[i])) {
1013 if (TemplateParam->hasTypeConstraint())
1014 Fragments.append(TemplateParam->getTypeConstraint()
1015 ->getNamedConcept()
1016 ->getName()
1017 .str(),
1019 else if (TemplateParam->wasDeclaredWithTypename())
1020 Fragments.append("typename",
1022 else
1024
1025 if (TemplateParam->isParameterPack())
1027
1028 if (!TemplateParam->getName().empty())
1029 Fragments.appendSpace().append(
1030 TemplateParam->getName(),
1032
1033 if (TemplateParam->hasDefaultArgument()) {
1034 const auto Default = TemplateParam->getDefaultArgument();
1037 {Default.getArgument()}, TemplateParam->getASTContext(),
1038 {Default}));
1039 }
1040 } else if (const auto *NTP =
1041 dyn_cast<NonTypeTemplateParmDecl>(ParameterArray[i])) {
1043 const auto TyFragments =
1044 getFragmentsForType(NTP->getType(), NTP->getASTContext(), After);
1045 Fragments.append(std::move(TyFragments)).append(std::move(After));
1046
1047 if (NTP->isParameterPack())
1049
1050 if (!NTP->getName().empty())
1051 Fragments.appendSpace().append(
1052 NTP->getName(),
1054
1055 if (NTP->hasDefaultArgument()) {
1056 SmallString<8> ExprStr;
1057 raw_svector_ostream Output(ExprStr);
1058 NTP->getDefaultArgument().getArgument().print(
1059 NTP->getASTContext().getPrintingPolicy(), Output,
1060 /*IncludeType=*/false);
1063 }
1064 } else if (const auto *TTP =
1065 dyn_cast<TemplateTemplateParmDecl>(ParameterArray[i])) {
1067 .appendSpace()
1070 TTP->getTemplateParameters()->asArray()))
1072 .appendSpace()
1073 .append(TTP->wasDeclaredWithTypename() ? "typename" : "class",
1075
1076 if (TTP->isParameterPack())
1078
1079 if (!TTP->getName().empty())
1080 Fragments.appendSpace().append(
1081 TTP->getName(),
1083 if (TTP->hasDefaultArgument()) {
1084 const auto Default = TTP->getDefaultArgument();
1087 {Default.getArgument()}, TTP->getASTContext(), {Default}));
1088 }
1089 }
1090 }
1091 return Fragments;
1092}
1093
1094// Get fragments for template arguments, e.g. int in template<typename T>
1095// Foo<int>;
1096//
1097// Note: TemplateParameters is only necessary if the Decl is a
1098// PartialSpecialization, where we need the parameters to deduce the name of the
1099// generic arguments.
1102 const ArrayRef<TemplateArgument> TemplateArguments, ASTContext &Context,
1103 const std::optional<ArrayRef<TemplateArgumentLoc>> TemplateArgumentLocs) {
1104 DeclarationFragments Fragments;
1105 for (unsigned i = 0, end = TemplateArguments.size(); i != end; ++i) {
1106 if (i)
1108 .appendSpace();
1109
1110 const auto &CTA = TemplateArguments[i];
1111 switch (CTA.getKind()) {
1114 DeclarationFragments ArgumentFragment =
1115 getFragmentsForType(CTA.getAsType(), Context, After);
1116
1117 if (StringRef(ArgumentFragment.begin()->Spelling)
1118 .starts_with("type-parameter")) {
1119 if (TemplateArgumentLocs.has_value() &&
1120 TemplateArgumentLocs->size() > i) {
1121 std::string ProperArgName = TemplateArgumentLocs.value()[i]
1122 .getTypeSourceInfo()
1123 ->getType()
1124 .getAsString();
1125 ArgumentFragment.begin()->Spelling.swap(ProperArgName);
1126 } else {
1127 auto &Spelling = ArgumentFragment.begin()->Spelling;
1128 Spelling.clear();
1129 raw_string_ostream OutStream(Spelling);
1130 CTA.print(Context.getPrintingPolicy(), OutStream, false);
1131 }
1132 }
1133
1134 Fragments.append(std::move(ArgumentFragment));
1135 break;
1136 }
1138 const auto *VD = CTA.getAsDecl();
1139 SmallString<128> USR;
1141 Fragments.append(VD->getNameAsString(),
1143 break;
1144 }
1147 break;
1148
1150 SmallString<4> Str;
1151 CTA.getAsIntegral().toString(Str);
1153 break;
1154 }
1155
1157 const auto SVTy = CTA.getStructuralValueType();
1158 Fragments.append(CTA.getAsStructuralValue().getAsString(Context, SVTy),
1160 break;
1161 }
1162
1165 std::string Str;
1166 raw_string_ostream Stream(Str);
1167 CTA.getAsTemplate().print(Stream, Context.getPrintingPolicy());
1168 SmallString<64> USR("");
1169 if (const auto *TemplDecl =
1170 CTA.getAsTemplateOrTemplatePattern().getAsTemplateDecl())
1171 index::generateUSRForDecl(TemplDecl, USR);
1173 USR);
1174 if (CTA.getKind() == TemplateArgument::TemplateExpansion)
1176 break;
1177 }
1178
1181 .append(getFragmentsForTemplateArguments(CTA.pack_elements(), Context,
1182 {}))
1184 break;
1185
1187 SmallString<8> ExprStr;
1188 raw_svector_ostream Output(ExprStr);
1189 CTA.getAsExpr()->printPretty(Output, nullptr,
1190 Context.getPrintingPolicy());
1192 break;
1193 }
1194
1196 break;
1197 }
1198 }
1199 return Fragments;
1200}
1201
1219
1222 const RedeclarableTemplateDecl *RedeclarableTemplate) {
1223 DeclarationFragments Fragments;
1225 .appendSpace()
1228 RedeclarableTemplate->getTemplateParameters()->asArray()))
1230 .appendSpace();
1231
1232 if (isa<TypeAliasTemplateDecl>(RedeclarableTemplate))
1233 Fragments.appendSpace()
1235 .appendSpace()
1236 .append(RedeclarableTemplate->getName(),
1238 // the templated records will be resposbible for injecting their templates
1239 return Fragments.appendSpace();
1240}
1241
1245 DeclarationFragments Fragments;
1246 std::optional<ArrayRef<TemplateArgumentLoc>> TemplateArgumentLocs = {};
1247 if (auto *TemplateArgs = Decl->getTemplateArgsAsWritten()) {
1248 TemplateArgumentLocs = TemplateArgs->arguments();
1249 }
1250 return Fragments
1252 .appendSpace()
1255 .appendSpace()
1258 .pop_back() // there is an extra semicolon now
1261 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1262 TemplateArgumentLocs))
1264 .appendSemicolon();
1265}
1266
1289
1309
1313 DeclarationFragments Fragments;
1314 return Fragments
1316 .appendSpace()
1318 // Partial specs may have new params.
1320 Decl->getTemplateParameters()->asArray()))
1322 .appendSpace()
1324 .pop_back() // there is an extra semicolon now
1327 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1328 Decl->getTemplateArgsAsWritten()->arguments()))
1330 .appendSemicolon();
1331}
1332
1349
1361
1364 const MacroInfo *MI) {
1365 DeclarationFragments Fragments;
1367 .appendSpace();
1369
1370 if (MI->isFunctionLike()) {
1372 unsigned numParameters = MI->getNumParams();
1373 if (MI->isC99Varargs())
1374 --numParameters;
1375 for (unsigned i = 0; i < numParameters; ++i) {
1376 if (i)
1378 Fragments.append(MI->params()[i]->getName(),
1380 }
1381 if (MI->isVariadic()) {
1382 if (numParameters && MI->isC99Varargs())
1385 }
1387 }
1388 return Fragments;
1389}
1390
1392 const ObjCCategoryDecl *Category) {
1393 DeclarationFragments Fragments;
1394
1395 auto *Interface = Category->getClassInterface();
1396 SmallString<128> InterfaceUSR;
1397 index::generateUSRForDecl(Interface, InterfaceUSR);
1398
1400 .appendSpace()
1401 .append(Interface->getName(),
1403 Interface)
1405 .append(Category->getName(),
1408
1409 return Fragments;
1410}
1411
1414 DeclarationFragments Fragments;
1415 // Build the base of the Objective-C interface declaration.
1417 .appendSpace()
1418 .append(Interface->getName(),
1420
1421 // Build the inheritance part of the declaration.
1422 if (const ObjCInterfaceDecl *SuperClass = Interface->getSuperClass()) {
1423 SmallString<128> SuperUSR;
1424 index::generateUSRForDecl(SuperClass, SuperUSR);
1426 .append(SuperClass->getName(),
1428 SuperClass);
1429 }
1430
1431 return Fragments;
1432}
1433
1435 const ObjCMethodDecl *Method) {
1436 DeclarationFragments Fragments, After;
1437 // Build the instance/class method indicator.
1438 if (Method->isClassMethod())
1440 else if (Method->isInstanceMethod())
1442
1443 // Build the return type.
1445 .append(getFragmentsForType(Method->getReturnType(),
1446 Method->getASTContext(), After))
1447 .append(std::move(After))
1449
1450 // Build the selector part.
1451 Selector Selector = Method->getSelector();
1452 if (Selector.getNumArgs() == 0)
1453 // For Objective-C methods that don't take arguments, the first (and only)
1454 // slot of the selector is the method name.
1455 Fragments.appendSpace().append(
1458
1459 // For Objective-C methods that take arguments, build the selector slots.
1460 for (unsigned i = 0, end = Method->param_size(); i != end; ++i) {
1461 // Objective-C method selector parts are considered as identifiers instead
1462 // of "external parameters" as in Swift. This is because Objective-C method
1463 // symbols are referenced with the entire selector, instead of just the
1464 // method name in Swift.
1466 ParamID.append(":");
1467 Fragments.appendSpace().append(
1469
1470 // Build the internal parameter.
1471 const ParmVarDecl *Param = Method->getParamDecl(i);
1472 Fragments.append(getFragmentsForParam(Param));
1473 }
1474
1475 return Fragments.appendSemicolon();
1476}
1477
1479 const ObjCPropertyDecl *Property) {
1480 DeclarationFragments Fragments, After;
1481
1482 // Build the Objective-C property keyword.
1484
1485 const auto Attributes = Property->getPropertyAttributesAsWritten();
1486 // Build the attributes if there is any associated with the property.
1487 if (Attributes != ObjCPropertyAttribute::kind_noattr) {
1488 // No leading comma for the first attribute.
1489 bool First = true;
1491 // Helper function to render the attribute.
1492 auto RenderAttribute =
1493 [&](ObjCPropertyAttribute::Kind Kind, StringRef Spelling,
1494 StringRef Arg = "",
1497 // Check if the `Kind` attribute is set for this property.
1498 if ((Attributes & Kind) && !Spelling.empty()) {
1499 // Add a leading comma if this is not the first attribute rendered.
1500 if (!First)
1502 // Render the spelling of this attribute `Kind` as a keyword.
1503 Fragments.append(Spelling,
1505 // If this attribute takes in arguments (e.g. `getter=getterName`),
1506 // render the arguments.
1507 if (!Arg.empty())
1509 .append(Arg, ArgKind);
1510 First = false;
1511 }
1512 };
1513
1514 // Go through all possible Objective-C property attributes and render set
1515 // ones.
1516 RenderAttribute(ObjCPropertyAttribute::kind_class, "class");
1517 RenderAttribute(ObjCPropertyAttribute::kind_direct, "direct");
1518 RenderAttribute(ObjCPropertyAttribute::kind_nonatomic, "nonatomic");
1519 RenderAttribute(ObjCPropertyAttribute::kind_atomic, "atomic");
1520 RenderAttribute(ObjCPropertyAttribute::kind_assign, "assign");
1521 RenderAttribute(ObjCPropertyAttribute::kind_retain, "retain");
1522 RenderAttribute(ObjCPropertyAttribute::kind_strong, "strong");
1523 RenderAttribute(ObjCPropertyAttribute::kind_copy, "copy");
1524 RenderAttribute(ObjCPropertyAttribute::kind_weak, "weak");
1526 "unsafe_unretained");
1527 RenderAttribute(ObjCPropertyAttribute::kind_readwrite, "readwrite");
1528 RenderAttribute(ObjCPropertyAttribute::kind_readonly, "readonly");
1529 RenderAttribute(ObjCPropertyAttribute::kind_getter, "getter",
1530 Property->getGetterName().getAsString());
1531 RenderAttribute(ObjCPropertyAttribute::kind_setter, "setter",
1532 Property->getSetterName().getAsString());
1533
1534 // Render nullability attributes.
1535 if (Attributes & ObjCPropertyAttribute::kind_nullability) {
1536 QualType Type = Property->getType();
1537 if (const auto Nullability =
1538 AttributedType::stripOuterNullability(Type)) {
1539 if (!First)
1541 if (*Nullability == NullabilityKind::Unspecified &&
1543 Fragments.append("null_resettable",
1545 else
1546 Fragments.append(
1547 getNullabilitySpelling(*Nullability, /*isContextSensitive=*/true),
1549 First = false;
1550 }
1551 }
1552
1554 }
1555
1556 Fragments.appendSpace();
1557
1558 FunctionTypeLoc BlockLoc;
1559 FunctionProtoTypeLoc BlockProtoLoc;
1560 findTypeLocForBlockDecl(Property->getTypeSourceInfo(), BlockLoc,
1561 BlockProtoLoc);
1562
1563 auto PropType = Property->getType();
1564 if (!BlockLoc)
1565 Fragments
1566 .append(getFragmentsForType(PropType, Property->getASTContext(), After))
1567 .appendSpace();
1568 else
1569 Fragments.append(
1570 getFragmentsForBlock(Property, BlockLoc, BlockProtoLoc, After));
1571
1572 return Fragments
1573 .append(Property->getName(),
1575 .append(std::move(After))
1576 .appendSemicolon();
1577}
1578
1580 const ObjCProtocolDecl *Protocol) {
1581 DeclarationFragments Fragments;
1582 // Build basic protocol declaration.
1584 .appendSpace()
1585 .append(Protocol->getName(),
1587
1588 // If this protocol conforms to other protocols, build the conformance list.
1589 if (!Protocol->protocols().empty()) {
1591 for (ObjCProtocolDecl::protocol_iterator It = Protocol->protocol_begin();
1592 It != Protocol->protocol_end(); It++) {
1593 // Add a leading comma if this is not the first protocol rendered.
1594 if (It != Protocol->protocol_begin())
1596
1597 SmallString<128> USR;
1598 index::generateUSRForDecl(*It, USR);
1599 Fragments.append((*It)->getName(),
1601 *It);
1602 }
1604 }
1605
1606 return Fragments;
1607}
1608
1610 const TypedefNameDecl *Decl) {
1611 DeclarationFragments Fragments, After;
1614 .appendSpace()
1615 .append(getFragmentsForType(Decl->getUnderlyingType(),
1616 Decl->getASTContext(), After))
1617 .append(std::move(After))
1618 .appendSpace()
1619 .append(Decl->getName(),
1621 else
1623 .appendSpace()
1625 .appendSpace()
1627 .appendSpace()
1628 .append(getFragmentsForType(Decl->getUnderlyingType(),
1629 Decl->getASTContext(), After))
1630 .append(std::move(After));
1631
1632 return Fragments.appendSemicolon();
1633}
1634
1635// Instantiate template for FunctionDecl.
1636template FunctionSignature
1638
1639// Instantiate template for ObjCMethodDecl.
1640template FunctionSignature
1642
1643// Subheading of a symbol defaults to its name.
1646 DeclarationFragments Fragments;
1648 Fragments.append(cast<CXXRecordDecl>(Decl->getDeclContext())->getName(),
1650 } else if (isa<CXXDestructorDecl>(Decl)) {
1651 Fragments.append(cast<CXXDestructorDecl>(Decl)->getNameAsString(),
1653 } else if (isa<CXXConversionDecl>(Decl)) {
1654 Fragments.append(
1655 cast<CXXConversionDecl>(Decl)->getConversionType().getAsString(),
1657 } else if (isa<CXXMethodDecl>(Decl) &&
1658 cast<CXXMethodDecl>(Decl)->isOverloadedOperator()) {
1659 Fragments.append(Decl->getNameAsString(),
1661 } else if (isa<TagDecl>(Decl) &&
1662 cast<TagDecl>(Decl)->getTypedefNameForAnonDecl()) {
1663 return getSubHeading(cast<TagDecl>(Decl)->getTypedefNameForAnonDecl());
1664 } else if (Decl->getIdentifier()) {
1665 Fragments.append(Decl->getName(),
1667 } else {
1668 Fragments.append(Decl->getDeclName().getAsString(),
1670 }
1671
1672 return Fragments;
1673}
1674
1675// Subheading of an Objective-C method is a `+` or `-` sign indicating whether
1676// it's a class method or an instance method, followed by the selector name.
1679 DeclarationFragments Fragments;
1680 if (Method->isClassMethod())
1682 else if (Method->isInstanceMethod())
1684
1685 return Fragments.append(Method->getNameAsString(),
1687}
1688
1689// Subheading of a symbol defaults to its name.
1692 DeclarationFragments Fragments;
1694 return Fragments;
1695}
Forward declaration of all AST node types.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines the Declaration Fragments related classes.
llvm::MachO::Record Record
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...
const clang::PrintingPolicy & getPrintingPolicy() const
Definition ASTContext.h:861
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
Type source information for an attributed type.
Definition TypeLoc.h:1008
Wrapper for source info for block pointers.
Definition TypeLoc.h:1557
Represents a C++ conversion function within a class.
Definition DeclCXX.h:2968
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2145
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.
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:550
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition DeclBase.cpp:273
DeclContext * getDeclContext()
Definition DeclBase.h:456
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:809
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3467
Represents an enum.
Definition Decl.h:4055
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4228
Represents a member of a struct/union/class.
Definition Decl.h:3204
Represents a function declaration or definition.
Definition Decl.h:2029
bool isVariadic() const
Whether this function prototype is variadic.
Definition TypeBase.h:5810
Declaration of a template function.
Wrapper for source info for functions.
Definition TypeLoc.h:1675
const TypeClass * getTypePtr() const
Definition TypeLoc.h:526
Encapsulates the data about a macro definition (e.g.
Definition MacroInfo.h:40
bool isC99Varargs() const
Definition MacroInfo.h:208
bool isFunctionLike() const
Definition MacroInfo.h:202
ArrayRef< const IdentifierInfo * > params() const
Definition MacroInfo.h:186
unsigned getNumParams() const
Definition MacroInfo.h:185
bool isVariadic() const
Definition MacroInfo.h:210
This represents a decl that may have a name.
Definition Decl.h:274
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
Represent a C++ namespace.
Definition Decl.h:592
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
NamespaceAndPrefix getAsNamespaceAndPrefix() const
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
ObjCCategoryDecl - Represents a category declaration.
Definition DeclObjC.h:2329
Represents an ObjC class declaration.
Definition DeclObjC.h:1154
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
Represents one property declaration in an Objective-C interface.
Definition DeclObjC.h:731
Represents an Objective-C protocol declaration.
Definition DeclObjC.h:2084
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:2158
Represents a parameter to a function.
Definition Decl.h:1819
A (possibly-)qualified type.
Definition TypeBase.h:938
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1005
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition TypeBase.h:8510
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition TypeBase.h:1348
Wrapper of type source information for a type with non-trivial direct qualifiers.
Definition TypeLoc.h:300
bool hasConst() const
Definition TypeBase.h:458
bool hasRestrict() const
Definition TypeBase.h:478
bool hasVolatile() const
Definition TypeBase.h:468
Represents a struct/union/class.
Definition Decl.h:4369
Declaration of a redeclarable template.
Smart pointer class that efficiently represents Objective-C method names.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
unsigned getNumArgs() const
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:3998
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
ArrayRef< NamedDecl * > asArray()
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:349
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:1468
A container of type source information.
Definition TypeBase.h:8460
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition TypeLoc.h:267
QualType getType() const
Return the type wrapped by this type source info.
Definition TypeBase.h:8471
The base class of the type hierarchy.
Definition TypeBase.h:1876
bool isFunctionPointerType() const
Definition TypeBase.h:8793
bool isPointerType() const
Definition TypeBase.h:8726
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:789
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition TypeBase.h:9372
bool isObjCObjectPointerType() const
Definition TypeBase.h:8905
bool isAnyPointerType() const
Definition TypeBase.h:8734
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9319
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3606
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:932
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1593
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
Definition Decl.cpp:2102
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition Decl.h:1306
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1174
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 getFragmentsForMacro(StringRef Name, const MacroInfo *MI)
Build DeclarationFragments for a macro.
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 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.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
Definition Specifiers.h:358
StorageClass
Storage classes.
Definition Specifiers.h:249
@ SC_Auto
Definition Specifiers.h:257
@ SC_PrivateExtern
Definition Specifiers.h:254
@ SC_Extern
Definition Specifiers.h:252
@ SC_Register
Definition Specifiers.h:258
@ SC_Static
Definition Specifiers.h:253
@ SC_None
Definition Specifiers.h:251
@ Default
Set to the current date and time.
@ Property
The type of a property.
Definition TypeBase.h:912
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
const FunctionProtoType * T
@ Keyword
The name has been typo-corrected to a keyword.
Definition Sema.h:561
@ Type
The name was classified as a type.
Definition Sema.h:563
@ Concept
The name was classified as a concept name.
Definition Sema.h:590
llvm::StringRef getAsString(SyncScope S)
Definition SyncScope.h:62
U cast(CodeGen::Address addr)
Definition Address.h:327
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition TypeBase.h:6005
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6010
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:6026
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_DependentNoexcept
noexcept(expression), value-dependent
@ EST_None
no exception specification
@ EST_BasicNoexcept
noexcept
@ EST_NoexceptFalse
noexcept(expression), evals to 'false'
@ EST_NoexceptTrue
noexcept(expression), evals to 'true'
@ EST_Dynamic
throw(T1, T2)
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Definition Type.cpp:3440
const Type * Ty
The locally-unqualified type.
Definition TypeBase.h:873
Qualifiers Quals
The local qualifiers.
Definition TypeBase.h:876
Fragment holds information of a single fragment.