clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name MicrosoftMangle.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangAST/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/libclangAST/obj/../include/clang/AST -I /usr/src/gnu/usr.bin/clang/libclangAST/../../../llvm/clang/include -I /usr/src/gnu/usr.bin/clang/libclangAST/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/libclangAST/../include -I /usr/src/gnu/usr.bin/clang/libclangAST/obj -I /usr/src/gnu/usr.bin/clang/libclangAST/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangAST/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -stack-protector 2 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c++ /usr/src/gnu/usr.bin/clang/libclangAST/../../../llvm/clang/lib/AST/MicrosoftMangle.cpp
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #include "clang/AST/ASTContext.h" |
| 14 | #include "clang/AST/Attr.h" |
| 15 | #include "clang/AST/CXXInheritance.h" |
| 16 | #include "clang/AST/CharUnits.h" |
| 17 | #include "clang/AST/Decl.h" |
| 18 | #include "clang/AST/DeclCXX.h" |
| 19 | #include "clang/AST/DeclObjC.h" |
| 20 | #include "clang/AST/DeclOpenMP.h" |
| 21 | #include "clang/AST/DeclTemplate.h" |
| 22 | #include "clang/AST/Expr.h" |
| 23 | #include "clang/AST/ExprCXX.h" |
| 24 | #include "clang/AST/Mangle.h" |
| 25 | #include "clang/AST/VTableBuilder.h" |
| 26 | #include "clang/Basic/ABI.h" |
| 27 | #include "clang/Basic/DiagnosticOptions.h" |
| 28 | #include "clang/Basic/FileManager.h" |
| 29 | #include "clang/Basic/SourceManager.h" |
| 30 | #include "clang/Basic/TargetInfo.h" |
| 31 | #include "llvm/ADT/StringExtras.h" |
| 32 | #include "llvm/Support/CRC.h" |
| 33 | #include "llvm/Support/MD5.h" |
| 34 | #include "llvm/Support/MathExtras.h" |
| 35 | #include "llvm/Support/StringSaver.h" |
| 36 | #include "llvm/Support/xxhash.h" |
| 37 | |
| 38 | using namespace clang; |
| 39 | |
| 40 | namespace { |
| 41 | |
| 42 | struct msvc_hashing_ostream : public llvm::raw_svector_ostream { |
| 43 | raw_ostream &OS; |
| 44 | llvm::SmallString<64> Buffer; |
| 45 | |
| 46 | msvc_hashing_ostream(raw_ostream &OS) |
| 47 | : llvm::raw_svector_ostream(Buffer), OS(OS) {} |
| 48 | ~msvc_hashing_ostream() override { |
| 49 | StringRef MangledName = str(); |
| 50 | bool StartsWithEscape = MangledName.startswith("\01"); |
| 51 | if (StartsWithEscape) |
| 52 | MangledName = MangledName.drop_front(1); |
| 53 | if (MangledName.size() < 4096) { |
| 54 | OS << str(); |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | llvm::MD5 Hasher; |
| 59 | llvm::MD5::MD5Result Hash; |
| 60 | Hasher.update(MangledName); |
| 61 | Hasher.final(Hash); |
| 62 | |
| 63 | SmallString<32> HexString; |
| 64 | llvm::MD5::stringifyResult(Hash, HexString); |
| 65 | |
| 66 | if (StartsWithEscape) |
| 67 | OS << '\01'; |
| 68 | OS << "??@" << HexString << '@'; |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | static const DeclContext * |
| 73 | getLambdaDefaultArgumentDeclContext(const Decl *D) { |
| 74 | if (const auto *RD = dyn_cast<CXXRecordDecl>(D)) |
| 75 | if (RD->isLambda()) |
| 76 | if (const auto *Parm = |
| 77 | dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl())) |
| 78 | return Parm->getDeclContext(); |
| 79 | return nullptr; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | |
| 84 | static const DeclContext *getEffectiveDeclContext(const Decl *D) { |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | if (const auto *LDADC = getLambdaDefaultArgumentDeclContext(D)) |
| 92 | return LDADC; |
| 93 | |
| 94 | |
| 95 | if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) { |
| 96 | if (ParmVarDecl *ContextParam = |
| 97 | dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) |
| 98 | return ContextParam->getDeclContext(); |
| 99 | } |
| 100 | |
| 101 | const DeclContext *DC = D->getDeclContext(); |
| 102 | if (isa<CapturedDecl>(DC) || isa<OMPDeclareReductionDecl>(DC) || |
| 103 | isa<OMPDeclareMapperDecl>(DC)) { |
| 104 | return getEffectiveDeclContext(cast<Decl>(DC)); |
| 105 | } |
| 106 | |
| 107 | return DC->getRedeclContext(); |
| 108 | } |
| 109 | |
| 110 | static const DeclContext *getEffectiveParentContext(const DeclContext *DC) { |
| 111 | return getEffectiveDeclContext(cast<Decl>(DC)); |
| 112 | } |
| 113 | |
| 114 | static const FunctionDecl *getStructor(const NamedDecl *ND) { |
| 115 | if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(ND)) |
| 116 | return FTD->getTemplatedDecl()->getCanonicalDecl(); |
| 117 | |
| 118 | const auto *FD = cast<FunctionDecl>(ND); |
| 119 | if (const auto *FTD = FD->getPrimaryTemplate()) |
| 120 | return FTD->getTemplatedDecl()->getCanonicalDecl(); |
| 121 | |
| 122 | return FD->getCanonicalDecl(); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | |
| 127 | class MicrosoftMangleContextImpl : public MicrosoftMangleContext { |
| 128 | typedef std::pair<const DeclContext *, IdentifierInfo *> DiscriminatorKeyTy; |
| 129 | llvm::DenseMap<DiscriminatorKeyTy, unsigned> Discriminator; |
| 130 | llvm::DenseMap<const NamedDecl *, unsigned> Uniquifier; |
| 131 | llvm::DenseMap<const CXXRecordDecl *, unsigned> LambdaIds; |
| 132 | llvm::DenseMap<const NamedDecl *, unsigned> SEHFilterIds; |
| 133 | llvm::DenseMap<const NamedDecl *, unsigned> SEHFinallyIds; |
| 134 | SmallString<16> AnonymousNamespaceHash; |
| 135 | |
| 136 | public: |
| 137 | MicrosoftMangleContextImpl(ASTContext &Context, DiagnosticsEngine &Diags); |
| 138 | bool shouldMangleCXXName(const NamedDecl *D) override; |
| 139 | bool shouldMangleStringLiteral(const StringLiteral *SL) override; |
| 140 | void mangleCXXName(GlobalDecl GD, raw_ostream &Out) override; |
| 141 | void mangleVirtualMemPtrThunk(const CXXMethodDecl *MD, |
| 142 | const MethodVFTableLocation &ML, |
| 143 | raw_ostream &Out) override; |
| 144 | void mangleThunk(const CXXMethodDecl *MD, const ThunkInfo &Thunk, |
| 145 | raw_ostream &) override; |
| 146 | void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type, |
| 147 | const ThisAdjustment &ThisAdjustment, |
| 148 | raw_ostream &) override; |
| 149 | void mangleCXXVFTable(const CXXRecordDecl *Derived, |
| 150 | ArrayRef<const CXXRecordDecl *> BasePath, |
| 151 | raw_ostream &Out) override; |
| 152 | void mangleCXXVBTable(const CXXRecordDecl *Derived, |
| 153 | ArrayRef<const CXXRecordDecl *> BasePath, |
| 154 | raw_ostream &Out) override; |
| 155 | void mangleCXXVirtualDisplacementMap(const CXXRecordDecl *SrcRD, |
| 156 | const CXXRecordDecl *DstRD, |
| 157 | raw_ostream &Out) override; |
| 158 | void mangleCXXThrowInfo(QualType T, bool IsConst, bool IsVolatile, |
| 159 | bool IsUnaligned, uint32_t NumEntries, |
| 160 | raw_ostream &Out) override; |
| 161 | void mangleCXXCatchableTypeArray(QualType T, uint32_t NumEntries, |
| 162 | raw_ostream &Out) override; |
| 163 | void mangleCXXCatchableType(QualType T, const CXXConstructorDecl *CD, |
| 164 | CXXCtorType CT, uint32_t Size, uint32_t NVOffset, |
| 165 | int32_t VBPtrOffset, uint32_t VBIndex, |
| 166 | raw_ostream &Out) override; |
| 167 | void mangleCXXRTTI(QualType T, raw_ostream &Out) override; |
| 168 | void mangleCXXRTTIName(QualType T, raw_ostream &Out) override; |
| 169 | void mangleCXXRTTIBaseClassDescriptor(const CXXRecordDecl *Derived, |
| 170 | uint32_t NVOffset, int32_t VBPtrOffset, |
| 171 | uint32_t VBTableOffset, uint32_t Flags, |
| 172 | raw_ostream &Out) override; |
| 173 | void mangleCXXRTTIBaseClassArray(const CXXRecordDecl *Derived, |
| 174 | raw_ostream &Out) override; |
| 175 | void mangleCXXRTTIClassHierarchyDescriptor(const CXXRecordDecl *Derived, |
| 176 | raw_ostream &Out) override; |
| 177 | void |
| 178 | mangleCXXRTTICompleteObjectLocator(const CXXRecordDecl *Derived, |
| 179 | ArrayRef<const CXXRecordDecl *> BasePath, |
| 180 | raw_ostream &Out) override; |
| 181 | void mangleTypeName(QualType T, raw_ostream &) override; |
| 182 | void mangleReferenceTemporary(const VarDecl *, unsigned ManglingNumber, |
| 183 | raw_ostream &) override; |
| 184 | void mangleStaticGuardVariable(const VarDecl *D, raw_ostream &Out) override; |
| 185 | void mangleThreadSafeStaticGuardVariable(const VarDecl *D, unsigned GuardNum, |
| 186 | raw_ostream &Out) override; |
| 187 | void mangleDynamicInitializer(const VarDecl *D, raw_ostream &Out) override; |
| 188 | void mangleDynamicAtExitDestructor(const VarDecl *D, |
| 189 | raw_ostream &Out) override; |
| 190 | void mangleSEHFilterExpression(const NamedDecl *EnclosingDecl, |
| 191 | raw_ostream &Out) override; |
| 192 | void mangleSEHFinallyBlock(const NamedDecl *EnclosingDecl, |
| 193 | raw_ostream &Out) override; |
| 194 | void mangleStringLiteral(const StringLiteral *SL, raw_ostream &Out) override; |
| 195 | bool getNextDiscriminator(const NamedDecl *ND, unsigned &disc) { |
| 196 | const DeclContext *DC = getEffectiveDeclContext(ND); |
| 197 | if (!DC->isFunctionOrMethod()) |
| 198 | return false; |
| 199 | |
| 200 | |
| 201 | |
| 202 | if (const auto *RD = dyn_cast<CXXRecordDecl>(ND)) { |
| 203 | if (RD->isLambda()) { |
| 204 | disc = 1; |
| 205 | return true; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | |
| 210 | if (ND->isExternallyVisible()) { |
| 211 | disc = getASTContext().getManglingNumber(ND); |
| 212 | return true; |
| 213 | } |
| 214 | |
| 215 | |
| 216 | if (const TagDecl *Tag = dyn_cast<TagDecl>(ND)) { |
| 217 | if (!Tag->hasNameForLinkage() && |
| 218 | !getASTContext().getDeclaratorForUnnamedTagDecl(Tag) && |
| 219 | !getASTContext().getTypedefNameForUnnamedTagDecl(Tag)) |
| 220 | return false; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | unsigned &discriminator = Uniquifier[ND]; |
| 225 | if (!discriminator) |
| 226 | discriminator = ++Discriminator[std::make_pair(DC, ND->getIdentifier())]; |
| 227 | disc = discriminator + 1; |
| 228 | return true; |
| 229 | } |
| 230 | |
| 231 | std::string getLambdaString(const CXXRecordDecl *Lambda) override { |
| 232 | assert(Lambda->isLambda() && "RD must be a lambda!"); |
| 233 | std::string Name("<lambda_"); |
| 234 | |
| 235 | Decl *LambdaContextDecl = Lambda->getLambdaContextDecl(); |
| 236 | unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber(); |
| 237 | unsigned LambdaId; |
| 238 | const ParmVarDecl *Parm = dyn_cast_or_null<ParmVarDecl>(LambdaContextDecl); |
| 239 | const FunctionDecl *Func = |
| 240 | Parm ? dyn_cast<FunctionDecl>(Parm->getDeclContext()) : nullptr; |
| 241 | |
| 242 | if (Func) { |
| 243 | unsigned DefaultArgNo = |
| 244 | Func->getNumParams() - Parm->getFunctionScopeIndex(); |
| 245 | Name += llvm::utostr(DefaultArgNo); |
| 246 | Name += "_"; |
| 247 | } |
| 248 | |
| 249 | if (LambdaManglingNumber) |
| 250 | LambdaId = LambdaManglingNumber; |
| 251 | else |
| 252 | LambdaId = getLambdaIdForDebugInfo(Lambda); |
| 253 | |
| 254 | Name += llvm::utostr(LambdaId); |
| 255 | Name += ">"; |
| 256 | return Name; |
| 257 | } |
| 258 | |
| 259 | unsigned getLambdaId(const CXXRecordDecl *RD) { |
| 260 | assert(RD->isLambda() && "RD must be a lambda!"); |
| 261 | assert(!RD->isExternallyVisible() && "RD must not be visible!"); |
| 262 | assert(RD->getLambdaManglingNumber() == 0 && |
| 263 | "RD must not have a mangling number!"); |
| 264 | std::pair<llvm::DenseMap<const CXXRecordDecl *, unsigned>::iterator, bool> |
| 265 | Result = LambdaIds.insert(std::make_pair(RD, LambdaIds.size())); |
| 266 | return Result.first->second; |
| 267 | } |
| 268 | |
| 269 | unsigned getLambdaIdForDebugInfo(const CXXRecordDecl *RD) { |
| 270 | assert(RD->isLambda() && "RD must be a lambda!"); |
| 271 | assert(!RD->isExternallyVisible() && "RD must not be visible!"); |
| 272 | assert(RD->getLambdaManglingNumber() == 0 && |
| 273 | "RD must not have a mangling number!"); |
| 274 | llvm::DenseMap<const CXXRecordDecl *, unsigned>::iterator Result = |
| 275 | LambdaIds.find(RD); |
| 276 | |
| 277 | if (Result == LambdaIds.end()) |
| 278 | return 0; |
| 279 | return Result->second; |
| 280 | } |
| 281 | |
| 282 | |
| 283 | |
| 284 | StringRef getAnonymousNamespaceHash() const { |
| 285 | return AnonymousNamespaceHash; |
| 286 | } |
| 287 | |
| 288 | private: |
| 289 | void mangleInitFiniStub(const VarDecl *D, char CharCode, raw_ostream &Out); |
| 290 | }; |
| 291 | |
| 292 | |
| 293 | |
| 294 | class MicrosoftCXXNameMangler { |
| 295 | MicrosoftMangleContextImpl &Context; |
| 296 | raw_ostream &Out; |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | const NamedDecl *Structor; |
| 302 | unsigned StructorType; |
| 303 | |
| 304 | typedef llvm::SmallVector<std::string, 10> BackRefVec; |
| 305 | BackRefVec NameBackReferences; |
| 306 | |
| 307 | typedef llvm::DenseMap<const void *, unsigned> ArgBackRefMap; |
| 308 | ArgBackRefMap FunArgBackReferences; |
| 309 | ArgBackRefMap TemplateArgBackReferences; |
| 310 | |
| 311 | typedef llvm::DenseMap<const void *, StringRef> TemplateArgStringMap; |
| 312 | TemplateArgStringMap TemplateArgStrings; |
| 313 | llvm::StringSaver TemplateArgStringStorage; |
| 314 | llvm::BumpPtrAllocator TemplateArgStringStorageAlloc; |
| 315 | |
| 316 | typedef std::set<std::pair<int, bool>> PassObjectSizeArgsSet; |
| 317 | PassObjectSizeArgsSet PassObjectSizeArgs; |
| 318 | |
| 319 | ASTContext &getASTContext() const { return Context.getASTContext(); } |
| 320 | |
| 321 | const bool PointersAre64Bit; |
| 322 | |
| 323 | public: |
| 324 | enum QualifierMangleMode { QMM_Drop, QMM_Mangle, QMM_Escape, QMM_Result }; |
| 325 | |
| 326 | MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &C, raw_ostream &Out_) |
| 327 | : Context(C), Out(Out_), Structor(nullptr), StructorType(-1), |
| 328 | TemplateArgStringStorage(TemplateArgStringStorageAlloc), |
| 329 | PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) == |
| 330 | 64) {} |
| 331 | |
| 332 | MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &C, raw_ostream &Out_, |
| 333 | const CXXConstructorDecl *D, CXXCtorType Type) |
| 334 | : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), |
| 335 | TemplateArgStringStorage(TemplateArgStringStorageAlloc), |
| 336 | PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) == |
| 337 | 64) {} |
| 338 | |
| 339 | MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &C, raw_ostream &Out_, |
| 340 | const CXXDestructorDecl *D, CXXDtorType Type) |
| 341 | : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), |
| 342 | TemplateArgStringStorage(TemplateArgStringStorageAlloc), |
| 343 | PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) == |
| 344 | 64) {} |
| 345 | |
| 346 | raw_ostream &getStream() const { return Out; } |
| 347 | |
| 348 | void mangle(const NamedDecl *D, StringRef Prefix = "?"); |
| 349 | void mangleName(const NamedDecl *ND); |
| 350 | void mangleFunctionEncoding(const FunctionDecl *FD, bool ShouldMangle); |
| 351 | void mangleVariableEncoding(const VarDecl *VD); |
| 352 | void mangleMemberDataPointer(const CXXRecordDecl *RD, const ValueDecl *VD, |
| 353 | StringRef Prefix = "$"); |
| 354 | void mangleMemberFunctionPointer(const CXXRecordDecl *RD, |
| 355 | const CXXMethodDecl *MD, |
| 356 | StringRef Prefix = "$"); |
| 357 | void mangleVirtualMemPtrThunk(const CXXMethodDecl *MD, |
| 358 | const MethodVFTableLocation &ML); |
| 359 | void mangleNumber(int64_t Number); |
| 360 | void mangleNumber(llvm::APSInt Number); |
| 361 | void mangleFloat(llvm::APFloat Number); |
| 362 | void mangleBits(llvm::APInt Number); |
| 363 | void mangleTagTypeKind(TagTypeKind TK); |
| 364 | void mangleArtificialTagType(TagTypeKind TK, StringRef UnqualifiedName, |
| 365 | ArrayRef<StringRef> NestedNames = None); |
| 366 | void mangleAddressSpaceType(QualType T, Qualifiers Quals, SourceRange Range); |
| 367 | void mangleType(QualType T, SourceRange Range, |
| 368 | QualifierMangleMode QMM = QMM_Mangle); |
| 369 | void mangleFunctionType(const FunctionType *T, |
| 370 | const FunctionDecl *D = nullptr, |
| 371 | bool ForceThisQuals = false, |
| 372 | bool MangleExceptionSpec = true); |
| 373 | void mangleNestedName(const NamedDecl *ND); |
| 374 | |
| 375 | private: |
| 376 | bool isStructorDecl(const NamedDecl *ND) const { |
| 377 | return ND == Structor || getStructor(ND) == Structor; |
| 378 | } |
| 379 | |
| 380 | bool is64BitPointer(Qualifiers Quals) const { |
| 381 | LangAS AddrSpace = Quals.getAddressSpace(); |
| 382 | return AddrSpace == LangAS::ptr64 || |
| 383 | (PointersAre64Bit && !(AddrSpace == LangAS::ptr32_sptr || |
| 384 | AddrSpace == LangAS::ptr32_uptr)); |
| 385 | } |
| 386 | |
| 387 | void mangleUnqualifiedName(const NamedDecl *ND) { |
| 388 | mangleUnqualifiedName(ND, ND->getDeclName()); |
| 389 | } |
| 390 | void mangleUnqualifiedName(const NamedDecl *ND, DeclarationName Name); |
| 391 | void mangleSourceName(StringRef Name); |
| 392 | void mangleOperatorName(OverloadedOperatorKind OO, SourceLocation Loc); |
| 393 | void mangleCXXDtorType(CXXDtorType T); |
| 394 | void mangleQualifiers(Qualifiers Quals, bool IsMember); |
| 395 | void mangleRefQualifier(RefQualifierKind RefQualifier); |
| 396 | void manglePointerCVQualifiers(Qualifiers Quals); |
| 397 | void manglePointerExtQualifiers(Qualifiers Quals, QualType PointeeType); |
| 398 | |
| 399 | void mangleUnscopedTemplateName(const TemplateDecl *ND); |
| 400 | void |
| 401 | mangleTemplateInstantiationName(const TemplateDecl *TD, |
| 402 | const TemplateArgumentList &TemplateArgs); |
| 403 | void mangleObjCMethodName(const ObjCMethodDecl *MD); |
| 404 | |
| 405 | void mangleFunctionArgumentType(QualType T, SourceRange Range); |
| 406 | void manglePassObjectSizeArg(const PassObjectSizeAttr *POSA); |
| 407 | |
| 408 | bool isArtificialTagType(QualType T) const; |
| 409 | |
| 410 | |
| 411 | #define ABSTRACT_TYPE(CLASS, PARENT) |
| 412 | #define NON_CANONICAL_TYPE(CLASS, PARENT) |
| 413 | #define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T, \ |
| 414 | Qualifiers Quals, \ |
| 415 | SourceRange Range); |
| 416 | #include "clang/AST/TypeNodes.inc" |
| 417 | #undef ABSTRACT_TYPE |
| 418 | #undef NON_CANONICAL_TYPE |
| 419 | #undef TYPE |
| 420 | |
| 421 | void mangleType(const TagDecl *TD); |
| 422 | void mangleDecayedArrayType(const ArrayType *T); |
| 423 | void mangleArrayType(const ArrayType *T); |
| 424 | void mangleFunctionClass(const FunctionDecl *FD); |
| 425 | void mangleCallingConvention(CallingConv CC); |
| 426 | void mangleCallingConvention(const FunctionType *T); |
| 427 | void mangleIntegerLiteral(const llvm::APSInt &Number, |
| 428 | const NonTypeTemplateParmDecl *PD = nullptr, |
| 429 | QualType TemplateArgType = QualType()); |
| 430 | void mangleExpression(const Expr *E, const NonTypeTemplateParmDecl *PD); |
| 431 | void mangleThrowSpecification(const FunctionProtoType *T); |
| 432 | |
| 433 | void mangleTemplateArgs(const TemplateDecl *TD, |
| 434 | const TemplateArgumentList &TemplateArgs); |
| 435 | void mangleTemplateArg(const TemplateDecl *TD, const TemplateArgument &TA, |
| 436 | const NamedDecl *Parm); |
| 437 | void mangleTemplateArgValue(QualType T, const APValue &V, |
| 438 | bool WithScalarType = false); |
| 439 | |
| 440 | void mangleObjCProtocol(const ObjCProtocolDecl *PD); |
| 441 | void mangleObjCLifetime(const QualType T, Qualifiers Quals, |
| 442 | SourceRange Range); |
| 443 | void mangleObjCKindOfType(const ObjCObjectType *T, Qualifiers Quals, |
| 444 | SourceRange Range); |
| 445 | }; |
| 446 | } |
| 447 | |
| 448 | MicrosoftMangleContextImpl::MicrosoftMangleContextImpl(ASTContext &Context, |
| 449 | DiagnosticsEngine &Diags) |
| 450 | : MicrosoftMangleContext(Context, Diags) { |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | SourceManager &SM = Context.getSourceManager(); |
| 466 | if (const FileEntry *FE = SM.getFileEntryForID(SM.getMainFileID())) { |
| 467 | |
| 468 | uint32_t TruncatedHash = uint32_t(xxHash64(FE->getName())); |
| 469 | AnonymousNamespaceHash = llvm::utohexstr(TruncatedHash); |
| 470 | } else { |
| 471 | |
| 472 | AnonymousNamespaceHash = "0"; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | bool MicrosoftMangleContextImpl::shouldMangleCXXName(const NamedDecl *D) { |
| 477 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 478 | LanguageLinkage L = FD->getLanguageLinkage(); |
| 479 | |
| 480 | if (FD->hasAttr<OverloadableAttr>()) |
| 481 | return true; |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | if (FD->isMSVCRTEntryPoint()) |
| 493 | return false; |
| 494 | |
| 495 | |
| 496 | |
| 497 | if (!FD->getDeclName().isIdentifier() || L == CXXLanguageLinkage) |
| 498 | return true; |
| 499 | |
| 500 | |
| 501 | if (L == CLanguageLinkage) |
| 502 | return false; |
| 503 | } |
| 504 | |
| 505 | |
| 506 | if (!getASTContext().getLangOpts().CPlusPlus) |
| 507 | return false; |
| 508 | |
| 509 | const VarDecl *VD = dyn_cast<VarDecl>(D); |
| 510 | if (VD && !isa<DecompositionDecl>(D)) { |
| 511 | |
| 512 | if (VD->isExternC()) |
| 513 | return false; |
| 514 | |
| 515 | |
| 516 | const DeclContext *DC = getEffectiveDeclContext(D); |
| 517 | |
| 518 | if (DC->isFunctionOrMethod() && D->hasLinkage()) |
| 519 | while (!DC->isNamespace() && !DC->isTranslationUnit()) |
| 520 | DC = getEffectiveParentContext(DC); |
| 521 | |
| 522 | if (DC->isTranslationUnit() && D->getFormalLinkage() == InternalLinkage && |
| 523 | !isa<VarTemplateSpecializationDecl>(D) && |
| 524 | D->getIdentifier() != nullptr) |
| 525 | return false; |
| 526 | } |
| 527 | |
| 528 | return true; |
| 529 | } |
| 530 | |
| 531 | bool |
| 532 | MicrosoftMangleContextImpl::shouldMangleStringLiteral(const StringLiteral *SL) { |
| 533 | return true; |
| 534 | } |
| 535 | |
| 536 | void MicrosoftCXXNameMangler::mangle(const NamedDecl *D, StringRef Prefix) { |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | Out << Prefix; |
| 545 | mangleName(D); |
| 546 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 547 | mangleFunctionEncoding(FD, Context.shouldMangleDeclName(FD)); |
| 548 | else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) |
| 549 | mangleVariableEncoding(VD); |
| 550 | else if (isa<MSGuidDecl>(D)) |
| 551 | |
| 552 | |
| 553 | Out << "3U__s_GUID@@B"; |
| 554 | else if (isa<TemplateParamObjectDecl>(D)) { |
| 555 | |
| 556 | |
| 557 | } else |
| 558 | llvm_unreachable("Tried to mangle unexpected NamedDecl!"); |
| 559 | } |
| 560 | |
| 561 | void MicrosoftCXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD, |
| 562 | bool ShouldMangle) { |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 | |
| 568 | FD = FD->getFirstDecl(); |
| 569 | |
| 570 | |
| 571 | |
| 572 | const FunctionProtoType *FT = FD->getType()->castAs<FunctionProtoType>(); |
| 573 | |
| 574 | |
| 575 | |
| 576 | |
| 577 | if (ShouldMangle) { |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | if (FD->isExternC() && FD->hasAttr<OverloadableAttr>()) |
| 583 | Out << "$$J0"; |
| 584 | |
| 585 | mangleFunctionClass(FD); |
| 586 | |
| 587 | mangleFunctionType(FT, FD, false, false); |
| 588 | } else { |
| 589 | Out << '9'; |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | void MicrosoftCXXNameMangler::mangleVariableEncoding(const VarDecl *VD) { |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | |
| 599 | |
| 600 | |
| 601 | |
| 602 | if (VD->isStaticDataMember()) { |
| 603 | |
| 604 | switch (VD->getAccess()) { |
| 605 | default: |
| 606 | case AS_private: Out << '0'; break; |
| 607 | case AS_protected: Out << '1'; break; |
| 608 | case AS_public: Out << '2'; break; |
| 609 | } |
| 610 | } |
| 611 | else if (!VD->isStaticLocal()) |
| 612 | Out << '3'; |
| 613 | else |
| 614 | Out << '4'; |
| 615 | |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | SourceRange SR = VD->getSourceRange(); |
| 621 | QualType Ty = VD->getType(); |
| 622 | if (Ty->isPointerType() || Ty->isReferenceType() || |
| 623 | Ty->isMemberPointerType()) { |
| 624 | mangleType(Ty, SR, QMM_Drop); |
| 625 | manglePointerExtQualifiers( |
| 626 | Ty.getDesugaredType(getASTContext()).getLocalQualifiers(), QualType()); |
| 627 | if (const MemberPointerType *MPT = Ty->getAs<MemberPointerType>()) { |
| 628 | mangleQualifiers(MPT->getPointeeType().getQualifiers(), true); |
| 629 | |
| 630 | |
| 631 | mangleName(MPT->getClass()->getAsCXXRecordDecl()); |
| 632 | } else |
| 633 | mangleQualifiers(Ty->getPointeeType().getQualifiers(), false); |
| 634 | } else if (const ArrayType *AT = getASTContext().getAsArrayType(Ty)) { |
| 635 | |
| 636 | mangleDecayedArrayType(AT); |
| 637 | if (AT->getElementType()->isArrayType()) |
| 638 | Out << 'A'; |
| 639 | else |
| 640 | mangleQualifiers(Ty.getQualifiers(), false); |
| 641 | } else { |
| 642 | mangleType(Ty, SR, QMM_Drop); |
| 643 | mangleQualifiers(Ty.getQualifiers(), false); |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | void MicrosoftCXXNameMangler::mangleMemberDataPointer(const CXXRecordDecl *RD, |
| 648 | const ValueDecl *VD, |
| 649 | StringRef Prefix) { |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | int64_t FieldOffset; |
| 655 | int64_t VBTableOffset; |
| 656 | MSInheritanceModel IM = RD->getMSInheritanceModel(); |
| 657 | if (VD) { |
| 658 | FieldOffset = getASTContext().getFieldOffset(VD); |
| 659 | assert(FieldOffset % getASTContext().getCharWidth() == 0 && |
| 660 | "cannot take address of bitfield"); |
| 661 | FieldOffset /= getASTContext().getCharWidth(); |
| 662 | |
| 663 | VBTableOffset = 0; |
| 664 | |
| 665 | if (IM == MSInheritanceModel::Virtual) |
| 666 | FieldOffset -= getASTContext().getOffsetOfBaseWithVBPtr(RD).getQuantity(); |
| 667 | } else { |
| 668 | FieldOffset = RD->nullFieldOffsetIsZero() ? 0 : -1; |
| 669 | |
| 670 | VBTableOffset = -1; |
| 671 | } |
| 672 | |
| 673 | char Code = '\0'; |
| 674 | switch (IM) { |
| 675 | case MSInheritanceModel::Single: Code = '0'; break; |
| 676 | case MSInheritanceModel::Multiple: Code = '0'; break; |
| 677 | case MSInheritanceModel::Virtual: Code = 'F'; break; |
| 678 | case MSInheritanceModel::Unspecified: Code = 'G'; break; |
| 679 | } |
| 680 | |
| 681 | Out << Prefix << Code; |
| 682 | |
| 683 | mangleNumber(FieldOffset); |
| 684 | |
| 685 | |
| 686 | |
| 687 | |
| 688 | if (inheritanceModelHasVBPtrOffsetField(IM)) |
| 689 | mangleNumber(0); |
| 690 | if (inheritanceModelHasVBTableOffsetField(IM)) |
| 691 | mangleNumber(VBTableOffset); |
| 692 | } |
| 693 | |
| 694 | void |
| 695 | MicrosoftCXXNameMangler::mangleMemberFunctionPointer(const CXXRecordDecl *RD, |
| 696 | const CXXMethodDecl *MD, |
| 697 | StringRef Prefix) { |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | MSInheritanceModel IM = RD->getMSInheritanceModel(); |
| 704 | |
| 705 | char Code = '\0'; |
| 706 | switch (IM) { |
| 707 | case MSInheritanceModel::Single: Code = '1'; break; |
| 708 | case MSInheritanceModel::Multiple: Code = 'H'; break; |
| 709 | case MSInheritanceModel::Virtual: Code = 'I'; break; |
| 710 | case MSInheritanceModel::Unspecified: Code = 'J'; break; |
| 711 | } |
| 712 | |
| 713 | |
| 714 | |
| 715 | uint64_t NVOffset = 0; |
| 716 | uint64_t VBTableOffset = 0; |
| 717 | uint64_t VBPtrOffset = 0; |
| 718 | if (MD) { |
| 719 | Out << Prefix << Code << '?'; |
| 720 | if (MD->isVirtual()) { |
| 721 | MicrosoftVTableContext *VTContext = |
| 722 | cast<MicrosoftVTableContext>(getASTContext().getVTableContext()); |
| 723 | MethodVFTableLocation ML = |
| 724 | VTContext->getMethodVFTableLocation(GlobalDecl(MD)); |
| 725 | mangleVirtualMemPtrThunk(MD, ML); |
| 726 | NVOffset = ML.VFPtrOffset.getQuantity(); |
| 727 | VBTableOffset = ML.VBTableIndex * 4; |
| 728 | if (ML.VBase) { |
| 729 | const ASTRecordLayout &Layout = getASTContext().getASTRecordLayout(RD); |
| 730 | VBPtrOffset = Layout.getVBPtrOffset().getQuantity(); |
| 731 | } |
| 732 | } else { |
| 733 | mangleName(MD); |
| 734 | mangleFunctionEncoding(MD, true); |
| 735 | } |
| 736 | |
| 737 | if (VBTableOffset == 0 && IM == MSInheritanceModel::Virtual) |
| 738 | NVOffset -= getASTContext().getOffsetOfBaseWithVBPtr(RD).getQuantity(); |
| 739 | } else { |
| 740 | |
| 741 | if (IM == MSInheritanceModel::Single) { |
| 742 | Out << Prefix << "0A@"; |
| 743 | return; |
| 744 | } |
| 745 | if (IM == MSInheritanceModel::Unspecified) |
| 746 | VBTableOffset = -1; |
| 747 | Out << Prefix << Code; |
| 748 | } |
| 749 | |
| 750 | if (inheritanceModelHasNVOffsetField(true, IM)) |
| 751 | mangleNumber(static_cast<uint32_t>(NVOffset)); |
| 752 | if (inheritanceModelHasVBPtrOffsetField(IM)) |
| 753 | mangleNumber(VBPtrOffset); |
| 754 | if (inheritanceModelHasVBTableOffsetField(IM)) |
| 755 | mangleNumber(VBTableOffset); |
| 756 | } |
| 757 | |
| 758 | void MicrosoftCXXNameMangler::mangleVirtualMemPtrThunk( |
| 759 | const CXXMethodDecl *MD, const MethodVFTableLocation &ML) { |
| 760 | |
| 761 | CharUnits PointerWidth = getASTContext().toCharUnitsFromBits( |
| 762 | getASTContext().getTargetInfo().getPointerWidth(0)); |
| 763 | uint64_t OffsetInVFTable = ML.Index * PointerWidth.getQuantity(); |
| 764 | |
| 765 | Out << "?_9"; |
| 766 | mangleName(MD->getParent()); |
| 767 | Out << "$B"; |
| 768 | mangleNumber(OffsetInVFTable); |
| 769 | Out << 'A'; |
| 770 | mangleCallingConvention(MD->getType()->castAs<FunctionProtoType>()); |
| 771 | } |
| 772 | |
| 773 | void MicrosoftCXXNameMangler::mangleName(const NamedDecl *ND) { |
| 774 | |
| 775 | |
| 776 | |
| 777 | mangleUnqualifiedName(ND); |
| 778 | |
| 779 | mangleNestedName(ND); |
| 780 | |
| 781 | |
| 782 | Out << '@'; |
| 783 | } |
| 784 | |
| 785 | void MicrosoftCXXNameMangler::mangleNumber(int64_t Number) { |
| 786 | mangleNumber(llvm::APSInt(llvm::APInt(64, Number), false)); |
| 787 | } |
| 788 | |
| 789 | void MicrosoftCXXNameMangler::mangleNumber(llvm::APSInt Number) { |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | llvm::APInt Value = |
| 795 | Number.isSigned() ? Number.sextOrSelf(64) : Number.zextOrSelf(64); |
| 796 | |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | if (Value.isNegative()) { |
| 804 | Value = -Value; |
| 805 | Out << '?'; |
| 806 | } |
| 807 | mangleBits(Value); |
| 808 | } |
| 809 | |
| 810 | void MicrosoftCXXNameMangler::mangleFloat(llvm::APFloat Number) { |
| 811 | using llvm::APFloat; |
| 812 | |
| 813 | switch (APFloat::SemanticsToEnum(Number.getSemantics())) { |
| 814 | case APFloat::S_IEEEsingle: Out << 'A'; break; |
| 815 | case APFloat::S_IEEEdouble: Out << 'B'; break; |
| 816 | |
| 817 | |
| 818 | |
| 819 | case APFloat::S_IEEEhalf: Out << 'V'; break; |
| 820 | case APFloat::S_BFloat: Out << 'W'; break; |
| 821 | case APFloat::S_x87DoubleExtended: Out << 'X'; break; |
| 822 | case APFloat::S_IEEEquad: Out << 'Y'; break; |
| 823 | case APFloat::S_PPCDoubleDouble: Out << 'Z'; break; |
| 824 | } |
| 825 | |
| 826 | mangleBits(Number.bitcastToAPInt()); |
| 827 | } |
| 828 | |
| 829 | void MicrosoftCXXNameMangler::mangleBits(llvm::APInt Value) { |
| 830 | if (Value == 0) |
| 831 | Out << "A@"; |
| 832 | else if (Value.uge(1) && Value.ule(10)) |
| 833 | Out << (Value - 1); |
| 834 | else { |
| 835 | |
| 836 | |
| 837 | |
| 838 | llvm::SmallString<32> EncodedNumberBuffer; |
| 839 | for (; Value != 0; Value.lshrInPlace(4)) |
| 840 | EncodedNumberBuffer.push_back('A' + (Value & 0xf).getZExtValue()); |
| 841 | std::reverse(EncodedNumberBuffer.begin(), EncodedNumberBuffer.end()); |
| 842 | Out.write(EncodedNumberBuffer.data(), EncodedNumberBuffer.size()); |
| 843 | Out << '@'; |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | static const TemplateDecl * |
| 848 | isTemplate(const NamedDecl *ND, const TemplateArgumentList *&TemplateArgs) { |
| 849 | |
| 850 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) { |
| 851 | if (const TemplateDecl *TD = FD->getPrimaryTemplate()) { |
| 852 | TemplateArgs = FD->getTemplateSpecializationArgs(); |
| 853 | return TD; |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | |
| 858 | if (const ClassTemplateSpecializationDecl *Spec = |
| 859 | dyn_cast<ClassTemplateSpecializationDecl>(ND)) { |
| 860 | TemplateArgs = &Spec->getTemplateArgs(); |
| 861 | return Spec->getSpecializedTemplate(); |
| 862 | } |
| 863 | |
| 864 | |
| 865 | if (const VarTemplateSpecializationDecl *Spec = |
| 866 | dyn_cast<VarTemplateSpecializationDecl>(ND)) { |
| 867 | TemplateArgs = &Spec->getTemplateArgs(); |
| 868 | return Spec->getSpecializedTemplate(); |
| 869 | } |
| 870 | |
| 871 | return nullptr; |
| 872 | } |
| 873 | |
| 874 | void MicrosoftCXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, |
| 875 | DeclarationName Name) { |
| 876 | |
| 877 | |
| 878 | |
| 879 | |
| 880 | |
| 881 | |
| 882 | const TemplateArgumentList *TemplateArgs = nullptr; |
| 883 | if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { |
| 884 | |
| 885 | |
| 886 | |
| 887 | if (isa<FunctionTemplateDecl>(TD)) { |
| 888 | mangleTemplateInstantiationName(TD, *TemplateArgs); |
| 889 | Out << '@'; |
| 890 | return; |
| 891 | } |
| 892 | |
| 893 | |
| 894 | |
| 895 | |
| 896 | |
| 897 | |
| 898 | |
| 899 | |
| 900 | |
| 901 | |
| 902 | |
| 903 | |
| 904 | |
| 905 | |
| 906 | |
| 907 | |
| 908 | |
| 909 | |
| 910 | |
| 911 | ArgBackRefMap::iterator Found = TemplateArgBackReferences.find(ND); |
| 912 | if (Found == TemplateArgBackReferences.end()) { |
| 913 | |
| 914 | TemplateArgStringMap::iterator Found = TemplateArgStrings.find(ND); |
| 915 | if (Found == TemplateArgStrings.end()) { |
| 916 | |
| 917 | llvm::SmallString<64> TemplateMangling; |
| 918 | llvm::raw_svector_ostream Stream(TemplateMangling); |
| 919 | MicrosoftCXXNameMangler Extra(Context, Stream); |
| 920 | Extra.mangleTemplateInstantiationName(TD, *TemplateArgs); |
| 921 | |
| 922 | |
| 923 | mangleSourceName(TemplateMangling); |
| 924 | |
| 925 | |
| 926 | |
| 927 | BackRefVec::iterator StringFound = |
| 928 | llvm::find(NameBackReferences, TemplateMangling); |
| 929 | if (StringFound != NameBackReferences.end()) { |
| 930 | TemplateArgBackReferences[ND] = |
| 931 | StringFound - NameBackReferences.begin(); |
| 932 | } else { |
| 933 | TemplateArgStrings[ND] = |
| 934 | TemplateArgStringStorage.save(TemplateMangling.str()); |
| 935 | } |
| 936 | } else { |
| 937 | Out << Found->second << '@'; |
| 938 | } |
| 939 | } else { |
| 940 | Out << Found->second; |
| 941 | } |
| 942 | return; |
| 943 | } |
| 944 | |
| 945 | switch (Name.getNameKind()) { |
| 946 | case DeclarationName::Identifier: { |
| 947 | if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) { |
| 948 | mangleSourceName(II->getName()); |
| 949 | break; |
| 950 | } |
| 951 | |
| 952 | |
| 953 | assert(ND && "mangling empty name without declaration"); |
| 954 | |
| 955 | if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) { |
| 956 | if (NS->isAnonymousNamespace()) { |
| 957 | Out << "?A0x" << Context.getAnonymousNamespaceHash() << '@'; |
| 958 | break; |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | if (const DecompositionDecl *DD = dyn_cast<DecompositionDecl>(ND)) { |
| 963 | |
| 964 | |
| 965 | llvm::SmallString<64> Name("$S"); |
| 966 | |
| 967 | Name += llvm::utostr(Context.getAnonymousStructId(DD) + 1); |
| 968 | mangleSourceName(Name); |
| 969 | break; |
| 970 | } |
| 971 | |
| 972 | if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) { |
| 973 | |
| 974 | const CXXRecordDecl *RD = VD->getType()->getAsCXXRecordDecl(); |
| 975 | assert(RD && "expected variable decl to have a record type"); |
| 976 | |
| 977 | |
| 978 | |
| 979 | llvm::SmallString<64> Name("$S"); |
| 980 | |
| 981 | Name += llvm::utostr(Context.getAnonymousStructId(RD) + 1); |
| 982 | mangleSourceName(Name.str()); |
| 983 | break; |
| 984 | } |
| 985 | |
| 986 | if (const MSGuidDecl *GD = dyn_cast<MSGuidDecl>(ND)) { |
| 987 | |
| 988 | |
| 989 | SmallString<sizeof("_GUID_12345678_1234_1234_1234_1234567890ab")> GUID; |
| 990 | llvm::raw_svector_ostream GUIDOS(GUID); |
| 991 | Context.mangleMSGuidDecl(GD, GUIDOS); |
| 992 | mangleSourceName(GUID); |
| 993 | break; |
| 994 | } |
| 995 | |
| 996 | if (const auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) { |
| 997 | Out << "?__N"; |
| 998 | mangleTemplateArgValue(TPO->getType().getUnqualifiedType(), |
| 999 | TPO->getValue()); |
| 1000 | break; |
| 1001 | } |
| 1002 | |
| 1003 | |
| 1004 | const TagDecl *TD = cast<TagDecl>(ND); |
| 1005 | if (const TypedefNameDecl *D = TD->getTypedefNameForAnonDecl()) { |
| 1006 | assert(TD->getDeclContext() == D->getDeclContext() && |
| 1007 | "Typedef should not be in another decl context!"); |
| 1008 | assert(D->getDeclName().getAsIdentifierInfo() && |
| 1009 | "Typedef was not named!"); |
| 1010 | mangleSourceName(D->getDeclName().getAsIdentifierInfo()->getName()); |
| 1011 | break; |
| 1012 | } |
| 1013 | |
| 1014 | if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(TD)) { |
| 1015 | if (Record->isLambda()) { |
| 1016 | llvm::SmallString<10> Name("<lambda_"); |
| 1017 | |
| 1018 | Decl *LambdaContextDecl = Record->getLambdaContextDecl(); |
| 1019 | unsigned LambdaManglingNumber = Record->getLambdaManglingNumber(); |
| 1020 | unsigned LambdaId; |
| 1021 | const ParmVarDecl *Parm = |
| 1022 | dyn_cast_or_null<ParmVarDecl>(LambdaContextDecl); |
| 1023 | const FunctionDecl *Func = |
| 1024 | Parm ? dyn_cast<FunctionDecl>(Parm->getDeclContext()) : nullptr; |
| 1025 | |
| 1026 | if (Func) { |
| 1027 | unsigned DefaultArgNo = |
| 1028 | Func->getNumParams() - Parm->getFunctionScopeIndex(); |
| 1029 | Name += llvm::utostr(DefaultArgNo); |
| 1030 | Name += "_"; |
| 1031 | } |
| 1032 | |
| 1033 | if (LambdaManglingNumber) |
| 1034 | LambdaId = LambdaManglingNumber; |
| 1035 | else |
| 1036 | LambdaId = Context.getLambdaId(Record); |
| 1037 | |
| 1038 | Name += llvm::utostr(LambdaId); |
| 1039 | Name += ">"; |
| 1040 | |
| 1041 | mangleSourceName(Name); |
| 1042 | |
| 1043 | |
| 1044 | |
| 1045 | if (LambdaManglingNumber && LambdaContextDecl) { |
| 1046 | if ((isa<VarDecl>(LambdaContextDecl) || |
| 1047 | isa<FieldDecl>(LambdaContextDecl)) && |
| 1048 | !isa<ParmVarDecl>(LambdaContextDecl)) { |
| 1049 | mangleUnqualifiedName(cast<NamedDecl>(LambdaContextDecl)); |
| 1050 | } |
| 1051 | } |
| 1052 | break; |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | llvm::SmallString<64> Name; |
| 1057 | if (DeclaratorDecl *DD = |
| 1058 | Context.getASTContext().getDeclaratorForUnnamedTagDecl(TD)) { |
| 1059 | |
| 1060 | |
| 1061 | Name += "<unnamed-type-"; |
| 1062 | Name += DD->getName(); |
| 1063 | } else if (TypedefNameDecl *TND = |
| 1064 | Context.getASTContext().getTypedefNameForUnnamedTagDecl( |
| 1065 | TD)) { |
| 1066 | |
| 1067 | |
| 1068 | Name += "<unnamed-type-"; |
| 1069 | Name += TND->getName(); |
| 1070 | } else if (isa<EnumDecl>(TD) && |
| 1071 | cast<EnumDecl>(TD)->enumerator_begin() != |
| 1072 | cast<EnumDecl>(TD)->enumerator_end()) { |
| 1073 | |
| 1074 | auto *ED = cast<EnumDecl>(TD); |
| 1075 | Name += "<unnamed-enum-"; |
| 1076 | Name += ED->enumerator_begin()->getName(); |
| 1077 | } else { |
| 1078 | |
| 1079 | Name += "<unnamed-type-$S"; |
| 1080 | Name += llvm::utostr(Context.getAnonymousStructId(TD) + 1); |
| 1081 | } |
| 1082 | Name += ">"; |
| 1083 | mangleSourceName(Name.str()); |
| 1084 | break; |
| 1085 | } |
| 1086 | |
| 1087 | case DeclarationName::ObjCZeroArgSelector: |
| 1088 | case DeclarationName::ObjCOneArgSelector: |
| 1089 | case DeclarationName::ObjCMultiArgSelector: { |
| 1090 | |
| 1091 | |
| 1092 | |
| 1093 | llvm::SmallString<64> Name; |
| 1094 | mangleSourceName(Name.str()); |
| 1095 | break; |
| 1096 | } |
| 1097 | |
| 1098 | case DeclarationName::CXXConstructorName: |
| 1099 | if (isStructorDecl(ND)) { |
| 1100 | if (StructorType == Ctor_CopyingClosure) { |
| 1101 | Out << "?_O"; |
| 1102 | return; |
| 1103 | } |
| 1104 | if (StructorType == Ctor_DefaultClosure) { |
| 1105 | Out << "?_F"; |
| 1106 | return; |
| 1107 | } |
| 1108 | } |
| 1109 | Out << "?0"; |
| 1110 | return; |
| 1111 | |
| 1112 | case DeclarationName::CXXDestructorName: |
| 1113 | if (isStructorDecl(ND)) |
| 1114 | |
| 1115 | |
| 1116 | mangleCXXDtorType(static_cast<CXXDtorType>(StructorType)); |
| 1117 | else |
| 1118 | |
| 1119 | |
| 1120 | mangleCXXDtorType(Dtor_Base); |
| 1121 | break; |
| 1122 | |
| 1123 | case DeclarationName::CXXConversionFunctionName: |
| 1124 | |
| 1125 | |
| 1126 | Out << "?B"; |
| 1127 | break; |
| 1128 | |
| 1129 | case DeclarationName::CXXOperatorName: |
| 1130 | mangleOperatorName(Name.getCXXOverloadedOperator(), ND->getLocation()); |
| 1131 | break; |
| 1132 | |
| 1133 | case DeclarationName::CXXLiteralOperatorName: { |
| 1134 | Out << "?__K"; |
| 1135 | mangleSourceName(Name.getCXXLiteralIdentifier()->getName()); |
| 1136 | break; |
| 1137 | } |
| 1138 | |
| 1139 | case DeclarationName::CXXDeductionGuideName: |
| 1140 | llvm_unreachable("Can't mangle a deduction guide name!"); |
| 1141 | |
| 1142 | case DeclarationName::CXXUsingDirective: |
| 1143 | llvm_unreachable("Can't mangle a using directive name!"); |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | |
| 1148 | |
| 1149 | void MicrosoftCXXNameMangler::mangleNestedName(const NamedDecl *ND) { |
| 1150 | const DeclContext *DC = getEffectiveDeclContext(ND); |
| 1151 | while (!DC->isTranslationUnit()) { |
| 1152 | if (isa<TagDecl>(ND) || isa<VarDecl>(ND)) { |
| 1153 | unsigned Disc; |
| 1154 | if (Context.getNextDiscriminator(ND, Disc)) { |
| 1155 | Out << '?'; |
| 1156 | mangleNumber(Disc); |
| 1157 | Out << '?'; |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) { |
| 1162 | auto Discriminate = |
| 1163 | [](StringRef Name, const unsigned Discriminator, |
| 1164 | const unsigned ParameterDiscriminator) -> std::string { |
| 1165 | std::string Buffer; |
| 1166 | llvm::raw_string_ostream Stream(Buffer); |
| 1167 | Stream << Name; |
| 1168 | if (Discriminator) |
| 1169 | Stream << '_' << Discriminator; |
| 1170 | if (ParameterDiscriminator) |
| 1171 | Stream << '_' << ParameterDiscriminator; |
| 1172 | return Stream.str(); |
| 1173 | }; |
| 1174 | |
| 1175 | unsigned Discriminator = BD->getBlockManglingNumber(); |
| 1176 | if (!Discriminator) |
| 1177 | Discriminator = Context.getBlockId(BD, false); |
| 1178 | |
| 1179 | |
| 1180 | |
| 1181 | |
| 1182 | unsigned ParameterDiscriminator = 0; |
| 1183 | if (const auto *MC = BD->getBlockManglingContextDecl()) |
| 1184 | if (const auto *P = dyn_cast<ParmVarDecl>(MC)) |
| 1185 | if (const auto *F = dyn_cast<FunctionDecl>(P->getDeclContext())) |
| 1186 | ParameterDiscriminator = |
| 1187 | F->getNumParams() - P->getFunctionScopeIndex(); |
| 1188 | |
| 1189 | DC = getEffectiveDeclContext(BD); |
| 1190 | |
| 1191 | Out << '?'; |
| 1192 | mangleSourceName(Discriminate("_block_invoke", Discriminator, |
| 1193 | ParameterDiscriminator)); |
| 1194 | |
| 1195 | |
| 1196 | |
| 1197 | |
| 1198 | if (const auto *MC = BD->getBlockManglingContextDecl()) |
| 1199 | if (!isa<ParmVarDecl>(MC)) |
| 1200 | if (const auto *ND = dyn_cast<NamedDecl>(MC)) |
| 1201 | mangleUnqualifiedName(ND); |
| 1202 | |
| 1203 | |
| 1204 | |
| 1205 | if (const auto *RD = dyn_cast<RecordDecl>(DC)) |
| 1206 | mangleName(RD); |
| 1207 | else |
| 1208 | Out << '@'; |
| 1209 | |
| 1210 | Out << "YAX"; |
| 1211 | |
| 1212 | Out << 'P'; |
| 1213 | |
| 1214 | if (PointersAre64Bit) |
| 1215 | Out << 'E'; |
| 1216 | Out << 'A'; |
| 1217 | mangleArtificialTagType(TTK_Struct, |
| 1218 | Discriminate("__block_literal", Discriminator, |
| 1219 | ParameterDiscriminator)); |
| 1220 | Out << "@Z"; |
| 1221 | |
| 1222 | |
| 1223 | |
| 1224 | if (isa<RecordDecl>(DC)) |
| 1225 | break; |
| 1226 | continue; |
| 1227 | } else if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(DC)) { |
| 1228 | mangleObjCMethodName(Method); |
| 1229 | } else if (isa<NamedDecl>(DC)) { |
| 1230 | ND = cast<NamedDecl>(DC); |
| 1231 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) { |
| 1232 | mangle(FD, "?"); |
| 1233 | break; |
| 1234 | } else { |
| 1235 | mangleUnqualifiedName(ND); |
| 1236 | |
| 1237 | |
| 1238 | if (const auto *LDADC = getLambdaDefaultArgumentDeclContext(ND)) { |
| 1239 | DC = LDADC; |
| 1240 | continue; |
| 1241 | } |
| 1242 | } |
| 1243 | } |
| 1244 | DC = DC->getParent(); |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | void MicrosoftCXXNameMangler::mangleCXXDtorType(CXXDtorType T) { |
| 1249 | |
| 1250 | |
| 1251 | |
| 1252 | switch (T) { |
| 1253 | |
| 1254 | case Dtor_Base: Out << "?1"; return; |
| 1255 | |
| 1256 | case Dtor_Complete: Out << "?_D"; return; |
| 1257 | |
| 1258 | case Dtor_Deleting: Out << "?_G"; return; |
| 1259 | |
| 1260 | |
| 1261 | |
| 1262 | case Dtor_Comdat: |
| 1263 | llvm_unreachable("not expecting a COMDAT"); |
| 1264 | } |
| 1265 | llvm_unreachable("Unsupported dtor type?"); |
| 1266 | } |
| 1267 | |
| 1268 | void MicrosoftCXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO, |
| 1269 | SourceLocation Loc) { |
| 1270 | switch (OO) { |
| 1271 | |
| 1272 | |
| 1273 | |
| 1274 | case OO_New: Out << "?2"; break; |
| 1275 | |
| 1276 | case OO_Delete: Out << "?3"; break; |
| 1277 | |
| 1278 | case OO_Equal: Out << "?4"; break; |
| 1279 | |
| 1280 | case OO_GreaterGreater: Out << "?5"; break; |
| 1281 | |
| 1282 | case OO_LessLess: Out << "?6"; break; |
| 1283 | |
| 1284 | case OO_Exclaim: Out << "?7"; break; |
| 1285 | |
| 1286 | case OO_EqualEqual: Out << "?8"; break; |
| 1287 | |
| 1288 | case OO_ExclaimEqual: Out << "?9"; break; |
| 1289 | |
| 1290 | case OO_Subscript: Out << "?A"; break; |
| 1291 | |
| 1292 | |
| 1293 | case OO_Arrow: Out << "?C"; break; |
| 1294 | |
| 1295 | case OO_Star: Out << "?D"; break; |
| 1296 | |
| 1297 | case OO_PlusPlus: Out << "?E"; break; |
| 1298 | |
| 1299 | case OO_MinusMinus: Out << "?F"; break; |
| 1300 | |
| 1301 | case OO_Minus: Out << "?G"; break; |
| 1302 | |
| 1303 | case OO_Plus: Out << "?H"; break; |
| 1304 | |
| 1305 | case OO_Amp: Out << "?I"; break; |
| 1306 | |
| 1307 | case OO_ArrowStar: Out << "?J"; break; |
| 1308 | |
| 1309 | case OO_Slash: Out << "?K"; break; |
| 1310 | |
| 1311 | case OO_Percent: Out << "?L"; break; |
| 1312 | |
| 1313 | case OO_Less: Out << "?M"; break; |
| 1314 | |
| 1315 | case OO_LessEqual: Out << "?N"; break; |
| 1316 | |
| 1317 | case OO_Greater: Out << "?O"; break; |
| 1318 | |
| 1319 | case OO_GreaterEqual: Out << "?P"; break; |
| 1320 | |
| 1321 | case OO_Comma: Out << "?Q"; break; |
| 1322 | |
| 1323 | case OO_Call: Out << "?R"; break; |
| 1324 | |
| 1325 | case OO_Tilde: Out << "?S"; break; |
| 1326 | |
| 1327 | case OO_Caret: Out << "?T"; break; |
| 1328 | |
| 1329 | case OO_Pipe: Out << "?U"; break; |
| 1330 | |
| 1331 | case OO_AmpAmp: Out << "?V"; break; |
| 1332 | |
| 1333 | case OO_PipePipe: Out << "?W"; break; |
| 1334 | |
| 1335 | case OO_StarEqual: Out << "?X"; break; |
| 1336 | |
| 1337 | case OO_PlusEqual: Out << "?Y"; break; |
| 1338 | |
| 1339 | case OO_MinusEqual: Out << "?Z"; break; |
| 1340 | |
| 1341 | case OO_SlashEqual: Out << "?_0"; break; |
| 1342 | |
| 1343 | case OO_PercentEqual: Out << "?_1"; break; |
| 1344 | |
| 1345 | case OO_GreaterGreaterEqual: Out << "?_2"; break; |
| 1346 | |
| 1347 | case OO_LessLessEqual: Out << "?_3"; break; |
| 1348 | |
| 1349 | case OO_AmpEqual: Out << "?_4"; break; |
| 1350 | |
| 1351 | case OO_PipeEqual: Out << "?_5"; break; |
| 1352 | |
| 1353 | case OO_CaretEqual: Out << "?_6"; break; |
| 1354 | |
| 1355 | |
| 1356 | |
| 1357 | |
| 1358 | |
| 1359 | |
| 1360 | |
| 1361 | |
| 1362 | |
| 1363 | |
| 1364 | |
| 1365 | |
| 1366 | |
| 1367 | |
| 1368 | |
| 1369 | |
| 1370 | |
| 1371 | |
| 1372 | |
| 1373 | |
| 1374 | |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | |
| 1379 | |
| 1380 | |
| 1381 | |
| 1382 | case OO_Array_New: Out << "?_U"; break; |
| 1383 | |
| 1384 | case OO_Array_Delete: Out << "?_V"; break; |
| 1385 | |
| 1386 | case OO_Coawait: Out << "?__L"; break; |
| 1387 | |
| 1388 | case OO_Spaceship: Out << "?__M"; break; |
| 1389 | |
| 1390 | case OO_Conditional: { |
| 1391 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1392 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1393 | "cannot mangle this conditional operator yet"); |
| 1394 | Diags.Report(Loc, DiagID); |
| 1395 | break; |
| 1396 | } |
| 1397 | |
| 1398 | case OO_None: |
| 1399 | case NUM_OVERLOADED_OPERATORS: |
| 1400 | llvm_unreachable("Not an overloaded operator"); |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | void MicrosoftCXXNameMangler::mangleSourceName(StringRef Name) { |
| 1405 | |
| 1406 | BackRefVec::iterator Found = llvm::find(NameBackReferences, Name); |
| 1407 | if (Found == NameBackReferences.end()) { |
| 1408 | if (NameBackReferences.size() < 10) |
| 1409 | NameBackReferences.push_back(std::string(Name)); |
| 1410 | Out << Name << '@'; |
| 1411 | } else { |
| 1412 | Out << (Found - NameBackReferences.begin()); |
| 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | void MicrosoftCXXNameMangler::mangleObjCMethodName(const ObjCMethodDecl *MD) { |
| 1417 | Context.mangleObjCMethodNameAsSourceName(MD, Out); |
| 1418 | } |
| 1419 | |
| 1420 | void MicrosoftCXXNameMangler::mangleTemplateInstantiationName( |
| 1421 | const TemplateDecl *TD, const TemplateArgumentList &TemplateArgs) { |
| 1422 | |
| 1423 | |
| 1424 | |
| 1425 | |
| 1426 | |
| 1427 | ArgBackRefMap OuterFunArgsContext; |
| 1428 | ArgBackRefMap OuterTemplateArgsContext; |
| 1429 | BackRefVec OuterTemplateContext; |
| 1430 | PassObjectSizeArgsSet OuterPassObjectSizeArgs; |
| 1431 | NameBackReferences.swap(OuterTemplateContext); |
| 1432 | FunArgBackReferences.swap(OuterFunArgsContext); |
| 1433 | TemplateArgBackReferences.swap(OuterTemplateArgsContext); |
| 1434 | PassObjectSizeArgs.swap(OuterPassObjectSizeArgs); |
| 1435 | |
| 1436 | mangleUnscopedTemplateName(TD); |
| 1437 | mangleTemplateArgs(TD, TemplateArgs); |
| 1438 | |
| 1439 | |
| 1440 | NameBackReferences.swap(OuterTemplateContext); |
| 1441 | FunArgBackReferences.swap(OuterFunArgsContext); |
| 1442 | TemplateArgBackReferences.swap(OuterTemplateArgsContext); |
| 1443 | PassObjectSizeArgs.swap(OuterPassObjectSizeArgs); |
| 1444 | } |
| 1445 | |
| 1446 | void |
| 1447 | MicrosoftCXXNameMangler::mangleUnscopedTemplateName(const TemplateDecl *TD) { |
| 1448 | |
| 1449 | Out << "?$"; |
| 1450 | mangleUnqualifiedName(TD); |
| 1451 | } |
| 1452 | |
| 1453 | void MicrosoftCXXNameMangler::mangleIntegerLiteral( |
| 1454 | const llvm::APSInt &Value, const NonTypeTemplateParmDecl *PD, |
| 1455 | QualType TemplateArgType) { |
| 1456 | |
| 1457 | Out << "$"; |
| 1458 | |
| 1459 | |
| 1460 | |
| 1461 | if (getASTContext().getLangOpts().isCompatibleWithMSVC( |
| 1462 | LangOptions::MSVC2019) && |
| 1463 | PD && PD->getType()->getTypeClass() == Type::Auto && |
| 1464 | !TemplateArgType.isNull()) { |
| 1465 | Out << "M"; |
| 1466 | mangleType(TemplateArgType, SourceRange(), QMM_Drop); |
| 1467 | } |
| 1468 | |
| 1469 | Out << "0"; |
| 1470 | |
| 1471 | mangleNumber(Value); |
| 1472 | } |
| 1473 | |
| 1474 | void MicrosoftCXXNameMangler::mangleExpression( |
| 1475 | const Expr *E, const NonTypeTemplateParmDecl *PD) { |
| 1476 | |
| 1477 | if (Optional<llvm::APSInt> Value = |
| 1478 | E->getIntegerConstantExpr(Context.getASTContext())) { |
| 1479 | mangleIntegerLiteral(*Value, PD, E->getType()); |
| 1480 | return; |
| 1481 | } |
| 1482 | |
| 1483 | |
| 1484 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1485 | unsigned DiagID = Diags.getCustomDiagID( |
| 1486 | DiagnosticsEngine::Error, "cannot yet mangle expression type %0"); |
| 1487 | Diags.Report(E->getExprLoc(), DiagID) << E->getStmtClassName() |
| 1488 | << E->getSourceRange(); |
| 1489 | } |
| 1490 | |
| 1491 | void MicrosoftCXXNameMangler::mangleTemplateArgs( |
| 1492 | const TemplateDecl *TD, const TemplateArgumentList &TemplateArgs) { |
| 1493 | |
| 1494 | const TemplateParameterList *TPL = TD->getTemplateParameters(); |
| 1495 | assert(TPL->size() == TemplateArgs.size() && |
| 1496 | "size mismatch between args and parms!"); |
| 1497 | |
| 1498 | for (size_t i = 0; i < TemplateArgs.size(); ++i) { |
| 1499 | const TemplateArgument &TA = TemplateArgs[i]; |
| 1500 | |
| 1501 | |
| 1502 | if (i > 0 && TA.getKind() == TemplateArgument::Pack && |
| 1503 | TemplateArgs[i - 1].getKind() == TemplateArgument::Pack) |
| 1504 | Out << "$$Z"; |
| 1505 | |
| 1506 | mangleTemplateArg(TD, TA, TPL->getParam(i)); |
| 1507 | } |
| 1508 | } |
| 1509 | |
| 1510 | void MicrosoftCXXNameMangler::mangleTemplateArg(const TemplateDecl *TD, |
| 1511 | const TemplateArgument &TA, |
| 1512 | const NamedDecl *Parm) { |
| 1513 | |
| 1514 | |
| 1515 | |
| 1516 | |
| 1517 | |
| 1518 | |
| 1519 | |
| 1520 | |
| 1521 | |
| 1522 | |
| 1523 | |
| 1524 | |
| 1525 | |
| 1526 | |
| 1527 | |
| 1528 | |
| 1529 | |
| 1530 | |
| 1531 | |
| 1532 | |
| 1533 | |
| 1534 | |
| 1535 | |
| 1536 | |
| 1537 | |
| 1538 | |
| 1539 | |
| 1540 | |
| 1541 | |
| 1542 | |
| 1543 | |
| 1544 | |
| 1545 | |
| 1546 | switch (TA.getKind()) { |
| 1547 | case TemplateArgument::Null: |
| 1548 | llvm_unreachable("Can't mangle null template arguments!"); |
| 1549 | case TemplateArgument::TemplateExpansion: |
| 1550 | llvm_unreachable("Can't mangle template expansion arguments!"); |
| 1551 | case TemplateArgument::Type: { |
| 1552 | QualType T = TA.getAsType(); |
| 1553 | mangleType(T, SourceRange(), QMM_Escape); |
| 1554 | break; |
| 1555 | } |
| 1556 | case TemplateArgument::Declaration: { |
| 1557 | const NamedDecl *ND = TA.getAsDecl(); |
| 1558 | if (isa<FieldDecl>(ND) || isa<IndirectFieldDecl>(ND)) { |
| 1559 | mangleMemberDataPointer(cast<CXXRecordDecl>(ND->getDeclContext()) |
| 1560 | ->getMostRecentNonInjectedDecl(), |
| 1561 | cast<ValueDecl>(ND)); |
| 1562 | } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) { |
| 1563 | const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD); |
| 1564 | if (MD && MD->isInstance()) { |
| 1565 | mangleMemberFunctionPointer( |
| 1566 | MD->getParent()->getMostRecentNonInjectedDecl(), MD); |
| 1567 | } else { |
| 1568 | Out << "$1?"; |
| 1569 | mangleName(FD); |
| 1570 | mangleFunctionEncoding(FD, true); |
| 1571 | } |
| 1572 | } else if (TA.getParamTypeForDecl()->isRecordType()) { |
| 1573 | Out << "$"; |
| 1574 | auto *TPO = cast<TemplateParamObjectDecl>(ND); |
| 1575 | mangleTemplateArgValue(TPO->getType().getUnqualifiedType(), |
| 1576 | TPO->getValue()); |
| 1577 | } else { |
| 1578 | mangle(ND, TA.getParamTypeForDecl()->isReferenceType() ? "$E?" : "$1?"); |
| 1579 | } |
| 1580 | break; |
| 1581 | } |
| 1582 | case TemplateArgument::Integral: { |
| 1583 | QualType T = TA.getIntegralType(); |
| 1584 | mangleIntegerLiteral(TA.getAsIntegral(), |
| 1585 | cast<NonTypeTemplateParmDecl>(Parm), T); |
| 1586 | break; |
| 1587 | } |
| 1588 | case TemplateArgument::NullPtr: { |
| 1589 | QualType T = TA.getNullPtrType(); |
| 1590 | if (const MemberPointerType *MPT = T->getAs<MemberPointerType>()) { |
| 1591 | const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl(); |
| 1592 | if (MPT->isMemberFunctionPointerType() && |
| 1593 | !isa<FunctionTemplateDecl>(TD)) { |
| 1594 | mangleMemberFunctionPointer(RD, nullptr); |
| 1595 | return; |
| 1596 | } |
| 1597 | if (MPT->isMemberDataPointer()) { |
| 1598 | if (!isa<FunctionTemplateDecl>(TD)) { |
| 1599 | mangleMemberDataPointer(RD, nullptr); |
| 1600 | return; |
| 1601 | } |
| 1602 | |
| 1603 | |
| 1604 | |
| 1605 | |
| 1606 | |
| 1607 | |
| 1608 | if (!RD->nullFieldOffsetIsZero()) { |
| 1609 | mangleIntegerLiteral(llvm::APSInt::get(-1), |
| 1610 | cast<NonTypeTemplateParmDecl>(Parm), T); |
| 1611 | return; |
| 1612 | } |
| 1613 | } |
| 1614 | } |
| 1615 | mangleIntegerLiteral(llvm::APSInt::getUnsigned(0), |
| 1616 | cast<NonTypeTemplateParmDecl>(Parm), T); |
| 1617 | break; |
| 1618 | } |
| 1619 | case TemplateArgument::Expression: |
| 1620 | mangleExpression(TA.getAsExpr(), cast<NonTypeTemplateParmDecl>(Parm)); |
| 1621 | break; |
| 1622 | case TemplateArgument::Pack: { |
| 1623 | ArrayRef<TemplateArgument> TemplateArgs = TA.getPackAsArray(); |
| 1624 | if (TemplateArgs.empty()) { |
| 1625 | if (isa<TemplateTypeParmDecl>(Parm) || |
| 1626 | isa<TemplateTemplateParmDecl>(Parm)) |
| 1627 | |
| 1628 | |
| 1629 | Out << (Context.getASTContext().getLangOpts().isCompatibleWithMSVC( |
| 1630 | LangOptions::MSVC2015) |
| 1631 | ? "$$V" |
| 1632 | : "$$$V"); |
| 1633 | else if (isa<NonTypeTemplateParmDecl>(Parm)) |
| 1634 | Out << "$S"; |
| 1635 | else |
| 1636 | llvm_unreachable("unexpected template parameter decl!"); |
| 1637 | } else { |
| 1638 | for (const TemplateArgument &PA : TemplateArgs) |
| 1639 | mangleTemplateArg(TD, PA, Parm); |
| 1640 | } |
| 1641 | break; |
| 1642 | } |
| 1643 | case TemplateArgument::Template: { |
| 1644 | const NamedDecl *ND = |
| 1645 | TA.getAsTemplate().getAsTemplateDecl()->getTemplatedDecl(); |
| 1646 | if (const auto *TD = dyn_cast<TagDecl>(ND)) { |
| 1647 | mangleType(TD); |
| 1648 | } else if (isa<TypeAliasDecl>(ND)) { |
| 1649 | Out << "$$Y"; |
| 1650 | mangleName(ND); |
| 1651 | } else { |
| 1652 | llvm_unreachable("unexpected template template NamedDecl!"); |
| 1653 | } |
| 1654 | break; |
| 1655 | } |
| 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | void MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T, |
| 1660 | const APValue &V, |
| 1661 | bool WithScalarType) { |
| 1662 | switch (V.getKind()) { |
| 1663 | case APValue::None: |
| 1664 | case APValue::Indeterminate: |
| 1665 | |
| 1666 | |
| 1667 | if (WithScalarType) |
| 1668 | mangleType(T, SourceRange(), QMM_Escape); |
| 1669 | Out << '@'; |
| 1670 | return; |
| 1671 | |
| 1672 | case APValue::Int: |
| 1673 | if (WithScalarType) |
| 1674 | mangleType(T, SourceRange(), QMM_Escape); |
| 1675 | Out << '0'; |
| 1676 | mangleNumber(V.getInt()); |
| 1677 | return; |
| 1678 | |
| 1679 | case APValue::Float: |
| 1680 | if (WithScalarType) |
| 1681 | mangleType(T, SourceRange(), QMM_Escape); |
| 1682 | mangleFloat(V.getFloat()); |
| 1683 | return; |
| 1684 | |
| 1685 | case APValue::LValue: { |
| 1686 | if (WithScalarType) |
| 1687 | mangleType(T, SourceRange(), QMM_Escape); |
| 1688 | |
| 1689 | |
| 1690 | if (V.isLValueOnePastTheEnd()) |
| 1691 | break; |
| 1692 | |
| 1693 | APValue::LValueBase Base = V.getLValueBase(); |
| 1694 | if (!V.hasLValuePath() || V.getLValuePath().empty()) { |
| 1695 | |
| 1696 | if (Base.isNull()) { |
| 1697 | |
| 1698 | |
| 1699 | |
| 1700 | |
| 1701 | Out << "0"; |
| 1702 | mangleNumber(V.getLValueOffset().getQuantity()); |
| 1703 | } else if (!V.hasLValuePath()) { |
| 1704 | |
| 1705 | break; |
| 1706 | } else if (auto *VD = Base.dyn_cast<const ValueDecl*>()) { |
| 1707 | Out << (T->isReferenceType() ? "E" : "1"); |
| 1708 | mangle(VD); |
| 1709 | } else { |
| 1710 | break; |
| 1711 | } |
| 1712 | } else { |
| 1713 | unsigned NumAts = 0; |
| 1714 | if (T->isPointerType()) { |
| 1715 | Out << "5"; |
| 1716 | ++NumAts; |
| 1717 | } |
| 1718 | |
| 1719 | QualType T = Base.getType(); |
| 1720 | for (APValue::LValuePathEntry E : V.getLValuePath()) { |
| 1721 | |
| 1722 | if (T->isArrayType()) |
| 1723 | goto mangling_unknown; |
| 1724 | |
| 1725 | const Decl *D = E.getAsBaseOrMember().getPointer(); |
| 1726 | auto *FD = dyn_cast<FieldDecl>(D); |
| 1727 | |
| 1728 | if (!FD) |
| 1729 | goto mangling_unknown; |
| 1730 | |
| 1731 | Out << "6"; |
| 1732 | ++NumAts; |
| 1733 | T = FD->getType(); |
| 1734 | } |
| 1735 | |
| 1736 | auto *VD = Base.dyn_cast<const ValueDecl*>(); |
| 1737 | if (!VD) |
| 1738 | break; |
| 1739 | Out << "E"; |
| 1740 | mangle(VD); |
| 1741 | |
| 1742 | for (APValue::LValuePathEntry E : V.getLValuePath()) { |
| 1743 | const Decl *D = E.getAsBaseOrMember().getPointer(); |
| 1744 | mangleUnqualifiedName(cast<FieldDecl>(D)); |
| 1745 | } |
| 1746 | for (unsigned I = 0; I != NumAts; ++I) |
| 1747 | Out << '@'; |
| 1748 | } |
| 1749 | |
| 1750 | return; |
| 1751 | } |
| 1752 | |
| 1753 | case APValue::MemberPointer: { |
| 1754 | if (WithScalarType) |
| 1755 | mangleType(T, SourceRange(), QMM_Escape); |
| 1756 | |
| 1757 | |
| 1758 | |
| 1759 | |
| 1760 | |
| 1761 | if (!V.getMemberPointerPath().empty()) |
| 1762 | break; |
| 1763 | |
| 1764 | const CXXRecordDecl *RD = |
| 1765 | T->castAs<MemberPointerType>()->getMostRecentCXXRecordDecl(); |
| 1766 | const ValueDecl *D = V.getMemberPointerDecl(); |
| 1767 | if (T->isMemberDataPointerType()) |
| 1768 | mangleMemberDataPointer(RD, D, ""); |
| 1769 | else |
| 1770 | mangleMemberFunctionPointer(RD, cast_or_null<CXXMethodDecl>(D), ""); |
| 1771 | return; |
| 1772 | } |
| 1773 | |
| 1774 | case APValue::Struct: { |
| 1775 | Out << '2'; |
| 1776 | mangleType(T, SourceRange(), QMM_Escape); |
| 1777 | const CXXRecordDecl *RD = T->getAsCXXRecordDecl(); |
| 1778 | assert(RD && "unexpected type for record value"); |
| 1779 | |
| 1780 | unsigned BaseIndex = 0; |
| 1781 | for (const CXXBaseSpecifier &B : RD->bases()) |
| 1782 | mangleTemplateArgValue(B.getType(), V.getStructBase(BaseIndex++)); |
| 1783 | for (const FieldDecl *FD : RD->fields()) |
| 1784 | if (!FD->isUnnamedBitfield()) |
| 1785 | mangleTemplateArgValue(FD->getType(), |
| 1786 | V.getStructField(FD->getFieldIndex()), |
| 1787 | true); |
| 1788 | Out << '@'; |
| 1789 | return; |
| 1790 | } |
| 1791 | |
| 1792 | case APValue::Union: |
| 1793 | Out << '7'; |
| 1794 | mangleType(T, SourceRange(), QMM_Escape); |
| 1795 | if (const FieldDecl *FD = V.getUnionField()) { |
| 1796 | mangleUnqualifiedName(FD); |
| 1797 | mangleTemplateArgValue(FD->getType(), V.getUnionValue()); |
| 1798 | } |
| 1799 | Out << '@'; |
| 1800 | return; |
| 1801 | |
| 1802 | case APValue::ComplexInt: |
| 1803 | |
| 1804 | Out << '2'; |
| 1805 | mangleType(T, SourceRange(), QMM_Escape); |
| 1806 | Out << '0'; |
| 1807 | mangleNumber(V.getComplexIntReal()); |
| 1808 | Out << '0'; |
| 1809 | mangleNumber(V.getComplexIntImag()); |
| 1810 | Out << '@'; |
| 1811 | return; |
| 1812 | |
| 1813 | case APValue::ComplexFloat: |
| 1814 | Out << '2'; |
| 1815 | mangleType(T, SourceRange(), QMM_Escape); |
| 1816 | mangleFloat(V.getComplexFloatReal()); |
| 1817 | mangleFloat(V.getComplexFloatImag()); |
| 1818 | Out << '@'; |
| 1819 | return; |
| 1820 | |
| 1821 | case APValue::Array: { |
| 1822 | Out << '3'; |
| 1823 | QualType ElemT = getASTContext().getAsArrayType(T)->getElementType(); |
| 1824 | mangleType(ElemT, SourceRange(), QMM_Escape); |
| 1825 | for (unsigned I = 0, N = V.getArraySize(); I != N; ++I) { |
| 1826 | const APValue &ElemV = I < V.getArrayInitializedElts() |
| 1827 | ? V.getArrayInitializedElt(I) |
| 1828 | : V.getArrayFiller(); |
| 1829 | mangleTemplateArgValue(ElemT, ElemV); |
| 1830 | Out << '@'; |
| 1831 | } |
| 1832 | Out << '@'; |
| 1833 | return; |
| 1834 | } |
| 1835 | |
| 1836 | case APValue::Vector: { |
| 1837 | |
| 1838 | |
| 1839 | Out << '2'; |
| 1840 | mangleType(T, SourceRange(), QMM_Escape); |
| 1841 | Out << '3'; |
| 1842 | QualType ElemT = T->castAs<VectorType>()->getElementType(); |
| 1843 | mangleType(ElemT, SourceRange(), QMM_Escape); |
| 1844 | for (unsigned I = 0, N = V.getVectorLength(); I != N; ++I) { |
| 1845 | const APValue &ElemV = V.getVectorElt(I); |
| 1846 | mangleTemplateArgValue(ElemT, ElemV); |
| 1847 | Out << '@'; |
| 1848 | } |
| 1849 | Out << "@@"; |
| 1850 | return; |
| 1851 | } |
| 1852 | |
| 1853 | case APValue::AddrLabelDiff: |
| 1854 | case APValue::FixedPoint: |
| 1855 | break; |
| 1856 | } |
| 1857 | |
| 1858 | mangling_unknown: |
| 1859 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1860 | unsigned DiagID = Diags.getCustomDiagID( |
| 1861 | DiagnosticsEngine::Error, "cannot mangle this template argument yet"); |
| 1862 | Diags.Report(DiagID); |
| 1863 | } |
| 1864 | |
| 1865 | void MicrosoftCXXNameMangler::mangleObjCProtocol(const ObjCProtocolDecl *PD) { |
| 1866 | llvm::SmallString<64> TemplateMangling; |
| 1867 | llvm::raw_svector_ostream Stream(TemplateMangling); |
| 1868 | MicrosoftCXXNameMangler Extra(Context, Stream); |
| 1869 | |
| 1870 | Stream << "?$"; |
| 1871 | Extra.mangleSourceName("Protocol"); |
| 1872 | Extra.mangleArtificialTagType(TTK_Struct, PD->getName()); |
| 1873 | |
| 1874 | mangleArtificialTagType(TTK_Struct, TemplateMangling, {"__ObjC"}); |
| 1875 | } |
| 1876 | |
| 1877 | void MicrosoftCXXNameMangler::mangleObjCLifetime(const QualType Type, |
| 1878 | Qualifiers Quals, |
| 1879 | SourceRange Range) { |
| 1880 | llvm::SmallString<64> TemplateMangling; |
| 1881 | llvm::raw_svector_ostream Stream(TemplateMangling); |
| 1882 | MicrosoftCXXNameMangler Extra(Context, Stream); |
| 1883 | |
| 1884 | Stream << "?$"; |
| 1885 | switch (Quals.getObjCLifetime()) { |
| 1886 | case Qualifiers::OCL_None: |
| 1887 | case Qualifiers::OCL_ExplicitNone: |
| 1888 | break; |
| 1889 | case Qualifiers::OCL_Autoreleasing: |
| 1890 | Extra.mangleSourceName("Autoreleasing"); |
| 1891 | break; |
| 1892 | case Qualifiers::OCL_Strong: |
| 1893 | Extra.mangleSourceName("Strong"); |
| 1894 | break; |
| 1895 | case Qualifiers::OCL_Weak: |
| 1896 | Extra.mangleSourceName("Weak"); |
| 1897 | break; |
| 1898 | } |
| 1899 | Extra.manglePointerCVQualifiers(Quals); |
| 1900 | Extra.manglePointerExtQualifiers(Quals, Type); |
| 1901 | Extra.mangleType(Type, Range); |
| 1902 | |
| 1903 | mangleArtificialTagType(TTK_Struct, TemplateMangling, {"__ObjC"}); |
| 1904 | } |
| 1905 | |
| 1906 | void MicrosoftCXXNameMangler::mangleObjCKindOfType(const ObjCObjectType *T, |
| 1907 | Qualifiers Quals, |
| 1908 | SourceRange Range) { |
| 1909 | llvm::SmallString<64> TemplateMangling; |
| 1910 | llvm::raw_svector_ostream Stream(TemplateMangling); |
| 1911 | MicrosoftCXXNameMangler Extra(Context, Stream); |
| 1912 | |
| 1913 | Stream << "?$"; |
| 1914 | Extra.mangleSourceName("KindOf"); |
| 1915 | Extra.mangleType(QualType(T, 0) |
| 1916 | .stripObjCKindOfType(getASTContext()) |
| 1917 | ->getAs<ObjCObjectType>(), |
| 1918 | Quals, Range); |
| 1919 | |
| 1920 | mangleArtificialTagType(TTK_Struct, TemplateMangling, {"__ObjC"}); |
| 1921 | } |
| 1922 | |
| 1923 | void MicrosoftCXXNameMangler::mangleQualifiers(Qualifiers Quals, |
| 1924 | bool IsMember) { |
| 1925 | |
| 1926 | |
| 1927 | |
| 1928 | |
| 1929 | |
| 1930 | |
| 1931 | |
| 1932 | |
| 1933 | |
| 1934 | |
| 1935 | |
| 1936 | |
| 1937 | |
| 1938 | |
| 1939 | |
| 1940 | |
| 1941 | |
| 1942 | |
| 1943 | |
| 1944 | |
| 1945 | |
| 1946 | |
| 1947 | |
| 1948 | |
| 1949 | |
| 1950 | |
| 1951 | |
| 1952 | |
| 1953 | |
| 1954 | |
| 1955 | |
| 1956 | |
| 1957 | |
| 1958 | |
| 1959 | |
| 1960 | |
| 1961 | |
| 1962 | |
| 1963 | |
| 1964 | |
| 1965 | |
| 1966 | |
| 1967 | |
| 1968 | |
| 1969 | |
| 1970 | |
| 1971 | |
| 1972 | |
| 1973 | |
| 1974 | |
| 1975 | |
| 1976 | |
| 1977 | bool HasConst = Quals.hasConst(), |
| 1978 | HasVolatile = Quals.hasVolatile(); |
| 1979 | |
| 1980 | if (!IsMember) { |
| 1981 | if (HasConst && HasVolatile) { |
| 1982 | Out << 'D'; |
| 1983 | } else if (HasVolatile) { |
| 1984 | Out << 'C'; |
| 1985 | } else if (HasConst) { |
| 1986 | Out << 'B'; |
| 1987 | } else { |
| 1988 | Out << 'A'; |
| 1989 | } |
| 1990 | } else { |
| 1991 | if (HasConst && HasVolatile) { |
| 1992 | Out << 'T'; |
| 1993 | } else if (HasVolatile) { |
| 1994 | Out << 'S'; |
| 1995 | } else if (HasConst) { |
| 1996 | Out << 'R'; |
| 1997 | } else { |
| 1998 | Out << 'Q'; |
| 1999 | } |
| 2000 | } |
| 2001 | |
| 2002 | |
| 2003 | } |
| 2004 | |
| 2005 | void |
| 2006 | MicrosoftCXXNameMangler::mangleRefQualifier(RefQualifierKind RefQualifier) { |
| 2007 | |
| 2008 | |
| 2009 | switch (RefQualifier) { |
| 2010 | case RQ_None: |
| 2011 | break; |
| 2012 | |
| 2013 | case RQ_LValue: |
| 2014 | Out << 'G'; |
| 2015 | break; |
| 2016 | |
| 2017 | case RQ_RValue: |
| 2018 | Out << 'H'; |
| 2019 | break; |
| 2020 | } |
| 2021 | } |
| 2022 | |
| 2023 | void MicrosoftCXXNameMangler::manglePointerExtQualifiers(Qualifiers Quals, |
| 2024 | QualType PointeeType) { |
| 2025 | |
| 2026 | bool is64Bit = PointeeType.isNull() ? PointersAre64Bit : |
| 2027 | is64BitPointer(PointeeType.getQualifiers()); |
| 2028 | if (is64Bit && (PointeeType.isNull() || !PointeeType->isFunctionType())) |
| 2029 | Out << 'E'; |
| 2030 | |
| 2031 | if (Quals.hasRestrict()) |
| 2032 | Out << 'I'; |
| 2033 | |
| 2034 | if (Quals.hasUnaligned() || |
| 2035 | (!PointeeType.isNull() && PointeeType.getLocalQualifiers().hasUnaligned())) |
| 2036 | Out << 'F'; |
| 2037 | } |
| 2038 | |
| 2039 | void MicrosoftCXXNameMangler::manglePointerCVQualifiers(Qualifiers Quals) { |
| 2040 | |
| 2041 | |
| 2042 | |
| 2043 | |
| 2044 | bool HasConst = Quals.hasConst(), |
| 2045 | HasVolatile = Quals.hasVolatile(); |
| 2046 | |
| 2047 | if (HasConst && HasVolatile) { |
| 2048 | Out << 'S'; |
| 2049 | } else if (HasVolatile) { |
| 2050 | Out << 'R'; |
| 2051 | } else if (HasConst) { |
| 2052 | Out << 'Q'; |
| 2053 | } else { |
| 2054 | Out << 'P'; |
| 2055 | } |
| 2056 | } |
| 2057 | |
| 2058 | void MicrosoftCXXNameMangler::mangleFunctionArgumentType(QualType T, |
| 2059 | SourceRange Range) { |
| 2060 | |
| 2061 | |
| 2062 | |
| 2063 | |
| 2064 | |
| 2065 | |
| 2066 | |
| 2067 | void *TypePtr; |
| 2068 | if (const auto *DT = T->getAs<DecayedType>()) { |
| 2069 | QualType OriginalType = DT->getOriginalType(); |
| 2070 | |
| 2071 | |
| 2072 | if (const auto *AT = getASTContext().getAsArrayType(OriginalType)) |
| 2073 | OriginalType = getASTContext().getIncompleteArrayType( |
| 2074 | AT->getElementType(), AT->getSizeModifier(), |
| 2075 | AT->getIndexTypeCVRQualifiers()); |
| 2076 | |
| 2077 | TypePtr = OriginalType.getCanonicalType().getAsOpaquePtr(); |
| 2078 | |
| 2079 | |
| 2080 | |
| 2081 | |
| 2082 | |
| 2083 | if (OriginalType->isArrayType()) |
| 2084 | T = T.withConst(); |
| 2085 | } else { |
| 2086 | TypePtr = T.getCanonicalType().getAsOpaquePtr(); |
| 2087 | } |
| 2088 | |
| 2089 | ArgBackRefMap::iterator Found = FunArgBackReferences.find(TypePtr); |
| 2090 | |
| 2091 | if (Found == FunArgBackReferences.end()) { |
| 2092 | size_t OutSizeBefore = Out.tell(); |
| 2093 | |
| 2094 | mangleType(T, Range, QMM_Drop); |
| 2095 | |
| 2096 | |
| 2097 | |
| 2098 | |
| 2099 | bool LongerThanOneChar = (Out.tell() - OutSizeBefore > 1); |
| 2100 | if (LongerThanOneChar && FunArgBackReferences.size() < 10) { |
| 2101 | size_t Size = FunArgBackReferences.size(); |
| 2102 | FunArgBackReferences[TypePtr] = Size; |
| 2103 | } |
| 2104 | } else { |
| 2105 | Out << Found->second; |
| 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | void MicrosoftCXXNameMangler::manglePassObjectSizeArg( |
| 2110 | const PassObjectSizeAttr *POSA) { |
| 2111 | int Type = POSA->getType(); |
| 2112 | bool Dynamic = POSA->isDynamic(); |
| 2113 | |
| 2114 | auto Iter = PassObjectSizeArgs.insert({Type, Dynamic}).first; |
| 2115 | auto *TypePtr = (const void *)&*Iter; |
| 2116 | ArgBackRefMap::iterator Found = FunArgBackReferences.find(TypePtr); |
| 2117 | |
| 2118 | if (Found == FunArgBackReferences.end()) { |
| 2119 | std::string Name = |
| 2120 | Dynamic ? "__pass_dynamic_object_size" : "__pass_object_size"; |
| 2121 | mangleArtificialTagType(TTK_Enum, Name + llvm::utostr(Type), {"__clang"}); |
| 2122 | |
| 2123 | if (FunArgBackReferences.size() < 10) { |
| 2124 | size_t Size = FunArgBackReferences.size(); |
| 2125 | FunArgBackReferences[TypePtr] = Size; |
| 2126 | } |
| 2127 | } else { |
| 2128 | Out << Found->second; |
| 2129 | } |
| 2130 | } |
| 2131 | |
| 2132 | void MicrosoftCXXNameMangler::mangleAddressSpaceType(QualType T, |
| 2133 | Qualifiers Quals, |
| 2134 | SourceRange Range) { |
| 2135 | |
| 2136 | |
| 2137 | |
| 2138 | |
| 2139 | |
| 2140 | |
| 2141 | |
| 2142 | |
| 2143 | |
| 2144 | |
| 2145 | |
| 2146 | |
| 2147 | |
| 2148 | assert(Quals.hasAddressSpace() && "Not valid without address space"); |
| 2149 | llvm::SmallString<32> ASMangling; |
| 2150 | llvm::raw_svector_ostream Stream(ASMangling); |
| 2151 | MicrosoftCXXNameMangler Extra(Context, Stream); |
| 2152 | Stream << "?$"; |
| 2153 | |
| 2154 | LangAS AS = Quals.getAddressSpace(); |
| 2155 | if (Context.getASTContext().addressSpaceMapManglingFor(AS)) { |
| 2156 | unsigned TargetAS = Context.getASTContext().getTargetAddressSpace(AS); |
| 2157 | Extra.mangleSourceName("_AS"); |
| 2158 | Extra.mangleIntegerLiteral(llvm::APSInt::getUnsigned(TargetAS)); |
| 2159 | } else { |
| 2160 | switch (AS) { |
| 2161 | default: |
| 2162 | llvm_unreachable("Not a language specific address space"); |
| 2163 | case LangAS::opencl_global: |
| 2164 | Extra.mangleSourceName("_ASCLglobal"); |
| 2165 | break; |
| 2166 | case LangAS::opencl_global_device: |
| 2167 | Extra.mangleSourceName("_ASCLdevice"); |
| 2168 | break; |
| 2169 | case LangAS::opencl_global_host: |
| 2170 | Extra.mangleSourceName("_ASCLhost"); |
| 2171 | break; |
| 2172 | case LangAS::opencl_local: |
| 2173 | Extra.mangleSourceName("_ASCLlocal"); |
| 2174 | break; |
| 2175 | case LangAS::opencl_constant: |
| 2176 | Extra.mangleSourceName("_ASCLconstant"); |
| 2177 | break; |
| 2178 | case LangAS::opencl_private: |
| 2179 | Extra.mangleSourceName("_ASCLprivate"); |
| 2180 | break; |
| 2181 | case LangAS::opencl_generic: |
| 2182 | Extra.mangleSourceName("_ASCLgeneric"); |
| 2183 | break; |
| 2184 | case LangAS::cuda_device: |
| 2185 | Extra.mangleSourceName("_ASCUdevice"); |
| 2186 | break; |
| 2187 | case LangAS::cuda_constant: |
| 2188 | Extra.mangleSourceName("_ASCUconstant"); |
| 2189 | break; |
| 2190 | case LangAS::cuda_shared: |
| 2191 | Extra.mangleSourceName("_ASCUshared"); |
| 2192 | break; |
| 2193 | case LangAS::ptr32_sptr: |
| 2194 | case LangAS::ptr32_uptr: |
| 2195 | case LangAS::ptr64: |
| 2196 | llvm_unreachable("don't mangle ptr address spaces with _AS"); |
| 2197 | } |
| 2198 | } |
| 2199 | |
| 2200 | Extra.mangleType(T, Range, QMM_Escape); |
| 2201 | mangleQualifiers(Qualifiers(), false); |
| 2202 | mangleArtificialTagType(TTK_Struct, ASMangling, {"__clang"}); |
| 2203 | } |
| 2204 | |
| 2205 | void MicrosoftCXXNameMangler::mangleType(QualType T, SourceRange Range, |
| 2206 | QualifierMangleMode QMM) { |
| 2207 | |
| 2208 | |
| 2209 | T = T.getDesugaredType(getASTContext()); |
| 2210 | Qualifiers Quals = T.getLocalQualifiers(); |
| 2211 | |
| 2212 | if (const ArrayType *AT = getASTContext().getAsArrayType(T)) { |
| 2213 | |
| 2214 | |
| 2215 | if (QMM == QMM_Mangle) |
| 2216 | Out << 'A'; |
| 2217 | else if (QMM == QMM_Escape || QMM == QMM_Result) |
| 2218 | Out << "$$B"; |
| 2219 | mangleArrayType(AT); |
| 2220 | return; |
| 2221 | } |
| 2222 | |
| 2223 | bool IsPointer = T->isAnyPointerType() || T->isMemberPointerType() || |
| 2224 | T->isReferenceType() || T->isBlockPointerType(); |
| 2225 | |
| 2226 | switch (QMM) { |
| 2227 | case QMM_Drop: |
| 2228 | if (Quals.hasObjCLifetime()) |
| 2229 | Quals = Quals.withoutObjCLifetime(); |
| 2230 | break; |
| 2231 | case QMM_Mangle: |
| 2232 | if (const FunctionType *FT = dyn_cast<FunctionType>(T)) { |
| 2233 | Out << '6'; |
| 2234 | mangleFunctionType(FT); |
| 2235 | return; |
| 2236 | } |
| 2237 | mangleQualifiers(Quals, false); |
| 2238 | break; |
| 2239 | case QMM_Escape: |
| 2240 | if (!IsPointer && Quals) { |
| 2241 | Out << "$$C"; |
| 2242 | mangleQualifiers(Quals, false); |
| 2243 | } |
| 2244 | break; |
| 2245 | case QMM_Result: |
| 2246 | |
| 2247 | Quals.removeUnaligned(); |
| 2248 | if (Quals.hasObjCLifetime()) |
| 2249 | Quals = Quals.withoutObjCLifetime(); |
| 2250 | if ((!IsPointer && Quals) || isa<TagType>(T) || isArtificialTagType(T)) { |
| 2251 | Out << '?'; |
| 2252 | mangleQualifiers(Quals, false); |
| 2253 | } |
| 2254 | break; |
| 2255 | } |
| 2256 | |
| 2257 | const Type *ty = T.getTypePtr(); |
| 2258 | |
| 2259 | switch (ty->getTypeClass()) { |
| 2260 | #define ABSTRACT_TYPE(CLASS, PARENT) |
| 2261 | #define NON_CANONICAL_TYPE(CLASS, PARENT) \ |
| 2262 | case Type::CLASS: \ |
| 2263 | llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \ |
| 2264 | return; |
| 2265 | #define TYPE(CLASS, PARENT) \ |
| 2266 | case Type::CLASS: \ |
| 2267 | mangleType(cast<CLASS##Type>(ty), Quals, Range); \ |
| 2268 | break; |
| 2269 | #include "clang/AST/TypeNodes.inc" |
| 2270 | #undef ABSTRACT_TYPE |
| 2271 | #undef NON_CANONICAL_TYPE |
| 2272 | #undef TYPE |
| 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers, |
| 2277 | SourceRange Range) { |
| 2278 | |
| 2279 | |
| 2280 | |
| 2281 | |
| 2282 | |
| 2283 | |
| 2284 | |
| 2285 | |
| 2286 | |
| 2287 | |
| 2288 | |
| 2289 | |
| 2290 | |
| 2291 | |
| 2292 | |
| 2293 | |
| 2294 | |
| 2295 | |
| 2296 | |
| 2297 | |
| 2298 | |
| 2299 | |
| 2300 | |
| 2301 | |
| 2302 | |
| 2303 | |
| 2304 | |
| 2305 | switch (T->getKind()) { |
| 2306 | case BuiltinType::Void: |
| 2307 | Out << 'X'; |
| 2308 | break; |
| 2309 | case BuiltinType::SChar: |
| 2310 | Out << 'C'; |
| 2311 | break; |
| 2312 | case BuiltinType::Char_U: |
| 2313 | case BuiltinType::Char_S: |
| 2314 | Out << 'D'; |
| 2315 | break; |
| 2316 | case BuiltinType::UChar: |
| 2317 | Out << 'E'; |
| 2318 | break; |
| 2319 | case BuiltinType::Short: |
| 2320 | Out << 'F'; |
| 2321 | break; |
| 2322 | case BuiltinType::UShort: |
| 2323 | Out << 'G'; |
| 2324 | break; |
| 2325 | case BuiltinType::Int: |
| 2326 | Out << 'H'; |
| 2327 | break; |
| 2328 | case BuiltinType::UInt: |
| 2329 | Out << 'I'; |
| 2330 | break; |
| 2331 | case BuiltinType::Long: |
| 2332 | Out << 'J'; |
| 2333 | break; |
| 2334 | case BuiltinType::ULong: |
| 2335 | Out << 'K'; |
| 2336 | break; |
| 2337 | case BuiltinType::Float: |
| 2338 | Out << 'M'; |
| 2339 | break; |
| 2340 | case BuiltinType::Double: |
| 2341 | Out << 'N'; |
| 2342 | break; |
| 2343 | |
| 2344 | case BuiltinType::LongDouble: |
| 2345 | Out << 'O'; |
| 2346 | break; |
| 2347 | case BuiltinType::LongLong: |
| 2348 | Out << "_J"; |
| 2349 | break; |
| 2350 | case BuiltinType::ULongLong: |
| 2351 | Out << "_K"; |
| 2352 | break; |
| 2353 | case BuiltinType::Int128: |
| 2354 | Out << "_L"; |
| 2355 | break; |
| 2356 | case BuiltinType::UInt128: |
| 2357 | Out << "_M"; |
| 2358 | break; |
| 2359 | case BuiltinType::Bool: |
| 2360 | Out << "_N"; |
| 2361 | break; |
| 2362 | case BuiltinType::Char8: |
| 2363 | Out << "_Q"; |
| 2364 | break; |
| 2365 | case BuiltinType::Char16: |
| 2366 | Out << "_S"; |
| 2367 | break; |
| 2368 | case BuiltinType::Char32: |
| 2369 | Out << "_U"; |
| 2370 | break; |
| 2371 | case BuiltinType::WChar_S: |
| 2372 | case BuiltinType::WChar_U: |
| 2373 | Out << "_W"; |
| 2374 | break; |
| 2375 | |
| 2376 | #define BUILTIN_TYPE(Id, SingletonId) |
| 2377 | #define PLACEHOLDER_TYPE(Id, SingletonId) \ |
| 2378 | case BuiltinType::Id: |
| 2379 | #include "clang/AST/BuiltinTypes.def" |
| 2380 | case BuiltinType::Dependent: |
| 2381 | llvm_unreachable("placeholder types shouldn't get to name mangling"); |
| 2382 | |
| 2383 | case BuiltinType::ObjCId: |
| 2384 | mangleArtificialTagType(TTK_Struct, "objc_object"); |
| 2385 | break; |
| 2386 | case BuiltinType::ObjCClass: |
| 2387 | mangleArtificialTagType(TTK_Struct, "objc_class"); |
| 2388 | break; |
| 2389 | case BuiltinType::ObjCSel: |
| 2390 | mangleArtificialTagType(TTK_Struct, "objc_selector"); |
| 2391 | break; |
| 2392 | |
| 2393 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 2394 | case BuiltinType::Id: \ |
| 2395 | Out << "PAUocl_" #ImgType "_" #Suffix "@@"; \ |
| 2396 | break; |
| 2397 | #include "clang/Basic/OpenCLImageTypes.def" |
| 2398 | case BuiltinType::OCLSampler: |
| 2399 | Out << "PA"; |
| 2400 | mangleArtificialTagType(TTK_Struct, "ocl_sampler"); |
| 2401 | break; |
| 2402 | case BuiltinType::OCLEvent: |
| 2403 | Out << "PA"; |
| 2404 | mangleArtificialTagType(TTK_Struct, "ocl_event"); |
| 2405 | break; |
| 2406 | case BuiltinType::OCLClkEvent: |
| 2407 | Out << "PA"; |
| 2408 | mangleArtificialTagType(TTK_Struct, "ocl_clkevent"); |
| 2409 | break; |
| 2410 | case BuiltinType::OCLQueue: |
| 2411 | Out << "PA"; |
| 2412 | mangleArtificialTagType(TTK_Struct, "ocl_queue"); |
| 2413 | break; |
| 2414 | case BuiltinType::OCLReserveID: |
| 2415 | Out << "PA"; |
| 2416 | mangleArtificialTagType(TTK_Struct, "ocl_reserveid"); |
| 2417 | break; |
| 2418 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 2419 | case BuiltinType::Id: \ |
| 2420 | mangleArtificialTagType(TTK_Struct, "ocl_" #ExtType); \ |
| 2421 | break; |
| 2422 | #include "clang/Basic/OpenCLExtensionTypes.def" |
| 2423 | |
| 2424 | case BuiltinType::NullPtr: |
| 2425 | Out << "$$T"; |
| 2426 | break; |
| 2427 | |
| 2428 | case BuiltinType::Float16: |
| 2429 | mangleArtificialTagType(TTK_Struct, "_Float16", {"__clang"}); |
| 2430 | break; |
| 2431 | |
| 2432 | case BuiltinType::Half: |
| 2433 | mangleArtificialTagType(TTK_Struct, "_Half", {"__clang"}); |
| 2434 | break; |
| 2435 | |
| 2436 | #define SVE_TYPE(Name, Id, SingletonId) \ |
| 2437 | case BuiltinType::Id: |
| 2438 | #include "clang/Basic/AArch64SVEACLETypes.def" |
| 2439 | #define PPC_VECTOR_TYPE(Name, Id, Size) \ |
| 2440 | case BuiltinType::Id: |
| 2441 | #include "clang/Basic/PPCTypes.def" |
| 2442 | #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id: |
| 2443 | #include "clang/Basic/RISCVVTypes.def" |
| 2444 | case BuiltinType::ShortAccum: |
| 2445 | case BuiltinType::Accum: |
| 2446 | case BuiltinType::LongAccum: |
| 2447 | case BuiltinType::UShortAccum: |
| 2448 | case BuiltinType::UAccum: |
| 2449 | case BuiltinType::ULongAccum: |
| 2450 | case BuiltinType::ShortFract: |
| 2451 | case BuiltinType::Fract: |
| 2452 | case BuiltinType::LongFract: |
| 2453 | case BuiltinType::UShortFract: |
| 2454 | case BuiltinType::UFract: |
| 2455 | case BuiltinType::ULongFract: |
| 2456 | case BuiltinType::SatShortAccum: |
| 2457 | case BuiltinType::SatAccum: |
| 2458 | case BuiltinType::SatLongAccum: |
| 2459 | case BuiltinType::SatUShortAccum: |
| 2460 | case BuiltinType::SatUAccum: |
| 2461 | case BuiltinType::SatULongAccum: |
| 2462 | case BuiltinType::SatShortFract: |
| 2463 | case BuiltinType::SatFract: |
| 2464 | case BuiltinType::SatLongFract: |
| 2465 | case BuiltinType::SatUShortFract: |
| 2466 | case BuiltinType::SatUFract: |
| 2467 | case BuiltinType::SatULongFract: |
| 2468 | case BuiltinType::BFloat16: |
| 2469 | case BuiltinType::Float128: { |
| 2470 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 2471 | unsigned DiagID = Diags.getCustomDiagID( |
| 2472 | DiagnosticsEngine::Error, "cannot mangle this built-in %0 type yet"); |
| 2473 | Diags.Report(Range.getBegin(), DiagID) |
| 2474 | << T->getName(Context.getASTContext().getPrintingPolicy()) << Range; |
| 2475 | break; |
| 2476 | } |
| 2477 | } |
| 2478 | } |
| 2479 | |
| 2480 | |
| 2481 | void MicrosoftCXXNameMangler::mangleType(const FunctionProtoType *T, Qualifiers, |
| 2482 | SourceRange) { |
| 2483 | |
| 2484 | |
| 2485 | |
| 2486 | if (T->getMethodQuals() || T->getRefQualifier() != RQ_None) { |
| 2487 | Out << "$$A8@@"; |
| 2488 | mangleFunctionType(T, nullptr, true); |
| 2489 | } else { |
| 2490 | Out << "$$A6"; |
| 2491 | mangleFunctionType(T); |
| 2492 | } |
| 2493 | } |
| 2494 | void MicrosoftCXXNameMangler::mangleType(const FunctionNoProtoType *T, |
| 2495 | Qualifiers, SourceRange) { |
| 2496 | Out << "$$A6"; |
| 2497 | mangleFunctionType(T); |
| 2498 | } |
| 2499 | |
| 2500 | void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T, |
| 2501 | const FunctionDecl *D, |
| 2502 | bool ForceThisQuals, |
| 2503 | bool MangleExceptionSpec) { |
| 2504 | |
| 2505 | |
| 2506 | const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(T); |
| 3 | | Assuming 'T' is not a 'FunctionProtoType' | |
|
| 4 | | 'Proto' initialized to a null pointer value | |
|
| 2507 | |
| 2508 | SourceRange Range; |
| 2509 | if (D) Range = D->getSourceRange(); |
| |
| 2510 | |
| 2511 | bool IsInLambda = false; |
| 2512 | bool IsStructor = false, HasThisQuals = ForceThisQuals, IsCtorClosure = false; |
| 2513 | CallingConv CC = T->getCallConv(); |
| 2514 | if (const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(D)) { |
| 6 | | Assuming 'D' is a 'CXXMethodDecl' | |
|
| |
| 2515 | if (MD->getParent()->isLambda()) |
| |
| 2516 | IsInLambda = true; |
| 2517 | if (MD->isInstance()) |
| 9 | | Calling 'CXXMethodDecl::isInstance' | |
|
| 12 | | Returning from 'CXXMethodDecl::isInstance' | |
|
| |
| 2518 | HasThisQuals = true; |
| 2519 | if (isa<CXXDestructorDecl>(MD)) { |
| 14 | | Assuming 'MD' is a 'CXXDestructorDecl' | |
|
| |
| 2520 | IsStructor = true; |
| 2521 | } else if (isa<CXXConstructorDecl>(MD)) { |
| 2522 | IsStructor = true; |
| 2523 | IsCtorClosure = (StructorType == Ctor_CopyingClosure || |
| 2524 | StructorType == Ctor_DefaultClosure) && |
| 2525 | isStructorDecl(MD); |
| 2526 | if (IsCtorClosure) |
| 2527 | CC = getASTContext().getDefaultCallingConvention( |
| 2528 | false, true); |
| 2529 | } |
| 2530 | } |
| 2531 | |
| 2532 | |
| 2533 | |
| 2534 | if (HasThisQuals) { |
| |
| 2535 | Qualifiers Quals = Proto->getMethodQuals(); |
| 17 | | Called C++ object pointer is null |
|
| 2536 | manglePointerExtQualifiers(Quals, QualType()); |
| 2537 | mangleRefQualifier(Proto->getRefQualifier()); |
| 2538 | mangleQualifiers(Quals, false); |
| 2539 | } |
| 2540 | |
| 2541 | mangleCallingConvention(CC); |
| 2542 | |
| 2543 | |
| 2544 | |
| 2545 | if (IsStructor) { |
| 2546 | if (isa<CXXDestructorDecl>(D) && isStructorDecl(D)) { |
| 2547 | |
| 2548 | |
| 2549 | if (StructorType == Dtor_Deleting) { |
| 2550 | Out << (PointersAre64Bit ? "PEAXI@Z" : "PAXI@Z"); |
| 2551 | return; |
| 2552 | } |
| 2553 | |
| 2554 | if (StructorType == Dtor_Complete) { |
| 2555 | Out << "XXZ"; |
| 2556 | return; |
| 2557 | } |
| 2558 | } |
| 2559 | if (IsCtorClosure) { |
| 2560 | |
| 2561 | |
| 2562 | Out << 'X'; |
| 2563 | |
| 2564 | if (StructorType == Ctor_DefaultClosure) { |
| 2565 | |
| 2566 | Out << 'X'; |
| 2567 | } else if (StructorType == Ctor_CopyingClosure) { |
| 2568 | |
| 2569 | mangleFunctionArgumentType(getASTContext().getLValueReferenceType( |
| 2570 | Proto->getParamType(0) |
| 2571 | ->getAs<LValueReferenceType>() |
| 2572 | ->getPointeeType(), |
| 2573 | true), |
| 2574 | Range); |
| 2575 | Out << '@'; |
| 2576 | } else { |
| 2577 | llvm_unreachable("unexpected constructor closure!"); |
| 2578 | } |
| 2579 | Out << 'Z'; |
| 2580 | return; |
| 2581 | } |
| 2582 | Out << '@'; |
| 2583 | } else if (IsInLambda && D && isa<CXXConversionDecl>(D)) { |
| 2584 | |
| 2585 | |
| 2586 | |
| 2587 | mangleType(T->getReturnType(), Range, QMM_Result); |
| 2588 | } else { |
| 2589 | QualType ResultType = T->getReturnType(); |
| 2590 | if (IsInLambda && isa<CXXConversionDecl>(D)) { |
| 2591 | |
| 2592 | |
| 2593 | |
| 2594 | mangleType(ResultType, Range, QMM_Result); |
| 2595 | } else if (const auto *AT = dyn_cast_or_null<AutoType>( |
| 2596 | ResultType->getContainedAutoType())) { |
| 2597 | Out << '?'; |
| 2598 | mangleQualifiers(ResultType.getLocalQualifiers(), false); |
| 2599 | Out << '?'; |
| 2600 | assert(AT->getKeyword() != AutoTypeKeyword::GNUAutoType && |
| 2601 | "shouldn't need to mangle __auto_type!"); |
| 2602 | mangleSourceName(AT->isDecltypeAuto() ? "<decltype-auto>" : "<auto>"); |
| 2603 | Out << '@'; |
| 2604 | } else if (IsInLambda) { |
| 2605 | Out << '@'; |
| 2606 | } else { |
| 2607 | if (ResultType->isVoidType()) |
| 2608 | ResultType = ResultType.getUnqualifiedType(); |
| 2609 | mangleType(ResultType, Range, QMM_Result); |
| 2610 | } |
| 2611 | } |
| 2612 | |
| 2613 | |
| 2614 | |
| 2615 | |
| 2616 | if (!Proto) { |
| 2617 | |
| 2618 | |
| 2619 | |
| 2620 | Out << '@'; |
| 2621 | } else if (Proto->getNumParams() == 0 && !Proto->isVariadic()) { |
| 2622 | Out << 'X'; |
| 2623 | } else { |
| 2624 | |
| 2625 | for (unsigned I = 0, E = Proto->getNumParams(); I != E; ++I) { |
| 2626 | mangleFunctionArgumentType(Proto->getParamType(I), Range); |
| 2627 | |
| 2628 | |
| 2629 | |
| 2630 | |
| 2631 | |
| 2632 | |
| 2633 | |
| 2634 | |
| 2635 | if (D) |
| 2636 | if (const auto *P = D->getParamDecl(I)->getAttr<PassObjectSizeAttr>()) |
| 2637 | manglePassObjectSizeArg(P); |
| 2638 | } |
| 2639 | |
| 2640 | if (Proto->isVariadic()) |
| 2641 | Out << 'Z'; |
| 2642 | else |
| 2643 | Out << '@'; |
| 2644 | } |
| 2645 | |
| 2646 | if (MangleExceptionSpec && getASTContext().getLangOpts().CPlusPlus17 && |
| 2647 | getASTContext().getLangOpts().isCompatibleWithMSVC( |
| 2648 | LangOptions::MSVC2017_5)) |
| 2649 | mangleThrowSpecification(Proto); |
| 2650 | else |
| 2651 | Out << 'Z'; |
| 2652 | } |
| 2653 | |
| 2654 | void MicrosoftCXXNameMangler::mangleFunctionClass(const FunctionDecl *FD) { |
| 2655 | |
| 2656 | |
| 2657 | |
| 2658 | |
| 2659 | |
| 2660 | |
| 2661 | |
| 2662 | |
| 2663 | |
| 2664 | |
| 2665 | |
| 2666 | |
| 2667 | |
| 2668 | |
| 2669 | |
| 2670 | |
| 2671 | |
| 2672 | |
| 2673 | |
| 2674 | |
| 2675 | |
| 2676 | |
| 2677 | |
| 2678 | |
| 2679 | if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { |
| 2680 | bool IsVirtual = MD->isVirtual(); |
| 2681 | |
| 2682 | |
| 2683 | if (isa<CXXDestructorDecl>(MD) && isStructorDecl(MD) && |
| 2684 | StructorType == Dtor_Complete) { |
| 2685 | IsVirtual = false; |
| 2686 | } |
| 2687 | switch (MD->getAccess()) { |
| 2688 | case AS_none: |
| 2689 | llvm_unreachable("Unsupported access specifier"); |
| 2690 | case AS_private: |
| 2691 | if (MD->isStatic()) |
| 2692 | Out << 'C'; |
| 2693 | else if (IsVirtual) |
| 2694 | Out << 'E'; |
| 2695 | else |
| 2696 | Out << 'A'; |
| 2697 | break; |
| 2698 | case AS_protected: |
| 2699 | if (MD->isStatic()) |
| 2700 | Out << 'K'; |
| 2701 | else if (IsVirtual) |
| 2702 | Out << 'M'; |
| 2703 | else |
| 2704 | Out << 'I'; |
| 2705 | break; |
| 2706 | case AS_public: |
| 2707 | if (MD->isStatic()) |
| 2708 | Out << 'S'; |
| 2709 | else if (IsVirtual) |
| 2710 | Out << 'U'; |
| 2711 | else |
| 2712 | Out << 'Q'; |
| 2713 | } |
| 2714 | } else { |
| 2715 | Out << 'Y'; |
| 2716 | } |
| 2717 | } |
| 2718 | void MicrosoftCXXNameMangler::mangleCallingConvention(CallingConv CC) { |
| 2719 | |
| 2720 | |
| 2721 | |
| 2722 | |
| 2723 | |
| 2724 | |
| 2725 | |
| 2726 | |
| 2727 | |
| 2728 | |
| 2729 | |
| 2730 | |
| 2731 | |
| 2732 | |
| 2733 | |
| 2734 | |
| 2735 | |
| 2736 | |
| 2737 | |
| 2738 | |
| 2739 | |
| 2740 | switch (CC) { |
| 2741 | default: |
| 2742 | llvm_unreachable("Unsupported CC for mangling"); |
| 2743 | case CC_Win64: |
| 2744 | case CC_X86_64SysV: |
| 2745 | case CC_C: Out << 'A'; break; |
| 2746 | case CC_X86Pascal: Out << 'C'; break; |
| 2747 | case CC_X86ThisCall: Out << 'E'; break; |
| 2748 | case CC_X86StdCall: Out << 'G'; break; |
| 2749 | case CC_X86FastCall: Out << 'I'; break; |
| 2750 | case CC_X86VectorCall: Out << 'Q'; break; |
| 2751 | case CC_Swift: Out << 'S'; break; |
| 2752 | case CC_SwiftAsync: Out << 'W'; break; |
| 2753 | case CC_PreserveMost: Out << 'U'; break; |
| 2754 | case CC_X86RegCall: Out << 'w'; break; |
| 2755 | } |
| 2756 | } |
| 2757 | void MicrosoftCXXNameMangler::mangleCallingConvention(const FunctionType *T) { |
| 2758 | mangleCallingConvention(T->getCallConv()); |
| 2759 | } |
| 2760 | |
| 2761 | void MicrosoftCXXNameMangler::mangleThrowSpecification( |
| 2762 | const FunctionProtoType *FT) { |
| 2763 | |
| 2764 | |
| 2765 | if (FT->canThrow()) |
| 2766 | Out << 'Z'; |
| 2767 | else |
| 2768 | Out << "_E"; |
| 2769 | } |
| 2770 | |
| 2771 | void MicrosoftCXXNameMangler::mangleType(const UnresolvedUsingType *T, |
| 2772 | Qualifiers, SourceRange Range) { |
| 2773 | |
| 2774 | |
| 2775 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 2776 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 2777 | "cannot mangle this unresolved dependent type yet"); |
| 2778 | Diags.Report(Range.getBegin(), DiagID) |
| 2779 | << Range; |
| 2780 | } |
| 2781 | |
| 2782 | |
| 2783 | |
| 2784 | |
| 2785 | |
| 2786 | |
| 2787 | void MicrosoftCXXNameMangler::mangleTagTypeKind(TagTypeKind TTK) { |
| 2788 | switch (TTK) { |
| 2789 | case TTK_Union: |
| 2790 | Out << 'T'; |
| 2791 | break; |
| 2792 | case TTK_Struct: |
| 2793 | case TTK_Interface: |
| 2794 | Out << 'U'; |
| 2795 | break; |
| 2796 | case TTK_Class: |
| 2797 | Out << 'V'; |
| 2798 | break; |
| 2799 | case TTK_Enum: |
| 2800 | Out << "W4"; |
| 2801 | break; |
| 2802 | } |
| 2803 | } |
| 2804 | void MicrosoftCXXNameMangler::mangleType(const EnumType *T, Qualifiers, |
| 2805 | SourceRange) { |
| 2806 | mangleType(cast<TagType>(T)->getDecl()); |
| 2807 | } |
| 2808 | void MicrosoftCXXNameMangler::mangleType(const RecordType *T, Qualifiers, |
| 2809 | SourceRange) { |
| 2810 | mangleType(cast<TagType>(T)->getDecl()); |
| 2811 | } |
| 2812 | void MicrosoftCXXNameMangler::mangleType(const TagDecl *TD) { |
| 2813 | mangleTagTypeKind(TD->getTagKind()); |
| 2814 | mangleName(TD); |
| 2815 | } |
| 2816 | |
| 2817 | |
| 2818 | void MicrosoftCXXNameMangler::mangleArtificialTagType( |
| 2819 | TagTypeKind TK, StringRef UnqualifiedName, |
| 2820 | ArrayRef<StringRef> NestedNames) { |
| 2821 | |
| 2822 | mangleTagTypeKind(TK); |
| 2823 | |
| 2824 | |
| 2825 | mangleSourceName(UnqualifiedName); |
| 2826 | |
| 2827 | for (auto I = NestedNames.rbegin(), E = NestedNames.rend(); I != E; ++I) |
| 2828 | mangleSourceName(*I); |
| 2829 | |
| 2830 | |
| 2831 | Out << '@'; |
| 2832 | } |
| 2833 | |
| 2834 | |
| 2835 | |
| 2836 | |
| 2837 | |
| 2838 | |
| 2839 | |
| 2840 | |
| 2841 | void MicrosoftCXXNameMangler::mangleDecayedArrayType(const ArrayType *T) { |
| 2842 | |
| 2843 | |
| 2844 | manglePointerCVQualifiers(T->getElementType().getQualifiers()); |
| 2845 | mangleType(T->getElementType(), SourceRange()); |
| 2846 | } |
| 2847 | void MicrosoftCXXNameMangler::mangleType(const ConstantArrayType *T, Qualifiers, |
| 2848 | SourceRange) { |
| 2849 | llvm_unreachable("Should have been special cased"); |
| 2850 | } |
| 2851 | void MicrosoftCXXNameMangler::mangleType(const VariableArrayType *T, Qualifiers, |
| 2852 | SourceRange) { |
| 2853 | llvm_unreachable("Should have been special cased"); |
| 2854 | } |
| 2855 | void MicrosoftCXXNameMangler::mangleType(const DependentSizedArrayType *T, |
| 2856 | Qualifiers, SourceRange) { |
| 2857 | llvm_unreachable("Should have been special cased"); |
| 2858 | } |
| 2859 | void MicrosoftCXXNameMangler::mangleType(const IncompleteArrayType *T, |
| 2860 | Qualifiers, SourceRange) { |
| 2861 | llvm_unreachable("Should have been special cased"); |
| 2862 | } |
| 2863 | void MicrosoftCXXNameMangler::mangleArrayType(const ArrayType *T) { |
| 2864 | QualType ElementTy(T, 0); |
| 2865 | SmallVector<llvm::APInt, 3> Dimensions; |
| 2866 | for (;;) { |
| 2867 | if (ElementTy->isConstantArrayType()) { |
| 2868 | const ConstantArrayType *CAT = |
| 2869 | getASTContext().getAsConstantArrayType(ElementTy); |
| 2870 | Dimensions.push_back(CAT->getSize()); |
| 2871 | ElementTy = CAT->getElementType(); |
| 2872 | } else if (ElementTy->isIncompleteArrayType()) { |
| 2873 | const IncompleteArrayType *IAT = |
| 2874 | getASTContext().getAsIncompleteArrayType(ElementTy); |
| 2875 | Dimensions.push_back(llvm::APInt(32, 0)); |
| 2876 | ElementTy = IAT->getElementType(); |
| 2877 | } else if (ElementTy->isVariableArrayType()) { |
| 2878 | const VariableArrayType *VAT = |
| 2879 | getASTContext().getAsVariableArrayType(ElementTy); |
| 2880 | Dimensions.push_back(llvm::APInt(32, 0)); |
| 2881 | ElementTy = VAT->getElementType(); |
| 2882 | } else if (ElementTy->isDependentSizedArrayType()) { |
| 2883 | |
| 2884 | const DependentSizedArrayType *DSAT = |
| 2885 | getASTContext().getAsDependentSizedArrayType(ElementTy); |
| 2886 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 2887 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 2888 | "cannot mangle this dependent-length array yet"); |
| 2889 | Diags.Report(DSAT->getSizeExpr()->getExprLoc(), DiagID) |
| 2890 | << DSAT->getBracketsRange(); |
| 2891 | return; |
| 2892 | } else { |
| 2893 | break; |
| 2894 | } |
| 2895 | } |
| 2896 | Out << 'Y'; |
| 2897 | |
| 2898 | mangleNumber(Dimensions.size()); |
| 2899 | for (const llvm::APInt &Dimension : Dimensions) |
| 2900 | mangleNumber(Dimension.getLimitedValue()); |
| 2901 | mangleType(ElementTy, SourceRange(), QMM_Escape); |
| 2902 | } |
| 2903 | |
| 2904 | |
| 2905 | |
| 2906 | |
| 2907 | void MicrosoftCXXNameMangler::mangleType(const MemberPointerType *T, |
| 2908 | Qualifiers Quals, SourceRange Range) { |
| 2909 | QualType PointeeType = T->getPointeeType(); |
| 2910 | manglePointerCVQualifiers(Quals); |
| 2911 | manglePointerExtQualifiers(Quals, PointeeType); |
| 2912 | if (const FunctionProtoType *FPT = PointeeType->getAs<FunctionProtoType>()) { |
| 2913 | Out << '8'; |
| 2914 | mangleName(T->getClass()->castAs<RecordType>()->getDecl()); |
| 2915 | mangleFunctionType(FPT, nullptr, true); |
| 2916 | } else { |
| 2917 | mangleQualifiers(PointeeType.getQualifiers(), true); |
| 2918 | mangleName(T->getClass()->castAs<RecordType>()->getDecl()); |
| 2919 | mangleType(PointeeType, Range, QMM_Drop); |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | void MicrosoftCXXNameMangler::mangleType(const TemplateTypeParmType *T, |
| 2924 | Qualifiers, SourceRange Range) { |
| 2925 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 2926 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 2927 | "cannot mangle this template type parameter type yet"); |
| 2928 | Diags.Report(Range.getBegin(), DiagID) |
| 2929 | << Range; |
| 2930 | } |
| 2931 | |
| 2932 | void MicrosoftCXXNameMangler::mangleType(const SubstTemplateTypeParmPackType *T, |
| 2933 | Qualifiers, SourceRange Range) { |
| 2934 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 2935 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 2936 | "cannot mangle this substituted parameter pack yet"); |
| 2937 | Diags.Report(Range.getBegin(), DiagID) |
| 2938 | << Range; |
| 2939 | } |
| 2940 | |
| 2941 | |
| 2942 | |
| 2943 | |
| 2944 | void MicrosoftCXXNameMangler::mangleType(const PointerType *T, Qualifiers Quals, |
| 2945 | SourceRange Range) { |
| 2946 | QualType PointeeType = T->getPointeeType(); |
| 2947 | manglePointerCVQualifiers(Quals); |
| 2948 | manglePointerExtQualifiers(Quals, PointeeType); |
| 2949 | |
| 2950 | |
| 2951 | |
| 2952 | LangAS AddrSpace = PointeeType.getQualifiers().getAddressSpace(); |
| 2953 | if (isPtrSizeAddressSpace(AddrSpace) || AddrSpace == LangAS::Default) |
| 2954 | mangleType(PointeeType, Range); |
| 2955 | else |
| 2956 | mangleAddressSpaceType(PointeeType, PointeeType.getQualifiers(), Range); |
| 2957 | } |
| 2958 | |
| 2959 | void MicrosoftCXXNameMangler::mangleType(const ObjCObjectPointerType *T, |
| 2960 | Qualifiers Quals, SourceRange Range) { |
| 2961 | QualType PointeeType = T->getPointeeType(); |
| 2962 | switch (Quals.getObjCLifetime()) { |
| 2963 | case Qualifiers::OCL_None: |
| 2964 | case Qualifiers::OCL_ExplicitNone: |
| 2965 | break; |
| 2966 | case Qualifiers::OCL_Autoreleasing: |
| 2967 | case Qualifiers::OCL_Strong: |
| 2968 | case Qualifiers::OCL_Weak: |
| 2969 | return mangleObjCLifetime(PointeeType, Quals, Range); |
| 2970 | } |
| 2971 | manglePointerCVQualifiers(Quals); |
| 2972 | manglePointerExtQualifiers(Quals, PointeeType); |
| 2973 | mangleType(PointeeType, Range); |
| 2974 | } |
| 2975 | |
| 2976 | |
| 2977 | |
| 2978 | |
| 2979 | void MicrosoftCXXNameMangler::mangleType(const LValueReferenceType *T, |
| 2980 | Qualifiers Quals, SourceRange Range) { |
| 2981 | QualType PointeeType = T->getPointeeType(); |
| 2982 | assert(!Quals.hasConst() && !Quals.hasVolatile() && "unexpected qualifier!"); |
| 2983 | Out << 'A'; |
| 2984 | manglePointerExtQualifiers(Quals, PointeeType); |
| 2985 | mangleType(PointeeType, Range); |
| 2986 | } |
| 2987 | |
| 2988 | |
| 2989 | |
| 2990 | |
| 2991 | void MicrosoftCXXNameMangler::mangleType(const RValueReferenceType *T, |
| 2992 | Qualifiers Quals, SourceRange Range) { |
| 2993 | QualType PointeeType = T->getPointeeType(); |
| 2994 | assert(!Quals.hasConst() && !Quals.hasVolatile() && "unexpected qualifier!"); |
| 2995 | Out << "$$Q"; |
| 2996 | manglePointerExtQualifiers(Quals, PointeeType); |
| 2997 | mangleType(PointeeType, Range); |
| 2998 | } |
| 2999 | |
| 3000 | void MicrosoftCXXNameMangler::mangleType(const ComplexType *T, Qualifiers, |
| 3001 | SourceRange Range) { |
| 3002 | QualType ElementType = T->getElementType(); |
| 3003 | |
| 3004 | llvm::SmallString<64> TemplateMangling; |
| 3005 | llvm::raw_svector_ostream Stream(TemplateMangling); |
| 3006 | MicrosoftCXXNameMangler Extra(Context, Stream); |
| 3007 | Stream << "?$"; |
| 3008 | Extra.mangleSourceName("_Complex"); |
| 3009 | Extra.mangleType(ElementType, Range, QMM_Escape); |
| 3010 | |
| 3011 | mangleArtificialTagType(TTK_Struct, TemplateMangling, {"__clang"}); |
| 3012 | } |
| 3013 | |
| 3014 | |
| 3015 | |
| 3016 | |
| 3017 | |
| 3018 | |
| 3019 | bool MicrosoftCXXNameMangler::isArtificialTagType(QualType T) const { |
| 3020 | const Type *ty = T.getTypePtr(); |
| 3021 | switch (ty->getTypeClass()) { |
| 3022 | default: |
| 3023 | return false; |
| 3024 | |
| 3025 | case Type::Vector: { |
| 3026 | |
| 3027 | |
| 3028 | |
| 3029 | return true; |
| 3030 | } |
| 3031 | } |
| 3032 | } |
| 3033 | |
| 3034 | void MicrosoftCXXNameMangler::mangleType(const VectorType *T, Qualifiers Quals, |
| 3035 | SourceRange Range) { |
| 3036 | const BuiltinType *ET = T->getElementType()->getAs<BuiltinType>(); |
| 3037 | assert(ET && "vectors with non-builtin elements are unsupported"); |
| 3038 | uint64_t Width = getASTContext().getTypeSize(T); |
| 3039 | |
| 3040 | |
| 3041 | size_t OutSizeBefore = Out.tell(); |
| 3042 | if (!isa<ExtVectorType>(T)) { |
| 3043 | if (getASTContext().getTargetInfo().getTriple().isX86()) { |
| 3044 | if (Width == 64 && ET->getKind() == BuiltinType::LongLong) { |
| 3045 | mangleArtificialTagType(TTK_Union, "__m64"); |
| 3046 | } else if (Width >= 128) { |
| 3047 | if (ET->getKind() == BuiltinType::Float) |
| 3048 | mangleArtificialTagType(TTK_Union, "__m" + llvm::utostr(Width)); |
| 3049 | else if (ET->getKind() == BuiltinType::LongLong) |
| 3050 | mangleArtificialTagType(TTK_Union, "__m" + llvm::utostr(Width) + 'i'); |
| 3051 | else if (ET->getKind() == BuiltinType::Double) |
| 3052 | mangleArtificialTagType(TTK_Struct, "__m" + llvm::utostr(Width) + 'd'); |
| 3053 | } |
| 3054 | } |
| 3055 | } |
| 3056 | |
| 3057 | bool IsBuiltin = Out.tell() != OutSizeBefore; |
| 3058 | if (!IsBuiltin) { |
| 3059 | |
| 3060 | |
| 3061 | |
| 3062 | |
| 3063 | llvm::SmallString<64> TemplateMangling; |
| 3064 | llvm::raw_svector_ostream Stream(TemplateMangling); |
| 3065 | MicrosoftCXXNameMangler Extra(Context, Stream); |
| 3066 | Stream << "?$"; |
| 3067 | Extra.mangleSourceName("__vector"); |
| 3068 | Extra.mangleType(QualType(ET, 0), Range, QMM_Escape); |
| 3069 | Extra.mangleIntegerLiteral(llvm::APSInt::getUnsigned(T->getNumElements())); |
| 3070 | |
| 3071 | mangleArtificialTagType(TTK_Union, TemplateMangling, {"__clang"}); |
| 3072 | } |
| 3073 | } |
| 3074 | |
| 3075 | void MicrosoftCXXNameMangler::mangleType(const ExtVectorType *T, |
| 3076 | Qualifiers Quals, SourceRange Range) { |
| 3077 | mangleType(static_cast<const VectorType *>(T), Quals, Range); |
| 3078 | } |
| 3079 | |
| 3080 | void MicrosoftCXXNameMangler::mangleType(const DependentVectorType *T, |
| 3081 | Qualifiers, SourceRange Range) { |
| 3082 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3083 | unsigned DiagID = Diags.getCustomDiagID( |
| 3084 | DiagnosticsEngine::Error, |
| 3085 | "cannot mangle this dependent-sized vector type yet"); |
| 3086 | Diags.Report(Range.getBegin(), DiagID) << Range; |
| 3087 | } |
| 3088 | |
| 3089 | void MicrosoftCXXNameMangler::mangleType(const DependentSizedExtVectorType *T, |
| 3090 | Qualifiers, SourceRange Range) { |
| 3091 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3092 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 3093 | "cannot mangle this dependent-sized extended vector type yet"); |
| 3094 | Diags.Report(Range.getBegin(), DiagID) |
| 3095 | << Range; |
| 3096 | } |
| 3097 | |
| 3098 | void MicrosoftCXXNameMangler::mangleType(const ConstantMatrixType *T, |
| 3099 | Qualifiers quals, SourceRange Range) { |
| 3100 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3101 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 3102 | "Cannot mangle this matrix type yet"); |
| 3103 | Diags.Report(Range.getBegin(), DiagID) << Range; |
| 3104 | } |
| 3105 | |
| 3106 | void MicrosoftCXXNameMangler::mangleType(const DependentSizedMatrixType *T, |
| 3107 | Qualifiers quals, SourceRange Range) { |
| 3108 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3109 | unsigned DiagID = Diags.getCustomDiagID( |
| 3110 | DiagnosticsEngine::Error, |
| 3111 | "Cannot mangle this dependent-sized matrix type yet"); |
| 3112 | Diags.Report(Range.getBegin(), DiagID) << Range; |
| 3113 | } |
| 3114 | |
| 3115 | void MicrosoftCXXNameMangler::mangleType(const DependentAddressSpaceType *T, |
| 3116 | Qualifiers, SourceRange Range) { |
| 3117 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3118 | unsigned DiagID = Diags.getCustomDiagID( |
| 3119 | DiagnosticsEngine::Error, |
| 3120 | "cannot mangle this dependent address space type yet"); |
| 3121 | Diags.Report(Range.getBegin(), DiagID) << Range; |
| 3122 | } |
| 3123 | |
| 3124 | void MicrosoftCXXNameMangler::mangleType(const ObjCInterfaceType *T, Qualifiers, |
| 3125 | SourceRange) { |
| 3126 | |
| 3127 | mangleTagTypeKind(TTK_Struct); |
| 3128 | mangleName(T->getDecl()); |
| 3129 | } |
| 3130 | |
| 3131 | void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T, |
| 3132 | Qualifiers Quals, SourceRange Range) { |
| 3133 | if (T->isKindOfType()) |
| 3134 | return mangleObjCKindOfType(T, Quals, Range); |
| 3135 | |
| 3136 | if (T->qual_empty() && !T->isSpecialized()) |
| 3137 | return mangleType(T->getBaseType(), Range, QMM_Drop); |
| 3138 | |
| 3139 | ArgBackRefMap OuterFunArgsContext; |
| 3140 | ArgBackRefMap OuterTemplateArgsContext; |
| 3141 | BackRefVec OuterTemplateContext; |
| 3142 | |
| 3143 | FunArgBackReferences.swap(OuterFunArgsContext); |
| 3144 | TemplateArgBackReferences.swap(OuterTemplateArgsContext); |
| 3145 | NameBackReferences.swap(OuterTemplateContext); |
| 3146 | |
| 3147 | mangleTagTypeKind(TTK_Struct); |
| 3148 | |
| 3149 | Out << "?$"; |
| 3150 | if (T->isObjCId()) |
| 3151 | mangleSourceName("objc_object"); |
| 3152 | else if (T->isObjCClass()) |
| 3153 | mangleSourceName("objc_class"); |
| 3154 | else |
| 3155 | mangleSourceName(T->getInterface()->getName()); |
| 3156 | |
| 3157 | for (const auto &Q : T->quals()) |
| 3158 | mangleObjCProtocol(Q); |
| 3159 | |
| 3160 | if (T->isSpecialized()) |
| 3161 | for (const auto &TA : T->getTypeArgs()) |
| 3162 | mangleType(TA, Range, QMM_Drop); |
| 3163 | |
| 3164 | Out << '@'; |
| 3165 | |
| 3166 | Out << '@'; |
| 3167 | |
| 3168 | FunArgBackReferences.swap(OuterFunArgsContext); |
| 3169 | TemplateArgBackReferences.swap(OuterTemplateArgsContext); |
| 3170 | NameBackReferences.swap(OuterTemplateContext); |
| 3171 | } |
| 3172 | |
| 3173 | void MicrosoftCXXNameMangler::mangleType(const BlockPointerType *T, |
| 3174 | Qualifiers Quals, SourceRange Range) { |
| 3175 | QualType PointeeType = T->getPointeeType(); |
| 3176 | manglePointerCVQualifiers(Quals); |
| 3177 | manglePointerExtQualifiers(Quals, PointeeType); |
| 3178 | |
| 3179 | Out << "_E"; |
| 3180 | |
| 3181 | mangleFunctionType(PointeeType->castAs<FunctionProtoType>()); |
| 3182 | } |
| 3183 | |
| 3184 | void MicrosoftCXXNameMangler::mangleType(const InjectedClassNameType *, |
| 3185 | Qualifiers, SourceRange) { |
| 3186 | llvm_unreachable("Cannot mangle injected class name type."); |
| 3187 | } |
| 3188 | |
| 3189 | void MicrosoftCXXNameMangler::mangleType(const TemplateSpecializationType *T, |
| 3190 | Qualifiers, SourceRange Range) { |
| 3191 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3192 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 3193 | "cannot mangle this template specialization type yet"); |
| 3194 | Diags.Report(Range.getBegin(), DiagID) |
| 3195 | << Range; |
| 3196 | } |
| 3197 | |
| 3198 | void MicrosoftCXXNameMangler::mangleType(const DependentNameType *T, Qualifiers, |
| 3199 | SourceRange Range) { |
| 3200 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3201 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 3202 | "cannot mangle this dependent name type yet"); |
| 3203 | Diags.Report(Range.getBegin(), DiagID) |
| 3204 | << Range; |
| 3205 | } |
| 3206 | |
| 3207 | void MicrosoftCXXNameMangler::mangleType( |
| 3208 | const DependentTemplateSpecializationType *T, Qualifiers, |
| 3209 | SourceRange Range) { |
| 3210 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3211 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 3212 | "cannot mangle this dependent template specialization type yet"); |
| 3213 | Diags.Report(Range.getBegin(), DiagID) |
| 3214 | << Range; |
| 3215 | } |
| 3216 | |
| 3217 | void MicrosoftCXXNameMangler::mangleType(const PackExpansionType *T, Qualifiers, |
| 3218 | SourceRange Range) { |
| 3219 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3220 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 3221 | "cannot mangle this pack expansion yet"); |
| 3222 | Diags.Report(Range.getBegin(), DiagID) |
| 3223 | << Range; |
| 3224 | } |
| 3225 | |
| 3226 | void MicrosoftCXXNameMangler::mangleType(const TypeOfType *T, Qualifiers, |
| 3227 | SourceRange Range) { |
| 3228 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3229 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 3230 | "cannot mangle this typeof(type) yet"); |
| 3231 | Diags.Report(Range.getBegin(), DiagID) |
| 3232 | << Range; |
| 3233 | } |
| 3234 | |
| 3235 | void MicrosoftCXXNameMangler::mangleType(const TypeOfExprType *T, Qualifiers, |
| 3236 | SourceRange Range) { |
| 3237 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3238 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 3239 | "cannot mangle this typeof(expression) yet"); |
| 3240 | Diags.Report(Range.getBegin(), DiagID) |
| 3241 | << Range; |
| 3242 | } |
| 3243 | |
| 3244 | void MicrosoftCXXNameMangler::mangleType(const DecltypeType *T, Qualifiers, |
| 3245 | SourceRange Range) { |
| 3246 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3247 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 3248 | "cannot mangle this decltype() yet"); |
| 3249 | Diags.Report(Range.getBegin(), DiagID) |
| 3250 | << Range; |
| 3251 | } |
| 3252 | |
| 3253 | void MicrosoftCXXNameMangler::mangleType(const UnaryTransformType *T, |
| 3254 | Qualifiers, SourceRange Range) { |
| 3255 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3256 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 3257 | "cannot mangle this unary transform type yet"); |
| 3258 | Diags.Report(Range.getBegin(), DiagID) |
| 3259 | << Range; |
| 3260 | } |
| 3261 | |
| 3262 | void MicrosoftCXXNameMangler::mangleType(const AutoType *T, Qualifiers, |
| 3263 | SourceRange Range) { |
| 3264 | assert(T->getDeducedType().isNull() && "expecting a dependent type!"); |
| 3265 | |
| 3266 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3267 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 3268 | "cannot mangle this 'auto' type yet"); |
| 3269 | Diags.Report(Range.getBegin(), DiagID) |
| 3270 | << Range; |
| 3271 | } |
| 3272 | |
| 3273 | void MicrosoftCXXNameMangler::mangleType( |
| 3274 | const DeducedTemplateSpecializationType *T, Qualifiers, SourceRange Range) { |
| 3275 | assert(T->getDeducedType().isNull() && "expecting a dependent type!"); |
| 3276 | |
| 3277 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3278 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 3279 | "cannot mangle this deduced class template specialization type yet"); |
| 3280 | Diags.Report(Range.getBegin(), DiagID) |
| 3281 | << Range; |
| 3282 | } |
| 3283 | |
| 3284 | void MicrosoftCXXNameMangler::mangleType(const AtomicType *T, Qualifiers, |
| 3285 | SourceRange Range) { |
| 3286 | QualType ValueType = T->getValueType(); |
| 3287 | |
| 3288 | llvm::SmallString<64> TemplateMangling; |
| 3289 | llvm::raw_svector_ostream Stream(TemplateMangling); |
| 3290 | MicrosoftCXXNameMangler Extra(Context, Stream); |
| 3291 | Stream << "?$"; |
| 3292 | Extra.mangleSourceName("_Atomic"); |
| 3293 | Extra.mangleType(ValueType, Range, QMM_Escape); |
| 3294 | |
| 3295 | mangleArtificialTagType(TTK_Struct, TemplateMangling, {"__clang"}); |
| 3296 | } |
| 3297 | |
| 3298 | void MicrosoftCXXNameMangler::mangleType(const PipeType *T, Qualifiers, |
| 3299 | SourceRange Range) { |
| 3300 | QualType ElementType = T->getElementType(); |
| 3301 | |
| 3302 | llvm::SmallString<64> TemplateMangling; |
| 3303 | llvm::raw_svector_ostream Stream(TemplateMangling); |
| 3304 | MicrosoftCXXNameMangler Extra(Context, Stream); |
| 3305 | Stream << "?$"; |
| 3306 | Extra.mangleSourceName("ocl_pipe"); |
| 3307 | Extra.mangleType(ElementType, Range, QMM_Escape); |
| 3308 | Extra.mangleIntegerLiteral(llvm::APSInt::get(T->isReadOnly())); |
| 3309 | |
| 3310 | mangleArtificialTagType(TTK_Struct, TemplateMangling, {"__clang"}); |
| 3311 | } |
| 3312 | |
| 3313 | void MicrosoftMangleContextImpl::mangleCXXName(GlobalDecl GD, |
| 3314 | raw_ostream &Out) { |
| 3315 | const NamedDecl *D = cast<NamedDecl>(GD.getDecl()); |
| 3316 | PrettyStackTraceDecl CrashInfo(D, SourceLocation(), |
| 3317 | getASTContext().getSourceManager(), |
| 3318 | "Mangling declaration"); |
| 3319 | |
| 3320 | msvc_hashing_ostream MHO(Out); |
| 3321 | |
| 3322 | if (auto *CD = dyn_cast<CXXConstructorDecl>(D)) { |
| 3323 | auto Type = GD.getCtorType(); |
| 3324 | MicrosoftCXXNameMangler mangler(*this, MHO, CD, Type); |
| 3325 | return mangler.mangle(D); |
| 3326 | } |
| 3327 | |
| 3328 | if (auto *DD = dyn_cast<CXXDestructorDecl>(D)) { |
| 3329 | auto Type = GD.getDtorType(); |
| 3330 | MicrosoftCXXNameMangler mangler(*this, MHO, DD, Type); |
| 3331 | return mangler.mangle(D); |
| 3332 | } |
| 3333 | |
| 3334 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3335 | return Mangler.mangle(D); |
| 3336 | } |
| 3337 | |
| 3338 | void MicrosoftCXXNameMangler::mangleType(const ExtIntType *T, Qualifiers, |
| 3339 | SourceRange Range) { |
| 3340 | llvm::SmallString<64> TemplateMangling; |
| 3341 | llvm::raw_svector_ostream Stream(TemplateMangling); |
| 3342 | MicrosoftCXXNameMangler Extra(Context, Stream); |
| 3343 | Stream << "?$"; |
| 3344 | if (T->isUnsigned()) |
| 3345 | Extra.mangleSourceName("_UExtInt"); |
| 3346 | else |
| 3347 | Extra.mangleSourceName("_ExtInt"); |
| 3348 | Extra.mangleIntegerLiteral(llvm::APSInt::getUnsigned(T->getNumBits())); |
| 3349 | |
| 3350 | mangleArtificialTagType(TTK_Struct, TemplateMangling, {"__clang"}); |
| 3351 | } |
| 3352 | |
| 3353 | void MicrosoftCXXNameMangler::mangleType(const DependentExtIntType *T, |
| 3354 | Qualifiers, SourceRange Range) { |
| 3355 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 3356 | unsigned DiagID = Diags.getCustomDiagID( |
| 3357 | DiagnosticsEngine::Error, "cannot mangle this DependentExtInt type yet"); |
| 3358 | Diags.Report(Range.getBegin(), DiagID) << Range; |
| 3359 | } |
| 3360 | |
| 3361 | |
| 3362 | |
| 3363 | |
| 3364 | |
| 3365 | |
| 3366 | |
| 3367 | |
| 3368 | |
| 3369 | |
| 3370 | |
| 3371 | |
| 3372 | |
| 3373 | |
| 3374 | |
| 3375 | |
| 3376 | |
| 3377 | |
| 3378 | |
| 3379 | |
| 3380 | |
| 3381 | |
| 3382 | |
| 3383 | |
| 3384 | |
| 3385 | static void mangleThunkThisAdjustment(AccessSpecifier AS, |
| 3386 | const ThisAdjustment &Adjustment, |
| 3387 | MicrosoftCXXNameMangler &Mangler, |
| 3388 | raw_ostream &Out) { |
| 3389 | if (!Adjustment.Virtual.isEmpty()) { |
| 3390 | Out << '$'; |
| 3391 | char AccessSpec; |
| 3392 | switch (AS) { |
| 3393 | case AS_none: |
| 3394 | llvm_unreachable("Unsupported access specifier"); |
| 3395 | case AS_private: |
| 3396 | AccessSpec = '0'; |
| 3397 | break; |
| 3398 | case AS_protected: |
| 3399 | AccessSpec = '2'; |
| 3400 | break; |
| 3401 | case AS_public: |
| 3402 | AccessSpec = '4'; |
| 3403 | } |
| 3404 | if (Adjustment.Virtual.Microsoft.VBPtrOffset) { |
| 3405 | Out << 'R' << AccessSpec; |
| 3406 | Mangler.mangleNumber( |
| 3407 | static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VBPtrOffset)); |
| 3408 | Mangler.mangleNumber( |
| 3409 | static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VBOffsetOffset)); |
| 3410 | Mangler.mangleNumber( |
| 3411 | static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VtordispOffset)); |
| 3412 | Mangler.mangleNumber(static_cast<uint32_t>(Adjustment.NonVirtual)); |
| 3413 | } else { |
| 3414 | Out << AccessSpec; |
| 3415 | Mangler.mangleNumber( |
| 3416 | static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VtordispOffset)); |
| 3417 | Mangler.mangleNumber(-static_cast<uint32_t>(Adjustment.NonVirtual)); |
| 3418 | } |
| 3419 | } else if (Adjustment.NonVirtual != 0) { |
| 3420 | switch (AS) { |
| 3421 | case AS_none: |
| 3422 | llvm_unreachable("Unsupported access specifier"); |
| 3423 | case AS_private: |
| 3424 | Out << 'G'; |
| 3425 | break; |
| 3426 | case AS_protected: |
| 3427 | Out << 'O'; |
| 3428 | break; |
| 3429 | case AS_public: |
| 3430 | Out << 'W'; |
| 3431 | } |
| 3432 | Mangler.mangleNumber(-static_cast<uint32_t>(Adjustment.NonVirtual)); |
| 3433 | } else { |
| 3434 | switch (AS) { |
| 3435 | case AS_none: |
| 3436 | llvm_unreachable("Unsupported access specifier"); |
| 3437 | case AS_private: |
| 3438 | Out << 'A'; |
| 3439 | break; |
| 3440 | case AS_protected: |
| 3441 | Out << 'I'; |
| 3442 | break; |
| 3443 | case AS_public: |
| 3444 | Out << 'Q'; |
| 3445 | } |
| 3446 | } |
| 3447 | } |
| 3448 | |
| 3449 | void MicrosoftMangleContextImpl::mangleVirtualMemPtrThunk( |
| 3450 | const CXXMethodDecl *MD, const MethodVFTableLocation &ML, |
| 3451 | raw_ostream &Out) { |
| 3452 | msvc_hashing_ostream MHO(Out); |
| 3453 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3454 | Mangler.getStream() << '?'; |
| 3455 | Mangler.mangleVirtualMemPtrThunk(MD, ML); |
| 3456 | } |
| 3457 | |
| 3458 | void MicrosoftMangleContextImpl::mangleThunk(const CXXMethodDecl *MD, |
| 3459 | const ThunkInfo &Thunk, |
| 3460 | raw_ostream &Out) { |
| 3461 | msvc_hashing_ostream MHO(Out); |
| 3462 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3463 | Mangler.getStream() << '?'; |
| 3464 | Mangler.mangleName(MD); |
| 3465 | |
| 3466 | |
| 3467 | |
| 3468 | |
| 3469 | AccessSpecifier AS = Thunk.Return.isEmpty() ? MD->getAccess() : AS_public; |
| 3470 | mangleThunkThisAdjustment(AS, Thunk.This, Mangler, MHO); |
| 3471 | |
| 3472 | if (!Thunk.Return.isEmpty()) |
| 3473 | assert(Thunk.Method != nullptr && |
| 3474 | "Thunk info should hold the overridee decl"); |
| 3475 | |
| 3476 | const CXXMethodDecl *DeclForFPT = Thunk.Method ? Thunk.Method : MD; |
| 3477 | Mangler.mangleFunctionType( |
| 3478 | DeclForFPT->getType()->castAs<FunctionProtoType>(), MD); |
| 3479 | } |
| 3480 | |
| 3481 | void MicrosoftMangleContextImpl::mangleCXXDtorThunk( |
| 3482 | const CXXDestructorDecl *DD, CXXDtorType Type, |
| 3483 | const ThisAdjustment &Adjustment, raw_ostream &Out) { |
| 3484 | |
| 3485 | |
| 3486 | |
| 3487 | assert(Type == Dtor_Deleting); |
| 3488 | msvc_hashing_ostream MHO(Out); |
| 3489 | MicrosoftCXXNameMangler Mangler(*this, MHO, DD, Type); |
| 3490 | Mangler.getStream() << "??_E"; |
| 3491 | Mangler.mangleName(DD->getParent()); |
| 3492 | mangleThunkThisAdjustment(DD->getAccess(), Adjustment, Mangler, MHO); |
| 3493 | Mangler.mangleFunctionType(DD->getType()->castAs<FunctionProtoType>(), DD); |
| 1 | The object is a 'FunctionProtoType' | |
|
| 2 | | Calling 'MicrosoftCXXNameMangler::mangleFunctionType' | |
|
| 3494 | } |
| 3495 | |
| 3496 | void MicrosoftMangleContextImpl::mangleCXXVFTable( |
| 3497 | const CXXRecordDecl *Derived, ArrayRef<const CXXRecordDecl *> BasePath, |
| 3498 | raw_ostream &Out) { |
| 3499 | |
| 3500 | |
| 3501 | |
| 3502 | |
| 3503 | msvc_hashing_ostream MHO(Out); |
| 3504 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3505 | if (Derived->hasAttr<DLLImportAttr>()) |
| 3506 | Mangler.getStream() << "??_S"; |
| 3507 | else |
| 3508 | Mangler.getStream() << "??_7"; |
| 3509 | Mangler.mangleName(Derived); |
| 3510 | Mangler.getStream() << "6B"; |
| 3511 | for (const CXXRecordDecl *RD : BasePath) |
| 3512 | Mangler.mangleName(RD); |
| 3513 | Mangler.getStream() << '@'; |
| 3514 | } |
| 3515 | |
| 3516 | void MicrosoftMangleContextImpl::mangleCXXVBTable( |
| 3517 | const CXXRecordDecl *Derived, ArrayRef<const CXXRecordDecl *> BasePath, |
| 3518 | raw_ostream &Out) { |
| 3519 | |
| 3520 | |
| 3521 | |
| 3522 | |
| 3523 | msvc_hashing_ostream MHO(Out); |
| 3524 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3525 | Mangler.getStream() << "??_8"; |
| 3526 | Mangler.mangleName(Derived); |
| 3527 | Mangler.getStream() << "7B"; |
| 3528 | for (const CXXRecordDecl *RD : BasePath) |
| 3529 | Mangler.mangleName(RD); |
| 3530 | Mangler.getStream() << '@'; |
| 3531 | } |
| 3532 | |
| 3533 | void MicrosoftMangleContextImpl::mangleCXXRTTI(QualType T, raw_ostream &Out) { |
| 3534 | msvc_hashing_ostream MHO(Out); |
| 3535 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3536 | Mangler.getStream() << "??_R0"; |
| 3537 | Mangler.mangleType(T, SourceRange(), MicrosoftCXXNameMangler::QMM_Result); |
| 3538 | Mangler.getStream() << "@8"; |
| 3539 | } |
| 3540 | |
| 3541 | void MicrosoftMangleContextImpl::mangleCXXRTTIName(QualType T, |
| 3542 | raw_ostream &Out) { |
| 3543 | MicrosoftCXXNameMangler Mangler(*this, Out); |
| 3544 | Mangler.getStream() << '.'; |
| 3545 | Mangler.mangleType(T, SourceRange(), MicrosoftCXXNameMangler::QMM_Result); |
| 3546 | } |
| 3547 | |
| 3548 | void MicrosoftMangleContextImpl::mangleCXXVirtualDisplacementMap( |
| 3549 | const CXXRecordDecl *SrcRD, const CXXRecordDecl *DstRD, raw_ostream &Out) { |
| 3550 | msvc_hashing_ostream MHO(Out); |
| 3551 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3552 | Mangler.getStream() << "??_K"; |
| 3553 | Mangler.mangleName(SrcRD); |
| 3554 | Mangler.getStream() << "$C"; |
| 3555 | Mangler.mangleName(DstRD); |
| 3556 | } |
| 3557 | |
| 3558 | void MicrosoftMangleContextImpl::mangleCXXThrowInfo(QualType T, bool IsConst, |
| 3559 | bool IsVolatile, |
| 3560 | bool IsUnaligned, |
| 3561 | uint32_t NumEntries, |
| 3562 | raw_ostream &Out) { |
| 3563 | msvc_hashing_ostream MHO(Out); |
| 3564 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3565 | Mangler.getStream() << "_TI"; |
| 3566 | if (IsConst) |
| 3567 | Mangler.getStream() << 'C'; |
| 3568 | if (IsVolatile) |
| 3569 | Mangler.getStream() << 'V'; |
| 3570 | if (IsUnaligned) |
| 3571 | Mangler.getStream() << 'U'; |
| 3572 | Mangler.getStream() << NumEntries; |
| 3573 | Mangler.mangleType(T, SourceRange(), MicrosoftCXXNameMangler::QMM_Result); |
| 3574 | } |
| 3575 | |
| 3576 | void MicrosoftMangleContextImpl::mangleCXXCatchableTypeArray( |
| 3577 | QualType T, uint32_t NumEntries, raw_ostream &Out) { |
| 3578 | msvc_hashing_ostream MHO(Out); |
| 3579 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3580 | Mangler.getStream() << "_CTA"; |
| 3581 | Mangler.getStream() << NumEntries; |
| 3582 | Mangler.mangleType(T, SourceRange(), MicrosoftCXXNameMangler::QMM_Result); |
| 3583 | } |
| 3584 | |
| 3585 | void MicrosoftMangleContextImpl::mangleCXXCatchableType( |
| 3586 | QualType T, const CXXConstructorDecl *CD, CXXCtorType CT, uint32_t Size, |
| 3587 | uint32_t NVOffset, int32_t VBPtrOffset, uint32_t VBIndex, |
| 3588 | raw_ostream &Out) { |
| 3589 | MicrosoftCXXNameMangler Mangler(*this, Out); |
| 3590 | Mangler.getStream() << "_CT"; |
| 3591 | |
| 3592 | llvm::SmallString<64> RTTIMangling; |
| 3593 | { |
| 3594 | llvm::raw_svector_ostream Stream(RTTIMangling); |
| 3595 | msvc_hashing_ostream MHO(Stream); |
| 3596 | mangleCXXRTTI(T, MHO); |
| 3597 | } |
| 3598 | Mangler.getStream() << RTTIMangling; |
| 3599 | |
| 3600 | |
| 3601 | |
| 3602 | |
| 3603 | |
| 3604 | |
| 3605 | |
| 3606 | bool OmitCopyCtor = getASTContext().getLangOpts().isCompatibleWithMSVC( |
| 3607 | LangOptions::MSVC2015) && |
| 3608 | !getASTContext().getLangOpts().isCompatibleWithMSVC( |
| 3609 | LangOptions::MSVC2017_7); |
| 3610 | llvm::SmallString<64> CopyCtorMangling; |
| 3611 | if (!OmitCopyCtor && CD) { |
| 3612 | llvm::raw_svector_ostream Stream(CopyCtorMangling); |
| 3613 | msvc_hashing_ostream MHO(Stream); |
| 3614 | mangleCXXName(GlobalDecl(CD, CT), MHO); |
| 3615 | } |
| 3616 | Mangler.getStream() << CopyCtorMangling; |
| 3617 | |
| 3618 | Mangler.getStream() << Size; |
| 3619 | if (VBPtrOffset == -1) { |
| 3620 | if (NVOffset) { |
| 3621 | Mangler.getStream() << NVOffset; |
| 3622 | } |
| 3623 | } else { |
| 3624 | Mangler.getStream() << NVOffset; |
| 3625 | Mangler.getStream() << VBPtrOffset; |
| 3626 | Mangler.getStream() << VBIndex; |
| 3627 | } |
| 3628 | } |
| 3629 | |
| 3630 | void MicrosoftMangleContextImpl::mangleCXXRTTIBaseClassDescriptor( |
| 3631 | const CXXRecordDecl *Derived, uint32_t NVOffset, int32_t VBPtrOffset, |
| 3632 | uint32_t VBTableOffset, uint32_t Flags, raw_ostream &Out) { |
| 3633 | msvc_hashing_ostream MHO(Out); |
| 3634 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3635 | Mangler.getStream() << "??_R1"; |
| 3636 | Mangler.mangleNumber(NVOffset); |
| 3637 | Mangler.mangleNumber(VBPtrOffset); |
| 3638 | Mangler.mangleNumber(VBTableOffset); |
| 3639 | Mangler.mangleNumber(Flags); |
| 3640 | Mangler.mangleName(Derived); |
| 3641 | Mangler.getStream() << "8"; |
| 3642 | } |
| 3643 | |
| 3644 | void MicrosoftMangleContextImpl::mangleCXXRTTIBaseClassArray( |
| 3645 | const CXXRecordDecl *Derived, raw_ostream &Out) { |
| 3646 | msvc_hashing_ostream MHO(Out); |
| 3647 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3648 | Mangler.getStream() << "??_R2"; |
| 3649 | Mangler.mangleName(Derived); |
| 3650 | Mangler.getStream() << "8"; |
| 3651 | } |
| 3652 | |
| 3653 | void MicrosoftMangleContextImpl::mangleCXXRTTIClassHierarchyDescriptor( |
| 3654 | const CXXRecordDecl *Derived, raw_ostream &Out) { |
| 3655 | msvc_hashing_ostream MHO(Out); |
| 3656 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3657 | Mangler.getStream() << "??_R3"; |
| 3658 | Mangler.mangleName(Derived); |
| 3659 | Mangler.getStream() << "8"; |
| 3660 | } |
| 3661 | |
| 3662 | void MicrosoftMangleContextImpl::mangleCXXRTTICompleteObjectLocator( |
| 3663 | const CXXRecordDecl *Derived, ArrayRef<const CXXRecordDecl *> BasePath, |
| 3664 | raw_ostream &Out) { |
| 3665 | |
| 3666 | |
| 3667 | |
| 3668 | |
| 3669 | llvm::SmallString<64> VFTableMangling; |
| 3670 | llvm::raw_svector_ostream Stream(VFTableMangling); |
| 3671 | mangleCXXVFTable(Derived, BasePath, Stream); |
| 3672 | |
| 3673 | if (VFTableMangling.startswith("??@")) { |
| 3674 | assert(VFTableMangling.endswith("@")); |
| 3675 | Out << VFTableMangling << "??_R4@"; |
| 3676 | return; |
| 3677 | } |
| 3678 | |
| 3679 | assert(VFTableMangling.startswith("??_7") || |
| 3680 | VFTableMangling.startswith("??_S")); |
| 3681 | |
| 3682 | Out << "??_R4" << VFTableMangling.str().drop_front(4); |
| 3683 | } |
| 3684 | |
| 3685 | void MicrosoftMangleContextImpl::mangleSEHFilterExpression( |
| 3686 | const NamedDecl *EnclosingDecl, raw_ostream &Out) { |
| 3687 | msvc_hashing_ostream MHO(Out); |
| 3688 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3689 | |
| 3690 | |
| 3691 | |
| 3692 | |
| 3693 | Mangler.getStream() << "?filt$" << SEHFilterIds[EnclosingDecl]++ << "@0@"; |
| 3694 | Mangler.mangleName(EnclosingDecl); |
| 3695 | } |
| 3696 | |
| 3697 | void MicrosoftMangleContextImpl::mangleSEHFinallyBlock( |
| 3698 | const NamedDecl *EnclosingDecl, raw_ostream &Out) { |
| 3699 | msvc_hashing_ostream MHO(Out); |
| 3700 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3701 | |
| 3702 | |
| 3703 | |
| 3704 | |
| 3705 | Mangler.getStream() << "?fin$" << SEHFinallyIds[EnclosingDecl]++ << "@0@"; |
| 3706 | Mangler.mangleName(EnclosingDecl); |
| 3707 | } |
| 3708 | |
| 3709 | void MicrosoftMangleContextImpl::mangleTypeName(QualType T, raw_ostream &Out) { |
| 3710 | |
| 3711 | |
| 3712 | MicrosoftCXXNameMangler Mangler(*this, Out); |
| 3713 | Mangler.getStream() << '?'; |
| 3714 | Mangler.mangleType(T, SourceRange()); |
| 3715 | } |
| 3716 | |
| 3717 | void MicrosoftMangleContextImpl::mangleReferenceTemporary( |
| 3718 | const VarDecl *VD, unsigned ManglingNumber, raw_ostream &Out) { |
| 3719 | msvc_hashing_ostream MHO(Out); |
| 3720 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3721 | |
| 3722 | Mangler.getStream() << "?$RT" << ManglingNumber << '@'; |
| 3723 | Mangler.mangle(VD, ""); |
| 3724 | } |
| 3725 | |
| 3726 | void MicrosoftMangleContextImpl::mangleThreadSafeStaticGuardVariable( |
| 3727 | const VarDecl *VD, unsigned GuardNum, raw_ostream &Out) { |
| 3728 | msvc_hashing_ostream MHO(Out); |
| 3729 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3730 | |
| 3731 | Mangler.getStream() << "?$TSS" << GuardNum << '@'; |
| 3732 | Mangler.mangleNestedName(VD); |
| 3733 | Mangler.getStream() << "@4HA"; |
| 3734 | } |
| 3735 | |
| 3736 | void MicrosoftMangleContextImpl::mangleStaticGuardVariable(const VarDecl *VD, |
| 3737 | raw_ostream &Out) { |
| 3738 | |
| 3739 | |
| 3740 | |
| 3741 | |
| 3742 | |
| 3743 | |
| 3744 | |
| 3745 | |
| 3746 | |
| 3747 | |
| 3748 | msvc_hashing_ostream MHO(Out); |
| 3749 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3750 | |
| 3751 | bool Visible = VD->isExternallyVisible(); |
| 3752 | if (Visible) { |
| 3753 | Mangler.getStream() << (VD->getTLSKind() ? "??__J" : "??_B"); |
| 3754 | } else { |
| 3755 | Mangler.getStream() << "?$S1@"; |
| 3756 | } |
| 3757 | unsigned ScopeDepth = 0; |
| 3758 | if (Visible && !getNextDiscriminator(VD, ScopeDepth)) |
| 3759 | |
| 3760 | |
| 3761 | |
| 3762 | Mangler.mangle(VD, ""); |
| 3763 | else |
| 3764 | Mangler.mangleNestedName(VD); |
| 3765 | Mangler.getStream() << (Visible ? "@5" : "@4IA"); |
| 3766 | if (ScopeDepth) |
| 3767 | Mangler.mangleNumber(ScopeDepth); |
| 3768 | } |
| 3769 | |
| 3770 | void MicrosoftMangleContextImpl::mangleInitFiniStub(const VarDecl *D, |
| 3771 | char CharCode, |
| 3772 | raw_ostream &Out) { |
| 3773 | msvc_hashing_ostream MHO(Out); |
| 3774 | MicrosoftCXXNameMangler Mangler(*this, MHO); |
| 3775 | Mangler.getStream() << "??__" << CharCode; |
| 3776 | if (D->isStaticDataMember()) { |
| 3777 | Mangler.getStream() << '?'; |
| 3778 | Mangler.mangleName(D); |
| 3779 | Mangler.mangleVariableEncoding(D); |
| 3780 | Mangler.getStream() << "@@"; |
| 3781 | } else { |
| 3782 | Mangler.mangleName(D); |
| 3783 | } |
| 3784 | |
| 3785 | |
| 3786 | Mangler.getStream() << "YAXXZ"; |
| 3787 | } |
| 3788 | |
| 3789 | void MicrosoftMangleContextImpl::mangleDynamicInitializer(const VarDecl *D, |
| 3790 | raw_ostream &Out) { |
| 3791 | |
| 3792 | mangleInitFiniStub(D, 'E', Out); |
| 3793 | } |
| 3794 | |
| 3795 | void |
| 3796 | MicrosoftMangleContextImpl::mangleDynamicAtExitDestructor(const VarDecl *D, |
| 3797 | raw_ostream &Out) { |
| 3798 | |
| 3799 | mangleInitFiniStub(D, 'F', Out); |
| 3800 | } |
| 3801 | |
| 3802 | void MicrosoftMangleContextImpl::mangleStringLiteral(const StringLiteral *SL, |
| 3803 | raw_ostream &Out) { |
| 3804 | |
| 3805 | |
| 3806 | |
| 3807 | |
| 3808 | |
| 3809 | |
| 3810 | |
| 3811 | |
| 3812 | |
| 3813 | |
| 3814 | |
| 3815 | |
| 3816 | |
| 3817 | |
| 3818 | |
| 3819 | |
| 3820 | |
| 3821 | |
| 3822 | |
| 3823 | MicrosoftCXXNameMangler Mangler(*this, Out); |
| 3824 | Mangler.getStream() << "??_C@_"; |
| 3825 | |
| 3826 | |
| 3827 | |
| 3828 | |
| 3829 | |
| 3830 | |
| 3831 | |
| 3832 | unsigned StringLength = getASTContext() |
| 3833 | .getAsConstantArrayType(SL->getType()) |
| 3834 | ->getSize() |
| 3835 | .getZExtValue(); |
| 3836 | unsigned StringByteLength = StringLength * SL->getCharByteWidth(); |
| 3837 | |
| 3838 | |
| 3839 | if (SL->isWide()) |
| 3840 | Mangler.getStream() << '1'; |
| 3841 | else |
| 3842 | Mangler.getStream() << '0'; |
| 3843 | |
| 3844 | |
| 3845 | |
| 3846 | Mangler.mangleNumber(StringByteLength); |
| 3847 | |
| 3848 | auto GetLittleEndianByte = [&SL](unsigned Index) { |
| 3849 | unsigned CharByteWidth = SL->getCharByteWidth(); |
| 3850 | if (Index / CharByteWidth >= SL->getLength()) |
| 3851 | return static_cast<char>(0); |
| 3852 | uint32_t CodeUnit = SL->getCodeUnit(Index / CharByteWidth); |
| 3853 | unsigned OffsetInCodeUnit = Index % CharByteWidth; |
| 3854 | return static_cast<char>((CodeUnit >> (8 * OffsetInCodeUnit)) & 0xff); |
| 3855 | }; |
| 3856 | |
| 3857 | auto GetBigEndianByte = [&SL](unsigned Index) { |
| 3858 | unsigned CharByteWidth = SL->getCharByteWidth(); |
| 3859 | if (Index / CharByteWidth >= SL->getLength()) |
| 3860 | return static_cast<char>(0); |
| 3861 | uint32_t CodeUnit = SL->getCodeUnit(Index / CharByteWidth); |
| 3862 | unsigned OffsetInCodeUnit = (CharByteWidth - 1) - (Index % CharByteWidth); |
| 3863 | return static_cast<char>((CodeUnit >> (8 * OffsetInCodeUnit)) & 0xff); |
| 3864 | }; |
| 3865 | |
| 3866 | |
| 3867 | llvm::JamCRC JC; |
| 3868 | for (unsigned I = 0, E = StringByteLength; I != E; ++I) |
| 3869 | JC.update(GetLittleEndianByte(I)); |
| 3870 | |
| 3871 | |
| 3872 | |
| 3873 | Mangler.mangleNumber(JC.getCRC()); |
| 3874 | |
| 3875 | |
| 3876 | |
| 3877 | |
| 3878 | |
| 3879 | auto MangleByte = [&Mangler](char Byte) { |
| 3880 | |
| 3881 | |
| 3882 | |
| 3883 | |
| 3884 | |
| 3885 | |
| 3886 | if (isIdentifierBody(Byte, true)) { |
| 3887 | Mangler.getStream() << Byte; |
| 3888 | } else if (isLetter(Byte & 0x7f)) { |
| 3889 | Mangler.getStream() << '?' << static_cast<char>(Byte & 0x7f); |
| 3890 | } else { |
| 3891 | const char SpecialChars[] = {',', '/', '\\', ':', '.', |
| 3892 | ' ', '\n', '\t', '\'', '-'}; |
| 3893 | const char *Pos = llvm::find(SpecialChars, Byte); |
| 3894 | if (Pos != std::end(SpecialChars)) { |
| 3895 | Mangler.getStream() << '?' << (Pos - std::begin(SpecialChars)); |
| 3896 | } else { |
| 3897 | Mangler.getStream() << "?$"; |
| 3898 | Mangler.getStream() << static_cast<char>('A' + ((Byte >> 4) & 0xf)); |
| 3899 | Mangler.getStream() << static_cast<char>('A' + (Byte & 0xf)); |
| 3900 | } |
| 3901 | } |
| 3902 | }; |
| 3903 | |
| 3904 | |
| 3905 | unsigned MaxBytesToMangle = SL->isWide() ? 64U : 32U; |
| 3906 | unsigned NumBytesToMangle = std::min(MaxBytesToMangle, StringByteLength); |
| 3907 | for (unsigned I = 0; I != NumBytesToMangle; ++I) { |
| 3908 | if (SL->isWide()) |
| 3909 | MangleByte(GetBigEndianByte(I)); |
| 3910 | else |
| 3911 | MangleByte(GetLittleEndianByte(I)); |
| 3912 | } |
| 3913 | |
| 3914 | Mangler.getStream() << '@'; |
| 3915 | } |
| 3916 | |
| 3917 | MicrosoftMangleContext * |
| 3918 | MicrosoftMangleContext::create(ASTContext &Context, DiagnosticsEngine &Diags) { |
| 3919 | return new MicrosoftMangleContextImpl(Context, Diags); |
| 3920 | } |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | #ifndef LLVM_CLANG_AST_DECLCXX_H |
| 16 | #define LLVM_CLANG_AST_DECLCXX_H |
| 17 | |
| 18 | #include "clang/AST/ASTUnresolvedSet.h" |
| 19 | #include "clang/AST/Decl.h" |
| 20 | #include "clang/AST/DeclBase.h" |
| 21 | #include "clang/AST/DeclarationName.h" |
| 22 | #include "clang/AST/Expr.h" |
| 23 | #include "clang/AST/ExternalASTSource.h" |
| 24 | #include "clang/AST/LambdaCapture.h" |
| 25 | #include "clang/AST/NestedNameSpecifier.h" |
| 26 | #include "clang/AST/Redeclarable.h" |
| 27 | #include "clang/AST/Stmt.h" |
| 28 | #include "clang/AST/Type.h" |
| 29 | #include "clang/AST/TypeLoc.h" |
| 30 | #include "clang/AST/UnresolvedSet.h" |
| 31 | #include "clang/Basic/LLVM.h" |
| 32 | #include "clang/Basic/Lambda.h" |
| 33 | #include "clang/Basic/LangOptions.h" |
| 34 | #include "clang/Basic/OperatorKinds.h" |
| 35 | #include "clang/Basic/SourceLocation.h" |
| 36 | #include "clang/Basic/Specifiers.h" |
| 37 | #include "llvm/ADT/ArrayRef.h" |
| 38 | #include "llvm/ADT/DenseMap.h" |
| 39 | #include "llvm/ADT/PointerIntPair.h" |
| 40 | #include "llvm/ADT/PointerUnion.h" |
| 41 | #include "llvm/ADT/STLExtras.h" |
| 42 | #include "llvm/ADT/TinyPtrVector.h" |
| 43 | #include "llvm/ADT/iterator_range.h" |
| 44 | #include "llvm/Support/Casting.h" |
| 45 | #include "llvm/Support/Compiler.h" |
| 46 | #include "llvm/Support/PointerLikeTypeTraits.h" |
| 47 | #include "llvm/Support/TrailingObjects.h" |
| 48 | #include <cassert> |
| 49 | #include <cstddef> |
| 50 | #include <iterator> |
| 51 | #include <memory> |
| 52 | #include <vector> |
| 53 | |
| 54 | namespace clang { |
| 55 | |
| 56 | class ASTContext; |
| 57 | class ClassTemplateDecl; |
| 58 | class ConstructorUsingShadowDecl; |
| 59 | class CXXBasePath; |
| 60 | class CXXBasePaths; |
| 61 | class CXXConstructorDecl; |
| 62 | class CXXDestructorDecl; |
| 63 | class CXXFinalOverriderMap; |
| 64 | class CXXIndirectPrimaryBaseSet; |
| 65 | class CXXMethodDecl; |
| 66 | class DecompositionDecl; |
| 67 | class DiagnosticBuilder; |
| 68 | class FriendDecl; |
| 69 | class FunctionTemplateDecl; |
| 70 | class IdentifierInfo; |
| 71 | class MemberSpecializationInfo; |
| 72 | class BaseUsingDecl; |
| 73 | class TemplateDecl; |
| 74 | class TemplateParameterList; |
| 75 | class UsingDecl; |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | class AccessSpecDecl : public Decl { |
| 88 | |
| 89 | SourceLocation ColonLoc; |
| 90 | |
| 91 | AccessSpecDecl(AccessSpecifier AS, DeclContext *DC, |
| 92 | SourceLocation ASLoc, SourceLocation ColonLoc) |
| 93 | : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) { |
| 94 | setAccess(AS); |
| 95 | } |
| 96 | |
| 97 | AccessSpecDecl(EmptyShell Empty) : Decl(AccessSpec, Empty) {} |
| 98 | |
| 99 | virtual void anchor(); |
| 100 | |
| 101 | public: |
| 102 | |
| 103 | SourceLocation getAccessSpecifierLoc() const { return getLocation(); } |
| 104 | |
| 105 | |
| 106 | void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); } |
| 107 | |
| 108 | |
| 109 | SourceLocation getColonLoc() const { return ColonLoc; } |
| 110 | |
| 111 | |
| 112 | void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; } |
| 113 | |
| 114 | SourceRange getSourceRange() const override LLVM_READONLY { |
| 115 | return SourceRange(getAccessSpecifierLoc(), getColonLoc()); |
| 116 | } |
| 117 | |
| 118 | static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS, |
| 119 | DeclContext *DC, SourceLocation ASLoc, |
| 120 | SourceLocation ColonLoc) { |
| 121 | return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc); |
| 122 | } |
| 123 | |
| 124 | static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 125 | |
| 126 | |
| 127 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 128 | static bool classofKind(Kind K) { return K == AccessSpec; } |
| 129 | }; |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | class CXXBaseSpecifier { |
| 148 | |
| 149 | |
| 150 | |
| 151 | SourceRange Range; |
| 152 | |
| 153 | |
| 154 | |
| 155 | SourceLocation EllipsisLoc; |
| 156 | |
| 157 | |
| 158 | unsigned Virtual : 1; |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | unsigned BaseOfClass : 1; |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | unsigned Access : 2; |
| 171 | |
| 172 | |
| 173 | |
| 174 | unsigned InheritConstructors : 1; |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | TypeSourceInfo *BaseTypeInfo; |
| 181 | |
| 182 | public: |
| 183 | CXXBaseSpecifier() = default; |
| 184 | CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, |
| 185 | TypeSourceInfo *TInfo, SourceLocation EllipsisLoc) |
| 186 | : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC), |
| 187 | Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) {} |
| 188 | |
| 189 | |
| 190 | SourceRange getSourceRange() const LLVM_READONLY { return Range; } |
| 191 | SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); } |
| 192 | SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); } |
| 193 | |
| 194 | |
| 195 | SourceLocation getBaseTypeLoc() const LLVM_READONLY { |
| 196 | return BaseTypeInfo->getTypeLoc().getBeginLoc(); |
| 197 | } |
| 198 | |
| 199 | |
| 200 | bool isVirtual() const { return Virtual; } |
| 201 | |
| 202 | |
| 203 | |
| 204 | bool isBaseOfClass() const { return BaseOfClass; } |
| 205 | |
| 206 | |
| 207 | bool isPackExpansion() const { return EllipsisLoc.isValid(); } |
| 208 | |
| 209 | |
| 210 | bool getInheritConstructors() const { return InheritConstructors; } |
| 211 | |
| 212 | |
| 213 | void setInheritConstructors(bool Inherit = true) { |
| 214 | InheritConstructors = Inherit; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | SourceLocation getEllipsisLoc() const { |
| 219 | return EllipsisLoc; |
| 220 | } |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | AccessSpecifier getAccessSpecifier() const { |
| 228 | if ((AccessSpecifier)Access == AS_none) |
| 229 | return BaseOfClass? AS_private : AS_public; |
| 230 | else |
| 231 | return (AccessSpecifier)Access; |
| 232 | } |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | AccessSpecifier getAccessSpecifierAsWritten() const { |
| 240 | return (AccessSpecifier)Access; |
| 241 | } |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | QualType getType() const { |
| 247 | return BaseTypeInfo->getType().getUnqualifiedType(); |
| 248 | } |
| 249 | |
| 250 | |
| 251 | TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; } |
| 252 | }; |
| 253 | |
| 254 | |
| 255 | class CXXRecordDecl : public RecordDecl { |
| 256 | friend class ASTDeclReader; |
| 257 | friend class ASTDeclWriter; |
| 258 | friend class ASTNodeImporter; |
| 259 | friend class ASTReader; |
| 260 | friend class ASTRecordWriter; |
| 261 | friend class ASTWriter; |
| 262 | friend class DeclContext; |
| 263 | friend class LambdaExpr; |
| 264 | |
| 265 | friend void FunctionDecl::setPure(bool); |
| 266 | friend void TagDecl::startDefinition(); |
| 267 | |
| 268 | |
| 269 | enum SpecialMemberFlags { |
| 270 | SMF_DefaultConstructor = 0x1, |
| 271 | SMF_CopyConstructor = 0x2, |
| 272 | SMF_MoveConstructor = 0x4, |
| 273 | SMF_CopyAssignment = 0x8, |
| 274 | SMF_MoveAssignment = 0x10, |
| 275 | SMF_Destructor = 0x20, |
| 276 | SMF_All = 0x3f |
| 277 | }; |
| 278 | |
| 279 | struct DefinitionData { |
| 280 | #define FIELD(Name, Width, Merge) \ |
| 281 | unsigned Name : Width; |
| 282 | #include "CXXRecordDeclDefinitionBits.def" |
| 283 | |
| 284 | |
| 285 | unsigned IsLambda : 1; |
| 286 | |
| 287 | |
| 288 | unsigned IsParsingBaseSpecifiers : 1; |
| 289 | |
| 290 | |
| 291 | |
| 292 | unsigned ComputedVisibleConversions : 1; |
| 293 | |
| 294 | unsigned HasODRHash : 1; |
| 295 | |
| 296 | |
| 297 | unsigned ODRHash = 0; |
| 298 | |
| 299 | |
| 300 | unsigned NumBases = 0; |
| 301 | |
| 302 | |
| 303 | unsigned NumVBases = 0; |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | LazyCXXBaseSpecifiersPtr Bases; |
| 309 | |
| 310 | |
| 311 | LazyCXXBaseSpecifiersPtr VBases; |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | LazyASTUnresolvedSet Conversions; |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | LazyASTUnresolvedSet VisibleConversions; |
| 325 | |
| 326 | |
| 327 | CXXRecordDecl *Definition; |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | LazyDeclPtr FirstFriend; |
| 334 | |
| 335 | DefinitionData(CXXRecordDecl *D); |
| 336 | |
| 337 | |
| 338 | CXXBaseSpecifier *getBases() const { |
| 339 | if (!Bases.isOffset()) |
| 340 | return Bases.get(nullptr); |
| 341 | return getBasesSlowCase(); |
| 342 | } |
| 343 | |
| 344 | |
| 345 | CXXBaseSpecifier *getVBases() const { |
| 346 | if (!VBases.isOffset()) |
| 347 | return VBases.get(nullptr); |
| 348 | return getVBasesSlowCase(); |
| 349 | } |
| 350 | |
| 351 | ArrayRef<CXXBaseSpecifier> bases() const { |
| 352 | return llvm::makeArrayRef(getBases(), NumBases); |
| 353 | } |
| 354 | |
| 355 | ArrayRef<CXXBaseSpecifier> vbases() const { |
| 356 | return llvm::makeArrayRef(getVBases(), NumVBases); |
| 357 | } |
| 358 | |
| 359 | private: |
| 360 | CXXBaseSpecifier *getBasesSlowCase() const; |
| 361 | CXXBaseSpecifier *getVBasesSlowCase() const; |
| 362 | }; |
| 363 | |
| 364 | struct DefinitionData *DefinitionData; |
| 365 | |
| 366 | |
| 367 | struct LambdaDefinitionData : public DefinitionData { |
| 368 | using Capture = LambdaCapture; |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | unsigned Dependent : 1; |
| 379 | |
| 380 | |
| 381 | unsigned IsGenericLambda : 1; |
| 382 | |
| 383 | |
| 384 | unsigned CaptureDefault : 2; |
| 385 | |
| 386 | |
| 387 | unsigned NumCaptures : 15; |
| 388 | |
| 389 | |
| 390 | unsigned NumExplicitCaptures : 13; |
| 391 | |
| 392 | |
| 393 | unsigned HasKnownInternalLinkage : 1; |
| 394 | |
| 395 | |
| 396 | |
| 397 | unsigned ManglingNumber : 31; |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | LazyDeclPtr ContextDecl; |
| 404 | |
| 405 | |
| 406 | |
| 407 | Capture *Captures = nullptr; |
| 408 | |
| 409 | |
| 410 | TypeSourceInfo *MethodTyInfo; |
| 411 | |
| 412 | LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, bool Dependent, |
| 413 | bool IsGeneric, LambdaCaptureDefault CaptureDefault) |
| 414 | : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric), |
| 415 | CaptureDefault(CaptureDefault), NumCaptures(0), |
| 416 | NumExplicitCaptures(0), HasKnownInternalLinkage(0), ManglingNumber(0), |
| 417 | MethodTyInfo(Info) { |
| 418 | IsLambda = true; |
| 419 | |
| 420 | |
| 421 | |
| 422 | Aggregate = false; |
| 423 | PlainOldData = false; |
| 424 | } |
| 425 | }; |
| 426 | |
| 427 | struct DefinitionData *dataPtr() const { |
| 428 | |
| 429 | getMostRecentDecl(); |
| 430 | return DefinitionData; |
| 431 | } |
| 432 | |
| 433 | struct DefinitionData &data() const { |
| 434 | auto *DD = dataPtr(); |
| 435 | assert(DD && "queried property of class with no definition"); |
| 436 | return *DD; |
| 437 | } |
| 438 | |
| 439 | struct LambdaDefinitionData &getLambdaData() const { |
| 440 | |
| 441 | |
| 442 | auto *DD = DefinitionData; |
| 443 | assert(DD && DD->IsLambda && "queried lambda property of non-lambda class"); |
| 444 | return static_cast<LambdaDefinitionData&>(*DD); |
| 445 | } |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | llvm::PointerUnion<ClassTemplateDecl *, MemberSpecializationInfo *> |
| 457 | TemplateOrInstantiation; |
| 458 | |
| 459 | |
| 460 | |
| 461 | void addedClassSubobject(CXXRecordDecl *Base); |
| 462 | |
| 463 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | void addedMember(Decl *D); |
| 469 | |
| 470 | void markedVirtualFunctionPure(); |
| 471 | |
| 472 | |
| 473 | |
| 474 | FriendDecl *getFirstFriend() const; |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | bool hasSubobjectAtOffsetZeroOfEmptyBaseType(ASTContext &Ctx, |
| 480 | const CXXRecordDecl *X); |
| 481 | |
| 482 | protected: |
| 483 | CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC, |
| 484 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 485 | IdentifierInfo *Id, CXXRecordDecl *PrevDecl); |
| 486 | |
| 487 | public: |
| 488 | |
| 489 | using base_class_iterator = CXXBaseSpecifier *; |
| 490 | |
| 491 | |
| 492 | using base_class_const_iterator = const CXXBaseSpecifier *; |
| 493 | |
| 494 | CXXRecordDecl *getCanonicalDecl() override { |
| 495 | return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); |
| 496 | } |
| 497 | |
| 498 | const CXXRecordDecl *getCanonicalDecl() const { |
| 499 | return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl(); |
| 500 | } |
| 501 | |
| 502 | CXXRecordDecl *getPreviousDecl() { |
| 503 | return cast_or_null<CXXRecordDecl>( |
| 504 | static_cast<RecordDecl *>(this)->getPreviousDecl()); |
| 505 | } |
| 506 | |
| 507 | const CXXRecordDecl *getPreviousDecl() const { |
| 508 | return const_cast<CXXRecordDecl*>(this)->getPreviousDecl(); |
| 509 | } |
| 510 | |
| 511 | CXXRecordDecl *getMostRecentDecl() { |
| 512 | return cast<CXXRecordDecl>( |
| 513 | static_cast<RecordDecl *>(this)->getMostRecentDecl()); |
| 514 | } |
| 515 | |
| 516 | const CXXRecordDecl *getMostRecentDecl() const { |
| 517 | return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl(); |
| 518 | } |
| 519 | |
| 520 | CXXRecordDecl *getMostRecentNonInjectedDecl() { |
| 521 | CXXRecordDecl *Recent = |
| 522 | static_cast<CXXRecordDecl *>(this)->getMostRecentDecl(); |
| 523 | while (Recent->isInjectedClassName()) { |
| 524 | |
| 525 | assert(Recent->getPreviousDecl()); |
| 526 | Recent = Recent->getPreviousDecl(); |
| 527 | } |
| 528 | return Recent; |
| 529 | } |
| 530 | |
| 531 | const CXXRecordDecl *getMostRecentNonInjectedDecl() const { |
| 532 | return const_cast<CXXRecordDecl*>(this)->getMostRecentNonInjectedDecl(); |
| 533 | } |
| 534 | |
| 535 | CXXRecordDecl *getDefinition() const { |
| 536 | |
| 537 | |
| 538 | auto *DD = DefinitionData ? DefinitionData : dataPtr(); |
| 539 | return DD ? DD->Definition : nullptr; |
| 540 | } |
| 541 | |
| 542 | bool hasDefinition() const { return DefinitionData || dataPtr(); } |
| 543 | |
| 544 | static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, |
| 545 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 546 | IdentifierInfo *Id, |
| 547 | CXXRecordDecl *PrevDecl = nullptr, |
| 548 | bool DelayTypeCreation = false); |
| 549 | static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC, |
| 550 | TypeSourceInfo *Info, SourceLocation Loc, |
| 551 | bool DependentLambda, bool IsGeneric, |
| 552 | LambdaCaptureDefault CaptureDefault); |
| 553 | static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID); |
| 554 | |
| 555 | bool isDynamicClass() const { |
| 556 | return data().Polymorphic || data().NumVBases != 0; |
| 557 | } |
| 558 | |
| 559 | |
| 560 | |
| 561 | bool mayBeDynamicClass() const { |
| 562 | return !hasDefinition() || isDynamicClass() || hasAnyDependentBases(); |
| 563 | } |
| 564 | |
| 565 | |
| 566 | |
| 567 | bool mayBeNonDynamicClass() const { |
| 568 | return !hasDefinition() || !isDynamicClass() || hasAnyDependentBases(); |
| 569 | } |
| 570 | |
| 571 | void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; } |
| 572 | |
| 573 | bool isParsingBaseSpecifiers() const { |
| 574 | return data().IsParsingBaseSpecifiers; |
| 575 | } |
| 576 | |
| 577 | unsigned getODRHash() const; |
| 578 | |
| 579 | |
| 580 | void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases); |
| 581 | |
| 582 | |
| 583 | unsigned getNumBases() const { return data().NumBases; } |
| 584 | |
| 585 | using base_class_range = llvm::iterator_range<base_class_iterator>; |
| 586 | using base_class_const_range = |
| 587 | llvm::iterator_range<base_class_const_iterator>; |
| 588 | |
| 589 | base_class_range bases() { |
| 590 | return base_class_range(bases_begin(), bases_end()); |
| 591 | } |
| 592 | base_class_const_range bases() const { |
| 593 | return base_class_const_range(bases_begin(), bases_end()); |
| 594 | } |
| 595 | |
| 596 | base_class_iterator bases_begin() { return data().getBases(); } |
| 597 | base_class_const_iterator bases_begin() const { return data().getBases(); } |
| 598 | base_class_iterator bases_end() { return bases_begin() + data().NumBases; } |
| 599 | base_class_const_iterator bases_end() const { |
| 600 | return bases_begin() + data().NumBases; |
| 601 | } |
| 602 | |
| 603 | |
| 604 | unsigned getNumVBases() const { return data().NumVBases; } |
| 605 | |
| 606 | base_class_range vbases() { |
| 607 | return base_class_range(vbases_begin(), vbases_end()); |
| 608 | } |
| 609 | base_class_const_range vbases() const { |
| 610 | return base_class_const_range(vbases_begin(), vbases_end()); |
| 611 | } |
| 612 | |
| 613 | base_class_iterator vbases_begin() { return data().getVBases(); } |
| 614 | base_class_const_iterator vbases_begin() const { return data().getVBases(); } |
| 615 | base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; } |
| 616 | base_class_const_iterator vbases_end() const { |
| 617 | return vbases_begin() + data().NumVBases; |
| 618 | } |
| 619 | |
| 620 | |
| 621 | |
| 622 | bool hasAnyDependentBases() const; |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | using method_iterator = specific_decl_iterator<CXXMethodDecl>; |
| 628 | using method_range = |
| 629 | llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>; |
| 630 | |
| 631 | method_range methods() const { |
| 632 | return method_range(method_begin(), method_end()); |
| 633 | } |
| 634 | |
| 635 | |
| 636 | |
| 637 | method_iterator method_begin() const { |
| 638 | return method_iterator(decls_begin()); |
| 639 | } |
| 640 | |
| 641 | |
| 642 | method_iterator method_end() const { |
| 643 | return method_iterator(decls_end()); |
| 644 | } |
| 645 | |
| 646 | |
| 647 | using ctor_iterator = specific_decl_iterator<CXXConstructorDecl>; |
| 648 | using ctor_range = |
| 649 | llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>; |
| 650 | |
| 651 | ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); } |
| 652 | |
| 653 | ctor_iterator ctor_begin() const { |
| 654 | return ctor_iterator(decls_begin()); |
| 655 | } |
| 656 | |
| 657 | ctor_iterator ctor_end() const { |
| 658 | return ctor_iterator(decls_end()); |
| 659 | } |
| 660 | |
| 661 | |
| 662 | |
| 663 | class friend_iterator; |
| 664 | using friend_range = llvm::iterator_range<friend_iterator>; |
| 665 | |
| 666 | friend_range friends() const; |
| 667 | friend_iterator friend_begin() const; |
| 668 | friend_iterator friend_end() const; |
| 669 | void pushFriendDecl(FriendDecl *FD); |
| 670 | |
| 671 | |
| 672 | bool hasFriends() const { |
| 673 | return data().FirstFriend.isValid(); |
| 674 | } |
| 675 | |
| 676 | |
| 677 | |
| 678 | bool defaultedCopyConstructorIsDeleted() const { |
| 679 | assert((!needsOverloadResolutionForCopyConstructor() || |
| 680 | (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && |
| 681 | "this property has not yet been computed by Sema"); |
| 682 | return data().DefaultedCopyConstructorIsDeleted; |
| 683 | } |
| 684 | |
| 685 | |
| 686 | |
| 687 | bool defaultedMoveConstructorIsDeleted() const { |
| 688 | assert((!needsOverloadResolutionForMoveConstructor() || |
| 689 | (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && |
| 690 | "this property has not yet been computed by Sema"); |
| 691 | return data().DefaultedMoveConstructorIsDeleted; |
| 692 | } |
| 693 | |
| 694 | |
| 695 | bool defaultedDestructorIsDeleted() const { |
| 696 | assert((!needsOverloadResolutionForDestructor() || |
| 697 | (data().DeclaredSpecialMembers & SMF_Destructor)) && |
| 698 | "this property has not yet been computed by Sema"); |
| 699 | return data().DefaultedDestructorIsDeleted; |
| 700 | } |
| 701 | |
| 702 | |
| 703 | |
| 704 | bool hasSimpleCopyConstructor() const { |
| 705 | return !hasUserDeclaredCopyConstructor() && |
| 706 | !data().DefaultedCopyConstructorIsDeleted; |
| 707 | } |
| 708 | |
| 709 | |
| 710 | |
| 711 | bool hasSimpleMoveConstructor() const { |
| 712 | return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() && |
| 713 | !data().DefaultedMoveConstructorIsDeleted; |
| 714 | } |
| 715 | |
| 716 | |
| 717 | |
| 718 | bool hasSimpleCopyAssignment() const { |
| 719 | return !hasUserDeclaredCopyAssignment() && |
| 720 | !data().DefaultedCopyAssignmentIsDeleted; |
| 721 | } |
| 722 | |
| 723 | |
| 724 | |
| 725 | bool hasSimpleMoveAssignment() const { |
| 726 | return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() && |
| 727 | !data().DefaultedMoveAssignmentIsDeleted; |
| 728 | } |
| 729 | |
| 730 | |
| 731 | |
| 732 | bool hasSimpleDestructor() const { |
| 733 | return !hasUserDeclaredDestructor() && |
| 734 | !data().DefaultedDestructorIsDeleted; |
| 735 | } |
| 736 | |
| 737 | |
| 738 | bool hasDefaultConstructor() const { |
| 739 | return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) || |
| 740 | needsImplicitDefaultConstructor(); |
| 741 | } |
| 742 | |
| 743 | |
| 744 | |
| 745 | |
| 746 | |
| 747 | bool needsImplicitDefaultConstructor() const { |
| 748 | return (!data().UserDeclaredConstructor && |
| 749 | !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) && |
| 750 | (!isLambda() || lambdaIsDefaultConstructibleAndAssignable())) || |
| 751 | |
| 752 | |
| 753 | |
| 754 | (data().HasInheritedDefaultConstructor && |
| 755 | !(data().DeclaredSpecialMembers & SMF_DefaultConstructor)); |
| 756 | } |
| 757 | |
| 758 | |
| 759 | |
| 760 | |
| 761 | bool hasUserDeclaredConstructor() const { |
| 762 | return data().UserDeclaredConstructor; |
| 763 | } |
| 764 | |
| 765 | |
| 766 | |
| 767 | bool hasUserProvidedDefaultConstructor() const { |
| 768 | return data().UserProvidedDefaultConstructor; |
| 769 | } |
| 770 | |
| 771 | |
| 772 | |
| 773 | |
| 774 | bool hasUserDeclaredCopyConstructor() const { |
| 775 | return data().UserDeclaredSpecialMembers & SMF_CopyConstructor; |
| 776 | } |
| 777 | |
| 778 | |
| 779 | |
| 780 | bool needsImplicitCopyConstructor() const { |
| 781 | return !(data().DeclaredSpecialMembers & SMF_CopyConstructor); |
| 782 | } |
| 783 | |
| 784 | |
| 785 | |
| 786 | bool needsOverloadResolutionForCopyConstructor() const { |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | if (data().UserDeclaredSpecialMembers & |
| 794 | (SMF_MoveConstructor | SMF_MoveAssignment)) |
| 795 | return true; |
| 796 | return data().NeedOverloadResolutionForCopyConstructor; |
| 797 | } |
| 798 | |
| 799 | |
| 800 | |
| 801 | bool implicitCopyConstructorHasConstParam() const { |
| 802 | return data().ImplicitCopyConstructorCanHaveConstParamForNonVBase && |
| 803 | (isAbstract() || |
| 804 | data().ImplicitCopyConstructorCanHaveConstParamForVBase); |
| 805 | } |
| 806 | |
| 807 | |
| 808 | |
| 809 | bool hasCopyConstructorWithConstParam() const { |
| 810 | return data().HasDeclaredCopyConstructorWithConstParam || |
| 811 | (needsImplicitCopyConstructor() && |
| 812 | implicitCopyConstructorHasConstParam()); |
| 813 | } |
| 814 | |
| 815 | |
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 | bool hasUserDeclaredMoveOperation() const { |
| 821 | return data().UserDeclaredSpecialMembers & |
| 822 | (SMF_MoveConstructor | SMF_MoveAssignment); |
| 823 | } |
| 824 | |
| 825 | |
| 826 | |
| 827 | bool hasUserDeclaredMoveConstructor() const { |
| 828 | return data().UserDeclaredSpecialMembers & SMF_MoveConstructor; |
| 829 | } |
| 830 | |
| 831 | |
| 832 | bool hasMoveConstructor() const { |
| 833 | return (data().DeclaredSpecialMembers & SMF_MoveConstructor) || |
| 834 | needsImplicitMoveConstructor(); |
| 835 | } |
| 836 | |
| 837 | |
| 838 | |
| 839 | void setImplicitCopyConstructorIsDeleted() { |
| 840 | assert((data().DefaultedCopyConstructorIsDeleted || |
| 841 | needsOverloadResolutionForCopyConstructor()) && |
| 842 | "Copy constructor should not be deleted"); |
| 843 | data().DefaultedCopyConstructorIsDeleted = true; |
| 844 | } |
| 845 | |
| 846 | |
| 847 | |
| 848 | void setImplicitMoveConstructorIsDeleted() { |
| 849 | assert((data().DefaultedMoveConstructorIsDeleted || |
| 850 | needsOverloadResolutionForMoveConstructor()) && |
| 851 | "move constructor should not be deleted"); |
| 852 | data().DefaultedMoveConstructorIsDeleted = true; |
| 853 | } |
| 854 | |
| 855 | |
| 856 | |
| 857 | void setImplicitDestructorIsDeleted() { |
| 858 | assert((data().DefaultedDestructorIsDeleted || |
| 859 | needsOverloadResolutionForDestructor()) && |
| 860 | "destructor should not be deleted"); |
| 861 | data().DefaultedDestructorIsDeleted = true; |
| 862 | } |
| 863 | |
| 864 | |
| 865 | |
| 866 | bool needsImplicitMoveConstructor() const { |
| 867 | return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) && |
| 868 | !hasUserDeclaredCopyConstructor() && |
| 869 | !hasUserDeclaredCopyAssignment() && |
| 870 | !hasUserDeclaredMoveAssignment() && |
| 871 | !hasUserDeclaredDestructor(); |
| 872 | } |
| 873 | |
| 874 | |
| 875 | |
| 876 | bool needsOverloadResolutionForMoveConstructor() const { |
| 877 | return data().NeedOverloadResolutionForMoveConstructor; |
| 878 | } |
| 879 | |
| 880 | |
| 881 | |
| 882 | |
| 883 | |
| 884 | bool hasUserDeclaredCopyAssignment() const { |
| 885 | return data().UserDeclaredSpecialMembers & SMF_CopyAssignment; |
| 886 | } |
| 887 | |
| 888 | |
| 889 | |
| 890 | void setImplicitCopyAssignmentIsDeleted() { |
| 891 | assert((data().DefaultedCopyAssignmentIsDeleted || |
| 892 | needsOverloadResolutionForCopyAssignment()) && |
| 893 | "copy assignment should not be deleted"); |
| 894 | data().DefaultedCopyAssignmentIsDeleted = true; |
| 895 | } |
| 896 | |
| 897 | |
| 898 | |
| 899 | bool needsImplicitCopyAssignment() const { |
| 900 | return !(data().DeclaredSpecialMembers & SMF_CopyAssignment); |
| 901 | } |
| 902 | |
| 903 | |
| 904 | |
| 905 | bool needsOverloadResolutionForCopyAssignment() const { |
| 906 | |
| 907 | |
| 908 | |
| 909 | |
| 910 | |
| 911 | |
| 912 | if (data().UserDeclaredSpecialMembers & |
| 913 | (SMF_MoveConstructor | SMF_MoveAssignment)) |
| 914 | return true; |
| 915 | return data().NeedOverloadResolutionForCopyAssignment; |
| 916 | } |
| 917 | |
| 918 | |
| 919 | |
| 920 | bool implicitCopyAssignmentHasConstParam() const { |
| 921 | return data().ImplicitCopyAssignmentHasConstParam; |
| 922 | } |
| 923 | |
| 924 | |
| 925 | |
| 926 | |
| 927 | bool hasCopyAssignmentWithConstParam() const { |
| 928 | return data().HasDeclaredCopyAssignmentWithConstParam || |
| 929 | (needsImplicitCopyAssignment() && |
| 930 | implicitCopyAssignmentHasConstParam()); |
| 931 | } |
| 932 | |
| 933 | |
| 934 | |
| 935 | bool hasUserDeclaredMoveAssignment() const { |
| 936 | return data().UserDeclaredSpecialMembers & SMF_MoveAssignment; |
| 937 | } |
| 938 | |
| 939 | |
| 940 | bool hasMoveAssignment() const { |
| 941 | return (data().DeclaredSpecialMembers & SMF_MoveAssignment) || |
| 942 | needsImplicitMoveAssignment(); |
| 943 | } |
| 944 | |
| 945 | |
| 946 | |
| 947 | void setImplicitMoveAssignmentIsDeleted() { |
| 948 | assert((data().DefaultedMoveAssignmentIsDeleted || |
| 949 | needsOverloadResolutionForMoveAssignment()) && |
| 950 | "move assignment should not be deleted"); |
| 951 | data().DefaultedMoveAssignmentIsDeleted = true; |
| 952 | } |
| 953 | |
| 954 | |
| 955 | |
| 956 | |
| 957 | bool needsImplicitMoveAssignment() const { |
| 958 | return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) && |
| 959 | !hasUserDeclaredCopyConstructor() && |
| 960 | !hasUserDeclaredCopyAssignment() && |
| 961 | !hasUserDeclaredMoveConstructor() && |
| 962 | !hasUserDeclaredDestructor() && |
| 963 | (!isLambda() || lambdaIsDefaultConstructibleAndAssignable()); |
| 964 | } |
| 965 | |
| 966 | |
| 967 | |
| 968 | bool needsOverloadResolutionForMoveAssignment() const { |
| 969 | return data().NeedOverloadResolutionForMoveAssignment; |
| 970 | } |
| 971 | |
| 972 | |
| 973 | |
| 974 | |
| 975 | bool hasUserDeclaredDestructor() const { |
| 976 | return data().UserDeclaredSpecialMembers & SMF_Destructor; |
| 977 | } |
| 978 | |
| 979 | |
| 980 | |
| 981 | bool needsImplicitDestructor() const { |
| 982 | return !(data().DeclaredSpecialMembers & SMF_Destructor); |
| 983 | } |
| 984 | |
| 985 | |
| 986 | |
| 987 | bool needsOverloadResolutionForDestructor() const { |
| 988 | return data().NeedOverloadResolutionForDestructor; |
| 989 | } |
| 990 | |
| 991 | |
| 992 | bool isLambda() const { |
| 993 | |
| 994 | auto *DD = DefinitionData; |
| 995 | return DD && DD->IsLambda; |
| 996 | } |
| 997 | |
| 998 | |
| 999 | |
| 1000 | |
| 1001 | bool isGenericLambda() const; |
| 1002 | |
| 1003 | |
| 1004 | |
| 1005 | bool lambdaIsDefaultConstructibleAndAssignable() const; |
| 1006 | |
| 1007 | |
| 1008 | |
| 1009 | CXXMethodDecl *getLambdaCallOperator() const; |
| 1010 | |
| 1011 | |
| 1012 | |
| 1013 | FunctionTemplateDecl *getDependentLambdaCallOperator() const; |
| 1014 | |
| 1015 | |
| 1016 | |
| 1017 | |
| 1018 | |
| 1019 | |
| 1020 | |
| 1021 | |
| 1022 | CXXMethodDecl *getLambdaStaticInvoker() const; |
| 1023 | CXXMethodDecl *getLambdaStaticInvoker(CallingConv CC) const; |
| 1024 | |
| 1025 | |
| 1026 | |
| 1027 | |
| 1028 | TemplateParameterList *getGenericLambdaTemplateParameterList() const; |
| 1029 | |
| 1030 | |
| 1031 | ArrayRef<NamedDecl *> getLambdaExplicitTemplateParameters() const; |
| 1032 | |
| 1033 | LambdaCaptureDefault getLambdaCaptureDefault() const { |
| 1034 | assert(isLambda()); |
| 1035 | return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault); |
| 1036 | } |
| 1037 | |
| 1038 | |
| 1039 | void setCaptures(ASTContext &Context, ArrayRef<LambdaCapture> Captures); |
| 1040 | |
| 1041 | |
| 1042 | |
| 1043 | |
| 1044 | |
| 1045 | |
| 1046 | |
| 1047 | |
| 1048 | |
| 1049 | |
| 1050 | |
| 1051 | |
| 1052 | |
| 1053 | void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, |
| 1054 | FieldDecl *&ThisCapture) const; |
| 1055 | |
| 1056 | using capture_const_iterator = const LambdaCapture *; |
| 1057 | using capture_const_range = llvm::iterator_range<capture_const_iterator>; |
| 1058 | |
| 1059 | capture_const_range captures() const { |
| 1060 | return capture_const_range(captures_begin(), captures_end()); |
| 1061 | } |
| 1062 | |
| 1063 | capture_const_iterator captures_begin() const { |
| 1064 | return isLambda() ? getLambdaData().Captures : nullptr; |
| 1065 | } |
| 1066 | |
| 1067 | capture_const_iterator captures_end() const { |
| 1068 | return isLambda() ? captures_begin() + getLambdaData().NumCaptures |
| 1069 | : nullptr; |
| 1070 | } |
| 1071 | |
| 1072 | unsigned capture_size() const { return getLambdaData().NumCaptures; } |
| 1073 | |
| 1074 | using conversion_iterator = UnresolvedSetIterator; |
| 1075 | |
| 1076 | conversion_iterator conversion_begin() const { |
| 1077 | return data().Conversions.get(getASTContext()).begin(); |
| 1078 | } |
| 1079 | |
| 1080 | conversion_iterator conversion_end() const { |
| 1081 | return data().Conversions.get(getASTContext()).end(); |
| 1082 | } |
| 1083 | |
| 1084 | |
| 1085 | |
| 1086 | |
| 1087 | void removeConversion(const NamedDecl *Old); |
| 1088 | |
| 1089 | |
| 1090 | |
| 1091 | llvm::iterator_range<conversion_iterator> |
| 1092 | getVisibleConversionFunctions() const; |
| 1093 | |
| 1094 | |
| 1095 | |
| 1096 | |
| 1097 | |
| 1098 | bool isAggregate() const { return data().Aggregate; } |
| 1099 | |
| 1100 | |
| 1101 | |
| 1102 | |
| 1103 | bool hasInClassInitializer() const { return data().HasInClassInitializer; } |
| 1104 | |
| 1105 | |
| 1106 | |
| 1107 | |
| 1108 | |
| 1109 | |
| 1110 | |
| 1111 | |
| 1112 | |
| 1113 | bool hasUninitializedReferenceMember() const { |
| 1114 | return !isUnion() && !hasUserDeclaredConstructor() && |
| 1115 | data().HasUninitializedReferenceMember; |
| 1116 | } |
| 1117 | |
| 1118 | |
| 1119 | |
| 1120 | |
| 1121 | |
| 1122 | |
| 1123 | |
| 1124 | |
| 1125 | |
| 1126 | bool isPOD() const { return data().PlainOldData; } |
| 1127 | |
| 1128 | |
| 1129 | |
| 1130 | bool isCLike() const; |
| 1131 | |
| 1132 | |
| 1133 | |
| 1134 | |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | bool isEmpty() const { return data().Empty; } |
| 1142 | |
| 1143 | bool hasPrivateFields() const { |
| 1144 | return data().HasPrivateFields; |
| 1145 | } |
| 1146 | |
| 1147 | bool hasProtectedFields() const { |
| 1148 | return data().HasProtectedFields; |
| 1149 | } |
| 1150 | |
| 1151 | |
| 1152 | bool hasDirectFields() const { |
| 1153 | auto &D = data(); |
| 1154 | return D.HasPublicFields || D.HasProtectedFields || D.HasPrivateFields; |
| 1155 | } |
| 1156 | |
| 1157 | |
| 1158 | |
| 1159 | bool isPolymorphic() const { return data().Polymorphic; } |
| 1160 | |
| 1161 | |
| 1162 | |
| 1163 | |
| 1164 | |
| 1165 | |
| 1166 | bool isAbstract() const { return data().Abstract; } |
| 1167 | |
| 1168 | |
| 1169 | |
| 1170 | bool isStandardLayout() const { return data().IsStandardLayout; } |
| 1171 | |
| 1172 | |
| 1173 | |
| 1174 | bool isCXX11StandardLayout() const { return data().IsCXX11StandardLayout; } |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | bool hasMutableFields() const { return data().HasMutableFields; } |
| 1179 | |
| 1180 | |
| 1181 | bool hasVariantMembers() const { return data().HasVariantMembers; } |
| 1182 | |
| 1183 | |
| 1184 | |
| 1185 | bool hasTrivialDefaultConstructor() const { |
| 1186 | return hasDefaultConstructor() && |
| 1187 | (data().HasTrivialSpecialMembers & SMF_DefaultConstructor); |
| 1188 | } |
| 1189 | |
| 1190 | |
| 1191 | |
| 1192 | bool hasNonTrivialDefaultConstructor() const { |
| 1193 | return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) || |
| 1194 | (needsImplicitDefaultConstructor() && |
| 1195 | !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor)); |
| 1196 | } |
| 1197 | |
| 1198 | |
| 1199 | |
| 1200 | bool hasConstexprNonCopyMoveConstructor() const { |
| 1201 | return data().HasConstexprNonCopyMoveConstructor || |
| 1202 | (needsImplicitDefaultConstructor() && |
| 1203 | defaultedDefaultConstructorIsConstexpr()); |
| 1204 | } |
| 1205 | |
| 1206 | |
| 1207 | |
| 1208 | bool defaultedDefaultConstructorIsConstexpr() const { |
| 1209 | return data().DefaultedDefaultConstructorIsConstexpr && |
| 1210 | (!isUnion() || hasInClassInitializer() || !hasVariantMembers() || |
| 1211 | getLangOpts().CPlusPlus20); |
| 1212 | } |
| 1213 | |
| 1214 | |
| 1215 | bool hasConstexprDefaultConstructor() const { |
| 1216 | return data().HasConstexprDefaultConstructor || |
| 1217 | (needsImplicitDefaultConstructor() && |
| 1218 | defaultedDefaultConstructorIsConstexpr()); |
| 1219 | } |
| 1220 | |
| 1221 | |
| 1222 | |
| 1223 | bool hasTrivialCopyConstructor() const { |
| 1224 | return data().HasTrivialSpecialMembers & SMF_CopyConstructor; |
| 1225 | } |
| 1226 | |
| 1227 | bool hasTrivialCopyConstructorForCall() const { |
| 1228 | return data().HasTrivialSpecialMembersForCall & SMF_CopyConstructor; |
| 1229 | } |
| 1230 | |
| 1231 | |
| 1232 | |
| 1233 | bool hasNonTrivialCopyConstructor() const { |
| 1234 | return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor || |
| 1235 | !hasTrivialCopyConstructor(); |
| 1236 | } |
| 1237 | |
| 1238 | bool hasNonTrivialCopyConstructorForCall() const { |
| 1239 | return (data().DeclaredNonTrivialSpecialMembersForCall & |
| 1240 | SMF_CopyConstructor) || |
| 1241 | !hasTrivialCopyConstructorForCall(); |
| 1242 | } |
| 1243 | |
| 1244 | |
| 1245 | |
| 1246 | bool hasTrivialMoveConstructor() const { |
| 1247 | return hasMoveConstructor() && |
| 1248 | (data().HasTrivialSpecialMembers & SMF_MoveConstructor); |
| 1249 | } |
| 1250 | |
| 1251 | bool hasTrivialMoveConstructorForCall() const { |
| 1252 | return hasMoveConstructor() && |
| 1253 | (data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor); |
| 1254 | } |
| 1255 | |
| 1256 | |
| 1257 | |
| 1258 | bool hasNonTrivialMoveConstructor() const { |
| 1259 | return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) || |
| 1260 | (needsImplicitMoveConstructor() && |
| 1261 | !(data().HasTrivialSpecialMembers & SMF_MoveConstructor)); |
| 1262 | } |
| 1263 | |
| 1264 | bool hasNonTrivialMoveConstructorForCall() const { |
| 1265 | return (data().DeclaredNonTrivialSpecialMembersForCall & |
| 1266 | SMF_MoveConstructor) || |
| 1267 | (needsImplicitMoveConstructor() && |
| 1268 | !(data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor)); |
| 1269 | } |
| 1270 | |
| 1271 | |
| 1272 | |
| 1273 | bool hasTrivialCopyAssignment() const { |
| 1274 | return data().HasTrivialSpecialMembers & SMF_CopyAssignment; |
| 1275 | } |
| 1276 | |
| 1277 | |
| 1278 | |
| 1279 | bool hasNonTrivialCopyAssignment() const { |
| 1280 | return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment || |
| 1281 | !hasTrivialCopyAssignment(); |
| 1282 | } |
| 1283 | |
| 1284 | |
| 1285 | |
| 1286 | bool hasTrivialMoveAssignment() const { |
| 1287 | return hasMoveAssignment() && |
| 1288 | (data().HasTrivialSpecialMembers & SMF_MoveAssignment); |
| 1289 | } |
| 1290 | |
| 1291 | |
| 1292 | |
| 1293 | bool hasNonTrivialMoveAssignment() const { |
| 1294 | return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) || |
| 1295 | (needsImplicitMoveAssignment() && |
| 1296 | !(data().HasTrivialSpecialMembers & SMF_MoveAssignment)); |
| 1297 | } |
| 1298 | |
| 1299 | |
| 1300 | |
| 1301 | bool defaultedDestructorIsConstexpr() const { |
| 1302 | return data().DefaultedDestructorIsConstexpr && |
| 1303 | getLangOpts().CPlusPlus20; |
| 1304 | } |
| 1305 | |
| 1306 | |
| 1307 | bool hasConstexprDestructor() const; |
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 | bool hasTrivialDestructor() const { |
| 1312 | return data().HasTrivialSpecialMembers & SMF_Destructor; |
| 1313 | } |
| 1314 | |
| 1315 | bool hasTrivialDestructorForCall() const { |
| 1316 | return data().HasTrivialSpecialMembersForCall & SMF_Destructor; |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | |
| 1321 | bool hasNonTrivialDestructor() const { |
| 1322 | return !(data().HasTrivialSpecialMembers & SMF_Destructor); |
| 1323 | } |
| 1324 | |
| 1325 | bool hasNonTrivialDestructorForCall() const { |
| 1326 | return !(data().HasTrivialSpecialMembersForCall & SMF_Destructor); |
| 1327 | } |
| 1328 | |
| 1329 | void setHasTrivialSpecialMemberForCall() { |
| 1330 | data().HasTrivialSpecialMembersForCall = |
| 1331 | (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor); |
| 1332 | } |
| 1333 | |
| 1334 | |
| 1335 | |
| 1336 | bool allowConstDefaultInit() const { |
| 1337 | return !data().HasUninitializedFields || |
| 1338 | !(data().HasDefaultedDefaultConstructor || |
| 1339 | needsImplicitDefaultConstructor()); |
| 1340 | } |
| 1341 | |
| 1342 | |
| 1343 | |
| 1344 | |
| 1345 | |
| 1346 | |
| 1347 | bool hasIrrelevantDestructor() const { |
| 1348 | return data().HasIrrelevantDestructor; |
| 1349 | } |
| 1350 | |
| 1351 | |
| 1352 | |
| 1353 | bool hasNonLiteralTypeFieldsOrBases() const { |
| 1354 | return data().HasNonLiteralTypeFieldsOrBases; |
| 1355 | } |
| 1356 | |
| 1357 | |
| 1358 | |
| 1359 | bool hasInheritedConstructor() const { |
| 1360 | return data().HasInheritedConstructor; |
| 1361 | } |
| 1362 | |
| 1363 | |
| 1364 | |
| 1365 | bool hasInheritedAssignment() const { |
| 1366 | return data().HasInheritedAssignment; |
| 1367 | } |
| 1368 | |
| 1369 | |
| 1370 | |
| 1371 | bool isTriviallyCopyable() const; |
| 1372 | |
| 1373 | |
| 1374 | |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | bool isTrivial() const { |
| 1379 | return isTriviallyCopyable() && hasTrivialDefaultConstructor(); |
| 1380 | } |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | |
| 1385 | |
| 1386 | |
| 1387 | |
| 1388 | |
| 1389 | |
| 1390 | |
| 1391 | |
| 1392 | |
| 1393 | |
| 1394 | |
| 1395 | |
| 1396 | |
| 1397 | |
| 1398 | |
| 1399 | bool isLiteral() const { |
| 1400 | const LangOptions &LangOpts = getLangOpts(); |
| 1401 | return (LangOpts.CPlusPlus20 ? hasConstexprDestructor() |
| 1402 | : hasTrivialDestructor()) && |
| 1403 | (!isLambda() || LangOpts.CPlusPlus17) && |
| 1404 | !hasNonLiteralTypeFieldsOrBases() && |
| 1405 | (isAggregate() || isLambda() || |
| 1406 | hasConstexprNonCopyMoveConstructor() || |
| 1407 | hasTrivialDefaultConstructor()); |
| 1408 | } |
| 1409 | |
| 1410 | |
| 1411 | bool isStructural() const { |
| 1412 | return isLiteral() && data().StructuralIfLiteral; |
| 1413 | } |
| 1414 | |
| 1415 | |
| 1416 | |
| 1417 | |
| 1418 | |
| 1419 | |
| 1420 | |
| 1421 | |
| 1422 | |
| 1423 | |
| 1424 | |
| 1425 | |
| 1426 | |
| 1427 | |
| 1428 | |
| 1429 | |
| 1430 | |
| 1431 | |
| 1432 | |
| 1433 | |
| 1434 | CXXRecordDecl *getInstantiatedFromMemberClass() const; |
| 1435 | |
| 1436 | |
| 1437 | |
| 1438 | |
| 1439 | MemberSpecializationInfo *getMemberSpecializationInfo() const; |
| 1440 | |
| 1441 | |
| 1442 | |
| 1443 | void setInstantiationOfMemberClass(CXXRecordDecl *RD, |
| 1444 | TemplateSpecializationKind TSK); |
| 1445 | |
| 1446 | |
| 1447 | |
| 1448 | |
| 1449 | |
| 1450 | |
| 1451 | |
| 1452 | |
| 1453 | |
| 1454 | |
| 1455 | |
| 1456 | |
| 1457 | ClassTemplateDecl *getDescribedClassTemplate() const; |
| 1458 | |
| 1459 | void setDescribedClassTemplate(ClassTemplateDecl *Template); |
| 1460 | |
| 1461 | |
| 1462 | |
| 1463 | |
| 1464 | TemplateSpecializationKind getTemplateSpecializationKind() const; |
| 1465 | |
| 1466 | |
| 1467 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK); |
| 1468 | |
| 1469 | |
| 1470 | |
| 1471 | const CXXRecordDecl *getTemplateInstantiationPattern() const; |
| 1472 | |
| 1473 | CXXRecordDecl *getTemplateInstantiationPattern() { |
| 1474 | return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this) |
| 1475 | ->getTemplateInstantiationPattern()); |
| 1476 | } |
| 1477 | |
| 1478 | |
| 1479 | CXXDestructorDecl *getDestructor() const; |
| 1480 | |
| 1481 | |
| 1482 | |
| 1483 | bool isAnyDestructorNoReturn() const { return data().IsAnyDestructorNoReturn; } |
| 1484 | |
| 1485 | |
| 1486 | |
| 1487 | const FunctionDecl *isLocalClass() const { |
| 1488 | if (const auto *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) |
| 1489 | return RD->isLocalClass(); |
| 1490 | |
| 1491 | return dyn_cast<FunctionDecl>(getDeclContext()); |
| 1492 | } |
| 1493 | |
| 1494 | FunctionDecl *isLocalClass() { |
| 1495 | return const_cast<FunctionDecl*>( |
| 1496 | const_cast<const CXXRecordDecl*>(this)->isLocalClass()); |
| 1497 | } |
| 1498 | |
| 1499 | |
| 1500 | |
| 1501 | bool isCurrentInstantiation(const DeclContext *CurContext) const; |
| 1502 | |
| 1503 | |
| 1504 | |
| 1505 | |
| 1506 | |
| 1507 | |
| 1508 | |
| 1509 | |
| 1510 | |
| 1511 | |
| 1512 | |
| 1513 | bool isDerivedFrom(const CXXRecordDecl *Base) const; |
| 1514 | |
| 1515 | |
| 1516 | |
| 1517 | |
| 1518 | |
| 1519 | |
| 1520 | |
| 1521 | |
| 1522 | |
| 1523 | |
| 1524 | |
| 1525 | |
| 1526 | |
| 1527 | |
| 1528 | |
| 1529 | |
| 1530 | |
| 1531 | bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const; |
| 1532 | |
| 1533 | |
| 1534 | |
| 1535 | |
| 1536 | |
| 1537 | |
| 1538 | |
| 1539 | |
| 1540 | |
| 1541 | |
| 1542 | |
| 1543 | |
| 1544 | |
| 1545 | |
| 1546 | bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const; |
| 1547 | |
| 1548 | |
| 1549 | |
| 1550 | bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const; |
| 1551 | |
| 1552 | |
| 1553 | |
| 1554 | |
| 1555 | |
| 1556 | |
| 1557 | using ForallBasesCallback = |
| 1558 | llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>; |
| 1559 | |
| 1560 | |
| 1561 | |
| 1562 | |
| 1563 | |
| 1564 | |
| 1565 | |
| 1566 | |
| 1567 | |
| 1568 | bool forallBases(ForallBasesCallback BaseMatches) const; |
| 1569 | |
| 1570 | |
| 1571 | |
| 1572 | |
| 1573 | |
| 1574 | |
| 1575 | |
| 1576 | |
| 1577 | |
| 1578 | |
| 1579 | |
| 1580 | using BaseMatchesCallback = |
| 1581 | llvm::function_ref<bool(const CXXBaseSpecifier *Specifier, |
| 1582 | CXXBasePath &Path)>; |
| 1583 | |
| 1584 | |
| 1585 | |
| 1586 | |
| 1587 | |
| 1588 | |
| 1589 | |
| 1590 | |
| 1591 | |
| 1592 | |
| 1593 | |
| 1594 | |
| 1595 | |
| 1596 | |
| 1597 | |
| 1598 | |
| 1599 | |
| 1600 | |
| 1601 | |
| 1602 | |
| 1603 | |
| 1604 | |
| 1605 | bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths, |
| 1606 | bool LookupInDependent = false) const; |
| 1607 | |
| 1608 | |
| 1609 | |
| 1610 | |
| 1611 | |
| 1612 | |
| 1613 | |
| 1614 | |
| 1615 | static bool FindBaseClass(const CXXBaseSpecifier *Specifier, |
| 1616 | CXXBasePath &Path, const CXXRecordDecl *BaseRecord); |
| 1617 | |
| 1618 | |
| 1619 | |
| 1620 | |
| 1621 | |
| 1622 | |
| 1623 | |
| 1624 | |
| 1625 | |
| 1626 | |
| 1627 | static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier, |
| 1628 | CXXBasePath &Path, |
| 1629 | const CXXRecordDecl *BaseRecord); |
| 1630 | |
| 1631 | |
| 1632 | |
| 1633 | |
| 1634 | void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const; |
| 1635 | |
| 1636 | |
| 1637 | void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const; |
| 1638 | |
| 1639 | |
| 1640 | |
| 1641 | |
| 1642 | |
| 1643 | |
| 1644 | |
| 1645 | bool hasMemberName(DeclarationName N) const; |
| 1646 | |
| 1647 | |
| 1648 | |
| 1649 | |
| 1650 | |
| 1651 | std::vector<const NamedDecl *> |
| 1652 | lookupDependentName(DeclarationName Name, |
| 1653 | llvm::function_ref<bool(const NamedDecl *ND)> Filter); |
| 1654 | |
| 1655 | |
| 1656 | |
| 1657 | |
| 1658 | void viewInheritance(ASTContext& Context) const; |
| 1659 | |
| 1660 | |
| 1661 | |
| 1662 | static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, |
| 1663 | AccessSpecifier DeclAccess) { |
| 1664 | assert(DeclAccess != AS_none); |
| 1665 | if (DeclAccess == AS_private) return AS_none; |
| 1666 | return (PathAccess > DeclAccess ? PathAccess : DeclAccess); |
| 1667 | } |
| 1668 | |
| 1669 | |
| 1670 | |
| 1671 | void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD); |
| 1672 | |
| 1673 | void setTrivialForCallFlags(CXXMethodDecl *MD); |
| 1674 | |
| 1675 | |
| 1676 | void completeDefinition() override; |
| 1677 | |
| 1678 | |
| 1679 | |
| 1680 | |
| 1681 | |
| 1682 | |
| 1683 | |
| 1684 | |
| 1685 | void completeDefinition(CXXFinalOverriderMap *FinalOverriders); |
| 1686 | |
| 1687 | |
| 1688 | |
| 1689 | |
| 1690 | |
| 1691 | |
| 1692 | |
| 1693 | |
| 1694 | bool mayBeAbstract() const; |
| 1695 | |
| 1696 | |
| 1697 | |
| 1698 | bool isEffectivelyFinal() const; |
| 1699 | |
| 1700 | |
| 1701 | |
| 1702 | |
| 1703 | |
| 1704 | |
| 1705 | |
| 1706 | unsigned getLambdaManglingNumber() const { |
| 1707 | assert(isLambda() && "Not a lambda closure type!"); |
| 1708 | return getLambdaData().ManglingNumber; |
| 1709 | } |
| 1710 | |
| 1711 | |
| 1712 | |
| 1713 | bool hasKnownLambdaInternalLinkage() const { |
| 1714 | assert(isLambda() && "Not a lambda closure type!"); |
| 1715 | return getLambdaData().HasKnownInternalLinkage; |
| 1716 | } |
| 1717 | |
| 1718 | |
| 1719 | |
| 1720 | |
| 1721 | |
| 1722 | |
| 1723 | |
| 1724 | |
| 1725 | |
| 1726 | |
| 1727 | Decl *getLambdaContextDecl() const; |
| 1728 | |
| 1729 | |
| 1730 | |
| 1731 | void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl, |
| 1732 | bool HasKnownInternalLinkage = false) { |
| 1733 | assert(isLambda() && "Not a lambda closure type!"); |
| 1734 | getLambdaData().ManglingNumber = ManglingNumber; |
| 1735 | getLambdaData().ContextDecl = ContextDecl; |
| 1736 | getLambdaData().HasKnownInternalLinkage = HasKnownInternalLinkage; |
| 1737 | } |
| 1738 | |
| 1739 | |
| 1740 | void setDeviceLambdaManglingNumber(unsigned Num) const; |
| 1741 | |
| 1742 | |
| 1743 | unsigned getDeviceLambdaManglingNumber() const; |
| 1744 | |
| 1745 | |
| 1746 | MSInheritanceModel getMSInheritanceModel() const; |
| 1747 | |
| 1748 | |
| 1749 | MSInheritanceModel calculateInheritanceModel() const; |
| 1750 | |
| 1751 | |
| 1752 | |
| 1753 | |
| 1754 | |
| 1755 | |
| 1756 | |
| 1757 | bool nullFieldOffsetIsZero() const; |
| 1758 | |
| 1759 | |
| 1760 | |
| 1761 | MSVtorDispMode getMSVtorDispMode() const; |
| 1762 | |
| 1763 | |
| 1764 | |
| 1765 | |
| 1766 | |
| 1767 | |
| 1768 | |
| 1769 | |
| 1770 | |
| 1771 | |
| 1772 | |
| 1773 | |
| 1774 | bool isDependentLambda() const { |
| 1775 | return isLambda() && getLambdaData().Dependent; |
| 1776 | } |
| 1777 | |
| 1778 | TypeSourceInfo *getLambdaTypeInfo() const { |
| 1779 | return getLambdaData().MethodTyInfo; |
| 1780 | } |
| 1781 | |
| 1782 | |
| 1783 | |
| 1784 | bool isInterfaceLike() const; |
| 1785 | |
| 1786 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 1787 | static bool classofKind(Kind K) { |
| 1788 | return K >= firstCXXRecord && K <= lastCXXRecord; |
| 1789 | } |
| 1790 | void markAbstract() { data().Abstract = true; } |
| 1791 | }; |
| 1792 | |
| 1793 | |
| 1794 | |
| 1795 | class ExplicitSpecifier { |
| 1796 | llvm::PointerIntPair<Expr *, 2, ExplicitSpecKind> ExplicitSpec{ |
| 1797 | nullptr, ExplicitSpecKind::ResolvedFalse}; |
| 1798 | |
| 1799 | public: |
| 1800 | ExplicitSpecifier() = default; |
| 1801 | ExplicitSpecifier(Expr *Expression, ExplicitSpecKind Kind) |
| 1802 | : ExplicitSpec(Expression, Kind) {} |
| 1803 | ExplicitSpecKind getKind() const { return ExplicitSpec.getInt(); } |
| 1804 | const Expr *getExpr() const { return ExplicitSpec.getPointer(); } |
| 1805 | Expr *getExpr() { return ExplicitSpec.getPointer(); } |
| 1806 | |
| 1807 | |
| 1808 | bool isSpecified() const { |
| 1809 | return ExplicitSpec.getInt() != ExplicitSpecKind::ResolvedFalse || |
| 1810 | ExplicitSpec.getPointer(); |
| 1811 | } |
| 1812 | |
| 1813 | |
| 1814 | |
| 1815 | bool isEquivalent(const ExplicitSpecifier Other) const; |
| 1816 | |
| 1817 | |
| 1818 | |
| 1819 | bool isExplicit() const { |
| 1820 | return ExplicitSpec.getInt() == ExplicitSpecKind::ResolvedTrue; |
| 1821 | } |
| 1822 | |
| 1823 | |
| 1824 | bool isInvalid() const { |
| 1825 | return ExplicitSpec.getInt() == ExplicitSpecKind::Unresolved && |
| 1826 | !ExplicitSpec.getPointer(); |
| 1827 | } |
| 1828 | void setKind(ExplicitSpecKind Kind) { ExplicitSpec.setInt(Kind); } |
| 1829 | void setExpr(Expr *E) { ExplicitSpec.setPointer(E); } |
| 1830 | |
| 1831 | static ExplicitSpecifier getFromDecl(FunctionDecl *Function); |
| 1832 | static const ExplicitSpecifier getFromDecl(const FunctionDecl *Function) { |
| 1833 | return getFromDecl(const_cast<FunctionDecl *>(Function)); |
| 1834 | } |
| 1835 | static ExplicitSpecifier Invalid() { |
| 1836 | return ExplicitSpecifier(nullptr, ExplicitSpecKind::Unresolved); |
| 1837 | } |
| 1838 | }; |
| 1839 | |
| 1840 | |
| 1841 | |
| 1842 | |
| 1843 | |
| 1844 | |
| 1845 | |
| 1846 | |
| 1847 | |
| 1848 | |
| 1849 | |
| 1850 | class CXXDeductionGuideDecl : public FunctionDecl { |
| 1851 | void anchor() override; |
| 1852 | |
| 1853 | private: |
| 1854 | CXXDeductionGuideDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
| 1855 | ExplicitSpecifier ES, |
| 1856 | const DeclarationNameInfo &NameInfo, QualType T, |
| 1857 | TypeSourceInfo *TInfo, SourceLocation EndLocation, |
| 1858 | CXXConstructorDecl *Ctor) |
| 1859 | : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo, |
| 1860 | SC_None, false, ConstexprSpecKind::Unspecified), |
| 1861 | Ctor(Ctor), ExplicitSpec(ES) { |
| 1862 | if (EndLocation.isValid()) |
| 1863 | setRangeEnd(EndLocation); |
| 1864 | setIsCopyDeductionCandidate(false); |
| 1865 | } |
| 1866 | |
| 1867 | CXXConstructorDecl *Ctor; |
| 1868 | ExplicitSpecifier ExplicitSpec; |
| 1869 | void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } |
| 1870 | |
| 1871 | public: |
| 1872 | friend class ASTDeclReader; |
| 1873 | friend class ASTDeclWriter; |
| 1874 | |
| 1875 | static CXXDeductionGuideDecl * |
| 1876 | Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
| 1877 | ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T, |
| 1878 | TypeSourceInfo *TInfo, SourceLocation EndLocation, |
| 1879 | CXXConstructorDecl *Ctor = nullptr); |
| 1880 | |
| 1881 | static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 1882 | |
| 1883 | ExplicitSpecifier getExplicitSpecifier() { return ExplicitSpec; } |
| 1884 | const ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; } |
| 1885 | |
| 1886 | |
| 1887 | bool isExplicit() const { return ExplicitSpec.isExplicit(); } |
| 1888 | |
| 1889 | |
| 1890 | TemplateDecl *getDeducedTemplate() const { |
| 1891 | return getDeclName().getCXXDeductionGuideTemplate(); |
| 1892 | } |
| 1893 | |
| 1894 | |
| 1895 | |
| 1896 | CXXConstructorDecl *getCorrespondingConstructor() const { |
| 1897 | return Ctor; |
| 1898 | } |
| 1899 | |
| 1900 | void setIsCopyDeductionCandidate(bool isCDC = true) { |
| 1901 | FunctionDeclBits.IsCopyDeductionCandidate = isCDC; |
| 1902 | } |
| 1903 | |
| 1904 | bool isCopyDeductionCandidate() const { |
| 1905 | return FunctionDeclBits.IsCopyDeductionCandidate; |
| 1906 | } |
| 1907 | |
| 1908 | |
| 1909 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 1910 | static bool classofKind(Kind K) { return K == CXXDeductionGuide; } |
| 1911 | }; |
| 1912 | |
| 1913 | |
| 1914 | |
| 1915 | |
| 1916 | |
| 1917 | |
| 1918 | |
| 1919 | |
| 1920 | |
| 1921 | |
| 1922 | |
| 1923 | |
| 1924 | |
| 1925 | |
| 1926 | class RequiresExprBodyDecl : public Decl, public DeclContext { |
| 1927 | RequiresExprBodyDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc) |
| 1928 | : Decl(RequiresExprBody, DC, StartLoc), DeclContext(RequiresExprBody) {} |
| 1929 | |
| 1930 | public: |
| 1931 | friend class ASTDeclReader; |
| 1932 | friend class ASTDeclWriter; |
| 1933 | |
| 1934 | static RequiresExprBodyDecl *Create(ASTContext &C, DeclContext *DC, |
| 1935 | SourceLocation StartLoc); |
| 1936 | |
| 1937 | static RequiresExprBodyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 1938 | |
| 1939 | |
| 1940 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 1941 | static bool classofKind(Kind K) { return K == RequiresExprBody; } |
| 1942 | }; |
| 1943 | |
| 1944 | |
| 1945 | |
| 1946 | |
| 1947 | |
| 1948 | class CXXMethodDecl : public FunctionDecl { |
| 1949 | void anchor() override; |
| 1950 | |
| 1951 | protected: |
| 1952 | CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD, |
| 1953 | SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, |
| 1954 | QualType T, TypeSourceInfo *TInfo, StorageClass SC, |
| 1955 | bool isInline, ConstexprSpecKind ConstexprKind, |
| 1956 | SourceLocation EndLocation, |
| 1957 | Expr *TrailingRequiresClause = nullptr) |
| 1958 | : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo, SC, isInline, |
| 1959 | ConstexprKind, TrailingRequiresClause) { |
| 1960 | if (EndLocation.isValid()) |
| 1961 | setRangeEnd(EndLocation); |
| 1962 | } |
| 1963 | |
| 1964 | public: |
| 1965 | static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, |
| 1966 | SourceLocation StartLoc, |
| 1967 | const DeclarationNameInfo &NameInfo, QualType T, |
| 1968 | TypeSourceInfo *TInfo, StorageClass SC, |
| 1969 | bool isInline, ConstexprSpecKind ConstexprKind, |
| 1970 | SourceLocation EndLocation, |
| 1971 | Expr *TrailingRequiresClause = nullptr); |
| 1972 | |
| 1973 | static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 1974 | |
| 1975 | bool isStatic() const; |
| 1976 | bool isInstance() const { return !isStatic(); } |
| 10 | | Assuming the condition is true | |
|
| 11 | | Returning the value 1, which participates in a condition later | |
|
| 1977 | |
| 1978 | |
| 1979 | |
| 1980 | static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) { |
| 1981 | |
| 1982 | |
| 1983 | |
| 1984 | |
| 1985 | |
| 1986 | return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete || |
| 1987 | OOK == OO_Array_Delete; |
| 1988 | } |
| 1989 | |
| 1990 | bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); } |
| 1991 | bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); } |
| 1992 | |
| 1993 | bool isVirtual() const { |
| 1994 | CXXMethodDecl *CD = const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); |
| 1995 | |
| 1996 | |
| 1997 | |
| 1998 | if (CD->isVirtualAsWritten() || CD->isPure()) |
| 1999 | return true; |
| 2000 | |
| 2001 | return CD->size_overridden_methods() != 0; |
| 2002 | } |
| 2003 | |
| 2004 | |
| 2005 | |
| 2006 | |
| 2007 | |
| 2008 | |
| 2009 | CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, bool IsAppleKext); |
| 2010 | |
| 2011 | const CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, |
| 2012 | bool IsAppleKext) const { |
| 2013 | return const_cast<CXXMethodDecl *>(this)->getDevirtualizedMethod( |
| 2014 | Base, IsAppleKext); |
| 2015 | } |
| 2016 | |
| 2017 | |
| 2018 | |
| 2019 | |
| 2020 | |
| 2021 | |
| 2022 | |
| 2023 | |
| 2024 | bool isUsualDeallocationFunction( |
| 2025 | SmallVectorImpl<const FunctionDecl *> &PreventedBy) const; |
| 2026 | |
| 2027 | |
| 2028 | |
| 2029 | bool isCopyAssignmentOperator() const; |
| 2030 | |
| 2031 | |
| 2032 | bool isMoveAssignmentOperator() const; |
| 2033 | |
| 2034 | CXXMethodDecl *getCanonicalDecl() override { |
| 2035 | return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); |
| 2036 | } |
| 2037 | const CXXMethodDecl *getCanonicalDecl() const { |
| 2038 | return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); |
| 2039 | } |
| 2040 | |
| 2041 | CXXMethodDecl *getMostRecentDecl() { |
| 2042 | return cast<CXXMethodDecl>( |
| 2043 | static_cast<FunctionDecl *>(this)->getMostRecentDecl()); |
| 2044 | } |
| 2045 | const CXXMethodDecl *getMostRecentDecl() const { |
| 2046 | return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl(); |
| 2047 | } |
| 2048 | |
| 2049 | void addOverriddenMethod(const CXXMethodDecl *MD); |
| 2050 | |
| 2051 | using method_iterator = const CXXMethodDecl *const *; |
| 2052 | |
| 2053 | method_iterator begin_overridden_methods() const; |
| 2054 | method_iterator end_overridden_methods() const; |
| 2055 | unsigned size_overridden_methods() const; |
| 2056 | |
| 2057 | using overridden_method_range = llvm::iterator_range< |
| 2058 | llvm::TinyPtrVector<const CXXMethodDecl *>::const_iterator>; |
| 2059 | |
| 2060 | overridden_method_range overridden_methods() const; |
| 2061 | |
| 2062 | |
| 2063 | |
| 2064 | const CXXRecordDecl *getParent() const { |
| 2065 | return cast<CXXRecordDecl>(FunctionDecl::getParent()); |
| 2066 | } |
| 2067 | |
| 2068 | |
| 2069 | |
| 2070 | CXXRecordDecl *getParent() { |
| 2071 | return const_cast<CXXRecordDecl *>( |
| 2072 | cast<CXXRecordDecl>(FunctionDecl::getParent())); |
| 2073 | } |
| 2074 | |
| 2075 | |
| 2076 | |
| 2077 | |
| 2078 | |
| 2079 | |
| 2080 | |
| 2081 | QualType getThisType() const; |
| 2082 | |
| 2083 | |
| 2084 | |
| 2085 | |
| 2086 | QualType getThisObjectType() const; |
| 2087 | |
| 2088 | static QualType getThisType(const FunctionProtoType *FPT, |
| 2089 | const CXXRecordDecl *Decl); |
| 2090 | |
| 2091 | static QualType getThisObjectType(const FunctionProtoType *FPT, |
| 2092 | const CXXRecordDecl *Decl); |
| 2093 | |
| 2094 | Qualifiers getMethodQualifiers() const { |
| 2095 | return getType()->castAs<FunctionProtoType>()->getMethodQuals(); |
| 2096 | } |
| 2097 | |
| 2098 | |
| 2099 | |
| 2100 | |
| 2101 | |
| 2102 | |
| 2103 | |
| 2104 | |
| 2105 | |
| 2106 | |
| 2107 | |
| 2108 | |
| 2109 | RefQualifierKind getRefQualifier() const { |
| 2110 | return getType()->castAs<FunctionProtoType>()->getRefQualifier(); |
| 2111 | } |
| 2112 | |
| 2113 | bool hasInlineBody() const; |
| 2114 | |
| 2115 | |
| 2116 | |
| 2117 | |
| 2118 | |
| 2119 | |
| 2120 | |
| 2121 | |
| 2122 | bool isLambdaStaticInvoker() const; |
| 2123 | |
| 2124 | |
| 2125 | |
| 2126 | |
| 2127 | |
| 2128 | |
| 2129 | CXXMethodDecl * |
| 2130 | getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
| 2131 | bool MayBeBase = false); |
| 2132 | |
| 2133 | const CXXMethodDecl * |
| 2134 | getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
| 2135 | bool MayBeBase = false) const { |
| 2136 | return const_cast<CXXMethodDecl *>(this) |
| 2137 | ->getCorrespondingMethodInClass(RD, MayBeBase); |
| 2138 | } |
| 2139 | |
| 2140 | |
| 2141 | |
| 2142 | CXXMethodDecl *getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
| 2143 | bool MayBeBase = false); |
| 2144 | const CXXMethodDecl * |
| 2145 | getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
| 2146 | bool MayBeBase = false) const { |
| 2147 | return const_cast<CXXMethodDecl *>(this) |
| 2148 | ->getCorrespondingMethodDeclaredInClass(RD, MayBeBase); |
| 2149 | } |
| 2150 | |
| 2151 | |
| 2152 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2153 | static bool classofKind(Kind K) { |
| 2154 | return K >= firstCXXMethod && K <= lastCXXMethod; |
| 2155 | } |
| 2156 | }; |
| 2157 | |
| 2158 | |
| 2159 | |
| 2160 | |
| 2161 | |
| 2162 | |
| 2163 | |
| 2164 | |
| 2165 | |
| 2166 | |
| 2167 | |
| 2168 | |
| 2169 | |
| 2170 | |
| 2171 | |
| 2172 | |
| 2173 | class CXXCtorInitializer final { |
| 2174 | |
| 2175 | |
| 2176 | |
| 2177 | llvm::PointerUnion<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *> |
| 2178 | Initializee; |
| 2179 | |
| 2180 | |
| 2181 | |
| 2182 | Stmt *Init; |
| 2183 | |
| 2184 | |
| 2185 | |
| 2186 | |
| 2187 | |
| 2188 | |
| 2189 | |
| 2190 | SourceLocation MemberOrEllipsisLocation; |
| 2191 | |
| 2192 | |
| 2193 | SourceLocation LParenLoc; |
| 2194 | |
| 2195 | |
| 2196 | SourceLocation RParenLoc; |
| 2197 | |
| 2198 | |
| 2199 | |
| 2200 | unsigned IsDelegating : 1; |
| 2201 | |
| 2202 | |
| 2203 | |
| 2204 | unsigned IsVirtual : 1; |
| 2205 | |
| 2206 | |
| 2207 | |
| 2208 | unsigned IsWritten : 1; |
| 2209 | |
| 2210 | |
| 2211 | |
| 2212 | unsigned SourceOrder : 13; |
| 2213 | |
| 2214 | public: |
| 2215 | |
| 2216 | explicit |
| 2217 | CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual, |
| 2218 | SourceLocation L, Expr *Init, SourceLocation R, |
| 2219 | SourceLocation EllipsisLoc); |
| 2220 | |
| 2221 | |
| 2222 | explicit |
| 2223 | CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, |
| 2224 | SourceLocation MemberLoc, SourceLocation L, Expr *Init, |
| 2225 | SourceLocation R); |
| 2226 | |
| 2227 | |
| 2228 | explicit |
| 2229 | CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member, |
| 2230 | SourceLocation MemberLoc, SourceLocation L, Expr *Init, |
| 2231 | SourceLocation R); |
| 2232 | |
| 2233 | |
| 2234 | explicit |
| 2235 | CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, |
| 2236 | SourceLocation L, Expr *Init, SourceLocation R); |
| 2237 | |
| 2238 | |
| 2239 | int64_t getID(const ASTContext &Context) const; |
| 2240 | |
| 2241 | |
| 2242 | bool isBaseInitializer() const { |
| 2243 | return Initializee.is<TypeSourceInfo*>() && !IsDelegating; |
| 2244 | } |
| 2245 | |
| 2246 | |
| 2247 | |
| 2248 | bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); } |
| 2249 | |
| 2250 | bool isAnyMemberInitializer() const { |
| 2251 | return isMemberInitializer() || isIndirectMemberInitializer(); |
| 2252 | } |
| 2253 | |
| 2254 | bool isIndirectMemberInitializer() const { |
| 2255 | return Initializee.is<IndirectFieldDecl*>(); |
| 2256 | } |
| 2257 | |
| 2258 | |
| 2259 | |
| 2260 | |
| 2261 | |
| 2262 | |
| 2263 | |
| 2264 | bool isInClassMemberInitializer() const { |
| 2265 | return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass; |
| 2266 | } |
| 2267 | |
| 2268 | |
| 2269 | |
| 2270 | bool isDelegatingInitializer() const { |
| 2271 | return Initializee.is<TypeSourceInfo*>() && IsDelegating; |
| 2272 | } |
| 2273 | |
| 2274 | |
| 2275 | bool isPackExpansion() const { |
| 2276 | return isBaseInitializer() && MemberOrEllipsisLocation.isValid(); |
| 2277 | } |
| 2278 | |
| 2279 | |
| 2280 | SourceLocation getEllipsisLoc() const { |
| 2281 | if (!isPackExpansion()) |
| 2282 | return {}; |
| 2283 | return MemberOrEllipsisLocation; |
| 2284 | } |
| 2285 | |
| 2286 | |
| 2287 | |
| 2288 | |
| 2289 | TypeLoc getBaseClassLoc() const; |
| 2290 | |
| 2291 | |
| 2292 | |
| 2293 | const Type *getBaseClass() const; |
| 2294 | |
| 2295 | |
| 2296 | bool isBaseVirtual() const { |
| 2297 | assert(isBaseInitializer() && "Must call this on base initializer!"); |
| 2298 | |
| 2299 | return IsVirtual; |
| 2300 | } |
| 2301 | |
| 2302 | |
| 2303 | |
| 2304 | TypeSourceInfo *getTypeSourceInfo() const { |
| 2305 | return Initializee.dyn_cast<TypeSourceInfo *>(); |
| 2306 | } |
| 2307 | |
| 2308 | |
| 2309 | |
| 2310 | FieldDecl *getMember() const { |
| 2311 | if (isMemberInitializer()) |
| 2312 | return Initializee.get<FieldDecl*>(); |
| 2313 | return nullptr; |
| 2314 | } |
| 2315 | |
| 2316 | FieldDecl *getAnyMember() const { |
| 2317 | if (isMemberInitializer()) |
| 2318 | return Initializee.get<FieldDecl*>(); |
| 2319 | if (isIndirectMemberInitializer()) |
| 2320 | return Initializee.get<IndirectFieldDecl*>()->getAnonField(); |
| 2321 | return nullptr; |
| 2322 | } |
| 2323 | |
| 2324 | IndirectFieldDecl *getIndirectMember() const { |
| 2325 | if (isIndirectMemberInitializer()) |
| 2326 | return Initializee.get<IndirectFieldDecl*>(); |
| 2327 | return nullptr; |
| 2328 | } |
| 2329 | |
| 2330 | SourceLocation getMemberLocation() const { |
| 2331 | return MemberOrEllipsisLocation; |
| 2332 | } |
| 2333 | |
| 2334 | |
| 2335 | SourceLocation getSourceLocation() const; |
| 2336 | |
| 2337 | |
| 2338 | SourceRange getSourceRange() const LLVM_READONLY; |
| 2339 | |
| 2340 | |
| 2341 | |
| 2342 | bool isWritten() const { return IsWritten; } |
| 2343 | |
| 2344 | |
| 2345 | |
| 2346 | int getSourceOrder() const { |
| 2347 | return IsWritten ? static_cast<int>(SourceOrder) : -1; |
| 2348 | } |
| 2349 | |
| 2350 | |
| 2351 | |
| 2352 | |
| 2353 | |
| 2354 | |
| 2355 | |
| 2356 | |
| 2357 | void setSourceOrder(int Pos) { |
| 2358 | assert(!IsWritten && |
| 2359 | "setSourceOrder() used on implicit initializer"); |
| 2360 | assert(SourceOrder == 0 && |
| 2361 | "calling twice setSourceOrder() on the same initializer"); |
| 2362 | assert(Pos >= 0 && |
| 2363 | "setSourceOrder() used to make an initializer implicit"); |
| 2364 | IsWritten = true; |
| 2365 | SourceOrder = static_cast<unsigned>(Pos); |
| 2366 | } |
| 2367 | |
| 2368 | SourceLocation getLParenLoc() const { return LParenLoc; } |
| 2369 | SourceLocation getRParenLoc() const { return RParenLoc; } |
| 2370 | |
| 2371 | |
| 2372 | Expr *getInit() const { return static_cast<Expr *>(Init); } |
| 2373 | }; |
| 2374 | |
| 2375 | |
| 2376 | class InheritedConstructor { |
| 2377 | ConstructorUsingShadowDecl *Shadow = nullptr; |
| 2378 | CXXConstructorDecl *BaseCtor = nullptr; |
| 2379 | |
| 2380 | public: |
| 2381 | InheritedConstructor() = default; |
| 2382 | InheritedConstructor(ConstructorUsingShadowDecl *Shadow, |
| 2383 | CXXConstructorDecl *BaseCtor) |
| 2384 | : Shadow(Shadow), BaseCtor(BaseCtor) {} |
| 2385 | |
| 2386 | explicit operator bool() const { return Shadow; } |
| 2387 | |
| 2388 | ConstructorUsingShadowDecl *getShadowDecl() const { return Shadow; } |
| 2389 | CXXConstructorDecl *getConstructor() const { return BaseCtor; } |
| 2390 | }; |
| 2391 | |
| 2392 | |
| 2393 | |
| 2394 | |
| 2395 | |
| 2396 | |
| 2397 | |
| 2398 | |
| 2399 | |
| 2400 | |
| 2401 | |
| 2402 | class CXXConstructorDecl final |
| 2403 | : public CXXMethodDecl, |
| 2404 | private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor, |
| 2405 | ExplicitSpecifier> { |
| 2406 | |
| 2407 | |
| 2408 | |
| 2409 | |
| 2410 | |
| 2411 | |
| 2412 | LazyCXXCtorInitializersPtr CtorInitializers; |
| 2413 | |
| 2414 | CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
| 2415 | const DeclarationNameInfo &NameInfo, QualType T, |
| 2416 | TypeSourceInfo *TInfo, ExplicitSpecifier ES, bool isInline, |
| 2417 | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
| 2418 | InheritedConstructor Inherited, |
| 2419 | Expr *TrailingRequiresClause); |
| 2420 | |
| 2421 | void anchor() override; |
| 2422 | |
| 2423 | size_t numTrailingObjects(OverloadToken<InheritedConstructor>) const { |
| 2424 | return CXXConstructorDeclBits.IsInheritingConstructor; |
| 2425 | } |
| 2426 | size_t numTrailingObjects(OverloadToken<ExplicitSpecifier>) const { |
| 2427 | return CXXConstructorDeclBits.HasTrailingExplicitSpecifier; |
| 2428 | } |
| 2429 | |
| 2430 | ExplicitSpecifier getExplicitSpecifierInternal() const { |
| 2431 | if (CXXConstructorDeclBits.HasTrailingExplicitSpecifier) |
| 2432 | return *getTrailingObjects<ExplicitSpecifier>(); |
| 2433 | return ExplicitSpecifier( |
| 2434 | nullptr, CXXConstructorDeclBits.IsSimpleExplicit |
| 2435 | ? ExplicitSpecKind::ResolvedTrue |
| 2436 | : ExplicitSpecKind::ResolvedFalse); |
| 2437 | } |
| 2438 | |
| 2439 | enum TrailingAllocKind { |
| 2440 | TAKInheritsConstructor = 1, |
| 2441 | TAKHasTailExplicit = 1 << 1, |
| 2442 | }; |
| 2443 | |
| 2444 | uint64_t getTrailingAllocKind() const { |
| 2445 | return numTrailingObjects(OverloadToken<InheritedConstructor>()) | |
| 2446 | (numTrailingObjects(OverloadToken<ExplicitSpecifier>()) << 1); |
| 2447 | } |
| 2448 | |
| 2449 | public: |
| 2450 | friend class ASTDeclReader; |
| 2451 | friend class ASTDeclWriter; |
| 2452 | friend TrailingObjects; |
| 2453 | |
| 2454 | static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
| 2455 | uint64_t AllocKind); |
| 2456 | static CXXConstructorDecl * |
| 2457 | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
| 2458 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
| 2459 | ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared, |
| 2460 | ConstexprSpecKind ConstexprKind, |
| 2461 | InheritedConstructor Inherited = InheritedConstructor(), |
| 2462 | Expr *TrailingRequiresClause = nullptr); |
| 2463 | |
| 2464 | void setExplicitSpecifier(ExplicitSpecifier ES) { |
| 2465 | assert((!ES.getExpr() || |
| 2466 | CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && |
| 2467 | "cannot set this explicit specifier. no trail-allocated space for " |
| 2468 | "explicit"); |
| 2469 | if (ES.getExpr()) |
| 2470 | *getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>() = ES; |
| 2471 | else |
| 2472 | CXXConstructorDeclBits.IsSimpleExplicit = ES.isExplicit(); |
| 2473 | } |
| 2474 | |
| 2475 | ExplicitSpecifier getExplicitSpecifier() { |
| 2476 | return getCanonicalDecl()->getExplicitSpecifierInternal(); |
| 2477 | } |
| 2478 | const ExplicitSpecifier getExplicitSpecifier() const { |
| 2479 | return getCanonicalDecl()->getExplicitSpecifierInternal(); |
| 2480 | } |
| 2481 | |
| 2482 | |
| 2483 | bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } |
| 2484 | |
| 2485 | |
| 2486 | using init_iterator = CXXCtorInitializer **; |
| 2487 | |
| 2488 | |
| 2489 | using init_const_iterator = CXXCtorInitializer *const *; |
| 2490 | |
| 2491 | using init_range = llvm::iterator_range<init_iterator>; |
| 2492 | using init_const_range = llvm::iterator_range<init_const_iterator>; |
| 2493 | |
| 2494 | init_range inits() { return init_range(init_begin(), init_end()); } |
| 2495 | init_const_range inits() const { |
| 2496 | return init_const_range(init_begin(), init_end()); |
| 2497 | } |
| 2498 | |
| 2499 | |
| 2500 | init_iterator init_begin() { |
| 2501 | const auto *ConstThis = this; |
| 2502 | return const_cast<init_iterator>(ConstThis->init_begin()); |
| 2503 | } |
| 2504 | |
| 2505 | |
| 2506 | init_const_iterator init_begin() const; |
| 2507 | |
| 2508 | |
| 2509 | init_iterator init_end() { |
| 2510 | return init_begin() + getNumCtorInitializers(); |
| 2511 | } |
| 2512 | |
| 2513 | |
| 2514 | init_const_iterator init_end() const { |
| 2515 | return init_begin() + getNumCtorInitializers(); |
| 2516 | } |
| 2517 | |
| 2518 | using init_reverse_iterator = std::reverse_iterator<init_iterator>; |
| 2519 | using init_const_reverse_iterator = |
| 2520 | std::reverse_iterator<init_const_iterator>; |
| 2521 | |
| 2522 | init_reverse_iterator init_rbegin() { |
| 2523 | return init_reverse_iterator(init_end()); |
| 2524 | } |
| 2525 | init_const_reverse_iterator init_rbegin() const { |
| 2526 | return init_const_reverse_iterator(init_end()); |
| 2527 | } |
| 2528 | |
| 2529 | init_reverse_iterator init_rend() { |
| 2530 | return init_reverse_iterator(init_begin()); |
| 2531 | } |
| 2532 | init_const_reverse_iterator init_rend() const { |
| 2533 | return init_const_reverse_iterator(init_begin()); |
| 2534 | } |
| 2535 | |
| 2536 | |
| 2537 | |
| 2538 | unsigned getNumCtorInitializers() const { |
| 2539 | return CXXConstructorDeclBits.NumCtorInitializers; |
| 2540 | } |
| 2541 | |
| 2542 | void setNumCtorInitializers(unsigned numCtorInitializers) { |
| 2543 | CXXConstructorDeclBits.NumCtorInitializers = numCtorInitializers; |
| 2544 | |
| 2545 | |
| 2546 | |
| 2547 | assert(CXXConstructorDeclBits.NumCtorInitializers == |
| 2548 | numCtorInitializers && "NumCtorInitializers overflow!"); |
| 2549 | } |
| 2550 | |
| 2551 | void setCtorInitializers(CXXCtorInitializer **Initializers) { |
| 2552 | CtorInitializers = Initializers; |
| 2553 | } |
| 2554 | |
| 2555 | |
| 2556 | bool isDelegatingConstructor() const { |
| 2557 | return (getNumCtorInitializers() == 1) && |
| 2558 | init_begin()[0]->isDelegatingInitializer(); |
| 2559 | } |
| 2560 | |
| 2561 | |
| 2562 | CXXConstructorDecl *getTargetConstructor() const; |
| 2563 | |
| 2564 | |
| 2565 | |
| 2566 | |
| 2567 | bool isDefaultConstructor() const; |
| 2568 | |
| 2569 | |
| 2570 | |
| 2571 | |
| 2572 | |
| 2573 | |
| 2574 | |
| 2575 | |
| 2576 | |
| 2577 | |
| 2578 | |
| 2579 | |
| 2580 | |
| 2581 | |
| 2582 | bool isCopyConstructor(unsigned &TypeQuals) const; |
| 2583 | |
| 2584 | |
| 2585 | |
| 2586 | |
| 2587 | bool isCopyConstructor() const { |
| 2588 | unsigned TypeQuals = 0; |
| 2589 | return isCopyConstructor(TypeQuals); |
| 2590 | } |
| 2591 | |
| 2592 | |
| 2593 | |
| 2594 | |
| 2595 | |
| 2596 | |
| 2597 | bool isMoveConstructor(unsigned &TypeQuals) const; |
| 2598 | |
| 2599 | |
| 2600 | |
| 2601 | bool isMoveConstructor() const { |
| 2602 | unsigned TypeQuals = 0; |
| 2603 | return isMoveConstructor(TypeQuals); |
| 2604 | } |
| 2605 | |
| 2606 | |
| 2607 | |
| 2608 | |
| 2609 | |
| 2610 | bool isCopyOrMoveConstructor(unsigned &TypeQuals) const; |
| 2611 | |
| 2612 | |
| 2613 | bool isCopyOrMoveConstructor() const { |
| 2614 | unsigned Quals; |
| 2615 | return isCopyOrMoveConstructor(Quals); |
| 2616 | } |
| 2617 | |
| 2618 | |
| 2619 | |
| 2620 | |
| 2621 | bool isConvertingConstructor(bool AllowExplicit) const; |
| 2622 | |
| 2623 | |
| 2624 | |
| 2625 | |
| 2626 | bool isSpecializationCopyingObject() const; |
| 2627 | |
| 2628 | |
| 2629 | |
| 2630 | bool isInheritingConstructor() const { |
| 2631 | return CXXConstructorDeclBits.IsInheritingConstructor; |
| 2632 | } |
| 2633 | |
| 2634 | |
| 2635 | |
| 2636 | void setInheritingConstructor(bool isIC = true) { |
| 2637 | CXXConstructorDeclBits.IsInheritingConstructor = isIC; |
| 2638 | } |
| 2639 | |
| 2640 | |
| 2641 | InheritedConstructor getInheritedConstructor() const { |
| 2642 | return isInheritingConstructor() ? |
| 2643 | *getTrailingObjects<InheritedConstructor>() : InheritedConstructor(); |
| 2644 | } |
| 2645 | |
| 2646 | CXXConstructorDecl *getCanonicalDecl() override { |
| 2647 | return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl()); |
| 2648 | } |
| 2649 | const CXXConstructorDecl *getCanonicalDecl() const { |
| 2650 | return const_cast<CXXConstructorDecl*>(this)->getCanonicalDecl(); |
| 2651 | } |
| 2652 | |
| 2653 | |
| 2654 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2655 | static bool classofKind(Kind K) { return K == CXXConstructor; } |
| 2656 | }; |
| 2657 | |
| 2658 | |
| 2659 | |
| 2660 | |
| 2661 | |
| 2662 | |
| 2663 | |
| 2664 | |
| 2665 | |
| 2666 | |
| 2667 | |
| 2668 | class CXXDestructorDecl : public CXXMethodDecl { |
| 2669 | friend class ASTDeclReader; |
| 2670 | friend class ASTDeclWriter; |
| 2671 | |
| 2672 | |
| 2673 | |
| 2674 | FunctionDecl *OperatorDelete = nullptr; |
| 2675 | Expr *OperatorDeleteThisArg = nullptr; |
| 2676 | |
| 2677 | CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
| 2678 | const DeclarationNameInfo &NameInfo, QualType T, |
| 2679 | TypeSourceInfo *TInfo, bool isInline, |
| 2680 | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
| 2681 | Expr *TrailingRequiresClause = nullptr) |
| 2682 | : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo, |
| 2683 | SC_None, isInline, ConstexprKind, SourceLocation(), |
| 2684 | TrailingRequiresClause) { |
| 2685 | setImplicit(isImplicitlyDeclared); |
| 2686 | } |
| 2687 | |
| 2688 | void anchor() override; |
| 2689 | |
| 2690 | public: |
| 2691 | static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, |
| 2692 | SourceLocation StartLoc, |
| 2693 | const DeclarationNameInfo &NameInfo, |
| 2694 | QualType T, TypeSourceInfo *TInfo, |
| 2695 | bool isInline, bool isImplicitlyDeclared, |
| 2696 | ConstexprSpecKind ConstexprKind, |
| 2697 | Expr *TrailingRequiresClause = nullptr); |
| 2698 | static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID); |
| 2699 | |
| 2700 | void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg); |
| 2701 | |
| 2702 | const FunctionDecl *getOperatorDelete() const { |
| 2703 | return getCanonicalDecl()->OperatorDelete; |
| 2704 | } |
| 2705 | |
| 2706 | Expr *getOperatorDeleteThisArg() const { |
| 2707 | return getCanonicalDecl()->OperatorDeleteThisArg; |
| 2708 | } |
| 2709 | |
| 2710 | CXXDestructorDecl *getCanonicalDecl() override { |
| 2711 | return cast<CXXDestructorDecl>(FunctionDecl::getCanonicalDecl()); |
| 2712 | } |
| 2713 | const CXXDestructorDecl *getCanonicalDecl() const { |
| 2714 | return const_cast<CXXDestructorDecl*>(this)->getCanonicalDecl(); |
| 2715 | } |
| 2716 | |
| 2717 | |
| 2718 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2719 | static bool classofKind(Kind K) { return K == CXXDestructor; } |
| 2720 | }; |
| 2721 | |
| 2722 | |
| 2723 | |
| 2724 | |
| 2725 | |
| 2726 | |
| 2727 | |
| 2728 | |
| 2729 | |
| 2730 | |
| 2731 | |
| 2732 | class CXXConversionDecl : public CXXMethodDecl { |
| 2733 | CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
| 2734 | const DeclarationNameInfo &NameInfo, QualType T, |
| 2735 | TypeSourceInfo *TInfo, bool isInline, ExplicitSpecifier ES, |
| 2736 | ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, |
| 2737 | Expr *TrailingRequiresClause = nullptr) |
| 2738 | : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo, |
| 2739 | SC_None, isInline, ConstexprKind, EndLocation, |
| 2740 | TrailingRequiresClause), |
| 2741 | ExplicitSpec(ES) {} |
| 2742 | void anchor() override; |
| 2743 | |
| 2744 | ExplicitSpecifier ExplicitSpec; |
| 2745 | |
| 2746 | public: |
| 2747 | friend class ASTDeclReader; |
| 2748 | friend class ASTDeclWriter; |
| 2749 | |
| 2750 | static CXXConversionDecl * |
| 2751 | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
| 2752 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
| 2753 | bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, |
| 2754 | SourceLocation EndLocation, Expr *TrailingRequiresClause = nullptr); |
| 2755 | static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 2756 | |
| 2757 | ExplicitSpecifier getExplicitSpecifier() { |
| 2758 | return getCanonicalDecl()->ExplicitSpec; |
| 2759 | } |
| 2760 | |
| 2761 | const ExplicitSpecifier getExplicitSpecifier() const { |
| 2762 | return getCanonicalDecl()->ExplicitSpec; |
| 2763 | } |
| 2764 | |
| 2765 | |
| 2766 | bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } |
| 2767 | void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } |
| 2768 | |
| 2769 | |
| 2770 | QualType getConversionType() const { |
| 2771 | return getType()->castAs<FunctionType>()->getReturnType(); |
| 2772 | } |
| 2773 | |
| 2774 | |
| 2775 | |
| 2776 | bool isLambdaToBlockPointerConversion() const; |
| 2777 | |
| 2778 | CXXConversionDecl *getCanonicalDecl() override { |
| 2779 | return cast<CXXConversionDecl>(FunctionDecl::getCanonicalDecl()); |
| 2780 | } |
| 2781 | const CXXConversionDecl *getCanonicalDecl() const { |
| 2782 | return const_cast<CXXConversionDecl*>(this)->getCanonicalDecl(); |
| 2783 | } |
| 2784 | |
| 2785 | |
| 2786 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2787 | static bool classofKind(Kind K) { return K == CXXConversion; } |
| 2788 | }; |
| 2789 | |
| 2790 | |
| 2791 | |
| 2792 | |
| 2793 | |
| 2794 | |
| 2795 | |
| 2796 | class LinkageSpecDecl : public Decl, public DeclContext { |
| 2797 | virtual void anchor(); |
| 2798 | |
| 2799 | |
| 2800 | public: |
| 2801 | |
| 2802 | |
| 2803 | |
| 2804 | |
| 2805 | enum LanguageIDs { lang_c = 1, lang_cxx = 2 }; |
| 2806 | |
| 2807 | private: |
| 2808 | |
| 2809 | SourceLocation ExternLoc; |
| 2810 | |
| 2811 | |
| 2812 | SourceLocation RBraceLoc; |
| 2813 | |
| 2814 | LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, |
| 2815 | SourceLocation LangLoc, LanguageIDs lang, bool HasBraces); |
| 2816 | |
| 2817 | public: |
| 2818 | static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, |
| 2819 | SourceLocation ExternLoc, |
| 2820 | SourceLocation LangLoc, LanguageIDs Lang, |
| 2821 | bool HasBraces); |
| 2822 | static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 2823 | |
| 2824 | |
| 2825 | LanguageIDs getLanguage() const { |
| 2826 | return static_cast<LanguageIDs>(LinkageSpecDeclBits.Language); |
| 2827 | } |
| 2828 | |
| 2829 | |
| 2830 | void setLanguage(LanguageIDs L) { LinkageSpecDeclBits.Language = L; } |
| 2831 | |
| 2832 | |
| 2833 | |
| 2834 | bool hasBraces() const { |
| 2835 | assert(!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces); |
| 2836 | return LinkageSpecDeclBits.HasBraces; |
| 2837 | } |
| 2838 | |
| 2839 | SourceLocation getExternLoc() const { return ExternLoc; } |
| 2840 | SourceLocation getRBraceLoc() const { return RBraceLoc; } |
| 2841 | void setExternLoc(SourceLocation L) { ExternLoc = L; } |
| 2842 | void setRBraceLoc(SourceLocation L) { |
| 2843 | RBraceLoc = L; |
| 2844 | LinkageSpecDeclBits.HasBraces = RBraceLoc.isValid(); |
| 2845 | } |
| 2846 | |
| 2847 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 2848 | if (hasBraces()) |
| 2849 | return getRBraceLoc(); |
| 2850 | |
| 2851 | |
| 2852 | return decls_empty() ? getLocation() : decls_begin()->getEndLoc(); |
| 2853 | } |
| 2854 | |
| 2855 | SourceRange getSourceRange() const override LLVM_READONLY { |
| 2856 | return SourceRange(ExternLoc, getEndLoc()); |
| 2857 | } |
| 2858 | |
| 2859 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2860 | static bool classofKind(Kind K) { return K == LinkageSpec; } |
| 2861 | |
| 2862 | static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { |
| 2863 | return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); |
| 2864 | } |
| 2865 | |
| 2866 | static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { |
| 2867 | return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); |
| 2868 | } |
| 2869 | }; |
| 2870 | |
| 2871 | |
| 2872 | |
| 2873 | |
| 2874 | |
| 2875 | |
| 2876 | |
| 2877 | |
| 2878 | |
| 2879 | |
| 2880 | |
| 2881 | class UsingDirectiveDecl : public NamedDecl { |
| 2882 | |
| 2883 | SourceLocation UsingLoc; |
| 2884 | |
| 2885 | |
| 2886 | SourceLocation NamespaceLoc; |
| 2887 | |
| 2888 | |
| 2889 | NestedNameSpecifierLoc QualifierLoc; |
| 2890 | |
| 2891 | |
| 2892 | NamedDecl *NominatedNamespace; |
| 2893 | |
| 2894 | |
| 2895 | |
| 2896 | DeclContext *CommonAncestor; |
| 2897 | |
| 2898 | UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc, |
| 2899 | SourceLocation NamespcLoc, |
| 2900 | NestedNameSpecifierLoc QualifierLoc, |
| 2901 | SourceLocation IdentLoc, |
| 2902 | NamedDecl *Nominated, |
| 2903 | DeclContext *CommonAncestor) |
| 2904 | : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc), |
| 2905 | NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc), |
| 2906 | NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) {} |
| 2907 | |
| 2908 | |
| 2909 | |
| 2910 | |
| 2911 | |
| 2912 | static DeclarationName getName() { |
| 2913 | return DeclarationName::getUsingDirectiveName(); |
| 2914 | } |
| 2915 | |
| 2916 | void anchor() override; |
| 2917 | |
| 2918 | public: |
| 2919 | friend class ASTDeclReader; |
| 2920 | |
| 2921 | |
| 2922 | friend class DeclContext; |
| 2923 | |
| 2924 | |
| 2925 | |
| 2926 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
| 2927 | |
| 2928 | |
| 2929 | |
| 2930 | NestedNameSpecifier *getQualifier() const { |
| 2931 | return QualifierLoc.getNestedNameSpecifier(); |
| 2932 | } |
| 2933 | |
| 2934 | NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; } |
| 2935 | const NamedDecl *getNominatedNamespaceAsWritten() const { |
| 2936 | return NominatedNamespace; |
| 2937 | } |
| 2938 | |
| 2939 | |
| 2940 | NamespaceDecl *getNominatedNamespace(); |
| 2941 | |
| 2942 | const NamespaceDecl *getNominatedNamespace() const { |
| 2943 | return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); |
| 2944 | } |
| 2945 | |
| 2946 | |
| 2947 | |
| 2948 | DeclContext *getCommonAncestor() { return CommonAncestor; } |
| 2949 | const DeclContext *getCommonAncestor() const { return CommonAncestor; } |
| 2950 | |
| 2951 | |
| 2952 | SourceLocation getUsingLoc() const { return UsingLoc; } |
| 2953 | |
| 2954 | |
| 2955 | |
| 2956 | SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } |
| 2957 | |
| 2958 | |
| 2959 | SourceLocation getIdentLocation() const { return getLocation(); } |
| 2960 | |
| 2961 | static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, |
| 2962 | SourceLocation UsingLoc, |
| 2963 | SourceLocation NamespaceLoc, |
| 2964 | NestedNameSpecifierLoc QualifierLoc, |
| 2965 | SourceLocation IdentLoc, |
| 2966 | NamedDecl *Nominated, |
| 2967 | DeclContext *CommonAncestor); |
| 2968 | static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 2969 | |
| 2970 | SourceRange getSourceRange() const override LLVM_READONLY { |
| 2971 | return SourceRange(UsingLoc, getLocation()); |
| 2972 | } |
| 2973 | |
| 2974 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2975 | static bool classofKind(Kind K) { return K == UsingDirective; } |
| 2976 | }; |
| 2977 | |
| 2978 | |
| 2979 | |
| 2980 | |
| 2981 | |
| 2982 | |
| 2983 | |
| 2984 | |
| 2985 | class NamespaceAliasDecl : public NamedDecl, |
| 2986 | public Redeclarable<NamespaceAliasDecl> { |
| 2987 | friend class ASTDeclReader; |
| 2988 | |
| 2989 | |
| 2990 | SourceLocation NamespaceLoc; |
| 2991 | |
| 2992 | |
| 2993 | |
| 2994 | |
| 2995 | SourceLocation IdentLoc; |
| 2996 | |
| 2997 | |
| 2998 | NestedNameSpecifierLoc QualifierLoc; |
| 2999 | |
| 3000 | |
| 3001 | |
| 3002 | NamedDecl *Namespace; |
| 3003 | |
| 3004 | NamespaceAliasDecl(ASTContext &C, DeclContext *DC, |
| 3005 | SourceLocation NamespaceLoc, SourceLocation AliasLoc, |
| 3006 | IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc, |
| 3007 | SourceLocation IdentLoc, NamedDecl *Namespace) |
| 3008 | : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C), |
| 3009 | NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc), |
| 3010 | QualifierLoc(QualifierLoc), Namespace(Namespace) {} |
| 3011 | |
| 3012 | void anchor() override; |
| 3013 | |
| 3014 | using redeclarable_base = Redeclarable<NamespaceAliasDecl>; |
| 3015 | |
| 3016 | NamespaceAliasDecl *getNextRedeclarationImpl() override; |
| 3017 | NamespaceAliasDecl *getPreviousDeclImpl() override; |
| 3018 | NamespaceAliasDecl *getMostRecentDeclImpl() override; |
| 3019 | |
| 3020 | public: |
| 3021 | static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, |
| 3022 | SourceLocation NamespaceLoc, |
| 3023 | SourceLocation AliasLoc, |
| 3024 | IdentifierInfo *Alias, |
| 3025 | NestedNameSpecifierLoc QualifierLoc, |
| 3026 | SourceLocation IdentLoc, |
| 3027 | NamedDecl *Namespace); |
| 3028 | |
| 3029 | static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 3030 | |
| 3031 | using redecl_range = redeclarable_base::redecl_range; |
| 3032 | using redecl_iterator = redeclarable_base::redecl_iterator; |
| 3033 | |
| 3034 | using redeclarable_base::redecls_begin; |
| 3035 | using redeclarable_base::redecls_end; |
| 3036 | using redeclarable_base::redecls; |
| 3037 | using redeclarable_base::getPreviousDecl; |
| 3038 | using redeclarable_base::getMostRecentDecl; |
| 3039 | |
| 3040 | NamespaceAliasDecl *getCanonicalDecl() override { |
| 3041 | return getFirstDecl(); |
| 3042 | } |
| 3043 | const NamespaceAliasDecl *getCanonicalDecl() const { |
| 3044 | return getFirstDecl(); |
| 3045 | } |
| 3046 | |
| 3047 | |
| 3048 | |
| 3049 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
| 3050 | |
| 3051 | |
| 3052 | |
| 3053 | NestedNameSpecifier *getQualifier() const { |
| 3054 | return QualifierLoc.getNestedNameSpecifier(); |
| 3055 | } |
| 3056 | |
| 3057 | |
| 3058 | NamespaceDecl *getNamespace() { |
| 3059 | if (auto *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) |
| 3060 | return AD->getNamespace(); |
| 3061 | |
| 3062 | return cast<NamespaceDecl>(Namespace); |
| 3063 | } |
| 3064 | |
| 3065 | const NamespaceDecl *getNamespace() const { |
| 3066 | return const_cast<NamespaceAliasDecl *>(this)->getNamespace(); |
| 3067 | } |
| 3068 | |
| 3069 | |
| 3070 | |
| 3071 | SourceLocation getAliasLoc() const { return getLocation(); } |
| 3072 | |
| 3073 | |
| 3074 | SourceLocation getNamespaceLoc() const { return NamespaceLoc; } |
| 3075 | |
| 3076 | |
| 3077 | SourceLocation getTargetNameLoc() const { return IdentLoc; } |
| 3078 | |
| 3079 | |
| 3080 | |
| 3081 | NamedDecl *getAliasedNamespace() const { return Namespace; } |
| 3082 | |
| 3083 | SourceRange getSourceRange() const override LLVM_READONLY { |
| 3084 | return SourceRange(NamespaceLoc, IdentLoc); |
| 3085 | } |
| 3086 | |
| 3087 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 3088 | static bool classofKind(Kind K) { return K == NamespaceAlias; } |
| 3089 | }; |
| 3090 | |
| 3091 | |
| 3092 | |
| 3093 | class LifetimeExtendedTemporaryDecl final |
| 3094 | : public Decl, |
| 3095 | public Mergeable<LifetimeExtendedTemporaryDecl> { |
| 3096 | friend class MaterializeTemporaryExpr; |
| 3097 | friend class ASTDeclReader; |
| 3098 | |
| 3099 | Stmt *ExprWithTemporary = nullptr; |
| 3100 | |
| 3101 | |
| 3102 | |
| 3103 | ValueDecl *ExtendingDecl = nullptr; |
| 3104 | unsigned ManglingNumber; |
| 3105 | |
| 3106 | mutable APValue *Value = nullptr; |
| 3107 | |
| 3108 | virtual void anchor(); |
| 3109 | |
| 3110 | LifetimeExtendedTemporaryDecl(Expr *Temp, ValueDecl *EDecl, unsigned Mangling) |
| 3111 | : Decl(Decl::LifetimeExtendedTemporary, EDecl->getDeclContext(), |
| 3112 | EDecl->getLocation()), |
| 3113 | ExprWithTemporary(Temp), ExtendingDecl(EDecl), |
| 3114 | ManglingNumber(Mangling) {} |
| 3115 | |
| 3116 | LifetimeExtendedTemporaryDecl(EmptyShell) |
| 3117 | : Decl(Decl::LifetimeExtendedTemporary, EmptyShell{}) {} |
| 3118 | |
| 3119 | public: |
| 3120 | static LifetimeExtendedTemporaryDecl *Create(Expr *Temp, ValueDecl *EDec, |
| 3121 | unsigned Mangling) { |
| 3122 | return new (EDec->getASTContext(), EDec->getDeclContext()) |
| 3123 | LifetimeExtendedTemporaryDecl(Temp, EDec, Mangling); |
| 3124 | } |
| 3125 | static LifetimeExtendedTemporaryDecl *CreateDeserialized(ASTContext &C, |
| 3126 | unsigned ID) { |
| 3127 | return new (C, ID) LifetimeExtendedTemporaryDecl(EmptyShell{}); |
| 3128 | } |
| 3129 | |
| 3130 | ValueDecl *getExtendingDecl() { return ExtendingDecl; } |
| 3131 | const ValueDecl *getExtendingDecl() const { return ExtendingDecl; } |
| 3132 | |
| 3133 | |
| 3134 | StorageDuration getStorageDuration() const; |
| 3135 | |
| 3136 | |
| 3137 | |
| 3138 | |
| 3139 | |
| 3140 | |
| 3141 | Expr *getTemporaryExpr() { return cast<Expr>(ExprWithTemporary); } |
| 3142 | const Expr *getTemporaryExpr() const { return cast<Expr>(ExprWithTemporary); } |
| 3143 | |
| 3144 | unsigned getManglingNumber() const { return ManglingNumber; } |
| 3145 | |
| 3146 | |
| 3147 | |
| 3148 | APValue *getOrCreateValue(bool MayCreate) const; |
| 3149 | |
| 3150 | APValue *getValue() const { return Value; } |
| 3151 | |
| 3152 | |
| 3153 | Stmt::child_range childrenExpr() { |
| 3154 | return Stmt::child_range(&ExprWithTemporary, &ExprWithTemporary + 1); |
| 3155 | } |
| 3156 | |
| 3157 | Stmt::const_child_range childrenExpr() const { |
| 3158 | return Stmt::const_child_range(&ExprWithTemporary, &ExprWithTemporary + 1); |
| 3159 | } |
| 3160 | |
| 3161 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 3162 | static bool classofKind(Kind K) { |
| 3163 | return K == Decl::LifetimeExtendedTemporary; |
| 3164 | } |
| 3165 | }; |
| 3166 | |
| 3167 | |
| 3168 | |
| 3169 | |
| 3170 | |
| 3171 | |
| 3172 | |
| 3173 | |
| 3174 | |
| 3175 | |
| 3176 | |
| 3177 | |
| 3178 | |
| 3179 | |
| 3180 | |
| 3181 | |
| 3182 | |
| 3183 | |
| 3184 | |
| 3185 | |
| 3186 | class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> { |
| 3187 | friend class BaseUsingDecl; |
| 3188 | |
| 3189 | |
| 3190 | NamedDecl *Underlying = nullptr; |
| 3191 | |
| 3192 | |
| 3193 | |
| 3194 | NamedDecl *UsingOrNextShadow = nullptr; |
| 3195 | |
| 3196 | void anchor() override; |
| 3197 | |
| 3198 | using redeclarable_base = Redeclarable<UsingShadowDecl>; |
| 3199 | |
| 3200 | UsingShadowDecl *getNextRedeclarationImpl() override { |
| 3201 | return getNextRedeclaration(); |
| 3202 | } |
| 3203 | |
| 3204 | UsingShadowDecl *getPreviousDeclImpl() override { |
| 3205 | return getPreviousDecl(); |
| 3206 | } |
| 3207 | |
| 3208 | UsingShadowDecl *getMostRecentDeclImpl() override { |
| 3209 | return getMostRecentDecl(); |
| 3210 | } |
| 3211 | |
| 3212 | protected: |
| 3213 | UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc, |
| 3214 | DeclarationName Name, BaseUsingDecl *Introducer, |
| 3215 | NamedDecl *Target); |
| 3216 | UsingShadowDecl(Kind K, ASTContext &C, EmptyShell); |
| 3217 | |
| 3218 | public: |
| 3219 | friend class ASTDeclReader; |
| 3220 | friend class ASTDeclWriter; |
| 3221 | |
| 3222 | static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC, |
| 3223 | SourceLocation Loc, DeclarationName Name, |
| 3224 | BaseUsingDecl *Introducer, NamedDecl *Target) { |
| 3225 | return new (C, DC) |
| 3226 | UsingShadowDecl(UsingShadow, C, DC, Loc, Name, Introducer, Target); |
| 3227 | } |
| 3228 | |
| 3229 | static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 3230 | |
| 3231 | using redecl_range = redeclarable_base::redecl_range; |
| 3232 | using redecl_iterator = redeclarable_base::redecl_iterator; |
| 3233 | |
| 3234 | using redeclarable_base::redecls_begin; |
| 3235 | using redeclarable_base::redecls_end; |
| 3236 | using redeclarable_base::redecls; |
| 3237 | using redeclarable_base::getPreviousDecl; |
| 3238 | using redeclarable_base::getMostRecentDecl; |
| 3239 | using redeclarable_base::isFirstDecl; |
| 3240 | |
| 3241 | UsingShadowDecl *getCanonicalDecl() override { |
| 3242 | return getFirstDecl(); |
| 3243 | } |
| 3244 | const UsingShadowDecl *getCanonicalDecl() const { |
| 3245 | return getFirstDecl(); |
| 3246 | } |
| 3247 | |
| 3248 | |
| 3249 | |
| 3250 | NamedDecl *getTargetDecl() const { return Underlying; } |
| 3251 | |
| 3252 | |
| 3253 | |
| 3254 | void setTargetDecl(NamedDecl *ND) { |
| 3255 | assert(ND && "Target decl is null!"); |
| 3256 | Underlying = ND; |
| 3257 | |
| 3258 | |
| 3259 | IdentifierNamespace = |
| 3260 | ND->getIdentifierNamespace() & |
| 3261 | ~(IDNS_OrdinaryFriend | IDNS_TagFriend | IDNS_LocalExtern); |
| 3262 | } |
| 3263 | |
| 3264 | |
| 3265 | |
| 3266 | BaseUsingDecl *getIntroducer() const; |
| 3267 | |
| 3268 | |
| 3269 | |
| 3270 | UsingShadowDecl *getNextUsingShadowDecl() const { |
| 3271 | return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow); |
| 3272 | } |
| 3273 | |
| 3274 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 3275 | static bool classofKind(Kind K) { |
| 3276 | return K == Decl::UsingShadow || K == Decl::ConstructorUsingShadow; |
| 3277 | } |
| 3278 | }; |
| 3279 | |
| 3280 | |
| 3281 | |
| 3282 | |
| 3283 | class BaseUsingDecl : public NamedDecl { |
| 3284 | |
| 3285 | |
| 3286 | |
| 3287 | |
| 3288 | |
| 3289 | llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow; |
| 3290 | |
| 3291 | protected: |
| 3292 | BaseUsingDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N) |
| 3293 | : NamedDecl(DK, DC, L, N), FirstUsingShadow(nullptr, 0) {} |
| 3294 | |
| 3295 | private: |
| 3296 | void anchor() override; |
| 3297 | |
| 3298 | protected: |
| 3299 | |
| 3300 | bool getShadowFlag() const { return FirstUsingShadow.getInt(); } |
| 3301 | |
| 3302 | |
| 3303 | void setShadowFlag(bool V) { FirstUsingShadow.setInt(V); } |
| 3304 | |
| 3305 | public: |
| 3306 | friend class ASTDeclReader; |
| 3307 | friend class ASTDeclWriter; |
| 3308 | |
| 3309 | |
| 3310 | |
| 3311 | class shadow_iterator { |
| 3312 | |
| 3313 | UsingShadowDecl *Current = nullptr; |
| 3314 | |
| 3315 | public: |
| 3316 | using value_type = UsingShadowDecl *; |
| 3317 | using reference = UsingShadowDecl *; |
| 3318 | using pointer = UsingShadowDecl *; |
| 3319 | using iterator_category = std::forward_iterator_tag; |
| 3320 | using difference_type = std::ptrdiff_t; |
| 3321 | |
| 3322 | shadow_iterator() = default; |
| 3323 | explicit shadow_iterator(UsingShadowDecl *C) : Current(C) {} |
| 3324 | |
| 3325 | reference operator*() const { return Current; } |
| 3326 | pointer operator->() const { return Current; } |
| 3327 | |
| 3328 | shadow_iterator &operator++() { |
| 3329 | Current = Current->getNextUsingShadowDecl(); |
| 3330 | return *this; |
| 3331 | } |
| 3332 | |
| 3333 | shadow_iterator operator++(int) { |
| 3334 | shadow_iterator tmp(*this); |
| 3335 | ++(*this); |
| 3336 | return tmp; |
| 3337 | } |
| 3338 | |
| 3339 | friend bool operator==(shadow_iterator x, shadow_iterator y) { |
| 3340 | return x.Current == y.Current; |
| 3341 | } |
| 3342 | friend bool operator!=(shadow_iterator x, shadow_iterator y) { |
| 3343 | return x.Current != y.Current; |
| 3344 | } |
| 3345 | }; |
| 3346 | |
| 3347 | using shadow_range = llvm::iterator_range<shadow_iterator>; |
| 3348 | |
| 3349 | shadow_range shadows() const { |
| 3350 | return shadow_range(shadow_begin(), shadow_end()); |
| 3351 | } |
| 3352 | |
| 3353 | shadow_iterator shadow_begin() const { |
| 3354 | return shadow_iterator(FirstUsingShadow.getPointer()); |
| 3355 | } |
| 3356 | |
| 3357 | shadow_iterator shadow_end() const { return shadow_iterator(); } |
| 3358 | |
| 3359 | |
| 3360 | |
| 3361 | unsigned shadow_size() const { |
| 3362 | return std::distance(shadow_begin(), shadow_end()); |
| 3363 | } |
| 3364 | |
| 3365 | void addShadowDecl(UsingShadowDecl *S); |
| 3366 | void removeShadowDecl(UsingShadowDecl *S); |
| 3367 | |
| 3368 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 3369 | static bool classofKind(Kind K) { return K == Using || K == UsingEnum; } |
| 3370 | }; |
| 3371 | |
| 3372 | |
| 3373 | |
| 3374 | |
| 3375 | |
| 3376 | |
| 3377 | |
| 3378 | class UsingDecl : public BaseUsingDecl, public Mergeable<UsingDecl> { |
| 3379 | |
| 3380 | SourceLocation UsingLocation; |
| 3381 | |
| 3382 | |
| 3383 | NestedNameSpecifierLoc QualifierLoc; |
| 3384 | |
| 3385 | |
| 3386 | |
| 3387 | DeclarationNameLoc DNLoc; |
| 3388 | |
| 3389 | UsingDecl(DeclContext *DC, SourceLocation UL, |
| 3390 | NestedNameSpecifierLoc QualifierLoc, |
| 3391 | const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword) |
| 3392 | : BaseUsingDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()), |
| 3393 | UsingLocation(UL), QualifierLoc(QualifierLoc), |
| 3394 | DNLoc(NameInfo.getInfo()) { |
| 3395 | setShadowFlag(HasTypenameKeyword); |
| 3396 | } |
| 3397 | |
| 3398 | void anchor() override; |
| 3399 | |
| 3400 | public: |
| 3401 | friend class ASTDeclReader; |
| 3402 | friend class ASTDeclWriter; |
| 3403 | |
| 3404 | |
| 3405 | SourceLocation getUsingLoc() const { return UsingLocation; } |
| 3406 | |
| 3407 | |
| 3408 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
| 3409 | |
| 3410 | |
| 3411 | |
| 3412 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
| 3413 | |
| 3414 | |
| 3415 | NestedNameSpecifier *getQualifier() const { |
| 3416 | return QualifierLoc.getNestedNameSpecifier(); |
| 3417 | } |
| 3418 | |
| 3419 | DeclarationNameInfo getNameInfo() const { |
| 3420 | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
| 3421 | } |
| 3422 | |
| 3423 | |
| 3424 | bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } |
| 3425 | |
| 3426 | |
| 3427 | bool hasTypename() const { return getShadowFlag(); } |
| 3428 | |
| 3429 | |
| 3430 | void setTypename(bool TN) { setShadowFlag(TN); } |
| 3431 | |
| 3432 | static UsingDecl *Create(ASTContext &C, DeclContext *DC, |
| 3433 | SourceLocation UsingL, |
| 3434 | NestedNameSpecifierLoc QualifierLoc, |
| 3435 | const DeclarationNameInfo &NameInfo, |
| 3436 | bool HasTypenameKeyword); |
| 3437 | |
| 3438 | static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 3439 | |
| 3440 | SourceRange getSourceRange() const override LLVM_READONLY; |
| 3441 | |
| 3442 | |
| 3443 | UsingDecl *getCanonicalDecl() override { |
| 3444 | return cast<UsingDecl>(getFirstDecl()); |
| 3445 | } |
| 3446 | const UsingDecl *getCanonicalDecl() const { |
| 3447 | return cast<UsingDecl>(getFirstDecl()); |
| 3448 | } |
| 3449 | |
| 3450 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 3451 | static bool classofKind(Kind K) { return K == Using; } |
| 3452 | }; |
| 3453 | |
| 3454 | |
| 3455 | |
| 3456 | |
| 3457 | |
| 3458 | |
| 3459 | |
| 3460 | |
| 3461 | |
| 3462 | |
| 3463 | |
| 3464 | class ConstructorUsingShadowDecl final : public UsingShadowDecl { |
| 3465 | |
| 3466 | |
| 3467 | |
| 3468 | ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl = nullptr; |
| 3469 | |
| 3470 | |
| 3471 | |
| 3472 | |
| 3473 | |
| 3474 | ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl = nullptr; |
| 3475 | |
| 3476 | |
| 3477 | |
| 3478 | |
| 3479 | unsigned IsVirtual : 1; |
| 3480 | |
| 3481 | ConstructorUsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc, |
| 3482 | UsingDecl *Using, NamedDecl *Target, |
| 3483 | bool TargetInVirtualBase) |
| 3484 | : UsingShadowDecl(ConstructorUsingShadow, C, DC, Loc, |
| 3485 | Using->getDeclName(), Using, |
| 3486 | Target->getUnderlyingDecl()), |
| 3487 | NominatedBaseClassShadowDecl( |
| 3488 | dyn_cast<ConstructorUsingShadowDecl>(Target)), |
| 3489 | ConstructedBaseClassShadowDecl(NominatedBaseClassShadowDecl), |
| 3490 | IsVirtual(TargetInVirtualBase) { |
| 3491 | |
| 3492 | |
| 3493 | |
| 3494 | if (NominatedBaseClassShadowDecl && |
| 3495 | NominatedBaseClassShadowDecl->constructsVirtualBase()) { |
| 3496 | ConstructedBaseClassShadowDecl = |
| 3497 | NominatedBaseClassShadowDecl->ConstructedBaseClassShadowDecl; |
| 3498 | IsVirtual = true; |
| 3499 | } |
| 3500 | } |
| 3501 | |
| 3502 | ConstructorUsingShadowDecl(ASTContext &C, EmptyShell Empty) |
| 3503 | : UsingShadowDecl(ConstructorUsingShadow, C, Empty), IsVirtual(false) {} |
| 3504 | |
| 3505 | void anchor() override; |
| 3506 | |
| 3507 | public: |
| 3508 | friend class ASTDeclReader; |
| 3509 | friend class ASTDeclWriter; |
| 3510 | |
| 3511 | static ConstructorUsingShadowDecl *Create(ASTContext &C, DeclContext *DC, |
| 3512 | SourceLocation Loc, |
| 3513 | UsingDecl *Using, NamedDecl *Target, |
| 3514 | bool IsVirtual); |
| 3515 | static ConstructorUsingShadowDecl *CreateDeserialized(ASTContext &C, |
| 3516 | unsigned ID); |
| 3517 | |
| 3518 | |
| 3519 | |
| 3520 | UsingDecl *getIntroducer() const { |
| 3521 | return cast<UsingDecl>(UsingShadowDecl::getIntroducer()); |
| 3522 | } |
| 3523 | |
| 3524 | |
| 3525 | |
| 3526 | |
| 3527 | const CXXRecordDecl *getParent() const { |
| 3528 | return cast<CXXRecordDecl>(getDeclContext()); |
| 3529 | } |
| 3530 | CXXRecordDecl *getParent() { |
| 3531 | return cast<CXXRecordDecl>(getDeclContext()); |
| 3532 | } |
| 3533 | |
| 3534 | |
| 3535 | |
| 3536 | |
| 3537 | |
| 3538 | ConstructorUsingShadowDecl *getNominatedBaseClassShadowDecl() const { |
| 3539 | return NominatedBaseClassShadowDecl; |
| 3540 | } |
| 3541 | |
| 3542 | |
| 3543 | |
| 3544 | ConstructorUsingShadowDecl *getConstructedBaseClassShadowDecl() const { |
| 3545 | return ConstructedBaseClassShadowDecl; |
| 3546 | } |
| 3547 | |
| 3548 | |
| 3549 | |
| 3550 | CXXRecordDecl *getNominatedBaseClass() const; |
| 3551 | |
| 3552 | |
| 3553 | |
| 3554 | CXXRecordDecl *getConstructedBaseClass() const { |
| 3555 | return cast<CXXRecordDecl>((ConstructedBaseClassShadowDecl |
| 3556 | ? ConstructedBaseClassShadowDecl |
| 3557 | : getTargetDecl()) |
| 3558 | ->getDeclContext()); |
| 3559 | } |
| 3560 | |
| 3561 | |
| 3562 | |
| 3563 | bool constructsVirtualBase() const { |
| 3564 | return IsVirtual; |
| 3565 | } |
| 3566 | |
| 3567 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 3568 | static bool classofKind(Kind K) { return K == ConstructorUsingShadow; } |
| 3569 | }; |
| 3570 | |
| 3571 | |
| 3572 | |
| 3573 | |
| 3574 | |
| 3575 | |
| 3576 | |
| 3577 | |
| 3578 | class UsingEnumDecl : public BaseUsingDecl, public Mergeable<UsingEnumDecl> { |
| 3579 | |
| 3580 | SourceLocation UsingLocation; |
| 3581 | |
| 3582 | |
| 3583 | SourceLocation EnumLocation; |
| 3584 | |
| 3585 | |
| 3586 | EnumDecl *Enum; |
| 3587 | |
| 3588 | UsingEnumDecl(DeclContext *DC, DeclarationName DN, SourceLocation UL, |
| 3589 | SourceLocation EL, SourceLocation NL, EnumDecl *ED) |
| 3590 | : BaseUsingDecl(UsingEnum, DC, NL, DN), UsingLocation(UL), |
| 3591 | EnumLocation(EL), Enum(ED) {} |
| 3592 | |
| 3593 | void anchor() override; |
| 3594 | |
| 3595 | public: |
| 3596 | friend class ASTDeclReader; |
| 3597 | friend class ASTDeclWriter; |
| 3598 | |
| 3599 | |
| 3600 | SourceLocation getUsingLoc() const { return UsingLocation; } |
| 3601 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
| 3602 | |
| 3603 | |
| 3604 | SourceLocation getEnumLoc() const { return EnumLocation; } |
| 3605 | void setEnumLoc(SourceLocation L) { EnumLocation = L; } |
| 3606 | |
| 3607 | public: |
| 3608 | EnumDecl *getEnumDecl() const { return Enum; } |
| 3609 | |
| 3610 | static UsingEnumDecl *Create(ASTContext &C, DeclContext *DC, |
| 3611 | SourceLocation UsingL, SourceLocation EnumL, |
| 3612 | SourceLocation NameL, EnumDecl *ED); |
| 3613 | |
| 3614 | static UsingEnumDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 3615 | |
| 3616 | SourceRange getSourceRange() const override LLVM_READONLY; |
| 3617 | |
| 3618 | |
| 3619 | UsingEnumDecl *getCanonicalDecl() override { |
| 3620 | return cast<UsingEnumDecl>(getFirstDecl()); |
| 3621 | } |
| 3622 | const UsingEnumDecl *getCanonicalDecl() const { |
| 3623 | return cast<UsingEnumDecl>(getFirstDecl()); |
| 3624 | } |
| 3625 | |
| 3626 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 3627 | static bool classofKind(Kind K) { return K == UsingEnum; } |
| 3628 | }; |
| 3629 | |
| 3630 | |
| 3631 | |
| 3632 | |
| 3633 | |
| 3634 | |
| 3635 | |
| 3636 | |
| 3637 | |
| 3638 | |
| 3639 | |
| 3640 | |
| 3641 | |
| 3642 | |
| 3643 | class UsingPackDecl final |
| 3644 | : public NamedDecl, public Mergeable<UsingPackDecl>, |
| 3645 | private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> { |
| 3646 | |
| 3647 | |
| 3648 | NamedDecl *InstantiatedFrom; |
| 3649 | |
| 3650 | |
| 3651 | unsigned NumExpansions; |
| 3652 | |
| 3653 | UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom, |
| 3654 | ArrayRef<NamedDecl *> UsingDecls) |
| 3655 | : NamedDecl(UsingPack, DC, |
| 3656 | InstantiatedFrom ? InstantiatedFrom->getLocation() |
| 3657 | : SourceLocation(), |
| 3658 | InstantiatedFrom ? InstantiatedFrom->getDeclName() |
| 3659 | : DeclarationName()), |
| 3660 | InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) { |
| 3661 | std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(), |
| 3662 | getTrailingObjects<NamedDecl *>()); |
| 3663 | } |
| 3664 | |
| 3665 | void anchor() override; |
| 3666 | |
| 3667 | public: |
| 3668 | friend class ASTDeclReader; |
| 3669 | friend class ASTDeclWriter; |
| 3670 | friend TrailingObjects; |
| 3671 | |
| 3672 | |
| 3673 | |
| 3674 | |
| 3675 | NamedDecl *getInstantiatedFromUsingDecl() const { return InstantiatedFrom; } |
| 3676 | |
| 3677 | |
| 3678 | |
| 3679 | ArrayRef<NamedDecl *> expansions() const { |
| 3680 | return llvm::makeArrayRef(getTrailingObjects<NamedDecl *>(), NumExpansions); |
| 3681 | } |
| 3682 | |
| 3683 | static UsingPackDecl *Create(ASTContext &C, DeclContext *DC, |
| 3684 | NamedDecl *InstantiatedFrom, |
| 3685 | ArrayRef<NamedDecl *> UsingDecls); |
| 3686 | |
| 3687 | static UsingPackDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
| 3688 | unsigned NumExpansions); |
| 3689 | |
| 3690 | SourceRange getSourceRange() const override LLVM_READONLY { |
| 3691 | return InstantiatedFrom->getSourceRange(); |
| 3692 | } |
| 3693 | |
| 3694 | UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); } |
| 3695 | const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); } |
| 3696 | |
| 3697 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 3698 | static bool classofKind(Kind K) { return K == UsingPack; } |
| 3699 | }; |
| 3700 | |
| 3701 | |
| 3702 | |
| 3703 | |
| 3704 | |
| 3705 | |
| 3706 | |
| 3707 | |
| 3708 | |
| 3709 | |
| 3710 | |
| 3711 | |
| 3712 | class UnresolvedUsingValueDecl : public ValueDecl, |
| 3713 | public Mergeable<UnresolvedUsingValueDecl> { |
| 3714 | |
| 3715 | SourceLocation UsingLocation; |
| 3716 | |
| 3717 | |
| 3718 | SourceLocation EllipsisLoc; |
| 3719 | |
| 3720 | |
| 3721 | NestedNameSpecifierLoc QualifierLoc; |
| 3722 | |
| 3723 | |
| 3724 | |
| 3725 | DeclarationNameLoc DNLoc; |
| 3726 | |
| 3727 | UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty, |
| 3728 | SourceLocation UsingLoc, |
| 3729 | NestedNameSpecifierLoc QualifierLoc, |
| 3730 | const DeclarationNameInfo &NameInfo, |
| 3731 | SourceLocation EllipsisLoc) |
| 3732 | : ValueDecl(UnresolvedUsingValue, DC, |
| 3733 | NameInfo.getLoc(), NameInfo.getName(), Ty), |
| 3734 | UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc), |
| 3735 | QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo()) {} |
| 3736 | |
| 3737 | void anchor() override; |
| 3738 | |
| 3739 | public: |
| 3740 | friend class ASTDeclReader; |
| 3741 | friend class ASTDeclWriter; |
| 3742 | |
| 3743 | |
| 3744 | SourceLocation getUsingLoc() const { return UsingLocation; } |
| 3745 | |
| 3746 | |
| 3747 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
| 3748 | |
| 3749 | |
| 3750 | bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } |
| 3751 | |
| 3752 | |
| 3753 | |
| 3754 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
| 3755 | |
| 3756 | |
| 3757 | NestedNameSpecifier *getQualifier() const { |
| 3758 | return QualifierLoc.getNestedNameSpecifier(); |
| 3759 | } |
| 3760 | |
| 3761 | DeclarationNameInfo getNameInfo() const { |
| 3762 | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
| 3763 | } |
| 3764 | |
| 3765 | |
| 3766 | bool isPackExpansion() const { |
| 3767 | return EllipsisLoc.isValid(); |
| 3768 | } |
| 3769 | |
| 3770 | |
| 3771 | SourceLocation getEllipsisLoc() const { |
| 3772 | return EllipsisLoc; |
| 3773 | } |
| 3774 | |
| 3775 | static UnresolvedUsingValueDecl * |
| 3776 | Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, |
| 3777 | NestedNameSpecifierLoc QualifierLoc, |
| 3778 | const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc); |
| 3779 | |
| 3780 | static UnresolvedUsingValueDecl * |
| 3781 | CreateDeserialized(ASTContext &C, unsigned ID); |
| 3782 | |
| 3783 | SourceRange getSourceRange() const override LLVM_READONLY; |
| 3784 | |
| 3785 | |
| 3786 | UnresolvedUsingValueDecl *getCanonicalDecl() override { |
| 3787 | return getFirstDecl(); |
| 3788 | } |
| 3789 | const UnresolvedUsingValueDecl *getCanonicalDecl() const { |
| 3790 | return getFirstDecl(); |
| 3791 | } |
| 3792 | |
| 3793 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 3794 | static bool classofKind(Kind K) { return K == UnresolvedUsingValue; } |
| 3795 | }; |
| 3796 | |
| 3797 | |
| 3798 | |
| 3799 | |
| 3800 | |
| 3801 | |
| 3802 | |
| 3803 | |
| 3804 | |
| 3805 | |
| 3806 | |
| 3807 | |
| 3808 | class UnresolvedUsingTypenameDecl |
| 3809 | : public TypeDecl, |
| 3810 | public Mergeable<UnresolvedUsingTypenameDecl> { |
| 3811 | friend class ASTDeclReader; |
| 3812 | |
| 3813 | |
| 3814 | SourceLocation TypenameLocation; |
| 3815 | |
| 3816 | |
| 3817 | SourceLocation EllipsisLoc; |
| 3818 | |
| 3819 | |
| 3820 | NestedNameSpecifierLoc QualifierLoc; |
| 3821 | |
| 3822 | UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc, |
| 3823 | SourceLocation TypenameLoc, |
| 3824 | NestedNameSpecifierLoc QualifierLoc, |
| 3825 | SourceLocation TargetNameLoc, |
| 3826 | IdentifierInfo *TargetName, |
| 3827 | SourceLocation EllipsisLoc) |
| 3828 | : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName, |
| 3829 | UsingLoc), |
| 3830 | TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc), |
| 3831 | QualifierLoc(QualifierLoc) {} |
| 3832 | |
| 3833 | void anchor() override; |
| 3834 | |
| 3835 | public: |
| 3836 | |
| 3837 | SourceLocation getUsingLoc() const { return getBeginLoc(); } |
| 3838 | |
| 3839 | |
| 3840 | SourceLocation getTypenameLoc() const { return TypenameLocation; } |
| 3841 | |
| 3842 | |
| 3843 | |
| 3844 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
| 3845 | |
| 3846 | |
| 3847 | NestedNameSpecifier *getQualifier() const { |
| 3848 | return QualifierLoc.getNestedNameSpecifier(); |
| 3849 | } |
| 3850 | |
| 3851 | DeclarationNameInfo getNameInfo() const { |
| 3852 | return DeclarationNameInfo(getDeclName(), getLocation()); |
| 3853 | } |
| 3854 | |
| 3855 | |
| 3856 | bool isPackExpansion() const { |
| 3857 | return EllipsisLoc.isValid(); |
| 3858 | } |
| 3859 | |
| 3860 | |
| 3861 | SourceLocation getEllipsisLoc() const { |
| 3862 | return EllipsisLoc; |
| 3863 | } |
| 3864 | |
| 3865 | static UnresolvedUsingTypenameDecl * |
| 3866 | Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, |
| 3867 | SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc, |
| 3868 | SourceLocation TargetNameLoc, DeclarationName TargetName, |
| 3869 | SourceLocation EllipsisLoc); |
| 3870 | |
| 3871 | static UnresolvedUsingTypenameDecl * |
| 3872 | CreateDeserialized(ASTContext &C, unsigned ID); |
| 3873 | |
| 3874 | |
| 3875 | UnresolvedUsingTypenameDecl *getCanonicalDecl() override { |
| 3876 | return getFirstDecl(); |
| 3877 | } |
| 3878 | const UnresolvedUsingTypenameDecl *getCanonicalDecl() const { |
| 3879 | return getFirstDecl(); |
| 3880 | } |
| 3881 | |
| 3882 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 3883 | static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; } |
| 3884 | }; |
| 3885 | |
| 3886 | |
| 3887 | |
| 3888 | |
| 3889 | |
| 3890 | |
| 3891 | class UnresolvedUsingIfExistsDecl final : public NamedDecl { |
| 3892 | UnresolvedUsingIfExistsDecl(DeclContext *DC, SourceLocation Loc, |
| 3893 | DeclarationName Name); |
| 3894 | |
| 3895 | void anchor() override; |
| 3896 | |
| 3897 | public: |
| 3898 | static UnresolvedUsingIfExistsDecl *Create(ASTContext &Ctx, DeclContext *DC, |
| 3899 | SourceLocation Loc, |
| 3900 | DeclarationName Name); |
| 3901 | static UnresolvedUsingIfExistsDecl *CreateDeserialized(ASTContext &Ctx, |
| 3902 | unsigned ID); |
| 3903 | |
| 3904 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 3905 | static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingIfExists; } |
| 3906 | }; |
| 3907 | |
| 3908 | |
| 3909 | class StaticAssertDecl : public Decl { |
| 3910 | llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed; |
| 3911 | StringLiteral *Message; |
| 3912 | SourceLocation RParenLoc; |
| 3913 | |
| 3914 | StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc, |
| 3915 | Expr *AssertExpr, StringLiteral *Message, |
| 3916 | SourceLocation RParenLoc, bool Failed) |
| 3917 | : Decl(StaticAssert, DC, StaticAssertLoc), |
| 3918 | AssertExprAndFailed(AssertExpr, Failed), Message(Message), |
| 3919 | RParenLoc(RParenLoc) {} |
| 3920 | |
| 3921 | virtual void anchor(); |
| 3922 | |
| 3923 | public: |
| 3924 | friend class ASTDeclReader; |
| 3925 | |
| 3926 | static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, |
| 3927 | SourceLocation StaticAssertLoc, |
| 3928 | Expr *AssertExpr, StringLiteral *Message, |
| 3929 | SourceLocation RParenLoc, bool Failed); |
| 3930 | static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 3931 | |
| 3932 | Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); } |
| 3933 | const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); } |
| 3934 | |
| 3935 | StringLiteral *getMessage() { return Message; } |
| 3936 | const StringLiteral *getMessage() const { return Message; } |
| 3937 | |
| 3938 | bool isFailed() const { return AssertExprAndFailed.getInt(); } |
| 3939 | |
| 3940 | SourceLocation getRParenLoc() const { return RParenLoc; } |
| 3941 | |
| 3942 | SourceRange getSourceRange() const override LLVM_READONLY { |
| 3943 | return SourceRange(getLocation(), getRParenLoc()); |
| 3944 | } |
| 3945 | |
| 3946 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 3947 | static bool classofKind(Kind K) { return K == StaticAssert; } |
| 3948 | }; |
| 3949 | |
| 3950 | |
| 3951 | |
| 3952 | |
| 3953 | |
| 3954 | |
| 3955 | |
| 3956 | |
| 3957 | |
| 3958 | class BindingDecl : public ValueDecl { |
| 3959 | |
| 3960 | ValueDecl *Decomp; |
| 3961 | |
| 3962 | |
| 3963 | |
| 3964 | |
| 3965 | Expr *Binding = nullptr; |
| 3966 | |
| 3967 | BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id) |
| 3968 | : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {} |
| 3969 | |
| 3970 | void anchor() override; |
| 3971 | |
| 3972 | public: |
| 3973 | friend class ASTDeclReader; |
| 3974 | |
| 3975 | static BindingDecl *Create(ASTContext &C, DeclContext *DC, |
| 3976 | SourceLocation IdLoc, IdentifierInfo *Id); |
| 3977 | static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 3978 | |
| 3979 | |
| 3980 | |
| 3981 | |
| 3982 | Expr *getBinding() const { return Binding; } |
| 3983 | |
| 3984 | |
| 3985 | |
| 3986 | ValueDecl *getDecomposedDecl() const { return Decomp; } |
| 3987 | |
| 3988 | |
| 3989 | |
| 3990 | VarDecl *getHoldingVar() const; |
| 3991 | |
| 3992 | |
| 3993 | |
| 3994 | |
| 3995 | void setBinding(QualType DeclaredType, Expr *Binding) { |
| 3996 | setType(DeclaredType); |
| 3997 | this->Binding = Binding; |
| 3998 | } |
| 3999 | |
| 4000 | |
| 4001 | void setDecomposedDecl(ValueDecl *Decomposed) { Decomp = Decomposed; } |
| 4002 | |
| 4003 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 4004 | static bool classofKind(Kind K) { return K == Decl::Binding; } |
| 4005 | }; |
| 4006 | |
| 4007 | |
| 4008 | |
| 4009 | |
| 4010 | |
| 4011 | |
| 4012 | |
| 4013 | |
| 4014 | |
| 4015 | class DecompositionDecl final |
| 4016 | : public VarDecl, |
| 4017 | private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> { |
| 4018 | |
| 4019 | unsigned NumBindings; |
| 4020 | |
| 4021 | DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
| 4022 | SourceLocation LSquareLoc, QualType T, |
| 4023 | TypeSourceInfo *TInfo, StorageClass SC, |
| 4024 | ArrayRef<BindingDecl *> Bindings) |
| 4025 | : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo, |
| 4026 | SC), |
| 4027 | NumBindings(Bindings.size()) { |
| 4028 | std::uninitialized_copy(Bindings.begin(), Bindings.end(), |
| 4029 | getTrailingObjects<BindingDecl *>()); |
| 4030 | for (auto *B : Bindings) |
| 4031 | B->setDecomposedDecl(this); |
| 4032 | } |
| 4033 | |
| 4034 | void anchor() override; |
| 4035 | |
| 4036 | public: |
| 4037 | friend class ASTDeclReader; |
| 4038 | friend TrailingObjects; |
| 4039 | |
| 4040 | static DecompositionDecl *Create(ASTContext &C, DeclContext *DC, |
| 4041 | SourceLocation StartLoc, |
| 4042 | SourceLocation LSquareLoc, |
| 4043 | QualType T, TypeSourceInfo *TInfo, |
| 4044 | StorageClass S, |
| 4045 | ArrayRef<BindingDecl *> Bindings); |
| 4046 | static DecompositionDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
| 4047 | unsigned NumBindings); |
| 4048 | |
| 4049 | ArrayRef<BindingDecl *> bindings() const { |
| 4050 | return llvm::makeArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings); |
| 4051 | } |
| 4052 | |
| 4053 | void printName(raw_ostream &os) const override; |
| 4054 | |
| 4055 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 4056 | static bool classofKind(Kind K) { return K == Decomposition; } |
| 4057 | }; |
| 4058 | |
| 4059 | |
| 4060 | |
| 4061 | |
| 4062 | |
| 4063 | |
| 4064 | |
| 4065 | |
| 4066 | |
| 4067 | |
| 4068 | |
| 4069 | |
| 4070 | |
| 4071 | |
| 4072 | |
| 4073 | |
| 4074 | |
| 4075 | |
| 4076 | |
| 4077 | |
| 4078 | |
| 4079 | |
| 4080 | |
| 4081 | |
| 4082 | |
| 4083 | |
| 4084 | |
| 4085 | |
| 4086 | class MSPropertyDecl : public DeclaratorDecl { |
| 4087 | IdentifierInfo *GetterId, *SetterId; |
| 4088 | |
| 4089 | MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N, |
| 4090 | QualType T, TypeSourceInfo *TInfo, SourceLocation StartL, |
| 4091 | IdentifierInfo *Getter, IdentifierInfo *Setter) |
| 4092 | : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL), |
| 4093 | GetterId(Getter), SetterId(Setter) {} |
| 4094 | |
| 4095 | void anchor() override; |
| 4096 | public: |
| 4097 | friend class ASTDeclReader; |
| 4098 | |
| 4099 | static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC, |
| 4100 | SourceLocation L, DeclarationName N, QualType T, |
| 4101 | TypeSourceInfo *TInfo, SourceLocation StartL, |
| 4102 | IdentifierInfo *Getter, IdentifierInfo *Setter); |
| 4103 | static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 4104 | |
| 4105 | static bool classof(const Decl *D) { return D->getKind() == MSProperty; } |
| 4106 | |
| 4107 | bool hasGetter() const { return GetterId != nullptr; } |
| 4108 | IdentifierInfo* getGetterId() const { return GetterId; } |
| 4109 | bool hasSetter() const { return SetterId != nullptr; } |
| 4110 | IdentifierInfo* getSetterId() const { return SetterId; } |
| 4111 | }; |
| 4112 | |
| 4113 | |
| 4114 | |
| 4115 | struct MSGuidDeclParts { |
| 4116 | |
| 4117 | uint32_t Part1; |
| 4118 | |
| 4119 | uint16_t Part2; |
| 4120 | |
| 4121 | uint16_t Part3; |
| 4122 | |
| 4123 | uint8_t Part4And5[8]; |
| 4124 | |
| 4125 | uint64_t getPart4And5AsUint64() const { |
| 4126 | uint64_t Val; |
| 4127 | memcpy(&Val, &Part4And5, sizeof(Part4And5)); |
| 4128 | return Val; |
| 4129 | } |
| 4130 | }; |
| 4131 | |
| 4132 | |
| 4133 | |
| 4134 | |
| 4135 | |
| 4136 | |
| 4137 | |
| 4138 | class MSGuidDecl : public ValueDecl, |
| 4139 | public Mergeable<MSGuidDecl>, |
| 4140 | public llvm::FoldingSetNode { |
| 4141 | public: |
| 4142 | using Parts = MSGuidDeclParts; |
| 4143 | |
| 4144 | private: |
| 4145 | |
| 4146 | Parts PartVal; |
| 4147 | |
| 4148 | |
| 4149 | |
| 4150 | mutable APValue APVal; |
| 4151 | |
| 4152 | void anchor() override; |
| 4153 | |
| 4154 | MSGuidDecl(DeclContext *DC, QualType T, Parts P); |
| 4155 | |
| 4156 | static MSGuidDecl *Create(const ASTContext &C, QualType T, Parts P); |
| 4157 | static MSGuidDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 4158 | |
| 4159 | |
| 4160 | friend class ASTContext; |
| 4161 | friend class ASTReader; |
| 4162 | friend class ASTDeclReader; |
| 4163 | |
| 4164 | public: |
| 4165 | |
| 4166 | void printName(llvm::raw_ostream &OS) const override; |
| 4167 | |
| 4168 | |
| 4169 | Parts getParts() const { return PartVal; } |
| 4170 | |
| 4171 | |
| 4172 | |
| 4173 | |
| 4174 | APValue &getAsAPValue() const; |
| 4175 | |
| 4176 | static void Profile(llvm::FoldingSetNodeID &ID, Parts P) { |
| 4177 | ID.AddInteger(P.Part1); |
| 4178 | ID.AddInteger(P.Part2); |
| 4179 | ID.AddInteger(P.Part3); |
| 4180 | ID.AddInteger(P.getPart4And5AsUint64()); |
| 4181 | } |
| 4182 | void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, PartVal); } |
| 4183 | |
| 4184 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 4185 | static bool classofKind(Kind K) { return K == Decl::MSGuid; } |
| 4186 | }; |
| 4187 | |
| 4188 | |
| 4189 | |
| 4190 | const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB, |
| 4191 | AccessSpecifier AS); |
| 4192 | |
| 4193 | } |
| 4194 | |
| 4195 | #endif // LLVM_CLANG_AST_DECLCXX_H |