clang  15.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 
17 #include "llvm/ADT/StringSwitch.h"
18 
19 using namespace clang::extractapi;
20 using namespace llvm;
21 
23  if (!Fragments.empty()) {
24  Fragment &Last = Fragments.back();
25  if (Last.Kind == FragmentKind::Text) {
26  // Merge the extra space into the last fragment if the last fragment is
27  // also text.
28  if (Last.Spelling.back() != ' ') { // avoid extra trailing spaces.
29  Last.Spelling.push_back(' ');
30  }
31  } else {
32  append(" ", FragmentKind::Text);
33  }
34  }
35 
36  return *this;
37 }
38 
41  switch (Kind) {
43  return "none";
45  return "keyword";
47  return "attribute";
49  return "number";
51  return "string";
53  return "identifier";
55  return "typeIdentifier";
57  return "genericParameter";
59  return "externalParam";
61  return "internalParam";
63  return "text";
64  }
65 
66  llvm_unreachable("Unhandled FragmentKind");
67 }
68 
71  return llvm::StringSwitch<FragmentKind>(S)
77  .Case("typeIdentifier",
79  .Case("genericParameter",
85 }
86 
87 // NNS stores C++ nested name specifiers, which are prefixes to qualified names.
88 // Build declaration fragments for NNS recursively so that we have the USR for
89 // every part in a qualified name, and also leaves the actual underlying type
90 // cleaner for its own fragment.
92 DeclarationFragmentsBuilder::getFragmentsForNNS(const NestedNameSpecifier *NNS,
93  ASTContext &Context,
95  DeclarationFragments Fragments;
96  if (NNS->getPrefix())
97  Fragments.append(getFragmentsForNNS(NNS->getPrefix(), Context, After));
98 
99  switch (NNS->getKind()) {
101  Fragments.append(NNS->getAsIdentifier()->getName(),
103  break;
104 
106  const NamespaceDecl *NS = NNS->getAsNamespace();
107  if (NS->isAnonymousNamespace())
108  return Fragments;
109  SmallString<128> USR;
110  index::generateUSRForDecl(NS, USR);
111  Fragments.append(NS->getName(),
113  break;
114  }
115 
117  const NamespaceAliasDecl *Alias = NNS->getAsNamespaceAlias();
118  SmallString<128> USR;
119  index::generateUSRForDecl(Alias, USR);
120  Fragments.append(Alias->getName(),
122  break;
123  }
124 
126  // The global specifier `::` at the beginning. No stored value.
127  break;
128 
130  // Microsoft's `__super` specifier.
132  break;
133 
135  // A type prefixed by the `template` keyword.
137  Fragments.appendSpace();
138  // Fallthrough after adding the keyword to handle the actual type.
139  LLVM_FALLTHROUGH;
140 
142  const Type *T = NNS->getAsType();
143  // FIXME: Handle C++ template specialization type
144  Fragments.append(getFragmentsForType(T, Context, After));
145  break;
146  }
147  }
148 
149  // Add the separator text `::` for this segment.
150  return Fragments.append("::", DeclarationFragments::FragmentKind::Text);
151 }
152 
153 // Recursively build the declaration fragments for an underlying `Type` with
154 // qualifiers removed.
155 DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
156  const Type *T, ASTContext &Context, DeclarationFragments &After) {
157  assert(T && "invalid type");
158 
159  DeclarationFragments Fragments;
160 
161  // Declaration fragments of a pointer type is the declaration fragments of
162  // the pointee type followed by a `*`, except for Objective-C `id` and `Class`
163  // pointers, where we do not spell out the `*`.
164  if (T->isPointerType() ||
165  (T->isObjCObjectPointerType() &&
166  !T->getAs<ObjCObjectPointerType>()->isObjCIdOrClassType())) {
167  return Fragments
168  .append(getFragmentsForType(T->getPointeeType(), Context, After))
170  }
171 
172  // Declaration fragments of a lvalue reference type is the declaration
173  // fragments of the underlying type followed by a `&`.
174  if (const LValueReferenceType *LRT = dyn_cast<LValueReferenceType>(T))
175  return Fragments
176  .append(
177  getFragmentsForType(LRT->getPointeeTypeAsWritten(), Context, After))
179 
180  // Declaration fragments of a rvalue reference type is the declaration
181  // fragments of the underlying type followed by a `&&`.
182  if (const RValueReferenceType *RRT = dyn_cast<RValueReferenceType>(T))
183  return Fragments
184  .append(
185  getFragmentsForType(RRT->getPointeeTypeAsWritten(), Context, After))
187 
188  // Declaration fragments of an array-typed variable have two parts:
189  // 1. the element type of the array that appears before the variable name;
190  // 2. array brackets `[(0-9)?]` that appear after the variable name.
191  if (const ArrayType *AT = T->getAsArrayTypeUnsafe()) {
192  // Build the "after" part first because the inner element type might also
193  // be an array-type. For example `int matrix[3][4]` which has a type of
194  // "(array 3 of (array 4 of ints))."
195  // Push the array size part first to make sure they are in the right order.
197 
198  switch (AT->getSizeModifier()) {
199  case ArrayType::Normal:
200  break;
201  case ArrayType::Static:
203  break;
204  case ArrayType::Star:
206  break;
207  }
208 
209  if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) {
210  // FIXME: right now this would evaluate any expressions/macros written in
211  // the original source to concrete values. For example
212  // `int nums[MAX]` -> `int nums[100]`
213  // `char *str[5 + 1]` -> `char *str[6]`
215  CAT->getSize().toStringUnsigned(Size);
217  }
218 
220 
221  return Fragments.append(
222  getFragmentsForType(AT->getElementType(), Context, After));
223  }
224 
225  // An ElaboratedType is a sugar for types that are referred to using an
226  // elaborated keyword, e.g., `struct S`, `enum E`, or (in C++) via a
227  // qualified name, e.g., `N::M::type`, or both.
228  if (const ElaboratedType *ET = dyn_cast<ElaboratedType>(T)) {
229  ElaboratedTypeKeyword Keyword = ET->getKeyword();
230  if (Keyword != ETK_None) {
231  Fragments
234  .appendSpace();
235  }
236 
237  if (const NestedNameSpecifier *NNS = ET->getQualifier())
238  Fragments.append(getFragmentsForNNS(NNS, Context, After));
239 
240  // After handling the elaborated keyword or qualified name, build
241  // declaration fragments for the desugared underlying type.
242  return Fragments.append(getFragmentsForType(ET->desugar(), Context, After));
243  }
244 
245  // Everything we care about has been handled now, reduce to the canonical
246  // unqualified base type.
247  QualType Base = T->getCanonicalTypeUnqualified();
248 
249  // Render Objective-C `id`/`instancetype` as keywords.
250  if (T->isObjCIdType())
251  return Fragments.append(Base.getAsString(),
253 
254  // If the type is a typedefed type, get the underlying TypedefNameDecl for a
255  // direct reference to the typedef instead of the wrapped type.
256  if (const TypedefType *TypedefTy = dyn_cast<TypedefType>(T)) {
257  const TypedefNameDecl *Decl = TypedefTy->getDecl();
258  std::string USR =
259  TypedefUnderlyingTypeResolver(Context).getUSRForType(QualType(T, 0));
260  return Fragments.append(Decl->getName(),
262  USR);
263  }
264 
265  // If the base type is a TagType (struct/interface/union/class/enum), let's
266  // get the underlying Decl for better names and USRs.
267  if (const TagType *TagTy = dyn_cast<TagType>(Base)) {
268  const TagDecl *Decl = TagTy->getDecl();
269  // Anonymous decl, skip this fragment.
270  if (Decl->getName().empty())
271  return Fragments;
272  SmallString<128> TagUSR;
273  clang::index::generateUSRForDecl(Decl, TagUSR);
274  return Fragments.append(Decl->getName(),
276  TagUSR);
277  }
278 
279  // If the base type is an ObjCInterfaceType, use the underlying
280  // ObjCInterfaceDecl for the true USR.
281  if (const auto *ObjCIT = dyn_cast<ObjCInterfaceType>(Base)) {
282  const auto *Decl = ObjCIT->getDecl();
283  SmallString<128> USR;
284  index::generateUSRForDecl(Decl, USR);
285  return Fragments.append(Decl->getName(),
287  USR);
288  }
289 
290  // Default fragment builder for other kinds of types (BuiltinType etc.)
291  SmallString<128> USR;
292  clang::index::generateUSRForType(Base, Context, USR);
293  Fragments.append(Base.getAsString(),
295 
296  return Fragments;
297 }
298 
300 DeclarationFragmentsBuilder::getFragmentsForQualifiers(const Qualifiers Quals) {
301  DeclarationFragments Fragments;
302  if (Quals.hasConst())
304  if (Quals.hasVolatile())
306  if (Quals.hasRestrict())
308 
309  return Fragments;
310 }
311 
312 DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
313  const QualType QT, ASTContext &Context, DeclarationFragments &After) {
314  assert(!QT.isNull() && "invalid type");
315 
316  if (const ParenType *PT = dyn_cast<ParenType>(QT)) {
318  return getFragmentsForType(PT->getInnerType(), Context, After)
320  }
321 
322  const SplitQualType SQT = QT.split();
323  DeclarationFragments QualsFragments = getFragmentsForQualifiers(SQT.Quals),
324  TypeFragments =
325  getFragmentsForType(SQT.Ty, Context, After);
326  if (QualsFragments.getFragments().empty())
327  return TypeFragments;
328 
329  // Use east qualifier for pointer types
330  // For example:
331  // ```
332  // int * const
333  // ^---- ^----
334  // type qualifier
335  // ^-----------------
336  // const pointer to int
337  // ```
338  // should not be reconstructed as
339  // ```
340  // const int *
341  // ^---- ^--
342  // qualifier type
343  // ^---------------- ^
344  // pointer to const int
345  // ```
346  if (SQT.Ty->isAnyPointerType())
347  return TypeFragments.appendSpace().append(std::move(QualsFragments));
348 
349  return QualsFragments.appendSpace().append(std::move(TypeFragments));
350 }
351 
354  DeclarationFragments Fragments;
355  StorageClass SC = Var->getStorageClass();
356  if (SC != SC_None)
357  Fragments
360  .appendSpace();
361  QualType T =
362  Var->getTypeSourceInfo()
363  ? Var->getTypeSourceInfo()->getType()
365 
366  // Capture potential fragments that needs to be placed after the variable name
367  // ```
368  // int nums[5];
369  // char (*ptr_to_array)[6];
370  // ```
372  return Fragments.append(getFragmentsForType(T, Var->getASTContext(), After))
373  .appendSpace()
375  .append(std::move(After));
376 }
377 
379 DeclarationFragmentsBuilder::getFragmentsForParam(const ParmVarDecl *Param) {
380  DeclarationFragments Fragments, After;
381 
382  QualType T = Param->getTypeSourceInfo()
383  ? Param->getTypeSourceInfo()->getType()
385  Param->getType());
386 
387  DeclarationFragments TypeFragments =
388  getFragmentsForType(T, Param->getASTContext(), After);
389 
390  if (Param->isObjCMethodParameter())
392  .append(std::move(TypeFragments))
394  else
395  Fragments.append(std::move(TypeFragments)).appendSpace();
396 
397  return Fragments
398  .append(Param->getName(),
400  .append(std::move(After));
401 }
402 
405  DeclarationFragments Fragments;
406  // FIXME: Handle template specialization
407  switch (Func->getStorageClass()) {
408  case SC_None:
409  case SC_PrivateExtern:
410  break;
411  case SC_Extern:
413  .appendSpace();
414  break;
415  case SC_Static:
417  .appendSpace();
418  break;
419  case SC_Auto:
420  case SC_Register:
421  llvm_unreachable("invalid for functions");
422  }
423  // FIXME: Handle C++ function specifiers: constexpr, consteval, explicit, etc.
424 
425  // FIXME: Is `after` actually needed here?
427  Fragments
428  .append(getFragmentsForType(Func->getReturnType(), Func->getASTContext(),
429  After))
430  .appendSpace()
432  .append(std::move(After));
433 
435  for (unsigned i = 0, end = Func->getNumParams(); i != end; ++i) {
436  if (i)
438  Fragments.append(getFragmentsForParam(Func->getParamDecl(i)));
439  }
441 
442  // FIXME: Handle exception specifiers: throw, noexcept
443  return Fragments;
444 }
445 
447  const EnumConstantDecl *EnumConstDecl) {
448  DeclarationFragments Fragments;
449  return Fragments.append(EnumConstDecl->getName(),
451 }
452 
456  return getFragmentsForTypedef(TypedefNameDecl);
457 
458  DeclarationFragments Fragments, After;
460 
461  if (!EnumDecl->getName().empty())
462  Fragments.appendSpace().append(
464 
465  QualType IntegerType = EnumDecl->getIntegerType();
466  if (!IntegerType.isNull())
468  .append(
469  getFragmentsForType(IntegerType, EnumDecl->getASTContext(), After))
470  .append(std::move(After));
471 
472  return Fragments;
473 }
474 
478  return getFragmentsForType(Field->getType(), Field->getASTContext(), After)
479  .appendSpace()
480  .append(Field->getName(), DeclarationFragments::FragmentKind::Identifier)
481  .append(std::move(After));
482 }
483 
486  if (const auto *TypedefNameDecl = Record->getTypedefNameForAnonDecl())
487  return getFragmentsForTypedef(TypedefNameDecl);
488 
489  DeclarationFragments Fragments;
491 
492  if (!Record->getName().empty())
493  Fragments.appendSpace().append(
495  return Fragments;
496 }
497 
500  const MacroDirective *MD) {
501  DeclarationFragments Fragments;
503  .appendSpace();
505 
506  auto *MI = MD->getMacroInfo();
507 
508  if (MI->isFunctionLike()) {
510  unsigned numParameters = MI->getNumParams();
511  if (MI->isC99Varargs())
512  --numParameters;
513  for (unsigned i = 0; i < numParameters; ++i) {
514  if (i)
516  Fragments.append(MI->params()[i]->getName(),
518  }
519  if (MI->isVariadic()) {
520  if (numParameters && MI->isC99Varargs())
523  }
525  }
526  return Fragments;
527 }
528 
530  const ObjCCategoryDecl *Category) {
531  DeclarationFragments Fragments;
532 
533  SmallString<128> InterfaceUSR;
534  index::generateUSRForDecl(Category->getClassInterface(), InterfaceUSR);
535 
536  Fragments.append("@interface", DeclarationFragments::FragmentKind::Keyword)
537  .appendSpace()
538  .append(Category->getClassInterface()->getName(),
541  .append(Category->getName(),
544 
545  return Fragments;
546 }
547 
549  const ObjCInterfaceDecl *Interface) {
550  DeclarationFragments Fragments;
551  // Build the base of the Objective-C interface declaration.
552  Fragments.append("@interface", DeclarationFragments::FragmentKind::Keyword)
553  .appendSpace()
554  .append(Interface->getName(),
556 
557  // Build the inheritance part of the declaration.
558  if (const ObjCInterfaceDecl *SuperClass = Interface->getSuperClass()) {
559  SmallString<128> SuperUSR;
560  index::generateUSRForDecl(SuperClass, SuperUSR);
562  .append(SuperClass->getName(),
564  }
565 
566  return Fragments;
567 }
568 
570  const ObjCMethodDecl *Method) {
571  DeclarationFragments Fragments, After;
572  // Build the instance/class method indicator.
573  if (Method->isClassMethod())
575  else if (Method->isInstanceMethod())
577 
578  // Build the return type.
580  .append(getFragmentsForType(Method->getReturnType(),
581  Method->getASTContext(), After))
582  .append(std::move(After))
584 
585  // Build the selector part.
586  Selector Selector = Method->getSelector();
587  if (Selector.getNumArgs() == 0)
588  // For Objective-C methods that don't take arguments, the first (and only)
589  // slot of the selector is the method name.
590  Fragments.appendSpace().append(
593 
594  // For Objective-C methods that take arguments, build the selector slots.
595  for (unsigned i = 0, end = Method->param_size(); i != end; ++i) {
596  // Objective-C method selector parts are considered as identifiers instead
597  // of "external parameters" as in Swift. This is because Objective-C method
598  // symbols are referenced with the entire selector, instead of just the
599  // method name in Swift.
601  ParamID.append(":");
602  Fragments.appendSpace().append(
604 
605  // Build the internal parameter.
606  const ParmVarDecl *Param = Method->getParamDecl(i);
607  Fragments.append(getFragmentsForParam(Param));
608  }
609 
610  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
611 }
612 
614  const ObjCPropertyDecl *Property) {
615  DeclarationFragments Fragments, After;
616 
617  // Build the Objective-C property keyword.
618  Fragments.append("@property", DeclarationFragments::FragmentKind::Keyword);
619 
620  const auto Attributes = Property->getPropertyAttributes();
621  // Build the attributes if there is any associated with the property.
622  if (Attributes != ObjCPropertyAttribute::kind_noattr) {
623  // No leading comma for the first attribute.
624  bool First = true;
626  // Helper function to render the attribute.
627  auto RenderAttribute =
628  [&](ObjCPropertyAttribute::Kind Kind, StringRef Spelling,
629  StringRef Arg = "",
632  // Check if the `Kind` attribute is set for this property.
633  if ((Attributes & Kind) && !Spelling.empty()) {
634  // Add a leading comma if this is not the first attribute rendered.
635  if (!First)
637  // Render the spelling of this attribute `Kind` as a keyword.
638  Fragments.append(Spelling,
640  // If this attribute takes in arguments (e.g. `getter=getterName`),
641  // render the arguments.
642  if (!Arg.empty())
644  .append(Arg, ArgKind);
645  First = false;
646  }
647  };
648 
649  // Go through all possible Objective-C property attributes and render set
650  // ones.
651  RenderAttribute(ObjCPropertyAttribute::kind_class, "class");
652  RenderAttribute(ObjCPropertyAttribute::kind_direct, "direct");
653  RenderAttribute(ObjCPropertyAttribute::kind_nonatomic, "nonatomic");
654  RenderAttribute(ObjCPropertyAttribute::kind_atomic, "atomic");
655  RenderAttribute(ObjCPropertyAttribute::kind_assign, "assign");
656  RenderAttribute(ObjCPropertyAttribute::kind_retain, "retain");
657  RenderAttribute(ObjCPropertyAttribute::kind_strong, "strong");
658  RenderAttribute(ObjCPropertyAttribute::kind_copy, "copy");
659  RenderAttribute(ObjCPropertyAttribute::kind_weak, "weak");
661  "unsafe_unretained");
662  RenderAttribute(ObjCPropertyAttribute::kind_readwrite, "readwrite");
663  RenderAttribute(ObjCPropertyAttribute::kind_readonly, "readonly");
664  RenderAttribute(ObjCPropertyAttribute::kind_getter, "getter",
665  Property->getGetterName().getAsString());
666  RenderAttribute(ObjCPropertyAttribute::kind_setter, "setter",
667  Property->getSetterName().getAsString());
668 
669  // Render nullability attributes.
670  if (Attributes & ObjCPropertyAttribute::kind_nullability) {
671  QualType Type = Property->getType();
672  if (const auto Nullability =
674  if (!First)
678  Fragments.append("null_resettable",
680  else
681  Fragments.append(
682  getNullabilitySpelling(*Nullability, /*isContextSensitive=*/true),
684  First = false;
685  }
686  }
687 
689  }
690 
691  // Build the property type and name, and return the completed fragments.
692  return Fragments.appendSpace()
693  .append(getFragmentsForType(Property->getType(),
694  Property->getASTContext(), After))
695  .append(Property->getName(),
697  .append(std::move(After));
698 }
699 
701  const ObjCProtocolDecl *Protocol) {
702  DeclarationFragments Fragments;
703  // Build basic protocol declaration.
705  .appendSpace()
706  .append(Protocol->getName(),
708 
709  // If this protocol conforms to other protocols, build the conformance list.
710  if (!Protocol->protocols().empty()) {
712  for (ObjCProtocolDecl::protocol_iterator It = Protocol->protocol_begin();
713  It != Protocol->protocol_end(); It++) {
714  // Add a leading comma if this is not the first protocol rendered.
715  if (It != Protocol->protocol_begin())
717 
718  SmallString<128> USR;
719  index::generateUSRForDecl(*It, USR);
720  Fragments.append((*It)->getName(),
722  }
724  }
725 
726  return Fragments;
727 }
728 
730  const TypedefNameDecl *Decl) {
731  DeclarationFragments Fragments, After;
733  .appendSpace()
734  .append(getFragmentsForType(Decl->getUnderlyingType(),
735  Decl->getASTContext(), After))
736  .append(std::move(After))
737  .appendSpace()
739 
740  return Fragments;
741 }
742 
743 template <typename FunctionT>
746  FunctionSignature Signature;
747 
748  DeclarationFragments ReturnType, After;
749  ReturnType
750  .append(getFragmentsForType(Function->getReturnType(),
751  Function->getASTContext(), After))
752  .append(std::move(After));
753  Signature.setReturnType(ReturnType);
754 
755  for (const auto *Param : Function->parameters())
756  Signature.addParameter(Param->getName(), getFragmentsForParam(Param));
757 
758  return Signature;
759 }
760 
761 // Instantiate template for FunctionDecl.
762 template FunctionSignature
764 
765 // Instantiate template for ObjCMethodDecl.
766 template FunctionSignature
768 
769 // Subheading of a symbol defaults to its name.
772  DeclarationFragments Fragments;
773  if (!Decl->getName().empty())
774  Fragments.append(Decl->getName(),
776  return Fragments;
777 }
778 
779 // Subheading of an Objective-C method is a `+` or `-` sign indicating whether
780 // it's a class method or an instance method, followed by the selector name.
783  DeclarationFragments Fragments;
784  if (Method->isClassMethod())
786  else if (Method->isInstanceMethod())
788 
789  return Fragments.append(Method->getNameAsString(),
791 }
792 
793 // Subheading of a symbol defaults to its name.
796  DeclarationFragments Fragments;
798  return Fragments;
799 }
clang::ElaboratedTypeKeyword
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:5462
clang::ObjCInterfaceDecl
Represents an ObjC class declaration.
Definition: DeclObjC.h:1150
clang::extractapi::DeclarationFragments::appendSpace
DeclarationFragments & appendSpace()
Append a text Fragment of a space character.
Definition: DeclarationFragments.cpp:22
clang::Decl::getASTContext
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:414
clang::NestedNameSpecifier::Identifier
@ Identifier
An identifier, stored as an IdentifierInfo*.
Definition: NestedNameSpecifier.h:81
llvm
YAML serialization mapping.
Definition: Dominators.h:30
clang::FunctionDecl::getNumParams
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3445
clang::NestedNameSpecifier::Super
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
Definition: NestedNameSpecifier.h:101
clang::extractapi::DeclarationFragments::FragmentKind::TypeIdentifier
@ TypeIdentifier
Identifier that refers to a type in the context.
clang::TypeSourceInfo::getType
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6541
clang::FunctionDecl::getReturnType
QualType getReturnType() const
Definition: Decl.h:2564
clang::ento::Nullability
Nullability
Definition: CheckerHelpers.h:55
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::extractapi::DeclarationFragmentsBuilder::getFragmentsForEnum
static DeclarationFragments getFragmentsForEnum(const EnumDecl *)
Build DeclarationFragments for an enum declaration EnumDecl.
Definition: DeclarationFragments.cpp:454
clang::extractapi::DeclarationFragments::FragmentKind::NumberLiteral
@ NumberLiteral
clang::NamespaceAliasDecl
Represents a C++ namespace alias.
Definition: DeclCXX.h:3019
clang::ObjCPropertyAttribute::kind_direct
@ kind_direct
Definition: DeclObjCCommon.h:41
clang::ObjCPropertyAttribute::kind_class
@ kind_class
Definition: DeclObjCCommon.h:40
clang::NestedNameSpecifier::NamespaceAlias
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
Definition: NestedNameSpecifier.h:87
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:247
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:731
clang::FunctionDecl::getParamDecl
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2533
clang::NestedNameSpecifier
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Definition: NestedNameSpecifier.h:50
clang::extractapi::DeclarationFragmentsBuilder::getFragmentsForStruct
static DeclarationFragments getFragmentsForStruct(const RecordDecl *)
Build DeclarationFragments for a struct record declaration RecordDecl.
Definition: DeclarationFragments.cpp:485
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2862
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1680
clang::extractapi::DeclarationFragments
DeclarationFragments is a vector of tagged important parts of a symbol's declaration.
Definition: DeclarationFragments.h:43
clang::ComparisonCategoryType::First
@ First
clang::extractapi::DeclarationFragmentsBuilder::getSubHeading
static DeclarationFragments getSubHeading(const NamedDecl *)
Build sub-heading fragments for a NamedDecl.
Definition: DeclarationFragments.cpp:771
clang::ASTContext::getUnqualifiedObjCPointerType
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
Definition: ASTContext.h:2161
clang::extractapi::DeclarationFragmentsBuilder::getFragmentsForObjCMethod
static DeclarationFragments getFragmentsForObjCMethod(const ObjCMethodDecl *)
Build DeclarationFragments for an Objective-C method declaration ObjCMethodDecl.
Definition: DeclarationFragments.cpp:569
clang::TagDecl::getTypedefNameForAnonDecl
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3583
clang::extractapi::FunctionSignature
Store function signature information with DeclarationFragments of the return type and parameters.
Definition: DeclarationFragments.h:147
clang::extractapi::DeclarationFragments::Fragment
Fragment holds information of a single fragment.
Definition: DeclarationFragments.h:83
clang::ArrayType::Normal
@ Normal
Definition: Type.h:2962
clang::ObjCPropertyAttribute::kind_strong
@ kind_strong
Definition: DeclObjCCommon.h:34
clang::ArrayType::Star
@ Star
Definition: Type.h:2962
clang::EnumDecl
Represents an enum.
Definition: Decl.h:3635
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1556
clang::CodeGen::AlignmentSource::Decl
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
clang::extractapi::TypedefUnderlyingTypeResolver
Definition: TypedefUnderlyingTypeResolver.h:28
clang::extractapi::DeclarationFragments::FragmentKind::ExternalParam
@ ExternalParam
External parameters in Objective-C methods.
clang::ObjCPropertyAttribute::kind_atomic
@ kind_atomic
Definition: DeclObjCCommon.h:32
clang::TypeWithKeyword::getKeywordName
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Definition: Type.cpp:2906
clang::ObjCPropertyAttribute::kind_copy
@ kind_copy
Definition: DeclObjCCommon.h:29
clang::NestedNameSpecifier::Namespace
@ Namespace
A namespace, stored as a NamespaceDecl*.
Definition: NestedNameSpecifier.h:84
clang::NestedNameSpecifier::getAsIdentifier
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
Definition: NestedNameSpecifier.h:176
clang::extractapi::DeclarationFragmentsBuilder::getFragmentsForField
static DeclarationFragments getFragmentsForField(const FieldDecl *)
Build DeclarationFragments for a field declaration FieldDecl.
Definition: DeclarationFragments.cpp:476
clang::VarDecl::getStorageClassSpecifierString
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
Definition: Decl.cpp:2026
clang::Selector::getNameForSlot
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
Definition: IdentifierTable.cpp:514
DeclarationFragments.h
clang::extractapi::FunctionSignature::setReturnType
void setReturnType(DeclarationFragments RT)
Definition: DeclarationFragments.h:169
clang::AttributedType::stripOuterNullability
static Optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
Definition: Type.cpp:4249
clang::ObjCPropertyAttribute::kind_weak
@ kind_weak
Definition: DeclObjCCommon.h:33
clang::SC_Extern
@ SC_Extern
Definition: Specifiers.h:236
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:209
clang::ObjCPropertyAttribute::kind_unsafe_unretained
@ kind_unsafe_unretained
Definition: DeclObjCCommon.h:35
clang::extractapi
Definition: API.h:36
clang::extractapi::DeclarationFragmentsBuilder::getFragmentsForObjCInterface
static DeclarationFragments getFragmentsForObjCInterface(const ObjCInterfaceDecl *)
Build DeclarationFragments for an Objective-C interface declaration ObjCInterfaceDecl.
Definition: DeclarationFragments.cpp:548
clang::Selector::getNumArgs
unsigned getNumArgs() const
Definition: IdentifierTable.cpp:492
clang::ObjCPropertyAttribute::kind_null_resettable
@ kind_null_resettable
Definition: DeclObjCCommon.h:39
clang::ObjCMethodDecl::getSelector
Selector getSelector() const
Definition: DeclObjC.h:330
llvm::SmallString< 128 >
clang::extractapi::DeclarationFragments::getFragments
const std::vector< Fragment > & getFragments() const
Definition: DeclarationFragments.h:95
clang::extractapi::DeclarationFragmentsBuilder::getSubHeadingForMacro
static DeclarationFragments getSubHeadingForMacro(StringRef Name)
Build a sub-heading for macro Name.
Definition: DeclarationFragments.cpp:795
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:874
clang::ObjCMethodDecl::getReturnType
QualType getReturnType() const
Definition: DeclObjC.h:332
Category
int Category
Definition: Format.cpp:2580
clang::extractapi::DeclarationFragmentsBuilder::getFragmentsForTypedef
static DeclarationFragments getFragmentsForTypedef(const TypedefNameDecl *Decl)
Build DeclarationFragments for a typedef TypedefNameDecl.
Definition: DeclarationFragments.cpp:729
clang::NestedNameSpecifier::Global
@ Global
The global specifier '::'. There is no stored value.
Definition: NestedNameSpecifier.h:97
clang::SC_Register
@ SC_Register
Definition: Specifiers.h:242
clang::ObjCPropertyAttribute::kind_readonly
@ kind_readonly
Definition: DeclObjCCommon.h:24
clang::EnumConstantDecl
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3077
Base
clang::extractapi::DeclarationFragmentsBuilder::getFragmentsForObjCProtocol
static DeclarationFragments getFragmentsForObjCProtocol(const ObjCProtocolDecl *)
Build DeclarationFragments for an Objective-C protocol declaration ObjCProtocolDecl.
Definition: DeclarationFragments.cpp:700
clang::NestedNameSpecifier::TypeSpecWithTemplate
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
Definition: NestedNameSpecifier.h:94
clang::SC_Static
@ SC_Static
Definition: Specifiers.h:237
clang::ETK_None
@ ETK_None
No keyword precedes the qualified type name.
Definition: Type.h:5483
clang::ObjCCategoryDecl
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2276
clang::extractapi::DeclarationFragmentsBuilder::getFragmentsForVar
static DeclarationFragments getFragmentsForVar(const VarDecl *)
Build DeclarationFragments for a variable declaration VarDecl.
Definition: DeclarationFragments.cpp:353
clang::NestedNameSpecifier::getAsNamespaceAlias
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
Definition: NestedNameSpecifier.cpp:177
clang::NestedNameSpecifier::getAsNamespace
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
Definition: NestedNameSpecifier.cpp:169
clang::syntax::NodeRole::Size
@ Size
clang::ObjCPropertyAttribute::kind_noattr
@ kind_noattr
Definition: DeclObjCCommon.h:23
clang::getNullabilitySpelling
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
Definition: IdentifierTable.cpp:761
clang::NullabilityKind::Unspecified
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
clang::VarDecl::getStorageClass
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1083
clang::extractapi::TypedefUnderlyingTypeResolver::getUSRForType
std::string getUSRForType(QualType Type) const
Get a USR for the given type.
Definition: TypedefUnderlyingTypeResolver.cpp:69
clang::extractapi::DeclarationFragments::FragmentKind::Identifier
@ Identifier
clang::ParmVarDecl::isObjCMethodParameter
bool isObjCMethodParameter() const
Definition: Decl.h:1723
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:796
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::ObjCPropertyDecl
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:732
clang::frontend::After
@ After
Like System, but searched after the system directories.
Definition: HeaderSearchOptions.h:61
clang::ObjCMethodDecl::isInstanceMethod
bool isInstanceMethod() const
Definition: DeclObjC.h:431
USRGeneration.h
clang::extractapi::DeclarationFragments::append
DeclarationFragments & append(StringRef Spelling, FragmentKind Kind, StringRef PreciseIdentifier="")
Append a new Fragment to the end of the Fragments.
Definition: DeclarationFragments.h:101
clang::ObjCPropertyAttribute::kind_assign
@ kind_assign
Definition: DeclObjCCommon.h:26
clang::SC_PrivateExtern
@ SC_PrivateExtern
Definition: Specifiers.h:238
clang::ObjCInterfaceDecl::getSuperClass
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:351
clang::extractapi::DeclarationFragments::FragmentKind::Keyword
@ Keyword
clang::extractapi::DeclarationFragments::FragmentKind::Text
@ Text
clang::ArrayType::Static
@ Static
Definition: Type.h:2962
clang::NamedDecl::getNameAsString
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:290
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::NamespaceDecl::isAnonymousNamespace
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
Definition: Decl.h:596
clang::ObjCMethodDecl
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
clang::ObjCPropertyAttribute::kind_readwrite
@ kind_readwrite
Definition: DeclObjCCommon.h:27
clang::extractapi::DeclarationFragmentsBuilder::getFragmentsForMacro
static DeclarationFragments getFragmentsForMacro(StringRef Name, const MacroDirective *MD)
Build DeclarationFragments for a macro.
Definition: DeclarationFragments.cpp:499
clang::index::generateUSRForDecl
bool generateUSRForDecl(const Decl *D, SmallVectorImpl< char > &Buf)
Generate a USR for a Decl, including the USR prefix.
Definition: USRGeneration.cpp:1088
clang::IdentifierInfo::getName
StringRef getName() const
Return the actual identifier string.
Definition: IdentifierTable.h:195
Text
StringRef Text
Definition: Format.cpp:2578
clang::Selector
Smart pointer class that efficiently represents Objective-C method names.
Definition: IdentifierTable.h:752
clang::extractapi::DeclarationFragments::getFragmentKindString
static StringRef getFragmentKindString(FragmentKind Kind)
Get the string description of a FragmentKind Kind.
Definition: DeclarationFragments.cpp:39
clang::NestedNameSpecifier::getAsType
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
Definition: NestedNameSpecifier.h:196
clang::MacroDirective
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
Definition: MacroInfo.h:314
clang::MacroDirective::getMacroInfo
const MacroInfo * getMacroInfo() const
Definition: MacroInfo.h:414
clang::ComparisonCategoryType::Last
@ Last
clang::extractapi::DeclarationFragmentsBuilder::getFragmentsForEnumConstant
static DeclarationFragments getFragmentsForEnumConstant(const EnumConstantDecl *)
Build DeclarationFragments for an enum constant declaration EnumConstantDecl.
Definition: DeclarationFragments.cpp:446
clang::ObjCPropertyAttribute::kind_nonatomic
@ kind_nonatomic
Definition: DeclObjCCommon.h:30
clang::EnumDecl::getIntegerType
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:3795
clang::ObjCProtocolDecl
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2052
clang::NestedNameSpecifier::getPrefix
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
Definition: NestedNameSpecifier.h:169
clang::extractapi::DeclarationFragments::FragmentKind::None
@ None
Unknown fragment kind.
clang::SC_Auto
@ SC_Auto
Definition: Specifiers.h:241
clang::ObjCSubstitutionContext::Property
@ Property
The type of a property.
clang::extractapi::DeclarationFragmentsBuilder::getFragmentsForObjCCategory
static DeclarationFragments getFragmentsForObjCCategory(const ObjCCategoryDecl *)
Build DeclarationFragments for an Objective-C category declaration ObjCCategoryDecl.
Definition: DeclarationFragments.cpp:529
clang::extractapi::DeclarationFragmentsBuilder::getFragmentsForObjCProperty
static DeclarationFragments getFragmentsForObjCProperty(const ObjCPropertyDecl *)
Build DeclarationFragments for an Objective-C property declaration ObjCPropertyDecl.
Definition: DeclarationFragments.cpp:613
clang::TypedefNameDecl
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3207
clang::extractapi::DeclarationFragmentsBuilder::getFunctionSignature
static FunctionSignature getFunctionSignature(const FunctionT *)
Build FunctionSignature for a function-like declaration FunctionT like FunctionDecl or ObjCMethodDecl...
Definition: DeclarationFragments.cpp:745
clang::ObjCMethodDecl::getParamDecl
ParmVarDecl * getParamDecl(unsigned Idx)
Definition: DeclObjC.h:381
clang::ObjCPropertyAttribute::kind_nullability
@ kind_nullability
Indicates that the nullability of the type was spelled with a property attribute rather than a type q...
Definition: DeclObjCCommon.h:38
clang::extractapi::DeclarationFragments::FragmentKind::GenericParameter
@ GenericParameter
Parameter that's used as generics in the context.
clang::ObjCPropertyAttribute::kind_getter
@ kind_getter
Definition: DeclObjCCommon.h:25
clang::NestedNameSpecifier::TypeSpec
@ TypeSpec
A type, stored as a Type*.
Definition: NestedNameSpecifier.h:90
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:685
clang::SC_None
@ SC_None
Definition: Specifiers.h:235
clang::ObjCProtocolDecl::protocol_iterator
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2114
clang::extractapi::DeclarationFragments::FragmentKind
FragmentKind
The kind of a fragment.
Definition: DeclarationFragments.h:48
clang::extractapi::FunctionSignature::addParameter
FunctionSignature & addParameter(StringRef Name, DeclarationFragments Fragments)
Definition: DeclarationFragments.h:163
clang::NestedNameSpecifier::getKind
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
Definition: NestedNameSpecifier.cpp:143
clang::extractapi::DeclarationFragments::FragmentKind::StringLiteral
@ StringLiteral
clang::ObjCMethodDecl::isClassMethod
bool isClassMethod() const
Definition: DeclObjC.h:439
clang::extractapi::DeclarationFragments::FragmentKind::Attribute
@ Attribute
clang::extractapi::DeclarationFragments::FragmentKind::InternalParam
@ InternalParam
Internal/local parameters in Objective-C methods.
clang::NamespaceDecl
Represent a C++ namespace.
Definition: Decl.h:540
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1872
TypedefUnderlyingTypeResolver.h
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3908
clang::index::generateUSRForType
bool generateUSRForType(QualType T, ASTContext &Ctx, SmallVectorImpl< char > &Buf)
Generates a USR for a type.
Definition: USRGeneration.cpp:1131
clang::FunctionDecl::getStorageClass
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2607
clang::extractapi::DeclarationFragments::parseFragmentKindFromString
static FragmentKind parseFragmentKindFromString(StringRef S)
Get the corresponding FragmentKind from string S.
Definition: DeclarationFragments.cpp:70
clang::ObjCPropertyAttribute::kind_retain
@ kind_retain
Definition: DeclObjCCommon.h:28
clang::extractapi::DeclarationFragmentsBuilder::getFragmentsForFunction
static DeclarationFragments getFragmentsForFunction(const FunctionDecl *)
Build DeclarationFragments for a function declaration FunctionDecl.
Definition: DeclarationFragments.cpp:404
clang::DeclaratorDecl::getTypeSourceInfo
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:755
clang::ObjCMethodDecl::param_size
unsigned param_size() const
Definition: DeclObjC.h:350
clang::ObjCPropertyAttribute::kind_setter
@ kind_setter
Definition: DeclObjCCommon.h:31
Type
MatchType Type
Definition: ASTMatchFinder.cpp:71
clang::StorageClass
StorageClass
Storage classes.
Definition: Specifiers.h:233
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274