clang 20.0.0git
DeclarationFragments.cpp
Go to the documentation of this file.
1//===- ExtractAPI/DeclarationFragments.cpp ----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file implements Declaration Fragments related classes.
11///
12//===----------------------------------------------------------------------===//
13
15#include "clang/AST/ASTFwd.h"
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclCXX.h"
20#include "clang/AST/Type.h"
21#include "clang/AST/TypeLoc.h"
24#include "llvm/ADT/StringSwitch.h"
25#include "llvm/Support/ErrorHandling.h"
26#include "llvm/Support/raw_ostream.h"
27#include <optional>
28
29using namespace clang::extractapi;
30using namespace llvm;
31
32namespace {
33
34void findTypeLocForBlockDecl(const clang::TypeSourceInfo *TSInfo,
36 clang::FunctionProtoTypeLoc &BlockProto) {
37 if (!TSInfo)
38 return;
39
41 while (true) {
42 // Look through qualified types
43 if (auto QualifiedTL = TL.getAs<clang::QualifiedTypeLoc>()) {
44 TL = QualifiedTL.getUnqualifiedLoc();
45 continue;
46 }
47
48 if (auto AttrTL = TL.getAs<clang::AttributedTypeLoc>()) {
49 TL = AttrTL.getModifiedLoc();
50 continue;
51 }
52
53 // Try to get the function prototype behind the block pointer type,
54 // then we're done.
55 if (auto BlockPtr = TL.getAs<clang::BlockPointerTypeLoc>()) {
56 TL = BlockPtr.getPointeeLoc().IgnoreParens();
58 BlockProto = TL.getAs<clang::FunctionProtoTypeLoc>();
59 }
60 break;
61 }
62}
63
64} // namespace
65
67DeclarationFragments::appendUnduplicatedTextCharacter(char Character) {
68 if (!Fragments.empty()) {
69 Fragment &Last = Fragments.back();
70 if (Last.Kind == FragmentKind::Text) {
71 // Merge the extra space into the last fragment if the last fragment is
72 // also text.
73 if (Last.Spelling.back() != Character) { // avoid duplicates at end
74 Last.Spelling.push_back(Character);
75 }
76 } else {
78 Fragments.back().Spelling.push_back(Character);
79 }
80 }
81
82 return *this;
83}
84
86 return appendUnduplicatedTextCharacter(' ');
87}
88
90 return appendUnduplicatedTextCharacter(';');
91}
92
94 if (Fragments.empty())
95 return *this;
96
97 Fragment &Last = Fragments.back();
98 if (Last.Kind == FragmentKind::Text && Last.Spelling.back() == ';')
99 Last.Spelling.pop_back();
100
101 return *this;
102}
103
106 switch (Kind) {
108 return "none";
110 return "keyword";
112 return "attribute";
114 return "number";
116 return "string";
118 return "identifier";
120 return "typeIdentifier";
122 return "genericParameter";
124 return "externalParam";
126 return "internalParam";
128 return "text";
129 }
130
131 llvm_unreachable("Unhandled FragmentKind");
132}
133
136 return llvm::StringSwitch<FragmentKind>(S)
142 .Case("typeIdentifier",
144 .Case("genericParameter",
150}
151
153 ExceptionSpecificationType ExceptionSpec) {
154 DeclarationFragments Fragments;
155 switch (ExceptionSpec) {
157 return Fragments;
164 // FIXME: throw(int), get types of inner expression
165 return Fragments;
170 // FIXME: throw(conditional-expression), get expression
171 break;
184 default:
185 return Fragments;
186 }
187
188 llvm_unreachable("Unhandled exception specification");
189}
190
193 DeclarationFragments Fragments;
194 if (Record->isStruct())
196 else if (Record->isUnion())
198 else
200
201 return Fragments;
202}
203
204// NNS stores C++ nested name specifiers, which are prefixes to qualified names.
205// Build declaration fragments for NNS recursively so that we have the USR for
206// every part in a qualified name, and also leaves the actual underlying type
207// cleaner for its own fragment.
209DeclarationFragmentsBuilder::getFragmentsForNNS(const NestedNameSpecifier *NNS,
210 ASTContext &Context,
211 DeclarationFragments &After) {
212 DeclarationFragments Fragments;
213 if (NNS->getPrefix())
214 Fragments.append(getFragmentsForNNS(NNS->getPrefix(), Context, After));
215
216 switch (NNS->getKind()) {
218 Fragments.append(NNS->getAsIdentifier()->getName(),
220 break;
221
223 const NamespaceDecl *NS = NNS->getAsNamespace();
224 if (NS->isAnonymousNamespace())
225 return Fragments;
228 Fragments.append(NS->getName(),
230 break;
231 }
232
234 const NamespaceAliasDecl *Alias = NNS->getAsNamespaceAlias();
236 index::generateUSRForDecl(Alias, USR);
237 Fragments.append(Alias->getName(),
239 Alias);
240 break;
241 }
242
244 // The global specifier `::` at the beginning. No stored value.
245 break;
246
248 // Microsoft's `__super` specifier.
250 break;
251
253 // A type prefixed by the `template` keyword.
255 Fragments.appendSpace();
256 // Fallthrough after adding the keyword to handle the actual type.
257 [[fallthrough]];
258
260 const Type *T = NNS->getAsType();
261 // FIXME: Handle C++ template specialization type
262 Fragments.append(getFragmentsForType(T, Context, After));
263 break;
264 }
265 }
266
267 // Add the separator text `::` for this segment.
268 return Fragments.append("::", DeclarationFragments::FragmentKind::Text);
269}
270
271// Recursively build the declaration fragments for an underlying `Type` with
272// qualifiers removed.
273DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
274 const Type *T, ASTContext &Context, DeclarationFragments &After) {
275 assert(T && "invalid type");
276
277 DeclarationFragments Fragments;
278
279 if (const MacroQualifiedType *MQT = dyn_cast<MacroQualifiedType>(T)) {
280 Fragments.append(
281 getFragmentsForType(MQT->getUnderlyingType(), Context, After));
282 return Fragments;
283 }
284
285 if (const AttributedType *AT = dyn_cast<AttributedType>(T)) {
286 // FIXME: Serialize Attributes correctly
287 Fragments.append(
288 getFragmentsForType(AT->getModifiedType(), Context, After));
289 return Fragments;
290 }
291
292 // An ElaboratedType is a sugar for types that are referred to using an
293 // elaborated keyword, e.g., `struct S`, `enum E`, or (in C++) via a
294 // qualified name, e.g., `N::M::type`, or both.
295 if (const ElaboratedType *ET = dyn_cast<ElaboratedType>(T)) {
296 ElaboratedTypeKeyword Keyword = ET->getKeyword();
297 if (Keyword != ElaboratedTypeKeyword::None) {
298 Fragments
301 .appendSpace();
302 }
303
304 if (const NestedNameSpecifier *NNS = ET->getQualifier())
305 Fragments.append(getFragmentsForNNS(NNS, Context, After));
306
307 // After handling the elaborated keyword or qualified name, build
308 // declaration fragments for the desugared underlying type.
309 return Fragments.append(getFragmentsForType(ET->desugar(), Context, After));
310 }
311
312 // If the type is a typedefed type, get the underlying TypedefNameDecl for a
313 // direct reference to the typedef instead of the wrapped type.
314
315 // 'id' type is a typedef for an ObjCObjectPointerType
316 // we treat it as a typedef
317 if (const TypedefType *TypedefTy = dyn_cast<TypedefType>(T)) {
318 const TypedefNameDecl *Decl = TypedefTy->getDecl();
319 TypedefUnderlyingTypeResolver TypedefResolver(Context);
320 std::string USR = TypedefResolver.getUSRForType(QualType(T, 0));
321
322 if (T->isObjCIdType()) {
323 return Fragments.append(Decl->getName(),
325 }
326
327 return Fragments.append(
329 USR, TypedefResolver.getUnderlyingTypeDecl(QualType(T, 0)));
330 }
331
332 // Declaration fragments of a pointer type is the declaration fragments of
333 // the pointee type followed by a `*`,
335 return Fragments
336 .append(getFragmentsForType(T->getPointeeType(), Context, After))
338
339 // For Objective-C `id` and `Class` pointers
340 // we do not spell out the `*`.
341 if (T->isObjCObjectPointerType() &&
343
344 Fragments.append(getFragmentsForType(T->getPointeeType(), Context, After));
345
346 // id<protocol> is an qualified id type
347 // id<protocol>* is not an qualified id type
350 }
351
352 return Fragments;
353 }
354
355 // Declaration fragments of a lvalue reference type is the declaration
356 // fragments of the underlying type followed by a `&`.
357 if (const LValueReferenceType *LRT = dyn_cast<LValueReferenceType>(T))
358 return Fragments
359 .append(
360 getFragmentsForType(LRT->getPointeeTypeAsWritten(), Context, After))
362
363 // Declaration fragments of a rvalue reference type is the declaration
364 // fragments of the underlying type followed by a `&&`.
365 if (const RValueReferenceType *RRT = dyn_cast<RValueReferenceType>(T))
366 return Fragments
367 .append(
368 getFragmentsForType(RRT->getPointeeTypeAsWritten(), Context, After))
370
371 // Declaration fragments of an array-typed variable have two parts:
372 // 1. the element type of the array that appears before the variable name;
373 // 2. array brackets `[(0-9)?]` that appear after the variable name.
374 if (const ArrayType *AT = T->getAsArrayTypeUnsafe()) {
375 // Build the "after" part first because the inner element type might also
376 // be an array-type. For example `int matrix[3][4]` which has a type of
377 // "(array 3 of (array 4 of ints))."
378 // Push the array size part first to make sure they are in the right order.
380
381 switch (AT->getSizeModifier()) {
383 break;
386 break;
389 break;
390 }
391
392 if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) {
393 // FIXME: right now this would evaluate any expressions/macros written in
394 // the original source to concrete values. For example
395 // `int nums[MAX]` -> `int nums[100]`
396 // `char *str[5 + 1]` -> `char *str[6]`
398 CAT->getSize().toStringUnsigned(Size);
400 }
401
403
404 return Fragments.append(
405 getFragmentsForType(AT->getElementType(), Context, After));
406 }
407
408 if (const TemplateSpecializationType *TemplSpecTy =
409 dyn_cast<TemplateSpecializationType>(T)) {
410 const auto TemplName = TemplSpecTy->getTemplateName();
411 std::string Str;
412 raw_string_ostream Stream(Str);
413 TemplName.print(Stream, Context.getPrintingPolicy(),
415 SmallString<64> USR("");
416 if (const auto *TemplDecl = TemplName.getAsTemplateDecl())
417 index::generateUSRForDecl(TemplDecl, USR);
418
419 return Fragments
423 TemplSpecTy->template_arguments(), Context, std::nullopt))
425 }
426
427 // Everything we care about has been handled now, reduce to the canonical
428 // unqualified base type.
430
431 // If the base type is a TagType (struct/interface/union/class/enum), let's
432 // get the underlying Decl for better names and USRs.
433 if (const TagType *TagTy = dyn_cast<TagType>(Base)) {
434 const TagDecl *Decl = TagTy->getDecl();
435 // Anonymous decl, skip this fragment.
436 if (Decl->getName().empty())
437 return Fragments.append("{ ... }",
439 SmallString<128> TagUSR;
441 return Fragments.append(Decl->getName(),
443 TagUSR, Decl);
444 }
445
446 // If the base type is an ObjCInterfaceType, use the underlying
447 // ObjCInterfaceDecl for the true USR.
448 if (const auto *ObjCIT = dyn_cast<ObjCInterfaceType>(Base)) {
449 const auto *Decl = ObjCIT->getDecl();
452 return Fragments.append(Decl->getName(),
454 USR, Decl);
455 }
456
457 // Default fragment builder for other kinds of types (BuiltinType etc.)
460 Fragments.append(Base.getAsString(),
462
463 return Fragments;
464}
465
467DeclarationFragmentsBuilder::getFragmentsForQualifiers(const Qualifiers Quals) {
468 DeclarationFragments Fragments;
469 if (Quals.hasConst())
471 if (Quals.hasVolatile())
473 if (Quals.hasRestrict())
475
476 return Fragments;
477}
478
479DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
480 const QualType QT, ASTContext &Context, DeclarationFragments &After) {
481 assert(!QT.isNull() && "invalid type");
482
483 if (const ParenType *PT = dyn_cast<ParenType>(QT)) {
485 return getFragmentsForType(PT->getInnerType(), Context, After)
487 }
488
489 const SplitQualType SQT = QT.split();
490 DeclarationFragments QualsFragments = getFragmentsForQualifiers(SQT.Quals),
491 TypeFragments =
492 getFragmentsForType(SQT.Ty, Context, After);
493 if (QT.getAsString() == "_Bool")
494 TypeFragments.replace("bool", 0);
495
496 if (QualsFragments.getFragments().empty())
497 return TypeFragments;
498
499 // Use east qualifier for pointer types
500 // For example:
501 // ```
502 // int * const
503 // ^---- ^----
504 // type qualifier
505 // ^-----------------
506 // const pointer to int
507 // ```
508 // should not be reconstructed as
509 // ```
510 // const int *
511 // ^---- ^--
512 // qualifier type
513 // ^---------------- ^
514 // pointer to const int
515 // ```
516 if (SQT.Ty->isAnyPointerType())
517 return TypeFragments.appendSpace().append(std::move(QualsFragments));
518
519 return QualsFragments.appendSpace().append(std::move(TypeFragments));
520}
521
523 const NamespaceDecl *Decl) {
524 DeclarationFragments Fragments;
526 if (!Decl->isAnonymousNamespace())
527 Fragments.appendSpace().append(
529 return Fragments.appendSemicolon();
530}
531
534 DeclarationFragments Fragments;
535 if (Var->isConstexpr())
537 .appendSpace();
538
539 StorageClass SC = Var->getStorageClass();
540 if (SC != SC_None)
541 Fragments
544 .appendSpace();
545
546 // Capture potential fragments that needs to be placed after the variable name
547 // ```
548 // int nums[5];
549 // char (*ptr_to_array)[6];
550 // ```
552 FunctionTypeLoc BlockLoc;
553 FunctionProtoTypeLoc BlockProtoLoc;
554 findTypeLocForBlockDecl(Var->getTypeSourceInfo(), BlockLoc, BlockProtoLoc);
555
556 if (!BlockLoc) {
558 ? Var->getTypeSourceInfo()->getType()
560 Var->getType());
561
562 Fragments.append(getFragmentsForType(T, Var->getASTContext(), After))
563 .appendSpace();
564 } else {
565 Fragments.append(getFragmentsForBlock(Var, BlockLoc, BlockProtoLoc, After));
566 }
567
568 return Fragments
570 .append(std::move(After))
572}
573
576 DeclarationFragments Fragments;
577 if (Var->isConstexpr())
579 .appendSpace();
580 QualType T =
581 Var->getTypeSourceInfo()
582 ? Var->getTypeSourceInfo()->getType()
584
585 // Might be a member, so might be static.
586 if (Var->isStaticDataMember())
588 .appendSpace();
589
591 DeclarationFragments ArgumentFragment =
592 getFragmentsForType(T, Var->getASTContext(), After);
593 if (StringRef(ArgumentFragment.begin()->Spelling)
594 .starts_with("type-parameter")) {
595 std::string ProperArgName = T.getAsString();
596 ArgumentFragment.begin()->Spelling.swap(ProperArgName);
597 }
598 Fragments.append(std::move(ArgumentFragment))
599 .appendSpace()
602 return Fragments;
603}
604
606DeclarationFragmentsBuilder::getFragmentsForParam(const ParmVarDecl *Param) {
607 DeclarationFragments Fragments, After;
608
609 auto *TSInfo = Param->getTypeSourceInfo();
610
611 QualType T = TSInfo ? TSInfo->getType()
613 Param->getType());
614
615 FunctionTypeLoc BlockLoc;
616 FunctionProtoTypeLoc BlockProtoLoc;
617 findTypeLocForBlockDecl(TSInfo, BlockLoc, BlockProtoLoc);
618
619 DeclarationFragments TypeFragments;
620 if (BlockLoc)
621 TypeFragments.append(
622 getFragmentsForBlock(Param, BlockLoc, BlockProtoLoc, After));
623 else
624 TypeFragments.append(getFragmentsForType(T, Param->getASTContext(), After));
625
626 if (StringRef(TypeFragments.begin()->Spelling)
627 .starts_with("type-parameter")) {
628 std::string ProperArgName = Param->getOriginalType().getAsString();
629 TypeFragments.begin()->Spelling.swap(ProperArgName);
630 }
631
632 if (Param->isObjCMethodParameter()) {
634 .append(std::move(TypeFragments))
635 .append(std::move(After))
637 .append(Param->getName(),
639 } else {
640 Fragments.append(std::move(TypeFragments));
641 if (!T->isBlockPointerType())
642 Fragments.appendSpace();
643 Fragments
644 .append(Param->getName(),
646 .append(std::move(After));
647 }
648 return Fragments;
649}
650
651DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForBlock(
653 FunctionProtoTypeLoc &BlockProto, DeclarationFragments &After) {
654 DeclarationFragments Fragments;
655
656 DeclarationFragments RetTyAfter;
657 auto ReturnValueFragment = getFragmentsForType(
658 Block.getTypePtr()->getReturnType(), BlockDecl->getASTContext(), After);
659
660 Fragments.append(std::move(ReturnValueFragment))
661 .append(std::move(RetTyAfter))
662 .appendSpace()
664
666 unsigned NumParams = Block.getNumParams();
667
668 if (!BlockProto || NumParams == 0) {
669 if (BlockProto && BlockProto.getTypePtr()->isVariadic())
671 else
673 } else {
675 for (unsigned I = 0; I != NumParams; ++I) {
676 if (I)
678 After.append(getFragmentsForParam(Block.getParam(I)));
679 if (I == NumParams - 1 && BlockProto.getTypePtr()->isVariadic())
681 }
683 }
684
685 return Fragments;
686}
687
690 DeclarationFragments Fragments;
691 switch (Func->getStorageClass()) {
692 case SC_None:
693 case SC_PrivateExtern:
694 break;
695 case SC_Extern:
697 .appendSpace();
698 break;
699 case SC_Static:
701 .appendSpace();
702 break;
703 case SC_Auto:
704 case SC_Register:
705 llvm_unreachable("invalid for functions");
706 }
707 if (Func->isConsteval()) // if consteval, it is also constexpr
709 .appendSpace();
710 else if (Func->isConstexpr())
712 .appendSpace();
713
714 // FIXME: Is `after` actually needed here?
716 auto ReturnValueFragment =
717 getFragmentsForType(Func->getReturnType(), Func->getASTContext(), After);
718 if (StringRef(ReturnValueFragment.begin()->Spelling)
719 .starts_with("type-parameter")) {
720 std::string ProperArgName = Func->getReturnType().getAsString();
721 ReturnValueFragment.begin()->Spelling.swap(ProperArgName);
722 }
723
724 Fragments.append(std::move(ReturnValueFragment))
725 .appendSpace()
726 .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
765 const EnumConstantDecl *EnumConstDecl) {
766 DeclarationFragments Fragments;
767 return Fragments.append(EnumConstDecl->getName(),
769}
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
894 // Build return type
896 Fragments
897 .append(getFragmentsForType(Method->getReturnType(),
898 Method->getASTContext(), After))
899 .appendSpace()
901 .append(std::move(After));
903 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
904 if (i)
906 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
907 }
909
910 if (Method->isConst())
911 Fragments.appendSpace().append("const",
913
915 Method->getExceptionSpecType()));
916
917 return Fragments.appendSemicolon();
918}
919
922 const CXXConversionDecl *ConversionFunction) {
923 DeclarationFragments Fragments;
924
925 if (ConversionFunction->isExplicit())
927 .appendSpace();
928
930 .appendSpace();
931
932 Fragments
933 .append(ConversionFunction->getConversionType().getAsString(),
936 for (unsigned i = 0, end = ConversionFunction->getNumParams(); i != end;
937 ++i) {
938 if (i)
940 Fragments.append(getFragmentsForParam(ConversionFunction->getParamDecl(i)));
941 }
943
944 if (ConversionFunction->isConst())
945 Fragments.appendSpace().append("const",
947
948 return Fragments.appendSemicolon();
949}
950
953 const CXXMethodDecl *Method) {
954 DeclarationFragments Fragments;
955
956 // Build return type
958 Fragments
959 .append(getFragmentsForType(Method->getReturnType(),
960 Method->getASTContext(), After))
961 .appendSpace()
962 .append(Method->getNameAsString(),
964 .append(std::move(After));
966 for (unsigned i = 0, end = Method->getNumParams(); i != end; ++i) {
967 if (i)
969 Fragments.append(getFragmentsForParam(Method->getParamDecl(i)));
970 }
972
973 if (Method->isConst())
974 Fragments.appendSpace().append("const",
976
978 Method->getExceptionSpecType()));
979
980 return Fragments.appendSemicolon();
981}
982
983// Get fragments for template parameters, e.g. T in tempalte<typename T> ...
986 ArrayRef<NamedDecl *> ParameterArray) {
987 DeclarationFragments Fragments;
988 for (unsigned i = 0, end = ParameterArray.size(); i != end; ++i) {
989 if (i)
991 .appendSpace();
992
993 if (const auto *TemplateParam =
994 dyn_cast<TemplateTypeParmDecl>(ParameterArray[i])) {
995 if (TemplateParam->hasTypeConstraint())
996 Fragments.append(TemplateParam->getTypeConstraint()
997 ->getNamedConcept()
998 ->getName()
999 .str(),
1001 else if (TemplateParam->wasDeclaredWithTypename())
1002 Fragments.append("typename",
1004 else
1006
1007 if (TemplateParam->isParameterPack())
1009
1010 if (!TemplateParam->getName().empty())
1011 Fragments.appendSpace().append(
1012 TemplateParam->getName(),
1014
1015 if (TemplateParam->hasDefaultArgument()) {
1016 const auto Default = TemplateParam->getDefaultArgument();
1019 {Default.getArgument()}, TemplateParam->getASTContext(),
1020 {Default}));
1021 }
1022 } else if (const auto *NTP =
1023 dyn_cast<NonTypeTemplateParmDecl>(ParameterArray[i])) {
1025 const auto TyFragments =
1026 getFragmentsForType(NTP->getType(), NTP->getASTContext(), After);
1027 Fragments.append(std::move(TyFragments)).append(std::move(After));
1028
1029 if (NTP->isParameterPack())
1031
1032 if (!NTP->getName().empty())
1033 Fragments.appendSpace().append(
1034 NTP->getName(),
1036
1037 if (NTP->hasDefaultArgument()) {
1038 SmallString<8> ExprStr;
1039 raw_svector_ostream Output(ExprStr);
1040 NTP->getDefaultArgument().getArgument().print(
1041 NTP->getASTContext().getPrintingPolicy(), Output,
1042 /*IncludeType=*/false);
1045 }
1046 } else if (const auto *TTP =
1047 dyn_cast<TemplateTemplateParmDecl>(ParameterArray[i])) {
1049 .appendSpace()
1052 TTP->getTemplateParameters()->asArray()))
1054 .appendSpace()
1055 .append(TTP->wasDeclaredWithTypename() ? "typename" : "class",
1057
1058 if (TTP->isParameterPack())
1060
1061 if (!TTP->getName().empty())
1062 Fragments.appendSpace().append(
1063 TTP->getName(),
1065 if (TTP->hasDefaultArgument()) {
1066 const auto Default = TTP->getDefaultArgument();
1069 {Default.getArgument()}, TTP->getASTContext(), {Default}));
1070 }
1071 }
1072 }
1073 return Fragments;
1074}
1075
1076// Get fragments for template arguments, e.g. int in template<typename T>
1077// Foo<int>;
1078//
1079// Note: TemplateParameters is only necessary if the Decl is a
1080// PartialSpecialization, where we need the parameters to deduce the name of the
1081// generic arguments.
1084 const ArrayRef<TemplateArgument> TemplateArguments, ASTContext &Context,
1085 const std::optional<ArrayRef<TemplateArgumentLoc>> TemplateArgumentLocs) {
1086 DeclarationFragments Fragments;
1087 for (unsigned i = 0, end = TemplateArguments.size(); i != end; ++i) {
1088 if (i)
1090 .appendSpace();
1091
1092 const auto &CTA = TemplateArguments[i];
1093 switch (CTA.getKind()) {
1096 DeclarationFragments ArgumentFragment =
1097 getFragmentsForType(CTA.getAsType(), Context, After);
1098
1099 if (StringRef(ArgumentFragment.begin()->Spelling)
1100 .starts_with("type-parameter")) {
1101 if (TemplateArgumentLocs.has_value() &&
1102 TemplateArgumentLocs->size() > i) {
1103 std::string ProperArgName = TemplateArgumentLocs.value()[i]
1104 .getTypeSourceInfo()
1105 ->getType()
1106 .getAsString();
1107 ArgumentFragment.begin()->Spelling.swap(ProperArgName);
1108 } else {
1109 auto &Spelling = ArgumentFragment.begin()->Spelling;
1110 Spelling.clear();
1111 raw_string_ostream OutStream(Spelling);
1112 CTA.print(Context.getPrintingPolicy(), OutStream, false);
1113 }
1114 }
1115
1116 Fragments.append(std::move(ArgumentFragment));
1117 break;
1118 }
1120 const auto *VD = CTA.getAsDecl();
1121 SmallString<128> USR;
1123 Fragments.append(VD->getNameAsString(),
1125 break;
1126 }
1129 break;
1130
1132 SmallString<4> Str;
1133 CTA.getAsIntegral().toString(Str);
1135 break;
1136 }
1137
1139 const auto SVTy = CTA.getStructuralValueType();
1140 Fragments.append(CTA.getAsStructuralValue().getAsString(Context, SVTy),
1142 break;
1143 }
1144
1147 std::string Str;
1148 raw_string_ostream Stream(Str);
1149 CTA.getAsTemplate().print(Stream, Context.getPrintingPolicy());
1150 SmallString<64> USR("");
1151 if (const auto *TemplDecl =
1152 CTA.getAsTemplateOrTemplatePattern().getAsTemplateDecl())
1153 index::generateUSRForDecl(TemplDecl, USR);
1155 USR);
1156 if (CTA.getKind() == TemplateArgument::TemplateExpansion)
1158 break;
1159 }
1160
1163 .append(getFragmentsForTemplateArguments(CTA.pack_elements(), Context,
1164 {}))
1166 break;
1167
1169 SmallString<8> ExprStr;
1170 raw_svector_ostream Output(ExprStr);
1171 CTA.getAsExpr()->printPretty(Output, nullptr,
1172 Context.getPrintingPolicy());
1174 break;
1175 }
1176
1178 break;
1179 }
1180 }
1181 return Fragments;
1182}
1183
1185 const ConceptDecl *Concept) {
1186 DeclarationFragments Fragments;
1187 return Fragments
1189 .appendSpace()
1192 Concept->getTemplateParameters()->asArray()))
1194 .appendSpace()
1196 .appendSpace()
1197 .append(Concept->getName().str(),
1199 .appendSemicolon();
1200}
1201
1204 const RedeclarableTemplateDecl *RedeclarableTemplate) {
1205 DeclarationFragments Fragments;
1207 .appendSpace()
1210 RedeclarableTemplate->getTemplateParameters()->asArray()))
1212 .appendSpace();
1213
1214 if (isa<TypeAliasTemplateDecl>(RedeclarableTemplate))
1215 Fragments.appendSpace()
1217 .appendSpace()
1218 .append(RedeclarableTemplate->getName(),
1220 // the templated records will be resposbible for injecting their templates
1221 return Fragments.appendSpace();
1222}
1223
1227 DeclarationFragments Fragments;
1228 return Fragments
1230 .appendSpace()
1233 .appendSpace()
1235 cast<CXXRecordDecl>(Decl)))
1236 .pop_back() // there is an extra semicolon now
1239 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1240 Decl->getTemplateArgsAsWritten()->arguments()))
1242 .appendSemicolon();
1243}
1244
1248 DeclarationFragments Fragments;
1249 return Fragments
1251 .appendSpace()
1254 Decl->getTemplateParameters()->asArray()))
1256 .appendSpace()
1258 cast<CXXRecordDecl>(Decl)))
1259 .pop_back() // there is an extra semicolon now
1262 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1263 Decl->getTemplateArgsAsWritten()->arguments()))
1265 .appendSemicolon();
1266}
1267
1271 DeclarationFragments Fragments;
1272 return Fragments
1274 .appendSpace()
1277 .appendSpace()
1279 .pop_back() // there is an extra semicolon now
1282 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1283 Decl->getTemplateArgsAsWritten()->arguments()))
1285 .appendSemicolon();
1286}
1287
1291 DeclarationFragments Fragments;
1292 return Fragments
1294 .appendSpace()
1296 // Partial specs may have new params.
1298 Decl->getTemplateParameters()->asArray()))
1300 .appendSpace()
1302 .pop_back() // there is an extra semicolon now
1305 Decl->getTemplateArgs().asArray(), Decl->getASTContext(),
1306 Decl->getTemplateArgsAsWritten()->arguments()))
1308 .appendSemicolon();
1309}
1310
1313 const FunctionTemplateDecl *Decl) {
1314 DeclarationFragments Fragments;
1315 return Fragments
1317 .appendSpace()
1319 // Partial specs may have new params.
1321 Decl->getTemplateParameters()->asArray()))
1323 .appendSpace()
1325 Decl->getAsFunction()));
1326}
1327
1330 const FunctionDecl *Decl) {
1331 DeclarationFragments Fragments;
1332 return Fragments
1334 .appendSpace()
1336 .appendSpace()
1338}
1339
1342 const MacroInfo *MI) {
1343 DeclarationFragments Fragments;
1345 .appendSpace();
1347
1348 if (MI->isFunctionLike()) {
1350 unsigned numParameters = MI->getNumParams();
1351 if (MI->isC99Varargs())
1352 --numParameters;
1353 for (unsigned i = 0; i < numParameters; ++i) {
1354 if (i)
1356 Fragments.append(MI->params()[i]->getName(),
1358 }
1359 if (MI->isVariadic()) {
1360 if (numParameters && MI->isC99Varargs())
1363 }
1365 }
1366 return Fragments;
1367}
1368
1370 const ObjCCategoryDecl *Category) {
1371 DeclarationFragments Fragments;
1372
1373 auto *Interface = Category->getClassInterface();
1374 SmallString<128> InterfaceUSR;
1375 index::generateUSRForDecl(Interface, InterfaceUSR);
1376
1378 .appendSpace()
1379 .append(Interface->getName(),
1381 Interface)
1383 .append(Category->getName(),
1386
1387 return Fragments;
1388}
1389
1392 DeclarationFragments Fragments;
1393 // Build the base of the Objective-C interface declaration.
1395 .appendSpace()
1396 .append(Interface->getName(),
1398
1399 // Build the inheritance part of the declaration.
1400 if (const ObjCInterfaceDecl *SuperClass = Interface->getSuperClass()) {
1401 SmallString<128> SuperUSR;
1402 index::generateUSRForDecl(SuperClass, SuperUSR);
1404 .append(SuperClass->getName(),
1406 SuperClass);
1407 }
1408
1409 return Fragments;
1410}
1411
1413 const ObjCMethodDecl *Method) {
1414 DeclarationFragments Fragments, After;
1415 // Build the instance/class method indicator.
1416 if (Method->isClassMethod())
1418 else if (Method->isInstanceMethod())
1420
1421 // Build the return type.
1423 .append(getFragmentsForType(Method->getReturnType(),
1424 Method->getASTContext(), After))
1425 .append(std::move(After))
1427
1428 // Build the selector part.
1429 Selector Selector = Method->getSelector();
1430 if (Selector.getNumArgs() == 0)
1431 // For Objective-C methods that don't take arguments, the first (and only)
1432 // slot of the selector is the method name.
1433 Fragments.appendSpace().append(
1436
1437 // For Objective-C methods that take arguments, build the selector slots.
1438 for (unsigned i = 0, end = Method->param_size(); i != end; ++i) {
1439 // Objective-C method selector parts are considered as identifiers instead
1440 // of "external parameters" as in Swift. This is because Objective-C method
1441 // symbols are referenced with the entire selector, instead of just the
1442 // method name in Swift.
1444 ParamID.append(":");
1445 Fragments.appendSpace().append(
1447
1448 // Build the internal parameter.
1449 const ParmVarDecl *Param = Method->getParamDecl(i);
1450 Fragments.append(getFragmentsForParam(Param));
1451 }
1452
1453 return Fragments.appendSemicolon();
1454}
1455
1457 const ObjCPropertyDecl *Property) {
1458 DeclarationFragments Fragments, After;
1459
1460 // Build the Objective-C property keyword.
1462
1463 const auto Attributes = Property->getPropertyAttributesAsWritten();
1464 // Build the attributes if there is any associated with the property.
1465 if (Attributes != ObjCPropertyAttribute::kind_noattr) {
1466 // No leading comma for the first attribute.
1467 bool First = true;
1469 // Helper function to render the attribute.
1470 auto RenderAttribute =
1471 [&](ObjCPropertyAttribute::Kind Kind, StringRef Spelling,
1472 StringRef Arg = "",
1475 // Check if the `Kind` attribute is set for this property.
1476 if ((Attributes & Kind) && !Spelling.empty()) {
1477 // Add a leading comma if this is not the first attribute rendered.
1478 if (!First)
1480 // Render the spelling of this attribute `Kind` as a keyword.
1481 Fragments.append(Spelling,
1483 // If this attribute takes in arguments (e.g. `getter=getterName`),
1484 // render the arguments.
1485 if (!Arg.empty())
1487 .append(Arg, ArgKind);
1488 First = false;
1489 }
1490 };
1491
1492 // Go through all possible Objective-C property attributes and render set
1493 // ones.
1494 RenderAttribute(ObjCPropertyAttribute::kind_class, "class");
1495 RenderAttribute(ObjCPropertyAttribute::kind_direct, "direct");
1496 RenderAttribute(ObjCPropertyAttribute::kind_nonatomic, "nonatomic");
1497 RenderAttribute(ObjCPropertyAttribute::kind_atomic, "atomic");
1498 RenderAttribute(ObjCPropertyAttribute::kind_assign, "assign");
1499 RenderAttribute(ObjCPropertyAttribute::kind_retain, "retain");
1500 RenderAttribute(ObjCPropertyAttribute::kind_strong, "strong");
1501 RenderAttribute(ObjCPropertyAttribute::kind_copy, "copy");
1502 RenderAttribute(ObjCPropertyAttribute::kind_weak, "weak");
1504 "unsafe_unretained");
1505 RenderAttribute(ObjCPropertyAttribute::kind_readwrite, "readwrite");
1506 RenderAttribute(ObjCPropertyAttribute::kind_readonly, "readonly");
1507 RenderAttribute(ObjCPropertyAttribute::kind_getter, "getter",
1508 Property->getGetterName().getAsString());
1509 RenderAttribute(ObjCPropertyAttribute::kind_setter, "setter",
1510 Property->getSetterName().getAsString());
1511
1512 // Render nullability attributes.
1513 if (Attributes & ObjCPropertyAttribute::kind_nullability) {
1514 QualType Type = Property->getType();
1515 if (const auto Nullability =
1517 if (!First)
1519 if (*Nullability == NullabilityKind::Unspecified &&
1521 Fragments.append("null_resettable",
1523 else
1524 Fragments.append(
1525 getNullabilitySpelling(*Nullability, /*isContextSensitive=*/true),
1527 First = false;
1528 }
1529 }
1530
1532 }
1533
1534 Fragments.appendSpace();
1535
1536 FunctionTypeLoc BlockLoc;
1537 FunctionProtoTypeLoc BlockProtoLoc;
1538 findTypeLocForBlockDecl(Property->getTypeSourceInfo(), BlockLoc,
1539 BlockProtoLoc);
1540
1541 auto PropType = Property->getType();
1542 if (!BlockLoc)
1543 Fragments
1544 .append(getFragmentsForType(PropType, Property->getASTContext(), After))
1545 .appendSpace();
1546 else
1547 Fragments.append(
1548 getFragmentsForBlock(Property, BlockLoc, BlockProtoLoc, After));
1549
1550 return Fragments
1551 .append(Property->getName(),
1553 .append(std::move(After))
1554 .appendSemicolon();
1555}
1556
1558 const ObjCProtocolDecl *Protocol) {
1559 DeclarationFragments Fragments;
1560 // Build basic protocol declaration.
1562 .appendSpace()
1563 .append(Protocol->getName(),
1565
1566 // If this protocol conforms to other protocols, build the conformance list.
1567 if (!Protocol->protocols().empty()) {
1569 for (ObjCProtocolDecl::protocol_iterator It = Protocol->protocol_begin();
1570 It != Protocol->protocol_end(); It++) {
1571 // Add a leading comma if this is not the first protocol rendered.
1572 if (It != Protocol->protocol_begin())
1574
1575 SmallString<128> USR;
1576 index::generateUSRForDecl(*It, USR);
1577 Fragments.append((*It)->getName(),
1579 *It);
1580 }
1582 }
1583
1584 return Fragments;
1585}
1586
1588 const TypedefNameDecl *Decl) {
1589 DeclarationFragments Fragments, After;
1591 .appendSpace()
1592 .append(getFragmentsForType(Decl->getUnderlyingType(),
1593 Decl->getASTContext(), After))
1594 .append(std::move(After))
1595 .appendSpace()
1597
1598 return Fragments.appendSemicolon();
1599}
1600
1601// Instantiate template for FunctionDecl.
1602template FunctionSignature
1604
1605// Instantiate template for ObjCMethodDecl.
1606template FunctionSignature
1608
1609// Subheading of a symbol defaults to its name.
1612 DeclarationFragments Fragments;
1613 if (isa<CXXConstructorDecl>(Decl) || isa<CXXDestructorDecl>(Decl))
1614 Fragments.append(cast<CXXRecordDecl>(Decl->getDeclContext())->getName(),
1616 else if (isa<CXXConversionDecl>(Decl)) {
1617 Fragments.append(
1618 cast<CXXConversionDecl>(Decl)->getConversionType().getAsString(),
1620 } else if (isa<CXXMethodDecl>(Decl) &&
1621 cast<CXXMethodDecl>(Decl)->isOverloadedOperator()) {
1622 Fragments.append(Decl->getNameAsString(),
1624 } else if (isa<TagDecl>(Decl) &&
1625 cast<TagDecl>(Decl)->getTypedefNameForAnonDecl()) {
1626 return getSubHeading(cast<TagDecl>(Decl)->getTypedefNameForAnonDecl());
1627 } else if (Decl->getIdentifier()) {
1628 Fragments.append(Decl->getName(),
1630 } else
1631 Fragments.append(Decl->getDeclName().getAsString(),
1633 return Fragments;
1634}
1635
1636// Subheading of an Objective-C method is a `+` or `-` sign indicating whether
1637// it's a class method or an instance method, followed by the selector name.
1640 DeclarationFragments Fragments;
1641 if (Method->isClassMethod())
1643 else if (Method->isInstanceMethod())
1645
1646 return Fragments.append(Method->getNameAsString(),
1648}
1649
1650// Subheading of a symbol defaults to its name.
1653 DeclarationFragments Fragments;
1655 return Fragments;
1656}
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:3035
const CFGBlock * Block
Definition: HTMLLogger.cpp:152
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:188
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
Definition: ASTContext.h:2324
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3577
Type source information for an attributed type.
Definition: TypeLoc.h:875
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:6127
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:4943
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4474
Wrapper for source info for block pointers.
Definition: TypeLoc.h:1345
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2880
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2078
bool isVolatile() const
Definition: DeclCXX.h:2131
bool isConst() const
Definition: DeclCXX.h:2130
bool isStatic() const
Definition: DeclCXX.cpp:2280
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:3615
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:520
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition: DeclBase.cpp:246
DeclContext * getDeclContext()
Definition: DeclBase.h:451
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:764
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6943
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3277
Represents an enum.
Definition: Decl.h:3847
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:4007
Represents a member of a struct/union/class.
Definition: Decl.h:3033
Represents a function declaration or definition.
Definition: Decl.h:1935
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2672
ExceptionSpecificationType getExceptionSpecType() const
Gets the ExceptionSpecificationType as declared.
Definition: Decl.h:2744
QualType getReturnType() const
Definition: Decl.h:2720
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition: Decl.h:2398
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3702
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:5479
Declaration of a template function.
Definition: DeclTemplate.h:959
Wrapper for source info for functions.
Definition: TypeLoc.h:1459
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:3483
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
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
Definition: Type.h:5765
This represents a decl that may have a name.
Definition: Decl.h:253
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:280
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:296
Represents a C++ namespace alias.
Definition: DeclCXX.h:3138
Represent a C++ namespace.
Definition: Decl.h:551
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
Definition: Decl.h:602
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2328
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
unsigned param_size() const
Definition: DeclObjC.h:347
Selector getSelector() const
Definition: DeclObjC.h:327
bool isInstanceMethod() const
Definition: DeclObjC.h:426
ParmVarDecl * getParamDecl(unsigned Idx)
Definition: DeclObjC.h:377
QualType getReturnType() const
Definition: DeclObjC.h:329
bool isClassMethod() const
Definition: DeclObjC.h:434
Represents a pointer to an Objective C object.
Definition: Type.h:7580
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
Definition: Type.h:7655
bool isObjCIdOrClassType() const
True if this is equivalent to the 'id' or 'Class' type,.
Definition: Type.h:7649
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:730
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2083
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2157
Sugar for parentheses used when specifying types.
Definition: Type.h:3172
Represents a parameter to a function.
Definition: Decl.h:1725
bool isObjCMethodParameter() const
Definition: Decl.h:1768
QualType getOriginalType() const
Definition: Decl.cpp:2931
A (possibly-)qualified type.
Definition: Type.h:929
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:996
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:7952
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:324
bool hasConst() const
Definition: Type.h:450
bool hasRestrict() const
Definition: Type.h:470
bool hasVolatile() const
Definition: Type.h:460
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3501
Represents a struct/union/class.
Definition: Decl.h:4148
Declaration of a redeclarable template.
Definition: DeclTemplate.h:721
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:3564
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3792
@ 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:418
ArrayRef< NamedDecl * > asArray()
Definition: DeclTemplate.h:142
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:6661
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:1256
A container of type source information.
Definition: Type.h:7902
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:7913
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Definition: Type.cpp:3248
The base class of the type hierarchy.
Definition: Type.h:1828
bool isBlockPointerType() const
Definition: Type.h:8200
bool isFunctionPointerType() const
Definition: Type.h:8226
bool isPointerType() const
Definition: Type.h:8186
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:738
bool isObjCIdType() const
Definition: Type.h:8361
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition: Type.h:8786
bool isObjCObjectPointerType() const
Definition: Type.h:8328
bool isAnyPointerType() const
Definition: Type.h:8194
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8731
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3413
QualType getType() const
Definition: Decl.h:682
Represents a variable declaration or definition.
Definition: Decl.h:882
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1513
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
Definition: Decl.cpp:2110
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition: Decl.h:1234
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1119
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.
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
StorageClass
Storage classes.
Definition: Specifiers.h:248
@ SC_Auto
Definition: Specifiers.h:256
@ SC_PrivateExtern
Definition: Specifiers.h:253
@ SC_Extern
Definition: Specifiers.h:251
@ SC_Register
Definition: Specifiers.h:257
@ SC_Static
Definition: Specifiers.h:252
@ SC_None
Definition: Specifiers.h:250
@ Property
The type of a property.
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
const FunctionProtoType * T
llvm::StringRef getAsString(SyncScope S)
Definition: SyncScope.h:60
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:6846
@ 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:862
const Type * Ty
The locally-unqualified type.
Definition: Type.h:864
Qualifiers Quals
The local qualifiers.
Definition: Type.h:867
Fragment holds information of a single fragment.