clang 20.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();
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
136 return llvm::StringSwitch<FragmentKind>(S)
142 .Case("typeIdentifier",
144 .Case("genericParameter",
150}
151
153 ExceptionSpecificationType ExceptionSpec) {
154 DeclarationFragments Fragments;
155 switch (ExceptionSpec) {
157 return Fragments;
164 // FIXME: throw(int), get types of inner expression
165 return Fragments;
170 // FIXME: throw(conditional-expression), get expression
171 break;
184 default:
185 return Fragments;
186 }
187
188 llvm_unreachable("Unhandled exception specification");
189}
190
193 DeclarationFragments Fragments;
194 if (Record->isStruct())
196 else if (Record->isUnion())
198 else
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.
209DeclarationFragmentsBuilder::getFragmentsForNNS(const NestedNameSpecifier *NNS,
210 ASTContext &Context,
211 DeclarationFragments &After) {
212 DeclarationFragments Fragments;
213 if (NNS->getPrefix())
214 Fragments.append(getFragmentsForNNS(NNS->getPrefix(), Context, After));
215
216 switch (NNS->getKind()) {
218 Fragments.append(NNS->getAsIdentifier()->getName(),
220 break;
221
223 const NamespaceDecl *NS = NNS->getAsNamespace();
224 if (NS->isAnonymousNamespace())
225 return Fragments;
228 Fragments.append(NS->getName(),
230 break;
231 }
232
234 const NamespaceAliasDecl *Alias = NNS->getAsNamespaceAlias();
236 index::generateUSRForDecl(Alias, USR);
237 Fragments.append(Alias->getName(),
239 Alias);
240 break;
241 }
242
244 // The global specifier `::` at the beginning. No stored value.
245 break;
246
248 // Microsoft's `__super` specifier.
250 break;
251
253 // A type prefixed by the `template` keyword.
255 Fragments.appendSpace();
256 // Fallthrough after adding the keyword to handle the actual type.
257 [[fallthrough]];
258
260 const Type *T = NNS->getAsType();
261 // FIXME: Handle C++ template specialization type
262 Fragments.append(getFragmentsForType(T, Context, After));
263 break;
264 }
265 }
266
267 // Add the separator text `::` for this segment.
268 return Fragments.append("::", DeclarationFragments::FragmentKind::Text);
269}
270
271// Recursively build the declaration fragments for an underlying `Type` with
272// qualifiers removed.
273DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
274 const Type *T, ASTContext &Context, DeclarationFragments &After) {
275 assert(T && "invalid type");
276
277 DeclarationFragments Fragments;
278
279 // An ElaboratedType is a sugar for types that are referred to using an
280 // elaborated keyword, e.g., `struct S`, `enum E`, or (in C++) via a
281 // qualified name, e.g., `N::M::type`, or both.
282 if (const ElaboratedType *ET = dyn_cast<ElaboratedType>(T)) {
283 ElaboratedTypeKeyword Keyword = ET->getKeyword();
284 if (Keyword != ElaboratedTypeKeyword::None) {
285 Fragments
288 .appendSpace();
289 }
290
291 if (const NestedNameSpecifier *NNS = ET->getQualifier())
292 Fragments.append(getFragmentsForNNS(NNS, Context, After));
293
294 // After handling the elaborated keyword or qualified name, build
295 // declaration fragments for the desugared underlying type.
296 return Fragments.append(getFragmentsForType(ET->desugar(), Context, After));
297 }
298
299 // If the type is a typedefed type, get the underlying TypedefNameDecl for a
300 // direct reference to the typedef instead of the wrapped type.
301
302 // 'id' type is a typedef for an ObjCObjectPointerType
303 // we treat it as a typedef
304 if (const TypedefType *TypedefTy = dyn_cast<TypedefType>(T)) {
305 const TypedefNameDecl *Decl = TypedefTy->getDecl();
306 TypedefUnderlyingTypeResolver TypedefResolver(Context);
307 std::string USR = TypedefResolver.getUSRForType(QualType(T, 0));
308
309 if (T->isObjCIdType()) {
310 return Fragments.append(Decl->getName(),
312 }
313
314 return Fragments.append(
316 USR, TypedefResolver.getUnderlyingTypeDecl(QualType(T, 0)));
317 }
318
319 // Declaration fragments of a pointer type is the declaration fragments of
320 // the pointee type followed by a `*`,
322 return Fragments
323 .append(getFragmentsForType(T->getPointeeType(), Context, After))
325
326 // For Objective-C `id` and `Class` pointers
327 // we do not spell out the `*`.
328 if (T->isObjCObjectPointerType() &&
330
331 Fragments.append(getFragmentsForType(T->getPointeeType(), Context, After));
332
333 // id<protocol> is an qualified id type
334 // id<protocol>* is not an qualified id type
337 }
338
339 return Fragments;
340 }
341
342 // Declaration fragments of a lvalue reference type is the declaration
343 // fragments of the underlying type followed by a `&`.
344 if (const LValueReferenceType *LRT = dyn_cast<LValueReferenceType>(T))
345 return Fragments
346 .append(
347 getFragmentsForType(LRT->getPointeeTypeAsWritten(), Context, After))
349
350 // Declaration fragments of a rvalue reference type is the declaration
351 // fragments of the underlying type followed by a `&&`.
352 if (const RValueReferenceType *RRT = dyn_cast<RValueReferenceType>(T))
353 return Fragments
354 .append(
355 getFragmentsForType(RRT->getPointeeTypeAsWritten(), Context, After))
357
358 // Declaration fragments of an array-typed variable have two parts:
359 // 1. the element type of the array that appears before the variable name;
360 // 2. array brackets `[(0-9)?]` that appear after the variable name.
361 if (const ArrayType *AT = T->getAsArrayTypeUnsafe()) {
362 // Build the "after" part first because the inner element type might also
363 // be an array-type. For example `int matrix[3][4]` which has a type of
364 // "(array 3 of (array 4 of ints))."
365 // Push the array size part first to make sure they are in the right order.
367
368 switch (AT->getSizeModifier()) {
370 break;
373 break;
376 break;
377 }
378
379 if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) {
380 // FIXME: right now this would evaluate any expressions/macros written in
381 // the original source to concrete values. For example
382 // `int nums[MAX]` -> `int nums[100]`
383 // `char *str[5 + 1]` -> `char *str[6]`
385 CAT->getSize().toStringUnsigned(Size);
387 }
388
390
391 return Fragments.append(
392 getFragmentsForType(AT->getElementType(), Context, After));
393 }
394
395 if (const TemplateSpecializationType *TemplSpecTy =
396 dyn_cast<TemplateSpecializationType>(T)) {
397 const auto TemplName = TemplSpecTy->getTemplateName();
398 std::string Str;
399 raw_string_ostream Stream(Str);
400 TemplName.print(Stream, Context.getPrintingPolicy(),
402 SmallString<64> USR("");
403 if (const auto *TemplDecl = TemplName.getAsTemplateDecl())
404 index::generateUSRForDecl(TemplDecl, USR);
405
406 return Fragments
410 TemplSpecTy->template_arguments(), Context, std::nullopt))
412 }
413
414 // Everything we care about has been handled now, reduce to the canonical
415 // unqualified base type.
417
418 // If the base type is a TagType (struct/interface/union/class/enum), let's
419 // get the underlying Decl for better names and USRs.
420 if (const TagType *TagTy = dyn_cast<TagType>(Base)) {
421 const TagDecl *Decl = TagTy->getDecl();
422 // Anonymous decl, skip this fragment.
423 if (Decl->getName().empty())
424 return Fragments.append("{ ... }",
426 SmallString<128> TagUSR;
428 return Fragments.append(Decl->getName(),
430 TagUSR, Decl);
431 }
432
433 // If the base type is an ObjCInterfaceType, use the underlying
434 // ObjCInterfaceDecl for the true USR.
435 if (const auto *ObjCIT = dyn_cast<ObjCInterfaceType>(Base)) {
436 const auto *Decl = ObjCIT->getDecl();
439 return Fragments.append(Decl->getName(),
441 USR, Decl);
442 }
443
444 // Default fragment builder for other kinds of types (BuiltinType etc.)
447 Fragments.append(Base.getAsString(),
449
450 return Fragments;
451}
452
454DeclarationFragmentsBuilder::getFragmentsForQualifiers(const Qualifiers Quals) {
455 DeclarationFragments Fragments;
456 if (Quals.hasConst())
458 if (Quals.hasVolatile())
460 if (Quals.hasRestrict())
462
463 return Fragments;
464}
465
466DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
467 const QualType QT, ASTContext &Context, DeclarationFragments &After) {
468 assert(!QT.isNull() && "invalid type");
469
470 if (const ParenType *PT = dyn_cast<ParenType>(QT)) {
472 return getFragmentsForType(PT->getInnerType(), Context, After)
474 }
475
476 const SplitQualType SQT = QT.split();
477 DeclarationFragments QualsFragments = getFragmentsForQualifiers(SQT.Quals),
478 TypeFragments =
479 getFragmentsForType(SQT.Ty, Context, After);
480 if (QT.getAsString() == "_Bool")
481 TypeFragments.replace("bool", 0);
482
483 if (QualsFragments.getFragments().empty())
484 return TypeFragments;
485
486 // Use east qualifier for pointer types
487 // For example:
488 // ```
489 // int * const
490 // ^---- ^----
491 // type qualifier
492 // ^-----------------
493 // const pointer to int
494 // ```
495 // should not be reconstructed as
496 // ```
497 // const int *
498 // ^---- ^--
499 // qualifier type
500 // ^---------------- ^
501 // pointer to const int
502 // ```
503 if (SQT.Ty->isAnyPointerType())
504 return TypeFragments.appendSpace().append(std::move(QualsFragments));
505
506 return QualsFragments.appendSpace().append(std::move(TypeFragments));
507}
508
510 const NamespaceDecl *Decl) {
511 DeclarationFragments Fragments;
513 if (!Decl->isAnonymousNamespace())
514 Fragments.appendSpace().append(
516 return Fragments.appendSemicolon();
517}
518
521 DeclarationFragments Fragments;
522 if (Var->isConstexpr())
524 .appendSpace();
525
526 StorageClass SC = Var->getStorageClass();
527 if (SC != SC_None)
528 Fragments
531 .appendSpace();
532
533 // Capture potential fragments that needs to be placed after the variable name
534 // ```
535 // int nums[5];
536 // char (*ptr_to_array)[6];
537 // ```
539 FunctionTypeLoc BlockLoc;
540 FunctionProtoTypeLoc BlockProtoLoc;
541 findTypeLocForBlockDecl(Var->getTypeSourceInfo(), BlockLoc, BlockProtoLoc);
542
543 if (!BlockLoc) {
545 ? Var->getTypeSourceInfo()->getType()
547 Var->getType());
548
549 Fragments.append(getFragmentsForType(T, Var->getASTContext(), After))
550 .appendSpace();
551 } else {
552 Fragments.append(getFragmentsForBlock(Var, BlockLoc, BlockProtoLoc, After));
553 }
554
555 return Fragments
557 .append(std::move(After))
559}
560
563 DeclarationFragments Fragments;
564 if (Var->isConstexpr())
566 .appendSpace();
567 QualType T =
568 Var->getTypeSourceInfo()
569 ? Var->getTypeSourceInfo()->getType()
571
572 // Might be a member, so might be static.
573 if (Var->isStaticDataMember())
575 .appendSpace();
576
578 DeclarationFragments ArgumentFragment =
579 getFragmentsForType(T, Var->getASTContext(), After);
580 if (StringRef(ArgumentFragment.begin()->Spelling)
581 .starts_with("type-parameter")) {
582 std::string ProperArgName = T.getAsString();
583 ArgumentFragment.begin()->Spelling.swap(ProperArgName);
584 }
585 Fragments.append(std::move(ArgumentFragment))
586 .appendSpace()
589 return Fragments;
590}
591
593DeclarationFragmentsBuilder::getFragmentsForParam(const ParmVarDecl *Param) {
594 DeclarationFragments Fragments, After;
595
596 auto *TSInfo = Param->getTypeSourceInfo();
597
598 QualType T = TSInfo ? TSInfo->getType()
600 Param->getType());
601
602 FunctionTypeLoc BlockLoc;
603 FunctionProtoTypeLoc BlockProtoLoc;
604 findTypeLocForBlockDecl(TSInfo, BlockLoc, BlockProtoLoc);
605
606 DeclarationFragments TypeFragments;
607 if (BlockLoc)
608 TypeFragments.append(
609 getFragmentsForBlock(Param, BlockLoc, BlockProtoLoc, After));
610 else
611 TypeFragments.append(getFragmentsForType(T, Param->getASTContext(), After));
612
613 if (StringRef(TypeFragments.begin()->Spelling)
614 .starts_with("type-parameter")) {
615 std::string ProperArgName = Param->getOriginalType().getAsString();
616 TypeFragments.begin()->Spelling.swap(ProperArgName);
617 }
618
619 if (Param->isObjCMethodParameter()) {
621 .append(std::move(TypeFragments))
622 .append(std::move(After))
624 .append(Param->getName(),
626 } else {
627 Fragments.append(std::move(TypeFragments));
628 if (!T->isBlockPointerType())
629 Fragments.appendSpace();
630 Fragments
631 .append(Param->getName(),
633 .append(std::move(After));
634 }
635 return Fragments;
636}
637
638DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForBlock(
640 FunctionProtoTypeLoc &BlockProto, DeclarationFragments &After) {
641 DeclarationFragments Fragments;
642
643 DeclarationFragments RetTyAfter;
644 auto ReturnValueFragment = getFragmentsForType(
645 Block.getTypePtr()->getReturnType(), BlockDecl->getASTContext(), After);
646
647 Fragments.append(std::move(ReturnValueFragment))
648 .append(std::move(RetTyAfter))
649 .appendSpace()
651
653 unsigned NumParams = Block.getNumParams();
654
655 if (!BlockProto || NumParams == 0) {
656 if (BlockProto && BlockProto.getTypePtr()->isVariadic())
658 else
660 } else {
662 for (unsigned I = 0; I != NumParams; ++I) {
663 if (I)
665 After.append(getFragmentsForParam(Block.getParam(I)));
666 if (I == NumParams - 1 && BlockProto.getTypePtr()->isVariadic())
668 }
670 }
671
672 return Fragments;
673}
674
677 DeclarationFragments Fragments;
678 switch (Func->getStorageClass()) {
679 case SC_None:
680 case SC_PrivateExtern:
681 break;
682 case SC_Extern:
684 .appendSpace();
685 break;
686 case SC_Static:
688 .appendSpace();
689 break;
690 case SC_Auto:
691 case SC_Register:
692 llvm_unreachable("invalid for functions");
693 }
694 if (Func->isConsteval()) // if consteval, it is also constexpr
696 .appendSpace();
697 else if (Func->isConstexpr())
699 .appendSpace();
700
701 // FIXME: Is `after` actually needed here?
703 auto ReturnValueFragment =
704 getFragmentsForType(Func->getReturnType(), Func->getASTContext(), After);
705 if (StringRef(ReturnValueFragment.begin()->Spelling)
706 .starts_with("type-parameter")) {
707 std::string ProperArgName = Func->getReturnType().getAsString();
708 ReturnValueFragment.begin()->Spelling.swap(ProperArgName);
709 }
710
711 Fragments.append(std::move(ReturnValueFragment))
712 .appendSpace()
713 .append(Func->getNameAsString(),
715
716 if (Func->getTemplateSpecializationInfo()) {
718
719 for (unsigned i = 0, end = Func->getNumParams(); i != end; ++i) {
720 if (i)
722 Fragments.append(
723 getFragmentsForType(Func->getParamDecl(i)->getType(),
724 Func->getParamDecl(i)->getASTContext(), After));
725 }
727 }
728 Fragments.append(std::move(After));
729
731 unsigned NumParams = Func->getNumParams();
732 for (unsigned i = 0; i != NumParams; ++i) {
733 if (i)
735 Fragments.append(getFragmentsForParam(Func->getParamDecl(i)));
736 }
737
738 if (Func->isVariadic()) {
739 if (NumParams > 0)
742 }
744
746 Func->getExceptionSpecType()));
747
748 return Fragments.appendSemicolon();
749}
750
752 const EnumConstantDecl *EnumConstDecl) {
753 DeclarationFragments Fragments;
754 return Fragments.append(EnumConstDecl->getName(),
756}
757
762
763 DeclarationFragments Fragments, After;
765
766 if (!EnumDecl->getName().empty())
767 Fragments.appendSpace().append(
769
770 QualType IntegerType = EnumDecl->getIntegerType();
771 if (!IntegerType.isNull())
772 Fragments.appendSpace()
774 .append(
775 getFragmentsForType(IntegerType, EnumDecl->getASTContext(), After))
776 .append(std::move(After));
777
778 if (EnumDecl->getName().empty())
779 Fragments.appendSpace().append("{ ... }",
781
782 return Fragments.appendSemicolon();
783}
784
788 DeclarationFragments Fragments;
789 if (Field->isMutable())
791 .appendSpace();
792 return Fragments
793 .append(
794 getFragmentsForType(Field->getType(), Field->getASTContext(), After))
795 .appendSpace()
797 .append(std::move(After))
799}
800
802 const RecordDecl *Record) {
803 if (const auto *TypedefNameDecl = Record->getTypedefNameForAnonDecl())
805
806 DeclarationFragments Fragments;
807 if (Record->isUnion())
809 else
811
812 Fragments.appendSpace();
813 if (!Record->getName().empty())
814 Fragments.append(Record->getName(),
816 else
818
819 return Fragments.appendSemicolon();
820}
821
823 const CXXRecordDecl *Record) {
824 if (const auto *TypedefNameDecl = Record->getTypedefNameForAnonDecl())
826
827 DeclarationFragments Fragments;
829
830 if (!Record->getName().empty())
831 Fragments.appendSpace().append(
833
834 return Fragments.appendSemicolon();
835}
836
839 const CXXMethodDecl *Method) {
840 DeclarationFragments Fragments;
841 std::string Name;
842 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(Method)) {
843 Name = Method->getNameAsString();
844 if (Constructor->isExplicit())
846 .appendSpace();
847 } else if (isa<CXXDestructorDecl>(Method))
848 Name = Method->getNameAsString();
849
852 .append(std::move(After));
854 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
855 if (i)
857 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
858 }
860
862 Method->getExceptionSpecType()));
863
864 return Fragments.appendSemicolon();
865}
866
868 const CXXMethodDecl *Method) {
869 DeclarationFragments Fragments;
870 StringRef Name = Method->getName();
871 if (Method->isStatic())
873 .appendSpace();
874 if (Method->isConstexpr())
876 .appendSpace();
877 if (Method->isVolatile())
879 .appendSpace();
880
881 // Build return type
883 Fragments
884 .append(getFragmentsForType(Method->getReturnType(),
885 Method->getASTContext(), After))
886 .appendSpace()
888 .append(std::move(After));
890 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
891 if (i)
893 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
894 }
896
897 if (Method->isConst())
898 Fragments.appendSpace().append("const",
900
902 Method->getExceptionSpecType()));
903
904 return Fragments.appendSemicolon();
905}
906
909 const CXXConversionDecl *ConversionFunction) {
910 DeclarationFragments Fragments;
911
912 if (ConversionFunction->isExplicit())
914 .appendSpace();
915
917 .appendSpace();
918
919 Fragments
920 .append(ConversionFunction->getConversionType().getAsString(),
923 for (unsigned i = 0, end = ConversionFunction->getNumParams(); i != end;
924 ++i) {
925 if (i)
927 Fragments.append(getFragmentsForParam(ConversionFunction->getParamDecl(i)));
928 }
930
931 if (ConversionFunction->isConst())
932 Fragments.appendSpace().append("const",
934
935 return Fragments.appendSemicolon();
936}
937
940 const CXXMethodDecl *Method) {
941 DeclarationFragments Fragments;
942
943 // Build return type
945 Fragments
946 .append(getFragmentsForType(Method->getReturnType(),
947 Method->getASTContext(), After))
948 .appendSpace()
949 .append(Method->getNameAsString(),
951 .append(std::move(After));
953 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
954 if (i)
956 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
957 }
959
960 if (Method->isConst())
961 Fragments.appendSpace().append("const",
963
965 Method->getExceptionSpecType()));
966
967 return Fragments.appendSemicolon();
968}
969
970// Get fragments for template parameters, e.g. T in tempalte<typename T> ...
973 ArrayRef<NamedDecl *> ParameterArray) {
974 DeclarationFragments Fragments;
975 for (unsigned i = 0, end = ParameterArray.size(); i != end; ++i) {
976 if (i)
978 .appendSpace();
979
980 if (const auto *TemplateParam =
981 dyn_cast<TemplateTypeParmDecl>(ParameterArray[i])) {
982 if (TemplateParam->hasTypeConstraint())
983 Fragments.append(TemplateParam->getTypeConstraint()
984 ->getNamedConcept()
985 ->getName()
986 .str(),
988 else if (TemplateParam->wasDeclaredWithTypename())
989 Fragments.append("typename",
991 else
993
994 if (TemplateParam->isParameterPack())
996
997 if (!TemplateParam->getName().empty())
998 Fragments.appendSpace().append(
999 TemplateParam->getName(),
1001
1002 if (TemplateParam->hasDefaultArgument()) {
1003 const auto Default = TemplateParam->getDefaultArgument();
1006 {Default.getArgument()}, TemplateParam->getASTContext(),
1007 {Default}));
1008 }
1009 } else if (const auto *NTP =
1010 dyn_cast<NonTypeTemplateParmDecl>(ParameterArray[i])) {
1012 const auto TyFragments =
1013 getFragmentsForType(NTP->getType(), NTP->getASTContext(), After);
1014 Fragments.append(std::move(TyFragments)).append(std::move(After));
1015
1016 if (NTP->isParameterPack())
1018
1019 if (!NTP->getName().empty())
1020 Fragments.appendSpace().append(
1021 NTP->getName(),
1023
1024 if (NTP->hasDefaultArgument()) {
1025 SmallString<8> ExprStr;
1026 raw_svector_ostream Output(ExprStr);
1027 NTP->getDefaultArgument().getArgument().print(
1028 NTP->getASTContext().getPrintingPolicy(), Output,
1029 /*IncludeType=*/false);
1032 }
1033 } else if (const auto *TTP =
1034 dyn_cast<TemplateTemplateParmDecl>(ParameterArray[i])) {
1036 .appendSpace()
1039 TTP->getTemplateParameters()->asArray()))
1041 .appendSpace()
1042 .append(TTP->wasDeclaredWithTypename() ? "typename" : "class",
1044
1045 if (TTP->isParameterPack())
1047
1048 if (!TTP->getName().empty())
1049 Fragments.appendSpace().append(
1050 TTP->getName(),
1052 if (TTP->hasDefaultArgument()) {
1053 const auto Default = TTP->getDefaultArgument();
1056 {Default.getArgument()}, TTP->getASTContext(), {Default}));
1057 }
1058 }
1059 }
1060 return Fragments;
1061}
1062
1063// Get fragments for template arguments, e.g. int in template<typename T>
1064// Foo<int>;
1065//
1066// Note: TemplateParameters is only necessary if the Decl is a
1067// PartialSpecialization, where we need the parameters to deduce the name of the
1068// generic arguments.
1071 const ArrayRef<TemplateArgument> TemplateArguments, ASTContext &Context,
1072 const std::optional<ArrayRef<TemplateArgumentLoc>> TemplateArgumentLocs) {
1073 DeclarationFragments Fragments;
1074 for (unsigned i = 0, end = TemplateArguments.size(); i != end; ++i) {
1075 if (i)
1077 .appendSpace();
1078
1079 const auto &CTA = TemplateArguments[i];
1080 switch (CTA.getKind()) {
1083 DeclarationFragments ArgumentFragment =
1084 getFragmentsForType(CTA.getAsType(), Context, After);
1085
1086 if (StringRef(ArgumentFragment.begin()->Spelling)
1087 .starts_with("type-parameter")) {
1088 if (TemplateArgumentLocs.has_value() &&
1089 TemplateArgumentLocs->size() > i) {
1090 std::string ProperArgName = TemplateArgumentLocs.value()[i]
1091 .getTypeSourceInfo()
1092 ->getType()
1093 .getAsString();
1094 ArgumentFragment.begin()->Spelling.swap(ProperArgName);
1095 } else {
1096 auto &Spelling = ArgumentFragment.begin()->Spelling;
1097 Spelling.clear();
1098 raw_string_ostream OutStream(Spelling);
1099 CTA.print(Context.getPrintingPolicy(), OutStream, false);
1100 OutStream.flush();
1101 }
1102 }
1103
1104 Fragments.append(std::move(ArgumentFragment));
1105 break;
1106 }
1108 const auto *VD = CTA.getAsDecl();
1109 SmallString<128> USR;
1111 Fragments.append(VD->getNameAsString(),
1113 break;
1114 }
1117 break;
1118
1120 SmallString<4> Str;
1121 CTA.getAsIntegral().toString(Str);
1123 break;
1124 }
1125
1127 const auto SVTy = CTA.getStructuralValueType();
1128 Fragments.append(CTA.getAsStructuralValue().getAsString(Context, SVTy),
1130 break;
1131 }
1132
1135 std::string Str;
1136 raw_string_ostream Stream(Str);
1137 CTA.getAsTemplate().print(Stream, Context.getPrintingPolicy());
1138 SmallString<64> USR("");
1139 if (const auto *TemplDecl =
1140 CTA.getAsTemplateOrTemplatePattern().getAsTemplateDecl())
1141 index::generateUSRForDecl(TemplDecl, USR);
1143 USR);
1144 if (CTA.getKind() == TemplateArgument::TemplateExpansion)
1146 break;
1147 }
1148
1151 .append(getFragmentsForTemplateArguments(CTA.pack_elements(), Context,
1152 {}))
1154 break;
1155
1157 SmallString<8> ExprStr;
1158 raw_svector_ostream Output(ExprStr);
1159 CTA.getAsExpr()->printPretty(Output, nullptr,
1160 Context.getPrintingPolicy());
1162 break;
1163 }
1164
1166 break;
1167 }
1168 }
1169 return Fragments;
1170}
1171
1173 const ConceptDecl *Concept) {
1174 DeclarationFragments Fragments;
1175 return Fragments
1177 .appendSpace()
1180 Concept->getTemplateParameters()->asArray()))
1182 .appendSpace()
1184 .appendSpace()
1185 .append(Concept->getName().str(),
1187 .appendSemicolon();
1188}
1189
1192 const RedeclarableTemplateDecl *RedeclarableTemplate) {
1193 DeclarationFragments Fragments;
1195 .appendSpace()
1198 RedeclarableTemplate->getTemplateParameters()->asArray()))
1200 .appendSpace();
1201
1202 if (isa<TypeAliasTemplateDecl>(RedeclarableTemplate))
1203 Fragments.appendSpace()
1205 .appendSpace()
1206 .append(RedeclarableTemplate->getName(),
1208 // the templated records will be resposbible for injecting their templates
1209 return Fragments.appendSpace();
1210}
1211
1215 DeclarationFragments Fragments;
1216 return Fragments
1218 .appendSpace()
1221 .appendSpace()
1223 cast<CXXRecordDecl>(Decl)))
1224 .pop_back() // there is an extra semicolon now
1227 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1228 Decl->getTemplateArgsAsWritten()->arguments()))
1230 .appendSemicolon();
1231}
1232
1236 DeclarationFragments Fragments;
1237 return Fragments
1239 .appendSpace()
1242 Decl->getTemplateParameters()->asArray()))
1244 .appendSpace()
1246 cast<CXXRecordDecl>(Decl)))
1247 .pop_back() // there is an extra semicolon now
1250 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1251 Decl->getTemplateArgsAsWritten()->arguments()))
1253 .appendSemicolon();
1254}
1255
1259 DeclarationFragments Fragments;
1260 return Fragments
1262 .appendSpace()
1265 .appendSpace()
1267 .pop_back() // there is an extra semicolon now
1270 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1271 Decl->getTemplateArgsAsWritten()->arguments()))
1273 .appendSemicolon();
1274}
1275
1279 DeclarationFragments Fragments;
1280 return Fragments
1282 .appendSpace()
1284 // Partial specs may have new params.
1286 Decl->getTemplateParameters()->asArray()))
1288 .appendSpace()
1290 .pop_back() // there is an extra semicolon now
1293 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1294 Decl->getTemplateArgsAsWritten()->arguments()))
1296 .appendSemicolon();
1297}
1298
1301 const FunctionTemplateDecl *Decl) {
1302 DeclarationFragments Fragments;
1303 return Fragments
1305 .appendSpace()
1307 // Partial specs may have new params.
1309 Decl->getTemplateParameters()->asArray()))
1311 .appendSpace()
1313 Decl->getAsFunction()));
1314}
1315
1318 const FunctionDecl *Decl) {
1319 DeclarationFragments Fragments;
1320 return Fragments
1322 .appendSpace()
1324 .appendSpace()
1326}
1327
1330 const MacroDirective *MD) {
1331 DeclarationFragments Fragments;
1333 .appendSpace();
1335
1336 auto *MI = MD->getMacroInfo();
1337
1338 if (MI->isFunctionLike()) {
1340 unsigned numParameters = MI->getNumParams();
1341 if (MI->isC99Varargs())
1342 --numParameters;
1343 for (unsigned i = 0; i < numParameters; ++i) {
1344 if (i)
1346 Fragments.append(MI->params()[i]->getName(),
1348 }
1349 if (MI->isVariadic()) {
1350 if (numParameters && MI->isC99Varargs())
1353 }
1355 }
1356 return Fragments;
1357}
1358
1360 const ObjCCategoryDecl *Category) {
1361 DeclarationFragments Fragments;
1362
1363 auto *Interface = Category->getClassInterface();
1364 SmallString<128> InterfaceUSR;
1365 index::generateUSRForDecl(Interface, InterfaceUSR);
1366
1368 .appendSpace()
1369 .append(Interface->getName(),
1371 Interface)
1373 .append(Category->getName(),
1376
1377 return Fragments;
1378}
1379
1382 DeclarationFragments Fragments;
1383 // Build the base of the Objective-C interface declaration.
1385 .appendSpace()
1386 .append(Interface->getName(),
1388
1389 // Build the inheritance part of the declaration.
1390 if (const ObjCInterfaceDecl *SuperClass = Interface->getSuperClass()) {
1391 SmallString<128> SuperUSR;
1392 index::generateUSRForDecl(SuperClass, SuperUSR);
1394 .append(SuperClass->getName(),
1396 SuperClass);
1397 }
1398
1399 return Fragments;
1400}
1401
1403 const ObjCMethodDecl *Method) {
1404 DeclarationFragments Fragments, After;
1405 // Build the instance/class method indicator.
1406 if (Method->isClassMethod())
1408 else if (Method->isInstanceMethod())
1410
1411 // Build the return type.
1413 .append(getFragmentsForType(Method->getReturnType(),
1414 Method->getASTContext(), After))
1415 .append(std::move(After))
1417
1418 // Build the selector part.
1419 Selector Selector = Method->getSelector();
1420 if (Selector.getNumArgs() == 0)
1421 // For Objective-C methods that don't take arguments, the first (and only)
1422 // slot of the selector is the method name.
1423 Fragments.appendSpace().append(
1426
1427 // For Objective-C methods that take arguments, build the selector slots.
1428 for (unsigned i = 0, end = Method->param_size(); i != end; ++i) {
1429 // Objective-C method selector parts are considered as identifiers instead
1430 // of "external parameters" as in Swift. This is because Objective-C method
1431 // symbols are referenced with the entire selector, instead of just the
1432 // method name in Swift.
1434 ParamID.append(":");
1435 Fragments.appendSpace().append(
1437
1438 // Build the internal parameter.
1439 const ParmVarDecl *Param = Method->getParamDecl(i);
1440 Fragments.append(getFragmentsForParam(Param));
1441 }
1442
1443 return Fragments.appendSemicolon();
1444}
1445
1447 const ObjCPropertyDecl *Property) {
1448 DeclarationFragments Fragments, After;
1449
1450 // Build the Objective-C property keyword.
1452
1453 const auto Attributes = Property->getPropertyAttributesAsWritten();
1454 // Build the attributes if there is any associated with the property.
1455 if (Attributes != ObjCPropertyAttribute::kind_noattr) {
1456 // No leading comma for the first attribute.
1457 bool First = true;
1459 // Helper function to render the attribute.
1460 auto RenderAttribute =
1461 [&](ObjCPropertyAttribute::Kind Kind, StringRef Spelling,
1462 StringRef Arg = "",
1465 // Check if the `Kind` attribute is set for this property.
1466 if ((Attributes & Kind) && !Spelling.empty()) {
1467 // Add a leading comma if this is not the first attribute rendered.
1468 if (!First)
1470 // Render the spelling of this attribute `Kind` as a keyword.
1471 Fragments.append(Spelling,
1473 // If this attribute takes in arguments (e.g. `getter=getterName`),
1474 // render the arguments.
1475 if (!Arg.empty())
1477 .append(Arg, ArgKind);
1478 First = false;
1479 }
1480 };
1481
1482 // Go through all possible Objective-C property attributes and render set
1483 // ones.
1484 RenderAttribute(ObjCPropertyAttribute::kind_class, "class");
1485 RenderAttribute(ObjCPropertyAttribute::kind_direct, "direct");
1486 RenderAttribute(ObjCPropertyAttribute::kind_nonatomic, "nonatomic");
1487 RenderAttribute(ObjCPropertyAttribute::kind_atomic, "atomic");
1488 RenderAttribute(ObjCPropertyAttribute::kind_assign, "assign");
1489 RenderAttribute(ObjCPropertyAttribute::kind_retain, "retain");
1490 RenderAttribute(ObjCPropertyAttribute::kind_strong, "strong");
1491 RenderAttribute(ObjCPropertyAttribute::kind_copy, "copy");
1492 RenderAttribute(ObjCPropertyAttribute::kind_weak, "weak");
1494 "unsafe_unretained");
1495 RenderAttribute(ObjCPropertyAttribute::kind_readwrite, "readwrite");
1496 RenderAttribute(ObjCPropertyAttribute::kind_readonly, "readonly");
1497 RenderAttribute(ObjCPropertyAttribute::kind_getter, "getter",
1498 Property->getGetterName().getAsString());
1499 RenderAttribute(ObjCPropertyAttribute::kind_setter, "setter",
1500 Property->getSetterName().getAsString());
1501
1502 // Render nullability attributes.
1503 if (Attributes & ObjCPropertyAttribute::kind_nullability) {
1504 QualType Type = Property->getType();
1505 if (const auto Nullability =
1507 if (!First)
1509 if (*Nullability == NullabilityKind::Unspecified &&
1511 Fragments.append("null_resettable",
1513 else
1514 Fragments.append(
1515 getNullabilitySpelling(*Nullability, /*isContextSensitive=*/true),
1517 First = false;
1518 }
1519 }
1520
1522 }
1523
1524 Fragments.appendSpace();
1525
1526 FunctionTypeLoc BlockLoc;
1527 FunctionProtoTypeLoc BlockProtoLoc;
1528 findTypeLocForBlockDecl(Property->getTypeSourceInfo(), BlockLoc,
1529 BlockProtoLoc);
1530
1531 auto PropType = Property->getType();
1532 if (!BlockLoc)
1533 Fragments
1534 .append(getFragmentsForType(PropType, Property->getASTContext(), After))
1535 .appendSpace();
1536 else
1537 Fragments.append(
1538 getFragmentsForBlock(Property, BlockLoc, BlockProtoLoc, After));
1539
1540 return Fragments
1541 .append(Property->getName(),
1543 .append(std::move(After))
1544 .appendSemicolon();
1545}
1546
1548 const ObjCProtocolDecl *Protocol) {
1549 DeclarationFragments Fragments;
1550 // Build basic protocol declaration.
1552 .appendSpace()
1553 .append(Protocol->getName(),
1555
1556 // If this protocol conforms to other protocols, build the conformance list.
1557 if (!Protocol->protocols().empty()) {
1559 for (ObjCProtocolDecl::protocol_iterator It = Protocol->protocol_begin();
1560 It != Protocol->protocol_end(); It++) {
1561 // Add a leading comma if this is not the first protocol rendered.
1562 if (It != Protocol->protocol_begin())
1564
1565 SmallString<128> USR;
1566 index::generateUSRForDecl(*It, USR);
1567 Fragments.append((*It)->getName(),
1569 *It);
1570 }
1572 }
1573
1574 return Fragments;
1575}
1576
1578 const TypedefNameDecl *Decl) {
1579 DeclarationFragments Fragments, After;
1581 .appendSpace()
1582 .append(getFragmentsForType(Decl->getUnderlyingType(),
1583 Decl->getASTContext(), After))
1584 .append(std::move(After))
1585 .appendSpace()
1587
1588 return Fragments.appendSemicolon();
1589}
1590
1591// Instantiate template for FunctionDecl.
1592template FunctionSignature
1594
1595// Instantiate template for ObjCMethodDecl.
1596template FunctionSignature
1598
1599// Subheading of a symbol defaults to its name.
1602 DeclarationFragments Fragments;
1603 if (isa<CXXConstructorDecl>(Decl) || isa<CXXDestructorDecl>(Decl))
1604 Fragments.append(cast<CXXRecordDecl>(Decl->getDeclContext())->getName(),
1606 else if (isa<CXXConversionDecl>(Decl)) {
1607 Fragments.append(
1608 cast<CXXConversionDecl>(Decl)->getConversionType().getAsString(),
1610 } else if (isa<CXXMethodDecl>(Decl) &&
1611 cast<CXXMethodDecl>(Decl)->isOverloadedOperator()) {
1612 Fragments.append(Decl->getNameAsString(),
1614 } else if (Decl->getIdentifier()) {
1615 Fragments.append(Decl->getName(),
1617 } else
1618 Fragments.append(Decl->getDeclName().getAsString(),
1620 return Fragments;
1621}
1622
1623// Subheading of an Objective-C method is a `+` or `-` sign indicating whether
1624// it's a class method or an instance method, followed by the selector name.
1627 DeclarationFragments Fragments;
1628 if (Method->isClassMethod())
1630 else if (Method->isInstanceMethod())
1632
1633 return Fragments.append(Method->getNameAsString(),
1635}
1636
1637// Subheading of a symbol defaults to its name.
1640 DeclarationFragments Fragments;
1642 return Fragments;
1643}
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.
int Category
Definition: Format.cpp:3004
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:187
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
Definition: ASTContext.h:2245
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3566
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:4865
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4471
Wrapper for source info for block pointers.
Definition: TypeLoc.h:1314
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2866
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2064
bool isVolatile() const
Definition: DeclCXX.h:2117
bool isConst() const
Definition: DeclCXX.h:2116
bool isStatic() const
Definition: DeclCXX.cpp:2224
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:3604
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:523
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition: DeclBase.cpp:249
DeclContext * getDeclContext()
Definition: DeclBase.h:455
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:760
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6762
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3274
Represents an enum.
Definition: Decl.h:3844
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:4004
Represents a member of a struct/union/class.
Definition: Decl.h:3030
Represents a function declaration or definition.
Definition: Decl.h:1932
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2669
ExceptionSpecificationType getExceptionSpecType() const
Gets the ExceptionSpecificationType as declared.
Definition: Decl.h:2741
QualType getReturnType() const
Definition: Decl.h:2717
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition: Decl.h:2395
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3678
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:5379
Declaration of a template function.
Definition: DeclTemplate.h:957
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:3472
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:3124
Represent a C++ namespace.
Definition: Decl.h:547
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
Definition: Decl.h:598
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:2328
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:7399
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
Definition: Type.h:7474
bool isObjCIdOrClassType() const
True if this is equivalent to the 'id' or 'Class' type,.
Definition: Type.h:7468
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:730
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2083
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2157
Sugar for parentheses used when specifying types.
Definition: Type.h:3161
Represents a parameter to a function.
Definition: Decl.h:1722
bool isObjCMethodParameter() const
Definition: Decl.h:1765
QualType getOriginalType() const
Definition: Decl.cpp:2912
A (possibly-)qualified type.
Definition: Type.h:941
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1008
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:7771
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition: Type.h:1339
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:319
bool hasConst() const
Definition: Type.h:444
bool hasRestrict() const
Definition: Type.h:464
bool hasVolatile() const
Definition: Type.h:454
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3490
Represents a struct/union/class.
Definition: Decl.h:4145
Declaration of a redeclarable template.
Definition: DeclTemplate.h:716
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:3561
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3789
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:93
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
Definition: TemplateBase.h:89
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:97
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:67
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:103
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:413
ArrayRef< NamedDecl * > asArray()
Definition: DeclTemplate.h:139
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:6480
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:7721
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:7732
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Definition: Type.cpp:3203
The base class of the type hierarchy.
Definition: Type.h:1829
bool isBlockPointerType() const
Definition: Type.h:8017
bool isFunctionPointerType() const
Definition: Type.h:8043
bool isPointerType() const
Definition: Type.h:8003
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:705
bool isObjCIdType() const
Definition: Type.h:8178
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition: Type.h:8593
bool isObjCObjectPointerType() const
Definition: Type.h:8145
bool isAnyPointerType() const
Definition: Type.h:8011
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8540
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3409
QualType getType() const
Definition: Decl.h:678
Represents a variable declaration or definition.
Definition: Decl.h:879
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1510
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
Definition: Decl.cpp:2103
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition: Decl.h:1231
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1116
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:248
@ SC_Auto
Definition: Specifiers.h:256
@ SC_PrivateExtern
Definition: Specifiers.h:253
@ SC_Extern
Definition: Specifiers.h:251
@ SC_Register
Definition: Specifiers.h:257
@ SC_Static
Definition: Specifiers.h:252
@ SC_None
Definition: Specifiers.h:250
@ 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:6665
@ 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:874
const Type * Ty
The locally-unqualified type.
Definition: Type.h:876
Qualifiers Quals
The local qualifiers.
Definition: Type.h:879
Fragment holds information of a single fragment.