clang 19.0.0git
DeclarationFragments.cpp
Go to the documentation of this file.
1//===- ExtractAPI/DeclarationFragments.cpp ----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file implements Declaration Fragments related classes.
11///
12//===----------------------------------------------------------------------===//
13
15#include "clang/AST/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()
714
715 if (Func->getTemplateSpecializationInfo()) {
717
718 for (unsigned i = 0, end = Func->getNumParams(); i != end; ++i) {
719 if (i)
721 Fragments.append(
722 getFragmentsForType(Func->getParamDecl(i)->getType(),
723 Func->getParamDecl(i)->getASTContext(), After));
724 }
726 }
727 Fragments.append(std::move(After));
728
730 unsigned NumParams = Func->getNumParams();
731 for (unsigned i = 0; i != NumParams; ++i) {
732 if (i)
734 Fragments.append(getFragmentsForParam(Func->getParamDecl(i)));
735 }
736
737 if (Func->isVariadic()) {
738 if (NumParams > 0)
741 }
743
745 Func->getExceptionSpecType()));
746
747 return Fragments.appendSemicolon();
748}
749
751 const EnumConstantDecl *EnumConstDecl) {
752 DeclarationFragments Fragments;
753 return Fragments.append(EnumConstDecl->getName(),
755}
756
761
762 DeclarationFragments Fragments, After;
764
765 if (!EnumDecl->getName().empty())
766 Fragments.appendSpace().append(
768
769 QualType IntegerType = EnumDecl->getIntegerType();
770 if (!IntegerType.isNull())
771 Fragments.appendSpace()
773 .append(
774 getFragmentsForType(IntegerType, EnumDecl->getASTContext(), After))
775 .append(std::move(After));
776
777 if (EnumDecl->getName().empty())
778 Fragments.appendSpace().append("{ ... }",
780
781 return Fragments.appendSemicolon();
782}
783
787 DeclarationFragments Fragments;
788 if (Field->isMutable())
790 .appendSpace();
791 return Fragments
792 .append(
793 getFragmentsForType(Field->getType(), Field->getASTContext(), After))
794 .appendSpace()
796 .append(std::move(After))
798}
799
801 const RecordDecl *Record) {
802 if (const auto *TypedefNameDecl = Record->getTypedefNameForAnonDecl())
804
805 DeclarationFragments Fragments;
806 if (Record->isUnion())
808 else
810
811 Fragments.appendSpace();
812 if (!Record->getName().empty())
813 Fragments.append(Record->getName(),
815 else
817
818 return Fragments.appendSemicolon();
819}
820
822 const CXXRecordDecl *Record) {
823 if (const auto *TypedefNameDecl = Record->getTypedefNameForAnonDecl())
825
826 DeclarationFragments Fragments;
828
829 if (!Record->getName().empty())
830 Fragments.appendSpace().append(
832
833 return Fragments.appendSemicolon();
834}
835
838 const CXXMethodDecl *Method) {
839 DeclarationFragments Fragments;
840 std::string Name;
841 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(Method)) {
842 Name = Method->getNameAsString();
843 if (Constructor->isExplicit())
845 .appendSpace();
846 } else if (isa<CXXDestructorDecl>(Method))
847 Name = Method->getNameAsString();
848
851 .append(std::move(After));
853 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
854 if (i)
856 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
857 }
859
861 Method->getExceptionSpecType()));
862
863 return Fragments.appendSemicolon();
864}
865
867 const CXXMethodDecl *Method) {
868 DeclarationFragments Fragments;
869 StringRef Name = Method->getName();
870 if (Method->isStatic())
872 .appendSpace();
873 if (Method->isConstexpr())
875 .appendSpace();
876 if (Method->isVolatile())
878 .appendSpace();
879
880 // Build return type
882 Fragments
883 .append(getFragmentsForType(Method->getReturnType(),
884 Method->getASTContext(), After))
885 .appendSpace()
887 .append(std::move(After));
889 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
890 if (i)
892 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
893 }
895
896 if (Method->isConst())
897 Fragments.appendSpace().append("const",
899
901 Method->getExceptionSpecType()));
902
903 return Fragments.appendSemicolon();
904}
905
908 const CXXConversionDecl *ConversionFunction) {
909 DeclarationFragments Fragments;
910
911 if (ConversionFunction->isExplicit())
913 .appendSpace();
914
916 .appendSpace();
917
918 Fragments
919 .append(ConversionFunction->getConversionType().getAsString(),
922 for (unsigned i = 0, end = ConversionFunction->getNumParams(); i != end;
923 ++i) {
924 if (i)
926 Fragments.append(getFragmentsForParam(ConversionFunction->getParamDecl(i)));
927 }
929
930 if (ConversionFunction->isConst())
931 Fragments.appendSpace().append("const",
933
934 return Fragments.appendSemicolon();
935}
936
939 const CXXMethodDecl *Method) {
940 DeclarationFragments Fragments;
941
942 // Build return type
944 Fragments
945 .append(getFragmentsForType(Method->getReturnType(),
946 Method->getASTContext(), After))
947 .appendSpace()
948 .append(Method->getNameAsString(),
950 .append(std::move(After));
952 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
953 if (i)
955 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
956 }
958
959 if (Method->isConst())
960 Fragments.appendSpace().append("const",
962
964 Method->getExceptionSpecType()));
965
966 return Fragments.appendSemicolon();
967}
968
969// Get fragments for template parameters, e.g. T in tempalte<typename T> ...
972 ArrayRef<NamedDecl *> ParameterArray) {
973 DeclarationFragments Fragments;
974 for (unsigned i = 0, end = ParameterArray.size(); i != end; ++i) {
975 if (i)
977 .appendSpace();
978
979 if (const auto *TemplateParam =
980 dyn_cast<TemplateTypeParmDecl>(ParameterArray[i])) {
981 if (TemplateParam->hasTypeConstraint())
982 Fragments.append(TemplateParam->getTypeConstraint()
983 ->getNamedConcept()
984 ->getName()
985 .str(),
987 else if (TemplateParam->wasDeclaredWithTypename())
988 Fragments.append("typename",
990 else
992
993 if (TemplateParam->isParameterPack())
995
996 if (!TemplateParam->getName().empty())
997 Fragments.appendSpace().append(
998 TemplateParam->getName(),
1000
1001 if (TemplateParam->hasDefaultArgument()) {
1004 .append(getFragmentsForType(TemplateParam->getDefaultArgument(),
1005 TemplateParam->getASTContext(), After));
1006 Fragments.append(std::move(After));
1007 }
1008 } else if (const auto *NTP =
1009 dyn_cast<NonTypeTemplateParmDecl>(ParameterArray[i])) {
1011 const auto TyFragments =
1012 getFragmentsForType(NTP->getType(), NTP->getASTContext(), After);
1013 Fragments.append(std::move(TyFragments)).append(std::move(After));
1014
1015 if (NTP->isParameterPack())
1017
1018 if (!NTP->getName().empty())
1019 Fragments.appendSpace().append(
1020 NTP->getName(),
1022
1023 if (NTP->hasDefaultArgument()) {
1024 SmallString<8> ExprStr;
1025 raw_svector_ostream Output(ExprStr);
1026 NTP->getDefaultArgument()->printPretty(
1027 Output, nullptr, NTP->getASTContext().getPrintingPolicy());
1030 }
1031 } else if (const auto *TTP =
1032 dyn_cast<TemplateTemplateParmDecl>(ParameterArray[i])) {
1034 .appendSpace()
1037 TTP->getTemplateParameters()->asArray()))
1039 .appendSpace()
1040 .append(TTP->wasDeclaredWithTypename() ? "typename" : "class",
1042
1043 if (TTP->isParameterPack())
1045
1046 if (!TTP->getName().empty())
1047 Fragments.appendSpace().append(
1048 TTP->getName(),
1050 if (TTP->hasDefaultArgument()) {
1051 const auto Default = TTP->getDefaultArgument();
1054 {Default.getArgument()}, TTP->getASTContext(), {Default}));
1055 }
1056 }
1057 }
1058 return Fragments;
1059}
1060
1061// Get fragments for template arguments, e.g. int in template<typename T>
1062// Foo<int>;
1063//
1064// Note: TemplateParameters is only necessary if the Decl is a
1065// PartialSpecialization, where we need the parameters to deduce the name of the
1066// generic arguments.
1069 const ArrayRef<TemplateArgument> TemplateArguments, ASTContext &Context,
1070 const std::optional<ArrayRef<TemplateArgumentLoc>> TemplateArgumentLocs) {
1071 DeclarationFragments Fragments;
1072 for (unsigned i = 0, end = TemplateArguments.size(); i != end; ++i) {
1073 if (i)
1075 .appendSpace();
1076
1077 const auto &CTA = TemplateArguments[i];
1078 switch (CTA.getKind()) {
1081 DeclarationFragments ArgumentFragment =
1082 getFragmentsForType(CTA.getAsType(), Context, After);
1083
1084 if (StringRef(ArgumentFragment.begin()->Spelling)
1085 .starts_with("type-parameter")) {
1086 std::string ProperArgName = TemplateArgumentLocs.value()[i]
1087 .getTypeSourceInfo()
1088 ->getType()
1089 .getAsString();
1090 ArgumentFragment.begin()->Spelling.swap(ProperArgName);
1091 }
1092 Fragments.append(std::move(ArgumentFragment));
1093 break;
1094 }
1096 const auto *VD = CTA.getAsDecl();
1097 SmallString<128> USR;
1099 Fragments.append(VD->getNameAsString(),
1101 break;
1102 }
1105 break;
1106
1108 SmallString<4> Str;
1109 CTA.getAsIntegral().toString(Str);
1111 break;
1112 }
1113
1115 const auto SVTy = CTA.getStructuralValueType();
1116 Fragments.append(CTA.getAsStructuralValue().getAsString(Context, SVTy),
1118 break;
1119 }
1120
1123 std::string Str;
1124 raw_string_ostream Stream(Str);
1125 CTA.getAsTemplate().print(Stream, Context.getPrintingPolicy());
1126 SmallString<64> USR("");
1127 if (const auto *TemplDecl =
1128 CTA.getAsTemplateOrTemplatePattern().getAsTemplateDecl())
1129 index::generateUSRForDecl(TemplDecl, USR);
1131 USR);
1132 if (CTA.getKind() == TemplateArgument::TemplateExpansion)
1134 break;
1135 }
1136
1139 .append(getFragmentsForTemplateArguments(CTA.pack_elements(), Context,
1140 {}))
1142 break;
1143
1145 SmallString<8> ExprStr;
1146 raw_svector_ostream Output(ExprStr);
1147 CTA.getAsExpr()->printPretty(Output, nullptr,
1148 Context.getPrintingPolicy());
1150 break;
1151 }
1152
1154 break;
1155 }
1156 }
1157 return Fragments;
1158}
1159
1161 const ConceptDecl *Concept) {
1162 DeclarationFragments Fragments;
1163 return Fragments
1165 .appendSpace()
1168 Concept->getTemplateParameters()->asArray()))
1170 .appendSpace()
1172 .appendSpace()
1173 .append(Concept->getName().str(),
1175 .appendSemicolon();
1176}
1177
1180 const RedeclarableTemplateDecl *RedeclarableTemplate) {
1181 DeclarationFragments Fragments;
1183 .appendSpace()
1186 RedeclarableTemplate->getTemplateParameters()->asArray()))
1188 .appendSpace();
1189
1190 if (isa<TypeAliasTemplateDecl>(RedeclarableTemplate))
1191 Fragments.appendSpace()
1193 .appendSpace()
1194 .append(RedeclarableTemplate->getName(),
1196 // the templated records will be resposbible for injecting their templates
1197 return Fragments.appendSpace();
1198}
1199
1203 DeclarationFragments Fragments;
1204 return Fragments
1206 .appendSpace()
1209 .appendSpace()
1211 cast<CXXRecordDecl>(Decl)))
1212 .pop_back() // there is an extra semicolon now
1214 .append(
1215 getFragmentsForTemplateArguments(Decl->getTemplateArgs().asArray(),
1216 Decl->getASTContext(), std::nullopt))
1218 .appendSemicolon();
1219}
1220
1224 DeclarationFragments Fragments;
1225 return Fragments
1227 .appendSpace()
1230 Decl->getTemplateParameters()->asArray()))
1232 .appendSpace()
1234 cast<CXXRecordDecl>(Decl)))
1235 .pop_back() // there is an extra semicolon now
1238 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1239 Decl->getTemplateArgsAsWritten()->arguments()))
1241 .appendSemicolon();
1242}
1243
1247 DeclarationFragments Fragments;
1248 return Fragments
1250 .appendSpace()
1253 .appendSpace()
1255 .pop_back() // there is an extra semicolon now
1257 .append(
1258 getFragmentsForTemplateArguments(Decl->getTemplateArgs().asArray(),
1259 Decl->getASTContext(), std::nullopt))
1261 .appendSemicolon();
1262}
1263
1267 DeclarationFragments Fragments;
1268 return Fragments
1270 .appendSpace()
1272 // Partial specs may have new params.
1274 Decl->getTemplateParameters()->asArray()))
1276 .appendSpace()
1278 .pop_back() // there is an extra semicolon now
1281 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1282 Decl->getTemplateArgsAsWritten()->arguments()))
1284 .appendSemicolon();
1285}
1286
1289 const FunctionTemplateDecl *Decl) {
1290 DeclarationFragments Fragments;
1291 return Fragments
1293 .appendSpace()
1295 // Partial specs may have new params.
1297 Decl->getTemplateParameters()->asArray()))
1299 .appendSpace()
1301 Decl->getAsFunction()));
1302}
1303
1306 const FunctionDecl *Decl) {
1307 DeclarationFragments Fragments;
1308 return Fragments
1310 .appendSpace()
1312 .appendSpace()
1314}
1315
1318 const MacroDirective *MD) {
1319 DeclarationFragments Fragments;
1321 .appendSpace();
1323
1324 auto *MI = MD->getMacroInfo();
1325
1326 if (MI->isFunctionLike()) {
1328 unsigned numParameters = MI->getNumParams();
1329 if (MI->isC99Varargs())
1330 --numParameters;
1331 for (unsigned i = 0; i < numParameters; ++i) {
1332 if (i)
1334 Fragments.append(MI->params()[i]->getName(),
1336 }
1337 if (MI->isVariadic()) {
1338 if (numParameters && MI->isC99Varargs())
1341 }
1343 }
1344 return Fragments;
1345}
1346
1348 const ObjCCategoryDecl *Category) {
1349 DeclarationFragments Fragments;
1350
1351 auto *Interface = Category->getClassInterface();
1352 SmallString<128> InterfaceUSR;
1353 index::generateUSRForDecl(Interface, InterfaceUSR);
1354
1356 .appendSpace()
1357 .append(Interface->getName(),
1359 Interface)
1361 .append(Category->getName(),
1364
1365 return Fragments;
1366}
1367
1370 DeclarationFragments Fragments;
1371 // Build the base of the Objective-C interface declaration.
1373 .appendSpace()
1374 .append(Interface->getName(),
1376
1377 // Build the inheritance part of the declaration.
1378 if (const ObjCInterfaceDecl *SuperClass = Interface->getSuperClass()) {
1379 SmallString<128> SuperUSR;
1380 index::generateUSRForDecl(SuperClass, SuperUSR);
1382 .append(SuperClass->getName(),
1384 SuperClass);
1385 }
1386
1387 return Fragments;
1388}
1389
1391 const ObjCMethodDecl *Method) {
1392 DeclarationFragments Fragments, After;
1393 // Build the instance/class method indicator.
1394 if (Method->isClassMethod())
1396 else if (Method->isInstanceMethod())
1398
1399 // Build the return type.
1401 .append(getFragmentsForType(Method->getReturnType(),
1402 Method->getASTContext(), After))
1403 .append(std::move(After))
1405
1406 // Build the selector part.
1407 Selector Selector = Method->getSelector();
1408 if (Selector.getNumArgs() == 0)
1409 // For Objective-C methods that don't take arguments, the first (and only)
1410 // slot of the selector is the method name.
1411 Fragments.appendSpace().append(
1414
1415 // For Objective-C methods that take arguments, build the selector slots.
1416 for (unsigned i = 0, end = Method->param_size(); i != end; ++i) {
1417 // Objective-C method selector parts are considered as identifiers instead
1418 // of "external parameters" as in Swift. This is because Objective-C method
1419 // symbols are referenced with the entire selector, instead of just the
1420 // method name in Swift.
1422 ParamID.append(":");
1423 Fragments.appendSpace().append(
1425
1426 // Build the internal parameter.
1427 const ParmVarDecl *Param = Method->getParamDecl(i);
1428 Fragments.append(getFragmentsForParam(Param));
1429 }
1430
1431 return Fragments.appendSemicolon();
1432}
1433
1435 const ObjCPropertyDecl *Property) {
1436 DeclarationFragments Fragments, After;
1437
1438 // Build the Objective-C property keyword.
1440
1441 const auto Attributes = Property->getPropertyAttributesAsWritten();
1442 // Build the attributes if there is any associated with the property.
1443 if (Attributes != ObjCPropertyAttribute::kind_noattr) {
1444 // No leading comma for the first attribute.
1445 bool First = true;
1447 // Helper function to render the attribute.
1448 auto RenderAttribute =
1449 [&](ObjCPropertyAttribute::Kind Kind, StringRef Spelling,
1450 StringRef Arg = "",
1453 // Check if the `Kind` attribute is set for this property.
1454 if ((Attributes & Kind) && !Spelling.empty()) {
1455 // Add a leading comma if this is not the first attribute rendered.
1456 if (!First)
1458 // Render the spelling of this attribute `Kind` as a keyword.
1459 Fragments.append(Spelling,
1461 // If this attribute takes in arguments (e.g. `getter=getterName`),
1462 // render the arguments.
1463 if (!Arg.empty())
1465 .append(Arg, ArgKind);
1466 First = false;
1467 }
1468 };
1469
1470 // Go through all possible Objective-C property attributes and render set
1471 // ones.
1472 RenderAttribute(ObjCPropertyAttribute::kind_class, "class");
1473 RenderAttribute(ObjCPropertyAttribute::kind_direct, "direct");
1474 RenderAttribute(ObjCPropertyAttribute::kind_nonatomic, "nonatomic");
1475 RenderAttribute(ObjCPropertyAttribute::kind_atomic, "atomic");
1476 RenderAttribute(ObjCPropertyAttribute::kind_assign, "assign");
1477 RenderAttribute(ObjCPropertyAttribute::kind_retain, "retain");
1478 RenderAttribute(ObjCPropertyAttribute::kind_strong, "strong");
1479 RenderAttribute(ObjCPropertyAttribute::kind_copy, "copy");
1480 RenderAttribute(ObjCPropertyAttribute::kind_weak, "weak");
1482 "unsafe_unretained");
1483 RenderAttribute(ObjCPropertyAttribute::kind_readwrite, "readwrite");
1484 RenderAttribute(ObjCPropertyAttribute::kind_readonly, "readonly");
1485 RenderAttribute(ObjCPropertyAttribute::kind_getter, "getter",
1486 Property->getGetterName().getAsString());
1487 RenderAttribute(ObjCPropertyAttribute::kind_setter, "setter",
1488 Property->getSetterName().getAsString());
1489
1490 // Render nullability attributes.
1491 if (Attributes & ObjCPropertyAttribute::kind_nullability) {
1492 QualType Type = Property->getType();
1493 if (const auto Nullability =
1495 if (!First)
1497 if (*Nullability == NullabilityKind::Unspecified &&
1499 Fragments.append("null_resettable",
1501 else
1502 Fragments.append(
1503 getNullabilitySpelling(*Nullability, /*isContextSensitive=*/true),
1505 First = false;
1506 }
1507 }
1508
1510 }
1511
1512 Fragments.appendSpace();
1513
1514 FunctionTypeLoc BlockLoc;
1515 FunctionProtoTypeLoc BlockProtoLoc;
1516 findTypeLocForBlockDecl(Property->getTypeSourceInfo(), BlockLoc,
1517 BlockProtoLoc);
1518
1519 auto PropType = Property->getType();
1520 if (!BlockLoc)
1521 Fragments
1522 .append(getFragmentsForType(PropType, Property->getASTContext(), After))
1523 .appendSpace();
1524 else
1525 Fragments.append(
1526 getFragmentsForBlock(Property, BlockLoc, BlockProtoLoc, After));
1527
1528 return Fragments
1529 .append(Property->getName(),
1531 .append(std::move(After))
1532 .appendSemicolon();
1533}
1534
1536 const ObjCProtocolDecl *Protocol) {
1537 DeclarationFragments Fragments;
1538 // Build basic protocol declaration.
1540 .appendSpace()
1541 .append(Protocol->getName(),
1543
1544 // If this protocol conforms to other protocols, build the conformance list.
1545 if (!Protocol->protocols().empty()) {
1547 for (ObjCProtocolDecl::protocol_iterator It = Protocol->protocol_begin();
1548 It != Protocol->protocol_end(); It++) {
1549 // Add a leading comma if this is not the first protocol rendered.
1550 if (It != Protocol->protocol_begin())
1552
1553 SmallString<128> USR;
1554 index::generateUSRForDecl(*It, USR);
1555 Fragments.append((*It)->getName(),
1557 *It);
1558 }
1560 }
1561
1562 return Fragments;
1563}
1564
1566 const TypedefNameDecl *Decl) {
1567 DeclarationFragments Fragments, After;
1569 .appendSpace()
1570 .append(getFragmentsForType(Decl->getUnderlyingType(),
1571 Decl->getASTContext(), After))
1572 .append(std::move(After))
1573 .appendSpace()
1575
1576 return Fragments.appendSemicolon();
1577}
1578
1579// Instantiate template for FunctionDecl.
1580template FunctionSignature
1582
1583// Instantiate template for ObjCMethodDecl.
1584template FunctionSignature
1586
1587// Subheading of a symbol defaults to its name.
1590 DeclarationFragments Fragments;
1591 if (isa<CXXConstructorDecl>(Decl) || isa<CXXDestructorDecl>(Decl))
1592 Fragments.append(cast<CXXRecordDecl>(Decl->getDeclContext())->getName(),
1594 else if (isa<CXXConversionDecl>(Decl)) {
1595 Fragments.append(
1596 cast<CXXConversionDecl>(Decl)->getConversionType().getAsString(),
1598 } else if (isa<CXXMethodDecl>(Decl) &&
1599 cast<CXXMethodDecl>(Decl)->isOverloadedOperator()) {
1600 Fragments.append(Decl->getNameAsString(),
1602 } else if (!Decl->getName().empty())
1603 Fragments.append(Decl->getName(),
1605 return Fragments;
1606}
1607
1608// Subheading of an Objective-C method is a `+` or `-` sign indicating whether
1609// it's a class method or an instance method, followed by the selector name.
1612 DeclarationFragments Fragments;
1613 if (Method->isClassMethod())
1615 else if (Method->isInstanceMethod())
1617
1618 return Fragments.append(Method->getNameAsString(),
1620}
1621
1622// Subheading of a symbol defaults to its name.
1625 DeclarationFragments Fragments;
1627 return Fragments;
1628}
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:2978
const CFGBlock * Block
Definition: HTMLLogger.cpp:153
llvm::MachO::Record Record
Definition: MachO.h:31
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
This file defines the UnderlyingTypeResolver which is a helper type for resolving the undelrying type...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
Definition: ASTContext.h:2192
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3518
Type source information for an attributed type.
Definition: TypeLoc.h:875
static std::optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
Definition: Type.cpp:4801
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4494
Wrapper for source info for block pointers.
Definition: TypeLoc.h:1314
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2862
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2060
bool isVolatile() const
Definition: DeclCXX.h:2113
bool isConst() const
Definition: DeclCXX.h:2112
bool isStatic() const
Definition: DeclCXX.cpp:2186
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Represents a class template specialization, which refers to a class template with a given set of temp...
Declaration of a C++20 concept.
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3556
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition: DeclBase.cpp:227
DeclContext * getDeclContext()
Definition: DeclBase.h:454
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:799
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6371
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3297
Represents an enum.
Definition: Decl.h:3867
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:4027
Represents a member of a struct/union/class.
Definition: Decl.h:3057
Represents a function declaration or definition.
Definition: Decl.h:1971
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2706
ExceptionSpecificationType getExceptionSpecType() const
Gets the ExceptionSpecificationType as declared.
Definition: Decl.h:2778
QualType getReturnType() const
Definition: Decl.h:2754
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition: Decl.h:2432
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3692
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:5012
Declaration of a template function.
Definition: DeclTemplate.h: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:3424
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
Definition: MacroInfo.h:313
const MacroInfo * getMacroInfo() const
Definition: MacroInfo.h:416
This represents a decl that may have a name.
Definition: Decl.h:249
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
Definition: Decl.h:292
Represents a C++ namespace alias.
Definition: DeclCXX.h:3120
Represent a C++ namespace.
Definition: Decl.h:547
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
Definition: Decl.h:605
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2326
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
unsigned param_size() const
Definition: DeclObjC.h:347
Selector getSelector() const
Definition: DeclObjC.h:327
bool isInstanceMethod() const
Definition: DeclObjC.h:426
ParmVarDecl * getParamDecl(unsigned Idx)
Definition: DeclObjC.h:377
QualType getReturnType() const
Definition: DeclObjC.h:329
bool isClassMethod() const
Definition: DeclObjC.h:434
Represents a pointer to an Objective C object.
Definition: Type.h:7008
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
Definition: Type.h:7083
bool isObjCIdOrClassType() const
True if this is equivalent to the 'id' or 'Class' type,.
Definition: Type.h:7077
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:730
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2082
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2155
Sugar for parentheses used when specifying types.
Definition: Type.h:3113
Represents a parameter to a function.
Definition: Decl.h:1761
bool isObjCMethodParameter() const
Definition: Decl.h:1804
QualType getOriginalType() const
Definition: Decl.cpp:2924
A (possibly-)qualified type.
Definition: Type.h:940
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1007
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:7380
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition: Type.h:1327
Wrapper of type source information for a type with non-trivial direct qualifiers.
Definition: TypeLoc.h:289
The collection of all-type qualifiers we support.
Definition: Type.h:318
bool hasConst() const
Definition: Type.h:443
bool hasRestrict() const
Definition: Type.h:463
bool hasVolatile() const
Definition: Type.h:453
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3442
Represents a struct/union/class.
Definition: Decl.h:4168
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:3584
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3812
@ 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:6089
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:59
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
Definition: TypeLoc.h:338
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:89
TypeLoc IgnoreParens() const
Definition: TypeLoc.h:1225
A container of type source information.
Definition: Type.h:7330
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:256
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7341
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Definition: Type.cpp:3212
The base class of the type hierarchy.
Definition: Type.h:1813
bool isBlockPointerType() const
Definition: Type.h:7620
bool isFunctionPointerType() const
Definition: Type.h:7646
bool isPointerType() const
Definition: Type.h:7612
CanQualType getCanonicalTypeUnqualified() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:695
bool isObjCIdType() const
Definition: Type.h:7777
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition: Type.h:8179
bool isObjCObjectPointerType() const
Definition: Type.h:7744
bool isAnyPointerType() const
Definition: Type.h:7616
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8126
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3432
QualType getType() const
Definition: Decl.h:717
Represents a variable declaration or definition.
Definition: Decl.h:918
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1549
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
Definition: Decl.cpp:2118
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition: Decl.h:1270
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1155
Represents a variable template specialization, which refers to a variable template with a given set o...
static DeclarationFragments getFragmentsForRedeclarableTemplate(const RedeclarableTemplateDecl *)
static DeclarationFragments getFragmentsForCXXClass(const CXXRecordDecl *)
static DeclarationFragments getFragmentsForEnumConstant(const EnumConstantDecl *)
Build DeclarationFragments for an enum constant declaration EnumConstantDecl.
static DeclarationFragments getFragmentsForObjCCategory(const ObjCCategoryDecl *)
Build DeclarationFragments for an Objective-C category declaration ObjCCategoryDecl.
static DeclarationFragments getFragmentsForTypedef(const TypedefNameDecl *Decl)
Build DeclarationFragments for a typedef TypedefNameDecl.
static DeclarationFragments getFragmentsForEnum(const EnumDecl *)
Build DeclarationFragments for an enum declaration EnumDecl.
static DeclarationFragments getFragmentsForConversionFunction(const CXXConversionDecl *)
static DeclarationFragments getFragmentsForClassTemplateSpecialization(const ClassTemplateSpecializationDecl *)
static DeclarationFragments getFragmentsForTemplateParameters(ArrayRef< NamedDecl * >)
static DeclarationFragments getFragmentsForObjCProtocol(const ObjCProtocolDecl *)
Build DeclarationFragments for an Objective-C protocol declaration ObjCProtocolDecl.
static DeclarationFragments getFragmentsForConcept(const ConceptDecl *)
static DeclarationFragments getFragmentsForField(const FieldDecl *)
Build DeclarationFragments for a field declaration FieldDecl.
static DeclarationFragments getFragmentsForVar(const VarDecl *)
Build DeclarationFragments for a variable declaration VarDecl.
static DeclarationFragments getFragmentsForTemplateArguments(const ArrayRef< TemplateArgument >, ASTContext &, const std::optional< ArrayRef< TemplateArgumentLoc > >)
static DeclarationFragments getFragmentsForClassTemplatePartialSpecialization(const ClassTemplatePartialSpecializationDecl *)
static DeclarationFragments getFragmentsForObjCMethod(const ObjCMethodDecl *)
Build DeclarationFragments for an Objective-C method declaration ObjCMethodDecl.
static DeclarationFragments getSubHeadingForMacro(StringRef Name)
Build a sub-heading for macro Name.
static DeclarationFragments getFragmentsForFunction(const FunctionDecl *)
Build DeclarationFragments for a function declaration FunctionDecl.
static DeclarationFragments getFragmentsForObjCProperty(const ObjCPropertyDecl *)
Build DeclarationFragments for an Objective-C property declaration ObjCPropertyDecl.
static DeclarationFragments getFragmentsForSpecialCXXMethod(const CXXMethodDecl *)
static DeclarationFragments getFragmentsForCXXMethod(const CXXMethodDecl *)
static DeclarationFragments getFragmentsForNamespace(const NamespaceDecl *Decl)
static DeclarationFragments getFragmentsForVarTemplatePartialSpecialization(const VarTemplatePartialSpecializationDecl *)
static DeclarationFragments getFragmentsForFunctionTemplate(const FunctionTemplateDecl *Decl)
static DeclarationFragments getFragmentsForVarTemplateSpecialization(const VarTemplateSpecializationDecl *)
static FunctionSignature getFunctionSignature(const FunctionT *Function)
Build FunctionSignature for a function-like declaration FunctionT like FunctionDecl,...
static DeclarationFragments getSubHeading(const NamedDecl *)
Build sub-heading fragments for a NamedDecl.
static DeclarationFragments getFragmentsForVarTemplate(const VarDecl *)
static DeclarationFragments getFragmentsForOverloadedOperator(const CXXMethodDecl *)
static DeclarationFragments getFragmentsForFunctionTemplateSpecialization(const FunctionDecl *Decl)
static DeclarationFragments getFragmentsForMacro(StringRef Name, const MacroDirective *MD)
Build DeclarationFragments for a macro.
static DeclarationFragments getFragmentsForRecordDecl(const RecordDecl *)
Build DeclarationFragments for a struct/union record declaration RecordDecl.
static DeclarationFragments getFragmentsForObjCInterface(const ObjCInterfaceDecl *)
Build DeclarationFragments for an Objective-C interface declaration ObjCInterfaceDecl.
DeclarationFragments is a vector of tagged important parts of a symbol's declaration.
DeclarationFragments & append(DeclarationFragments Other)
Append another DeclarationFragments to the end.
const std::vector< Fragment > & getFragments() const
DeclarationFragments & appendSpace()
Append a text Fragment of a space character.
static DeclarationFragments getExceptionSpecificationString(ExceptionSpecificationType ExceptionSpec)
@ GenericParameter
Parameter that's used as generics in the context.
@ ExternalParam
External parameters in Objective-C methods.
@ TypeIdentifier
Identifier that refers to a type in the context.
@ InternalParam
Internal/local parameters in Objective-C methods.
DeclarationFragments & removeTrailingSemicolon()
Removes a trailing semicolon character if present.
static StringRef getFragmentKindString(FragmentKind Kind)
Get the string description of a FragmentKind Kind.
static DeclarationFragments getStructureTypeFragment(const RecordDecl *Decl)
DeclarationFragments & appendSemicolon()
Append a text Fragment of a semicolon character.
static FragmentKind parseFragmentKindFromString(StringRef S)
Get the corresponding FragmentKind from string S.
Store function signature information with DeclarationFragments of the return type and parameters.
@ kind_nullability
Indicates that the nullability of the type was spelled with a property attribute rather than a type q...
@ After
Like System, but searched after the system directories.
bool generateUSRForType(QualType T, ASTContext &Ctx, SmallVectorImpl< char > &Buf)
Generates a USR for a type.
bool generateUSRForDecl(const Decl *D, SmallVectorImpl< char > &Buf)
Generate a USR for a Decl, including the USR prefix.
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
StorageClass
Storage classes.
Definition: Specifiers.h:245
@ SC_Auto
Definition: Specifiers.h:253
@ SC_PrivateExtern
Definition: Specifiers.h:250
@ SC_Extern
Definition: Specifiers.h:248
@ SC_Register
Definition: Specifiers.h:254
@ SC_Static
Definition: Specifiers.h:249
@ SC_None
Definition: Specifiers.h:247
@ Property
The type of a property.
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
const FunctionProtoType * T
llvm::StringRef getAsString(SyncScope S)
Definition: SyncScope.h:60
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:6274
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
@ None
No keyword precedes the qualified type name.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_DependentNoexcept
noexcept(expression), value-dependent
@ EST_DynamicNone
throw()
@ EST_None
no exception specification
@ EST_BasicNoexcept
noexcept
@ EST_NoexceptFalse
noexcept(expression), evals to 'false'
@ EST_NoexceptTrue
noexcept(expression), evals to 'true'
@ EST_Dynamic
throw(T1, T2)
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:873
const Type * Ty
The locally-unqualified type.
Definition: Type.h:875
Qualifiers Quals
The local qualifiers.
Definition: Type.h:878
Fragment holds information of a single fragment.