File indexing completed on 2026-05-10 08:36:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_CLANG_AST_DECLARATIONNAME_H
0014 #define LLVM_CLANG_AST_DECLARATIONNAME_H
0015
0016 #include "clang/AST/Type.h"
0017 #include "clang/Basic/Diagnostic.h"
0018 #include "clang/Basic/IdentifierTable.h"
0019 #include "clang/Basic/OperatorKinds.h"
0020 #include "clang/Basic/PartialDiagnostic.h"
0021 #include "clang/Basic/SourceLocation.h"
0022 #include "llvm/ADT/DenseMapInfo.h"
0023 #include "llvm/ADT/FoldingSet.h"
0024 #include "llvm/ADT/STLExtras.h"
0025 #include "llvm/Support/Compiler.h"
0026 #include "llvm/Support/type_traits.h"
0027 #include <cassert>
0028 #include <cstdint>
0029 #include <cstring>
0030 #include <string>
0031
0032 namespace clang {
0033
0034 class ASTContext;
0035 template <typename> class CanQual;
0036 class DeclarationName;
0037 class DeclarationNameTable;
0038 struct PrintingPolicy;
0039 class TemplateDecl;
0040 class TypeSourceInfo;
0041
0042 using CanQualType = CanQual<Type>;
0043
0044 namespace detail {
0045
0046
0047
0048
0049
0050
0051
0052 class alignas(IdentifierInfoAlignment) CXXSpecialNameExtra
0053 : public llvm::FoldingSetNode {
0054 friend class clang::DeclarationName;
0055 friend class clang::DeclarationNameTable;
0056
0057
0058 QualType Type;
0059
0060
0061
0062
0063 void *FETokenInfo;
0064
0065 CXXSpecialNameExtra(QualType QT) : Type(QT), FETokenInfo(nullptr) {}
0066
0067 public:
0068 void Profile(llvm::FoldingSetNodeID &ID) {
0069 ID.AddPointer(Type.getAsOpaquePtr());
0070 }
0071 };
0072
0073
0074 class alignas(IdentifierInfoAlignment) CXXDeductionGuideNameExtra
0075 : public detail::DeclarationNameExtra,
0076 public llvm::FoldingSetNode {
0077 friend class clang::DeclarationName;
0078 friend class clang::DeclarationNameTable;
0079
0080
0081 TemplateDecl *Template;
0082
0083
0084
0085
0086 void *FETokenInfo;
0087
0088 CXXDeductionGuideNameExtra(TemplateDecl *TD)
0089 : DeclarationNameExtra(CXXDeductionGuideName), Template(TD),
0090 FETokenInfo(nullptr) {}
0091
0092 public:
0093 void Profile(llvm::FoldingSetNodeID &ID) { ID.AddPointer(Template); }
0094 };
0095
0096
0097
0098
0099
0100 class alignas(IdentifierInfoAlignment) CXXOperatorIdName {
0101 friend class clang::DeclarationName;
0102 friend class clang::DeclarationNameTable;
0103
0104
0105 OverloadedOperatorKind Kind = OO_None;
0106
0107
0108
0109
0110 void *FETokenInfo = nullptr;
0111 };
0112
0113
0114
0115 class alignas(IdentifierInfoAlignment) CXXLiteralOperatorIdName
0116 : public detail::DeclarationNameExtra,
0117 public llvm::FoldingSetNode {
0118 friend class clang::DeclarationName;
0119 friend class clang::DeclarationNameTable;
0120
0121 const IdentifierInfo *ID;
0122
0123
0124
0125
0126 void *FETokenInfo;
0127
0128 CXXLiteralOperatorIdName(const IdentifierInfo *II)
0129 : DeclarationNameExtra(CXXLiteralOperatorName), ID(II),
0130 FETokenInfo(nullptr) {}
0131
0132 public:
0133 void Profile(llvm::FoldingSetNodeID &FSID) { FSID.AddPointer(ID); }
0134 };
0135
0136 }
0137
0138
0139
0140
0141
0142
0143
0144 class DeclarationName {
0145 friend class DeclarationNameTable;
0146 friend class NamedDecl;
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174 enum StoredNameKind {
0175 StoredIdentifier = 0,
0176 StoredObjCZeroArgSelector = Selector::ZeroArg,
0177 StoredObjCOneArgSelector = Selector::OneArg,
0178 StoredCXXConstructorName = 3,
0179 StoredCXXDestructorName = 4,
0180 StoredCXXConversionFunctionName = 5,
0181 StoredCXXOperatorName = 6,
0182 StoredDeclarationNameExtra = Selector::MultiArg,
0183 PtrMask = 7,
0184 UncommonNameKindOffset = 8
0185 };
0186
0187 static_assert(alignof(IdentifierInfo) >= 8 &&
0188 alignof(detail::DeclarationNameExtra) >= 8 &&
0189 alignof(detail::CXXSpecialNameExtra) >= 8 &&
0190 alignof(detail::CXXOperatorIdName) >= 8 &&
0191 alignof(detail::CXXDeductionGuideNameExtra) >= 8 &&
0192 alignof(detail::CXXLiteralOperatorIdName) >= 8,
0193 "The various classes that DeclarationName::Ptr can point to"
0194 " must be at least aligned to 8 bytes!");
0195
0196 static_assert(
0197 std::is_same<std::underlying_type_t<StoredNameKind>,
0198 std::underlying_type_t<
0199 detail::DeclarationNameExtra::ExtraKind>>::value,
0200 "The various enums used to compute values for NameKind should "
0201 "all have the same underlying type");
0202
0203 public:
0204
0205
0206
0207
0208 enum NameKind {
0209 Identifier = StoredIdentifier,
0210 ObjCZeroArgSelector = StoredObjCZeroArgSelector,
0211 ObjCOneArgSelector = StoredObjCOneArgSelector,
0212 CXXConstructorName = StoredCXXConstructorName,
0213 CXXDestructorName = StoredCXXDestructorName,
0214 CXXConversionFunctionName = StoredCXXConversionFunctionName,
0215 CXXOperatorName = StoredCXXOperatorName,
0216 CXXDeductionGuideName = llvm::addEnumValues(
0217 UncommonNameKindOffset,
0218 detail::DeclarationNameExtra::CXXDeductionGuideName),
0219 CXXLiteralOperatorName = llvm::addEnumValues(
0220 UncommonNameKindOffset,
0221 detail::DeclarationNameExtra::CXXLiteralOperatorName),
0222 CXXUsingDirective =
0223 llvm::addEnumValues(UncommonNameKindOffset,
0224 detail::DeclarationNameExtra::CXXUsingDirective),
0225 ObjCMultiArgSelector =
0226 llvm::addEnumValues(UncommonNameKindOffset,
0227 detail::DeclarationNameExtra::ObjCMultiArgSelector),
0228 };
0229
0230 private:
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263 uintptr_t Ptr = 0;
0264
0265 StoredNameKind getStoredNameKind() const {
0266 return static_cast<StoredNameKind>(Ptr & PtrMask);
0267 }
0268
0269 void *getPtr() const { return reinterpret_cast<void *>(Ptr & ~PtrMask); }
0270
0271 void setPtrAndKind(const void *P, StoredNameKind Kind) {
0272 uintptr_t PAsInteger = reinterpret_cast<uintptr_t>(P);
0273 assert((Kind & ~PtrMask) == 0 &&
0274 "Invalid StoredNameKind in setPtrAndKind!");
0275 assert((PAsInteger & PtrMask) == 0 &&
0276 "Improperly aligned pointer in setPtrAndKind!");
0277 Ptr = PAsInteger | Kind;
0278 }
0279
0280
0281 DeclarationName(detail::DeclarationNameExtra *Name) {
0282 setPtrAndKind(Name, StoredDeclarationNameExtra);
0283 }
0284
0285
0286 DeclarationName(detail::CXXSpecialNameExtra *Name,
0287 StoredNameKind StoredKind) {
0288 assert((StoredKind == StoredCXXConstructorName ||
0289 StoredKind == StoredCXXDestructorName ||
0290 StoredKind == StoredCXXConversionFunctionName) &&
0291 "Invalid StoredNameKind when constructing a DeclarationName"
0292 " from a CXXSpecialNameExtra!");
0293 setPtrAndKind(Name, StoredKind);
0294 }
0295
0296
0297 DeclarationName(detail::CXXOperatorIdName *Name) {
0298 setPtrAndKind(Name, StoredCXXOperatorName);
0299 }
0300
0301
0302 IdentifierInfo *castAsIdentifierInfo() const {
0303 assert((getStoredNameKind() == StoredIdentifier) &&
0304 "DeclarationName does not store an IdentifierInfo!");
0305 return static_cast<IdentifierInfo *>(getPtr());
0306 }
0307
0308
0309
0310 detail::DeclarationNameExtra *castAsExtra() const {
0311 assert((getStoredNameKind() == StoredDeclarationNameExtra) &&
0312 "DeclarationName does not store an Extra structure!");
0313 return static_cast<detail::DeclarationNameExtra *>(getPtr());
0314 }
0315
0316
0317
0318 detail::CXXSpecialNameExtra *castAsCXXSpecialNameExtra() const {
0319 assert((getStoredNameKind() == StoredCXXConstructorName ||
0320 getStoredNameKind() == StoredCXXDestructorName ||
0321 getStoredNameKind() == StoredCXXConversionFunctionName) &&
0322 "DeclarationName does not store a CXXSpecialNameExtra!");
0323 return static_cast<detail::CXXSpecialNameExtra *>(getPtr());
0324 }
0325
0326
0327
0328 detail::CXXOperatorIdName *castAsCXXOperatorIdName() const {
0329 assert((getStoredNameKind() == StoredCXXOperatorName) &&
0330 "DeclarationName does not store a CXXOperatorIdName!");
0331 return static_cast<detail::CXXOperatorIdName *>(getPtr());
0332 }
0333
0334
0335
0336 detail::CXXDeductionGuideNameExtra *castAsCXXDeductionGuideNameExtra() const {
0337 assert(getNameKind() == CXXDeductionGuideName &&
0338 "DeclarationName does not store a CXXDeductionGuideNameExtra!");
0339 return static_cast<detail::CXXDeductionGuideNameExtra *>(getPtr());
0340 }
0341
0342
0343
0344 detail::CXXLiteralOperatorIdName *castAsCXXLiteralOperatorIdName() const {
0345 assert(getNameKind() == CXXLiteralOperatorName &&
0346 "DeclarationName does not store a CXXLiteralOperatorIdName!");
0347 return static_cast<detail::CXXLiteralOperatorIdName *>(getPtr());
0348 }
0349
0350
0351
0352 void *getFETokenInfoSlow() const;
0353 void setFETokenInfoSlow(void *T);
0354
0355 public:
0356
0357 DeclarationName() { setPtrAndKind(nullptr, StoredIdentifier); }
0358
0359
0360 DeclarationName(const IdentifierInfo *II) {
0361 setPtrAndKind(II, StoredIdentifier);
0362 }
0363
0364
0365 DeclarationName(Selector Sel)
0366 : Ptr(reinterpret_cast<uintptr_t>(Sel.InfoPtr.getOpaqueValue())) {}
0367
0368
0369 static DeclarationName getUsingDirectiveName() {
0370
0371 static detail::DeclarationNameExtra UDirExtra(
0372 detail::DeclarationNameExtra::CXXUsingDirective);
0373 return DeclarationName(&UDirExtra);
0374 }
0375
0376
0377 explicit operator bool() const {
0378 return getPtr() || (getStoredNameKind() != StoredIdentifier);
0379 }
0380
0381
0382 bool isEmpty() const { return !*this; }
0383
0384
0385 bool isIdentifier() const { return getStoredNameKind() == StoredIdentifier; }
0386 bool isObjCZeroArgSelector() const {
0387 return getStoredNameKind() == StoredObjCZeroArgSelector;
0388 }
0389 bool isObjCOneArgSelector() const {
0390 return getStoredNameKind() == StoredObjCOneArgSelector;
0391 }
0392
0393
0394 NameKind getNameKind() const {
0395
0396
0397 StoredNameKind StoredKind = getStoredNameKind();
0398 if (StoredKind != StoredDeclarationNameExtra)
0399 return static_cast<NameKind>(StoredKind);
0400
0401
0402
0403 unsigned ExtraKind = castAsExtra()->getKind();
0404 return static_cast<NameKind>(UncommonNameKindOffset + ExtraKind);
0405 }
0406
0407
0408
0409
0410
0411
0412
0413 bool isDependentName() const;
0414
0415
0416 std::string getAsString() const;
0417
0418
0419
0420 IdentifierInfo *getAsIdentifierInfo() const {
0421 if (isIdentifier())
0422 return castAsIdentifierInfo();
0423 return nullptr;
0424 }
0425
0426
0427 uintptr_t getAsOpaqueInteger() const { return Ptr; }
0428
0429
0430 void *getAsOpaquePtr() const { return reinterpret_cast<void *>(Ptr); }
0431
0432
0433 static DeclarationName getFromOpaquePtr(void *P) {
0434 DeclarationName N;
0435 N.Ptr = reinterpret_cast<uintptr_t>(P);
0436 return N;
0437 }
0438
0439
0440
0441 static DeclarationName getFromOpaqueInteger(uintptr_t P) {
0442 DeclarationName N;
0443 N.Ptr = P;
0444 return N;
0445 }
0446
0447
0448
0449 QualType getCXXNameType() const {
0450 if (getStoredNameKind() == StoredCXXConstructorName ||
0451 getStoredNameKind() == StoredCXXDestructorName ||
0452 getStoredNameKind() == StoredCXXConversionFunctionName) {
0453 assert(getPtr() && "getCXXNameType on a null DeclarationName!");
0454 return castAsCXXSpecialNameExtra()->Type;
0455 }
0456 return QualType();
0457 }
0458
0459
0460
0461 TemplateDecl *getCXXDeductionGuideTemplate() const {
0462 if (getNameKind() == CXXDeductionGuideName) {
0463 assert(getPtr() &&
0464 "getCXXDeductionGuideTemplate on a null DeclarationName!");
0465 return castAsCXXDeductionGuideNameExtra()->Template;
0466 }
0467 return nullptr;
0468 }
0469
0470
0471
0472 OverloadedOperatorKind getCXXOverloadedOperator() const {
0473 if (getStoredNameKind() == StoredCXXOperatorName) {
0474 assert(getPtr() && "getCXXOverloadedOperator on a null DeclarationName!");
0475 return castAsCXXOperatorIdName()->Kind;
0476 }
0477 return OO_None;
0478 }
0479
0480
0481
0482 const IdentifierInfo *getCXXLiteralIdentifier() const {
0483 if (getNameKind() == CXXLiteralOperatorName) {
0484 assert(getPtr() && "getCXXLiteralIdentifier on a null DeclarationName!");
0485 return castAsCXXLiteralOperatorIdName()->ID;
0486 }
0487 return nullptr;
0488 }
0489
0490
0491 Selector getObjCSelector() const {
0492 assert((getNameKind() == ObjCZeroArgSelector ||
0493 getNameKind() == ObjCOneArgSelector ||
0494 getNameKind() == ObjCMultiArgSelector || !getPtr()) &&
0495 "Not a selector!");
0496 return Selector(Ptr);
0497 }
0498
0499
0500
0501
0502 void *getFETokenInfo() const {
0503 assert(getPtr() && "getFETokenInfo on an empty DeclarationName!");
0504 if (getStoredNameKind() == StoredIdentifier)
0505 return castAsIdentifierInfo()->getFETokenInfo();
0506 return getFETokenInfoSlow();
0507 }
0508
0509 void setFETokenInfo(void *T) {
0510 assert(getPtr() && "setFETokenInfo on an empty DeclarationName!");
0511 if (getStoredNameKind() == StoredIdentifier)
0512 castAsIdentifierInfo()->setFETokenInfo(T);
0513 else
0514 setFETokenInfoSlow(T);
0515 }
0516
0517
0518 friend bool operator==(DeclarationName LHS, DeclarationName RHS) {
0519 return LHS.Ptr == RHS.Ptr;
0520 }
0521
0522
0523 friend bool operator!=(DeclarationName LHS, DeclarationName RHS) {
0524 return LHS.Ptr != RHS.Ptr;
0525 }
0526
0527 static DeclarationName getEmptyMarker() {
0528 DeclarationName Name;
0529 Name.Ptr = uintptr_t(-1);
0530 return Name;
0531 }
0532
0533 static DeclarationName getTombstoneMarker() {
0534 DeclarationName Name;
0535 Name.Ptr = uintptr_t(-2);
0536 return Name;
0537 }
0538
0539 static int compare(DeclarationName LHS, DeclarationName RHS);
0540
0541 void print(raw_ostream &OS, const PrintingPolicy &Policy) const;
0542
0543 void dump() const;
0544 };
0545
0546 raw_ostream &operator<<(raw_ostream &OS, DeclarationName N);
0547
0548
0549
0550 inline bool operator<(DeclarationName LHS, DeclarationName RHS) {
0551 return DeclarationName::compare(LHS, RHS) < 0;
0552 }
0553
0554
0555
0556 inline bool operator>(DeclarationName LHS, DeclarationName RHS) {
0557 return DeclarationName::compare(LHS, RHS) > 0;
0558 }
0559
0560
0561
0562 inline bool operator<=(DeclarationName LHS, DeclarationName RHS) {
0563 return DeclarationName::compare(LHS, RHS) <= 0;
0564 }
0565
0566
0567
0568 inline bool operator>=(DeclarationName LHS, DeclarationName RHS) {
0569 return DeclarationName::compare(LHS, RHS) >= 0;
0570 }
0571
0572
0573
0574
0575
0576
0577 class DeclarationNameTable {
0578
0579 const ASTContext &Ctx;
0580
0581
0582
0583
0584 llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXConstructorNames;
0585
0586
0587
0588
0589 llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXDestructorNames;
0590
0591
0592
0593
0594
0595 llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXConversionFunctionNames;
0596
0597
0598
0599
0600 detail::CXXOperatorIdName CXXOperatorNames[NUM_OVERLOADED_OPERATORS];
0601
0602
0603
0604
0605
0606 llvm::FoldingSet<detail::CXXLiteralOperatorIdName> CXXLiteralOperatorNames;
0607
0608
0609
0610
0611
0612 llvm::FoldingSet<detail::CXXDeductionGuideNameExtra> CXXDeductionGuideNames;
0613
0614 public:
0615 DeclarationNameTable(const ASTContext &C);
0616 DeclarationNameTable(const DeclarationNameTable &) = delete;
0617 DeclarationNameTable &operator=(const DeclarationNameTable &) = delete;
0618 DeclarationNameTable(DeclarationNameTable &&) = delete;
0619 DeclarationNameTable &operator=(DeclarationNameTable &&) = delete;
0620 ~DeclarationNameTable() = default;
0621
0622
0623 DeclarationName getIdentifier(const IdentifierInfo *ID) {
0624 return DeclarationName(ID);
0625 }
0626
0627
0628 DeclarationName getCXXConstructorName(CanQualType Ty);
0629
0630
0631 DeclarationName getCXXDestructorName(CanQualType Ty);
0632
0633
0634 DeclarationName getCXXDeductionGuideName(TemplateDecl *TD);
0635
0636
0637 DeclarationName getCXXConversionFunctionName(CanQualType Ty);
0638
0639
0640
0641
0642
0643
0644
0645 DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind,
0646 CanQualType Ty);
0647
0648
0649 DeclarationName getCXXOperatorName(OverloadedOperatorKind Op) {
0650 return DeclarationName(&CXXOperatorNames[Op]);
0651 }
0652
0653
0654 DeclarationName getCXXLiteralOperatorName(const IdentifierInfo *II);
0655 };
0656
0657
0658
0659
0660 class DeclarationNameLoc {
0661
0662
0663
0664
0665
0666
0667 struct NT {
0668 TypeSourceInfo *TInfo;
0669 };
0670
0671
0672 struct CXXOpName {
0673 SourceLocation::UIntTy BeginOpNameLoc;
0674 SourceLocation::UIntTy EndOpNameLoc;
0675 };
0676
0677
0678 struct CXXLitOpName {
0679 SourceLocation::UIntTy OpNameLoc;
0680 };
0681
0682
0683
0684
0685
0686 union {
0687 struct NT NamedType;
0688 struct CXXOpName CXXOperatorName;
0689 struct CXXLitOpName CXXLiteralOperatorName;
0690 };
0691
0692 void setNamedTypeLoc(TypeSourceInfo *TInfo) { NamedType.TInfo = TInfo; }
0693
0694 void setCXXOperatorNameRange(SourceRange Range) {
0695 CXXOperatorName.BeginOpNameLoc = Range.getBegin().getRawEncoding();
0696 CXXOperatorName.EndOpNameLoc = Range.getEnd().getRawEncoding();
0697 }
0698
0699 void setCXXLiteralOperatorNameLoc(SourceLocation Loc) {
0700 CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding();
0701 }
0702
0703 public:
0704 DeclarationNameLoc(DeclarationName Name);
0705
0706 DeclarationNameLoc() { memset((void*) this, 0, sizeof(*this)); }
0707
0708
0709
0710 TypeSourceInfo *getNamedTypeInfo() const { return NamedType.TInfo; }
0711
0712
0713 SourceLocation getCXXOperatorNameBeginLoc() const {
0714 return SourceLocation::getFromRawEncoding(CXXOperatorName.BeginOpNameLoc);
0715 }
0716
0717
0718 SourceLocation getCXXOperatorNameEndLoc() const {
0719 return SourceLocation::getFromRawEncoding(CXXOperatorName.EndOpNameLoc);
0720 }
0721
0722
0723
0724
0725 SourceRange getCXXOperatorNameRange() const {
0726 return SourceRange(getCXXOperatorNameBeginLoc(),
0727 getCXXOperatorNameEndLoc());
0728 }
0729
0730
0731
0732
0733 SourceLocation getCXXLiteralOperatorNameLoc() const {
0734 return SourceLocation::getFromRawEncoding(CXXLiteralOperatorName.OpNameLoc);
0735 }
0736
0737
0738
0739 static DeclarationNameLoc makeNamedTypeLoc(TypeSourceInfo *TInfo) {
0740 DeclarationNameLoc DNL;
0741 DNL.setNamedTypeLoc(TInfo);
0742 return DNL;
0743 }
0744
0745
0746 static DeclarationNameLoc makeCXXOperatorNameLoc(SourceLocation BeginLoc,
0747 SourceLocation EndLoc) {
0748 return makeCXXOperatorNameLoc(SourceRange(BeginLoc, EndLoc));
0749 }
0750
0751
0752 static DeclarationNameLoc makeCXXOperatorNameLoc(SourceRange Range) {
0753 DeclarationNameLoc DNL;
0754 DNL.setCXXOperatorNameRange(Range);
0755 return DNL;
0756 }
0757
0758
0759 static DeclarationNameLoc makeCXXLiteralOperatorNameLoc(SourceLocation Loc) {
0760 DeclarationNameLoc DNL;
0761 DNL.setCXXLiteralOperatorNameLoc(Loc);
0762 return DNL;
0763 }
0764 };
0765
0766
0767
0768 struct DeclarationNameInfo {
0769 private:
0770
0771 DeclarationName Name;
0772
0773
0774 SourceLocation NameLoc;
0775
0776
0777 DeclarationNameLoc LocInfo;
0778
0779 public:
0780
0781 DeclarationNameInfo() = default;
0782
0783 DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc)
0784 : Name(Name), NameLoc(NameLoc), LocInfo(Name) {}
0785
0786 DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc,
0787 DeclarationNameLoc LocInfo)
0788 : Name(Name), NameLoc(NameLoc), LocInfo(LocInfo) {}
0789
0790
0791 DeclarationName getName() const { return Name; }
0792
0793
0794 void setName(DeclarationName N) { Name = N; }
0795
0796
0797 SourceLocation getLoc() const { return NameLoc; }
0798
0799
0800 void setLoc(SourceLocation L) { NameLoc = L; }
0801
0802 const DeclarationNameLoc &getInfo() const { return LocInfo; }
0803 void setInfo(const DeclarationNameLoc &Info) { LocInfo = Info; }
0804
0805
0806
0807 TypeSourceInfo *getNamedTypeInfo() const {
0808 if (Name.getNameKind() != DeclarationName::CXXConstructorName &&
0809 Name.getNameKind() != DeclarationName::CXXDestructorName &&
0810 Name.getNameKind() != DeclarationName::CXXConversionFunctionName)
0811 return nullptr;
0812 return LocInfo.getNamedTypeInfo();
0813 }
0814
0815
0816
0817 void setNamedTypeInfo(TypeSourceInfo *TInfo) {
0818 assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
0819 Name.getNameKind() == DeclarationName::CXXDestructorName ||
0820 Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
0821 LocInfo = DeclarationNameLoc::makeNamedTypeLoc(TInfo);
0822 }
0823
0824
0825
0826 SourceRange getCXXOperatorNameRange() const {
0827 if (Name.getNameKind() != DeclarationName::CXXOperatorName)
0828 return SourceRange();
0829 return LocInfo.getCXXOperatorNameRange();
0830 }
0831
0832
0833
0834 void setCXXOperatorNameRange(SourceRange R) {
0835 assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
0836 LocInfo = DeclarationNameLoc::makeCXXOperatorNameLoc(R);
0837 }
0838
0839
0840
0841
0842 SourceLocation getCXXLiteralOperatorNameLoc() const {
0843 if (Name.getNameKind() != DeclarationName::CXXLiteralOperatorName)
0844 return SourceLocation();
0845 return LocInfo.getCXXLiteralOperatorNameLoc();
0846 }
0847
0848
0849
0850
0851 void setCXXLiteralOperatorNameLoc(SourceLocation Loc) {
0852 assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
0853 LocInfo = DeclarationNameLoc::makeCXXLiteralOperatorNameLoc(Loc);
0854 }
0855
0856
0857 bool isInstantiationDependent() const;
0858
0859
0860
0861 bool containsUnexpandedParameterPack() const;
0862
0863
0864 std::string getAsString() const;
0865
0866
0867 void printName(raw_ostream &OS, PrintingPolicy Policy) const;
0868
0869
0870 SourceLocation getBeginLoc() const { return NameLoc; }
0871
0872
0873 SourceRange getSourceRange() const LLVM_READONLY {
0874 return SourceRange(getBeginLoc(), getEndLoc());
0875 }
0876
0877 SourceLocation getEndLoc() const LLVM_READONLY {
0878 SourceLocation EndLoc = getEndLocPrivate();
0879 return EndLoc.isValid() ? EndLoc : getBeginLoc();
0880 }
0881
0882 private:
0883 SourceLocation getEndLocPrivate() const;
0884 };
0885
0886
0887
0888 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
0889 DeclarationName N) {
0890 PD.AddTaggedVal(N.getAsOpaqueInteger(),
0891 DiagnosticsEngine::ak_declarationname);
0892 return PD;
0893 }
0894
0895 raw_ostream &operator<<(raw_ostream &OS, DeclarationNameInfo DNInfo);
0896
0897 }
0898
0899 namespace llvm {
0900
0901
0902
0903 template<>
0904 struct DenseMapInfo<clang::DeclarationName> {
0905 static inline clang::DeclarationName getEmptyKey() {
0906 return clang::DeclarationName::getEmptyMarker();
0907 }
0908
0909 static inline clang::DeclarationName getTombstoneKey() {
0910 return clang::DeclarationName::getTombstoneMarker();
0911 }
0912
0913 static unsigned getHashValue(clang::DeclarationName Name) {
0914 return DenseMapInfo<void*>::getHashValue(Name.getAsOpaquePtr());
0915 }
0916
0917 static inline bool
0918 isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS) {
0919 return LHS == RHS;
0920 }
0921 };
0922
0923 template <> struct PointerLikeTypeTraits<clang::DeclarationName> {
0924 static inline void *getAsVoidPointer(clang::DeclarationName P) {
0925 return P.getAsOpaquePtr();
0926 }
0927 static inline clang::DeclarationName getFromVoidPointer(void *P) {
0928 return clang::DeclarationName::getFromOpaquePtr(P);
0929 }
0930 static constexpr int NumLowBitsAvailable = 0;
0931 };
0932
0933 }
0934
0935
0936
0937 namespace clang {
0938
0939
0940
0941 class AssumedTemplateStorage : public UncommonTemplateNameStorage {
0942 friend class ASTContext;
0943
0944 AssumedTemplateStorage(DeclarationName Name)
0945 : UncommonTemplateNameStorage(Assumed, 0, 0), Name(Name) {}
0946 DeclarationName Name;
0947
0948 public:
0949
0950 DeclarationName getDeclName() const { return Name; }
0951 };
0952
0953 }
0954
0955 #endif