clang 22.0.0git
DeclarationFragments.cpp
Go to the documentation of this file.
1//===- ExtractAPI/DeclarationFragments.cpp ----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file implements Declaration Fragments related classes.
11///
12//===----------------------------------------------------------------------===//
13
15#include "clang/AST/ASTFwd.h"
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclCXX.h"
20#include "clang/AST/Type.h"
21#include "clang/AST/TypeLoc.h"
24#include "llvm/ADT/StringSwitch.h"
25#include "llvm/Support/ErrorHandling.h"
26#include "llvm/Support/raw_ostream.h"
27#include <optional>
28
29using namespace clang::extractapi;
30using namespace llvm;
31
32namespace {
33
34void findTypeLocForBlockDecl(const clang::TypeSourceInfo *TSInfo,
36 clang::FunctionProtoTypeLoc &BlockProto) {
37 if (!TSInfo)
38 return;
39
41 while (true) {
42 // Look through qualified types
43 if (auto QualifiedTL = TL.getAs<clang::QualifiedTypeLoc>()) {
44 TL = QualifiedTL.getUnqualifiedLoc();
45 continue;
46 }
47
48 if (auto AttrTL = TL.getAs<clang::AttributedTypeLoc>()) {
49 TL = AttrTL.getModifiedLoc();
50 continue;
51 }
52
53 // Try to get the function prototype behind the block pointer type,
54 // then we're done.
55 if (auto BlockPtr = TL.getAs<clang::BlockPointerTypeLoc>()) {
56 TL = BlockPtr.getPointeeLoc().IgnoreParens();
57 Block = TL.getAs<clang::FunctionTypeLoc>();
58 BlockProto = TL.getAs<clang::FunctionProtoTypeLoc>();
59 }
60 break;
61 }
62}
63
64} // namespace
65
67DeclarationFragments::appendUnduplicatedTextCharacter(char Character) {
68 if (!Fragments.empty()) {
69 Fragment &Last = Fragments.back();
70 if (Last.Kind == FragmentKind::Text) {
71 // Merge the extra space into the last fragment if the last fragment is
72 // also text.
73 if (Last.Spelling.back() != Character) { // avoid duplicates at end
74 Last.Spelling.push_back(Character);
75 }
76 } else {
78 Fragments.back().Spelling.push_back(Character);
79 }
80 }
81
82 return *this;
83}
84
86 return appendUnduplicatedTextCharacter(' ');
87}
88
90 return appendUnduplicatedTextCharacter(';');
91}
92
94 if (Fragments.empty())
95 return *this;
96
97 Fragment &Last = Fragments.back();
98 if (Last.Kind == FragmentKind::Text && Last.Spelling.back() == ';')
99 Last.Spelling.pop_back();
100
101 return *this;
102}
103
106 switch (Kind) {
108 return "none";
110 return "keyword";
112 return "attribute";
114 return "number";
116 return "string";
118 return "identifier";
120 return "typeIdentifier";
122 return "genericParameter";
124 return "externalParam";
126 return "internalParam";
128 return "text";
129 }
130
131 llvm_unreachable("Unhandled FragmentKind");
132}
133
151
153 ExceptionSpecificationType ExceptionSpec) {
154 DeclarationFragments Fragments;
155 switch (ExceptionSpec) {
157 return Fragments;
159 return Fragments.append(" ", DeclarationFragments::FragmentKind::Text)
164 // FIXME: throw(int), get types of inner expression
165 return Fragments;
167 return Fragments.append(" ", DeclarationFragments::FragmentKind::Text)
170 // FIXME: throw(conditional-expression), get expression
171 break;
173 return Fragments.append(" ", DeclarationFragments::FragmentKind::Text)
179 return Fragments.append(" ", DeclarationFragments::FragmentKind::Text)
184 default:
185 return Fragments;
186 }
187
188 llvm_unreachable("Unhandled exception specification");
189}
190
193 DeclarationFragments Fragments;
194 if (Record->isStruct())
195 Fragments.append("struct", DeclarationFragments::FragmentKind::Keyword);
196 else if (Record->isUnion())
197 Fragments.append("union", DeclarationFragments::FragmentKind::Keyword);
198 else
199 Fragments.append("class", DeclarationFragments::FragmentKind::Keyword);
200
201 return Fragments;
202}
203
204// NNS stores C++ nested name specifiers, which are prefixes to qualified names.
205// Build declaration fragments for NNS recursively so that we have the USR for
206// every part in a qualified name, and also leaves the actual underlying type
207// cleaner for its own fragment.
208DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForNNS(
210 DeclarationFragments Fragments;
211 switch (NNS.getKind()) {
213 return Fragments;
214
216 auto [Namespace, Prefix] = NNS.getAsNamespaceAndPrefix();
217 Fragments.append(getFragmentsForNNS(Prefix, Context, After));
218 if (const auto *NS = dyn_cast<NamespaceDecl>(Namespace);
219 NS && NS->isAnonymousNamespace())
220 return Fragments;
222 index::generateUSRForDecl(Namespace, USR);
223 Fragments.append(Namespace->getName(),
225 Namespace);
226 break;
227 }
228
230 // The global specifier `::` at the beginning. No stored value.
231 break;
232
234 // Microsoft's `__super` specifier.
236 break;
237
239 // FIXME: Handle C++ template specialization type
240 Fragments.append(getFragmentsForType(NNS.getAsType(), Context, After));
241 break;
242 }
243 }
244
245 // Add the separator text `::` for this segment.
246 return Fragments.append("::", DeclarationFragments::FragmentKind::Text);
247}
248
249// Recursively build the declaration fragments for an underlying `Type` with
250// qualifiers removed.
251DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
252 const Type *T, ASTContext &Context, DeclarationFragments &After) {
253 assert(T && "invalid type");
254
255 DeclarationFragments Fragments;
256
257 if (const MacroQualifiedType *MQT = dyn_cast<MacroQualifiedType>(T)) {
258 Fragments.append(
259 getFragmentsForType(MQT->getUnderlyingType(), Context, After));
260 return Fragments;
261 }
262
263 if (const AttributedType *AT = dyn_cast<AttributedType>(T)) {
264 // FIXME: Serialize Attributes correctly
265 Fragments.append(
266 getFragmentsForType(AT->getModifiedType(), Context, After));
267 return Fragments;
268 }
269
270 // If the type is a typedefed type, get the underlying TypedefNameDecl for a
271 // direct reference to the typedef instead of the wrapped type.
272
273 // 'id' type is a typedef for an ObjCObjectPointerType
274 // we treat it as a typedef
275 if (const TypedefType *TypedefTy = dyn_cast<TypedefType>(T)) {
276 const TypedefNameDecl *Decl = TypedefTy->getDecl();
277 TypedefUnderlyingTypeResolver TypedefResolver(Context);
278 std::string USR = TypedefResolver.getUSRForType(QualType(T, 0));
279
280 if (ElaboratedTypeKeyword Keyword = TypedefTy->getKeyword();
282 Fragments
285 .appendSpace();
286 }
287
288 Fragments.append(
289 getFragmentsForNNS(TypedefTy->getQualifier(), Context, After));
290
291 if (TypedefTy->isObjCIdType()) {
292 return Fragments.append(Decl->getName(),
294 }
295
296 return Fragments.append(
298 USR, TypedefResolver.getUnderlyingTypeDecl(QualType(T, 0)));
299 }
300
301 // Declaration fragments of a pointer type is the declaration fragments of
302 // the pointee type followed by a `*`,
303 if (T->isPointerType() && !T->isFunctionPointerType()) {
304 QualType PointeeT = T->getPointeeType();
305 Fragments.append(getFragmentsForType(PointeeT, Context, After));
306 // If the pointee is itself a pointer, we do not want to insert a space
307 // before the `*` as the preceding character in the type name is a `*`.
308 if (!PointeeT->isAnyPointerType())
309 Fragments.appendSpace();
311 }
312
313 // For Objective-C `id` and `Class` pointers
314 // we do not spell out the `*`.
315 if (T->isObjCObjectPointerType() &&
316 !T->getAs<ObjCObjectPointerType>()->isObjCIdOrClassType()) {
317
318 Fragments.append(getFragmentsForType(T->getPointeeType(), Context, After));
319
320 // id<protocol> is an qualified id type
321 // id<protocol>* is not an qualified id type
322 if (!T->getAs<ObjCObjectPointerType>()->isObjCQualifiedIdType()) {
324 }
325
326 return Fragments;
327 }
328
329 // Declaration fragments of a lvalue reference type is the declaration
330 // fragments of the underlying type followed by a `&`.
331 if (const LValueReferenceType *LRT = dyn_cast<LValueReferenceType>(T))
332 return Fragments
333 .append(
334 getFragmentsForType(LRT->getPointeeTypeAsWritten(), Context, After))
336
337 // Declaration fragments of a rvalue reference type is the declaration
338 // fragments of the underlying type followed by a `&&`.
339 if (const RValueReferenceType *RRT = dyn_cast<RValueReferenceType>(T))
340 return Fragments
341 .append(
342 getFragmentsForType(RRT->getPointeeTypeAsWritten(), Context, After))
344
345 // Declaration fragments of an array-typed variable have two parts:
346 // 1. the element type of the array that appears before the variable name;
347 // 2. array brackets `[(0-9)?]` that appear after the variable name.
348 if (const ArrayType *AT = T->getAsArrayTypeUnsafe()) {
349 // Build the "after" part first because the inner element type might also
350 // be an array-type. For example `int matrix[3][4]` which has a type of
351 // "(array 3 of (array 4 of ints))."
352 // Push the array size part first to make sure they are in the right order.
354
355 switch (AT->getSizeModifier()) {
357 break;
360 break;
363 break;
364 }
365
366 if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) {
367 // FIXME: right now this would evaluate any expressions/macros written in
368 // the original source to concrete values. For example
369 // `int nums[MAX]` -> `int nums[100]`
370 // `char *str[5 + 1]` -> `char *str[6]`
371 SmallString<128> Size;
372 CAT->getSize().toStringUnsigned(Size);
374 }
375
377
378 return Fragments.append(
379 getFragmentsForType(AT->getElementType(), Context, After));
380 }
381
382 if (const TemplateSpecializationType *TemplSpecTy =
383 dyn_cast<TemplateSpecializationType>(T)) {
384 if (ElaboratedTypeKeyword Keyword = TemplSpecTy->getKeyword();
386 Fragments
389 .appendSpace();
390
391 auto TemplName = TemplSpecTy->getTemplateName();
392 std::string Str;
393 raw_string_ostream Stream(Str);
394 TemplName.print(Stream, Context.getPrintingPolicy(),
396 SmallString<64> USR("");
397 if (const auto *QTN = TemplName.getAsQualifiedTemplateName()) {
398 Fragments.append(getFragmentsForNNS(QTN->getQualifier(), Context, After));
399 TemplName = QTN->getUnderlyingTemplate();
400 }
401 if (const auto *TemplDecl = TemplName.getAsTemplateDecl())
402 index::generateUSRForDecl(TemplDecl, USR);
403 // FIXME: Handle other kinds of TemplateNames.
404
405 return Fragments
409 TemplSpecTy->template_arguments(), Context, std::nullopt))
411 }
412
413 // If the base type is a TagType (struct/interface/union/class/enum), let's
414 // get the underlying Decl for better names and USRs.
415 if (const TagType *TagTy = dyn_cast<TagType>(T)) {
416 if (ElaboratedTypeKeyword Keyword = TagTy->getKeyword();
418 Fragments
421 .appendSpace();
422
423 Fragments.append(getFragmentsForNNS(TagTy->getQualifier(), Context, After));
424
425 const TagDecl *Decl = TagTy->getDecl();
426 // Anonymous decl, skip this fragment.
427 if (Decl->getName().empty())
428 return Fragments.append("{ ... }",
430 SmallString<128> TagUSR;
432 return Fragments.append(Decl->getName(),
434 TagUSR, Decl);
435 }
436
437 // Everything we care about has been handled now, reduce to the canonical
438 // unqualified base type.
439 QualType Base = T->getCanonicalTypeUnqualified();
440
441 // If the base type is an ObjCInterfaceType, use the underlying
442 // ObjCInterfaceDecl for the true USR.
443 if (const auto *ObjCIT = dyn_cast<ObjCInterfaceType>(Base)) {
444 const auto *Decl = ObjCIT->getDecl();
445 SmallString<128> USR;
446 index::generateUSRForDecl(Decl, USR);
447 return Fragments.append(Decl->getName(),
449 USR, Decl);
450 }
451
452 // Default fragment builder for other kinds of types (BuiltinType etc.)
453 SmallString<128> USR;
454 clang::index::generateUSRForType(Base, Context, USR);
455 Fragments.append(Base.getAsString(),
457
458 return Fragments;
459}
460
462DeclarationFragmentsBuilder::getFragmentsForQualifiers(const Qualifiers Quals) {
463 DeclarationFragments Fragments;
464 if (Quals.hasConst())
466 if (Quals.hasVolatile())
468 if (Quals.hasRestrict())
470
471 return Fragments;
472}
473
474DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
475 const QualType QT, ASTContext &Context, DeclarationFragments &After) {
476 assert(!QT.isNull() && "invalid type");
477
478 if (const ParenType *PT = dyn_cast<ParenType>(QT)) {
480 return getFragmentsForType(PT->getInnerType(), Context, After)
482 }
483
484 const SplitQualType SQT = QT.split();
485 DeclarationFragments QualsFragments = getFragmentsForQualifiers(SQT.Quals),
486 TypeFragments =
487 getFragmentsForType(SQT.Ty, Context, After);
488 if (QT.getAsString() == "_Bool")
489 TypeFragments.replace("bool", 0);
490
491 if (QualsFragments.getFragments().empty())
492 return TypeFragments;
493
494 // Use east qualifier for pointer types
495 // For example:
496 // ```
497 // int * const
498 // ^---- ^----
499 // type qualifier
500 // ^-----------------
501 // const pointer to int
502 // ```
503 // should not be reconstructed as
504 // ```
505 // const int *
506 // ^---- ^--
507 // qualifier type
508 // ^---------------- ^
509 // pointer to const int
510 // ```
511 if (SQT.Ty->isAnyPointerType())
512 return TypeFragments.appendSpace().append(std::move(QualsFragments));
513
514 return QualsFragments.appendSpace().append(std::move(TypeFragments));
515}
516
518 const NamespaceDecl *Decl) {
519 DeclarationFragments Fragments;
521 if (!Decl->isAnonymousNamespace())
522 Fragments.appendSpace().append(
524 return Fragments.appendSemicolon();
525}
526
529 DeclarationFragments Fragments;
530 if (Var->isConstexpr())
532 .appendSpace();
533
534 StorageClass SC = Var->getStorageClass();
535 if (SC != SC_None)
536 Fragments
539 .appendSpace();
540
541 // Capture potential fragments that needs to be placed after the variable name
542 // ```
543 // int nums[5];
544 // char (*ptr_to_array)[6];
545 // ```
547 FunctionTypeLoc BlockLoc;
548 FunctionProtoTypeLoc BlockProtoLoc;
549 findTypeLocForBlockDecl(Var->getTypeSourceInfo(), BlockLoc, BlockProtoLoc);
550
551 if (!BlockLoc) {
553 ? Var->getTypeSourceInfo()->getType()
555 Var->getType());
556
557 Fragments.append(getFragmentsForType(T, Var->getASTContext(), After))
558 .appendSpace();
559 } else {
560 Fragments.append(getFragmentsForBlock(Var, BlockLoc, BlockProtoLoc, After));
561 }
562
563 return Fragments
565 .append(std::move(After))
567}
568
571 DeclarationFragments Fragments;
572 if (Var->isConstexpr())
574 .appendSpace();
575 QualType T =
576 Var->getTypeSourceInfo()
577 ? Var->getTypeSourceInfo()->getType()
579
580 // Might be a member, so might be static.
581 if (Var->isStaticDataMember())
583 .appendSpace();
584
586 DeclarationFragments ArgumentFragment =
587 getFragmentsForType(T, Var->getASTContext(), After);
588 if (StringRef(ArgumentFragment.begin()->Spelling)
589 .starts_with("type-parameter")) {
590 std::string ProperArgName = T.getAsString();
591 ArgumentFragment.begin()->Spelling.swap(ProperArgName);
592 }
593 Fragments.append(std::move(ArgumentFragment))
594 .appendSpace()
597 return Fragments;
598}
599
601DeclarationFragmentsBuilder::getFragmentsForParam(const ParmVarDecl *Param) {
602 DeclarationFragments Fragments, After;
603
604 auto *TSInfo = Param->getTypeSourceInfo();
605
606 QualType T = TSInfo ? TSInfo->getType()
607 : Param->getASTContext().getUnqualifiedObjCPointerType(
608 Param->getType());
609
610 FunctionTypeLoc BlockLoc;
611 FunctionProtoTypeLoc BlockProtoLoc;
612 findTypeLocForBlockDecl(TSInfo, BlockLoc, BlockProtoLoc);
613
614 DeclarationFragments TypeFragments;
615 if (BlockLoc)
616 TypeFragments.append(
617 getFragmentsForBlock(Param, BlockLoc, BlockProtoLoc, After));
618 else
619 TypeFragments.append(getFragmentsForType(T, Param->getASTContext(), After));
620
621 if (StringRef(TypeFragments.begin()->Spelling)
622 .starts_with("type-parameter")) {
623 std::string ProperArgName = Param->getOriginalType().getAsString();
624 TypeFragments.begin()->Spelling.swap(ProperArgName);
625 }
626
627 if (Param->isObjCMethodParameter()) {
629 .append(std::move(TypeFragments))
630 .append(std::move(After))
632 .append(Param->getName(),
634 } else {
635 Fragments.append(std::move(TypeFragments));
636 // If the type is a type alias, append the space
637 // even if the underlying type is a pointer type.
638 if (T->isTypedefNameType() ||
639 (!T->isAnyPointerType() && !T->isBlockPointerType()))
640 Fragments.appendSpace();
641 Fragments
642 .append(Param->getName(),
644 .append(std::move(After));
645 }
646 return Fragments;
647}
648
649DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForBlock(
650 const NamedDecl *BlockDecl, FunctionTypeLoc &Block,
651 FunctionProtoTypeLoc &BlockProto, DeclarationFragments &After) {
652 DeclarationFragments Fragments;
653
654 DeclarationFragments RetTyAfter;
655 auto ReturnValueFragment = getFragmentsForType(
656 Block.getTypePtr()->getReturnType(), BlockDecl->getASTContext(), After);
657
658 Fragments.append(std::move(ReturnValueFragment))
659 .append(std::move(RetTyAfter))
660 .appendSpace()
662
664 unsigned NumParams = Block.getNumParams();
665
666 if (!BlockProto || NumParams == 0) {
667 if (BlockProto && BlockProto.getTypePtr()->isVariadic())
669 else
671 } else {
673 for (unsigned I = 0; I != NumParams; ++I) {
674 if (I)
676 After.append(getFragmentsForParam(Block.getParam(I)));
677 if (I == NumParams - 1 && BlockProto.getTypePtr()->isVariadic())
679 }
681 }
682
683 return Fragments;
684}
685
688 DeclarationFragments Fragments;
689 switch (Func->getStorageClass()) {
690 case SC_None:
691 case SC_PrivateExtern:
692 break;
693 case SC_Extern:
695 .appendSpace();
696 break;
697 case SC_Static:
699 .appendSpace();
700 break;
701 case SC_Auto:
702 case SC_Register:
703 llvm_unreachable("invalid for functions");
704 }
705 if (Func->isConsteval()) // if consteval, it is also constexpr
707 .appendSpace();
708 else if (Func->isConstexpr())
710 .appendSpace();
711
712 // FIXME: Is `after` actually needed here?
714 QualType ReturnType = Func->getReturnType();
715 auto ReturnValueFragment =
716 getFragmentsForType(ReturnType, Func->getASTContext(), After);
717 if (StringRef(ReturnValueFragment.begin()->Spelling)
718 .starts_with("type-parameter")) {
719 std::string ProperArgName = ReturnType.getAsString();
720 ReturnValueFragment.begin()->Spelling.swap(ProperArgName);
721 }
722
723 Fragments.append(std::move(ReturnValueFragment));
724 if (!ReturnType->isAnyPointerType())
725 Fragments.appendSpace();
726 Fragments.append(Func->getNameAsString(),
728
729 if (Func->getTemplateSpecializationInfo()) {
731
732 for (unsigned i = 0, end = Func->getNumParams(); i != end; ++i) {
733 if (i)
735 Fragments.append(
736 getFragmentsForType(Func->getParamDecl(i)->getType(),
737 Func->getParamDecl(i)->getASTContext(), After));
738 }
740 }
741 Fragments.append(std::move(After));
742
744 unsigned NumParams = Func->getNumParams();
745 for (unsigned i = 0; i != NumParams; ++i) {
746 if (i)
748 Fragments.append(getFragmentsForParam(Func->getParamDecl(i)));
749 }
750
751 if (Func->isVariadic()) {
752 if (NumParams > 0)
755 }
757
759 Func->getExceptionSpecType()));
760
761 return Fragments.appendSemicolon();
762}
763
770
775
776 DeclarationFragments Fragments, After;
778
779 if (!EnumDecl->getName().empty())
780 Fragments.appendSpace().append(
782
783 QualType IntegerType = EnumDecl->getIntegerType();
784 if (!IntegerType.isNull())
785 Fragments.appendSpace()
787 .append(
788 getFragmentsForType(IntegerType, EnumDecl->getASTContext(), After))
789 .append(std::move(After));
790
791 if (EnumDecl->getName().empty())
792 Fragments.appendSpace().append("{ ... }",
794
795 return Fragments.appendSemicolon();
796}
797
801 DeclarationFragments Fragments;
802 if (Field->isMutable())
804 .appendSpace();
805 return Fragments
806 .append(
807 getFragmentsForType(Field->getType(), Field->getASTContext(), After))
808 .appendSpace()
810 .append(std::move(After))
812}
813
815 const RecordDecl *Record) {
816 if (const auto *TypedefNameDecl = Record->getTypedefNameForAnonDecl())
818
819 DeclarationFragments Fragments;
820 if (Record->isUnion())
822 else
824
825 Fragments.appendSpace();
826 if (!Record->getName().empty())
827 Fragments.append(Record->getName(),
829 else
831
832 return Fragments.appendSemicolon();
833}
834
836 const CXXRecordDecl *Record) {
837 if (const auto *TypedefNameDecl = Record->getTypedefNameForAnonDecl())
839
840 DeclarationFragments Fragments;
842
843 if (!Record->getName().empty())
844 Fragments.appendSpace().append(
846
847 return Fragments.appendSemicolon();
848}
849
852 const CXXMethodDecl *Method) {
853 DeclarationFragments Fragments;
854 std::string Name;
855 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(Method)) {
856 Name = Method->getNameAsString();
857 if (Constructor->isExplicit())
859 .appendSpace();
860 } else if (isa<CXXDestructorDecl>(Method))
861 Name = Method->getNameAsString();
862
865 .append(std::move(After));
867 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
868 if (i)
870 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
871 }
873
875 Method->getExceptionSpecType()));
876
877 return Fragments.appendSemicolon();
878}
879
881 const CXXMethodDecl *Method) {
882 DeclarationFragments Fragments;
883 StringRef Name = Method->getName();
884 if (Method->isStatic())
886 .appendSpace();
887 if (Method->isConstexpr())
889 .appendSpace();
890 if (Method->isVolatile())
892 .appendSpace();
893 if (Method->isVirtual())
895 .appendSpace();
896
897 // Build return type
899 Fragments
900 .append(getFragmentsForType(Method->getReturnType(),
901 Method->getASTContext(), After))
902 .appendSpace()
904 .append(std::move(After));
906 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
907 if (i)
909 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
910 }
912
913 if (Method->isConst())
914 Fragments.appendSpace().append("const",
916
918 Method->getExceptionSpecType()));
919
920 return Fragments.appendSemicolon();
921}
922
925 const CXXConversionDecl *ConversionFunction) {
926 DeclarationFragments Fragments;
927
928 if (ConversionFunction->isExplicit())
930 .appendSpace();
931
933 .appendSpace();
934
935 Fragments
936 .append(ConversionFunction->getConversionType().getAsString(),
939 for (unsigned i = 0, end = ConversionFunction->getNumParams(); i != end;
940 ++i) {
941 if (i)
943 Fragments.append(getFragmentsForParam(ConversionFunction->getParamDecl(i)));
944 }
946
947 if (ConversionFunction->isConst())
948 Fragments.appendSpace().append("const",
950
951 return Fragments.appendSemicolon();
952}
953
956 const CXXMethodDecl *Method) {
957 DeclarationFragments Fragments;
958
959 // Build return type
961 Fragments
962 .append(getFragmentsForType(Method->getReturnType(),
963 Method->getASTContext(), After))
964 .appendSpace()
965 .append(Method->getNameAsString(),
967 .append(std::move(After));
969 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
970 if (i)
972 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
973 }
975
976 if (Method->isConst())
977 Fragments.appendSpace().append("const",
979
981 Method->getExceptionSpecType()));
982
983 return Fragments.appendSemicolon();
984}
985
986// Get fragments for template parameters, e.g. T in tempalte<typename T> ...
989 ArrayRef<NamedDecl *> ParameterArray) {
990 DeclarationFragments Fragments;
991 for (unsigned i = 0, end = ParameterArray.size(); i != end; ++i) {
992 if (i)
994 .appendSpace();
995
996 if (const auto *TemplateParam =
997 dyn_cast<TemplateTypeParmDecl>(ParameterArray[i])) {
998 if (TemplateParam->hasTypeConstraint())
999 Fragments.append(TemplateParam->getTypeConstraint()
1000 ->getNamedConcept()
1001 ->getName()
1002 .str(),
1004 else if (TemplateParam->wasDeclaredWithTypename())
1005 Fragments.append("typename",
1007 else
1009
1010 if (TemplateParam->isParameterPack())
1012
1013 if (!TemplateParam->getName().empty())
1014 Fragments.appendSpace().append(
1015 TemplateParam->getName(),
1017
1018 if (TemplateParam->hasDefaultArgument()) {
1019 const auto Default = TemplateParam->getDefaultArgument();
1022 {Default.getArgument()}, TemplateParam->getASTContext(),
1023 {Default}));
1024 }
1025 } else if (const auto *NTP =
1026 dyn_cast<NonTypeTemplateParmDecl>(ParameterArray[i])) {
1028 const auto TyFragments =
1029 getFragmentsForType(NTP->getType(), NTP->getASTContext(), After);
1030 Fragments.append(std::move(TyFragments)).append(std::move(After));
1031
1032 if (NTP->isParameterPack())
1034
1035 if (!NTP->getName().empty())
1036 Fragments.appendSpace().append(
1037 NTP->getName(),
1039
1040 if (NTP->hasDefaultArgument()) {
1041 SmallString<8> ExprStr;
1042 raw_svector_ostream Output(ExprStr);
1043 NTP->getDefaultArgument().getArgument().print(
1044 NTP->getASTContext().getPrintingPolicy(), Output,
1045 /*IncludeType=*/false);
1048 }
1049 } else if (const auto *TTP =
1050 dyn_cast<TemplateTemplateParmDecl>(ParameterArray[i])) {
1052 .appendSpace()
1055 TTP->getTemplateParameters()->asArray()))
1057 .appendSpace()
1058 .append(TTP->wasDeclaredWithTypename() ? "typename" : "class",
1060
1061 if (TTP->isParameterPack())
1063
1064 if (!TTP->getName().empty())
1065 Fragments.appendSpace().append(
1066 TTP->getName(),
1068 if (TTP->hasDefaultArgument()) {
1069 const auto Default = TTP->getDefaultArgument();
1072 {Default.getArgument()}, TTP->getASTContext(), {Default}));
1073 }
1074 }
1075 }
1076 return Fragments;
1077}
1078
1079// Get fragments for template arguments, e.g. int in template<typename T>
1080// Foo<int>;
1081//
1082// Note: TemplateParameters is only necessary if the Decl is a
1083// PartialSpecialization, where we need the parameters to deduce the name of the
1084// generic arguments.
1087 const ArrayRef<TemplateArgument> TemplateArguments, ASTContext &Context,
1088 const std::optional<ArrayRef<TemplateArgumentLoc>> TemplateArgumentLocs) {
1089 DeclarationFragments Fragments;
1090 for (unsigned i = 0, end = TemplateArguments.size(); i != end; ++i) {
1091 if (i)
1093 .appendSpace();
1094
1095 const auto &CTA = TemplateArguments[i];
1096 switch (CTA.getKind()) {
1099 DeclarationFragments ArgumentFragment =
1100 getFragmentsForType(CTA.getAsType(), Context, After);
1101
1102 if (StringRef(ArgumentFragment.begin()->Spelling)
1103 .starts_with("type-parameter")) {
1104 if (TemplateArgumentLocs.has_value() &&
1105 TemplateArgumentLocs->size() > i) {
1106 std::string ProperArgName = TemplateArgumentLocs.value()[i]
1107 .getTypeSourceInfo()
1108 ->getType()
1109 .getAsString();
1110 ArgumentFragment.begin()->Spelling.swap(ProperArgName);
1111 } else {
1112 auto &Spelling = ArgumentFragment.begin()->Spelling;
1113 Spelling.clear();
1114 raw_string_ostream OutStream(Spelling);
1115 CTA.print(Context.getPrintingPolicy(), OutStream, false);
1116 }
1117 }
1118
1119 Fragments.append(std::move(ArgumentFragment));
1120 break;
1121 }
1123 const auto *VD = CTA.getAsDecl();
1124 SmallString<128> USR;
1126 Fragments.append(VD->getNameAsString(),
1128 break;
1129 }
1132 break;
1133
1135 SmallString<4> Str;
1136 CTA.getAsIntegral().toString(Str);
1138 break;
1139 }
1140
1142 const auto SVTy = CTA.getStructuralValueType();
1143 Fragments.append(CTA.getAsStructuralValue().getAsString(Context, SVTy),
1145 break;
1146 }
1147
1150 std::string Str;
1151 raw_string_ostream Stream(Str);
1152 CTA.getAsTemplate().print(Stream, Context.getPrintingPolicy());
1153 SmallString<64> USR("");
1154 if (const auto *TemplDecl =
1155 CTA.getAsTemplateOrTemplatePattern().getAsTemplateDecl())
1156 index::generateUSRForDecl(TemplDecl, USR);
1158 USR);
1159 if (CTA.getKind() == TemplateArgument::TemplateExpansion)
1161 break;
1162 }
1163
1166 .append(getFragmentsForTemplateArguments(CTA.pack_elements(), Context,
1167 {}))
1169 break;
1170
1172 SmallString<8> ExprStr;
1173 raw_svector_ostream Output(ExprStr);
1174 CTA.getAsExpr()->printPretty(Output, nullptr,
1175 Context.getPrintingPolicy());
1177 break;
1178 }
1179
1181 break;
1182 }
1183 }
1184 return Fragments;
1185}
1186
1204
1207 const RedeclarableTemplateDecl *RedeclarableTemplate) {
1208 DeclarationFragments Fragments;
1210 .appendSpace()
1213 RedeclarableTemplate->getTemplateParameters()->asArray()))
1215 .appendSpace();
1216
1217 if (isa<TypeAliasTemplateDecl>(RedeclarableTemplate))
1218 Fragments.appendSpace()
1220 .appendSpace()
1221 .append(RedeclarableTemplate->getName(),
1223 // the templated records will be resposbible for injecting their templates
1224 return Fragments.appendSpace();
1225}
1226
1230 DeclarationFragments Fragments;
1231 std::optional<ArrayRef<TemplateArgumentLoc>> TemplateArgumentLocs = {};
1232 if (auto *TemplateArgs = Decl->getTemplateArgsAsWritten()) {
1233 TemplateArgumentLocs = TemplateArgs->arguments();
1234 }
1235 return Fragments
1237 .appendSpace()
1240 .appendSpace()
1243 .pop_back() // there is an extra semicolon now
1246 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1247 TemplateArgumentLocs))
1249 .appendSemicolon();
1250}
1251
1274
1294
1298 DeclarationFragments Fragments;
1299 return Fragments
1301 .appendSpace()
1303 // Partial specs may have new params.
1305 Decl->getTemplateParameters()->asArray()))
1307 .appendSpace()
1309 .pop_back() // there is an extra semicolon now
1312 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1313 Decl->getTemplateArgsAsWritten()->arguments()))
1315 .appendSemicolon();
1316}
1317
1334
1346
1349 const MacroInfo *MI) {
1350 DeclarationFragments Fragments;
1352 .appendSpace();
1354
1355 if (MI->isFunctionLike()) {
1357 unsigned numParameters = MI->getNumParams();
1358 if (MI->isC99Varargs())
1359 --numParameters;
1360 for (unsigned i = 0; i < numParameters; ++i) {
1361 if (i)
1363 Fragments.append(MI->params()[i]->getName(),
1365 }
1366 if (MI->isVariadic()) {
1367 if (numParameters && MI->isC99Varargs())
1370 }
1372 }
1373 return Fragments;
1374}
1375
1377 const ObjCCategoryDecl *Category) {
1378 DeclarationFragments Fragments;
1379
1380 auto *Interface = Category->getClassInterface();
1381 SmallString<128> InterfaceUSR;
1382 index::generateUSRForDecl(Interface, InterfaceUSR);
1383
1385 .appendSpace()
1386 .append(Interface->getName(),
1388 Interface)
1390 .append(Category->getName(),
1393
1394 return Fragments;
1395}
1396
1399 DeclarationFragments Fragments;
1400 // Build the base of the Objective-C interface declaration.
1402 .appendSpace()
1403 .append(Interface->getName(),
1405
1406 // Build the inheritance part of the declaration.
1407 if (const ObjCInterfaceDecl *SuperClass = Interface->getSuperClass()) {
1408 SmallString<128> SuperUSR;
1409 index::generateUSRForDecl(SuperClass, SuperUSR);
1411 .append(SuperClass->getName(),
1413 SuperClass);
1414 }
1415
1416 return Fragments;
1417}
1418
1420 const ObjCMethodDecl *Method) {
1421 DeclarationFragments Fragments, After;
1422 // Build the instance/class method indicator.
1423 if (Method->isClassMethod())
1425 else if (Method->isInstanceMethod())
1427
1428 // Build the return type.
1430 .append(getFragmentsForType(Method->getReturnType(),
1431 Method->getASTContext(), After))
1432 .append(std::move(After))
1434
1435 // Build the selector part.
1436 Selector Selector = Method->getSelector();
1437 if (Selector.getNumArgs() == 0)
1438 // For Objective-C methods that don't take arguments, the first (and only)
1439 // slot of the selector is the method name.
1440 Fragments.appendSpace().append(
1443
1444 // For Objective-C methods that take arguments, build the selector slots.
1445 for (unsigned i = 0, end = Method->param_size(); i != end; ++i) {
1446 // Objective-C method selector parts are considered as identifiers instead
1447 // of "external parameters" as in Swift. This is because Objective-C method
1448 // symbols are referenced with the entire selector, instead of just the
1449 // method name in Swift.
1451 ParamID.append(":");
1452 Fragments.appendSpace().append(
1454
1455 // Build the internal parameter.
1456 const ParmVarDecl *Param = Method->getParamDecl(i);
1457 Fragments.append(getFragmentsForParam(Param));
1458 }
1459
1460 return Fragments.appendSemicolon();
1461}
1462
1464 const ObjCPropertyDecl *Property) {
1465 DeclarationFragments Fragments, After;
1466
1467 // Build the Objective-C property keyword.
1469
1470 const auto Attributes = Property->getPropertyAttributesAsWritten();
1471 // Build the attributes if there is any associated with the property.
1472 if (Attributes != ObjCPropertyAttribute::kind_noattr) {
1473 // No leading comma for the first attribute.
1474 bool First = true;
1476 // Helper function to render the attribute.
1477 auto RenderAttribute =
1478 [&](ObjCPropertyAttribute::Kind Kind, StringRef Spelling,
1479 StringRef Arg = "",
1482 // Check if the `Kind` attribute is set for this property.
1483 if ((Attributes & Kind) && !Spelling.empty()) {
1484 // Add a leading comma if this is not the first attribute rendered.
1485 if (!First)
1487 // Render the spelling of this attribute `Kind` as a keyword.
1488 Fragments.append(Spelling,
1490 // If this attribute takes in arguments (e.g. `getter=getterName`),
1491 // render the arguments.
1492 if (!Arg.empty())
1494 .append(Arg, ArgKind);
1495 First = false;
1496 }
1497 };
1498
1499 // Go through all possible Objective-C property attributes and render set
1500 // ones.
1501 RenderAttribute(ObjCPropertyAttribute::kind_class, "class");
1502 RenderAttribute(ObjCPropertyAttribute::kind_direct, "direct");
1503 RenderAttribute(ObjCPropertyAttribute::kind_nonatomic, "nonatomic");
1504 RenderAttribute(ObjCPropertyAttribute::kind_atomic, "atomic");
1505 RenderAttribute(ObjCPropertyAttribute::kind_assign, "assign");
1506 RenderAttribute(ObjCPropertyAttribute::kind_retain, "retain");
1507 RenderAttribute(ObjCPropertyAttribute::kind_strong, "strong");
1508 RenderAttribute(ObjCPropertyAttribute::kind_copy, "copy");
1509 RenderAttribute(ObjCPropertyAttribute::kind_weak, "weak");
1511 "unsafe_unretained");
1512 RenderAttribute(ObjCPropertyAttribute::kind_readwrite, "readwrite");
1513 RenderAttribute(ObjCPropertyAttribute::kind_readonly, "readonly");
1514 RenderAttribute(ObjCPropertyAttribute::kind_getter, "getter",
1515 Property->getGetterName().getAsString());
1516 RenderAttribute(ObjCPropertyAttribute::kind_setter, "setter",
1517 Property->getSetterName().getAsString());
1518
1519 // Render nullability attributes.
1520 if (Attributes & ObjCPropertyAttribute::kind_nullability) {
1521 QualType Type = Property->getType();
1522 if (const auto Nullability =
1523 AttributedType::stripOuterNullability(Type)) {
1524 if (!First)
1526 if (*Nullability == NullabilityKind::Unspecified &&
1528 Fragments.append("null_resettable",
1530 else
1531 Fragments.append(
1532 getNullabilitySpelling(*Nullability, /*isContextSensitive=*/true),
1534 First = false;
1535 }
1536 }
1537
1539 }
1540
1541 Fragments.appendSpace();
1542
1543 FunctionTypeLoc BlockLoc;
1544 FunctionProtoTypeLoc BlockProtoLoc;
1545 findTypeLocForBlockDecl(Property->getTypeSourceInfo(), BlockLoc,
1546 BlockProtoLoc);
1547
1548 auto PropType = Property->getType();
1549 if (!BlockLoc)
1550 Fragments
1551 .append(getFragmentsForType(PropType, Property->getASTContext(), After))
1552 .appendSpace();
1553 else
1554 Fragments.append(
1555 getFragmentsForBlock(Property, BlockLoc, BlockProtoLoc, After));
1556
1557 return Fragments
1558 .append(Property->getName(),
1560 .append(std::move(After))
1561 .appendSemicolon();
1562}
1563
1565 const ObjCProtocolDecl *Protocol) {
1566 DeclarationFragments Fragments;
1567 // Build basic protocol declaration.
1569 .appendSpace()
1570 .append(Protocol->getName(),
1572
1573 // If this protocol conforms to other protocols, build the conformance list.
1574 if (!Protocol->protocols().empty()) {
1576 for (ObjCProtocolDecl::protocol_iterator It = Protocol->protocol_begin();
1577 It != Protocol->protocol_end(); It++) {
1578 // Add a leading comma if this is not the first protocol rendered.
1579 if (It != Protocol->protocol_begin())
1581
1582 SmallString<128> USR;
1583 index::generateUSRForDecl(*It, USR);
1584 Fragments.append((*It)->getName(),
1586 *It);
1587 }
1589 }
1590
1591 return Fragments;
1592}
1593
1595 const TypedefNameDecl *Decl) {
1596 DeclarationFragments Fragments, After;
1598 .appendSpace()
1599 .append(getFragmentsForType(Decl->getUnderlyingType(),
1600 Decl->getASTContext(), After))
1601 .append(std::move(After))
1602 .appendSpace()
1604
1605 return Fragments.appendSemicolon();
1606}
1607
1608// Instantiate template for FunctionDecl.
1609template FunctionSignature
1611
1612// Instantiate template for ObjCMethodDecl.
1613template FunctionSignature
1615
1616// Subheading of a symbol defaults to its name.
1619 DeclarationFragments Fragments;
1621 Fragments.append(cast<CXXRecordDecl>(Decl->getDeclContext())->getName(),
1623 } else if (isa<CXXDestructorDecl>(Decl)) {
1624 Fragments.append(cast<CXXDestructorDecl>(Decl)->getNameAsString(),
1626 } else if (isa<CXXConversionDecl>(Decl)) {
1627 Fragments.append(
1628 cast<CXXConversionDecl>(Decl)->getConversionType().getAsString(),
1630 } else if (isa<CXXMethodDecl>(Decl) &&
1631 cast<CXXMethodDecl>(Decl)->isOverloadedOperator()) {
1632 Fragments.append(Decl->getNameAsString(),
1634 } else if (isa<TagDecl>(Decl) &&
1635 cast<TagDecl>(Decl)->getTypedefNameForAnonDecl()) {
1636 return getSubHeading(cast<TagDecl>(Decl)->getTypedefNameForAnonDecl());
1637 } else if (Decl->getIdentifier()) {
1638 Fragments.append(Decl->getName(),
1640 } else {
1641 Fragments.append(Decl->getDeclName().getAsString(),
1643 }
1644
1645 return Fragments;
1646}
1647
1648// Subheading of an Objective-C method is a `+` or `-` sign indicating whether
1649// it's a class method or an instance method, followed by the selector name.
1652 DeclarationFragments Fragments;
1653 if (Method->isClassMethod())
1655 else if (Method->isInstanceMethod())
1657
1658 return Fragments.append(Method->getNameAsString(),
1660}
1661
1662// Subheading of a symbol defaults to its name.
1665 DeclarationFragments Fragments;
1667 return Fragments;
1668}
Forward declaration of all AST node types.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines the Declaration Fragments related classes.
llvm::MachO::Record Record
Definition MachO.h:31
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
This file defines the UnderlyingTypeResolver which is a helper type for resolving the undelrying type...
const clang::PrintingPolicy & getPrintingPolicy() const
Definition ASTContext.h:844
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:220
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
Type source information for an attributed type.
Definition TypeLoc.h:1008
Wrapper for source info for block pointers.
Definition TypeLoc.h:1497
Represents a C++ conversion function within a class.
Definition DeclCXX.h:2939
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2129
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents a class template specialization, which refers to a class template with a given set of temp...
Declaration of a C++20 concept.
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:546
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition DeclBase.cpp:273
DeclContext * getDeclContext()
Definition DeclBase.h:448
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:809
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3423
Represents an enum.
Definition Decl.h:4007
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4180
Represents a member of a struct/union/class.
Definition Decl.h:3160
Represents a function declaration or definition.
Definition Decl.h:2000
bool isVariadic() const
Whether this function prototype is variadic.
Definition TypeBase.h:5658
Declaration of a template function.
Wrapper for source info for functions.
Definition TypeLoc.h:1615
const TypeClass * getTypePtr() const
Definition TypeLoc.h:526
Encapsulates the data about a macro definition (e.g.
Definition MacroInfo.h:39
bool isC99Varargs() const
Definition MacroInfo.h:207
bool isFunctionLike() const
Definition MacroInfo.h:201
ArrayRef< const IdentifierInfo * > params() const
Definition MacroInfo.h:185
unsigned getNumParams() const
Definition MacroInfo.h:184
bool isVariadic() const
Definition MacroInfo.h:209
This represents a decl that may have a name.
Definition Decl.h:274
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
Represent a C++ namespace.
Definition Decl.h:592
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
NamespaceAndPrefix getAsNamespaceAndPrefix() const
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
ObjCCategoryDecl - Represents a category declaration.
Definition DeclObjC.h:2329
Represents an ObjC class declaration.
Definition DeclObjC.h:1154
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
Represents one property declaration in an Objective-C interface.
Definition DeclObjC.h:731
Represents an Objective-C protocol declaration.
Definition DeclObjC.h:2084
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:2158
Represents a parameter to a function.
Definition Decl.h:1790
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1004
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition TypeBase.h:8299
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition TypeBase.h:1332
Wrapper of type source information for a type with non-trivial direct qualifiers.
Definition TypeLoc.h:300
bool hasConst() const
Definition TypeBase.h:457
bool hasRestrict() const
Definition TypeBase.h:477
bool hasVolatile() const
Definition TypeBase.h:467
Represents a struct/union/class.
Definition Decl.h:4321
Declaration of a redeclarable template.
Smart pointer class that efficiently represents Objective-C method names.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
unsigned getNumArgs() const
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:3948
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
ArrayRef< NamedDecl * > asArray()
Base wrapper for a particular "section" of type source info.
Definition TypeLoc.h:59
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
Definition TypeLoc.h:349
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition TypeLoc.h:89
TypeLoc IgnoreParens() const
Definition TypeLoc.h:1408
A container of type source information.
Definition TypeBase.h:8249
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition TypeLoc.h:267
QualType getType() const
Return the type wrapped by this type source info.
Definition TypeBase.h:8260
The base class of the type hierarchy.
Definition TypeBase.h:1833
bool isFunctionPointerType() const
Definition TypeBase.h:8582
bool isPointerType() const
Definition TypeBase.h:8515
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:752
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition TypeBase.h:9144
bool isObjCObjectPointerType() const
Definition TypeBase.h:8684
bool isAnyPointerType() const
Definition TypeBase.h:8523
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9091
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3562
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:926
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1569
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
Definition Decl.cpp:2128
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition Decl.h:1283
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1168
Represents a variable template specialization, which refers to a variable template with a given set o...
static DeclarationFragments getFragmentsForRedeclarableTemplate(const RedeclarableTemplateDecl *)
static DeclarationFragments getFragmentsForCXXClass(const CXXRecordDecl *)
static DeclarationFragments getFragmentsForEnumConstant(const EnumConstantDecl *)
Build DeclarationFragments for an enum constant declaration EnumConstantDecl.
static DeclarationFragments getFragmentsForObjCCategory(const ObjCCategoryDecl *)
Build DeclarationFragments for an Objective-C category declaration ObjCCategoryDecl.
static DeclarationFragments getFragmentsForMacro(StringRef Name, const MacroInfo *MI)
Build DeclarationFragments for a macro.
static DeclarationFragments getFragmentsForTypedef(const TypedefNameDecl *Decl)
Build DeclarationFragments for a typedef TypedefNameDecl.
static DeclarationFragments getFragmentsForEnum(const EnumDecl *)
Build DeclarationFragments for an enum declaration EnumDecl.
static DeclarationFragments getFragmentsForConversionFunction(const CXXConversionDecl *)
static DeclarationFragments getFragmentsForClassTemplateSpecialization(const ClassTemplateSpecializationDecl *)
static DeclarationFragments getFragmentsForTemplateParameters(ArrayRef< NamedDecl * >)
static DeclarationFragments getFragmentsForObjCProtocol(const ObjCProtocolDecl *)
Build DeclarationFragments for an Objective-C protocol declaration ObjCProtocolDecl.
static DeclarationFragments getFragmentsForConcept(const ConceptDecl *)
static DeclarationFragments getFragmentsForField(const FieldDecl *)
Build DeclarationFragments for a field declaration FieldDecl.
static DeclarationFragments getFragmentsForVar(const VarDecl *)
Build DeclarationFragments for a variable declaration VarDecl.
static DeclarationFragments getFragmentsForTemplateArguments(const ArrayRef< TemplateArgument >, ASTContext &, const std::optional< ArrayRef< TemplateArgumentLoc > >)
static DeclarationFragments getFragmentsForClassTemplatePartialSpecialization(const ClassTemplatePartialSpecializationDecl *)
static DeclarationFragments getFragmentsForObjCMethod(const ObjCMethodDecl *)
Build DeclarationFragments for an Objective-C method declaration ObjCMethodDecl.
static DeclarationFragments getSubHeadingForMacro(StringRef Name)
Build a sub-heading for macro Name.
static DeclarationFragments getFragmentsForFunction(const FunctionDecl *)
Build DeclarationFragments for a function declaration FunctionDecl.
static DeclarationFragments getFragmentsForObjCProperty(const ObjCPropertyDecl *)
Build DeclarationFragments for an Objective-C property declaration ObjCPropertyDecl.
static DeclarationFragments getFragmentsForSpecialCXXMethod(const CXXMethodDecl *)
static DeclarationFragments getFragmentsForCXXMethod(const CXXMethodDecl *)
static DeclarationFragments getFragmentsForNamespace(const NamespaceDecl *Decl)
static DeclarationFragments getFragmentsForVarTemplatePartialSpecialization(const VarTemplatePartialSpecializationDecl *)
static DeclarationFragments getFragmentsForFunctionTemplate(const FunctionTemplateDecl *Decl)
static DeclarationFragments getFragmentsForVarTemplateSpecialization(const VarTemplateSpecializationDecl *)
static FunctionSignature getFunctionSignature(const FunctionT *Function)
Build FunctionSignature for a function-like declaration FunctionT like FunctionDecl,...
static DeclarationFragments getSubHeading(const NamedDecl *)
Build sub-heading fragments for a NamedDecl.
static DeclarationFragments getFragmentsForVarTemplate(const VarDecl *)
static DeclarationFragments getFragmentsForOverloadedOperator(const CXXMethodDecl *)
static DeclarationFragments getFragmentsForFunctionTemplateSpecialization(const FunctionDecl *Decl)
static DeclarationFragments getFragmentsForRecordDecl(const RecordDecl *)
Build DeclarationFragments for a struct/union record declaration RecordDecl.
static DeclarationFragments getFragmentsForObjCInterface(const ObjCInterfaceDecl *)
Build DeclarationFragments for an Objective-C interface declaration ObjCInterfaceDecl.
DeclarationFragments is a vector of tagged important parts of a symbol's declaration.
DeclarationFragments & append(DeclarationFragments Other)
Append another DeclarationFragments to the end.
const std::vector< Fragment > & getFragments() const
DeclarationFragments & appendSpace()
Append a text Fragment of a space character.
static DeclarationFragments getExceptionSpecificationString(ExceptionSpecificationType ExceptionSpec)
@ GenericParameter
Parameter that's used as generics in the context.
@ ExternalParam
External parameters in Objective-C methods.
@ TypeIdentifier
Identifier that refers to a type in the context.
@ InternalParam
Internal/local parameters in Objective-C methods.
DeclarationFragments & removeTrailingSemicolon()
Removes a trailing semicolon character if present.
static StringRef getFragmentKindString(FragmentKind Kind)
Get the string description of a FragmentKind Kind.
static DeclarationFragments getStructureTypeFragment(const RecordDecl *Decl)
DeclarationFragments & appendSemicolon()
Append a text Fragment of a semicolon character.
static FragmentKind parseFragmentKindFromString(StringRef S)
Get the corresponding FragmentKind from string S.
Store function signature information with DeclarationFragments of the return type and parameters.
@ kind_nullability
Indicates that the nullability of the type was spelled with a property attribute rather than a type q...
@ After
Like System, but searched after the system directories.
bool generateUSRForType(QualType T, ASTContext &Ctx, SmallVectorImpl< char > &Buf)
Generates a USR for a type.
bool generateUSRForDecl(const Decl *D, SmallVectorImpl< char > &Buf)
Generate a USR for a Decl, including the USR prefix.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
Definition Specifiers.h:357
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.
Definition TypeBase.h:911
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
const FunctionProtoType * T
@ Keyword
The name has been typo-corrected to a keyword.
Definition Sema.h:560
@ Type
The name was classified as a type.
Definition Sema.h:562
@ Concept
The name was classified as a concept name.
Definition Sema.h:589
llvm::StringRef getAsString(SyncScope S)
Definition SyncScope.h:62
U cast(CodeGen::Address addr)
Definition Address.h:327
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition TypeBase.h:5853
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5858
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:5874
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_DependentNoexcept
noexcept(expression), value-dependent
@ EST_None
no exception specification
@ EST_BasicNoexcept
noexcept
@ EST_NoexceptFalse
noexcept(expression), evals to 'false'
@ EST_NoexceptTrue
noexcept(expression), evals to 'true'
@ EST_Dynamic
throw(T1, T2)
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Definition Type.cpp:3309
const Type * Ty
The locally-unqualified type.
Definition TypeBase.h:872
Qualifiers Quals
The local qualifiers.
Definition TypeBase.h:875
Fragment holds information of a single fragment.