clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name DeclObjC.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/DeclObjC.cpp
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #include "clang/AST/DeclObjC.h" |
| 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/ASTMutationListener.h" |
| 16 | #include "clang/AST/Attr.h" |
| 17 | #include "clang/AST/Decl.h" |
| 18 | #include "clang/AST/DeclBase.h" |
| 19 | #include "clang/AST/Stmt.h" |
| 20 | #include "clang/AST/Type.h" |
| 21 | #include "clang/AST/TypeLoc.h" |
| 22 | #include "clang/Basic/IdentifierTable.h" |
| 23 | #include "clang/Basic/LLVM.h" |
| 24 | #include "clang/Basic/LangOptions.h" |
| 25 | #include "clang/Basic/SourceLocation.h" |
| 26 | #include "llvm/ADT/None.h" |
| 27 | #include "llvm/ADT/SmallString.h" |
| 28 | #include "llvm/ADT/SmallVector.h" |
| 29 | #include "llvm/Support/Casting.h" |
| 30 | #include "llvm/Support/ErrorHandling.h" |
| 31 | #include "llvm/Support/raw_ostream.h" |
| 32 | #include <algorithm> |
| 33 | #include <cassert> |
| 34 | #include <cstdint> |
| 35 | #include <cstring> |
| 36 | #include <queue> |
| 37 | #include <utility> |
| 38 | |
| 39 | using namespace clang; |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) { |
| 46 | List = nullptr; |
| 47 | if (Elts == 0) return; |
| 48 | |
| 49 | List = new (Ctx) void*[Elts]; |
| 50 | NumElts = Elts; |
| 51 | memcpy(List, InList, sizeof(void*)*Elts); |
| 52 | } |
| 53 | |
| 54 | void ObjCProtocolList::set(ObjCProtocolDecl* const* InList, unsigned Elts, |
| 55 | const SourceLocation *Locs, ASTContext &Ctx) { |
| 56 | if (Elts == 0) |
| 57 | return; |
| 58 | |
| 59 | Locations = new (Ctx) SourceLocation[Elts]; |
| 60 | memcpy(Locations, Locs, sizeof(SourceLocation) * Elts); |
| 61 | set(InList, Elts, Ctx); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | ObjCContainerDecl::ObjCContainerDecl(Kind DK, DeclContext *DC, |
| 69 | IdentifierInfo *Id, SourceLocation nameLoc, |
| 70 | SourceLocation atStartLoc) |
| 71 | : NamedDecl(DK, DC, nameLoc, Id), DeclContext(DK) { |
| 72 | setAtStartLoc(atStartLoc); |
| 73 | } |
| 74 | |
| 75 | void ObjCContainerDecl::anchor() {} |
| 76 | |
| 77 | |
| 78 | |
| 79 | ObjCIvarDecl * |
| 80 | ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const { |
| 81 | lookup_result R = lookup(Id); |
| 82 | for (lookup_iterator Ivar = R.begin(), IvarEnd = R.end(); |
| 83 | Ivar != IvarEnd; ++Ivar) { |
| 84 | if (auto *ivar = dyn_cast<ObjCIvarDecl>(*Ivar)) |
| 85 | return ivar; |
| 86 | } |
| 87 | return nullptr; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | ObjCMethodDecl * |
| 92 | ObjCContainerDecl::getMethod(Selector Sel, bool isInstance, |
| 93 | bool AllowHidden) const { |
| 94 | |
| 95 | |
| 96 | if (const auto *Proto = dyn_cast<ObjCProtocolDecl>(this)) { |
| 97 | if (const ObjCProtocolDecl *Def = Proto->getDefinition()) |
| 98 | if (!Def->isUnconditionallyVisible() && !AllowHidden) |
| 99 | return nullptr; |
| 100 | } |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | lookup_result R = lookup(Sel); |
| 110 | for (lookup_iterator Meth = R.begin(), MethEnd = R.end(); |
| 111 | Meth != MethEnd; ++Meth) { |
| 112 | auto *MD = dyn_cast<ObjCMethodDecl>(*Meth); |
| 113 | if (MD && MD->isInstanceMethod() == isInstance) |
| 114 | return MD; |
| 115 | } |
| 116 | return nullptr; |
| 117 | } |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | bool ObjCContainerDecl::HasUserDeclaredSetterMethod( |
| 125 | const ObjCPropertyDecl *Property) const { |
| 126 | Selector Sel = Property->getSetterName(); |
| 127 | lookup_result R = lookup(Sel); |
| 128 | for (lookup_iterator Meth = R.begin(), MethEnd = R.end(); |
| 129 | Meth != MethEnd; ++Meth) { |
| 130 | auto *MD = dyn_cast<ObjCMethodDecl>(*Meth); |
| 131 | if (MD && MD->isInstanceMethod() && !MD->isImplicit()) |
| 132 | return true; |
| 133 | } |
| 134 | |
| 135 | if (const auto *ID = dyn_cast<ObjCInterfaceDecl>(this)) { |
| 136 | |
| 137 | |
| 138 | for (const auto *Cat : ID->visible_categories()) { |
| 139 | if (ObjCMethodDecl *MD = Cat->getInstanceMethod(Sel)) |
| 140 | if (!MD->isImplicit()) |
| 141 | return true; |
| 142 | if (Cat->IsClassExtension()) |
| 143 | continue; |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | for (const auto *P : Cat->properties()) |
| 149 | if (P->getIdentifier() == Property->getIdentifier()) { |
| 150 | if (P->getPropertyAttributes() & |
| 151 | ObjCPropertyAttribute::kind_readwrite) |
| 152 | return true; |
| 153 | break; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | |
| 158 | for (const auto *Proto : ID->all_referenced_protocols()) |
| 159 | if (Proto->HasUserDeclaredSetterMethod(Property)) |
| 160 | return true; |
| 161 | |
| 162 | |
| 163 | ObjCInterfaceDecl *OSC = ID->getSuperClass(); |
| 164 | while (OSC) { |
| 165 | if (OSC->HasUserDeclaredSetterMethod(Property)) |
| 166 | return true; |
| 167 | OSC = OSC->getSuperClass(); |
| 168 | } |
| 169 | } |
| 170 | if (const auto *PD = dyn_cast<ObjCProtocolDecl>(this)) |
| 171 | for (const auto *PI : PD->protocols()) |
| 172 | if (PI->HasUserDeclaredSetterMethod(Property)) |
| 173 | return true; |
| 174 | return false; |
| 175 | } |
| 176 | |
| 177 | ObjCPropertyDecl * |
| 178 | ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC, |
| 179 | const IdentifierInfo *propertyID, |
| 180 | ObjCPropertyQueryKind queryKind) { |
| 181 | |
| 182 | |
| 183 | if (const auto *Proto = dyn_cast<ObjCProtocolDecl>(DC)) { |
| 184 | if (const ObjCProtocolDecl *Def = Proto->getDefinition()) |
| 185 | if (!Def->isUnconditionallyVisible()) |
| 186 | return nullptr; |
| 187 | } |
| 188 | |
| 189 | |
| 190 | |
| 191 | if (auto *IDecl = dyn_cast<ObjCInterfaceDecl>(DC)) { |
| 192 | for (const auto *Ext : IDecl->visible_extensions()) |
| 193 | if (ObjCPropertyDecl *PD = ObjCPropertyDecl::findPropertyDecl(Ext, |
| 194 | propertyID, |
| 195 | queryKind)) |
| 196 | return PD; |
| 197 | } |
| 198 | |
| 199 | DeclContext::lookup_result R = DC->lookup(propertyID); |
| 200 | ObjCPropertyDecl *classProp = nullptr; |
| 201 | for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E; |
| 202 | ++I) |
| 203 | if (auto *PD = dyn_cast<ObjCPropertyDecl>(*I)) { |
| 204 | |
| 205 | |
| 206 | if ((queryKind == ObjCPropertyQueryKind::OBJC_PR_query_unknown && |
| 207 | !PD->isClassProperty()) || |
| 208 | (queryKind == ObjCPropertyQueryKind::OBJC_PR_query_class && |
| 209 | PD->isClassProperty()) || |
| 210 | (queryKind == ObjCPropertyQueryKind::OBJC_PR_query_instance && |
| 211 | !PD->isClassProperty())) |
| 212 | return PD; |
| 213 | |
| 214 | if (PD->isClassProperty()) |
| 215 | classProp = PD; |
| 216 | } |
| 217 | |
| 218 | if (queryKind == ObjCPropertyQueryKind::OBJC_PR_query_unknown) |
| 219 | |
| 220 | return classProp; |
| 221 | |
| 222 | return nullptr; |
| 223 | } |
| 224 | |
| 225 | IdentifierInfo * |
| 226 | ObjCPropertyDecl::getDefaultSynthIvarName(ASTContext &Ctx) const { |
| 227 | SmallString<128> ivarName; |
| 228 | { |
| 229 | llvm::raw_svector_ostream os(ivarName); |
| 230 | os << '_' << getIdentifier()->getName(); |
| 231 | } |
| 232 | return &Ctx.Idents.get(ivarName.str()); |
| 233 | } |
| 234 | |
| 235 | |
| 236 | |
| 237 | ObjCPropertyDecl *ObjCContainerDecl::FindPropertyDeclaration( |
| 238 | const IdentifierInfo *PropertyId, |
| 239 | ObjCPropertyQueryKind QueryKind) const { |
| 240 | |
| 241 | if (const auto *Proto = dyn_cast<ObjCProtocolDecl>(this)) { |
| 242 | if (const ObjCProtocolDecl *Def = Proto->getDefinition()) |
| 243 | if (!Def->isUnconditionallyVisible()) |
| 244 | return nullptr; |
| 245 | } |
| 246 | |
| 247 | |
| 248 | |
| 249 | if (const auto *ClassDecl = dyn_cast<ObjCInterfaceDecl>(this)) { |
| 250 | for (const auto *Ext : ClassDecl->visible_extensions()) { |
| 251 | if (auto *P = Ext->FindPropertyDeclaration(PropertyId, QueryKind)) |
| 252 | return P; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | if (ObjCPropertyDecl *PD = |
| 257 | ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId, |
| 258 | QueryKind)) |
| 259 | return PD; |
| 260 | |
| 261 | switch (getKind()) { |
| 262 | default: |
| 263 | break; |
| 264 | case Decl::ObjCProtocol: { |
| 265 | const auto *PID = cast<ObjCProtocolDecl>(this); |
| 266 | for (const auto *I : PID->protocols()) |
| 267 | if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId, |
| 268 | QueryKind)) |
| 269 | return P; |
| 270 | break; |
| 271 | } |
| 272 | case Decl::ObjCInterface: { |
| 273 | const auto *OID = cast<ObjCInterfaceDecl>(this); |
| 274 | |
| 275 | for (const auto *Cat : OID->visible_categories()) { |
| 276 | if (!Cat->IsClassExtension()) |
| 277 | if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration( |
| 278 | PropertyId, QueryKind)) |
| 279 | return P; |
| 280 | } |
| 281 | |
| 282 | |
| 283 | for (const auto *I : OID->all_referenced_protocols()) |
| 284 | if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId, |
| 285 | QueryKind)) |
| 286 | return P; |
| 287 | |
| 288 | |
| 289 | if (const ObjCInterfaceDecl *superClass = OID->getSuperClass()) |
| 290 | return superClass->FindPropertyDeclaration(PropertyId, QueryKind); |
| 291 | break; |
| 292 | } |
| 293 | case Decl::ObjCCategory: { |
| 294 | const auto *OCD = cast<ObjCCategoryDecl>(this); |
| 295 | |
| 296 | if (!OCD->IsClassExtension()) |
| 297 | for (const auto *I : OCD->protocols()) |
| 298 | if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId, |
| 299 | QueryKind)) |
| 300 | return P; |
| 301 | break; |
| 302 | } |
| 303 | } |
| 304 | return nullptr; |
| 305 | } |
| 306 | |
| 307 | void ObjCInterfaceDecl::anchor() {} |
| 308 | |
| 309 | ObjCTypeParamList *ObjCInterfaceDecl::getTypeParamList() const { |
| 310 | |
| 311 | if (ObjCTypeParamList *written = getTypeParamListAsWritten()) |
| 312 | return written; |
| 313 | |
| 314 | |
| 315 | if (const ObjCInterfaceDecl *def = getDefinition()) |
| 316 | return def->getTypeParamListAsWritten(); |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | for (const ObjCInterfaceDecl *decl = getMostRecentDecl(); decl; |
| 322 | decl = decl->getPreviousDecl()) { |
| 323 | if (ObjCTypeParamList *written = decl->getTypeParamListAsWritten()) |
| 324 | return written; |
| 325 | } |
| 326 | |
| 327 | return nullptr; |
| 328 | } |
| 329 | |
| 330 | void ObjCInterfaceDecl::setTypeParamList(ObjCTypeParamList *TPL) { |
| 331 | TypeParamList = TPL; |
| 332 | if (!TPL) |
| 333 | return; |
| 334 | |
| 335 | for (auto *typeParam : *TypeParamList) |
| 336 | typeParam->setDeclContext(this); |
| 337 | } |
| 338 | |
| 339 | ObjCInterfaceDecl *ObjCInterfaceDecl::getSuperClass() const { |
| 340 | |
| 341 | if (!hasDefinition()) |
| 342 | return nullptr; |
| 343 | |
| 344 | if (data().ExternallyCompleted) |
| 345 | LoadExternalDefinition(); |
| 346 | |
| 347 | if (const ObjCObjectType *superType = getSuperClassType()) { |
| 348 | if (ObjCInterfaceDecl *superDecl = superType->getInterface()) { |
| 349 | if (ObjCInterfaceDecl *superDef = superDecl->getDefinition()) |
| 350 | return superDef; |
| 351 | |
| 352 | return superDecl; |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | return nullptr; |
| 357 | } |
| 358 | |
| 359 | SourceLocation ObjCInterfaceDecl::getSuperClassLoc() const { |
| 360 | if (TypeSourceInfo *superTInfo = getSuperClassTInfo()) |
| 361 | return superTInfo->getTypeLoc().getBeginLoc(); |
| 362 | |
| 363 | return SourceLocation(); |
| 364 | } |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | ObjCPropertyDecl * |
| 370 | ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass( |
| 371 | IdentifierInfo *PropertyId, |
| 372 | ObjCPropertyQueryKind QueryKind) const { |
| 373 | |
| 374 | if (!hasDefinition()) |
| 375 | return nullptr; |
| 376 | |
| 377 | if (data().ExternallyCompleted) |
| 378 | LoadExternalDefinition(); |
| 379 | |
| 380 | if (ObjCPropertyDecl *PD = |
| 381 | ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId, |
| 382 | QueryKind)) |
| 383 | return PD; |
| 384 | |
| 385 | |
| 386 | for (const auto *I : all_referenced_protocols()) |
| 387 | if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId, |
| 388 | QueryKind)) |
| 389 | return P; |
| 390 | |
| 391 | return nullptr; |
| 392 | } |
| 393 | |
| 394 | void ObjCInterfaceDecl::collectPropertiesToImplement(PropertyMap &PM, |
| 395 | PropertyDeclOrder &PO) const { |
| 396 | for (auto *Prop : properties()) { |
| 397 | PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop; |
| 398 | PO.push_back(Prop); |
| 399 | } |
| 400 | for (const auto *Ext : known_extensions()) { |
| 401 | const ObjCCategoryDecl *ClassExt = Ext; |
| 402 | for (auto *Prop : ClassExt->properties()) { |
| 403 | PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop; |
| 404 | PO.push_back(Prop); |
| 405 | } |
| 406 | } |
| 407 | for (const auto *PI : all_referenced_protocols()) |
| 408 | PI->collectPropertiesToImplement(PM, PO); |
| 409 | |
| 410 | |
| 411 | |
| 412 | } |
| 413 | |
| 414 | bool ObjCInterfaceDecl::isArcWeakrefUnavailable() const { |
| 415 | const ObjCInterfaceDecl *Class = this; |
| 416 | while (Class) { |
| 417 | if (Class->hasAttr<ArcWeakrefUnavailableAttr>()) |
| 418 | return true; |
| 419 | Class = Class->getSuperClass(); |
| 420 | } |
| 421 | return false; |
| 422 | } |
| 423 | |
| 424 | const ObjCInterfaceDecl *ObjCInterfaceDecl::isObjCRequiresPropertyDefs() const { |
| 425 | const ObjCInterfaceDecl *Class = this; |
| 426 | while (Class) { |
| 427 | if (Class->hasAttr<ObjCRequiresPropertyDefsAttr>()) |
| 428 | return Class; |
| 429 | Class = Class->getSuperClass(); |
| 430 | } |
| 431 | return nullptr; |
| 432 | } |
| 433 | |
| 434 | void ObjCInterfaceDecl::mergeClassExtensionProtocolList( |
| 435 | ObjCProtocolDecl *const* ExtList, unsigned ExtNum, |
| 436 | ASTContext &C) { |
| 437 | if (data().ExternallyCompleted) |
| 438 | LoadExternalDefinition(); |
| 439 | |
| 440 | if (data().AllReferencedProtocols.empty() && |
| 441 | data().ReferencedProtocols.empty()) { |
| 442 | data().AllReferencedProtocols.set(ExtList, ExtNum, C); |
| 443 | return; |
| 444 | } |
| 445 | |
| 446 | |
| 447 | |
| 448 | |
| 449 | SmallVector<ObjCProtocolDecl *, 8> ProtocolRefs; |
| 450 | for (unsigned i = 0; i < ExtNum; i++) { |
| 451 | bool protocolExists = false; |
| 452 | ObjCProtocolDecl *ProtoInExtension = ExtList[i]; |
| 453 | for (auto *Proto : all_referenced_protocols()) { |
| 454 | if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) { |
| 455 | protocolExists = true; |
| 456 | break; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | |
| 461 | if (!protocolExists) |
| 462 | ProtocolRefs.push_back(ProtoInExtension); |
| 463 | } |
| 464 | |
| 465 | if (ProtocolRefs.empty()) |
| 466 | return; |
| 467 | |
| 468 | |
| 469 | ProtocolRefs.append(all_referenced_protocol_begin(), |
| 470 | all_referenced_protocol_end()); |
| 471 | |
| 472 | data().AllReferencedProtocols.set(ProtocolRefs.data(), ProtocolRefs.size(),C); |
| 473 | } |
| 474 | |
| 475 | const ObjCInterfaceDecl * |
| 476 | ObjCInterfaceDecl::findInterfaceWithDesignatedInitializers() const { |
| 477 | const ObjCInterfaceDecl *IFace = this; |
| 478 | while (IFace) { |
| 479 | if (IFace->hasDesignatedInitializers()) |
| 480 | return IFace; |
| 481 | if (!IFace->inheritsDesignatedInitializers()) |
| 482 | break; |
| 483 | IFace = IFace->getSuperClass(); |
| 484 | } |
| 485 | return nullptr; |
| 486 | } |
| 487 | |
| 488 | static bool isIntroducingInitializers(const ObjCInterfaceDecl *D) { |
| 489 | for (const auto *MD : D->instance_methods()) { |
| 490 | if (MD->getMethodFamily() == OMF_init && !MD->isOverriding()) |
| 491 | return true; |
| 492 | } |
| 493 | for (const auto *Ext : D->visible_extensions()) { |
| 494 | for (const auto *MD : Ext->instance_methods()) { |
| 495 | if (MD->getMethodFamily() == OMF_init && !MD->isOverriding()) |
| 496 | return true; |
| 497 | } |
| 498 | } |
| 499 | if (const auto *ImplD = D->getImplementation()) { |
| 500 | for (const auto *MD : ImplD->instance_methods()) { |
| 501 | if (MD->getMethodFamily() == OMF_init && !MD->isOverriding()) |
| 502 | return true; |
| 503 | } |
| 504 | } |
| 505 | return false; |
| 506 | } |
| 507 | |
| 508 | bool ObjCInterfaceDecl::inheritsDesignatedInitializers() const { |
| 509 | switch (data().InheritedDesignatedInitializers) { |
| 510 | case DefinitionData::IDI_Inherited: |
| 511 | return true; |
| 512 | case DefinitionData::IDI_NotInherited: |
| 513 | return false; |
| 514 | case DefinitionData::IDI_Unknown: |
| 515 | |
| 516 | |
| 517 | |
| 518 | if (isIntroducingInitializers(this)) { |
| 519 | data().InheritedDesignatedInitializers = DefinitionData::IDI_NotInherited; |
| 520 | } else { |
| 521 | if (auto SuperD = getSuperClass()) { |
| 522 | data().InheritedDesignatedInitializers = |
| 523 | SuperD->declaresOrInheritsDesignatedInitializers() ? |
| 524 | DefinitionData::IDI_Inherited : |
| 525 | DefinitionData::IDI_NotInherited; |
| 526 | } else { |
| 527 | data().InheritedDesignatedInitializers = |
| 528 | DefinitionData::IDI_NotInherited; |
| 529 | } |
| 530 | } |
| 531 | assert(data().InheritedDesignatedInitializers |
| 532 | != DefinitionData::IDI_Unknown); |
| 533 | return data().InheritedDesignatedInitializers == |
| 534 | DefinitionData::IDI_Inherited; |
| 535 | } |
| 536 | |
| 537 | llvm_unreachable("unexpected InheritedDesignatedInitializers value"); |
| 538 | } |
| 539 | |
| 540 | void ObjCInterfaceDecl::getDesignatedInitializers( |
| 541 | llvm::SmallVectorImpl<const ObjCMethodDecl *> &Methods) const { |
| 542 | |
| 543 | if (!isThisDeclarationADefinition()) |
| 544 | return; |
| 545 | if (data().ExternallyCompleted) |
| 546 | LoadExternalDefinition(); |
| 547 | |
| 548 | const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers(); |
| 549 | if (!IFace) |
| 550 | return; |
| 551 | |
| 552 | for (const auto *MD : IFace->instance_methods()) |
| 553 | if (MD->isThisDeclarationADesignatedInitializer()) |
| 554 | Methods.push_back(MD); |
| 555 | for (const auto *Ext : IFace->visible_extensions()) { |
| 556 | for (const auto *MD : Ext->instance_methods()) |
| 557 | if (MD->isThisDeclarationADesignatedInitializer()) |
| 558 | Methods.push_back(MD); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | bool ObjCInterfaceDecl::isDesignatedInitializer(Selector Sel, |
| 563 | const ObjCMethodDecl **InitMethod) const { |
| 564 | bool HasCompleteDef = isThisDeclarationADefinition(); |
| 565 | |
| 566 | |
| 567 | |
| 568 | if (!HasCompleteDef && getCanonicalDecl()->hasDefinition() && |
| 569 | getCanonicalDecl()->getDefinition() == getDefinition()) |
| 570 | HasCompleteDef = true; |
| 571 | |
| 572 | |
| 573 | if (!HasCompleteDef) |
| 574 | return false; |
| 575 | |
| 576 | if (data().ExternallyCompleted) |
| 577 | LoadExternalDefinition(); |
| 578 | |
| 579 | const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers(); |
| 580 | if (!IFace) |
| 581 | return false; |
| 582 | |
| 583 | if (const ObjCMethodDecl *MD = IFace->getInstanceMethod(Sel)) { |
| 584 | if (MD->isThisDeclarationADesignatedInitializer()) { |
| 585 | if (InitMethod) |
| 586 | *InitMethod = MD; |
| 587 | return true; |
| 588 | } |
| 589 | } |
| 590 | for (const auto *Ext : IFace->visible_extensions()) { |
| 591 | if (const ObjCMethodDecl *MD = Ext->getInstanceMethod(Sel)) { |
| 592 | if (MD->isThisDeclarationADesignatedInitializer()) { |
| 593 | if (InitMethod) |
| 594 | *InitMethod = MD; |
| 595 | return true; |
| 596 | } |
| 597 | } |
| 598 | } |
| 599 | return false; |
| 600 | } |
| 601 | |
| 602 | void ObjCInterfaceDecl::allocateDefinitionData() { |
| 603 | assert(!hasDefinition() && "ObjC class already has a definition"); |
| 604 | Data.setPointer(new (getASTContext()) DefinitionData()); |
| 605 | Data.getPointer()->Definition = this; |
| 606 | |
| 607 | |
| 608 | if (TypeForDecl) |
| 609 | cast<ObjCInterfaceType>(TypeForDecl)->Decl = this; |
| 610 | } |
| 611 | |
| 612 | void ObjCInterfaceDecl::startDefinition() { |
| 613 | allocateDefinitionData(); |
| 614 | |
| 615 | |
| 616 | for (auto *RD : redecls()) { |
| 617 | if (RD != this) |
| 618 | RD->Data = Data; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID, |
| 623 | ObjCInterfaceDecl *&clsDeclared) { |
| 624 | |
| 625 | if (!hasDefinition()) |
| 626 | return nullptr; |
| 627 | |
| 628 | if (data().ExternallyCompleted) |
| 629 | LoadExternalDefinition(); |
| 630 | |
| 631 | ObjCInterfaceDecl* ClassDecl = this; |
| 632 | while (ClassDecl != nullptr) { |
| 633 | if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) { |
| 634 | clsDeclared = ClassDecl; |
| 635 | return I; |
| 636 | } |
| 637 | |
| 638 | for (const auto *Ext : ClassDecl->visible_extensions()) { |
| 639 | if (ObjCIvarDecl *I = Ext->getIvarDecl(ID)) { |
| 640 | clsDeclared = ClassDecl; |
| 641 | return I; |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | ClassDecl = ClassDecl->getSuperClass(); |
| 646 | } |
| 647 | return nullptr; |
| 648 | } |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass( |
| 654 | const IdentifierInfo*ICName) { |
| 655 | |
| 656 | if (!hasDefinition()) |
| 657 | return nullptr; |
| 658 | |
| 659 | if (data().ExternallyCompleted) |
| 660 | LoadExternalDefinition(); |
| 661 | |
| 662 | ObjCInterfaceDecl* ClassDecl = this; |
| 663 | while (ClassDecl != nullptr) { |
| 664 | if (ClassDecl->getIdentifier() == ICName) |
| 665 | return ClassDecl; |
| 666 | ClassDecl = ClassDecl->getSuperClass(); |
| 667 | } |
| 668 | return nullptr; |
| 669 | } |
| 670 | |
| 671 | ObjCProtocolDecl * |
| 672 | ObjCInterfaceDecl::lookupNestedProtocol(IdentifierInfo *Name) { |
| 673 | for (auto *P : all_referenced_protocols()) |
| 674 | if (P->lookupProtocolNamed(Name)) |
| 675 | return P; |
| 676 | ObjCInterfaceDecl *SuperClass = getSuperClass(); |
| 677 | return SuperClass ? SuperClass->lookupNestedProtocol(Name) : nullptr; |
| 678 | } |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | |
| 684 | ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel, |
| 685 | bool isInstance, |
| 686 | bool shallowCategoryLookup, |
| 687 | bool followSuper, |
| 688 | const ObjCCategoryDecl *C) const |
| 689 | { |
| 690 | |
| 691 | if (!hasDefinition()) |
| 692 | return nullptr; |
| 693 | |
| 694 | const ObjCInterfaceDecl* ClassDecl = this; |
| 695 | ObjCMethodDecl *MethodDecl = nullptr; |
| 696 | |
| 697 | if (data().ExternallyCompleted) |
| 698 | LoadExternalDefinition(); |
| 699 | |
| 700 | while (ClassDecl) { |
| 701 | |
| 702 | if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance))) |
| 703 | return MethodDecl; |
| 704 | |
| 705 | |
| 706 | for (const auto *Cat : ClassDecl->visible_categories()) |
| 707 | if ((MethodDecl = Cat->getMethod(Sel, isInstance))) |
| 708 | if (C != Cat || !MethodDecl->isImplicit()) |
| 709 | return MethodDecl; |
| 710 | |
| 711 | |
| 712 | for (const auto *I : ClassDecl->protocols()) |
| 713 | if ((MethodDecl = I->lookupMethod(Sel, isInstance))) |
| 714 | return MethodDecl; |
| 715 | |
| 716 | |
| 717 | if (!shallowCategoryLookup) |
| 718 | for (const auto *Cat : ClassDecl->visible_categories()) { |
| 719 | |
| 720 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 721 | Cat->getReferencedProtocols(); |
| 722 | for (auto *Protocol : Protocols) |
| 723 | if ((MethodDecl = Protocol->lookupMethod(Sel, isInstance))) |
| 724 | if (C != Cat || !MethodDecl->isImplicit()) |
| 725 | return MethodDecl; |
| 726 | } |
| 727 | |
| 728 | |
| 729 | if (!followSuper) |
| 730 | return nullptr; |
| 731 | |
| 732 | |
| 733 | ClassDecl = ClassDecl->getSuperClass(); |
| 734 | } |
| 735 | return nullptr; |
| 736 | } |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod( |
| 742 | const Selector &Sel, |
| 743 | bool Instance) const { |
| 744 | |
| 745 | if (!hasDefinition()) |
| 746 | return nullptr; |
| 747 | |
| 748 | if (data().ExternallyCompleted) |
| 749 | LoadExternalDefinition(); |
| 750 | |
| 751 | ObjCMethodDecl *Method = nullptr; |
| 752 | if (ObjCImplementationDecl *ImpDecl = getImplementation()) |
| 753 | Method = Instance ? ImpDecl->getInstanceMethod(Sel) |
| 754 | : ImpDecl->getClassMethod(Sel); |
| 755 | |
| 756 | |
| 757 | if (!Method) |
| 758 | Method = getCategoryMethod(Sel, Instance); |
| 759 | |
| 760 | |
| 761 | |
| 762 | |
| 763 | if (!Instance && !Method && !getSuperClass()) { |
| 764 | Method = lookupInstanceMethod(Sel); |
| 765 | |
| 766 | |
| 767 | if (!Method) |
| 768 | Method = lookupPrivateMethod(Sel, true); |
| 769 | } |
| 770 | |
| 771 | if (!Method && getSuperClass()) |
| 772 | return getSuperClass()->lookupPrivateMethod(Sel, Instance); |
| 773 | return Method; |
| 774 | } |
| 775 | |
| 776 | |
| 777 | |
| 778 | |
| 779 | |
| 780 | ObjCMethodDecl::ObjCMethodDecl( |
| 781 | SourceLocation beginLoc, SourceLocation endLoc, Selector SelInfo, |
| 782 | QualType T, TypeSourceInfo *ReturnTInfo, DeclContext *contextDecl, |
| 783 | bool isInstance, bool isVariadic, bool isPropertyAccessor, |
| 784 | bool isSynthesizedAccessorStub, bool isImplicitlyDeclared, bool isDefined, |
| 785 | ImplementationControl impControl, bool HasRelatedResultType) |
| 786 | : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo), |
| 787 | DeclContext(ObjCMethod), MethodDeclType(T), ReturnTInfo(ReturnTInfo), |
| 788 | DeclEndLoc(endLoc) { |
| 789 | |
| 790 | |
| 791 | ObjCMethodDeclBits.Family = |
| 792 | static_cast<ObjCMethodFamily>(InvalidObjCMethodFamily); |
| 793 | setInstanceMethod(isInstance); |
| 794 | setVariadic(isVariadic); |
| 795 | setPropertyAccessor(isPropertyAccessor); |
| 796 | setSynthesizedAccessorStub(isSynthesizedAccessorStub); |
| 797 | setDefined(isDefined); |
| 798 | setIsRedeclaration(false); |
| 799 | setHasRedeclaration(false); |
| 800 | setDeclImplementation(impControl); |
| 801 | setObjCDeclQualifier(OBJC_TQ_None); |
| 802 | setRelatedResultType(HasRelatedResultType); |
| 803 | setSelLocsKind(SelLoc_StandardNoSpace); |
| 804 | setOverriding(false); |
| 805 | setHasSkippedBody(false); |
| 806 | |
| 807 | setImplicit(isImplicitlyDeclared); |
| 808 | } |
| 809 | |
| 810 | ObjCMethodDecl *ObjCMethodDecl::Create( |
| 811 | ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc, |
| 812 | Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo, |
| 813 | DeclContext *contextDecl, bool isInstance, bool isVariadic, |
| 814 | bool isPropertyAccessor, bool isSynthesizedAccessorStub, |
| 815 | bool isImplicitlyDeclared, bool isDefined, ImplementationControl impControl, |
| 816 | bool HasRelatedResultType) { |
| 817 | return new (C, contextDecl) ObjCMethodDecl( |
| 818 | beginLoc, endLoc, SelInfo, T, ReturnTInfo, contextDecl, isInstance, |
| 819 | isVariadic, isPropertyAccessor, isSynthesizedAccessorStub, |
| 820 | isImplicitlyDeclared, isDefined, impControl, HasRelatedResultType); |
| 821 | } |
| 822 | |
| 823 | ObjCMethodDecl *ObjCMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 824 | return new (C, ID) ObjCMethodDecl(SourceLocation(), SourceLocation(), |
| 825 | Selector(), QualType(), nullptr, nullptr); |
| 826 | } |
| 827 | |
| 828 | bool ObjCMethodDecl::isDirectMethod() const { |
| 829 | return hasAttr<ObjCDirectAttr>() && |
| 830 | !getASTContext().getLangOpts().ObjCDisableDirectMethodsForTesting; |
| 831 | } |
| 832 | |
| 833 | bool ObjCMethodDecl::isThisDeclarationADesignatedInitializer() const { |
| 834 | return getMethodFamily() == OMF_init && |
| 835 | hasAttr<ObjCDesignatedInitializerAttr>(); |
| 836 | } |
| 837 | |
| 838 | bool ObjCMethodDecl::definedInNSObject(const ASTContext &Ctx) const { |
| 839 | if (const auto *PD = dyn_cast<const ObjCProtocolDecl>(getDeclContext())) |
| 840 | return PD->getIdentifier() == Ctx.getNSObjectName(); |
| 841 | if (const auto *ID = dyn_cast<const ObjCInterfaceDecl>(getDeclContext())) |
| 842 | return ID->getIdentifier() == Ctx.getNSObjectName(); |
| 843 | return false; |
| 844 | } |
| 845 | |
| 846 | bool ObjCMethodDecl::isDesignatedInitializerForTheInterface( |
| 847 | const ObjCMethodDecl **InitMethod) const { |
| 848 | if (getMethodFamily() != OMF_init) |
| 849 | return false; |
| 850 | const DeclContext *DC = getDeclContext(); |
| 851 | if (isa<ObjCProtocolDecl>(DC)) |
| 852 | return false; |
| 853 | if (const ObjCInterfaceDecl *ID = getClassInterface()) |
| 854 | return ID->isDesignatedInitializer(getSelector(), InitMethod); |
| 855 | return false; |
| 856 | } |
| 857 | |
| 858 | Stmt *ObjCMethodDecl::getBody() const { |
| 859 | return Body.get(getASTContext().getExternalSource()); |
| 860 | } |
| 861 | |
| 862 | void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) { |
| 863 | assert(PrevMethod); |
| 864 | getASTContext().setObjCMethodRedeclaration(PrevMethod, this); |
| 865 | setIsRedeclaration(true); |
| 866 | PrevMethod->setHasRedeclaration(true); |
| 867 | } |
| 868 | |
| 869 | void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C, |
| 870 | ArrayRef<ParmVarDecl*> Params, |
| 871 | ArrayRef<SourceLocation> SelLocs) { |
| 872 | ParamsAndSelLocs = nullptr; |
| 873 | NumParams = Params.size(); |
| 874 | if (Params.empty() && SelLocs.empty()) |
| 875 | return; |
| 876 | |
| 877 | static_assert(alignof(ParmVarDecl *) >= alignof(SourceLocation), |
| 878 | "Alignment not sufficient for SourceLocation"); |
| 879 | |
| 880 | unsigned Size = sizeof(ParmVarDecl *) * NumParams + |
| 881 | sizeof(SourceLocation) * SelLocs.size(); |
| 882 | ParamsAndSelLocs = C.Allocate(Size); |
| 883 | std::copy(Params.begin(), Params.end(), getParams()); |
| 884 | std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); |
| 885 | } |
| 886 | |
| 887 | void ObjCMethodDecl::getSelectorLocs( |
| 888 | SmallVectorImpl<SourceLocation> &SelLocs) const { |
| 889 | for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i) |
| 890 | SelLocs.push_back(getSelectorLoc(i)); |
| 891 | } |
| 892 | |
| 893 | void ObjCMethodDecl::setMethodParams(ASTContext &C, |
| 894 | ArrayRef<ParmVarDecl*> Params, |
| 895 | ArrayRef<SourceLocation> SelLocs) { |
| 896 | assert((!SelLocs.empty() || isImplicit()) && |
| 897 | "No selector locs for non-implicit method"); |
| 898 | if (isImplicit()) |
| 899 | return setParamsAndSelLocs(C, Params, llvm::None); |
| 900 | |
| 901 | setSelLocsKind(hasStandardSelectorLocs(getSelector(), SelLocs, Params, |
| 902 | DeclEndLoc)); |
| 903 | if (getSelLocsKind() != SelLoc_NonStandard) |
| 904 | return setParamsAndSelLocs(C, Params, llvm::None); |
| 905 | |
| 906 | setParamsAndSelLocs(C, Params, SelLocs); |
| 907 | } |
| 908 | |
| 909 | |
| 910 | |
| 911 | |
| 912 | ObjCMethodDecl *ObjCMethodDecl::getNextRedeclarationImpl() { |
| 913 | ASTContext &Ctx = getASTContext(); |
| 914 | ObjCMethodDecl *Redecl = nullptr; |
| 915 | if (hasRedeclaration()) |
| 916 | Redecl = const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this)); |
| 917 | if (Redecl) |
| 918 | return Redecl; |
| 919 | |
| 920 | auto *CtxD = cast<Decl>(getDeclContext()); |
| 921 | |
| 922 | if (!CtxD->isInvalidDecl()) { |
| 923 | if (auto *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) { |
| 924 | if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD)) |
| 925 | if (!ImplD->isInvalidDecl()) |
| 926 | Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); |
| 927 | |
| 928 | } else if (auto *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) { |
| 929 | if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD)) |
| 930 | if (!ImplD->isInvalidDecl()) |
| 931 | Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); |
| 932 | |
| 933 | } else if (auto *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) { |
| 934 | if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) |
| 935 | if (!IFD->isInvalidDecl()) |
| 936 | Redecl = IFD->getMethod(getSelector(), isInstanceMethod()); |
| 937 | |
| 938 | } else if (auto *CImplD = dyn_cast<ObjCCategoryImplDecl>(CtxD)) { |
| 939 | if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) |
| 940 | if (!CatD->isInvalidDecl()) |
| 941 | Redecl = CatD->getMethod(getSelector(), isInstanceMethod()); |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | |
| 946 | |
| 947 | |
| 948 | if (Redecl && cast<Decl>(Redecl->getDeclContext())->isInvalidDecl()) |
| 949 | Redecl = nullptr; |
| 950 | |
| 951 | if (!Redecl && isRedeclaration()) { |
| 952 | |
| 953 | return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(), |
| 954 | isInstanceMethod(), |
| 955 | true); |
| 956 | } |
| 957 | |
| 958 | return Redecl ? Redecl : this; |
| 959 | } |
| 960 | |
| 961 | ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() { |
| 962 | auto *CtxD = cast<Decl>(getDeclContext()); |
| 963 | const auto &Sel = getSelector(); |
| 964 | |
| 965 | if (auto *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) { |
| 966 | if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) { |
| 967 | |
| 968 | |
| 969 | |
| 970 | |
| 971 | |
| 972 | |
| 973 | if (ObjCMethodDecl *MD = IFD->getMethod(Sel, isInstanceMethod())) |
| 974 | return MD; |
| 975 | for (auto *Ext : IFD->known_extensions()) |
| 976 | if (ObjCMethodDecl *MD = Ext->getMethod(Sel, isInstanceMethod())) |
| 977 | return MD; |
| 978 | } |
| 979 | } else if (auto *CImplD = dyn_cast<ObjCCategoryImplDecl>(CtxD)) { |
| 980 | if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) |
| 981 | if (ObjCMethodDecl *MD = CatD->getMethod(Sel, isInstanceMethod())) |
| 982 | return MD; |
| 983 | } |
| 984 | |
| 985 | if (isRedeclaration()) { |
| 986 | |
| 987 | ObjCMethodDecl *MD = |
| 988 | cast<ObjCContainerDecl>(CtxD)->getMethod(Sel, isInstanceMethod(), |
| 989 | true); |
| 990 | return MD ? MD : this; |
| 991 | } |
| 992 | |
| 993 | return this; |
| 994 | } |
| 995 | |
| 996 | SourceLocation ObjCMethodDecl::getEndLoc() const { |
| 997 | if (Stmt *Body = getBody()) |
| 998 | return Body->getEndLoc(); |
| 999 | return DeclEndLoc; |
| 1000 | } |
| 1001 | |
| 1002 | ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const { |
| 1003 | auto family = static_cast<ObjCMethodFamily>(ObjCMethodDeclBits.Family); |
| 1004 | if (family != static_cast<unsigned>(InvalidObjCMethodFamily)) |
| 1005 | return family; |
| 1006 | |
| 1007 | |
| 1008 | if (const ObjCMethodFamilyAttr *attr = getAttr<ObjCMethodFamilyAttr>()) { |
| 1009 | |
| 1010 | |
| 1011 | switch (attr->getFamily()) { |
| 1012 | case ObjCMethodFamilyAttr::OMF_None: family = OMF_None; break; |
| 1013 | case ObjCMethodFamilyAttr::OMF_alloc: family = OMF_alloc; break; |
| 1014 | case ObjCMethodFamilyAttr::OMF_copy: family = OMF_copy; break; |
| 1015 | case ObjCMethodFamilyAttr::OMF_init: family = OMF_init; break; |
| 1016 | case ObjCMethodFamilyAttr::OMF_mutableCopy: family = OMF_mutableCopy; break; |
| 1017 | case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break; |
| 1018 | } |
| 1019 | ObjCMethodDeclBits.Family = family; |
| 1020 | return family; |
| 1021 | } |
| 1022 | |
| 1023 | family = getSelector().getMethodFamily(); |
| 1024 | switch (family) { |
| 1025 | case OMF_None: break; |
| 1026 | |
| 1027 | |
| 1028 | |
| 1029 | case OMF_init: |
| 1030 | if (!isInstanceMethod() || !getReturnType()->isObjCObjectPointerType()) |
| 1031 | family = OMF_None; |
| 1032 | break; |
| 1033 | |
| 1034 | |
| 1035 | |
| 1036 | case OMF_alloc: |
| 1037 | case OMF_copy: |
| 1038 | case OMF_mutableCopy: |
| 1039 | case OMF_new: |
| 1040 | if (!getReturnType()->isObjCObjectPointerType()) |
| 1041 | family = OMF_None; |
| 1042 | break; |
| 1043 | |
| 1044 | |
| 1045 | case OMF_dealloc: |
| 1046 | case OMF_finalize: |
| 1047 | case OMF_retain: |
| 1048 | case OMF_release: |
| 1049 | case OMF_autorelease: |
| 1050 | case OMF_retainCount: |
| 1051 | case OMF_self: |
| 1052 | if (!isInstanceMethod()) |
| 1053 | family = OMF_None; |
| 1054 | break; |
| 1055 | |
| 1056 | case OMF_initialize: |
| 1057 | if (isInstanceMethod() || !getReturnType()->isVoidType()) |
| 1058 | family = OMF_None; |
| 1059 | break; |
| 1060 | |
| 1061 | case OMF_performSelector: |
| 1062 | if (!isInstanceMethod() || !getReturnType()->isObjCIdType()) |
| 1063 | family = OMF_None; |
| 1064 | else { |
| 1065 | unsigned noParams = param_size(); |
| 1066 | if (noParams < 1 || noParams > 3) |
| 1067 | family = OMF_None; |
| 1068 | else { |
| 1069 | ObjCMethodDecl::param_type_iterator it = param_type_begin(); |
| 1070 | QualType ArgT = (*it); |
| 1071 | if (!ArgT->isObjCSelType()) { |
| 1072 | family = OMF_None; |
| 1073 | break; |
| 1074 | } |
| 1075 | while (--noParams) { |
| 1076 | it++; |
| 1077 | ArgT = (*it); |
| 1078 | if (!ArgT->isObjCIdType()) { |
| 1079 | family = OMF_None; |
| 1080 | break; |
| 1081 | } |
| 1082 | } |
| 1083 | } |
| 1084 | } |
| 1085 | break; |
| 1086 | |
| 1087 | } |
| 1088 | |
| 1089 | |
| 1090 | ObjCMethodDeclBits.Family = family; |
| 1091 | return family; |
| 1092 | } |
| 1093 | |
| 1094 | QualType ObjCMethodDecl::getSelfType(ASTContext &Context, |
| 1095 | const ObjCInterfaceDecl *OID, |
| 1096 | bool &selfIsPseudoStrong, |
| 1097 | bool &selfIsConsumed) const { |
| 1098 | QualType selfTy; |
| 1099 | selfIsPseudoStrong = false; |
| 1100 | selfIsConsumed = false; |
| 1101 | if (isInstanceMethod()) { |
| 1102 | |
| 1103 | |
| 1104 | if (OID) { |
| 1105 | selfTy = Context.getObjCInterfaceType(OID); |
| 1106 | selfTy = Context.getObjCObjectPointerType(selfTy); |
| 1107 | } else { |
| 1108 | selfTy = Context.getObjCIdType(); |
| 1109 | } |
| 1110 | } else |
| 1111 | selfTy = Context.getObjCClassType(); |
| 1112 | |
| 1113 | if (Context.getLangOpts().ObjCAutoRefCount) { |
| 1114 | if (isInstanceMethod()) { |
| 1115 | selfIsConsumed = hasAttr<NSConsumesSelfAttr>(); |
| 1116 | |
| 1117 | |
| 1118 | |
| 1119 | Qualifiers qs; |
| 1120 | qs.setObjCLifetime(Qualifiers::OCL_Strong); |
| 1121 | selfTy = Context.getQualifiedType(selfTy, qs); |
| 1122 | |
| 1123 | |
| 1124 | if (getMethodFamily() != OMF_init && !selfIsConsumed) { |
| 1125 | selfTy = selfTy.withConst(); |
| 1126 | selfIsPseudoStrong = true; |
| 1127 | } |
| 1128 | } |
| 1129 | else { |
| 1130 | assert(isClassMethod()); |
| 1131 | |
| 1132 | selfTy = selfTy.withConst(); |
| 1133 | selfIsPseudoStrong = true; |
| 1134 | } |
| 1135 | } |
| 1136 | return selfTy; |
| 1137 | } |
| 1138 | |
| 1139 | void ObjCMethodDecl::createImplicitParams(ASTContext &Context, |
| 1140 | const ObjCInterfaceDecl *OID) { |
| 1141 | bool selfIsPseudoStrong, selfIsConsumed; |
| 1142 | QualType selfTy = |
| 1143 | getSelfType(Context, OID, selfIsPseudoStrong, selfIsConsumed); |
| 1144 | auto *Self = ImplicitParamDecl::Create(Context, this, SourceLocation(), |
| 1145 | &Context.Idents.get("self"), selfTy, |
| 1146 | ImplicitParamDecl::ObjCSelf); |
| 1147 | setSelfDecl(Self); |
| 1148 | |
| 1149 | if (selfIsConsumed) |
| 1150 | Self->addAttr(NSConsumedAttr::CreateImplicit(Context)); |
| 1151 | |
| 1152 | if (selfIsPseudoStrong) |
| 1153 | Self->setARCPseudoStrong(true); |
| 1154 | |
| 1155 | setCmdDecl(ImplicitParamDecl::Create( |
| 1156 | Context, this, SourceLocation(), &Context.Idents.get("_cmd"), |
| 1157 | Context.getObjCSelType(), ImplicitParamDecl::ObjCCmd)); |
| 1158 | } |
| 1159 | |
| 1160 | ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() { |
| 1161 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext())) |
| 1162 | return ID; |
| 1163 | if (auto *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext())) |
| 1164 | return CD->getClassInterface(); |
| 1165 | if (auto *IMD = dyn_cast<ObjCImplDecl>(getDeclContext())) |
| 1166 | return IMD->getClassInterface(); |
| 1167 | if (isa<ObjCProtocolDecl>(getDeclContext())) |
| 1168 | return nullptr; |
| 1169 | llvm_unreachable("unknown method context"); |
| 1170 | } |
| 1171 | |
| 1172 | ObjCCategoryDecl *ObjCMethodDecl::getCategory() { |
| 1173 | if (auto *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext())) |
| 1174 | return CD; |
| 1175 | if (auto *IMD = dyn_cast<ObjCCategoryImplDecl>(getDeclContext())) |
| 1176 | return IMD->getCategoryDecl(); |
| 1177 | return nullptr; |
| 1178 | } |
| 1179 | |
| 1180 | SourceRange ObjCMethodDecl::getReturnTypeSourceRange() const { |
| 1181 | const auto *TSI = getReturnTypeSourceInfo(); |
| 1182 | if (TSI) |
| 1183 | return TSI->getTypeLoc().getSourceRange(); |
| 1184 | return SourceRange(); |
| 1185 | } |
| 1186 | |
| 1187 | QualType ObjCMethodDecl::getSendResultType() const { |
| 1188 | ASTContext &Ctx = getASTContext(); |
| 1189 | return getReturnType().getNonLValueExprType(Ctx) |
| 1190 | .substObjCTypeArgs(Ctx, {}, ObjCSubstitutionContext::Result); |
| 1191 | } |
| 1192 | |
| 1193 | QualType ObjCMethodDecl::getSendResultType(QualType receiverType) const { |
| 1194 | |
| 1195 | |
| 1196 | return getReturnType().getNonLValueExprType(getASTContext()) |
| 1197 | .substObjCMemberType(receiverType, getDeclContext(), |
| 1198 | ObjCSubstitutionContext::Result); |
| 1199 | } |
| 1200 | |
| 1201 | static void CollectOverriddenMethodsRecurse(const ObjCContainerDecl *Container, |
| 1202 | const ObjCMethodDecl *Method, |
| 1203 | SmallVectorImpl<const ObjCMethodDecl *> &Methods, |
| 1204 | bool MovedToSuper) { |
| 1205 | if (!Container) |
| 1206 | return; |
| 1207 | |
| 1208 | |
| 1209 | |
| 1210 | |
| 1211 | if (const auto *Category = dyn_cast<ObjCCategoryDecl>(Container)) { |
| 1212 | |
| 1213 | |
| 1214 | if (MovedToSuper) |
| 1215 | if (ObjCMethodDecl * |
| 1216 | Overridden = Container->getMethod(Method->getSelector(), |
| 1217 | Method->isInstanceMethod(), |
| 1218 | true)) |
| 1219 | if (Method != Overridden) { |
| 1220 | |
| 1221 | |
| 1222 | Methods.push_back(Overridden); |
| 1223 | return; |
| 1224 | } |
| 1225 | |
| 1226 | for (const auto *P : Category->protocols()) |
| 1227 | CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper); |
| 1228 | return; |
| 1229 | } |
| 1230 | |
| 1231 | |
| 1232 | if (const ObjCMethodDecl * |
| 1233 | Overridden = Container->getMethod(Method->getSelector(), |
| 1234 | Method->isInstanceMethod(), |
| 1235 | true)) |
| 1236 | if (Method != Overridden) { |
| 1237 | |
| 1238 | |
| 1239 | Methods.push_back(Overridden); |
| 1240 | return; |
| 1241 | } |
| 1242 | |
| 1243 | if (const auto *Protocol = dyn_cast<ObjCProtocolDecl>(Container)){ |
| 1244 | for (const auto *P : Protocol->protocols()) |
| 1245 | CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper); |
| 1246 | } |
| 1247 | |
| 1248 | if (const auto *Interface = dyn_cast<ObjCInterfaceDecl>(Container)) { |
| 1249 | for (const auto *P : Interface->protocols()) |
| 1250 | CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper); |
| 1251 | |
| 1252 | for (const auto *Cat : Interface->known_categories()) |
| 1253 | CollectOverriddenMethodsRecurse(Cat, Method, Methods, MovedToSuper); |
| 1254 | |
| 1255 | if (const ObjCInterfaceDecl *Super = Interface->getSuperClass()) |
| 1256 | return CollectOverriddenMethodsRecurse(Super, Method, Methods, |
| 1257 | true); |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | static inline void CollectOverriddenMethods(const ObjCContainerDecl *Container, |
| 1262 | const ObjCMethodDecl *Method, |
| 1263 | SmallVectorImpl<const ObjCMethodDecl *> &Methods) { |
| 1264 | CollectOverriddenMethodsRecurse(Container, Method, Methods, |
| 1265 | false); |
| 1266 | } |
| 1267 | |
| 1268 | static void collectOverriddenMethodsSlow(const ObjCMethodDecl *Method, |
| 1269 | SmallVectorImpl<const ObjCMethodDecl *> &overridden) { |
| 1270 | assert(Method->isOverriding()); |
| 1271 | |
| 1272 | if (const auto *ProtD = |
| 1273 | dyn_cast<ObjCProtocolDecl>(Method->getDeclContext())) { |
| 1274 | CollectOverriddenMethods(ProtD, Method, overridden); |
| 1275 | |
| 1276 | } else if (const auto *IMD = |
| 1277 | dyn_cast<ObjCImplDecl>(Method->getDeclContext())) { |
| 1278 | const ObjCInterfaceDecl *ID = IMD->getClassInterface(); |
| 1279 | if (!ID) |
| 1280 | return; |
| 1281 | |
| 1282 | |
| 1283 | if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(), |
| 1284 | Method->isInstanceMethod(), |
| 1285 | true)) |
| 1286 | Method = IFaceMeth; |
| 1287 | CollectOverriddenMethods(ID, Method, overridden); |
| 1288 | |
| 1289 | } else if (const auto *CatD = |
| 1290 | dyn_cast<ObjCCategoryDecl>(Method->getDeclContext())) { |
| 1291 | const ObjCInterfaceDecl *ID = CatD->getClassInterface(); |
| 1292 | if (!ID) |
| 1293 | return; |
| 1294 | |
| 1295 | |
| 1296 | if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(), |
| 1297 | Method->isInstanceMethod(), |
| 1298 | true)) |
| 1299 | Method = IFaceMeth; |
| 1300 | CollectOverriddenMethods(ID, Method, overridden); |
| 1301 | |
| 1302 | } else { |
| 1303 | CollectOverriddenMethods( |
| 1304 | dyn_cast_or_null<ObjCContainerDecl>(Method->getDeclContext()), |
| 1305 | Method, overridden); |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | void ObjCMethodDecl::getOverriddenMethods( |
| 1310 | SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const { |
| 1311 | const ObjCMethodDecl *Method = this; |
| 1312 | |
| 1313 | if (Method->isRedeclaration()) { |
| 1314 | Method = cast<ObjCContainerDecl>(Method->getDeclContext()) |
| 1315 | ->getMethod(Method->getSelector(), Method->isInstanceMethod(), |
| 1316 | true); |
| 1317 | } |
| 1318 | |
| 1319 | if (Method->isOverriding()) { |
| 1320 | collectOverriddenMethodsSlow(Method, Overridden); |
| 1321 | assert(!Overridden.empty() && |
| 1322 | "ObjCMethodDecl's overriding bit is not as expected"); |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | const ObjCPropertyDecl * |
| 1327 | ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const { |
| 1328 | Selector Sel = getSelector(); |
| 1329 | unsigned NumArgs = Sel.getNumArgs(); |
| 1330 | if (NumArgs > 1) |
| 1331 | return nullptr; |
| 1332 | |
| 1333 | if (isPropertyAccessor()) { |
| 1334 | const auto *Container = cast<ObjCContainerDecl>(getParent()); |
| 1335 | |
| 1336 | if (auto *ImplDecl = dyn_cast<ObjCImplDecl>(Container)) |
| 1337 | if (isSynthesizedAccessorStub()) |
| 1338 | Container = ImplDecl->getClassInterface(); |
| 1339 | |
| 1340 | bool IsGetter = (NumArgs == 0); |
| 1341 | bool IsInstance = isInstanceMethod(); |
| 1342 | |
| 1343 | |
| 1344 | |
| 1345 | auto findMatchingProperty = |
| 1346 | [&](const ObjCContainerDecl *Container) -> const ObjCPropertyDecl * { |
| 1347 | if (IsInstance) { |
| 1348 | for (const auto *I : Container->instance_properties()) { |
| 1349 | Selector NextSel = IsGetter ? I->getGetterName() |
| 1350 | : I->getSetterName(); |
| 1351 | if (NextSel == Sel) |
| 1352 | return I; |
| 1353 | } |
| 1354 | } else { |
| 1355 | for (const auto *I : Container->class_properties()) { |
| 1356 | Selector NextSel = IsGetter ? I->getGetterName() |
| 1357 | : I->getSetterName(); |
| 1358 | if (NextSel == Sel) |
| 1359 | return I; |
| 1360 | } |
| 1361 | } |
| 1362 | |
| 1363 | return nullptr; |
| 1364 | }; |
| 1365 | |
| 1366 | |
| 1367 | if (const auto *Found = findMatchingProperty(Container)) |
| 1368 | return Found; |
| 1369 | |
| 1370 | |
| 1371 | const ObjCInterfaceDecl *ClassDecl = nullptr; |
| 1372 | if (const auto *Category = dyn_cast<ObjCCategoryDecl>(Container)) { |
| 1373 | ClassDecl = Category->getClassInterface(); |
| 1374 | if (const auto *Found = findMatchingProperty(ClassDecl)) |
| 1375 | return Found; |
| 1376 | } else { |
| 1377 | |
| 1378 | ClassDecl = cast<ObjCInterfaceDecl>(Container); |
| 1379 | } |
| 1380 | assert(ClassDecl && "Failed to find main class"); |
| 1381 | |
| 1382 | |
| 1383 | for (const auto *Ext : ClassDecl->visible_extensions()) { |
| 1384 | if (Ext == Container) |
| 1385 | continue; |
| 1386 | if (const auto *Found = findMatchingProperty(Ext)) |
| 1387 | return Found; |
| 1388 | } |
| 1389 | |
| 1390 | assert(isSynthesizedAccessorStub() && "expected an accessor stub"); |
| 1391 | |
| 1392 | for (const auto *Cat : ClassDecl->known_categories()) { |
| 1393 | if (Cat == Container) |
| 1394 | continue; |
| 1395 | if (const auto *Found = findMatchingProperty(Cat)) |
| 1396 | return Found; |
| 1397 | } |
| 1398 | |
| 1399 | llvm_unreachable("Marked as a property accessor but no property found!"); |
| 1400 | } |
| 1401 | |
| 1402 | if (!CheckOverrides) |
| 1403 | return nullptr; |
| 1404 | |
| 1405 | using OverridesTy = SmallVector<const ObjCMethodDecl *, 8>; |
| 1406 | |
| 1407 | OverridesTy Overrides; |
| 1408 | getOverriddenMethods(Overrides); |
| 1409 | for (const auto *Override : Overrides) |
| 1410 | if (const ObjCPropertyDecl *Prop = Override->findPropertyDecl(false)) |
| 1411 | return Prop; |
| 1412 | |
| 1413 | return nullptr; |
| 1414 | } |
| 1415 | |
| 1416 | |
| 1417 | |
| 1418 | |
| 1419 | |
| 1420 | void ObjCTypeParamDecl::anchor() {} |
| 1421 | |
| 1422 | ObjCTypeParamDecl *ObjCTypeParamDecl::Create(ASTContext &ctx, DeclContext *dc, |
| 1423 | ObjCTypeParamVariance variance, |
| 1424 | SourceLocation varianceLoc, |
| 1425 | unsigned index, |
| 1426 | SourceLocation nameLoc, |
| 1427 | IdentifierInfo *name, |
| 1428 | SourceLocation colonLoc, |
| 1429 | TypeSourceInfo *boundInfo) { |
| 1430 | auto *TPDecl = |
| 1431 | new (ctx, dc) ObjCTypeParamDecl(ctx, dc, variance, varianceLoc, index, |
| 1432 | nameLoc, name, colonLoc, boundInfo); |
| 1433 | QualType TPType = ctx.getObjCTypeParamType(TPDecl, {}); |
| 1434 | TPDecl->setTypeForDecl(TPType.getTypePtr()); |
| 1435 | return TPDecl; |
| 1436 | } |
| 1437 | |
| 1438 | ObjCTypeParamDecl *ObjCTypeParamDecl::CreateDeserialized(ASTContext &ctx, |
| 1439 | unsigned ID) { |
| 1440 | return new (ctx, ID) ObjCTypeParamDecl(ctx, nullptr, |
| 1441 | ObjCTypeParamVariance::Invariant, |
| 1442 | SourceLocation(), 0, SourceLocation(), |
| 1443 | nullptr, SourceLocation(), nullptr); |
| 1444 | } |
| 1445 | |
| 1446 | SourceRange ObjCTypeParamDecl::getSourceRange() const { |
| 1447 | SourceLocation startLoc = VarianceLoc; |
| 1448 | if (startLoc.isInvalid()) |
| 1449 | startLoc = getLocation(); |
| 1450 | |
| 1451 | if (hasExplicitBound()) { |
| 1452 | return SourceRange(startLoc, |
| 1453 | getTypeSourceInfo()->getTypeLoc().getEndLoc()); |
| 1454 | } |
| 1455 | |
| 1456 | return SourceRange(startLoc); |
| 1457 | } |
| 1458 | |
| 1459 | |
| 1460 | |
| 1461 | |
| 1462 | ObjCTypeParamList::ObjCTypeParamList(SourceLocation lAngleLoc, |
| 1463 | ArrayRef<ObjCTypeParamDecl *> typeParams, |
| 1464 | SourceLocation rAngleLoc) |
| 1465 | : Brackets(lAngleLoc, rAngleLoc), NumParams(typeParams.size()) { |
| 1466 | std::copy(typeParams.begin(), typeParams.end(), begin()); |
| 1467 | } |
| 1468 | |
| 1469 | ObjCTypeParamList *ObjCTypeParamList::create( |
| 1470 | ASTContext &ctx, |
| 1471 | SourceLocation lAngleLoc, |
| 1472 | ArrayRef<ObjCTypeParamDecl *> typeParams, |
| 1473 | SourceLocation rAngleLoc) { |
| 1474 | void *mem = |
| 1475 | ctx.Allocate(totalSizeToAlloc<ObjCTypeParamDecl *>(typeParams.size()), |
| 1476 | alignof(ObjCTypeParamList)); |
| 1477 | return new (mem) ObjCTypeParamList(lAngleLoc, typeParams, rAngleLoc); |
| 1478 | } |
| 1479 | |
| 1480 | void ObjCTypeParamList::gatherDefaultTypeArgs( |
| 1481 | SmallVectorImpl<QualType> &typeArgs) const { |
| 1482 | typeArgs.reserve(size()); |
| 1483 | for (auto typeParam : *this) |
| 1484 | typeArgs.push_back(typeParam->getUnderlyingType()); |
| 1485 | } |
| 1486 | |
| 1487 | |
| 1488 | |
| 1489 | |
| 1490 | |
| 1491 | ObjCInterfaceDecl *ObjCInterfaceDecl::Create(const ASTContext &C, |
| 1492 | DeclContext *DC, |
| 1493 | SourceLocation atLoc, |
| 1494 | IdentifierInfo *Id, |
| 1495 | ObjCTypeParamList *typeParamList, |
| 1496 | ObjCInterfaceDecl *PrevDecl, |
| 1497 | SourceLocation ClassLoc, |
| 1498 | bool isInternal){ |
| 1499 | auto *Result = new (C, DC) |
| 1500 | ObjCInterfaceDecl(C, DC, atLoc, Id, typeParamList, ClassLoc, PrevDecl, |
| 1501 | isInternal); |
| 1502 | Result->Data.setInt(!C.getLangOpts().Modules); |
| 1503 | C.getObjCInterfaceType(Result, PrevDecl); |
| 1504 | return Result; |
| 1505 | } |
| 1506 | |
| 1507 | ObjCInterfaceDecl *ObjCInterfaceDecl::CreateDeserialized(const ASTContext &C, |
| 1508 | unsigned ID) { |
| 1509 | auto *Result = new (C, ID) |
| 1510 | ObjCInterfaceDecl(C, nullptr, SourceLocation(), nullptr, nullptr, |
| 1511 | SourceLocation(), nullptr, false); |
| 1512 | Result->Data.setInt(!C.getLangOpts().Modules); |
| 1513 | return Result; |
| 1514 | } |
| 1515 | |
| 1516 | ObjCInterfaceDecl::ObjCInterfaceDecl(const ASTContext &C, DeclContext *DC, |
| 1517 | SourceLocation AtLoc, IdentifierInfo *Id, |
| 1518 | ObjCTypeParamList *typeParamList, |
| 1519 | SourceLocation CLoc, |
| 1520 | ObjCInterfaceDecl *PrevDecl, |
| 1521 | bool IsInternal) |
| 1522 | : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, AtLoc), |
| 1523 | redeclarable_base(C) { |
| 1524 | setPreviousDecl(PrevDecl); |
| 1525 | |
| 1526 | |
| 1527 | if (PrevDecl) |
| 1528 | Data = PrevDecl->Data; |
| 1529 | |
| 1530 | setImplicit(IsInternal); |
| 1531 | |
| 1532 | setTypeParamList(typeParamList); |
| 1533 | } |
| 1534 | |
| 1535 | void ObjCInterfaceDecl::LoadExternalDefinition() const { |
| 1536 | assert(data().ExternallyCompleted && "Class is not externally completed"); |
| 1537 | data().ExternallyCompleted = false; |
| 1538 | getASTContext().getExternalSource()->CompleteType( |
| 1539 | const_cast<ObjCInterfaceDecl *>(this)); |
| 1540 | } |
| 1541 | |
| 1542 | void ObjCInterfaceDecl::setExternallyCompleted() { |
| 1543 | assert(getASTContext().getExternalSource() && |
| 1544 | "Class can't be externally completed without an external source"); |
| 1545 | assert(hasDefinition() && |
| 1546 | "Forward declarations can't be externally completed"); |
| 1547 | data().ExternallyCompleted = true; |
| 1548 | } |
| 1549 | |
| 1550 | void ObjCInterfaceDecl::setHasDesignatedInitializers() { |
| 1551 | |
| 1552 | if (!isThisDeclarationADefinition()) |
| 1553 | return; |
| 1554 | data().HasDesignatedInitializers = true; |
| 1555 | } |
| 1556 | |
| 1557 | bool ObjCInterfaceDecl::hasDesignatedInitializers() const { |
| 1558 | |
| 1559 | if (!isThisDeclarationADefinition()) |
| 1560 | return false; |
| 1561 | if (data().ExternallyCompleted) |
| 1562 | LoadExternalDefinition(); |
| 1563 | |
| 1564 | return data().HasDesignatedInitializers; |
| 1565 | } |
| 1566 | |
| 1567 | StringRef |
| 1568 | ObjCInterfaceDecl::getObjCRuntimeNameAsString() const { |
| 1569 | if (const auto *ObjCRTName = getAttr<ObjCRuntimeNameAttr>()) |
| 1570 | return ObjCRTName->getMetadataName(); |
| 1571 | |
| 1572 | return getName(); |
| 1573 | } |
| 1574 | |
| 1575 | StringRef |
| 1576 | ObjCImplementationDecl::getObjCRuntimeNameAsString() const { |
| 1577 | if (ObjCInterfaceDecl *ID = |
| 1578 | const_cast<ObjCImplementationDecl*>(this)->getClassInterface()) |
| 1579 | return ID->getObjCRuntimeNameAsString(); |
| 1580 | |
| 1581 | return getName(); |
| 1582 | } |
| 1583 | |
| 1584 | ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const { |
| 1585 | if (const ObjCInterfaceDecl *Def = getDefinition()) { |
| 14 | | Calling 'ObjCInterfaceDecl::getDefinition' | |
|
| 18 | | Returning from 'ObjCInterfaceDecl::getDefinition' | |
|
| 19 | | Assuming 'Def' is non-null | |
|
| |
| 1586 | if (data().ExternallyCompleted) |
| 21 | | Assuming field 'ExternallyCompleted' is 0 | |
|
| |
| 1587 | LoadExternalDefinition(); |
| 1588 | |
| 1589 | return getASTContext().getObjCImplementation( |
| 23 | | Returning pointer, which participates in a condition later | |
|
| 1590 | const_cast<ObjCInterfaceDecl*>(Def)); |
| 1591 | } |
| 1592 | |
| 1593 | |
| 1594 | return nullptr; |
| 1595 | } |
| 1596 | |
| 1597 | void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) { |
| 1598 | getASTContext().setObjCImplementation(getDefinition(), ImplD); |
| 1599 | } |
| 1600 | |
| 1601 | namespace { |
| 1602 | |
| 1603 | struct SynthesizeIvarChunk { |
| 1604 | uint64_t Size; |
| 1605 | ObjCIvarDecl *Ivar; |
| 1606 | |
| 1607 | SynthesizeIvarChunk(uint64_t size, ObjCIvarDecl *ivar) |
| 1608 | : Size(size), Ivar(ivar) {} |
| 1609 | }; |
| 1610 | |
| 1611 | bool operator<(const SynthesizeIvarChunk & LHS, |
| 1612 | const SynthesizeIvarChunk &RHS) { |
| 1613 | return LHS.Size < RHS.Size; |
| 1614 | } |
| 1615 | |
| 1616 | } |
| 1617 | |
| 1618 | |
| 1619 | |
| 1620 | |
| 1621 | |
| 1622 | |
| 1623 | |
| 1624 | |
| 1625 | |
| 1626 | |
| 1627 | ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() { |
| 1628 | |
| 1629 | if (!hasDefinition()) |
| 1 | Calling 'ObjCInterfaceDecl::hasDefinition' | |
|
| 5 | | Returning from 'ObjCInterfaceDecl::hasDefinition' | |
|
| 6 | | Assuming the condition is false | |
|
| |
| 1630 | return nullptr; |
| 1631 | |
| 1632 | ObjCIvarDecl *curIvar = nullptr; |
| 8 | | 'curIvar' initialized to a null pointer value | |
|
| 1633 | if (!data().IvarList) { |
| 9 | | Assuming field 'IvarList' is non-null | |
|
| |
| 1634 | if (!ivar_empty()) { |
| 1635 | ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end(); |
| 1636 | data().IvarList = *I; ++I; |
| 1637 | for (curIvar = data().IvarList; I != E; curIvar = *I, ++I) |
| 1638 | curIvar->setNextIvar(*I); |
| 1639 | } |
| 1640 | |
| 1641 | for (const auto *Ext : known_extensions()) { |
| 1642 | if (!Ext->ivar_empty()) { |
| 1643 | ObjCCategoryDecl::ivar_iterator |
| 1644 | I = Ext->ivar_begin(), |
| 1645 | E = Ext->ivar_end(); |
| 1646 | if (!data().IvarList) { |
| 1647 | data().IvarList = *I; ++I; |
| 1648 | curIvar = data().IvarList; |
| 1649 | } |
| 1650 | for ( ;I != E; curIvar = *I, ++I) |
| 1651 | curIvar->setNextIvar(*I); |
| 1652 | } |
| 1653 | } |
| 1654 | data().IvarListMissingImplementation = true; |
| 1655 | } |
| 1656 | |
| 1657 | |
| 1658 | if (!data().IvarListMissingImplementation) |
| 11 | | Assuming field 'IvarListMissingImplementation' is not equal to 0 | |
|
| |
| 1659 | return data().IvarList; |
| 1660 | |
| 1661 | if (ObjCImplementationDecl *ImplDecl = getImplementation()) { |
| 13 | | Calling 'ObjCInterfaceDecl::getImplementation' | |
|
| 24 | | Returning from 'ObjCInterfaceDecl::getImplementation' | |
|
| 25 | | Assuming 'ImplDecl' is non-null | |
|
| |
| 1662 | data().IvarListMissingImplementation = false; |
| 1663 | if (!ImplDecl->ivar_empty()) { |
| 27 | | Calling 'ObjCImplementationDecl::ivar_empty' | |
|
| 36 | | Returning from 'ObjCImplementationDecl::ivar_empty' | |
|
| |
| 1664 | SmallVector<SynthesizeIvarChunk, 16> layout; |
| 1665 | for (auto *IV : ImplDecl->ivars()) { |
| 1666 | if (IV->getSynthesize() && !IV->isInvalidDecl()) { |
| 38 | | Assuming the condition is false | |
|
| 1667 | layout.push_back(SynthesizeIvarChunk( |
| 1668 | IV->getASTContext().getTypeSize(IV->getType()), IV)); |
| 1669 | continue; |
| 1670 | } |
| 1671 | if (!data().IvarList) |
| 39 | | Assuming field 'IvarList' is non-null | |
|
| |
| 1672 | data().IvarList = IV; |
| 1673 | else |
| 1674 | curIvar->setNextIvar(IV); |
| 41 | | Called C++ object pointer is null |
|
| 1675 | curIvar = IV; |
| 1676 | } |
| 1677 | |
| 1678 | if (!layout.empty()) { |
| 1679 | |
| 1680 | llvm::stable_sort(layout); |
| 1681 | unsigned Ix = 0, EIx = layout.size(); |
| 1682 | if (!data().IvarList) { |
| 1683 | data().IvarList = layout[0].Ivar; Ix++; |
| 1684 | curIvar = data().IvarList; |
| 1685 | } |
| 1686 | for ( ; Ix != EIx; curIvar = layout[Ix].Ivar, Ix++) |
| 1687 | curIvar->setNextIvar(layout[Ix].Ivar); |
| 1688 | } |
| 1689 | } |
| 1690 | } |
| 1691 | return data().IvarList; |
| 1692 | } |
| 1693 | |
| 1694 | |
| 1695 | |
| 1696 | |
| 1697 | |
| 1698 | ObjCCategoryDecl * |
| 1699 | ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const { |
| 1700 | |
| 1701 | if (!hasDefinition()) |
| 1702 | return nullptr; |
| 1703 | |
| 1704 | if (data().ExternallyCompleted) |
| 1705 | LoadExternalDefinition(); |
| 1706 | |
| 1707 | for (auto *Cat : visible_categories()) |
| 1708 | if (Cat->getIdentifier() == CategoryId) |
| 1709 | return Cat; |
| 1710 | |
| 1711 | return nullptr; |
| 1712 | } |
| 1713 | |
| 1714 | ObjCMethodDecl * |
| 1715 | ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const { |
| 1716 | for (const auto *Cat : visible_categories()) { |
| 1717 | if (ObjCCategoryImplDecl *Impl = Cat->getImplementation()) |
| 1718 | if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel)) |
| 1719 | return MD; |
| 1720 | } |
| 1721 | |
| 1722 | return nullptr; |
| 1723 | } |
| 1724 | |
| 1725 | ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const { |
| 1726 | for (const auto *Cat : visible_categories()) { |
| 1727 | if (ObjCCategoryImplDecl *Impl = Cat->getImplementation()) |
| 1728 | if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel)) |
| 1729 | return MD; |
| 1730 | } |
| 1731 | |
| 1732 | return nullptr; |
| 1733 | } |
| 1734 | |
| 1735 | |
| 1736 | |
| 1737 | |
| 1738 | bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto, |
| 1739 | bool lookupCategory, |
| 1740 | bool RHSIsQualifiedID) { |
| 1741 | if (!hasDefinition()) |
| 1742 | return false; |
| 1743 | |
| 1744 | ObjCInterfaceDecl *IDecl = this; |
| 1745 | |
| 1746 | for (auto *PI : IDecl->protocols()){ |
| 1747 | if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI)) |
| 1748 | return true; |
| 1749 | |
| 1750 | |
| 1751 | |
| 1752 | |
| 1753 | |
| 1754 | |
| 1755 | if (RHSIsQualifiedID && |
| 1756 | getASTContext().ProtocolCompatibleWithProtocol(PI, lProto)) |
| 1757 | return true; |
| 1758 | } |
| 1759 | |
| 1760 | |
| 1761 | if (lookupCategory) |
| 1762 | for (const auto *Cat : visible_categories()) { |
| 1763 | for (auto *PI : Cat->protocols()) |
| 1764 | if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI)) |
| 1765 | return true; |
| 1766 | } |
| 1767 | |
| 1768 | |
| 1769 | if (IDecl->getSuperClass()) |
| 1770 | return |
| 1771 | IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory, |
| 1772 | RHSIsQualifiedID); |
| 1773 | |
| 1774 | return false; |
| 1775 | } |
| 1776 | |
| 1777 | |
| 1778 | |
| 1779 | |
| 1780 | |
| 1781 | void ObjCIvarDecl::anchor() {} |
| 1782 | |
| 1783 | ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC, |
| 1784 | SourceLocation StartLoc, |
| 1785 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 1786 | QualType T, TypeSourceInfo *TInfo, |
| 1787 | AccessControl ac, Expr *BW, |
| 1788 | bool synthesized) { |
| 1789 | if (DC) { |
| 1790 | |
| 1791 | |
| 1792 | |
| 1793 | |
| 1794 | |
| 1795 | |
| 1796 | |
| 1797 | |
| 1798 | |
| 1799 | |
| 1800 | assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) || |
| 1801 | isa<ObjCCategoryDecl>(DC)) && |
| 1802 | "Invalid ivar decl context!"); |
| 1803 | |
| 1804 | |
| 1805 | auto *ID = dyn_cast<ObjCInterfaceDecl>(DC); |
| 1806 | if (!ID) { |
| 1807 | if (auto *IM = dyn_cast<ObjCImplementationDecl>(DC)) |
| 1808 | ID = IM->getClassInterface(); |
| 1809 | else |
| 1810 | ID = cast<ObjCCategoryDecl>(DC)->getClassInterface(); |
| 1811 | } |
| 1812 | ID->setIvarList(nullptr); |
| 1813 | } |
| 1814 | |
| 1815 | return new (C, DC) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo, ac, BW, |
| 1816 | synthesized); |
| 1817 | } |
| 1818 | |
| 1819 | ObjCIvarDecl *ObjCIvarDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1820 | return new (C, ID) ObjCIvarDecl(nullptr, SourceLocation(), SourceLocation(), |
| 1821 | nullptr, QualType(), nullptr, |
| 1822 | ObjCIvarDecl::None, nullptr, false); |
| 1823 | } |
| 1824 | |
| 1825 | const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const { |
| 1826 | const auto *DC = cast<ObjCContainerDecl>(getDeclContext()); |
| 1827 | |
| 1828 | switch (DC->getKind()) { |
| 1829 | default: |
| 1830 | case ObjCCategoryImpl: |
| 1831 | case ObjCProtocol: |
| 1832 | llvm_unreachable("invalid ivar container!"); |
| 1833 | |
| 1834 | |
| 1835 | case ObjCCategory: { |
| 1836 | const auto *CD = cast<ObjCCategoryDecl>(DC); |
| 1837 | assert(CD->IsClassExtension() && "invalid container for ivar!"); |
| 1838 | return CD->getClassInterface(); |
| 1839 | } |
| 1840 | |
| 1841 | case ObjCImplementation: |
| 1842 | return cast<ObjCImplementationDecl>(DC)->getClassInterface(); |
| 1843 | |
| 1844 | case ObjCInterface: |
| 1845 | return cast<ObjCInterfaceDecl>(DC); |
| 1846 | } |
| 1847 | } |
| 1848 | |
| 1849 | QualType ObjCIvarDecl::getUsageType(QualType objectType) const { |
| 1850 | return getType().substObjCMemberType(objectType, getDeclContext(), |
| 1851 | ObjCSubstitutionContext::Property); |
| 1852 | } |
| 1853 | |
| 1854 | |
| 1855 | |
| 1856 | |
| 1857 | |
| 1858 | void ObjCAtDefsFieldDecl::anchor() {} |
| 1859 | |
| 1860 | ObjCAtDefsFieldDecl |
| 1861 | *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, |
| 1862 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 1863 | IdentifierInfo *Id, QualType T, Expr *BW) { |
| 1864 | return new (C, DC) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW); |
| 1865 | } |
| 1866 | |
| 1867 | ObjCAtDefsFieldDecl *ObjCAtDefsFieldDecl::CreateDeserialized(ASTContext &C, |
| 1868 | unsigned ID) { |
| 1869 | return new (C, ID) ObjCAtDefsFieldDecl(nullptr, SourceLocation(), |
| 1870 | SourceLocation(), nullptr, QualType(), |
| 1871 | nullptr); |
| 1872 | } |
| 1873 | |
| 1874 | |
| 1875 | |
| 1876 | |
| 1877 | |
| 1878 | void ObjCProtocolDecl::anchor() {} |
| 1879 | |
| 1880 | ObjCProtocolDecl::ObjCProtocolDecl(ASTContext &C, DeclContext *DC, |
| 1881 | IdentifierInfo *Id, SourceLocation nameLoc, |
| 1882 | SourceLocation atStartLoc, |
| 1883 | ObjCProtocolDecl *PrevDecl) |
| 1884 | : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc), |
| 1885 | redeclarable_base(C) { |
| 1886 | setPreviousDecl(PrevDecl); |
| 1887 | if (PrevDecl) |
| 1888 | Data = PrevDecl->Data; |
| 1889 | } |
| 1890 | |
| 1891 | ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
| 1892 | IdentifierInfo *Id, |
| 1893 | SourceLocation nameLoc, |
| 1894 | SourceLocation atStartLoc, |
| 1895 | ObjCProtocolDecl *PrevDecl) { |
| 1896 | auto *Result = |
| 1897 | new (C, DC) ObjCProtocolDecl(C, DC, Id, nameLoc, atStartLoc, PrevDecl); |
| 1898 | Result->Data.setInt(!C.getLangOpts().Modules); |
| 1899 | return Result; |
| 1900 | } |
| 1901 | |
| 1902 | ObjCProtocolDecl *ObjCProtocolDecl::CreateDeserialized(ASTContext &C, |
| 1903 | unsigned ID) { |
| 1904 | ObjCProtocolDecl *Result = |
| 1905 | new (C, ID) ObjCProtocolDecl(C, nullptr, nullptr, SourceLocation(), |
| 1906 | SourceLocation(), nullptr); |
| 1907 | Result->Data.setInt(!C.getLangOpts().Modules); |
| 1908 | return Result; |
| 1909 | } |
| 1910 | |
| 1911 | bool ObjCProtocolDecl::isNonRuntimeProtocol() const { |
| 1912 | return hasAttr<ObjCNonRuntimeProtocolAttr>(); |
| 1913 | } |
| 1914 | |
| 1915 | void ObjCProtocolDecl::getImpliedProtocols( |
| 1916 | llvm::DenseSet<const ObjCProtocolDecl *> &IPs) const { |
| 1917 | std::queue<const ObjCProtocolDecl *> WorkQueue; |
| 1918 | WorkQueue.push(this); |
| 1919 | |
| 1920 | while (!WorkQueue.empty()) { |
| 1921 | const auto *PD = WorkQueue.front(); |
| 1922 | WorkQueue.pop(); |
| 1923 | for (const auto *Parent : PD->protocols()) { |
| 1924 | const auto *Can = Parent->getCanonicalDecl(); |
| 1925 | auto Result = IPs.insert(Can); |
| 1926 | if (Result.second) |
| 1927 | WorkQueue.push(Parent); |
| 1928 | } |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) { |
| 1933 | ObjCProtocolDecl *PDecl = this; |
| 1934 | |
| 1935 | if (Name == getIdentifier()) |
| 1936 | return PDecl; |
| 1937 | |
| 1938 | for (auto *I : protocols()) |
| 1939 | if ((PDecl = I->lookupProtocolNamed(Name))) |
| 1940 | return PDecl; |
| 1941 | |
| 1942 | return nullptr; |
| 1943 | } |
| 1944 | |
| 1945 | |
| 1946 | |
| 1947 | ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel, |
| 1948 | bool isInstance) const { |
| 1949 | ObjCMethodDecl *MethodDecl = nullptr; |
| 1950 | |
| 1951 | |
| 1952 | |
| 1953 | const ObjCProtocolDecl *Def = getDefinition(); |
| 1954 | if (!Def || !Def->isUnconditionallyVisible()) |
| 1955 | return nullptr; |
| 1956 | |
| 1957 | if ((MethodDecl = getMethod(Sel, isInstance))) |
| 1958 | return MethodDecl; |
| 1959 | |
| 1960 | for (const auto *I : protocols()) |
| 1961 | if ((MethodDecl = I->lookupMethod(Sel, isInstance))) |
| 1962 | return MethodDecl; |
| 1963 | return nullptr; |
| 1964 | } |
| 1965 | |
| 1966 | void ObjCProtocolDecl::allocateDefinitionData() { |
| 1967 | assert(!Data.getPointer() && "Protocol already has a definition!"); |
| 1968 | Data.setPointer(new (getASTContext()) DefinitionData); |
| 1969 | Data.getPointer()->Definition = this; |
| 1970 | } |
| 1971 | |
| 1972 | void ObjCProtocolDecl::startDefinition() { |
| 1973 | allocateDefinitionData(); |
| 1974 | |
| 1975 | |
| 1976 | for (auto *RD : redecls()) |
| 1977 | RD->Data = this->Data; |
| 1978 | } |
| 1979 | |
| 1980 | void ObjCProtocolDecl::collectPropertiesToImplement(PropertyMap &PM, |
| 1981 | PropertyDeclOrder &PO) const { |
| 1982 | if (const ObjCProtocolDecl *PDecl = getDefinition()) { |
| 1983 | for (auto *Prop : PDecl->properties()) { |
| 1984 | |
| 1985 | PM.insert(std::make_pair( |
| 1986 | std::make_pair(Prop->getIdentifier(), Prop->isClassProperty()), |
| 1987 | Prop)); |
| 1988 | PO.push_back(Prop); |
| 1989 | } |
| 1990 | |
| 1991 | for (const auto *PI : PDecl->protocols()) |
| 1992 | PI->collectPropertiesToImplement(PM, PO); |
| 1993 | } |
| 1994 | } |
| 1995 | |
| 1996 | void ObjCProtocolDecl::collectInheritedProtocolProperties( |
| 1997 | const ObjCPropertyDecl *Property, ProtocolPropertySet &PS, |
| 1998 | PropertyDeclOrder &PO) const { |
| 1999 | if (const ObjCProtocolDecl *PDecl = getDefinition()) { |
| 2000 | if (!PS.insert(PDecl).second) |
| 2001 | return; |
| 2002 | for (auto *Prop : PDecl->properties()) { |
| 2003 | if (Prop == Property) |
| 2004 | continue; |
| 2005 | if (Prop->getIdentifier() == Property->getIdentifier()) { |
| 2006 | PO.push_back(Prop); |
| 2007 | return; |
| 2008 | } |
| 2009 | } |
| 2010 | |
| 2011 | for (const auto *PI : PDecl->protocols()) |
| 2012 | PI->collectInheritedProtocolProperties(Property, PS, PO); |
| 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | StringRef |
| 2017 | ObjCProtocolDecl::getObjCRuntimeNameAsString() const { |
| 2018 | if (const auto *ObjCRTName = getAttr<ObjCRuntimeNameAttr>()) |
| 2019 | return ObjCRTName->getMetadataName(); |
| 2020 | |
| 2021 | return getName(); |
| 2022 | } |
| 2023 | |
| 2024 | |
| 2025 | |
| 2026 | |
| 2027 | |
| 2028 | void ObjCCategoryDecl::anchor() {} |
| 2029 | |
| 2030 | ObjCCategoryDecl::ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc, |
| 2031 | SourceLocation ClassNameLoc, |
| 2032 | SourceLocation CategoryNameLoc, |
| 2033 | IdentifierInfo *Id, ObjCInterfaceDecl *IDecl, |
| 2034 | ObjCTypeParamList *typeParamList, |
| 2035 | SourceLocation IvarLBraceLoc, |
| 2036 | SourceLocation IvarRBraceLoc) |
| 2037 | : ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc), |
| 2038 | ClassInterface(IDecl), CategoryNameLoc(CategoryNameLoc), |
| 2039 | IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc) { |
| 2040 | setTypeParamList(typeParamList); |
| 2041 | } |
| 2042 | |
| 2043 | ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, |
| 2044 | SourceLocation AtLoc, |
| 2045 | SourceLocation ClassNameLoc, |
| 2046 | SourceLocation CategoryNameLoc, |
| 2047 | IdentifierInfo *Id, |
| 2048 | ObjCInterfaceDecl *IDecl, |
| 2049 | ObjCTypeParamList *typeParamList, |
| 2050 | SourceLocation IvarLBraceLoc, |
| 2051 | SourceLocation IvarRBraceLoc) { |
| 2052 | auto *CatDecl = |
| 2053 | new (C, DC) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id, |
| 2054 | IDecl, typeParamList, IvarLBraceLoc, |
| 2055 | IvarRBraceLoc); |
| 2056 | if (IDecl) { |
| 2057 | |
| 2058 | CatDecl->NextClassCategory = IDecl->getCategoryListRaw(); |
| 2059 | if (IDecl->hasDefinition()) { |
| 2060 | IDecl->setCategoryListRaw(CatDecl); |
| 2061 | if (ASTMutationListener *L = C.getASTMutationListener()) |
| 2062 | L->AddedObjCCategoryToInterface(CatDecl, IDecl); |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | return CatDecl; |
| 2067 | } |
| 2068 | |
| 2069 | ObjCCategoryDecl *ObjCCategoryDecl::CreateDeserialized(ASTContext &C, |
| 2070 | unsigned ID) { |
| 2071 | return new (C, ID) ObjCCategoryDecl(nullptr, SourceLocation(), |
| 2072 | SourceLocation(), SourceLocation(), |
| 2073 | nullptr, nullptr, nullptr); |
| 2074 | } |
| 2075 | |
| 2076 | ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const { |
| 2077 | return getASTContext().getObjCImplementation( |
| 2078 | const_cast<ObjCCategoryDecl*>(this)); |
| 2079 | } |
| 2080 | |
| 2081 | void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) { |
| 2082 | getASTContext().setObjCImplementation(this, ImplD); |
| 2083 | } |
| 2084 | |
| 2085 | void ObjCCategoryDecl::setTypeParamList(ObjCTypeParamList *TPL) { |
| 2086 | TypeParamList = TPL; |
| 2087 | if (!TPL) |
| 2088 | return; |
| 2089 | |
| 2090 | for (auto *typeParam : *TypeParamList) |
| 2091 | typeParam->setDeclContext(this); |
| 2092 | } |
| 2093 | |
| 2094 | |
| 2095 | |
| 2096 | |
| 2097 | |
| 2098 | void ObjCCategoryImplDecl::anchor() {} |
| 2099 | |
| 2100 | ObjCCategoryImplDecl * |
| 2101 | ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, |
| 2102 | IdentifierInfo *Id, |
| 2103 | ObjCInterfaceDecl *ClassInterface, |
| 2104 | SourceLocation nameLoc, |
| 2105 | SourceLocation atStartLoc, |
| 2106 | SourceLocation CategoryNameLoc) { |
| 2107 | if (ClassInterface && ClassInterface->hasDefinition()) |
| 2108 | ClassInterface = ClassInterface->getDefinition(); |
| 2109 | return new (C, DC) ObjCCategoryImplDecl(DC, Id, ClassInterface, nameLoc, |
| 2110 | atStartLoc, CategoryNameLoc); |
| 2111 | } |
| 2112 | |
| 2113 | ObjCCategoryImplDecl *ObjCCategoryImplDecl::CreateDeserialized(ASTContext &C, |
| 2114 | unsigned ID) { |
| 2115 | return new (C, ID) ObjCCategoryImplDecl(nullptr, nullptr, nullptr, |
| 2116 | SourceLocation(), SourceLocation(), |
| 2117 | SourceLocation()); |
| 2118 | } |
| 2119 | |
| 2120 | ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const { |
| 2121 | |
| 2122 | if (const ObjCInterfaceDecl *ID = getClassInterface()) |
| 2123 | return ID->FindCategoryDeclaration(getIdentifier()); |
| 2124 | return nullptr; |
| 2125 | } |
| 2126 | |
| 2127 | void ObjCImplDecl::anchor() {} |
| 2128 | |
| 2129 | void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) { |
| 2130 | |
| 2131 | property->setLexicalDeclContext(this); |
| 2132 | addDecl(property); |
| 2133 | } |
| 2134 | |
| 2135 | void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) { |
| 2136 | ASTContext &Ctx = getASTContext(); |
| 2137 | |
| 2138 | if (auto *ImplD = dyn_cast_or_null<ObjCImplementationDecl>(this)) { |
| 2139 | if (IFace) |
| 2140 | Ctx.setObjCImplementation(IFace, ImplD); |
| 2141 | |
| 2142 | } else if (auto *ImplD = dyn_cast_or_null<ObjCCategoryImplDecl>(this)) { |
| 2143 | if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier())) |
| 2144 | Ctx.setObjCImplementation(CD, ImplD); |
| 2145 | } |
| 2146 | |
| 2147 | ClassInterface = IFace; |
| 2148 | } |
| 2149 | |
| 2150 | |
| 2151 | |
| 2152 | |
| 2153 | ObjCPropertyImplDecl *ObjCImplDecl:: |
| 2154 | FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { |
| 2155 | for (auto *PID : property_impls()) |
| 2156 | if (PID->getPropertyIvarDecl() && |
| 2157 | PID->getPropertyIvarDecl()->getIdentifier() == ivarId) |
| 2158 | return PID; |
| 2159 | return nullptr; |
| 2160 | } |
| 2161 | |
| 2162 | |
| 2163 | |
| 2164 | |
| 2165 | ObjCPropertyImplDecl *ObjCImplDecl:: |
| 2166 | FindPropertyImplDecl(IdentifierInfo *Id, |
| 2167 | ObjCPropertyQueryKind QueryKind) const { |
| 2168 | ObjCPropertyImplDecl *ClassPropImpl = nullptr; |
| 2169 | for (auto *PID : property_impls()) |
| 2170 | |
| 2171 | |
| 2172 | if (PID->getPropertyDecl()->getIdentifier() == Id) { |
| 2173 | if ((QueryKind == ObjCPropertyQueryKind::OBJC_PR_query_unknown && |
| 2174 | !PID->getPropertyDecl()->isClassProperty()) || |
| 2175 | (QueryKind == ObjCPropertyQueryKind::OBJC_PR_query_class && |
| 2176 | PID->getPropertyDecl()->isClassProperty()) || |
| 2177 | (QueryKind == ObjCPropertyQueryKind::OBJC_PR_query_instance && |
| 2178 | !PID->getPropertyDecl()->isClassProperty())) |
| 2179 | return PID; |
| 2180 | |
| 2181 | if (PID->getPropertyDecl()->isClassProperty()) |
| 2182 | ClassPropImpl = PID; |
| 2183 | } |
| 2184 | |
| 2185 | if (QueryKind == ObjCPropertyQueryKind::OBJC_PR_query_unknown) |
| 2186 | |
| 2187 | return ClassPropImpl; |
| 2188 | |
| 2189 | return nullptr; |
| 2190 | } |
| 2191 | |
| 2192 | raw_ostream &clang::operator<<(raw_ostream &OS, |
| 2193 | const ObjCCategoryImplDecl &CID) { |
| 2194 | OS << CID.getName(); |
| 2195 | return OS; |
| 2196 | } |
| 2197 | |
| 2198 | |
| 2199 | |
| 2200 | |
| 2201 | |
| 2202 | void ObjCImplementationDecl::anchor() {} |
| 2203 | |
| 2204 | ObjCImplementationDecl * |
| 2205 | ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, |
| 2206 | ObjCInterfaceDecl *ClassInterface, |
| 2207 | ObjCInterfaceDecl *SuperDecl, |
| 2208 | SourceLocation nameLoc, |
| 2209 | SourceLocation atStartLoc, |
| 2210 | SourceLocation superLoc, |
| 2211 | SourceLocation IvarLBraceLoc, |
| 2212 | SourceLocation IvarRBraceLoc) { |
| 2213 | if (ClassInterface && ClassInterface->hasDefinition()) |
| 2214 | ClassInterface = ClassInterface->getDefinition(); |
| 2215 | return new (C, DC) ObjCImplementationDecl(DC, ClassInterface, SuperDecl, |
| 2216 | nameLoc, atStartLoc, superLoc, |
| 2217 | IvarLBraceLoc, IvarRBraceLoc); |
| 2218 | } |
| 2219 | |
| 2220 | ObjCImplementationDecl * |
| 2221 | ObjCImplementationDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 2222 | return new (C, ID) ObjCImplementationDecl(nullptr, nullptr, nullptr, |
| 2223 | SourceLocation(), SourceLocation()); |
| 2224 | } |
| 2225 | |
| 2226 | void ObjCImplementationDecl::setIvarInitializers(ASTContext &C, |
| 2227 | CXXCtorInitializer ** initializers, |
| 2228 | unsigned numInitializers) { |
| 2229 | if (numInitializers > 0) { |
| 2230 | NumIvarInitializers = numInitializers; |
| 2231 | auto **ivarInitializers = new (C) CXXCtorInitializer*[NumIvarInitializers]; |
| 2232 | memcpy(ivarInitializers, initializers, |
| 2233 | numInitializers * sizeof(CXXCtorInitializer*)); |
| 2234 | IvarInitializers = ivarInitializers; |
| 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | ObjCImplementationDecl::init_const_iterator |
| 2239 | ObjCImplementationDecl::init_begin() const { |
| 2240 | return IvarInitializers.get(getASTContext().getExternalSource()); |
| 2241 | } |
| 2242 | |
| 2243 | raw_ostream &clang::operator<<(raw_ostream &OS, |
| 2244 | const ObjCImplementationDecl &ID) { |
| 2245 | OS << ID.getName(); |
| 2246 | return OS; |
| 2247 | } |
| 2248 | |
| 2249 | |
| 2250 | |
| 2251 | |
| 2252 | |
| 2253 | void ObjCCompatibleAliasDecl::anchor() {} |
| 2254 | |
| 2255 | ObjCCompatibleAliasDecl * |
| 2256 | ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, |
| 2257 | SourceLocation L, |
| 2258 | IdentifierInfo *Id, |
| 2259 | ObjCInterfaceDecl* AliasedClass) { |
| 2260 | return new (C, DC) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); |
| 2261 | } |
| 2262 | |
| 2263 | ObjCCompatibleAliasDecl * |
| 2264 | ObjCCompatibleAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 2265 | return new (C, ID) ObjCCompatibleAliasDecl(nullptr, SourceLocation(), |
| 2266 | nullptr, nullptr); |
| 2267 | } |
| 2268 | |
| 2269 | |
| 2270 | |
| 2271 | |
| 2272 | |
| 2273 | void ObjCPropertyDecl::anchor() {} |
| 2274 | |
| 2275 | ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, |
| 2276 | SourceLocation L, |
| 2277 | IdentifierInfo *Id, |
| 2278 | SourceLocation AtLoc, |
| 2279 | SourceLocation LParenLoc, |
| 2280 | QualType T, |
| 2281 | TypeSourceInfo *TSI, |
| 2282 | PropertyControl propControl) { |
| 2283 | return new (C, DC) ObjCPropertyDecl(DC, L, Id, AtLoc, LParenLoc, T, TSI, |
| 2284 | propControl); |
| 2285 | } |
| 2286 | |
| 2287 | ObjCPropertyDecl *ObjCPropertyDecl::CreateDeserialized(ASTContext &C, |
| 2288 | unsigned ID) { |
| 2289 | return new (C, ID) ObjCPropertyDecl(nullptr, SourceLocation(), nullptr, |
| 2290 | SourceLocation(), SourceLocation(), |
| 2291 | QualType(), nullptr, None); |
| 2292 | } |
| 2293 | |
| 2294 | QualType ObjCPropertyDecl::getUsageType(QualType objectType) const { |
| 2295 | return DeclType.substObjCMemberType(objectType, getDeclContext(), |
| 2296 | ObjCSubstitutionContext::Property); |
| 2297 | } |
| 2298 | |
| 2299 | bool ObjCPropertyDecl::isDirectProperty() const { |
| 2300 | return (PropertyAttributes & ObjCPropertyAttribute::kind_direct) && |
| 2301 | !getASTContext().getLangOpts().ObjCDisableDirectMethodsForTesting; |
| 2302 | } |
| 2303 | |
| 2304 | |
| 2305 | |
| 2306 | |
| 2307 | |
| 2308 | ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, |
| 2309 | DeclContext *DC, |
| 2310 | SourceLocation atLoc, |
| 2311 | SourceLocation L, |
| 2312 | ObjCPropertyDecl *property, |
| 2313 | Kind PK, |
| 2314 | ObjCIvarDecl *ivar, |
| 2315 | SourceLocation ivarLoc) { |
| 2316 | return new (C, DC) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar, |
| 2317 | ivarLoc); |
| 2318 | } |
| 2319 | |
| 2320 | ObjCPropertyImplDecl *ObjCPropertyImplDecl::CreateDeserialized(ASTContext &C, |
| 2321 | unsigned ID) { |
| 2322 | return new (C, ID) ObjCPropertyImplDecl(nullptr, SourceLocation(), |
| 2323 | SourceLocation(), nullptr, Dynamic, |
| 2324 | nullptr, SourceLocation()); |
| 2325 | } |
| 2326 | |
| 2327 | SourceRange ObjCPropertyImplDecl::getSourceRange() const { |
| 2328 | SourceLocation EndLoc = getLocation(); |
| 2329 | if (IvarLoc.isValid()) |
| 2330 | EndLoc = IvarLoc; |
| 2331 | |
| 2332 | return SourceRange(AtLoc, EndLoc); |
| 2333 | } |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #ifndef LLVM_CLANG_AST_DECLOBJC_H |
| 14 | #define LLVM_CLANG_AST_DECLOBJC_H |
| 15 | |
| 16 | #include "clang/AST/Decl.h" |
| 17 | #include "clang/AST/DeclBase.h" |
| 18 | #include "clang/AST/DeclObjCCommon.h" |
| 19 | #include "clang/AST/ExternalASTSource.h" |
| 20 | #include "clang/AST/Redeclarable.h" |
| 21 | #include "clang/AST/SelectorLocationsKind.h" |
| 22 | #include "clang/AST/Type.h" |
| 23 | #include "clang/Basic/IdentifierTable.h" |
| 24 | #include "clang/Basic/LLVM.h" |
| 25 | #include "clang/Basic/SourceLocation.h" |
| 26 | #include "clang/Basic/Specifiers.h" |
| 27 | #include "llvm/ADT/ArrayRef.h" |
| 28 | #include "llvm/ADT/DenseMap.h" |
| 29 | #include "llvm/ADT/DenseSet.h" |
| 30 | #include "llvm/ADT/None.h" |
| 31 | #include "llvm/ADT/PointerIntPair.h" |
| 32 | #include "llvm/ADT/STLExtras.h" |
| 33 | #include "llvm/ADT/StringRef.h" |
| 34 | #include "llvm/ADT/iterator_range.h" |
| 35 | #include "llvm/Support/Compiler.h" |
| 36 | #include "llvm/Support/TrailingObjects.h" |
| 37 | #include <cassert> |
| 38 | #include <cstddef> |
| 39 | #include <cstdint> |
| 40 | #include <iterator> |
| 41 | #include <string> |
| 42 | #include <utility> |
| 43 | |
| 44 | namespace clang { |
| 45 | |
| 46 | class ASTContext; |
| 47 | class CompoundStmt; |
| 48 | class CXXCtorInitializer; |
| 49 | class Expr; |
| 50 | class ObjCCategoryDecl; |
| 51 | class ObjCCategoryImplDecl; |
| 52 | class ObjCImplementationDecl; |
| 53 | class ObjCInterfaceDecl; |
| 54 | class ObjCIvarDecl; |
| 55 | class ObjCPropertyDecl; |
| 56 | class ObjCPropertyImplDecl; |
| 57 | class ObjCProtocolDecl; |
| 58 | class Stmt; |
| 59 | |
| 60 | class ObjCListBase { |
| 61 | protected: |
| 62 | |
| 63 | void **List = nullptr; |
| 64 | unsigned NumElts = 0; |
| 65 | |
| 66 | public: |
| 67 | ObjCListBase() = default; |
| 68 | ObjCListBase(const ObjCListBase &) = delete; |
| 69 | ObjCListBase &operator=(const ObjCListBase &) = delete; |
| 70 | |
| 71 | unsigned size() const { return NumElts; } |
| 72 | bool empty() const { return NumElts == 0; } |
| 73 | |
| 74 | protected: |
| 75 | void set(void *const* InList, unsigned Elts, ASTContext &Ctx); |
| 76 | }; |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | template <typename T> |
| 83 | class ObjCList : public ObjCListBase { |
| 84 | public: |
| 85 | void set(T* const* InList, unsigned Elts, ASTContext &Ctx) { |
| 86 | ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts, Ctx); |
| 87 | } |
| 88 | |
| 89 | using iterator = T* const *; |
| 90 | |
| 91 | iterator begin() const { return (iterator)List; } |
| 92 | iterator end() const { return (iterator)List+NumElts; } |
| 93 | |
| 94 | T* operator[](unsigned Idx) const { |
| 95 | assert(Idx < NumElts && "Invalid access"); |
| 96 | return (T*)List[Idx]; |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | |
| 101 | |
| 102 | class ObjCProtocolList : public ObjCList<ObjCProtocolDecl> { |
| 103 | SourceLocation *Locations = nullptr; |
| 104 | |
| 105 | using ObjCList<ObjCProtocolDecl>::set; |
| 106 | |
| 107 | public: |
| 108 | ObjCProtocolList() = default; |
| 109 | |
| 110 | using loc_iterator = const SourceLocation *; |
| 111 | |
| 112 | loc_iterator loc_begin() const { return Locations; } |
| 113 | loc_iterator loc_end() const { return Locations + size(); } |
| 114 | |
| 115 | void set(ObjCProtocolDecl* const* InList, unsigned Elts, |
| 116 | const SourceLocation *Locs, ASTContext &Ctx); |
| 117 | }; |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | class ObjCMethodDecl : public NamedDecl, public DeclContext { |
| 140 | |
| 141 | |
| 142 | |
| 143 | public: |
| 144 | enum ImplementationControl { None, Required, Optional }; |
| 145 | |
| 146 | private: |
| 147 | |
| 148 | QualType MethodDeclType; |
| 149 | |
| 150 | |
| 151 | TypeSourceInfo *ReturnTInfo; |
| 152 | |
| 153 | |
| 154 | |
| 155 | void *ParamsAndSelLocs = nullptr; |
| 156 | unsigned NumParams = 0; |
| 157 | |
| 158 | |
| 159 | SourceLocation DeclEndLoc; |
| 160 | |
| 161 | |
| 162 | LazyDeclStmtPtr Body; |
| 163 | |
| 164 | |
| 165 | |
| 166 | ImplicitParamDecl *SelfDecl = nullptr; |
| 167 | |
| 168 | |
| 169 | |
| 170 | ImplicitParamDecl *CmdDecl = nullptr; |
| 171 | |
| 172 | ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc, |
| 173 | Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo, |
| 174 | DeclContext *contextDecl, bool isInstance = true, |
| 175 | bool isVariadic = false, bool isPropertyAccessor = false, |
| 176 | bool isSynthesizedAccessorStub = false, |
| 177 | bool isImplicitlyDeclared = false, bool isDefined = false, |
| 178 | ImplementationControl impControl = None, |
| 179 | bool HasRelatedResultType = false); |
| 180 | |
| 181 | SelectorLocationsKind getSelLocsKind() const { |
| 182 | return static_cast<SelectorLocationsKind>(ObjCMethodDeclBits.SelLocsKind); |
| 183 | } |
| 184 | |
| 185 | void setSelLocsKind(SelectorLocationsKind Kind) { |
| 186 | ObjCMethodDeclBits.SelLocsKind = Kind; |
| 187 | } |
| 188 | |
| 189 | bool hasStandardSelLocs() const { |
| 190 | return getSelLocsKind() != SelLoc_NonStandard; |
| 191 | } |
| 192 | |
| 193 | |
| 194 | |
| 195 | SourceLocation *getStoredSelLocs() { |
| 196 | return reinterpret_cast<SourceLocation *>(getParams() + NumParams); |
| 197 | } |
| 198 | const SourceLocation *getStoredSelLocs() const { |
| 199 | return reinterpret_cast<const SourceLocation *>(getParams() + NumParams); |
| 200 | } |
| 201 | |
| 202 | |
| 203 | |
| 204 | ParmVarDecl **getParams() { |
| 205 | return reinterpret_cast<ParmVarDecl **>(ParamsAndSelLocs); |
| 206 | } |
| 207 | const ParmVarDecl *const *getParams() const { |
| 208 | return reinterpret_cast<const ParmVarDecl *const *>(ParamsAndSelLocs); |
| 209 | } |
| 210 | |
| 211 | |
| 212 | |
| 213 | unsigned getNumStoredSelLocs() const { |
| 214 | if (hasStandardSelLocs()) |
| 215 | return 0; |
| 216 | return getNumSelectorLocs(); |
| 217 | } |
| 218 | |
| 219 | void setParamsAndSelLocs(ASTContext &C, |
| 220 | ArrayRef<ParmVarDecl*> Params, |
| 221 | ArrayRef<SourceLocation> SelLocs); |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | ObjCMethodDecl *getNextRedeclarationImpl() override; |
| 227 | |
| 228 | public: |
| 229 | friend class ASTDeclReader; |
| 230 | friend class ASTDeclWriter; |
| 231 | |
| 232 | static ObjCMethodDecl * |
| 233 | Create(ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc, |
| 234 | Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo, |
| 235 | DeclContext *contextDecl, bool isInstance = true, |
| 236 | bool isVariadic = false, bool isPropertyAccessor = false, |
| 237 | bool isSynthesizedAccessorStub = false, |
| 238 | bool isImplicitlyDeclared = false, bool isDefined = false, |
| 239 | ImplementationControl impControl = None, |
| 240 | bool HasRelatedResultType = false); |
| 241 | |
| 242 | static ObjCMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 243 | |
| 244 | ObjCMethodDecl *getCanonicalDecl() override; |
| 245 | const ObjCMethodDecl *getCanonicalDecl() const { |
| 246 | return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl(); |
| 247 | } |
| 248 | |
| 249 | ObjCDeclQualifier getObjCDeclQualifier() const { |
| 250 | return static_cast<ObjCDeclQualifier>(ObjCMethodDeclBits.objcDeclQualifier); |
| 251 | } |
| 252 | |
| 253 | void setObjCDeclQualifier(ObjCDeclQualifier QV) { |
| 254 | ObjCMethodDeclBits.objcDeclQualifier = QV; |
| 255 | } |
| 256 | |
| 257 | |
| 258 | |
| 259 | bool hasRelatedResultType() const { |
| 260 | return ObjCMethodDeclBits.RelatedResultType; |
| 261 | } |
| 262 | |
| 263 | |
| 264 | void setRelatedResultType(bool RRT = true) { |
| 265 | ObjCMethodDeclBits.RelatedResultType = RRT; |
| 266 | } |
| 267 | |
| 268 | |
| 269 | bool isRedeclaration() const { return ObjCMethodDeclBits.IsRedeclaration; } |
| 270 | void setIsRedeclaration(bool RD) { ObjCMethodDeclBits.IsRedeclaration = RD; } |
| 271 | void setAsRedeclaration(const ObjCMethodDecl *PrevMethod); |
| 272 | |
| 273 | |
| 274 | bool hasRedeclaration() const { return ObjCMethodDeclBits.HasRedeclaration; } |
| 275 | void setHasRedeclaration(bool HRD) const { |
| 276 | ObjCMethodDeclBits.HasRedeclaration = HRD; |
| 277 | } |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | SourceLocation getDeclaratorEndLoc() const { return DeclEndLoc; } |
| 283 | |
| 284 | |
| 285 | SourceLocation getBeginLoc() const LLVM_READONLY { return getLocation(); } |
| 286 | SourceLocation getEndLoc() const LLVM_READONLY; |
| 287 | SourceRange getSourceRange() const override LLVM_READONLY { |
| 288 | return SourceRange(getLocation(), getEndLoc()); |
| 289 | } |
| 290 | |
| 291 | SourceLocation getSelectorStartLoc() const { |
| 292 | if (isImplicit()) |
| 293 | return getBeginLoc(); |
| 294 | return getSelectorLoc(0); |
| 295 | } |
| 296 | |
| 297 | SourceLocation getSelectorLoc(unsigned Index) const { |
| 298 | assert(Index < getNumSelectorLocs() && "Index out of range!"); |
| 299 | if (hasStandardSelLocs()) |
| 300 | return getStandardSelectorLoc(Index, getSelector(), |
| 301 | getSelLocsKind() == SelLoc_StandardWithSpace, |
| 302 | parameters(), |
| 303 | DeclEndLoc); |
| 304 | return getStoredSelLocs()[Index]; |
| 305 | } |
| 306 | |
| 307 | void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const; |
| 308 | |
| 309 | unsigned getNumSelectorLocs() const { |
| 310 | if (isImplicit()) |
| 311 | return 0; |
| 312 | Selector Sel = getSelector(); |
| 313 | if (Sel.isUnarySelector()) |
| 314 | return 1; |
| 315 | return Sel.getNumArgs(); |
| 316 | } |
| 317 | |
| 318 | ObjCInterfaceDecl *getClassInterface(); |
| 319 | const ObjCInterfaceDecl *getClassInterface() const { |
| 320 | return const_cast<ObjCMethodDecl*>(this)->getClassInterface(); |
| 321 | } |
| 322 | |
| 323 | |
| 324 | |
| 325 | ObjCCategoryDecl *getCategory(); |
| 326 | const ObjCCategoryDecl *getCategory() const { |
| 327 | return const_cast<ObjCMethodDecl*>(this)->getCategory(); |
| 328 | } |
| 329 | |
| 330 | Selector getSelector() const { return getDeclName().getObjCSelector(); } |
| 331 | |
| 332 | QualType getReturnType() const { return MethodDeclType; } |
| 333 | void setReturnType(QualType T) { MethodDeclType = T; } |
| 334 | SourceRange getReturnTypeSourceRange() const; |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | QualType getSendResultType() const; |
| 341 | |
| 342 | |
| 343 | |
| 344 | QualType getSendResultType(QualType receiverType) const; |
| 345 | |
| 346 | TypeSourceInfo *getReturnTypeSourceInfo() const { return ReturnTInfo; } |
| 347 | void setReturnTypeSourceInfo(TypeSourceInfo *TInfo) { ReturnTInfo = TInfo; } |
| 348 | |
| 349 | |
| 350 | unsigned param_size() const { return NumParams; } |
| 351 | |
| 352 | using param_const_iterator = const ParmVarDecl *const *; |
| 353 | using param_iterator = ParmVarDecl *const *; |
| 354 | using param_range = llvm::iterator_range<param_iterator>; |
| 355 | using param_const_range = llvm::iterator_range<param_const_iterator>; |
| 356 | |
| 357 | param_const_iterator param_begin() const { |
| 358 | return param_const_iterator(getParams()); |
| 359 | } |
| 360 | |
| 361 | param_const_iterator param_end() const { |
| 362 | return param_const_iterator(getParams() + NumParams); |
| 363 | } |
| 364 | |
| 365 | param_iterator param_begin() { return param_iterator(getParams()); } |
| 366 | param_iterator param_end() { return param_iterator(getParams() + NumParams); } |
| 367 | |
| 368 | |
| 369 | |
| 370 | param_const_iterator sel_param_end() const { |
| 371 | return param_begin() + getSelector().getNumArgs(); |
| 372 | } |
| 373 | |
| 374 | |
| 375 | |
| 376 | ArrayRef<ParmVarDecl*> parameters() const { |
| 377 | return llvm::makeArrayRef(const_cast<ParmVarDecl**>(getParams()), |
| 378 | NumParams); |
| 379 | } |
| 380 | |
| 381 | ParmVarDecl *getParamDecl(unsigned Idx) { |
| 382 | assert(Idx < NumParams && "Index out of bounds!"); |
| 383 | return getParams()[Idx]; |
| 384 | } |
| 385 | const ParmVarDecl *getParamDecl(unsigned Idx) const { |
| 386 | return const_cast<ObjCMethodDecl *>(this)->getParamDecl(Idx); |
| 387 | } |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | void setMethodParams(ASTContext &C, |
| 393 | ArrayRef<ParmVarDecl*> Params, |
| 394 | ArrayRef<SourceLocation> SelLocs = llvm::None); |
| 395 | |
| 396 | |
| 397 | struct GetTypeFn { |
| 398 | QualType operator()(const ParmVarDecl *PD) const { return PD->getType(); } |
| 399 | }; |
| 400 | |
| 401 | using param_type_iterator = |
| 402 | llvm::mapped_iterator<param_const_iterator, GetTypeFn>; |
| 403 | |
| 404 | param_type_iterator param_type_begin() const { |
| 405 | return llvm::map_iterator(param_begin(), GetTypeFn()); |
| 406 | } |
| 407 | |
| 408 | param_type_iterator param_type_end() const { |
| 409 | return llvm::map_iterator(param_end(), GetTypeFn()); |
| 410 | } |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID); |
| 417 | |
| 418 | |
| 419 | |
| 420 | QualType getSelfType(ASTContext &Context, const ObjCInterfaceDecl *OID, |
| 421 | bool &selfIsPseudoStrong, bool &selfIsConsumed) const; |
| 422 | |
| 423 | ImplicitParamDecl * getSelfDecl() const { return SelfDecl; } |
| 424 | void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; } |
| 425 | ImplicitParamDecl * getCmdDecl() const { return CmdDecl; } |
| 426 | void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; } |
| 427 | |
| 428 | |
| 429 | ObjCMethodFamily getMethodFamily() const; |
| 430 | |
| 431 | bool isInstanceMethod() const { return ObjCMethodDeclBits.IsInstance; } |
| 432 | void setInstanceMethod(bool isInst) { |
| 433 | ObjCMethodDeclBits.IsInstance = isInst; |
| 434 | } |
| 435 | |
| 436 | bool isVariadic() const { return ObjCMethodDeclBits.IsVariadic; } |
| 437 | void setVariadic(bool isVar) { ObjCMethodDeclBits.IsVariadic = isVar; } |
| 438 | |
| 439 | bool isClassMethod() const { return !isInstanceMethod(); } |
| 440 | |
| 441 | bool isPropertyAccessor() const { |
| 442 | return ObjCMethodDeclBits.IsPropertyAccessor; |
| 443 | } |
| 444 | |
| 445 | void setPropertyAccessor(bool isAccessor) { |
| 446 | ObjCMethodDeclBits.IsPropertyAccessor = isAccessor; |
| 447 | } |
| 448 | |
| 449 | bool isSynthesizedAccessorStub() const { |
| 450 | return ObjCMethodDeclBits.IsSynthesizedAccessorStub; |
| 451 | } |
| 452 | |
| 453 | void setSynthesizedAccessorStub(bool isSynthesizedAccessorStub) { |
| 454 | ObjCMethodDeclBits.IsSynthesizedAccessorStub = isSynthesizedAccessorStub; |
| 455 | } |
| 456 | |
| 457 | bool isDefined() const { return ObjCMethodDeclBits.IsDefined; } |
| 458 | void setDefined(bool isDefined) { ObjCMethodDeclBits.IsDefined = isDefined; } |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | bool isOverriding() const { return ObjCMethodDeclBits.IsOverriding; } |
| 468 | void setOverriding(bool IsOver) { ObjCMethodDeclBits.IsOverriding = IsOver; } |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | void getOverriddenMethods( |
| 479 | SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const; |
| 480 | |
| 481 | |
| 482 | bool hasSkippedBody() const { return ObjCMethodDeclBits.HasSkippedBody; } |
| 483 | void setHasSkippedBody(bool Skipped = true) { |
| 484 | ObjCMethodDeclBits.HasSkippedBody = Skipped; |
| 485 | } |
| 486 | |
| 487 | |
| 488 | bool isDirectMethod() const; |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | |
| 495 | const ObjCPropertyDecl *findPropertyDecl(bool CheckOverrides = true) const; |
| 496 | |
| 497 | |
| 498 | void setDeclImplementation(ImplementationControl ic) { |
| 499 | ObjCMethodDeclBits.DeclImplementation = ic; |
| 500 | } |
| 501 | |
| 502 | ImplementationControl getImplementationControl() const { |
| 503 | return ImplementationControl(ObjCMethodDeclBits.DeclImplementation); |
| 504 | } |
| 505 | |
| 506 | bool isOptional() const { |
| 507 | return getImplementationControl() == Optional; |
| 508 | } |
| 509 | |
| 510 | |
| 511 | |
| 512 | bool isThisDeclarationADesignatedInitializer() const; |
| 513 | |
| 514 | |
| 515 | |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | bool isDesignatedInitializerForTheInterface( |
| 521 | const ObjCMethodDecl **InitMethod = nullptr) const; |
| 522 | |
| 523 | |
| 524 | bool hasBody() const override { return Body.isValid(); } |
| 525 | |
| 526 | |
| 527 | Stmt *getBody() const override; |
| 528 | |
| 529 | void setLazyBody(uint64_t Offset) { Body = Offset; } |
| 530 | |
| 531 | CompoundStmt *getCompoundBody() { return (CompoundStmt*)getBody(); } |
| 532 | void setBody(Stmt *B) { Body = B; } |
| 533 | |
| 534 | |
| 535 | bool isThisDeclarationADefinition() const { return hasBody(); } |
| 536 | |
| 537 | |
| 538 | bool definedInNSObject(const ASTContext &) const; |
| 539 | |
| 540 | |
| 541 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 542 | static bool classofKind(Kind K) { return K == ObjCMethod; } |
| 543 | |
| 544 | static DeclContext *castToDeclContext(const ObjCMethodDecl *D) { |
| 545 | return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D)); |
| 546 | } |
| 547 | |
| 548 | static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) { |
| 549 | return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC)); |
| 550 | } |
| 551 | }; |
| 552 | |
| 553 | |
| 554 | enum class ObjCTypeParamVariance : uint8_t { |
| 555 | |
| 556 | Invariant, |
| 557 | |
| 558 | |
| 559 | |
| 560 | Covariant, |
| 561 | |
| 562 | |
| 563 | |
| 564 | Contravariant, |
| 565 | }; |
| 566 | |
| 567 | |
| 568 | |
| 569 | |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | class ObjCTypeParamDecl : public TypedefNameDecl { |
| 580 | |
| 581 | unsigned Index : 14; |
| 582 | |
| 583 | |
| 584 | unsigned Variance : 2; |
| 585 | |
| 586 | |
| 587 | SourceLocation VarianceLoc; |
| 588 | |
| 589 | |
| 590 | |
| 591 | SourceLocation ColonLoc; |
| 592 | |
| 593 | ObjCTypeParamDecl(ASTContext &ctx, DeclContext *dc, |
| 594 | ObjCTypeParamVariance variance, SourceLocation varianceLoc, |
| 595 | unsigned index, |
| 596 | SourceLocation nameLoc, IdentifierInfo *name, |
| 597 | SourceLocation colonLoc, TypeSourceInfo *boundInfo) |
| 598 | : TypedefNameDecl(ObjCTypeParam, ctx, dc, nameLoc, nameLoc, name, |
| 599 | boundInfo), |
| 600 | Index(index), Variance(static_cast<unsigned>(variance)), |
| 601 | VarianceLoc(varianceLoc), ColonLoc(colonLoc) {} |
| 602 | |
| 603 | void anchor() override; |
| 604 | |
| 605 | public: |
| 606 | friend class ASTDeclReader; |
| 607 | friend class ASTDeclWriter; |
| 608 | |
| 609 | static ObjCTypeParamDecl *Create(ASTContext &ctx, DeclContext *dc, |
| 610 | ObjCTypeParamVariance variance, |
| 611 | SourceLocation varianceLoc, |
| 612 | unsigned index, |
| 613 | SourceLocation nameLoc, |
| 614 | IdentifierInfo *name, |
| 615 | SourceLocation colonLoc, |
| 616 | TypeSourceInfo *boundInfo); |
| 617 | static ObjCTypeParamDecl *CreateDeserialized(ASTContext &ctx, unsigned ID); |
| 618 | |
| 619 | SourceRange getSourceRange() const override LLVM_READONLY; |
| 620 | |
| 621 | |
| 622 | ObjCTypeParamVariance getVariance() const { |
| 623 | return static_cast<ObjCTypeParamVariance>(Variance); |
| 624 | } |
| 625 | |
| 626 | |
| 627 | void setVariance(ObjCTypeParamVariance variance) { |
| 628 | Variance = static_cast<unsigned>(variance); |
| 629 | } |
| 630 | |
| 631 | |
| 632 | SourceLocation getVarianceLoc() const { return VarianceLoc; } |
| 633 | |
| 634 | |
| 635 | unsigned getIndex() const { return Index; } |
| 636 | |
| 637 | |
| 638 | |
| 639 | bool hasExplicitBound() const { return ColonLoc.isValid(); } |
| 640 | |
| 641 | |
| 642 | |
| 643 | SourceLocation getColonLoc() const { return ColonLoc; } |
| 644 | |
| 645 | |
| 646 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 647 | static bool classofKind(Kind K) { return K == ObjCTypeParam; } |
| 648 | }; |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | |
| 655 | |
| 656 | |
| 657 | class ObjCTypeParamList final |
| 658 | : private llvm::TrailingObjects<ObjCTypeParamList, ObjCTypeParamDecl *> { |
| 659 | |
| 660 | SourceRange Brackets; |
| 661 | |
| 662 | unsigned NumParams; |
| 663 | |
| 664 | ObjCTypeParamList(SourceLocation lAngleLoc, |
| 665 | ArrayRef<ObjCTypeParamDecl *> typeParams, |
| 666 | SourceLocation rAngleLoc); |
| 667 | |
| 668 | public: |
| 669 | friend TrailingObjects; |
| 670 | |
| 671 | |
| 672 | static ObjCTypeParamList *create(ASTContext &ctx, |
| 673 | SourceLocation lAngleLoc, |
| 674 | ArrayRef<ObjCTypeParamDecl *> typeParams, |
| 675 | SourceLocation rAngleLoc); |
| 676 | |
| 677 | |
| 678 | using iterator = ObjCTypeParamDecl **; |
| 679 | |
| 680 | iterator begin() { return getTrailingObjects<ObjCTypeParamDecl *>(); } |
| 681 | |
| 682 | iterator end() { return begin() + size(); } |
| 683 | |
| 684 | |
| 685 | unsigned size() const { return NumParams; } |
| 686 | |
| 687 | |
| 688 | using const_iterator = ObjCTypeParamDecl * const *; |
| 689 | |
| 690 | const_iterator begin() const { |
| 691 | return getTrailingObjects<ObjCTypeParamDecl *>(); |
| 692 | } |
| 693 | |
| 694 | const_iterator end() const { |
| 695 | return begin() + size(); |
| 696 | } |
| 697 | |
| 698 | ObjCTypeParamDecl *front() const { |
| 699 | assert(size() > 0 && "empty Objective-C type parameter list"); |
| 700 | return *begin(); |
| 701 | } |
| 702 | |
| 703 | ObjCTypeParamDecl *back() const { |
| 704 | assert(size() > 0 && "empty Objective-C type parameter list"); |
| 705 | return *(end() - 1); |
| 706 | } |
| 707 | |
| 708 | SourceLocation getLAngleLoc() const { return Brackets.getBegin(); } |
| 709 | SourceLocation getRAngleLoc() const { return Brackets.getEnd(); } |
| 710 | SourceRange getSourceRange() const { return Brackets; } |
| 711 | |
| 712 | |
| 713 | |
| 714 | void gatherDefaultTypeArgs(SmallVectorImpl<QualType> &typeArgs) const; |
| 715 | }; |
| 716 | |
| 717 | enum class ObjCPropertyQueryKind : uint8_t { |
| 718 | OBJC_PR_query_unknown = 0x00, |
| 719 | OBJC_PR_query_instance, |
| 720 | OBJC_PR_query_class |
| 721 | }; |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | class ObjCPropertyDecl : public NamedDecl { |
| 730 | void anchor() override; |
| 731 | |
| 732 | public: |
| 733 | enum SetterKind { Assign, Retain, Copy, Weak }; |
| 734 | enum PropertyControl { None, Required, Optional }; |
| 735 | |
| 736 | private: |
| 737 | |
| 738 | SourceLocation AtLoc; |
| 739 | |
| 740 | |
| 741 | SourceLocation LParenLoc; |
| 742 | |
| 743 | QualType DeclType; |
| 744 | TypeSourceInfo *DeclTypeSourceInfo; |
| 745 | unsigned PropertyAttributes : NumObjCPropertyAttrsBits; |
| 746 | unsigned PropertyAttributesAsWritten : NumObjCPropertyAttrsBits; |
| 747 | |
| 748 | |
| 749 | unsigned PropertyImplementation : 2; |
| 750 | |
| 751 | |
| 752 | Selector GetterName; |
| 753 | |
| 754 | |
| 755 | Selector SetterName; |
| 756 | |
| 757 | |
| 758 | SourceLocation GetterNameLoc; |
| 759 | |
| 760 | |
| 761 | SourceLocation SetterNameLoc; |
| 762 | |
| 763 | |
| 764 | ObjCMethodDecl *GetterMethodDecl = nullptr; |
| 765 | |
| 766 | |
| 767 | ObjCMethodDecl *SetterMethodDecl = nullptr; |
| 768 | |
| 769 | |
| 770 | ObjCIvarDecl *PropertyIvarDecl = nullptr; |
| 771 | |
| 772 | ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, |
| 773 | SourceLocation AtLocation, SourceLocation LParenLocation, |
| 774 | QualType T, TypeSourceInfo *TSI, PropertyControl propControl) |
| 775 | : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation), |
| 776 | LParenLoc(LParenLocation), DeclType(T), DeclTypeSourceInfo(TSI), |
| 777 | PropertyAttributes(ObjCPropertyAttribute::kind_noattr), |
| 778 | PropertyAttributesAsWritten(ObjCPropertyAttribute::kind_noattr), |
| 779 | PropertyImplementation(propControl), GetterName(Selector()), |
| 780 | SetterName(Selector()) {} |
| 781 | |
| 782 | public: |
| 783 | static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC, |
| 784 | SourceLocation L, |
| 785 | IdentifierInfo *Id, SourceLocation AtLocation, |
| 786 | SourceLocation LParenLocation, |
| 787 | QualType T, |
| 788 | TypeSourceInfo *TSI, |
| 789 | PropertyControl propControl = None); |
| 790 | |
| 791 | static ObjCPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 792 | |
| 793 | SourceLocation getAtLoc() const { return AtLoc; } |
| 794 | void setAtLoc(SourceLocation L) { AtLoc = L; } |
| 795 | |
| 796 | SourceLocation getLParenLoc() const { return LParenLoc; } |
| 797 | void setLParenLoc(SourceLocation L) { LParenLoc = L; } |
| 798 | |
| 799 | TypeSourceInfo *getTypeSourceInfo() const { return DeclTypeSourceInfo; } |
| 800 | |
| 801 | QualType getType() const { return DeclType; } |
| 802 | |
| 803 | void setType(QualType T, TypeSourceInfo *TSI) { |
| 804 | DeclType = T; |
| 805 | DeclTypeSourceInfo = TSI; |
| 806 | } |
| 807 | |
| 808 | |
| 809 | |
| 810 | QualType getUsageType(QualType objectType) const; |
| 811 | |
| 812 | ObjCPropertyAttribute::Kind getPropertyAttributes() const { |
| 813 | return ObjCPropertyAttribute::Kind(PropertyAttributes); |
| 814 | } |
| 815 | |
| 816 | void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal) { |
| 817 | PropertyAttributes |= PRVal; |
| 818 | } |
| 819 | |
| 820 | void overwritePropertyAttributes(unsigned PRVal) { |
| 821 | PropertyAttributes = PRVal; |
| 822 | } |
| 823 | |
| 824 | ObjCPropertyAttribute::Kind getPropertyAttributesAsWritten() const { |
| 825 | return ObjCPropertyAttribute::Kind(PropertyAttributesAsWritten); |
| 826 | } |
| 827 | |
| 828 | void setPropertyAttributesAsWritten(ObjCPropertyAttribute::Kind PRVal) { |
| 829 | PropertyAttributesAsWritten = PRVal; |
| 830 | } |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | bool isReadOnly() const { |
| 836 | return (PropertyAttributes & ObjCPropertyAttribute::kind_readonly); |
| 837 | } |
| 838 | |
| 839 | |
| 840 | bool isAtomic() const { |
| 841 | return (PropertyAttributes & ObjCPropertyAttribute::kind_atomic); |
| 842 | } |
| 843 | |
| 844 | |
| 845 | bool isRetaining() const { |
| 846 | return (PropertyAttributes & (ObjCPropertyAttribute::kind_retain | |
| 847 | ObjCPropertyAttribute::kind_strong | |
| 848 | ObjCPropertyAttribute::kind_copy)); |
| 849 | } |
| 850 | |
| 851 | bool isInstanceProperty() const { return !isClassProperty(); } |
| 852 | bool isClassProperty() const { |
| 853 | return PropertyAttributes & ObjCPropertyAttribute::kind_class; |
| 854 | } |
| 855 | bool isDirectProperty() const; |
| 856 | |
| 857 | ObjCPropertyQueryKind getQueryKind() const { |
| 858 | return isClassProperty() ? ObjCPropertyQueryKind::OBJC_PR_query_class : |
| 859 | ObjCPropertyQueryKind::OBJC_PR_query_instance; |
| 860 | } |
| 861 | |
| 862 | static ObjCPropertyQueryKind getQueryKind(bool isClassProperty) { |
| 863 | return isClassProperty ? ObjCPropertyQueryKind::OBJC_PR_query_class : |
| 864 | ObjCPropertyQueryKind::OBJC_PR_query_instance; |
| 865 | } |
| 866 | |
| 867 | |
| 868 | |
| 869 | |
| 870 | SetterKind getSetterKind() const { |
| 871 | if (PropertyAttributes & ObjCPropertyAttribute::kind_strong) |
| 872 | return getType()->isBlockPointerType() ? Copy : Retain; |
| 873 | if (PropertyAttributes & ObjCPropertyAttribute::kind_retain) |
| 874 | return Retain; |
| 875 | if (PropertyAttributes & ObjCPropertyAttribute::kind_copy) |
| 876 | return Copy; |
| 877 | if (PropertyAttributes & ObjCPropertyAttribute::kind_weak) |
| 878 | return Weak; |
| 879 | return Assign; |
| 880 | } |
| 881 | |
| 882 | Selector getGetterName() const { return GetterName; } |
| 883 | SourceLocation getGetterNameLoc() const { return GetterNameLoc; } |
| 884 | |
| 885 | void setGetterName(Selector Sel, SourceLocation Loc = SourceLocation()) { |
| 886 | GetterName = Sel; |
| 887 | GetterNameLoc = Loc; |
| 888 | } |
| 889 | |
| 890 | Selector getSetterName() const { return SetterName; } |
| 891 | SourceLocation getSetterNameLoc() const { return SetterNameLoc; } |
| 892 | |
| 893 | void setSetterName(Selector Sel, SourceLocation Loc = SourceLocation()) { |
| 894 | SetterName = Sel; |
| 895 | SetterNameLoc = Loc; |
| 896 | } |
| 897 | |
| 898 | ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; } |
| 899 | void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; } |
| 900 | |
| 901 | ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; } |
| 902 | void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; } |
| 903 | |
| 904 | |
| 905 | void setPropertyImplementation(PropertyControl pc) { |
| 906 | PropertyImplementation = pc; |
| 907 | } |
| 908 | |
| 909 | PropertyControl getPropertyImplementation() const { |
| 910 | return PropertyControl(PropertyImplementation); |
| 911 | } |
| 912 | |
| 913 | bool isOptional() const { |
| 914 | return getPropertyImplementation() == PropertyControl::Optional; |
| 915 | } |
| 916 | |
| 917 | void setPropertyIvarDecl(ObjCIvarDecl *Ivar) { |
| 918 | PropertyIvarDecl = Ivar; |
| 919 | } |
| 920 | |
| 921 | ObjCIvarDecl *getPropertyIvarDecl() const { |
| 922 | return PropertyIvarDecl; |
| 923 | } |
| 924 | |
| 925 | SourceRange getSourceRange() const override LLVM_READONLY { |
| 926 | return SourceRange(AtLoc, getLocation()); |
| 927 | } |
| 928 | |
| 929 | |
| 930 | IdentifierInfo *getDefaultSynthIvarName(ASTContext &Ctx) const; |
| 931 | |
| 932 | |
| 933 | static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC, |
| 934 | const IdentifierInfo *propertyID, |
| 935 | ObjCPropertyQueryKind queryKind); |
| 936 | |
| 937 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 938 | static bool classofKind(Kind K) { return K == ObjCProperty; } |
| 939 | }; |
| 940 | |
| 941 | |
| 942 | |
| 943 | |
| 944 | |
| 945 | class ObjCContainerDecl : public NamedDecl, public DeclContext { |
| 946 | |
| 947 | |
| 948 | |
| 949 | |
| 950 | |
| 951 | SourceRange AtEnd; |
| 952 | |
| 953 | void anchor() override; |
| 954 | |
| 955 | public: |
| 956 | ObjCContainerDecl(Kind DK, DeclContext *DC, IdentifierInfo *Id, |
| 957 | SourceLocation nameLoc, SourceLocation atStartLoc); |
| 958 | |
| 959 | |
| 960 | using prop_iterator = specific_decl_iterator<ObjCPropertyDecl>; |
| 961 | using prop_range = |
| 962 | llvm::iterator_range<specific_decl_iterator<ObjCPropertyDecl>>; |
| 963 | |
| 964 | prop_range properties() const { return prop_range(prop_begin(), prop_end()); } |
| 965 | |
| 966 | prop_iterator prop_begin() const { |
| 967 | return prop_iterator(decls_begin()); |
| 968 | } |
| 969 | |
| 970 | prop_iterator prop_end() const { |
| 971 | return prop_iterator(decls_end()); |
| 972 | } |
| 973 | |
| 974 | using instprop_iterator = |
| 975 | filtered_decl_iterator<ObjCPropertyDecl, |
| 976 | &ObjCPropertyDecl::isInstanceProperty>; |
| 977 | using instprop_range = llvm::iterator_range<instprop_iterator>; |
| 978 | |
| 979 | instprop_range instance_properties() const { |
| 980 | return instprop_range(instprop_begin(), instprop_end()); |
| 981 | } |
| 982 | |
| 983 | instprop_iterator instprop_begin() const { |
| 984 | return instprop_iterator(decls_begin()); |
| 985 | } |
| 986 | |
| 987 | instprop_iterator instprop_end() const { |
| 988 | return instprop_iterator(decls_end()); |
| 989 | } |
| 990 | |
| 991 | using classprop_iterator = |
| 992 | filtered_decl_iterator<ObjCPropertyDecl, |
| 993 | &ObjCPropertyDecl::isClassProperty>; |
| 994 | using classprop_range = llvm::iterator_range<classprop_iterator>; |
| 995 | |
| 996 | classprop_range class_properties() const { |
| 997 | return classprop_range(classprop_begin(), classprop_end()); |
| 998 | } |
| 999 | |
| 1000 | classprop_iterator classprop_begin() const { |
| 1001 | return classprop_iterator(decls_begin()); |
| 1002 | } |
| 1003 | |
| 1004 | classprop_iterator classprop_end() const { |
| 1005 | return classprop_iterator(decls_end()); |
| 1006 | } |
| 1007 | |
| 1008 | |
| 1009 | using method_iterator = specific_decl_iterator<ObjCMethodDecl>; |
| 1010 | using method_range = |
| 1011 | llvm::iterator_range<specific_decl_iterator<ObjCMethodDecl>>; |
| 1012 | |
| 1013 | method_range methods() const { |
| 1014 | return method_range(meth_begin(), meth_end()); |
| 1015 | } |
| 1016 | |
| 1017 | method_iterator meth_begin() const { |
| 1018 | return method_iterator(decls_begin()); |
| 1019 | } |
| 1020 | |
| 1021 | method_iterator meth_end() const { |
| 1022 | return method_iterator(decls_end()); |
| 1023 | } |
| 1024 | |
| 1025 | using instmeth_iterator = |
| 1026 | filtered_decl_iterator<ObjCMethodDecl, |
| 1027 | &ObjCMethodDecl::isInstanceMethod>; |
| 1028 | using instmeth_range = llvm::iterator_range<instmeth_iterator>; |
| 1029 | |
| 1030 | instmeth_range instance_methods() const { |
| 1031 | return instmeth_range(instmeth_begin(), instmeth_end()); |
| 1032 | } |
| 1033 | |
| 1034 | instmeth_iterator instmeth_begin() const { |
| 1035 | return instmeth_iterator(decls_begin()); |
| 1036 | } |
| 1037 | |
| 1038 | instmeth_iterator instmeth_end() const { |
| 1039 | return instmeth_iterator(decls_end()); |
| 1040 | } |
| 1041 | |
| 1042 | using classmeth_iterator = |
| 1043 | filtered_decl_iterator<ObjCMethodDecl, |
| 1044 | &ObjCMethodDecl::isClassMethod>; |
| 1045 | using classmeth_range = llvm::iterator_range<classmeth_iterator>; |
| 1046 | |
| 1047 | classmeth_range class_methods() const { |
| 1048 | return classmeth_range(classmeth_begin(), classmeth_end()); |
| 1049 | } |
| 1050 | |
| 1051 | classmeth_iterator classmeth_begin() const { |
| 1052 | return classmeth_iterator(decls_begin()); |
| 1053 | } |
| 1054 | |
| 1055 | classmeth_iterator classmeth_end() const { |
| 1056 | return classmeth_iterator(decls_end()); |
| 1057 | } |
| 1058 | |
| 1059 | |
| 1060 | ObjCMethodDecl *getMethod(Selector Sel, bool isInstance, |
| 1061 | bool AllowHidden = false) const; |
| 1062 | |
| 1063 | ObjCMethodDecl *getInstanceMethod(Selector Sel, |
| 1064 | bool AllowHidden = false) const { |
| 1065 | return getMethod(Sel, true, AllowHidden); |
| 1066 | } |
| 1067 | |
| 1068 | ObjCMethodDecl *getClassMethod(Selector Sel, bool AllowHidden = false) const { |
| 1069 | return getMethod(Sel, false, AllowHidden); |
| 1070 | } |
| 1071 | |
| 1072 | bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const; |
| 1073 | ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const; |
| 1074 | |
| 1075 | ObjCPropertyDecl * |
| 1076 | FindPropertyDeclaration(const IdentifierInfo *PropertyId, |
| 1077 | ObjCPropertyQueryKind QueryKind) const; |
| 1078 | |
| 1079 | using PropertyMap = |
| 1080 | llvm::DenseMap<std::pair<IdentifierInfo *, unsigned>, |
| 1081 | ObjCPropertyDecl *>; |
| 1082 | using ProtocolPropertySet = llvm::SmallDenseSet<const ObjCProtocolDecl *, 8>; |
| 1083 | using PropertyDeclOrder = llvm::SmallVector<ObjCPropertyDecl *, 8>; |
| 1084 | |
| 1085 | |
| 1086 | |
| 1087 | |
| 1088 | virtual void collectPropertiesToImplement(PropertyMap &PM, |
| 1089 | PropertyDeclOrder &PO) const {} |
| 1090 | |
| 1091 | SourceLocation getAtStartLoc() const { return ObjCContainerDeclBits.AtStart; } |
| 1092 | |
| 1093 | void setAtStartLoc(SourceLocation Loc) { |
| 1094 | ObjCContainerDeclBits.AtStart = Loc; |
| 1095 | } |
| 1096 | |
| 1097 | |
| 1098 | SourceRange getAtEndRange() const { return AtEnd; } |
| 1099 | |
| 1100 | void setAtEndRange(SourceRange atEnd) { AtEnd = atEnd; } |
| 1101 | |
| 1102 | SourceRange getSourceRange() const override LLVM_READONLY { |
| 1103 | return SourceRange(getAtStartLoc(), getAtEndRange().getEnd()); |
| 1104 | } |
| 1105 | |
| 1106 | |
| 1107 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 1108 | |
| 1109 | static bool classofKind(Kind K) { |
| 1110 | return K >= firstObjCContainer && |
| 1111 | K <= lastObjCContainer; |
| 1112 | } |
| 1113 | |
| 1114 | static DeclContext *castToDeclContext(const ObjCContainerDecl *D) { |
| 1115 | return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D)); |
| 1116 | } |
| 1117 | |
| 1118 | static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) { |
| 1119 | return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC)); |
| 1120 | } |
| 1121 | }; |
| 1122 | |
| 1123 | |
| 1124 | |
| 1125 | |
| 1126 | |
| 1127 | |
| 1128 | |
| 1129 | |
| 1130 | |
| 1131 | |
| 1132 | |
| 1133 | |
| 1134 | |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | |
| 1142 | |
| 1143 | |
| 1144 | |
| 1145 | |
| 1146 | |
| 1147 | |
| 1148 | class ObjCInterfaceDecl : public ObjCContainerDecl |
| 1149 | , public Redeclarable<ObjCInterfaceDecl> { |
| 1150 | friend class ASTContext; |
| 1151 | |
| 1152 | |
| 1153 | |
| 1154 | mutable const Type *TypeForDecl = nullptr; |
| 1155 | |
| 1156 | struct DefinitionData { |
| 1157 | |
| 1158 | |
| 1159 | ObjCInterfaceDecl *Definition = nullptr; |
| 1160 | |
| 1161 | |
| 1162 | TypeSourceInfo *SuperClassTInfo = nullptr; |
| 1163 | |
| 1164 | |
| 1165 | ObjCProtocolList ReferencedProtocols; |
| 1166 | |
| 1167 | |
| 1168 | ObjCList<ObjCProtocolDecl> AllReferencedProtocols; |
| 1169 | |
| 1170 | |
| 1171 | |
| 1172 | |
| 1173 | |
| 1174 | |
| 1175 | ObjCCategoryDecl *CategoryList = nullptr; |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | ObjCIvarDecl *IvarList = nullptr; |
| 1180 | |
| 1181 | |
| 1182 | |
| 1183 | mutable unsigned ExternallyCompleted : 1; |
| 1184 | |
| 1185 | |
| 1186 | |
| 1187 | mutable unsigned IvarListMissingImplementation : 1; |
| 1188 | |
| 1189 | |
| 1190 | |
| 1191 | unsigned HasDesignatedInitializers : 1; |
| 1192 | |
| 1193 | enum InheritedDesignatedInitializersState { |
| 1194 | |
| 1195 | |
| 1196 | IDI_Unknown = 0, |
| 1197 | |
| 1198 | |
| 1199 | IDI_Inherited = 1, |
| 1200 | |
| 1201 | |
| 1202 | IDI_NotInherited = 2 |
| 1203 | }; |
| 1204 | |
| 1205 | |
| 1206 | mutable unsigned InheritedDesignatedInitializers : 2; |
| 1207 | |
| 1208 | |
| 1209 | |
| 1210 | |
| 1211 | SourceLocation EndLoc; |
| 1212 | |
| 1213 | DefinitionData() |
| 1214 | : ExternallyCompleted(false), IvarListMissingImplementation(true), |
| 1215 | HasDesignatedInitializers(false), |
| 1216 | InheritedDesignatedInitializers(IDI_Unknown) {} |
| 1217 | }; |
| 1218 | |
| 1219 | |
| 1220 | ObjCTypeParamList *TypeParamList = nullptr; |
| 1221 | |
| 1222 | |
| 1223 | |
| 1224 | |
| 1225 | |
| 1226 | |
| 1227 | llvm::PointerIntPair<DefinitionData *, 1, bool> Data; |
| 1228 | |
| 1229 | ObjCInterfaceDecl(const ASTContext &C, DeclContext *DC, SourceLocation AtLoc, |
| 1230 | IdentifierInfo *Id, ObjCTypeParamList *typeParamList, |
| 1231 | SourceLocation CLoc, ObjCInterfaceDecl *PrevDecl, |
| 1232 | bool IsInternal); |
| 1233 | |
| 1234 | void anchor() override; |
| 1235 | |
| 1236 | void LoadExternalDefinition() const; |
| 1237 | |
| 1238 | DefinitionData &data() const { |
| 1239 | assert(Data.getPointer() && "Declaration has no definition!"); |
| 1240 | return *Data.getPointer(); |
| 1241 | } |
| 1242 | |
| 1243 | |
| 1244 | void allocateDefinitionData(); |
| 1245 | |
| 1246 | using redeclarable_base = Redeclarable<ObjCInterfaceDecl>; |
| 1247 | |
| 1248 | ObjCInterfaceDecl *getNextRedeclarationImpl() override { |
| 1249 | return getNextRedeclaration(); |
| 1250 | } |
| 1251 | |
| 1252 | ObjCInterfaceDecl *getPreviousDeclImpl() override { |
| 1253 | return getPreviousDecl(); |
| 1254 | } |
| 1255 | |
| 1256 | ObjCInterfaceDecl *getMostRecentDeclImpl() override { |
| 1257 | return getMostRecentDecl(); |
| 1258 | } |
| 1259 | |
| 1260 | public: |
| 1261 | static ObjCInterfaceDecl *Create(const ASTContext &C, DeclContext *DC, |
| 1262 | SourceLocation atLoc, |
| 1263 | IdentifierInfo *Id, |
| 1264 | ObjCTypeParamList *typeParamList, |
| 1265 | ObjCInterfaceDecl *PrevDecl, |
| 1266 | SourceLocation ClassLoc = SourceLocation(), |
| 1267 | bool isInternal = false); |
| 1268 | |
| 1269 | static ObjCInterfaceDecl *CreateDeserialized(const ASTContext &C, unsigned ID); |
| 1270 | |
| 1271 | |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | |
| 1276 | |
| 1277 | ObjCTypeParamList *getTypeParamList() const; |
| 1278 | |
| 1279 | |
| 1280 | |
| 1281 | |
| 1282 | |
| 1283 | void setTypeParamList(ObjCTypeParamList *TPL); |
| 1284 | |
| 1285 | |
| 1286 | |
| 1287 | ObjCTypeParamList *getTypeParamListAsWritten() const { |
| 1288 | return TypeParamList; |
| 1289 | } |
| 1290 | |
| 1291 | SourceRange getSourceRange() const override LLVM_READONLY { |
| 1292 | if (isThisDeclarationADefinition()) |
| 1293 | return ObjCContainerDecl::getSourceRange(); |
| 1294 | |
| 1295 | return SourceRange(getAtStartLoc(), getLocation()); |
| 1296 | } |
| 1297 | |
| 1298 | |
| 1299 | |
| 1300 | |
| 1301 | void setExternallyCompleted(); |
| 1302 | |
| 1303 | |
| 1304 | |
| 1305 | void setHasDesignatedInitializers(); |
| 1306 | |
| 1307 | |
| 1308 | |
| 1309 | bool hasDesignatedInitializers() const; |
| 1310 | |
| 1311 | |
| 1312 | |
| 1313 | bool declaresOrInheritsDesignatedInitializers() const { |
| 1314 | return hasDesignatedInitializers() || inheritsDesignatedInitializers(); |
| 1315 | } |
| 1316 | |
| 1317 | const ObjCProtocolList &getReferencedProtocols() const { |
| 1318 | assert(hasDefinition() && "Caller did not check for forward reference!"); |
| 1319 | if (data().ExternallyCompleted) |
| 1320 | LoadExternalDefinition(); |
| 1321 | |
| 1322 | return data().ReferencedProtocols; |
| 1323 | } |
| 1324 | |
| 1325 | ObjCImplementationDecl *getImplementation() const; |
| 1326 | void setImplementation(ObjCImplementationDecl *ImplD); |
| 1327 | |
| 1328 | ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const; |
| 1329 | |
| 1330 | |
| 1331 | ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const; |
| 1332 | ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const; |
| 1333 | |
| 1334 | ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const { |
| 1335 | return isInstance ? getCategoryInstanceMethod(Sel) |
| 1336 | : getCategoryClassMethod(Sel); |
| 1337 | } |
| 1338 | |
| 1339 | using protocol_iterator = ObjCProtocolList::iterator; |
| 1340 | using protocol_range = llvm::iterator_range<protocol_iterator>; |
| 1341 | |
| 1342 | protocol_range protocols() const { |
| 1343 | return protocol_range(protocol_begin(), protocol_end()); |
| 1344 | } |
| 1345 | |
| 1346 | protocol_iterator protocol_begin() const { |
| 1347 | |
| 1348 | if (!hasDefinition()) |
| 1349 | return protocol_iterator(); |
| 1350 | |
| 1351 | if (data().ExternallyCompleted) |
| 1352 | LoadExternalDefinition(); |
| 1353 | |
| 1354 | return data().ReferencedProtocols.begin(); |
| 1355 | } |
| 1356 | |
| 1357 | protocol_iterator protocol_end() const { |
| 1358 | |
| 1359 | if (!hasDefinition()) |
| 1360 | return protocol_iterator(); |
| 1361 | |
| 1362 | if (data().ExternallyCompleted) |
| 1363 | LoadExternalDefinition(); |
| 1364 | |
| 1365 | return data().ReferencedProtocols.end(); |
| 1366 | } |
| 1367 | |
| 1368 | using protocol_loc_iterator = ObjCProtocolList::loc_iterator; |
| 1369 | using protocol_loc_range = llvm::iterator_range<protocol_loc_iterator>; |
| 1370 | |
| 1371 | protocol_loc_range protocol_locs() const { |
| 1372 | return protocol_loc_range(protocol_loc_begin(), protocol_loc_end()); |
| 1373 | } |
| 1374 | |
| 1375 | protocol_loc_iterator protocol_loc_begin() const { |
| 1376 | |
| 1377 | if (!hasDefinition()) |
| 1378 | return protocol_loc_iterator(); |
| 1379 | |
| 1380 | if (data().ExternallyCompleted) |
| 1381 | LoadExternalDefinition(); |
| 1382 | |
| 1383 | return data().ReferencedProtocols.loc_begin(); |
| 1384 | } |
| 1385 | |
| 1386 | protocol_loc_iterator protocol_loc_end() const { |
| 1387 | |
| 1388 | if (!hasDefinition()) |
| 1389 | return protocol_loc_iterator(); |
| 1390 | |
| 1391 | if (data().ExternallyCompleted) |
| 1392 | LoadExternalDefinition(); |
| 1393 | |
| 1394 | return data().ReferencedProtocols.loc_end(); |
| 1395 | } |
| 1396 | |
| 1397 | using all_protocol_iterator = ObjCList<ObjCProtocolDecl>::iterator; |
| 1398 | using all_protocol_range = llvm::iterator_range<all_protocol_iterator>; |
| 1399 | |
| 1400 | all_protocol_range all_referenced_protocols() const { |
| 1401 | return all_protocol_range(all_referenced_protocol_begin(), |
| 1402 | all_referenced_protocol_end()); |
| 1403 | } |
| 1404 | |
| 1405 | all_protocol_iterator all_referenced_protocol_begin() const { |
| 1406 | |
| 1407 | if (!hasDefinition()) |
| 1408 | return all_protocol_iterator(); |
| 1409 | |
| 1410 | if (data().ExternallyCompleted) |
| 1411 | LoadExternalDefinition(); |
| 1412 | |
| 1413 | return data().AllReferencedProtocols.empty() |
| 1414 | ? protocol_begin() |
| 1415 | : data().AllReferencedProtocols.begin(); |
| 1416 | } |
| 1417 | |
| 1418 | all_protocol_iterator all_referenced_protocol_end() const { |
| 1419 | |
| 1420 | if (!hasDefinition()) |
| 1421 | return all_protocol_iterator(); |
| 1422 | |
| 1423 | if (data().ExternallyCompleted) |
| 1424 | LoadExternalDefinition(); |
| 1425 | |
| 1426 | return data().AllReferencedProtocols.empty() |
| 1427 | ? protocol_end() |
| 1428 | : data().AllReferencedProtocols.end(); |
| 1429 | } |
| 1430 | |
| 1431 | using ivar_iterator = specific_decl_iterator<ObjCIvarDecl>; |
| 1432 | using ivar_range = llvm::iterator_range<specific_decl_iterator<ObjCIvarDecl>>; |
| 1433 | |
| 1434 | ivar_range ivars() const { return ivar_range(ivar_begin(), ivar_end()); } |
| 1435 | |
| 1436 | ivar_iterator ivar_begin() const { |
| 1437 | if (const ObjCInterfaceDecl *Def = getDefinition()) |
| 1438 | return ivar_iterator(Def->decls_begin()); |
| 1439 | |
| 1440 | |
| 1441 | return ivar_iterator(); |
| 1442 | } |
| 1443 | |
| 1444 | ivar_iterator ivar_end() const { |
| 1445 | if (const ObjCInterfaceDecl *Def = getDefinition()) |
| 1446 | return ivar_iterator(Def->decls_end()); |
| 1447 | |
| 1448 | |
| 1449 | return ivar_iterator(); |
| 1450 | } |
| 1451 | |
| 1452 | unsigned ivar_size() const { |
| 1453 | return std::distance(ivar_begin(), ivar_end()); |
| 1454 | } |
| 1455 | |
| 1456 | bool ivar_empty() const { return ivar_begin() == ivar_end(); } |
| 1457 | |
| 1458 | ObjCIvarDecl *all_declared_ivar_begin(); |
| 1459 | const ObjCIvarDecl *all_declared_ivar_begin() const { |
| 1460 | |
| 1461 | |
| 1462 | return const_cast<ObjCInterfaceDecl *>(this)->all_declared_ivar_begin(); |
| 1463 | } |
| 1464 | void setIvarList(ObjCIvarDecl *ivar) { data().IvarList = ivar; } |
| 1465 | |
| 1466 | |
| 1467 | |
| 1468 | void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num, |
| 1469 | const SourceLocation *Locs, ASTContext &C) { |
| 1470 | data().ReferencedProtocols.set(List, Num, Locs, C); |
| 1471 | } |
| 1472 | |
| 1473 | |
| 1474 | |
| 1475 | void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List, |
| 1476 | unsigned Num, |
| 1477 | ASTContext &C); |
| 1478 | |
| 1479 | |
| 1480 | |
| 1481 | StringRef getObjCRuntimeNameAsString() const; |
| 1482 | |
| 1483 | |
| 1484 | |
| 1485 | |
| 1486 | |
| 1487 | |
| 1488 | void getDesignatedInitializers( |
| 1489 | llvm::SmallVectorImpl<const ObjCMethodDecl *> &Methods) const; |
| 1490 | |
| 1491 | |
| 1492 | |
| 1493 | |
| 1494 | |
| 1495 | |
| 1496 | |
| 1497 | |
| 1498 | |
| 1499 | |
| 1500 | bool |
| 1501 | isDesignatedInitializer(Selector Sel, |
| 1502 | const ObjCMethodDecl **InitMethod = nullptr) const; |
| 1503 | |
| 1504 | |
| 1505 | |
| 1506 | bool isThisDeclarationADefinition() const { |
| 1507 | return getDefinition() == this; |
| 1508 | } |
| 1509 | |
| 1510 | |
| 1511 | bool hasDefinition() const { |
| 1512 | |
| 1513 | |
| 1514 | |
| 1515 | |
| 1516 | if (!Data.getOpaqueValue()) |
| 2 | | Assuming the condition is false | |
|
| |
| 1517 | getMostRecentDecl(); |
| 1518 | |
| 1519 | return Data.getPointer(); |
| 4 | | Returning value, which participates in a condition later | |
|
| 1520 | } |
| 1521 | |
| 1522 | |
| 1523 | |
| 1524 | |
| 1525 | ObjCInterfaceDecl *getDefinition() { |
| 1526 | return hasDefinition()? Data.getPointer()->Definition : nullptr; |
| 1527 | } |
| 1528 | |
| 1529 | |
| 1530 | |
| 1531 | |
| 1532 | const ObjCInterfaceDecl *getDefinition() const { |
| 1533 | return hasDefinition()? Data.getPointer()->Definition : nullptr; |
| 15 | | Assuming the condition is true | |
|
| |
| 17 | | Returning pointer, which participates in a condition later | |
|
| 1534 | } |
| 1535 | |
| 1536 | |
| 1537 | |
| 1538 | void startDefinition(); |
| 1539 | |
| 1540 | |
| 1541 | const ObjCObjectType *getSuperClassType() const { |
| 1542 | if (TypeSourceInfo *TInfo = getSuperClassTInfo()) |
| 1543 | return TInfo->getType()->castAs<ObjCObjectType>(); |
| 1544 | |
| 1545 | return nullptr; |
| 1546 | } |
| 1547 | |
| 1548 | |
| 1549 | TypeSourceInfo *getSuperClassTInfo() const { |
| 1550 | |
| 1551 | if (!hasDefinition()) |
| 1552 | return nullptr; |
| 1553 | |
| 1554 | if (data().ExternallyCompleted) |
| 1555 | LoadExternalDefinition(); |
| 1556 | |
| 1557 | return data().SuperClassTInfo; |
| 1558 | } |
| 1559 | |
| 1560 | |
| 1561 | |
| 1562 | ObjCInterfaceDecl *getSuperClass() const; |
| 1563 | |
| 1564 | void setSuperClass(TypeSourceInfo *superClass) { |
| 1565 | data().SuperClassTInfo = superClass; |
| 1566 | } |
| 1567 | |
| 1568 | |
| 1569 | |
| 1570 | |
| 1571 | |
| 1572 | |
| 1573 | template<bool (*Filter)(ObjCCategoryDecl *)> |
| 1574 | class filtered_category_iterator { |
| 1575 | ObjCCategoryDecl *Current = nullptr; |
| 1576 | |
| 1577 | void findAcceptableCategory(); |
| 1578 | |
| 1579 | public: |
| 1580 | using value_type = ObjCCategoryDecl *; |
| 1581 | using reference = value_type; |
| 1582 | using pointer = value_type; |
| 1583 | using difference_type = std::ptrdiff_t; |
| 1584 | using iterator_category = std::input_iterator_tag; |
| 1585 | |
| 1586 | filtered_category_iterator() = default; |
| 1587 | explicit filtered_category_iterator(ObjCCategoryDecl *Current) |
| 1588 | : Current(Current) { |
| 1589 | findAcceptableCategory(); |
| 1590 | } |
| 1591 | |
| 1592 | reference operator*() const { return Current; } |
| 1593 | pointer operator->() const { return Current; } |
| 1594 | |
| 1595 | filtered_category_iterator &operator++(); |
| 1596 | |
| 1597 | filtered_category_iterator operator++(int) { |
| 1598 | filtered_category_iterator Tmp = *this; |
| 1599 | ++(*this); |
| 1600 | return Tmp; |
| 1601 | } |
| 1602 | |
| 1603 | friend bool operator==(filtered_category_iterator X, |
| 1604 | filtered_category_iterator Y) { |
| 1605 | return X.Current == Y.Current; |
| 1606 | } |
| 1607 | |
| 1608 | friend bool operator!=(filtered_category_iterator X, |
| 1609 | filtered_category_iterator Y) { |
| 1610 | return X.Current != Y.Current; |
| 1611 | } |
| 1612 | }; |
| 1613 | |
| 1614 | private: |
| 1615 | |
| 1616 | |
| 1617 | |
| 1618 | static bool isVisibleCategory(ObjCCategoryDecl *Cat); |
| 1619 | |
| 1620 | public: |
| 1621 | |
| 1622 | |
| 1623 | using visible_categories_iterator = |
| 1624 | filtered_category_iterator<isVisibleCategory>; |
| 1625 | |
| 1626 | using visible_categories_range = |
| 1627 | llvm::iterator_range<visible_categories_iterator>; |
| 1628 | |
| 1629 | visible_categories_range visible_categories() const { |
| 1630 | return visible_categories_range(visible_categories_begin(), |
| 1631 | visible_categories_end()); |
| 1632 | } |
| 1633 | |
| 1634 | |
| 1635 | |
| 1636 | visible_categories_iterator visible_categories_begin() const { |
| 1637 | return visible_categories_iterator(getCategoryListRaw()); |
| 1638 | } |
| 1639 | |
| 1640 | |
| 1641 | visible_categories_iterator visible_categories_end() const { |
| 1642 | return visible_categories_iterator(); |
| 1643 | } |
| 1644 | |
| 1645 | |
| 1646 | bool visible_categories_empty() const { |
| 1647 | return visible_categories_begin() == visible_categories_end(); |
| 1648 | } |
| 1649 | |
| 1650 | private: |
| 1651 | |
| 1652 | |
| 1653 | |
| 1654 | static bool isKnownCategory(ObjCCategoryDecl *) { return true; } |
| 1655 | |
| 1656 | public: |
| 1657 | |
| 1658 | |
| 1659 | using known_categories_iterator = filtered_category_iterator<isKnownCategory>; |
| 1660 | using known_categories_range = |
| 1661 | llvm::iterator_range<known_categories_iterator>; |
| 1662 | |
| 1663 | known_categories_range known_categories() const { |
| 1664 | return known_categories_range(known_categories_begin(), |
| 1665 | known_categories_end()); |
| 1666 | } |
| 1667 | |
| 1668 | |
| 1669 | |
| 1670 | known_categories_iterator known_categories_begin() const { |
| 1671 | return known_categories_iterator(getCategoryListRaw()); |
| 1672 | } |
| 1673 | |
| 1674 | |
| 1675 | known_categories_iterator known_categories_end() const { |
| 1676 | return known_categories_iterator(); |
| 1677 | } |
| 1678 | |
| 1679 | |
| 1680 | bool known_categories_empty() const { |
| 1681 | return known_categories_begin() == known_categories_end(); |
| 1682 | } |
| 1683 | |
| 1684 | private: |
| 1685 | |
| 1686 | |
| 1687 | |
| 1688 | static bool isVisibleExtension(ObjCCategoryDecl *Cat); |
| 1689 | |
| 1690 | public: |
| 1691 | |
| 1692 | |
| 1693 | using visible_extensions_iterator = |
| 1694 | filtered_category_iterator<isVisibleExtension>; |
| 1695 | |
| 1696 | using visible_extensions_range = |
| 1697 | llvm::iterator_range<visible_extensions_iterator>; |
| 1698 | |
| 1699 | visible_extensions_range visible_extensions() const { |
| 1700 | return visible_extensions_range(visible_extensions_begin(), |
| 1701 | visible_extensions_end()); |
| 1702 | } |
| 1703 | |
| 1704 | |
| 1705 | |
| 1706 | visible_extensions_iterator visible_extensions_begin() const { |
| 1707 | return visible_extensions_iterator(getCategoryListRaw()); |
| 1708 | } |
| 1709 | |
| 1710 | |
| 1711 | visible_extensions_iterator visible_extensions_end() const { |
| 1712 | return visible_extensions_iterator(); |
| 1713 | } |
| 1714 | |
| 1715 | |
| 1716 | bool visible_extensions_empty() const { |
| 1717 | return visible_extensions_begin() == visible_extensions_end(); |
| 1718 | } |
| 1719 | |
| 1720 | private: |
| 1721 | |
| 1722 | |
| 1723 | |
| 1724 | static bool isKnownExtension(ObjCCategoryDecl *Cat); |
| 1725 | |
| 1726 | public: |
| 1727 | friend class ASTDeclReader; |
| 1728 | friend class ASTDeclWriter; |
| 1729 | friend class ASTReader; |
| 1730 | |
| 1731 | |
| 1732 | using known_extensions_iterator = |
| 1733 | filtered_category_iterator<isKnownExtension>; |
| 1734 | using known_extensions_range = |
| 1735 | llvm::iterator_range<known_extensions_iterator>; |
| 1736 | |
| 1737 | known_extensions_range known_extensions() const { |
| 1738 | return known_extensions_range(known_extensions_begin(), |
| 1739 | known_extensions_end()); |
| 1740 | } |
| 1741 | |
| 1742 | |
| 1743 | |
| 1744 | known_extensions_iterator known_extensions_begin() const { |
| 1745 | return known_extensions_iterator(getCategoryListRaw()); |
| 1746 | } |
| 1747 | |
| 1748 | |
| 1749 | known_extensions_iterator known_extensions_end() const { |
| 1750 | return known_extensions_iterator(); |
| 1751 | } |
| 1752 | |
| 1753 | |
| 1754 | bool known_extensions_empty() const { |
| 1755 | return known_extensions_begin() == known_extensions_end(); |
| 1756 | } |
| 1757 | |
| 1758 | |
| 1759 | |
| 1760 | ObjCCategoryDecl* getCategoryListRaw() const { |
| 1761 | |
| 1762 | if (!hasDefinition()) |
| 1763 | return nullptr; |
| 1764 | |
| 1765 | if (data().ExternallyCompleted) |
| 1766 | LoadExternalDefinition(); |
| 1767 | |
| 1768 | return data().CategoryList; |
| 1769 | } |
| 1770 | |
| 1771 | |
| 1772 | |
| 1773 | void setCategoryListRaw(ObjCCategoryDecl *category) { |
| 1774 | data().CategoryList = category; |
| 1775 | } |
| 1776 | |
| 1777 | ObjCPropertyDecl |
| 1778 | *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId, |
| 1779 | ObjCPropertyQueryKind QueryKind) const; |
| 1780 | |
| 1781 | void collectPropertiesToImplement(PropertyMap &PM, |
| 1782 | PropertyDeclOrder &PO) const override; |
| 1783 | |
| 1784 | |
| 1785 | |
| 1786 | bool isSuperClassOf(const ObjCInterfaceDecl *I) const { |
| 1787 | |
| 1788 | while (I != nullptr) { |
| 1789 | if (declaresSameEntity(this, I)) |
| 1790 | return true; |
| 1791 | |
| 1792 | I = I->getSuperClass(); |
| 1793 | } |
| 1794 | return false; |
| 1795 | } |
| 1796 | |
| 1797 | |
| 1798 | |
| 1799 | bool isArcWeakrefUnavailable() const; |
| 1800 | |
| 1801 | |
| 1802 | |
| 1803 | |
| 1804 | const ObjCInterfaceDecl *isObjCRequiresPropertyDefs() const; |
| 1805 | |
| 1806 | ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName, |
| 1807 | ObjCInterfaceDecl *&ClassDeclared); |
| 1808 | ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) { |
| 1809 | ObjCInterfaceDecl *ClassDeclared; |
| 1810 | return lookupInstanceVariable(IVarName, ClassDeclared); |
| 1811 | } |
| 1812 | |
| 1813 | ObjCProtocolDecl *lookupNestedProtocol(IdentifierInfo *Name); |
| 1814 | |
| 1815 | |
| 1816 | |
| 1817 | ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance, |
| 1818 | bool shallowCategoryLookup = false, |
| 1819 | bool followSuper = true, |
| 1820 | const ObjCCategoryDecl *C = nullptr) const; |
| 1821 | |
| 1822 | |
| 1823 | ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const { |
| 1824 | return lookupMethod(Sel, true); |
| 1825 | } |
| 1826 | |
| 1827 | |
| 1828 | ObjCMethodDecl *lookupClassMethod(Selector Sel) const { |
| 1829 | return lookupMethod(Sel, false); |
| 1830 | } |
| 1831 | |
| 1832 | ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName); |
| 1833 | |
| 1834 | |
| 1835 | ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel, |
| 1836 | bool Instance=true) const; |
| 1837 | |
| 1838 | ObjCMethodDecl *lookupPrivateClassMethod(const Selector &Sel) { |
| 1839 | return lookupPrivateMethod(Sel, false); |
| 1840 | } |
| 1841 | |
| 1842 | |
| 1843 | |
| 1844 | |
| 1845 | ObjCMethodDecl *lookupPropertyAccessor(const Selector Sel, |
| 1846 | const ObjCCategoryDecl *Cat, |
| 1847 | bool IsClassProperty) const { |
| 1848 | return lookupMethod(Sel, !IsClassProperty, |
| 1849 | false, |
| 1850 | true , |
| 1851 | Cat); |
| 1852 | } |
| 1853 | |
| 1854 | SourceLocation getEndOfDefinitionLoc() const { |
| 1855 | if (!hasDefinition()) |
| 1856 | return getLocation(); |
| 1857 | |
| 1858 | return data().EndLoc; |
| 1859 | } |
| 1860 | |
| 1861 | void setEndOfDefinitionLoc(SourceLocation LE) { data().EndLoc = LE; } |
| 1862 | |
| 1863 | |
| 1864 | SourceLocation getSuperClassLoc() const; |
| 1865 | |
| 1866 | |
| 1867 | |
| 1868 | |
| 1869 | bool isImplicitInterfaceDecl() const { |
| 1870 | return hasDefinition() ? data().Definition->isImplicit() : isImplicit(); |
| 1871 | } |
| 1872 | |
| 1873 | |
| 1874 | |
| 1875 | |
| 1876 | bool ClassImplementsProtocol(ObjCProtocolDecl *lProto, |
| 1877 | bool lookupCategory, |
| 1878 | bool RHSIsQualifiedID = false); |
| 1879 | |
| 1880 | using redecl_range = redeclarable_base::redecl_range; |
| 1881 | using redecl_iterator = redeclarable_base::redecl_iterator; |
| 1882 | |
| 1883 | using redeclarable_base::redecls_begin; |
| 1884 | using redeclarable_base::redecls_end; |
| 1885 | using redeclarable_base::redecls; |
| 1886 | using redeclarable_base::getPreviousDecl; |
| 1887 | using redeclarable_base::getMostRecentDecl; |
| 1888 | using redeclarable_base::isFirstDecl; |
| 1889 | |
| 1890 | |
| 1891 | ObjCInterfaceDecl *getCanonicalDecl() override { return getFirstDecl(); } |
| 1892 | const ObjCInterfaceDecl *getCanonicalDecl() const { return getFirstDecl(); } |
| 1893 | |
| 1894 | |
| 1895 | const Type *getTypeForDecl() const { return TypeForDecl; } |
| 1896 | void setTypeForDecl(const Type *TD) const { TypeForDecl = TD; } |
| 1897 | |
| 1898 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 1899 | static bool classofKind(Kind K) { return K == ObjCInterface; } |
| 1900 | |
| 1901 | private: |
| 1902 | const ObjCInterfaceDecl *findInterfaceWithDesignatedInitializers() const; |
| 1903 | bool inheritsDesignatedInitializers() const; |
| 1904 | }; |
| 1905 | |
| 1906 | |
| 1907 | |
| 1908 | |
| 1909 | |
| 1910 | |
| 1911 | |
| 1912 | |
| 1913 | |
| 1914 | |
| 1915 | |
| 1916 | |
| 1917 | |
| 1918 | |
| 1919 | |
| 1920 | |
| 1921 | class ObjCIvarDecl : public FieldDecl { |
| 1922 | void anchor() override; |
| 1923 | |
| 1924 | public: |
| 1925 | enum AccessControl { |
| 1926 | None, Private, Protected, Public, Package |
| 1927 | }; |
| 1928 | |
| 1929 | private: |
| 1930 | ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation StartLoc, |
| 1931 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 1932 | QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW, |
| 1933 | bool synthesized) |
| 1934 | : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, BW, |
| 1935 | false, ICIS_NoInit), |
| 1936 | DeclAccess(ac), Synthesized(synthesized) {} |
| 1937 | |
| 1938 | public: |
| 1939 | static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC, |
| 1940 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 1941 | IdentifierInfo *Id, QualType T, |
| 1942 | TypeSourceInfo *TInfo, |
| 1943 | AccessControl ac, Expr *BW = nullptr, |
| 1944 | bool synthesized=false); |
| 1945 | |
| 1946 | static ObjCIvarDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 1947 | |
| 1948 | |
| 1949 | |
| 1950 | |
| 1951 | |
| 1952 | const ObjCInterfaceDecl *getContainingInterface() const; |
| 1953 | |
| 1954 | ObjCIvarDecl *getNextIvar() { return NextIvar; } |
| 1955 | const ObjCIvarDecl *getNextIvar() const { return NextIvar; } |
| 1956 | void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; } |
| 1957 | |
| 1958 | void setAccessControl(AccessControl ac) { DeclAccess = ac; } |
| 1959 | |
| 1960 | AccessControl getAccessControl() const { return AccessControl(DeclAccess); } |
| 1961 | |
| 1962 | AccessControl getCanonicalAccessControl() const { |
| 1963 | return DeclAccess == None ? Protected : AccessControl(DeclAccess); |
| 1964 | } |
| 1965 | |
| 1966 | void setSynthesize(bool synth) { Synthesized = synth; } |
| 1967 | bool getSynthesize() const { return Synthesized; } |
| 1968 | |
| 1969 | |
| 1970 | |
| 1971 | QualType getUsageType(QualType objectType) const; |
| 1972 | |
| 1973 | |
| 1974 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 1975 | static bool classofKind(Kind K) { return K == ObjCIvar; } |
| 1976 | |
| 1977 | private: |
| 1978 | |
| 1979 | |
| 1980 | ObjCIvarDecl *NextIvar = nullptr; |
| 1981 | |
| 1982 | |
| 1983 | unsigned DeclAccess : 3; |
| 1984 | unsigned Synthesized : 1; |
| 1985 | }; |
| 1986 | |
| 1987 | |
| 1988 | class ObjCAtDefsFieldDecl : public FieldDecl { |
| 1989 | ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation StartLoc, |
| 1990 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 1991 | QualType T, Expr *BW) |
| 1992 | : FieldDecl(ObjCAtDefsField, DC, StartLoc, IdLoc, Id, T, |
| 1993 | nullptr, |
| 1994 | BW, false, ICIS_NoInit) {} |
| 1995 | |
| 1996 | void anchor() override; |
| 1997 | |
| 1998 | public: |
| 1999 | static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC, |
| 2000 | SourceLocation StartLoc, |
| 2001 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 2002 | QualType T, Expr *BW); |
| 2003 | |
| 2004 | static ObjCAtDefsFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 2005 | |
| 2006 | |
| 2007 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2008 | static bool classofKind(Kind K) { return K == ObjCAtDefsField; } |
| 2009 | }; |
| 2010 | |
| 2011 | |
| 2012 | |
| 2013 | |
| 2014 | |
| 2015 | |
| 2016 | |
| 2017 | |
| 2018 | |
| 2019 | |
| 2020 | |
| 2021 | |
| 2022 | |
| 2023 | |
| 2024 | |
| 2025 | |
| 2026 | |
| 2027 | |
| 2028 | |
| 2029 | |
| 2030 | |
| 2031 | |
| 2032 | |
| 2033 | |
| 2034 | |
| 2035 | |
| 2036 | |
| 2037 | |
| 2038 | |
| 2039 | |
| 2040 | class ObjCProtocolDecl : public ObjCContainerDecl, |
| 2041 | public Redeclarable<ObjCProtocolDecl> { |
| 2042 | struct DefinitionData { |
| 2043 | |
| 2044 | ObjCProtocolDecl *Definition; |
| 2045 | |
| 2046 | |
| 2047 | ObjCProtocolList ReferencedProtocols; |
| 2048 | }; |
| 2049 | |
| 2050 | |
| 2051 | |
| 2052 | |
| 2053 | |
| 2054 | |
| 2055 | llvm::PointerIntPair<DefinitionData *, 1, bool> Data; |
| 2056 | |
| 2057 | ObjCProtocolDecl(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, |
| 2058 | SourceLocation nameLoc, SourceLocation atStartLoc, |
| 2059 | ObjCProtocolDecl *PrevDecl); |
| 2060 | |
| 2061 | void anchor() override; |
| 2062 | |
| 2063 | DefinitionData &data() const { |
| 2064 | assert(Data.getPointer() && "Objective-C protocol has no definition!"); |
| 2065 | return *Data.getPointer(); |
| 2066 | } |
| 2067 | |
| 2068 | void allocateDefinitionData(); |
| 2069 | |
| 2070 | using redeclarable_base = Redeclarable<ObjCProtocolDecl>; |
| 2071 | |
| 2072 | ObjCProtocolDecl *getNextRedeclarationImpl() override { |
| 2073 | return getNextRedeclaration(); |
| 2074 | } |
| 2075 | |
| 2076 | ObjCProtocolDecl *getPreviousDeclImpl() override { |
| 2077 | return getPreviousDecl(); |
| 2078 | } |
| 2079 | |
| 2080 | ObjCProtocolDecl *getMostRecentDeclImpl() override { |
| 2081 | return getMostRecentDecl(); |
| 2082 | } |
| 2083 | |
| 2084 | public: |
| 2085 | friend class ASTDeclReader; |
| 2086 | friend class ASTDeclWriter; |
| 2087 | friend class ASTReader; |
| 2088 | |
| 2089 | static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC, |
| 2090 | IdentifierInfo *Id, |
| 2091 | SourceLocation nameLoc, |
| 2092 | SourceLocation atStartLoc, |
| 2093 | ObjCProtocolDecl *PrevDecl); |
| 2094 | |
| 2095 | static ObjCProtocolDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 2096 | |
| 2097 | const ObjCProtocolList &getReferencedProtocols() const { |
| 2098 | assert(hasDefinition() && "No definition available!"); |
| 2099 | return data().ReferencedProtocols; |
| 2100 | } |
| 2101 | |
| 2102 | using protocol_iterator = ObjCProtocolList::iterator; |
| 2103 | using protocol_range = llvm::iterator_range<protocol_iterator>; |
| 2104 | |
| 2105 | protocol_range protocols() const { |
| 2106 | return protocol_range(protocol_begin(), protocol_end()); |
| 2107 | } |
| 2108 | |
| 2109 | protocol_iterator protocol_begin() const { |
| 2110 | if (!hasDefinition()) |
| 2111 | return protocol_iterator(); |
| 2112 | |
| 2113 | return data().ReferencedProtocols.begin(); |
| 2114 | } |
| 2115 | |
| 2116 | protocol_iterator protocol_end() const { |
| 2117 | if (!hasDefinition()) |
| 2118 | return protocol_iterator(); |
| 2119 | |
| 2120 | return data().ReferencedProtocols.end(); |
| 2121 | } |
| 2122 | |
| 2123 | using protocol_loc_iterator = ObjCProtocolList::loc_iterator; |
| 2124 | using protocol_loc_range = llvm::iterator_range<protocol_loc_iterator>; |
| 2125 | |
| 2126 | protocol_loc_range protocol_locs() const { |
| 2127 | return protocol_loc_range(protocol_loc_begin(), protocol_loc_end()); |
| 2128 | } |
| 2129 | |
| 2130 | protocol_loc_iterator protocol_loc_begin() const { |
| 2131 | if (!hasDefinition()) |
| 2132 | return protocol_loc_iterator(); |
| 2133 | |
| 2134 | return data().ReferencedProtocols.loc_begin(); |
| 2135 | } |
| 2136 | |
| 2137 | protocol_loc_iterator protocol_loc_end() const { |
| 2138 | if (!hasDefinition()) |
| 2139 | return protocol_loc_iterator(); |
| 2140 | |
| 2141 | return data().ReferencedProtocols.loc_end(); |
| 2142 | } |
| 2143 | |
| 2144 | unsigned protocol_size() const { |
| 2145 | if (!hasDefinition()) |
| 2146 | return 0; |
| 2147 | |
| 2148 | return data().ReferencedProtocols.size(); |
| 2149 | } |
| 2150 | |
| 2151 | |
| 2152 | |
| 2153 | void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num, |
| 2154 | const SourceLocation *Locs, ASTContext &C) { |
| 2155 | assert(hasDefinition() && "Protocol is not defined"); |
| 2156 | data().ReferencedProtocols.set(List, Num, Locs, C); |
| 2157 | } |
| 2158 | |
| 2159 | |
| 2160 | |
| 2161 | bool isNonRuntimeProtocol() const; |
| 2162 | |
| 2163 | |
| 2164 | |
| 2165 | void getImpliedProtocols(llvm::DenseSet<const ObjCProtocolDecl *> &IPs) const; |
| 2166 | |
| 2167 | ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName); |
| 2168 | |
| 2169 | |
| 2170 | |
| 2171 | ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const; |
| 2172 | |
| 2173 | ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const { |
| 2174 | return lookupMethod(Sel, true); |
| 2175 | } |
| 2176 | |
| 2177 | ObjCMethodDecl *lookupClassMethod(Selector Sel) const { |
| 2178 | return lookupMethod(Sel, false); |
| 2179 | } |
| 2180 | |
| 2181 | |
| 2182 | bool hasDefinition() const { |
| 2183 | |
| 2184 | |
| 2185 | |
| 2186 | |
| 2187 | if (!Data.getOpaqueValue()) |
| 2188 | getMostRecentDecl(); |
| 2189 | |
| 2190 | return Data.getPointer(); |
| 2191 | } |
| 2192 | |
| 2193 | |
| 2194 | ObjCProtocolDecl *getDefinition() { |
| 2195 | return hasDefinition()? Data.getPointer()->Definition : nullptr; |
| 2196 | } |
| 2197 | |
| 2198 | |
| 2199 | const ObjCProtocolDecl *getDefinition() const { |
| 2200 | return hasDefinition()? Data.getPointer()->Definition : nullptr; |
| 2201 | } |
| 2202 | |
| 2203 | |
| 2204 | |
| 2205 | bool isThisDeclarationADefinition() const { |
| 2206 | return getDefinition() == this; |
| 2207 | } |
| 2208 | |
| 2209 | |
| 2210 | void startDefinition(); |
| 2211 | |
| 2212 | |
| 2213 | |
| 2214 | StringRef getObjCRuntimeNameAsString() const; |
| 2215 | |
| 2216 | SourceRange getSourceRange() const override LLVM_READONLY { |
| 2217 | if (isThisDeclarationADefinition()) |
| 2218 | return ObjCContainerDecl::getSourceRange(); |
| 2219 | |
| 2220 | return SourceRange(getAtStartLoc(), getLocation()); |
| 2221 | } |
| 2222 | |
| 2223 | using redecl_range = redeclarable_base::redecl_range; |
| 2224 | using redecl_iterator = redeclarable_base::redecl_iterator; |
| 2225 | |
| 2226 | using redeclarable_base::redecls_begin; |
| 2227 | using redeclarable_base::redecls_end; |
| 2228 | using redeclarable_base::redecls; |
| 2229 | using redeclarable_base::getPreviousDecl; |
| 2230 | using redeclarable_base::getMostRecentDecl; |
| 2231 | using redeclarable_base::isFirstDecl; |
| 2232 | |
| 2233 | |
| 2234 | ObjCProtocolDecl *getCanonicalDecl() override { return getFirstDecl(); } |
| 2235 | const ObjCProtocolDecl *getCanonicalDecl() const { return getFirstDecl(); } |
| 2236 | |
| 2237 | void collectPropertiesToImplement(PropertyMap &PM, |
| 2238 | PropertyDeclOrder &PO) const override; |
| 2239 | |
| 2240 | void collectInheritedProtocolProperties(const ObjCPropertyDecl *Property, |
| 2241 | ProtocolPropertySet &PS, |
| 2242 | PropertyDeclOrder &PO) const; |
| 2243 | |
| 2244 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2245 | static bool classofKind(Kind K) { return K == ObjCProtocol; } |
| 2246 | }; |
| 2247 | |
| 2248 | |
| 2249 | |
| 2250 | |
| 2251 | |
| 2252 | |
| 2253 | |
| 2254 | |
| 2255 | |
| 2256 | |
| 2257 | |
| 2258 | |
| 2259 | |
| 2260 | |
| 2261 | |
| 2262 | |
| 2263 | |
| 2264 | class ObjCCategoryDecl : public ObjCContainerDecl { |
| 2265 | |
| 2266 | ObjCInterfaceDecl *ClassInterface; |
| 2267 | |
| 2268 | |
| 2269 | ObjCTypeParamList *TypeParamList = nullptr; |
| 2270 | |
| 2271 | |
| 2272 | ObjCProtocolList ReferencedProtocols; |
| 2273 | |
| 2274 | |
| 2275 | |
| 2276 | ObjCCategoryDecl *NextClassCategory = nullptr; |
| 2277 | |
| 2278 | |
| 2279 | SourceLocation CategoryNameLoc; |
| 2280 | |
| 2281 | |
| 2282 | SourceLocation IvarLBraceLoc; |
| 2283 | SourceLocation IvarRBraceLoc; |
| 2284 | |
| 2285 | ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc, |
| 2286 | SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc, |
| 2287 | IdentifierInfo *Id, ObjCInterfaceDecl *IDecl, |
| 2288 | ObjCTypeParamList *typeParamList, |
| 2289 | SourceLocation IvarLBraceLoc = SourceLocation(), |
| 2290 | SourceLocation IvarRBraceLoc = SourceLocation()); |
| 2291 | |
| 2292 | void anchor() override; |
| 2293 | |
| 2294 | public: |
| 2295 | friend class ASTDeclReader; |
| 2296 | friend class ASTDeclWriter; |
| 2297 | |
| 2298 | static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC, |
| 2299 | SourceLocation AtLoc, |
| 2300 | SourceLocation ClassNameLoc, |
| 2301 | SourceLocation CategoryNameLoc, |
| 2302 | IdentifierInfo *Id, |
| 2303 | ObjCInterfaceDecl *IDecl, |
| 2304 | ObjCTypeParamList *typeParamList, |
| 2305 | SourceLocation IvarLBraceLoc=SourceLocation(), |
| 2306 | SourceLocation IvarRBraceLoc=SourceLocation()); |
| 2307 | static ObjCCategoryDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 2308 | |
| 2309 | ObjCInterfaceDecl *getClassInterface() { return ClassInterface; } |
| 2310 | const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; } |
| 2311 | |
| 2312 | |
| 2313 | |
| 2314 | ObjCTypeParamList *getTypeParamList() const { return TypeParamList; } |
| 2315 | |
| 2316 | |
| 2317 | |
| 2318 | |
| 2319 | |
| 2320 | void setTypeParamList(ObjCTypeParamList *TPL); |
| 2321 | |
| 2322 | |
| 2323 | ObjCCategoryImplDecl *getImplementation() const; |
| 2324 | void setImplementation(ObjCCategoryImplDecl *ImplD); |
| 2325 | |
| 2326 | |
| 2327 | |
| 2328 | void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num, |
| 2329 | const SourceLocation *Locs, ASTContext &C) { |
| 2330 | ReferencedProtocols.set(List, Num, Locs, C); |
| 2331 | } |
| 2332 | |
| 2333 | const ObjCProtocolList &getReferencedProtocols() const { |
| 2334 | return ReferencedProtocols; |
| 2335 | } |
| 2336 | |
| 2337 | using protocol_iterator = ObjCProtocolList::iterator; |
| 2338 | using protocol_range = llvm::iterator_range<protocol_iterator>; |
| 2339 | |
| 2340 | protocol_range protocols() const { |
| 2341 | return protocol_range(protocol_begin(), protocol_end()); |
| 2342 | } |
| 2343 | |
| 2344 | protocol_iterator protocol_begin() const { |
| 2345 | return ReferencedProtocols.begin(); |
| 2346 | } |
| 2347 | |
| 2348 | protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } |
| 2349 | unsigned protocol_size() const { return ReferencedProtocols.size(); } |
| 2350 | |
| 2351 | using protocol_loc_iterator = ObjCProtocolList::loc_iterator; |
| 2352 | using protocol_loc_range = llvm::iterator_range<protocol_loc_iterator>; |
| 2353 | |
| 2354 | protocol_loc_range protocol_locs() const { |
| 2355 | return protocol_loc_range(protocol_loc_begin(), protocol_loc_end()); |
| 2356 | } |
| 2357 | |
| 2358 | protocol_loc_iterator protocol_loc_begin() const { |
| 2359 | return ReferencedProtocols.loc_begin(); |
| 2360 | } |
| 2361 | |
| 2362 | protocol_loc_iterator protocol_loc_end() const { |
| 2363 | return ReferencedProtocols.loc_end(); |
| 2364 | } |
| 2365 | |
| 2366 | ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; } |
| 2367 | |
| 2368 | |
| 2369 | |
| 2370 | ObjCCategoryDecl *getNextClassCategoryRaw() const { |
| 2371 | return NextClassCategory; |
| 2372 | } |
| 2373 | |
| 2374 | bool IsClassExtension() const { return getIdentifier() == nullptr; } |
| 2375 | |
| 2376 | using ivar_iterator = specific_decl_iterator<ObjCIvarDecl>; |
| 2377 | using ivar_range = llvm::iterator_range<specific_decl_iterator<ObjCIvarDecl>>; |
| 2378 | |
| 2379 | ivar_range ivars() const { return ivar_range(ivar_begin(), ivar_end()); } |
| 2380 | |
| 2381 | ivar_iterator ivar_begin() const { |
| 2382 | return ivar_iterator(decls_begin()); |
| 2383 | } |
| 2384 | |
| 2385 | ivar_iterator ivar_end() const { |
| 2386 | return ivar_iterator(decls_end()); |
| 2387 | } |
| 2388 | |
| 2389 | unsigned ivar_size() const { |
| 2390 | return std::distance(ivar_begin(), ivar_end()); |
| 2391 | } |
| 2392 | |
| 2393 | bool ivar_empty() const { |
| 2394 | return ivar_begin() == ivar_end(); |
| 2395 | } |
| 2396 | |
| 2397 | SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; } |
| 2398 | void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; } |
| 2399 | |
| 2400 | void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; } |
| 2401 | SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; } |
| 2402 | void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; } |
| 2403 | SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; } |
| 2404 | |
| 2405 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2406 | static bool classofKind(Kind K) { return K == ObjCCategory; } |
| 2407 | }; |
| 2408 | |
| 2409 | class ObjCImplDecl : public ObjCContainerDecl { |
| 2410 | |
| 2411 | ObjCInterfaceDecl *ClassInterface; |
| 2412 | |
| 2413 | void anchor() override; |
| 2414 | |
| 2415 | protected: |
| 2416 | ObjCImplDecl(Kind DK, DeclContext *DC, |
| 2417 | ObjCInterfaceDecl *classInterface, |
| 2418 | IdentifierInfo *Id, |
| 2419 | SourceLocation nameLoc, SourceLocation atStartLoc) |
| 2420 | : ObjCContainerDecl(DK, DC, Id, nameLoc, atStartLoc), |
| 2421 | ClassInterface(classInterface) {} |
| 2422 | |
| 2423 | public: |
| 2424 | const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; } |
| 2425 | ObjCInterfaceDecl *getClassInterface() { return ClassInterface; } |
| 2426 | void setClassInterface(ObjCInterfaceDecl *IFace); |
| 2427 | |
| 2428 | void addInstanceMethod(ObjCMethodDecl *method) { |
| 2429 | |
| 2430 | method->setLexicalDeclContext(this); |
| 2431 | addDecl(method); |
| 2432 | } |
| 2433 | |
| 2434 | void addClassMethod(ObjCMethodDecl *method) { |
| 2435 | |
| 2436 | method->setLexicalDeclContext(this); |
| 2437 | addDecl(method); |
| 2438 | } |
| 2439 | |
| 2440 | void addPropertyImplementation(ObjCPropertyImplDecl *property); |
| 2441 | |
| 2442 | ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId, |
| 2443 | ObjCPropertyQueryKind queryKind) const; |
| 2444 | ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const; |
| 2445 | |
| 2446 | |
| 2447 | using propimpl_iterator = specific_decl_iterator<ObjCPropertyImplDecl>; |
| 2448 | using propimpl_range = |
| 2449 | llvm::iterator_range<specific_decl_iterator<ObjCPropertyImplDecl>>; |
| 2450 | |
| 2451 | propimpl_range property_impls() const { |
| 2452 | return propimpl_range(propimpl_begin(), propimpl_end()); |
| 2453 | } |
| 2454 | |
| 2455 | propimpl_iterator propimpl_begin() const { |
| 2456 | return propimpl_iterator(decls_begin()); |
| 2457 | } |
| 2458 | |
| 2459 | propimpl_iterator propimpl_end() const { |
| 2460 | return propimpl_iterator(decls_end()); |
| 2461 | } |
| 2462 | |
| 2463 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2464 | |
| 2465 | static bool classofKind(Kind K) { |
| 2466 | return K >= firstObjCImpl && K <= lastObjCImpl; |
| 2467 | } |
| 2468 | }; |
| 2469 | |
| 2470 | |
| 2471 | |
| 2472 | |
| 2473 | |
| 2474 | |
| 2475 | |
| 2476 | |
| 2477 | |
| 2478 | |
| 2479 | |
| 2480 | |
| 2481 | |
| 2482 | |
| 2483 | class ObjCCategoryImplDecl : public ObjCImplDecl { |
| 2484 | |
| 2485 | SourceLocation CategoryNameLoc; |
| 2486 | |
| 2487 | ObjCCategoryImplDecl(DeclContext *DC, IdentifierInfo *Id, |
| 2488 | ObjCInterfaceDecl *classInterface, |
| 2489 | SourceLocation nameLoc, SourceLocation atStartLoc, |
| 2490 | SourceLocation CategoryNameLoc) |
| 2491 | : ObjCImplDecl(ObjCCategoryImpl, DC, classInterface, Id, |
| 2492 | nameLoc, atStartLoc), |
| 2493 | CategoryNameLoc(CategoryNameLoc) {} |
| 2494 | |
| 2495 | void anchor() override; |
| 2496 | |
| 2497 | public: |
| 2498 | friend class ASTDeclReader; |
| 2499 | friend class ASTDeclWriter; |
| 2500 | |
| 2501 | static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC, |
| 2502 | IdentifierInfo *Id, |
| 2503 | ObjCInterfaceDecl *classInterface, |
| 2504 | SourceLocation nameLoc, |
| 2505 | SourceLocation atStartLoc, |
| 2506 | SourceLocation CategoryNameLoc); |
| 2507 | static ObjCCategoryImplDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 2508 | |
| 2509 | ObjCCategoryDecl *getCategoryDecl() const; |
| 2510 | |
| 2511 | SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; } |
| 2512 | |
| 2513 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2514 | static bool classofKind(Kind K) { return K == ObjCCategoryImpl;} |
| 2515 | }; |
| 2516 | |
| 2517 | raw_ostream &operator<<(raw_ostream &OS, const ObjCCategoryImplDecl &CID); |
| 2518 | |
| 2519 | |
| 2520 | |
| 2521 | |
| 2522 | |
| 2523 | |
| 2524 | |
| 2525 | |
| 2526 | |
| 2527 | |
| 2528 | |
| 2529 | |
| 2530 | |
| 2531 | |
| 2532 | |
| 2533 | |
| 2534 | |
| 2535 | |
| 2536 | class ObjCImplementationDecl : public ObjCImplDecl { |
| 2537 | |
| 2538 | ObjCInterfaceDecl *SuperClass; |
| 2539 | SourceLocation SuperLoc; |
| 2540 | |
| 2541 | |
| 2542 | SourceLocation IvarLBraceLoc; |
| 2543 | SourceLocation IvarRBraceLoc; |
| 2544 | |
| 2545 | |
| 2546 | |
| 2547 | LazyCXXCtorInitializersPtr IvarInitializers; |
| 2548 | unsigned NumIvarInitializers = 0; |
| 2549 | |
| 2550 | |
| 2551 | |
| 2552 | bool HasNonZeroConstructors : 1; |
| 2553 | |
| 2554 | |
| 2555 | bool HasDestructors : 1; |
| 2556 | |
| 2557 | ObjCImplementationDecl(DeclContext *DC, |
| 2558 | ObjCInterfaceDecl *classInterface, |
| 2559 | ObjCInterfaceDecl *superDecl, |
| 2560 | SourceLocation nameLoc, SourceLocation atStartLoc, |
| 2561 | SourceLocation superLoc = SourceLocation(), |
| 2562 | SourceLocation IvarLBraceLoc=SourceLocation(), |
| 2563 | SourceLocation IvarRBraceLoc=SourceLocation()) |
| 2564 | : ObjCImplDecl(ObjCImplementation, DC, classInterface, |
| 2565 | classInterface ? classInterface->getIdentifier() |
| 2566 | : nullptr, |
| 2567 | nameLoc, atStartLoc), |
| 2568 | SuperClass(superDecl), SuperLoc(superLoc), |
| 2569 | IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc), |
| 2570 | HasNonZeroConstructors(false), HasDestructors(false) {} |
| 2571 | |
| 2572 | void anchor() override; |
| 2573 | |
| 2574 | public: |
| 2575 | friend class ASTDeclReader; |
| 2576 | friend class ASTDeclWriter; |
| 2577 | |
| 2578 | static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC, |
| 2579 | ObjCInterfaceDecl *classInterface, |
| 2580 | ObjCInterfaceDecl *superDecl, |
| 2581 | SourceLocation nameLoc, |
| 2582 | SourceLocation atStartLoc, |
| 2583 | SourceLocation superLoc = SourceLocation(), |
| 2584 | SourceLocation IvarLBraceLoc=SourceLocation(), |
| 2585 | SourceLocation IvarRBraceLoc=SourceLocation()); |
| 2586 | |
| 2587 | static ObjCImplementationDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 2588 | |
| 2589 | |
| 2590 | using init_iterator = CXXCtorInitializer **; |
| 2591 | |
| 2592 | |
| 2593 | using init_const_iterator = CXXCtorInitializer * const *; |
| 2594 | |
| 2595 | using init_range = llvm::iterator_range<init_iterator>; |
| 2596 | using init_const_range = llvm::iterator_range<init_const_iterator>; |
| 2597 | |
| 2598 | init_range inits() { return init_range(init_begin(), init_end()); } |
| 2599 | |
| 2600 | init_const_range inits() const { |
| 2601 | return init_const_range(init_begin(), init_end()); |
| 2602 | } |
| 2603 | |
| 2604 | |
| 2605 | init_iterator init_begin() { |
| 2606 | const auto *ConstThis = this; |
| 2607 | return const_cast<init_iterator>(ConstThis->init_begin()); |
| 2608 | } |
| 2609 | |
| 2610 | |
| 2611 | init_const_iterator init_begin() const; |
| 2612 | |
| 2613 | |
| 2614 | init_iterator init_end() { |
| 2615 | return init_begin() + NumIvarInitializers; |
| 2616 | } |
| 2617 | |
| 2618 | |
| 2619 | init_const_iterator init_end() const { |
| 2620 | return init_begin() + NumIvarInitializers; |
| 2621 | } |
| 2622 | |
| 2623 | |
| 2624 | unsigned getNumIvarInitializers() const { |
| 2625 | return NumIvarInitializers; |
| 2626 | } |
| 2627 | |
| 2628 | void setNumIvarInitializers(unsigned numNumIvarInitializers) { |
| 2629 | NumIvarInitializers = numNumIvarInitializers; |
| 2630 | } |
| 2631 | |
| 2632 | void setIvarInitializers(ASTContext &C, |
| 2633 | CXXCtorInitializer ** initializers, |
| 2634 | unsigned numInitializers); |
| 2635 | |
| 2636 | |
| 2637 | |
| 2638 | bool hasNonZeroConstructors() const { return HasNonZeroConstructors; } |
| 2639 | void setHasNonZeroConstructors(bool val) { HasNonZeroConstructors = val; } |
| 2640 | |
| 2641 | |
| 2642 | |
| 2643 | bool hasDestructors() const { return HasDestructors; } |
| 2644 | void setHasDestructors(bool val) { HasDestructors = val; } |
| 2645 | |
| 2646 | |
| 2647 | |
| 2648 | IdentifierInfo *getIdentifier() const { |
| 2649 | return getClassInterface()->getIdentifier(); |
| 2650 | } |
| 2651 | |
| 2652 | |
| 2653 | |
| 2654 | |
| 2655 | |
| 2656 | |
| 2657 | StringRef getName() const { |
| 2658 | assert(getIdentifier() && "Name is not a simple identifier"); |
| 2659 | return getIdentifier()->getName(); |
| 2660 | } |
| 2661 | |
| 2662 | |
| 2663 | |
| 2664 | |
| 2665 | std::string getNameAsString() const { return std::string(getName()); } |
| 2666 | |
| 2667 | |
| 2668 | |
| 2669 | StringRef getObjCRuntimeNameAsString() const; |
| 2670 | |
| 2671 | const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; } |
| 2672 | ObjCInterfaceDecl *getSuperClass() { return SuperClass; } |
| 2673 | SourceLocation getSuperClassLoc() const { return SuperLoc; } |
| 2674 | |
| 2675 | void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; } |
| 2676 | |
| 2677 | void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; } |
| 2678 | SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; } |
| 2679 | void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; } |
| 2680 | SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; } |
| 2681 | |
| 2682 | using ivar_iterator = specific_decl_iterator<ObjCIvarDecl>; |
| 2683 | using ivar_range = llvm::iterator_range<specific_decl_iterator<ObjCIvarDecl>>; |
| 2684 | |
| 2685 | ivar_range ivars() const { return ivar_range(ivar_begin(), ivar_end()); } |
| 2686 | |
| 2687 | ivar_iterator ivar_begin() const { |
| 2688 | return ivar_iterator(decls_begin()); |
| 2689 | } |
| 2690 | |
| 2691 | ivar_iterator ivar_end() const { |
| 2692 | return ivar_iterator(decls_end()); |
| 2693 | } |
| 2694 | |
| 2695 | unsigned ivar_size() const { |
| 2696 | return std::distance(ivar_begin(), ivar_end()); |
| 2697 | } |
| 2698 | |
| 2699 | bool ivar_empty() const { |
| 2700 | return ivar_begin() == ivar_end(); |
| |
| 34 | | Returning from 'operator==' | |
|
| 35 | | Returning zero, which participates in a condition later | |
|
| 2701 | } |
| 2702 | |
| 2703 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2704 | static bool classofKind(Kind K) { return K == ObjCImplementation; } |
| 2705 | }; |
| 2706 | |
| 2707 | raw_ostream &operator<<(raw_ostream &OS, const ObjCImplementationDecl &ID); |
| 2708 | |
| 2709 | |
| 2710 | |
| 2711 | class ObjCCompatibleAliasDecl : public NamedDecl { |
| 2712 | |
| 2713 | ObjCInterfaceDecl *AliasedClass; |
| 2714 | |
| 2715 | ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, |
| 2716 | ObjCInterfaceDecl* aliasedClass) |
| 2717 | : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {} |
| 2718 | |
| 2719 | void anchor() override; |
| 2720 | |
| 2721 | public: |
| 2722 | static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC, |
| 2723 | SourceLocation L, IdentifierInfo *Id, |
| 2724 | ObjCInterfaceDecl* aliasedClass); |
| 2725 | |
| 2726 | static ObjCCompatibleAliasDecl *CreateDeserialized(ASTContext &C, |
| 2727 | unsigned ID); |
| 2728 | |
| 2729 | const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; } |
| 2730 | ObjCInterfaceDecl *getClassInterface() { return AliasedClass; } |
| 2731 | void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; } |
| 2732 | |
| 2733 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2734 | static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; } |
| 2735 | }; |
| 2736 | |
| 2737 | |
| 2738 | |
| 2739 | |
| 2740 | |
| 2741 | class ObjCPropertyImplDecl : public Decl { |
| 2742 | public: |
| 2743 | enum Kind { |
| 2744 | Synthesize, |
| 2745 | Dynamic |
| 2746 | }; |
| 2747 | |
| 2748 | private: |
| 2749 | SourceLocation AtLoc; |
| 2750 | |
| 2751 | |
| 2752 | |
| 2753 | |
| 2754 | |
| 2755 | |
| 2756 | |
| 2757 | SourceLocation IvarLoc; |
| 2758 | |
| 2759 | |
| 2760 | ObjCPropertyDecl *PropertyDecl; |
| 2761 | |
| 2762 | |
| 2763 | ObjCIvarDecl *PropertyIvarDecl; |
| 2764 | |
| 2765 | |
| 2766 | ObjCMethodDecl *GetterMethodDecl = nullptr; |
| 2767 | |
| 2768 | ObjCMethodDecl *SetterMethodDecl = nullptr; |
| 2769 | |
| 2770 | |
| 2771 | |
| 2772 | Expr *GetterCXXConstructor = nullptr; |
| 2773 | |
| 2774 | |
| 2775 | |
| 2776 | Expr *SetterCXXAssignment = nullptr; |
| 2777 | |
| 2778 | ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L, |
| 2779 | ObjCPropertyDecl *property, |
| 2780 | Kind PK, |
| 2781 | ObjCIvarDecl *ivarDecl, |
| 2782 | SourceLocation ivarLoc) |
| 2783 | : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc), |
| 2784 | IvarLoc(ivarLoc), PropertyDecl(property), PropertyIvarDecl(ivarDecl) { |
| 2785 | assert(PK == Dynamic || PropertyIvarDecl); |
| 2786 | } |
| 2787 | |
| 2788 | public: |
| 2789 | friend class ASTDeclReader; |
| 2790 | |
| 2791 | static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC, |
| 2792 | SourceLocation atLoc, SourceLocation L, |
| 2793 | ObjCPropertyDecl *property, |
| 2794 | Kind PK, |
| 2795 | ObjCIvarDecl *ivarDecl, |
| 2796 | SourceLocation ivarLoc); |
| 2797 | |
| 2798 | static ObjCPropertyImplDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 2799 | |
| 2800 | SourceRange getSourceRange() const override LLVM_READONLY; |
| 2801 | |
| 2802 | SourceLocation getBeginLoc() const LLVM_READONLY { return AtLoc; } |
| 2803 | void setAtLoc(SourceLocation Loc) { AtLoc = Loc; } |
| 2804 | |
| 2805 | ObjCPropertyDecl *getPropertyDecl() const { |
| 2806 | return PropertyDecl; |
| 2807 | } |
| 2808 | void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; } |
| 2809 | |
| 2810 | Kind getPropertyImplementation() const { |
| 2811 | return PropertyIvarDecl ? Synthesize : Dynamic; |
| 2812 | } |
| 2813 | |
| 2814 | ObjCIvarDecl *getPropertyIvarDecl() const { |
| 2815 | return PropertyIvarDecl; |
| 2816 | } |
| 2817 | SourceLocation getPropertyIvarDeclLoc() const { return IvarLoc; } |
| 2818 | |
| 2819 | void setPropertyIvarDecl(ObjCIvarDecl *Ivar, |
| 2820 | SourceLocation IvarLoc) { |
| 2821 | PropertyIvarDecl = Ivar; |
| 2822 | this->IvarLoc = IvarLoc; |
| 2823 | } |
| 2824 | |
| 2825 | |
| 2826 | |
| 2827 | |
| 2828 | |
| 2829 | |
| 2830 | |
| 2831 | |
| 2832 | bool isIvarNameSpecified() const { |
| 2833 | return IvarLoc.isValid() && IvarLoc != getLocation(); |
| 2834 | } |
| 2835 | |
| 2836 | ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; } |
| 2837 | void setGetterMethodDecl(ObjCMethodDecl *MD) { GetterMethodDecl = MD; } |
| 2838 | |
| 2839 | ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; } |
| 2840 | void setSetterMethodDecl(ObjCMethodDecl *MD) { SetterMethodDecl = MD; } |
| 2841 | |
| 2842 | Expr *getGetterCXXConstructor() const { |
| 2843 | return GetterCXXConstructor; |
| 2844 | } |
| 2845 | |
| 2846 | void setGetterCXXConstructor(Expr *getterCXXConstructor) { |
| 2847 | GetterCXXConstructor = getterCXXConstructor; |
| 2848 | } |
| 2849 | |
| 2850 | Expr *getSetterCXXAssignment() const { |
| 2851 | return SetterCXXAssignment; |
| 2852 | } |
| 2853 | |
| 2854 | void setSetterCXXAssignment(Expr *setterCXXAssignment) { |
| 2855 | SetterCXXAssignment = setterCXXAssignment; |
| 2856 | } |
| 2857 | |
| 2858 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2859 | static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; } |
| 2860 | }; |
| 2861 | |
| 2862 | template<bool (*Filter)(ObjCCategoryDecl *)> |
| 2863 | void |
| 2864 | ObjCInterfaceDecl::filtered_category_iterator<Filter>:: |
| 2865 | findAcceptableCategory() { |
| 2866 | while (Current && !Filter(Current)) |
| 2867 | Current = Current->getNextClassCategoryRaw(); |
| 2868 | } |
| 2869 | |
| 2870 | template<bool (*Filter)(ObjCCategoryDecl *)> |
| 2871 | inline ObjCInterfaceDecl::filtered_category_iterator<Filter> & |
| 2872 | ObjCInterfaceDecl::filtered_category_iterator<Filter>::operator++() { |
| 2873 | Current = Current->getNextClassCategoryRaw(); |
| 2874 | findAcceptableCategory(); |
| 2875 | return *this; |
| 2876 | } |
| 2877 | |
| 2878 | inline bool ObjCInterfaceDecl::isVisibleCategory(ObjCCategoryDecl *Cat) { |
| 2879 | return Cat->isUnconditionallyVisible(); |
| 2880 | } |
| 2881 | |
| 2882 | inline bool ObjCInterfaceDecl::isVisibleExtension(ObjCCategoryDecl *Cat) { |
| 2883 | return Cat->IsClassExtension() && Cat->isUnconditionallyVisible(); |
| 2884 | } |
| 2885 | |
| 2886 | inline bool ObjCInterfaceDecl::isKnownExtension(ObjCCategoryDecl *Cat) { |
| 2887 | return Cat->IsClassExtension(); |
| 2888 | } |
| 2889 | |
| 2890 | } |
| 2891 | |
| 2892 | #endif // LLVM_CLANG_AST_DECLOBJC_H |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #ifndef LLVM_CLANG_AST_DECLBASE_H |
| 14 | #define LLVM_CLANG_AST_DECLBASE_H |
| 15 | |
| 16 | #include "clang/AST/ASTDumperUtils.h" |
| 17 | #include "clang/AST/AttrIterator.h" |
| 18 | #include "clang/AST/DeclarationName.h" |
| 19 | #include "clang/Basic/IdentifierTable.h" |
| 20 | #include "clang/Basic/LLVM.h" |
| 21 | #include "clang/Basic/SourceLocation.h" |
| 22 | #include "clang/Basic/Specifiers.h" |
| 23 | #include "llvm/ADT/ArrayRef.h" |
| 24 | #include "llvm/ADT/PointerIntPair.h" |
| 25 | #include "llvm/ADT/PointerUnion.h" |
| 26 | #include "llvm/ADT/iterator.h" |
| 27 | #include "llvm/ADT/iterator_range.h" |
| 28 | #include "llvm/Support/Casting.h" |
| 29 | #include "llvm/Support/Compiler.h" |
| 30 | #include "llvm/Support/PrettyStackTrace.h" |
| 31 | #include "llvm/Support/VersionTuple.h" |
| 32 | #include <algorithm> |
| 33 | #include <cassert> |
| 34 | #include <cstddef> |
| 35 | #include <iterator> |
| 36 | #include <string> |
| 37 | #include <type_traits> |
| 38 | #include <utility> |
| 39 | |
| 40 | namespace clang { |
| 41 | |
| 42 | class ASTContext; |
| 43 | class ASTMutationListener; |
| 44 | class Attr; |
| 45 | class BlockDecl; |
| 46 | class DeclContext; |
| 47 | class ExternalSourceSymbolAttr; |
| 48 | class FunctionDecl; |
| 49 | class FunctionType; |
| 50 | class IdentifierInfo; |
| 51 | enum Linkage : unsigned char; |
| 52 | class LinkageSpecDecl; |
| 53 | class Module; |
| 54 | class NamedDecl; |
| 55 | class ObjCCategoryDecl; |
| 56 | class ObjCCategoryImplDecl; |
| 57 | class ObjCContainerDecl; |
| 58 | class ObjCImplDecl; |
| 59 | class ObjCImplementationDecl; |
| 60 | class ObjCInterfaceDecl; |
| 61 | class ObjCMethodDecl; |
| 62 | class ObjCProtocolDecl; |
| 63 | struct PrintingPolicy; |
| 64 | class RecordDecl; |
| 65 | class SourceManager; |
| 66 | class Stmt; |
| 67 | class StoredDeclsMap; |
| 68 | class TemplateDecl; |
| 69 | class TemplateParameterList; |
| 70 | class TranslationUnitDecl; |
| 71 | class UsingDirectiveDecl; |
| 72 | |
| 73 | |
| 74 | |
| 75 | enum AvailabilityResult { |
| 76 | AR_Available = 0, |
| 77 | AR_NotYetIntroduced, |
| 78 | AR_Deprecated, |
| 79 | AR_Unavailable |
| 80 | }; |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | class alignas(8) Decl { |
| 90 | public: |
| 91 | |
| 92 | enum Kind { |
| 93 | #define DECL(DERIVED, BASE) DERIVED, |
| 94 | #define ABSTRACT_DECL(DECL) |
| 95 | #define DECL_RANGE(BASE, START, END) \ |
| 96 | first##BASE = START, last##BASE = END, |
| 97 | #define LAST_DECL_RANGE(BASE, START, END) \ |
| 98 | first##BASE = START, last##BASE = END |
| 99 | #include "clang/AST/DeclNodes.inc" |
| 100 | }; |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | struct EmptyShell {}; |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | enum IdentifierNamespace { |
| 119 | |
| 120 | IDNS_Label = 0x0001, |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | IDNS_Tag = 0x0002, |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | IDNS_Type = 0x0004, |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | IDNS_Member = 0x0008, |
| 140 | |
| 141 | |
| 142 | |
| 143 | IDNS_Namespace = 0x0010, |
| 144 | |
| 145 | |
| 146 | |
| 147 | IDNS_Ordinary = 0x0020, |
| 148 | |
| 149 | |
| 150 | IDNS_ObjCProtocol = 0x0040, |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | IDNS_OrdinaryFriend = 0x0080, |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | IDNS_TagFriend = 0x0100, |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | IDNS_Using = 0x0200, |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | IDNS_NonMemberOperator = 0x0400, |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | IDNS_LocalExtern = 0x0800, |
| 179 | |
| 180 | |
| 181 | IDNS_OMPReduction = 0x1000, |
| 182 | |
| 183 | |
| 184 | IDNS_OMPMapper = 0x2000, |
| 185 | }; |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | enum ObjCDeclQualifier { |
| 202 | OBJC_TQ_None = 0x0, |
| 203 | OBJC_TQ_In = 0x1, |
| 204 | OBJC_TQ_Inout = 0x2, |
| 205 | OBJC_TQ_Out = 0x4, |
| 206 | OBJC_TQ_Bycopy = 0x8, |
| 207 | OBJC_TQ_Byref = 0x10, |
| 208 | OBJC_TQ_Oneway = 0x20, |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | OBJC_TQ_CSNullability = 0x40 |
| 214 | }; |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | enum class ModuleOwnershipKind : unsigned { |
| 220 | |
| 221 | Unowned, |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | Visible, |
| 229 | |
| 230 | |
| 231 | |
| 232 | VisibleWhenImported, |
| 233 | |
| 234 | |
| 235 | |
| 236 | ModulePrivate |
| 237 | }; |
| 238 | |
| 239 | protected: |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | llvm::PointerIntPair<Decl *, 2, ModuleOwnershipKind> NextInContextAndBits; |
| 246 | |
| 247 | private: |
| 248 | friend class DeclContext; |
| 249 | |
| 250 | struct MultipleDC { |
| 251 | DeclContext *SemanticDC; |
| 252 | DeclContext *LexicalDC; |
| 253 | }; |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx; |
| 269 | |
| 270 | bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); } |
| 271 | bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); } |
| 272 | |
| 273 | MultipleDC *getMultipleDC() const { |
| 274 | return DeclCtx.get<MultipleDC*>(); |
| 275 | } |
| 276 | |
| 277 | DeclContext *getSemanticDC() const { |
| 278 | return DeclCtx.get<DeclContext*>(); |
| 279 | } |
| 280 | |
| 281 | |
| 282 | SourceLocation Loc; |
| 283 | |
| 284 | |
| 285 | unsigned DeclKind : 7; |
| 286 | |
| 287 | |
| 288 | unsigned InvalidDecl : 1; |
| 289 | |
| 290 | |
| 291 | unsigned HasAttrs : 1; |
| 292 | |
| 293 | |
| 294 | |
| 295 | unsigned Implicit : 1; |
| 296 | |
| 297 | |
| 298 | |
| 299 | unsigned Used : 1; |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | unsigned Referenced : 1; |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | unsigned TopLevelDeclInObjCContainer : 1; |
| 311 | |
| 312 | |
| 313 | static bool StatisticsEnabled; |
| 314 | |
| 315 | protected: |
| 316 | friend class ASTDeclReader; |
| 317 | friend class ASTDeclWriter; |
| 318 | friend class ASTNodeImporter; |
| 319 | friend class ASTReader; |
| 320 | friend class CXXClassMemberWrapper; |
| 321 | friend class LinkageComputer; |
| 322 | template<typename decl_type> friend class Redeclarable; |
| 323 | |
| 324 | |
| 325 | |
| 326 | unsigned Access : 2; |
| 327 | |
| 328 | |
| 329 | unsigned FromASTFile : 1; |
| 330 | |
| 331 | |
| 332 | unsigned IdentifierNamespace : 14; |
| 333 | |
| 334 | |
| 335 | |
| 336 | mutable unsigned CacheValidAndLinkage : 3; |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | void *operator new(std::size_t Size, const ASTContext &Ctx, unsigned ID, |
| 348 | std::size_t Extra = 0); |
| 349 | |
| 350 | |
| 351 | void *operator new(std::size_t Size, const ASTContext &Ctx, |
| 352 | DeclContext *Parent, std::size_t Extra = 0); |
| 353 | |
| 354 | private: |
| 355 | bool AccessDeclContextSanity() const; |
| 356 | |
| 357 | |
| 358 | |
| 359 | static ModuleOwnershipKind getModuleOwnershipKindForChildOf(DeclContext *DC) { |
| 360 | if (DC) { |
| 361 | auto *D = cast<Decl>(DC); |
| 362 | auto MOK = D->getModuleOwnershipKind(); |
| 363 | if (MOK != ModuleOwnershipKind::Unowned && |
| 364 | (!D->isFromASTFile() || D->hasLocalOwningModuleStorage())) |
| 365 | return MOK; |
| 366 | |
| 367 | |
| 368 | } |
| 369 | return ModuleOwnershipKind::Unowned; |
| 370 | } |
| 371 | |
| 372 | public: |
| 373 | Decl() = delete; |
| 374 | Decl(const Decl&) = delete; |
| 375 | Decl(Decl &&) = delete; |
| 376 | Decl &operator=(const Decl&) = delete; |
| 377 | Decl &operator=(Decl&&) = delete; |
| 378 | |
| 379 | protected: |
| 380 | Decl(Kind DK, DeclContext *DC, SourceLocation L) |
| 381 | : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)), |
| 382 | DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false), |
| 383 | Implicit(false), Used(false), Referenced(false), |
| 384 | TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0), |
| 385 | IdentifierNamespace(getIdentifierNamespaceForKind(DK)), |
| 386 | CacheValidAndLinkage(0) { |
| 387 | if (StatisticsEnabled) add(DK); |
| 388 | } |
| 389 | |
| 390 | Decl(Kind DK, EmptyShell Empty) |
| 391 | : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false), |
| 392 | Used(false), Referenced(false), TopLevelDeclInObjCContainer(false), |
| 393 | Access(AS_none), FromASTFile(0), |
| 394 | IdentifierNamespace(getIdentifierNamespaceForKind(DK)), |
| 395 | CacheValidAndLinkage(0) { |
| 396 | if (StatisticsEnabled) add(DK); |
| 397 | } |
| 398 | |
| 399 | virtual ~Decl(); |
| 400 | |
| 401 | |
| 402 | void updateOutOfDate(IdentifierInfo &II) const; |
| 403 | |
| 404 | Linkage getCachedLinkage() const { |
| 405 | return Linkage(CacheValidAndLinkage - 1); |
| 406 | } |
| 407 | |
| 408 | void setCachedLinkage(Linkage L) const { |
| 409 | CacheValidAndLinkage = L + 1; |
| 410 | } |
| 411 | |
| 412 | bool hasCachedLinkage() const { |
| 413 | return CacheValidAndLinkage; |
| 414 | } |
| 415 | |
| 416 | public: |
| 417 | |
| 418 | virtual SourceRange getSourceRange() const LLVM_READONLY { |
| 419 | return SourceRange(getLocation(), getLocation()); |
| 420 | } |
| 421 | |
| 422 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 423 | return getSourceRange().getBegin(); |
| 424 | } |
| 425 | |
| 426 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 427 | return getSourceRange().getEnd(); |
| 428 | } |
| 429 | |
| 430 | SourceLocation getLocation() const { return Loc; } |
| 431 | void setLocation(SourceLocation L) { Loc = L; } |
| 432 | |
| 433 | Kind getKind() const { return static_cast<Kind>(DeclKind); } |
| 434 | const char *getDeclKindName() const; |
| 435 | |
| 436 | Decl *getNextDeclInContext() { return NextInContextAndBits.getPointer(); } |
| 437 | const Decl *getNextDeclInContext() const {return NextInContextAndBits.getPointer();} |
| 438 | |
| 439 | DeclContext *getDeclContext() { |
| 440 | if (isInSemaDC()) |
| 441 | return getSemanticDC(); |
| 442 | return getMultipleDC()->SemanticDC; |
| 443 | } |
| 444 | const DeclContext *getDeclContext() const { |
| 445 | return const_cast<Decl*>(this)->getDeclContext(); |
| 446 | } |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | Decl *getNonClosureContext(); |
| 454 | const Decl *getNonClosureContext() const { |
| 455 | return const_cast<Decl*>(this)->getNonClosureContext(); |
| 456 | } |
| 457 | |
| 458 | TranslationUnitDecl *getTranslationUnitDecl(); |
| 459 | const TranslationUnitDecl *getTranslationUnitDecl() const { |
| 460 | return const_cast<Decl*>(this)->getTranslationUnitDecl(); |
| 461 | } |
| 462 | |
| 463 | bool isInAnonymousNamespace() const; |
| 464 | |
| 465 | bool isInStdNamespace() const; |
| 466 | |
| 467 | ASTContext &getASTContext() const LLVM_READONLY; |
| 468 | |
| 469 | |
| 470 | |
| 471 | const LangOptions &getLangOpts() const LLVM_READONLY; |
| 472 | |
| 473 | void setAccess(AccessSpecifier AS) { |
| 474 | Access = AS; |
| 475 | assert(AccessDeclContextSanity()); |
| 476 | } |
| 477 | |
| 478 | AccessSpecifier getAccess() const { |
| 479 | assert(AccessDeclContextSanity()); |
| 480 | return AccessSpecifier(Access); |
| 481 | } |
| 482 | |
| 483 | |
| 484 | |
| 485 | AccessSpecifier getAccessUnsafe() const { |
| 486 | return AccessSpecifier(Access); |
| 487 | } |
| 488 | |
| 489 | bool hasAttrs() const { return HasAttrs; } |
| 490 | |
| 491 | void setAttrs(const AttrVec& Attrs) { |
| 492 | return setAttrsImpl(Attrs, getASTContext()); |
| 493 | } |
| 494 | |
| 495 | AttrVec &getAttrs() { |
| 496 | return const_cast<AttrVec&>(const_cast<const Decl*>(this)->getAttrs()); |
| 497 | } |
| 498 | |
| 499 | const AttrVec &getAttrs() const; |
| 500 | void dropAttrs(); |
| 501 | void addAttr(Attr *A); |
| 502 | |
| 503 | using attr_iterator = AttrVec::const_iterator; |
| 504 | using attr_range = llvm::iterator_range<attr_iterator>; |
| 505 | |
| 506 | attr_range attrs() const { |
| 507 | return attr_range(attr_begin(), attr_end()); |
| 508 | } |
| 509 | |
| 510 | attr_iterator attr_begin() const { |
| 511 | return hasAttrs() ? getAttrs().begin() : nullptr; |
| 512 | } |
| 513 | attr_iterator attr_end() const { |
| 514 | return hasAttrs() ? getAttrs().end() : nullptr; |
| 515 | } |
| 516 | |
| 517 | template <typename T> |
| 518 | void dropAttr() { |
| 519 | if (!HasAttrs) return; |
| 520 | |
| 521 | AttrVec &Vec = getAttrs(); |
| 522 | llvm::erase_if(Vec, [](Attr *A) { return isa<T>(A); }); |
| 523 | |
| 524 | if (Vec.empty()) |
| 525 | HasAttrs = false; |
| 526 | } |
| 527 | |
| 528 | template <typename T> |
| 529 | llvm::iterator_range<specific_attr_iterator<T>> specific_attrs() const { |
| 530 | return llvm::make_range(specific_attr_begin<T>(), specific_attr_end<T>()); |
| 531 | } |
| 532 | |
| 533 | template <typename T> |
| 534 | specific_attr_iterator<T> specific_attr_begin() const { |
| 535 | return specific_attr_iterator<T>(attr_begin()); |
| 536 | } |
| 537 | |
| 538 | template <typename T> |
| 539 | specific_attr_iterator<T> specific_attr_end() const { |
| 540 | return specific_attr_iterator<T>(attr_end()); |
| 541 | } |
| 542 | |
| 543 | template<typename T> T *getAttr() const { |
| 544 | return hasAttrs() ? getSpecificAttr<T>(getAttrs()) : nullptr; |
| 545 | } |
| 546 | |
| 547 | template<typename T> bool hasAttr() const { |
| 548 | return hasAttrs() && hasSpecificAttr<T>(getAttrs()); |
| 549 | } |
| 550 | |
| 551 | |
| 552 | |
| 553 | unsigned getMaxAlignment() const; |
| 554 | |
| 555 | |
| 556 | |
| 557 | void setInvalidDecl(bool Invalid = true); |
| 558 | bool isInvalidDecl() const { return (bool) InvalidDecl; } |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | bool isImplicit() const { return Implicit; } |
| 564 | void setImplicit(bool I = true) { Implicit = I; } |
| 565 | |
| 566 | |
| 567 | |
| 568 | |
| 569 | |
| 570 | |
| 571 | |
| 572 | bool isUsed(bool CheckUsedAttr = true) const; |
| 573 | |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | void setIsUsed() { getCanonicalDecl()->Used = true; } |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | void markUsed(ASTContext &C); |
| 585 | |
| 586 | |
| 587 | bool isReferenced() const; |
| 588 | |
| 589 | |
| 590 | |
| 591 | bool isThisDeclarationReferenced() const { return Referenced; } |
| 592 | |
| 593 | void setReferenced(bool R = true) { Referenced = R; } |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | bool isTopLevelDeclInObjCContainer() const { |
| 599 | return TopLevelDeclInObjCContainer; |
| 600 | } |
| 601 | |
| 602 | void setTopLevelDeclInObjCContainer(bool V = true) { |
| 603 | TopLevelDeclInObjCContainer = V; |
| 604 | } |
| 605 | |
| 606 | |
| 607 | |
| 608 | ExternalSourceSymbolAttr *getExternalSourceSymbolAttr() const; |
| 609 | |
| 610 | |
| 611 | |
| 612 | bool isModulePrivate() const { |
| 613 | return getModuleOwnershipKind() == ModuleOwnershipKind::ModulePrivate; |
| 614 | } |
| 615 | |
| 616 | |
| 617 | |
| 618 | bool hasDefiningAttr() const; |
| 619 | |
| 620 | |
| 621 | const Attr *getDefiningAttr() const; |
| 622 | |
| 623 | protected: |
| 624 | |
| 625 | |
| 626 | void setModulePrivate() { |
| 627 | |
| 628 | |
| 629 | if (getModuleOwnershipKind() == ModuleOwnershipKind::Unowned) |
| 630 | return; |
| 631 | setModuleOwnershipKind(ModuleOwnershipKind::ModulePrivate); |
| 632 | } |
| 633 | |
| 634 | public: |
| 635 | |
| 636 | |
| 637 | |
| 638 | void setFromASTFile() { |
| 639 | FromASTFile = true; |
| 640 | } |
| 641 | |
| 642 | |
| 643 | |
| 644 | void setOwningModuleID(unsigned ID) { |
| 645 | assert(isFromASTFile() && "Only works on a deserialized declaration"); |
| 646 | *((unsigned*)this - 2) = ID; |
| 647 | } |
| 648 | |
| 649 | public: |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | |
| 655 | |
| 656 | |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
| 667 | AvailabilityResult |
| 668 | getAvailability(std::string *Message = nullptr, |
| 669 | VersionTuple EnclosingVersion = VersionTuple(), |
| 670 | StringRef *RealizedPlatform = nullptr) const; |
| 671 | |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | VersionTuple getVersionIntroduced() const; |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | |
| 684 | |
| 685 | bool isDeprecated(std::string *Message = nullptr) const { |
| 686 | return getAvailability(Message) == AR_Deprecated; |
| 687 | } |
| 688 | |
| 689 | |
| 690 | |
| 691 | |
| 692 | |
| 693 | |
| 694 | bool isUnavailable(std::string *Message = nullptr) const { |
| 695 | return getAvailability(Message) == AR_Unavailable; |
| 696 | } |
| 697 | |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | bool isWeakImported() const; |
| 705 | |
| 706 | |
| 707 | |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | bool canBeWeakImported(bool &IsDefinition) const; |
| 713 | |
| 714 | |
| 715 | |
| 716 | bool isFromASTFile() const { return FromASTFile; } |
| 717 | |
| 718 | |
| 719 | |
| 720 | unsigned getGlobalID() const { |
| 721 | if (isFromASTFile()) |
| 722 | return *((const unsigned*)this - 1); |
| 723 | return 0; |
| 724 | } |
| 725 | |
| 726 | |
| 727 | |
| 728 | unsigned getOwningModuleID() const { |
| 729 | if (isFromASTFile()) |
| 730 | return *((const unsigned*)this - 2); |
| 731 | return 0; |
| 732 | } |
| 733 | |
| 734 | private: |
| 735 | Module *getOwningModuleSlow() const; |
| 736 | |
| 737 | protected: |
| 738 | bool hasLocalOwningModuleStorage() const; |
| 739 | |
| 740 | public: |
| 741 | |
| 742 | |
| 743 | Module *getImportedOwningModule() const { |
| 744 | if (!isFromASTFile() || !hasOwningModule()) |
| 745 | return nullptr; |
| 746 | |
| 747 | return getOwningModuleSlow(); |
| 748 | } |
| 749 | |
| 750 | |
| 751 | |
| 752 | Module *getLocalOwningModule() const { |
| 753 | if (isFromASTFile() || !hasOwningModule()) |
| 754 | return nullptr; |
| 755 | |
| 756 | assert(hasLocalOwningModuleStorage() && |
| 757 | "owned local decl but no local module storage"); |
| 758 | return reinterpret_cast<Module *const *>(this)[-1]; |
| 759 | } |
| 760 | void setLocalOwningModule(Module *M) { |
| 761 | assert(!isFromASTFile() && hasOwningModule() && |
| 762 | hasLocalOwningModuleStorage() && |
| 763 | "should not have a cached owning module"); |
| 764 | reinterpret_cast<Module **>(this)[-1] = M; |
| 765 | } |
| 766 | |
| 767 | |
| 768 | bool hasOwningModule() const { |
| 769 | return getModuleOwnershipKind() != ModuleOwnershipKind::Unowned; |
| 770 | } |
| 771 | |
| 772 | |
| 773 | Module *getOwningModule() const { |
| 774 | return isFromASTFile() ? getImportedOwningModule() : getLocalOwningModule(); |
| 775 | } |
| 776 | |
| 777 | |
| 778 | |
| 779 | |
| 780 | |
| 781 | |
| 782 | Module *getOwningModuleForLinkage(bool IgnoreLinkage = false) const; |
| 783 | |
| 784 | |
| 785 | |
| 786 | |
| 787 | |
| 788 | |
| 789 | bool isUnconditionallyVisible() const { |
| 790 | return (int)getModuleOwnershipKind() <= (int)ModuleOwnershipKind::Visible; |
| 791 | } |
| 792 | |
| 793 | |
| 794 | |
| 795 | void setVisibleDespiteOwningModule() { |
| 796 | if (!isUnconditionallyVisible()) |
| 797 | setModuleOwnershipKind(ModuleOwnershipKind::Visible); |
| 798 | } |
| 799 | |
| 800 | |
| 801 | ModuleOwnershipKind getModuleOwnershipKind() const { |
| 802 | return NextInContextAndBits.getInt(); |
| 803 | } |
| 804 | |
| 805 | |
| 806 | void setModuleOwnershipKind(ModuleOwnershipKind MOK) { |
| 807 | assert(!(getModuleOwnershipKind() == ModuleOwnershipKind::Unowned && |
| 808 | MOK != ModuleOwnershipKind::Unowned && !isFromASTFile() && |
| 809 | !hasLocalOwningModuleStorage()) && |
| 810 | "no storage available for owning module for this declaration"); |
| 811 | NextInContextAndBits.setInt(MOK); |
| 812 | } |
| 813 | |
| 814 | unsigned getIdentifierNamespace() const { |
| 815 | return IdentifierNamespace; |
| 816 | } |
| 817 | |
| 818 | bool isInIdentifierNamespace(unsigned NS) const { |
| 819 | return getIdentifierNamespace() & NS; |
| 820 | } |
| 821 | |
| 822 | static unsigned getIdentifierNamespaceForKind(Kind DK); |
| 823 | |
| 824 | bool hasTagIdentifierNamespace() const { |
| 825 | return isTagIdentifierNamespace(getIdentifierNamespace()); |
| 826 | } |
| 827 | |
| 828 | static bool isTagIdentifierNamespace(unsigned NS) { |
| 829 | |
| 830 | return (NS & ~IDNS_TagFriend) == (IDNS_Tag | IDNS_Type); |
| 831 | } |
| 832 | |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | |
| 843 | DeclContext *getLexicalDeclContext() { |
| 844 | if (isInSemaDC()) |
| 845 | return getSemanticDC(); |
| 846 | return getMultipleDC()->LexicalDC; |
| 847 | } |
| 848 | const DeclContext *getLexicalDeclContext() const { |
| 849 | return const_cast<Decl*>(this)->getLexicalDeclContext(); |
| 850 | } |
| 851 | |
| 852 | |
| 853 | |
| 854 | virtual bool isOutOfLine() const; |
| 855 | |
| 856 | |
| 857 | |
| 858 | void setDeclContext(DeclContext *DC); |
| 859 | |
| 860 | void setLexicalDeclContext(DeclContext *DC); |
| 861 | |
| 862 | |
| 863 | |
| 864 | bool isTemplated() const; |
| 865 | |
| 866 | |
| 867 | |
| 868 | unsigned getTemplateDepth() const; |
| 869 | |
| 870 | |
| 871 | |
| 872 | |
| 873 | |
| 874 | bool isDefinedOutsideFunctionOrMethod() const { |
| 875 | return getParentFunctionOrMethod() == nullptr; |
| 876 | } |
| 877 | |
| 878 | |
| 879 | |
| 880 | |
| 881 | |
| 882 | |
| 883 | |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | |
| 889 | |
| 890 | bool isInLocalScopeForInstantiation() const; |
| 891 | |
| 892 | |
| 893 | |
| 894 | const DeclContext *getParentFunctionOrMethod() const; |
| 895 | DeclContext *getParentFunctionOrMethod() { |
| 896 | return const_cast<DeclContext*>( |
| 897 | const_cast<const Decl*>(this)->getParentFunctionOrMethod()); |
| 898 | } |
| 899 | |
| 900 | |
| 901 | virtual Decl *getCanonicalDecl() { return this; } |
| 902 | const Decl *getCanonicalDecl() const { |
| 903 | return const_cast<Decl*>(this)->getCanonicalDecl(); |
| 904 | } |
| 905 | |
| 906 | |
| 907 | bool isCanonicalDecl() const { return getCanonicalDecl() == this; } |
| 908 | |
| 909 | protected: |
| 910 | |
| 911 | |
| 912 | |
| 913 | |
| 914 | virtual Decl *getNextRedeclarationImpl() { return this; } |
| 915 | |
| 916 | |
| 917 | |
| 918 | virtual Decl *getPreviousDeclImpl() { return nullptr; } |
| 919 | |
| 920 | |
| 921 | |
| 922 | virtual Decl *getMostRecentDeclImpl() { return this; } |
| 923 | |
| 924 | public: |
| 925 | |
| 926 | class redecl_iterator { |
| 927 | |
| 928 | Decl *Current = nullptr; |
| 929 | Decl *Starter; |
| 930 | |
| 931 | public: |
| 932 | using value_type = Decl *; |
| 933 | using reference = const value_type &; |
| 934 | using pointer = const value_type *; |
| 935 | using iterator_category = std::forward_iterator_tag; |
| 936 | using difference_type = std::ptrdiff_t; |
| 937 | |
| 938 | redecl_iterator() = default; |
| 939 | explicit redecl_iterator(Decl *C) : Current(C), Starter(C) {} |
| 940 | |
| 941 | reference operator*() const { return Current; } |
| 942 | value_type operator->() const { return Current; } |
| 943 | |
| 944 | redecl_iterator& operator++() { |
| 945 | assert(Current && "Advancing while iterator has reached end"); |
| 946 | |
| 947 | Decl *Next = Current->getNextRedeclarationImpl(); |
| 948 | assert(Next && "Should return next redeclaration or itself, never null!"); |
| 949 | Current = (Next != Starter) ? Next : nullptr; |
| 950 | return *this; |
| 951 | } |
| 952 | |
| 953 | redecl_iterator operator++(int) { |
| 954 | redecl_iterator tmp(*this); |
| 955 | ++(*this); |
| 956 | return tmp; |
| 957 | } |
| 958 | |
| 959 | friend bool operator==(redecl_iterator x, redecl_iterator y) { |
| 960 | return x.Current == y.Current; |
| 961 | } |
| 962 | |
| 963 | friend bool operator!=(redecl_iterator x, redecl_iterator y) { |
| 964 | return x.Current != y.Current; |
| 965 | } |
| 966 | }; |
| 967 | |
| 968 | using redecl_range = llvm::iterator_range<redecl_iterator>; |
| 969 | |
| 970 | |
| 971 | |
| 972 | redecl_range redecls() const { |
| 973 | return redecl_range(redecls_begin(), redecls_end()); |
| 974 | } |
| 975 | |
| 976 | redecl_iterator redecls_begin() const { |
| 977 | return redecl_iterator(const_cast<Decl *>(this)); |
| 978 | } |
| 979 | |
| 980 | redecl_iterator redecls_end() const { return redecl_iterator(); } |
| 981 | |
| 982 | |
| 983 | |
| 984 | Decl *getPreviousDecl() { return getPreviousDeclImpl(); } |
| 985 | |
| 986 | |
| 987 | |
| 988 | const Decl *getPreviousDecl() const { |
| 989 | return const_cast<Decl *>(this)->getPreviousDeclImpl(); |
| 990 | } |
| 991 | |
| 992 | |
| 993 | bool isFirstDecl() const { |
| 994 | return getPreviousDecl() == nullptr; |
| 995 | } |
| 996 | |
| 997 | |
| 998 | |
| 999 | Decl *getMostRecentDecl() { return getMostRecentDeclImpl(); } |
| 1000 | |
| 1001 | |
| 1002 | |
| 1003 | const Decl *getMostRecentDecl() const { |
| 1004 | return const_cast<Decl *>(this)->getMostRecentDeclImpl(); |
| 1005 | } |
| 1006 | |
| 1007 | |
| 1008 | |
| 1009 | |
| 1010 | virtual Stmt* getBody() const { return nullptr; } |
| 1011 | |
| 1012 | |
| 1013 | |
| 1014 | |
| 1015 | |
| 1016 | virtual bool hasBody() const { return getBody() != nullptr; } |
| 1017 | |
| 1018 | |
| 1019 | |
| 1020 | SourceLocation getBodyRBrace() const; |
| 1021 | |
| 1022 | |
| 1023 | static void add(Kind k); |
| 1024 | static void EnableStatistics(); |
| 1025 | static void PrintStats(); |
| 1026 | |
| 1027 | |
| 1028 | |
| 1029 | bool isTemplateParameter() const; |
| 1030 | |
| 1031 | |
| 1032 | |
| 1033 | bool isTemplateParameterPack() const; |
| 1034 | |
| 1035 | |
| 1036 | bool isParameterPack() const; |
| 1037 | |
| 1038 | |
| 1039 | bool isTemplateDecl() const; |
| 1040 | |
| 1041 | |
| 1042 | bool isFunctionOrFunctionTemplate() const { |
| 1043 | return (DeclKind >= Decl::firstFunction && |
| 1044 | DeclKind <= Decl::lastFunction) || |
| 1045 | DeclKind == FunctionTemplate; |
| 1046 | } |
| 1047 | |
| 1048 | |
| 1049 | |
| 1050 | |
| 1051 | |
| 1052 | |
| 1053 | |
| 1054 | TemplateDecl *getDescribedTemplate() const; |
| 1055 | |
| 1056 | |
| 1057 | |
| 1058 | const TemplateParameterList *getDescribedTemplateParams() const; |
| 1059 | |
| 1060 | |
| 1061 | |
| 1062 | FunctionDecl *getAsFunction() LLVM_READONLY; |
| 1063 | |
| 1064 | const FunctionDecl *getAsFunction() const { |
| 1065 | return const_cast<Decl *>(this)->getAsFunction(); |
| 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | |
| 1070 | |
| 1071 | |
| 1072 | |
| 1073 | |
| 1074 | void setLocalExternDecl() { |
| 1075 | Decl *Prev = getPreviousDecl(); |
| 1076 | IdentifierNamespace &= ~IDNS_Ordinary; |
| 1077 | |
| 1078 | |
| 1079 | |
| 1080 | |
| 1081 | assert((IdentifierNamespace & ~(IDNS_OrdinaryFriend | IDNS_Tag)) == 0 && |
| 1082 | "namespace is not ordinary"); |
| 1083 | |
| 1084 | IdentifierNamespace |= IDNS_LocalExtern; |
| 1085 | if (Prev && Prev->getIdentifierNamespace() & IDNS_Ordinary) |
| 1086 | IdentifierNamespace |= IDNS_Ordinary; |
| 1087 | } |
| 1088 | |
| 1089 | |
| 1090 | |
| 1091 | |
| 1092 | bool isLocalExternDecl() { |
| 1093 | return IdentifierNamespace & IDNS_LocalExtern; |
| 1094 | } |
| 1095 | |
| 1096 | |
| 1097 | |
| 1098 | |
| 1099 | |
| 1100 | |
| 1101 | |
| 1102 | |
| 1103 | void setObjectOfFriendDecl(bool PerformFriendInjection = false) { |
| 1104 | unsigned OldNS = IdentifierNamespace; |
| 1105 | assert((OldNS & (IDNS_Tag | IDNS_Ordinary | |
| 1106 | IDNS_TagFriend | IDNS_OrdinaryFriend | |
| 1107 | IDNS_LocalExtern | IDNS_NonMemberOperator)) && |
| 1108 | "namespace includes neither ordinary nor tag"); |
| 1109 | assert(!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type | |
| 1110 | IDNS_TagFriend | IDNS_OrdinaryFriend | |
| 1111 | IDNS_LocalExtern | IDNS_NonMemberOperator)) && |
| 1112 | "namespace includes other than ordinary or tag"); |
| 1113 | |
| 1114 | Decl *Prev = getPreviousDecl(); |
| 1115 | IdentifierNamespace &= ~(IDNS_Ordinary | IDNS_Tag | IDNS_Type); |
| 1116 | |
| 1117 | if (OldNS & (IDNS_Tag | IDNS_TagFriend)) { |
| 1118 | IdentifierNamespace |= IDNS_TagFriend; |
| 1119 | if (PerformFriendInjection || |
| 1120 | (Prev && Prev->getIdentifierNamespace() & IDNS_Tag)) |
| 1121 | IdentifierNamespace |= IDNS_Tag | IDNS_Type; |
| 1122 | } |
| 1123 | |
| 1124 | if (OldNS & (IDNS_Ordinary | IDNS_OrdinaryFriend | |
| 1125 | IDNS_LocalExtern | IDNS_NonMemberOperator)) { |
| 1126 | IdentifierNamespace |= IDNS_OrdinaryFriend; |
| 1127 | if (PerformFriendInjection || |
| 1128 | (Prev && Prev->getIdentifierNamespace() & IDNS_Ordinary)) |
| 1129 | IdentifierNamespace |= IDNS_Ordinary; |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | enum FriendObjectKind { |
| 1134 | FOK_None, |
| 1135 | FOK_Declared, |
| 1136 | FOK_Undeclared |
| 1137 | }; |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | |
| 1142 | |
| 1143 | FriendObjectKind getFriendObjectKind() const { |
| 1144 | unsigned mask = |
| 1145 | (IdentifierNamespace & (IDNS_TagFriend | IDNS_OrdinaryFriend)); |
| 1146 | if (!mask) return FOK_None; |
| 1147 | return (IdentifierNamespace & (IDNS_Tag | IDNS_Ordinary) ? FOK_Declared |
| 1148 | : FOK_Undeclared); |
| 1149 | } |
| 1150 | |
| 1151 | |
| 1152 | void setNonMemberOperator() { |
| 1153 | assert(getKind() == Function || getKind() == FunctionTemplate); |
| 1154 | assert((IdentifierNamespace & IDNS_Ordinary) && |
| 1155 | "visible non-member operators should be in ordinary namespace"); |
| 1156 | IdentifierNamespace |= IDNS_NonMemberOperator; |
| 1157 | } |
| 1158 | |
| 1159 | static bool classofKind(Kind K) { return true; } |
| 1160 | static DeclContext *castToDeclContext(const Decl *); |
| 1161 | static Decl *castFromDeclContext(const DeclContext *); |
| 1162 | |
| 1163 | void print(raw_ostream &Out, unsigned Indentation = 0, |
| 1164 | bool PrintInstantiation = false) const; |
| 1165 | void print(raw_ostream &Out, const PrintingPolicy &Policy, |
| 1166 | unsigned Indentation = 0, bool PrintInstantiation = false) const; |
| 1167 | static void printGroup(Decl** Begin, unsigned NumDecls, |
| 1168 | raw_ostream &Out, const PrintingPolicy &Policy, |
| 1169 | unsigned Indentation = 0); |
| 1170 | |
| 1171 | |
| 1172 | void dump() const; |
| 1173 | |
| 1174 | |
| 1175 | void dumpColor() const; |
| 1176 | |
| 1177 | void dump(raw_ostream &Out, bool Deserialize = false, |
| 1178 | ASTDumpOutputFormat OutputFormat = ADOF_Default) const; |
| 1179 | |
| 1180 | |
| 1181 | int64_t getID() const; |
| 1182 | |
| 1183 | |
| 1184 | |
| 1185 | |
| 1186 | const FunctionType *getFunctionType(bool BlocksToo = true) const; |
| 1187 | |
| 1188 | private: |
| 1189 | void setAttrsImpl(const AttrVec& Attrs, ASTContext &Ctx); |
| 1190 | void setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC, |
| 1191 | ASTContext &Ctx); |
| 1192 | |
| 1193 | protected: |
| 1194 | ASTMutationListener *getASTMutationListener() const; |
| 1195 | }; |
| 1196 | |
| 1197 | |
| 1198 | inline bool declaresSameEntity(const Decl *D1, const Decl *D2) { |
| 1199 | if (!D1 || !D2) |
| 1200 | return false; |
| 1201 | |
| 1202 | if (D1 == D2) |
| 1203 | return true; |
| 1204 | |
| 1205 | return D1->getCanonicalDecl() == D2->getCanonicalDecl(); |
| 1206 | } |
| 1207 | |
| 1208 | |
| 1209 | |
| 1210 | class PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry { |
| 1211 | const Decl *TheDecl; |
| 1212 | SourceLocation Loc; |
| 1213 | SourceManager &SM; |
| 1214 | const char *Message; |
| 1215 | |
| 1216 | public: |
| 1217 | PrettyStackTraceDecl(const Decl *theDecl, SourceLocation L, |
| 1218 | SourceManager &sm, const char *Msg) |
| 1219 | : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {} |
| 1220 | |
| 1221 | void print(raw_ostream &OS) const override; |
| 1222 | }; |
| 1223 | } |
| 1224 | |
| 1225 | |
| 1226 | |
| 1227 | namespace llvm { |
| 1228 | template <> struct PointerLikeTypeTraits<::clang::NamedDecl *> { |
| 1229 | static inline void *getAsVoidPointer(::clang::NamedDecl *P) { return P; } |
| 1230 | static inline ::clang::NamedDecl *getFromVoidPointer(void *P) { |
| 1231 | return static_cast<::clang::NamedDecl *>(P); |
| 1232 | } |
| 1233 | static constexpr int NumLowBitsAvailable = 3; |
| 1234 | }; |
| 1235 | } |
| 1236 | |
| 1237 | namespace clang { |
| 1238 | |
| 1239 | class DeclListNode { |
| 1240 | friend class ASTContext; |
| 1241 | friend class StoredDeclsList; |
| 1242 | public: |
| 1243 | using Decls = llvm::PointerUnion<NamedDecl*, DeclListNode*>; |
| 1244 | class iterator { |
| 1245 | friend class DeclContextLookupResult; |
| 1246 | friend class StoredDeclsList; |
| 1247 | |
| 1248 | Decls Ptr; |
| 1249 | iterator(Decls Node) : Ptr(Node) { } |
| 1250 | public: |
| 1251 | using difference_type = ptrdiff_t; |
| 1252 | using value_type = NamedDecl*; |
| 1253 | using pointer = void; |
| 1254 | using reference = value_type; |
| 1255 | using iterator_category = std::forward_iterator_tag; |
| 1256 | |
| 1257 | iterator() = default; |
| 1258 | |
| 1259 | reference operator*() const { |
| 1260 | assert(Ptr && "dereferencing end() iterator"); |
| 1261 | if (DeclListNode *CurNode = Ptr.dyn_cast<DeclListNode*>()) |
| 1262 | return CurNode->D; |
| 1263 | return Ptr.get<NamedDecl*>(); |
| 1264 | } |
| 1265 | void operator->() const { } |
| 1266 | bool operator==(const iterator &X) const { return Ptr == X.Ptr; } |
| 1267 | bool operator!=(const iterator &X) const { return Ptr != X.Ptr; } |
| 1268 | inline iterator &operator++() { |
| 1269 | assert(!Ptr.isNull() && "Advancing empty iterator"); |
| 1270 | |
| 1271 | if (DeclListNode *CurNode = Ptr.dyn_cast<DeclListNode*>()) |
| 1272 | Ptr = CurNode->Rest; |
| 1273 | else |
| 1274 | Ptr = nullptr; |
| 1275 | return *this; |
| 1276 | } |
| 1277 | iterator operator++(int) { |
| 1278 | iterator temp = *this; |
| 1279 | ++(*this); |
| 1280 | return temp; |
| 1281 | } |
| 1282 | |
| 1283 | iterator end() { return iterator(); } |
| 1284 | }; |
| 1285 | private: |
| 1286 | NamedDecl *D = nullptr; |
| 1287 | Decls Rest = nullptr; |
| 1288 | DeclListNode(NamedDecl *ND) : D(ND) {} |
| 1289 | }; |
| 1290 | |
| 1291 | |
| 1292 | class DeclContextLookupResult { |
| 1293 | using Decls = DeclListNode::Decls; |
| 1294 | |
| 1295 | |
| 1296 | Decls Result; |
| 1297 | |
| 1298 | public: |
| 1299 | DeclContextLookupResult() = default; |
| 1300 | DeclContextLookupResult(Decls Result) : Result(Result) {} |
| 1301 | |
| 1302 | using iterator = DeclListNode::iterator; |
| 1303 | using const_iterator = iterator; |
| 1304 | using reference = iterator::reference; |
| 1305 | |
| 1306 | iterator begin() { return iterator(Result); } |
| 1307 | iterator end() { return iterator(); } |
| 1308 | const_iterator begin() const { |
| 1309 | return const_cast<DeclContextLookupResult*>(this)->begin(); |
| 1310 | } |
| 1311 | const_iterator end() const { return iterator(); } |
| 1312 | |
| 1313 | bool empty() const { return Result.isNull(); } |
| 1314 | bool isSingleResult() const { return Result.dyn_cast<NamedDecl*>(); } |
| 1315 | reference front() const { return *begin(); } |
| 1316 | |
| 1317 | |
| 1318 | |
| 1319 | |
| 1320 | |
| 1321 | template<class T> T *find_first() const { |
| 1322 | for (auto *D : *this) |
| 1323 | if (T *Decl = dyn_cast<T>(D)) |
| 1324 | return Decl; |
| 1325 | |
| 1326 | return nullptr; |
| 1327 | } |
| 1328 | }; |
| 1329 | |
| 1330 | |
| 1331 | |
| 1332 | |
| 1333 | |
| 1334 | |
| 1335 | |
| 1336 | |
| 1337 | |
| 1338 | |
| 1339 | |
| 1340 | |
| 1341 | |
| 1342 | |
| 1343 | |
| 1344 | |
| 1345 | |
| 1346 | |
| 1347 | class DeclContext { |
| 1348 | |
| 1349 | friend class ASTDeclReader; |
| 1350 | |
| 1351 | |
| 1352 | friend class ExternalASTSource; |
| 1353 | |
| 1354 | friend class DependentDiagnostic; |
| 1355 | |
| 1356 | |
| 1357 | friend class ASTWriter; |
| 1358 | |
| 1359 | |
| 1360 | |
| 1361 | |
| 1362 | |
| 1363 | |
| 1364 | |
| 1365 | class DeclContextBitfields { |
| 1366 | friend class DeclContext; |
| 1367 | |
| 1368 | uint64_t DeclKind : 7; |
| 1369 | |
| 1370 | |
| 1371 | |
| 1372 | |
| 1373 | mutable uint64_t ExternalLexicalStorage : 1; |
| 1374 | |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | mutable uint64_t ExternalVisibleStorage : 1; |
| 1379 | |
| 1380 | |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | mutable uint64_t NeedToReconcileExternalVisibleStorage : 1; |
| 1385 | |
| 1386 | |
| 1387 | |
| 1388 | mutable uint64_t HasLazyLocalLexicalLookups : 1; |
| 1389 | |
| 1390 | |
| 1391 | |
| 1392 | mutable uint64_t HasLazyExternalLexicalLookups : 1; |
| 1393 | |
| 1394 | |
| 1395 | |
| 1396 | |
| 1397 | mutable uint64_t UseQualifiedLookup : 1; |
| 1398 | }; |
| 1399 | |
| 1400 | |
| 1401 | enum { NumDeclContextBits = 13 }; |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | |
| 1406 | class TagDeclBitfields { |
| 1407 | friend class TagDecl; |
| 1408 | |
| 1409 | uint64_t : NumDeclContextBits; |
| 1410 | |
| 1411 | |
| 1412 | uint64_t TagDeclKind : 3; |
| 1413 | |
| 1414 | |
| 1415 | |
| 1416 | |
| 1417 | uint64_t IsCompleteDefinition : 1; |
| 1418 | |
| 1419 | |
| 1420 | uint64_t IsBeingDefined : 1; |
| 1421 | |
| 1422 | |
| 1423 | |
| 1424 | uint64_t IsEmbeddedInDeclarator : 1; |
| 1425 | |
| 1426 | |
| 1427 | uint64_t IsFreeStanding : 1; |
| 1428 | |
| 1429 | |
| 1430 | |
| 1431 | |
| 1432 | |
| 1433 | uint64_t MayHaveOutOfDateDef : 1; |
| 1434 | |
| 1435 | |
| 1436 | |
| 1437 | uint64_t IsCompleteDefinitionRequired : 1; |
| 1438 | }; |
| 1439 | |
| 1440 | |
| 1441 | enum { NumTagDeclBits = 9 }; |
| 1442 | |
| 1443 | |
| 1444 | |
| 1445 | |
| 1446 | class EnumDeclBitfields { |
| 1447 | friend class EnumDecl; |
| 1448 | |
| 1449 | uint64_t : NumDeclContextBits; |
| 1450 | |
| 1451 | uint64_t : NumTagDeclBits; |
| 1452 | |
| 1453 | |
| 1454 | |
| 1455 | uint64_t NumPositiveBits : 8; |
| 1456 | |
| 1457 | |
| 1458 | |
| 1459 | uint64_t NumNegativeBits : 8; |
| 1460 | |
| 1461 | |
| 1462 | |
| 1463 | uint64_t IsScoped : 1; |
| 1464 | |
| 1465 | |
| 1466 | |
| 1467 | |
| 1468 | |
| 1469 | uint64_t IsScopedUsingClassTag : 1; |
| 1470 | |
| 1471 | |
| 1472 | |
| 1473 | uint64_t IsFixed : 1; |
| 1474 | |
| 1475 | |
| 1476 | uint64_t HasODRHash : 1; |
| 1477 | }; |
| 1478 | |
| 1479 | |
| 1480 | enum { NumEnumDeclBits = 20 }; |
| 1481 | |
| 1482 | |
| 1483 | |
| 1484 | |
| 1485 | class RecordDeclBitfields { |
| 1486 | friend class RecordDecl; |
| 1487 | |
| 1488 | uint64_t : NumDeclContextBits; |
| 1489 | |
| 1490 | uint64_t : NumTagDeclBits; |
| 1491 | |
| 1492 | |
| 1493 | |
| 1494 | |
| 1495 | uint64_t HasFlexibleArrayMember : 1; |
| 1496 | |
| 1497 | |
| 1498 | uint64_t AnonymousStructOrUnion : 1; |
| 1499 | |
| 1500 | |
| 1501 | |
| 1502 | uint64_t HasObjectMember : 1; |
| 1503 | |
| 1504 | |
| 1505 | |
| 1506 | uint64_t HasVolatileMember : 1; |
| 1507 | |
| 1508 | |
| 1509 | |
| 1510 | |
| 1511 | |
| 1512 | mutable uint64_t LoadedFieldsFromExternalStorage : 1; |
| 1513 | |
| 1514 | |
| 1515 | uint64_t NonTrivialToPrimitiveDefaultInitialize : 1; |
| 1516 | uint64_t NonTrivialToPrimitiveCopy : 1; |
| 1517 | uint64_t NonTrivialToPrimitiveDestroy : 1; |
| 1518 | |
| 1519 | |
| 1520 | |
| 1521 | |
| 1522 | uint64_t HasNonTrivialToPrimitiveDefaultInitializeCUnion : 1; |
| 1523 | uint64_t HasNonTrivialToPrimitiveDestructCUnion : 1; |
| 1524 | uint64_t HasNonTrivialToPrimitiveCopyCUnion : 1; |
| 1525 | |
| 1526 | |
| 1527 | uint64_t ParamDestroyedInCallee : 1; |
| 1528 | |
| 1529 | |
| 1530 | uint64_t ArgPassingRestrictions : 2; |
| 1531 | }; |
| 1532 | |
| 1533 | |
| 1534 | enum { NumRecordDeclBits = 14 }; |
| 1535 | |
| 1536 | |
| 1537 | |
| 1538 | |
| 1539 | class OMPDeclareReductionDeclBitfields { |
| 1540 | friend class OMPDeclareReductionDecl; |
| 1541 | |
| 1542 | uint64_t : NumDeclContextBits; |
| 1543 | |
| 1544 | |
| 1545 | |
| 1546 | uint64_t InitializerKind : 2; |
| 1547 | }; |
| 1548 | |
| 1549 | |
| 1550 | enum { NumOMPDeclareReductionDeclBits = 2 }; |
| 1551 | |
| 1552 | |
| 1553 | |
| 1554 | |
| 1555 | |
| 1556 | class FunctionDeclBitfields { |
| 1557 | friend class FunctionDecl; |
| 1558 | |
| 1559 | friend class CXXDeductionGuideDecl; |
| 1560 | |
| 1561 | uint64_t : NumDeclContextBits; |
| 1562 | |
| 1563 | uint64_t SClass : 3; |
| 1564 | uint64_t IsInline : 1; |
| 1565 | uint64_t IsInlineSpecified : 1; |
| 1566 | |
| 1567 | uint64_t IsVirtualAsWritten : 1; |
| 1568 | uint64_t IsPure : 1; |
| 1569 | uint64_t HasInheritedPrototype : 1; |
| 1570 | uint64_t HasWrittenPrototype : 1; |
| 1571 | uint64_t IsDeleted : 1; |
| 1572 | |
| 1573 | uint64_t IsTrivial : 1; |
| 1574 | |
| 1575 | |
| 1576 | |
| 1577 | |
| 1578 | uint64_t IsTrivialForCall : 1; |
| 1579 | |
| 1580 | uint64_t IsDefaulted : 1; |
| 1581 | uint64_t IsExplicitlyDefaulted : 1; |
| 1582 | uint64_t HasDefaultedFunctionInfo : 1; |
| 1583 | uint64_t HasImplicitReturnZero : 1; |
| 1584 | uint64_t IsLateTemplateParsed : 1; |
| 1585 | |
| 1586 | |
| 1587 | uint64_t ConstexprKind : 2; |
| 1588 | uint64_t InstantiationIsPending : 1; |
| 1589 | |
| 1590 | |
| 1591 | uint64_t UsesSEHTry : 1; |
| 1592 | |
| 1593 | |
| 1594 | |
| 1595 | uint64_t HasSkippedBody : 1; |
| 1596 | |
| 1597 | |
| 1598 | |
| 1599 | uint64_t WillHaveBody : 1; |
| 1600 | |
| 1601 | |
| 1602 | |
| 1603 | uint64_t IsMultiVersion : 1; |
| 1604 | |
| 1605 | |
| 1606 | |
| 1607 | |
| 1608 | uint64_t IsCopyDeductionCandidate : 1; |
| 1609 | |
| 1610 | |
| 1611 | uint64_t HasODRHash : 1; |
| 1612 | |
| 1613 | |
| 1614 | uint64_t UsesFPIntrin : 1; |
| 1615 | }; |
| 1616 | |
| 1617 | |
| 1618 | enum { NumFunctionDeclBits = 27 }; |
| 1619 | |
| 1620 | |
| 1621 | |
| 1622 | |
| 1623 | class CXXConstructorDeclBitfields { |
| 1624 | friend class CXXConstructorDecl; |
| 1625 | |
| 1626 | uint64_t : NumDeclContextBits; |
| 1627 | |
| 1628 | uint64_t : NumFunctionDeclBits; |
| 1629 | |
| 1630 | |
| 1631 | |
| 1632 | |
| 1633 | |
| 1634 | |
| 1635 | uint64_t NumCtorInitializers : 21; |
| 1636 | uint64_t IsInheritingConstructor : 1; |
| 1637 | |
| 1638 | |
| 1639 | uint64_t HasTrailingExplicitSpecifier : 1; |
| 1640 | |
| 1641 | |
| 1642 | uint64_t IsSimpleExplicit : 1; |
| 1643 | }; |
| 1644 | |
| 1645 | |
| 1646 | enum { |
| 1647 | NumCXXConstructorDeclBits = 64 - NumDeclContextBits - NumFunctionDeclBits |
| 1648 | }; |
| 1649 | |
| 1650 | |
| 1651 | |
| 1652 | |
| 1653 | class ObjCMethodDeclBitfields { |
| 1654 | friend class ObjCMethodDecl; |
| 1655 | |
| 1656 | |
| 1657 | uint64_t : NumDeclContextBits; |
| 1658 | |
| 1659 | |
| 1660 | |
| 1661 | |
| 1662 | mutable uint64_t Family : ObjCMethodFamilyBitWidth; |
| 1663 | |
| 1664 | |
| 1665 | uint64_t IsInstance : 1; |
| 1666 | uint64_t IsVariadic : 1; |
| 1667 | |
| 1668 | |
| 1669 | uint64_t IsPropertyAccessor : 1; |
| 1670 | |
| 1671 | |
| 1672 | uint64_t IsSynthesizedAccessorStub : 1; |
| 1673 | |
| 1674 | |
| 1675 | uint64_t IsDefined : 1; |
| 1676 | |
| 1677 | |
| 1678 | uint64_t IsRedeclaration : 1; |
| 1679 | |
| 1680 | |
| 1681 | mutable uint64_t HasRedeclaration : 1; |
| 1682 | |
| 1683 | |
| 1684 | uint64_t DeclImplementation : 2; |
| 1685 | |
| 1686 | |
| 1687 | uint64_t objcDeclQualifier : 7; |
| 1688 | |
| 1689 | |
| 1690 | uint64_t RelatedResultType : 1; |
| 1691 | |
| 1692 | |
| 1693 | |
| 1694 | uint64_t SelLocsKind : 2; |
| 1695 | |
| 1696 | |
| 1697 | |
| 1698 | |
| 1699 | |
| 1700 | |
| 1701 | |
| 1702 | |
| 1703 | uint64_t IsOverriding : 1; |
| 1704 | |
| 1705 | |
| 1706 | uint64_t HasSkippedBody : 1; |
| 1707 | }; |
| 1708 | |
| 1709 | |
| 1710 | enum { NumObjCMethodDeclBits = 24 }; |
| 1711 | |
| 1712 | |
| 1713 | |
| 1714 | |
| 1715 | class ObjCContainerDeclBitfields { |
| 1716 | friend class ObjCContainerDecl; |
| 1717 | |
| 1718 | uint32_t : NumDeclContextBits; |
| 1719 | |
| 1720 | |
| 1721 | |
| 1722 | SourceLocation AtStart; |
| 1723 | }; |
| 1724 | |
| 1725 | |
| 1726 | |
| 1727 | |
| 1728 | enum { NumObjCContainerDeclBits = 64 - NumDeclContextBits }; |
| 1729 | |
| 1730 | |
| 1731 | |
| 1732 | |
| 1733 | class LinkageSpecDeclBitfields { |
| 1734 | friend class LinkageSpecDecl; |
| 1735 | |
| 1736 | uint64_t : NumDeclContextBits; |
| 1737 | |
| 1738 | |
| 1739 | |
| 1740 | uint64_t Language : 3; |
| 1741 | |
| 1742 | |
| 1743 | |
| 1744 | |
| 1745 | |
| 1746 | uint64_t HasBraces : 1; |
| 1747 | }; |
| 1748 | |
| 1749 | |
| 1750 | enum { NumLinkageSpecDeclBits = 4 }; |
| 1751 | |
| 1752 | |
| 1753 | |
| 1754 | |
| 1755 | class BlockDeclBitfields { |
| 1756 | friend class BlockDecl; |
| 1757 | |
| 1758 | uint64_t : NumDeclContextBits; |
| 1759 | |
| 1760 | uint64_t IsVariadic : 1; |
| 1761 | uint64_t CapturesCXXThis : 1; |
| 1762 | uint64_t BlockMissingReturnType : 1; |
| 1763 | uint64_t IsConversionFromLambda : 1; |
| 1764 | |
| 1765 | |
| 1766 | |
| 1767 | uint64_t DoesNotEscape : 1; |
| 1768 | |
| 1769 | |
| 1770 | |
| 1771 | |
| 1772 | uint64_t CanAvoidCopyToHeap : 1; |
| 1773 | }; |
| 1774 | |
| 1775 | |
| 1776 | enum { NumBlockDeclBits = 5 }; |
| 1777 | |
| 1778 | |
| 1779 | |
| 1780 | |
| 1781 | |
| 1782 | |
| 1783 | |
| 1784 | mutable StoredDeclsMap *LookupPtr = nullptr; |
| 1785 | |
| 1786 | protected: |
| 1787 | |
| 1788 | |
| 1789 | |
| 1790 | |
| 1791 | |
| 1792 | |
| 1793 | |
| 1794 | |
| 1795 | union { |
| 1796 | DeclContextBitfields DeclContextBits; |
| 1797 | TagDeclBitfields TagDeclBits; |
| 1798 | EnumDeclBitfields EnumDeclBits; |
| 1799 | RecordDeclBitfields RecordDeclBits; |
| 1800 | OMPDeclareReductionDeclBitfields OMPDeclareReductionDeclBits; |
| 1801 | FunctionDeclBitfields FunctionDeclBits; |
| 1802 | CXXConstructorDeclBitfields CXXConstructorDeclBits; |
| 1803 | ObjCMethodDeclBitfields ObjCMethodDeclBits; |
| 1804 | ObjCContainerDeclBitfields ObjCContainerDeclBits; |
| 1805 | LinkageSpecDeclBitfields LinkageSpecDeclBits; |
| 1806 | BlockDeclBitfields BlockDeclBits; |
| 1807 | |
| 1808 | static_assert(sizeof(DeclContextBitfields) <= 8, |
| 1809 | "DeclContextBitfields is larger than 8 bytes!"); |
| 1810 | static_assert(sizeof(TagDeclBitfields) <= 8, |
| 1811 | "TagDeclBitfields is larger than 8 bytes!"); |
| 1812 | static_assert(sizeof(EnumDeclBitfields) <= 8, |
| 1813 | "EnumDeclBitfields is larger than 8 bytes!"); |
| 1814 | static_assert(sizeof(RecordDeclBitfields) <= 8, |
| 1815 | "RecordDeclBitfields is larger than 8 bytes!"); |
| 1816 | static_assert(sizeof(OMPDeclareReductionDeclBitfields) <= 8, |
| 1817 | "OMPDeclareReductionDeclBitfields is larger than 8 bytes!"); |
| 1818 | static_assert(sizeof(FunctionDeclBitfields) <= 8, |
| 1819 | "FunctionDeclBitfields is larger than 8 bytes!"); |
| 1820 | static_assert(sizeof(CXXConstructorDeclBitfields) <= 8, |
| 1821 | "CXXConstructorDeclBitfields is larger than 8 bytes!"); |
| 1822 | static_assert(sizeof(ObjCMethodDeclBitfields) <= 8, |
| 1823 | "ObjCMethodDeclBitfields is larger than 8 bytes!"); |
| 1824 | static_assert(sizeof(ObjCContainerDeclBitfields) <= 8, |
| 1825 | "ObjCContainerDeclBitfields is larger than 8 bytes!"); |
| 1826 | static_assert(sizeof(LinkageSpecDeclBitfields) <= 8, |
| 1827 | "LinkageSpecDeclBitfields is larger than 8 bytes!"); |
| 1828 | static_assert(sizeof(BlockDeclBitfields) <= 8, |
| 1829 | "BlockDeclBitfields is larger than 8 bytes!"); |
| 1830 | }; |
| 1831 | |
| 1832 | |
| 1833 | |
| 1834 | mutable Decl *FirstDecl = nullptr; |
| 1835 | |
| 1836 | |
| 1837 | |
| 1838 | |
| 1839 | |
| 1840 | mutable Decl *LastDecl = nullptr; |
| 1841 | |
| 1842 | |
| 1843 | |
| 1844 | |
| 1845 | static std::pair<Decl *, Decl *> |
| 1846 | BuildDeclChain(ArrayRef<Decl*> Decls, bool FieldsAlreadyLoaded); |
| 1847 | |
| 1848 | DeclContext(Decl::Kind K); |
| 1849 | |
| 1850 | public: |
| 1851 | ~DeclContext(); |
| 1852 | |
| 1853 | Decl::Kind getDeclKind() const { |
| 1854 | return static_cast<Decl::Kind>(DeclContextBits.DeclKind); |
| 1855 | } |
| 1856 | |
| 1857 | const char *getDeclKindName() const; |
| 1858 | |
| 1859 | |
| 1860 | DeclContext *getParent() { |
| 1861 | return cast<Decl>(this)->getDeclContext(); |
| 1862 | } |
| 1863 | const DeclContext *getParent() const { |
| 1864 | return const_cast<DeclContext*>(this)->getParent(); |
| 1865 | } |
| 1866 | |
| 1867 | |
| 1868 | |
| 1869 | |
| 1870 | |
| 1871 | |
| 1872 | |
| 1873 | |
| 1874 | |
| 1875 | |
| 1876 | DeclContext *getLexicalParent() { |
| 1877 | return cast<Decl>(this)->getLexicalDeclContext(); |
| 1878 | } |
| 1879 | const DeclContext *getLexicalParent() const { |
| 1880 | return const_cast<DeclContext*>(this)->getLexicalParent(); |
| 1881 | } |
| 1882 | |
| 1883 | DeclContext *getLookupParent(); |
| 1884 | |
| 1885 | const DeclContext *getLookupParent() const { |
| 1886 | return const_cast<DeclContext*>(this)->getLookupParent(); |
| 1887 | } |
| 1888 | |
| 1889 | ASTContext &getParentASTContext() const { |
| 1890 | return cast<Decl>(this)->getASTContext(); |
| 1891 | } |
| 1892 | |
| 1893 | bool isClosure() const { return getDeclKind() == Decl::Block; } |
| 1894 | |
| 1895 | |
| 1896 | |
| 1897 | const BlockDecl *getInnermostBlockDecl() const; |
| 1898 | |
| 1899 | bool isObjCContainer() const { |
| 1900 | switch (getDeclKind()) { |
| 1901 | case Decl::ObjCCategory: |
| 1902 | case Decl::ObjCCategoryImpl: |
| 1903 | case Decl::ObjCImplementation: |
| 1904 | case Decl::ObjCInterface: |
| 1905 | case Decl::ObjCProtocol: |
| 1906 | return true; |
| 1907 | default: |
| 1908 | return false; |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | bool isFunctionOrMethod() const { |
| 1913 | switch (getDeclKind()) { |
| 1914 | case Decl::Block: |
| 1915 | case Decl::Captured: |
| 1916 | case Decl::ObjCMethod: |
| 1917 | return true; |
| 1918 | default: |
| 1919 | return getDeclKind() >= Decl::firstFunction && |
| 1920 | getDeclKind() <= Decl::lastFunction; |
| 1921 | } |
| 1922 | } |
| 1923 | |
| 1924 | |
| 1925 | bool isLookupContext() const { |
| 1926 | return !isFunctionOrMethod() && getDeclKind() != Decl::LinkageSpec && |
| 1927 | getDeclKind() != Decl::Export; |
| 1928 | } |
| 1929 | |
| 1930 | bool isFileContext() const { |
| 1931 | return getDeclKind() == Decl::TranslationUnit || |
| 1932 | getDeclKind() == Decl::Namespace; |
| 1933 | } |
| 1934 | |
| 1935 | bool isTranslationUnit() const { |
| 1936 | return getDeclKind() == Decl::TranslationUnit; |
| 1937 | } |
| 1938 | |
| 1939 | bool isRecord() const { |
| 1940 | return getDeclKind() >= Decl::firstRecord && |
| 1941 | getDeclKind() <= Decl::lastRecord; |
| 1942 | } |
| 1943 | |
| 1944 | bool isNamespace() const { return getDeclKind() == Decl::Namespace; } |
| 1945 | |
| 1946 | bool isStdNamespace() const; |
| 1947 | |
| 1948 | bool isInlineNamespace() const; |
| 1949 | |
| 1950 | |
| 1951 | |
| 1952 | bool isDependentContext() const; |
| 1953 | |
| 1954 | |
| 1955 | |
| 1956 | |
| 1957 | |
| 1958 | |
| 1959 | |
| 1960 | |
| 1961 | |
| 1962 | |
| 1963 | |
| 1964 | |
| 1965 | |
| 1966 | |
| 1967 | |
| 1968 | |
| 1969 | bool isTransparentContext() const; |
| 1970 | |
| 1971 | |
| 1972 | |
| 1973 | bool isExternCContext() const; |
| 1974 | |
| 1975 | |
| 1976 | const LinkageSpecDecl *getExternCContext() const; |
| 1977 | |
| 1978 | |
| 1979 | |
| 1980 | bool isExternCXXContext() const; |
| 1981 | |
| 1982 | |
| 1983 | |
| 1984 | bool Equals(const DeclContext *DC) const { |
| 1985 | return DC && this->getPrimaryContext() == DC->getPrimaryContext(); |
| 1986 | } |
| 1987 | |
| 1988 | |
| 1989 | |
| 1990 | bool Encloses(const DeclContext *DC) const; |
| 1991 | |
| 1992 | |
| 1993 | |
| 1994 | |
| 1995 | Decl *getNonClosureAncestor(); |
| 1996 | const Decl *getNonClosureAncestor() const { |
| 1997 | return const_cast<DeclContext*>(this)->getNonClosureAncestor(); |
| 1998 | } |
| 1999 | |
| 2000 | |
| 2001 | |
| 2002 | |
| 2003 | |
| 2004 | |
| 2005 | |
| 2006 | DeclContext *getPrimaryContext(); |
| 2007 | const DeclContext *getPrimaryContext() const { |
| 2008 | return const_cast<DeclContext*>(this)->getPrimaryContext(); |
| 2009 | } |
| 2010 | |
| 2011 | |
| 2012 | |
| 2013 | |
| 2014 | DeclContext *getRedeclContext(); |
| 2015 | const DeclContext *getRedeclContext() const { |
| 2016 | return const_cast<DeclContext *>(this)->getRedeclContext(); |
| 2017 | } |
| 2018 | |
| 2019 | |
| 2020 | DeclContext *getEnclosingNamespaceContext(); |
| 2021 | const DeclContext *getEnclosingNamespaceContext() const { |
| 2022 | return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext(); |
| 2023 | } |
| 2024 | |
| 2025 | |
| 2026 | RecordDecl *getOuterLexicalRecordContext(); |
| 2027 | const RecordDecl *getOuterLexicalRecordContext() const { |
| 2028 | return const_cast<DeclContext *>(this)->getOuterLexicalRecordContext(); |
| 2029 | } |
| 2030 | |
| 2031 | |
| 2032 | |
| 2033 | |
| 2034 | |
| 2035 | |
| 2036 | |
| 2037 | bool InEnclosingNamespaceSetOf(const DeclContext *NS) const; |
| 2038 | |
| 2039 | |
| 2040 | |
| 2041 | |
| 2042 | |
| 2043 | |
| 2044 | |
| 2045 | |
| 2046 | |
| 2047 | |
| 2048 | |
| 2049 | |
| 2050 | |
| 2051 | |
| 2052 | |
| 2053 | |
| 2054 | |
| 2055 | |
| 2056 | |
| 2057 | |
| 2058 | |
| 2059 | |
| 2060 | |
| 2061 | |
| 2062 | void collectAllContexts(SmallVectorImpl<DeclContext *> &Contexts); |
| 2063 | |
| 2064 | |
| 2065 | |
| 2066 | class decl_iterator { |
| 2067 | |
| 2068 | Decl *Current = nullptr; |
| 2069 | |
| 2070 | public: |
| 2071 | using value_type = Decl *; |
| 2072 | using reference = const value_type &; |
| 2073 | using pointer = const value_type *; |
| 2074 | using iterator_category = std::forward_iterator_tag; |
| 2075 | using difference_type = std::ptrdiff_t; |
| 2076 | |
| 2077 | decl_iterator() = default; |
| 2078 | explicit decl_iterator(Decl *C) : Current(C) {} |
| 2079 | |
| 2080 | reference operator*() const { return Current; } |
| 2081 | |
| 2082 | |
| 2083 | value_type operator->() const { return Current; } |
| 2084 | |
| 2085 | decl_iterator& operator++() { |
| 2086 | Current = Current->getNextDeclInContext(); |
| 2087 | return *this; |
| 2088 | } |
| 2089 | |
| 2090 | decl_iterator operator++(int) { |
| 2091 | decl_iterator tmp(*this); |
| 2092 | ++(*this); |
| 2093 | return tmp; |
| 2094 | } |
| 2095 | |
| 2096 | friend bool operator==(decl_iterator x, decl_iterator y) { |
| 2097 | return x.Current == y.Current; |
| 30 | | Assuming 'x.Current' is not equal to 'y.Current' | |
|
| 31 | | Returning zero, which participates in a condition later | |
|
| 2098 | } |
| 2099 | |
| 2100 | friend bool operator!=(decl_iterator x, decl_iterator y) { |
| 2101 | return x.Current != y.Current; |
| 2102 | } |
| 2103 | }; |
| 2104 | |
| 2105 | using decl_range = llvm::iterator_range<decl_iterator>; |
| 2106 | |
| 2107 | |
| 2108 | |
| 2109 | decl_range decls() const { return decl_range(decls_begin(), decls_end()); } |
| 2110 | decl_iterator decls_begin() const; |
| 2111 | decl_iterator decls_end() const { return decl_iterator(); } |
| 2112 | bool decls_empty() const; |
| 2113 | |
| 2114 | |
| 2115 | |
| 2116 | |
| 2117 | decl_range noload_decls() const { |
| 2118 | return decl_range(noload_decls_begin(), noload_decls_end()); |
| 2119 | } |
| 2120 | decl_iterator noload_decls_begin() const { return decl_iterator(FirstDecl); } |
| 2121 | decl_iterator noload_decls_end() const { return decl_iterator(); } |
| 2122 | |
| 2123 | |
| 2124 | |
| 2125 | |
| 2126 | |
| 2127 | |
| 2128 | template<typename SpecificDecl> |
| 2129 | class specific_decl_iterator { |
| 2130 | |
| 2131 | |
| 2132 | |
| 2133 | DeclContext::decl_iterator Current; |
| 2134 | |
| 2135 | |
| 2136 | |
| 2137 | |
| 2138 | void SkipToNextDecl() { |
| 2139 | while (*Current && !isa<SpecificDecl>(*Current)) |
| 2140 | ++Current; |
| 2141 | } |
| 2142 | |
| 2143 | public: |
| 2144 | using value_type = SpecificDecl *; |
| 2145 | |
| 2146 | |
| 2147 | using reference = void; |
| 2148 | using pointer = void; |
| 2149 | using difference_type = |
| 2150 | std::iterator_traits<DeclContext::decl_iterator>::difference_type; |
| 2151 | using iterator_category = std::forward_iterator_tag; |
| 2152 | |
| 2153 | specific_decl_iterator() = default; |
| 2154 | |
| 2155 | |
| 2156 | |
| 2157 | |
| 2158 | |
| 2159 | |
| 2160 | |
| 2161 | |
| 2162 | |
| 2163 | explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) { |
| 2164 | SkipToNextDecl(); |
| 2165 | } |
| 2166 | |
| 2167 | value_type operator*() const { return cast<SpecificDecl>(*Current); } |
| 2168 | |
| 2169 | |
| 2170 | value_type operator->() const { return **this; } |
| 2171 | |
| 2172 | specific_decl_iterator& operator++() { |
| 2173 | ++Current; |
| 2174 | SkipToNextDecl(); |
| 2175 | return *this; |
| 2176 | } |
| 2177 | |
| 2178 | specific_decl_iterator operator++(int) { |
| 2179 | specific_decl_iterator tmp(*this); |
| 2180 | ++(*this); |
| 2181 | return tmp; |
| 2182 | } |
| 2183 | |
| 2184 | friend bool operator==(const specific_decl_iterator& x, |
| 2185 | const specific_decl_iterator& y) { |
| 2186 | return x.Current == y.Current; |
| |
| 32 | | Returning from 'operator==' | |
|
| 33 | | Returning zero, which participates in a condition later | |
|
| 2187 | } |
| 2188 | |
| 2189 | friend bool operator!=(const specific_decl_iterator& x, |
| 2190 | const specific_decl_iterator& y) { |
| 2191 | return x.Current != y.Current; |
| 2192 | } |
| 2193 | }; |
| 2194 | |
| 2195 | |
| 2196 | |
| 2197 | |
| 2198 | |
| 2199 | |
| 2200 | |
| 2201 | |
| 2202 | |
| 2203 | |
| 2204 | template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const> |
| 2205 | class filtered_decl_iterator { |
| 2206 | |
| 2207 | |
| 2208 | |
| 2209 | DeclContext::decl_iterator Current; |
| 2210 | |
| 2211 | |
| 2212 | |
| 2213 | |
| 2214 | void SkipToNextDecl() { |
| 2215 | while (*Current && |
| 2216 | (!isa<SpecificDecl>(*Current) || |
| 2217 | (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)()))) |
| 2218 | ++Current; |
| 2219 | } |
| 2220 | |
| 2221 | public: |
| 2222 | using value_type = SpecificDecl *; |
| 2223 | |
| 2224 | |
| 2225 | using reference = void; |
| 2226 | using pointer = void; |
| 2227 | using difference_type = |
| 2228 | std::iterator_traits<DeclContext::decl_iterator>::difference_type; |
| 2229 | using iterator_category = std::forward_iterator_tag; |
| 2230 | |
| 2231 | filtered_decl_iterator() = default; |
| 2232 | |
| 2233 | |
| 2234 | |
| 2235 | |
| 2236 | |
| 2237 | |
| 2238 | |
| 2239 | |
| 2240 | |
| 2241 | explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) { |
| 2242 | SkipToNextDecl(); |
| 2243 | } |
| 2244 | |
| 2245 | value_type operator*() const { return cast<SpecificDecl>(*Current); } |
| 2246 | value_type operator->() const { return cast<SpecificDecl>(*Current); } |
| 2247 | |
| 2248 | filtered_decl_iterator& operator++() { |
| 2249 | ++Current; |
| 2250 | SkipToNextDecl(); |
| 2251 | return *this; |
| 2252 | } |
| 2253 | |
| 2254 | filtered_decl_iterator operator++(int) { |
| 2255 | filtered_decl_iterator tmp(*this); |
| 2256 | ++(*this); |
| 2257 | return tmp; |
| 2258 | } |
| 2259 | |
| 2260 | friend bool operator==(const filtered_decl_iterator& x, |
| 2261 | const filtered_decl_iterator& y) { |
| 2262 | return x.Current == y.Current; |
| 2263 | } |
| 2264 | |
| 2265 | friend bool operator!=(const filtered_decl_iterator& x, |
| 2266 | const filtered_decl_iterator& y) { |
| 2267 | return x.Current != y.Current; |
| 2268 | } |
| 2269 | }; |
| 2270 | |
| 2271 | |
| 2272 | |
| 2273 | |
| 2274 | |
| 2275 | |
| 2276 | |
| 2277 | |
| 2278 | |
| 2279 | |
| 2280 | |
| 2281 | |
| 2282 | |
| 2283 | void addDecl(Decl *D); |
| 2284 | |
| 2285 | |
| 2286 | |
| 2287 | |
| 2288 | |
| 2289 | |
| 2290 | |
| 2291 | |
| 2292 | |
| 2293 | void addDeclInternal(Decl *D); |
| 2294 | |
| 2295 | |
| 2296 | |
| 2297 | |
| 2298 | |
| 2299 | |
| 2300 | |
| 2301 | void addHiddenDecl(Decl *D); |
| 2302 | |
| 2303 | |
| 2304 | void removeDecl(Decl *D); |
| 2305 | |
| 2306 | |
| 2307 | bool containsDecl(Decl *D) const; |
| 2308 | |
| 2309 | |
| 2310 | |
| 2311 | bool containsDeclAndLoad(Decl *D) const; |
| 2312 | |
| 2313 | using lookup_result = DeclContextLookupResult; |
| 2314 | using lookup_iterator = lookup_result::iterator; |
| 2315 | |
| 2316 | |
| 2317 | |
| 2318 | |
| 2319 | |
| 2320 | |
| 2321 | lookup_result lookup(DeclarationName Name) const; |
| 2322 | |
| 2323 | |
| 2324 | |
| 2325 | |
| 2326 | lookup_result noload_lookup(DeclarationName Name); |
| 2327 | |
| 2328 | |
| 2329 | |
| 2330 | |
| 2331 | |
| 2332 | |
| 2333 | |
| 2334 | |
| 2335 | |
| 2336 | |
| 2337 | void localUncachedLookup(DeclarationName Name, |
| 2338 | SmallVectorImpl<NamedDecl *> &Results); |
| 2339 | |
| 2340 | |
| 2341 | |
| 2342 | |
| 2343 | |
| 2344 | |
| 2345 | |
| 2346 | |
| 2347 | |
| 2348 | |
| 2349 | |
| 2350 | |
| 2351 | |
| 2352 | |
| 2353 | |
| 2354 | void makeDeclVisibleInContext(NamedDecl *D); |
| 2355 | |
| 2356 | |
| 2357 | |
| 2358 | class all_lookups_iterator; |
| 2359 | |
| 2360 | using lookups_range = llvm::iterator_range<all_lookups_iterator>; |
| 2361 | |
| 2362 | lookups_range lookups() const; |
| 2363 | |
| 2364 | |
| 2365 | lookups_range noload_lookups(bool PreserveInternalState) const; |
| 2366 | |
| 2367 | |
| 2368 | all_lookups_iterator lookups_begin() const; |
| 2369 | all_lookups_iterator lookups_end() const; |
| 2370 | |
| 2371 | |
| 2372 | |
| 2373 | |
| 2374 | all_lookups_iterator noload_lookups_begin() const; |
| 2375 | all_lookups_iterator noload_lookups_end() const; |
| 2376 | |
| 2377 | struct udir_iterator; |
| 2378 | |
| 2379 | using udir_iterator_base = |
| 2380 | llvm::iterator_adaptor_base<udir_iterator, lookup_iterator, |
| 2381 | typename lookup_iterator::iterator_category, |
| 2382 | UsingDirectiveDecl *>; |
| 2383 | |
| 2384 | struct udir_iterator : udir_iterator_base { |
| 2385 | udir_iterator(lookup_iterator I) : udir_iterator_base(I) {} |
| 2386 | |
| 2387 | UsingDirectiveDecl *operator*() const; |
| 2388 | }; |
| 2389 | |
| 2390 | using udir_range = llvm::iterator_range<udir_iterator>; |
| 2391 | |
| 2392 | udir_range using_directives() const; |
| 2393 | |
| 2394 | |
| 2395 | class ddiag_iterator; |
| 2396 | |
| 2397 | using ddiag_range = llvm::iterator_range<DeclContext::ddiag_iterator>; |
| 2398 | |
| 2399 | inline ddiag_range ddiags() const; |
| 2400 | |
| 2401 | |
| 2402 | |
| 2403 | |
| 2404 | |
| 2405 | |
| 2406 | |
| 2407 | |
| 2408 | |
| 2409 | void setMustBuildLookupTable() { |
| 2410 | assert(this == getPrimaryContext() && |
| 2411 | "should only be called on primary context"); |
| 2412 | DeclContextBits.HasLazyExternalLexicalLookups = true; |
| 2413 | } |
| 2414 | |
| 2415 | |
| 2416 | |
| 2417 | StoredDeclsMap *getLookupPtr() const { return LookupPtr; } |
| 2418 | |
| 2419 | |
| 2420 | StoredDeclsMap *buildLookup(); |
| 2421 | |
| 2422 | |
| 2423 | |
| 2424 | bool hasExternalLexicalStorage() const { |
| 2425 | return DeclContextBits.ExternalLexicalStorage; |
| 2426 | } |
| 2427 | |
| 2428 | |
| 2429 | |
| 2430 | void setHasExternalLexicalStorage(bool ES = true) const { |
| 2431 | DeclContextBits.ExternalLexicalStorage = ES; |
| 2432 | } |
| 2433 | |
| 2434 | |
| 2435 | |
| 2436 | bool hasExternalVisibleStorage() const { |
| 2437 | return DeclContextBits.ExternalVisibleStorage; |
| 2438 | } |
| 2439 | |
| 2440 | |
| 2441 | |
| 2442 | void setHasExternalVisibleStorage(bool ES = true) const { |
| 2443 | DeclContextBits.ExternalVisibleStorage = ES; |
| 2444 | if (ES && LookupPtr) |
| 2445 | DeclContextBits.NeedToReconcileExternalVisibleStorage = true; |
| 2446 | } |
| 2447 | |
| 2448 | |
| 2449 | |
| 2450 | bool isDeclInLexicalTraversal(const Decl *D) const { |
| 2451 | return D && (D->NextInContextAndBits.getPointer() || D == FirstDecl || |
| 2452 | D == LastDecl); |
| 2453 | } |
| 2454 | |
| 2455 | bool setUseQualifiedLookup(bool use = true) const { |
| 2456 | bool old_value = DeclContextBits.UseQualifiedLookup; |
| 2457 | DeclContextBits.UseQualifiedLookup = use; |
| 2458 | return old_value; |
| 2459 | } |
| 2460 | |
| 2461 | bool shouldUseQualifiedLookup() const { |
| 2462 | return DeclContextBits.UseQualifiedLookup; |
| 2463 | } |
| 2464 | |
| 2465 | static bool classof(const Decl *D); |
| 2466 | static bool classof(const DeclContext *D) { return true; } |
| 2467 | |
| 2468 | void dumpDeclContext() const; |
| 2469 | void dumpLookups() const; |
| 2470 | void dumpLookups(llvm::raw_ostream &OS, bool DumpDecls = false, |
| 2471 | bool Deserialize = false) const; |
| 2472 | |
| 2473 | private: |
| 2474 | |
| 2475 | |
| 2476 | |
| 2477 | |
| 2478 | bool hasNeedToReconcileExternalVisibleStorage() const { |
| 2479 | return DeclContextBits.NeedToReconcileExternalVisibleStorage; |
| 2480 | } |
| 2481 | |
| 2482 | |
| 2483 | |
| 2484 | |
| 2485 | |
| 2486 | void setNeedToReconcileExternalVisibleStorage(bool Need = true) const { |
| 2487 | DeclContextBits.NeedToReconcileExternalVisibleStorage = Need; |
| 2488 | } |
| 2489 | |
| 2490 | |
| 2491 | |
| 2492 | bool hasLazyLocalLexicalLookups() const { |
| 2493 | return DeclContextBits.HasLazyLocalLexicalLookups; |
| 2494 | } |
| 2495 | |
| 2496 | |
| 2497 | |
| 2498 | void setHasLazyLocalLexicalLookups(bool HasLLLL = true) const { |
| 2499 | DeclContextBits.HasLazyLocalLexicalLookups = HasLLLL; |
| 2500 | } |
| 2501 | |
| 2502 | |
| 2503 | |
| 2504 | bool hasLazyExternalLexicalLookups() const { |
| 2505 | return DeclContextBits.HasLazyExternalLexicalLookups; |
| 2506 | } |
| 2507 | |
| 2508 | |
| 2509 | |
| 2510 | void setHasLazyExternalLexicalLookups(bool HasLELL = true) const { |
| 2511 | DeclContextBits.HasLazyExternalLexicalLookups = HasLELL; |
| 2512 | } |
| 2513 | |
| 2514 | void reconcileExternalVisibleStorage() const; |
| 2515 | bool LoadLexicalDeclsFromExternalStorage() const; |
| 2516 | |
| 2517 | |
| 2518 | |
| 2519 | |
| 2520 | |
| 2521 | |
| 2522 | |
| 2523 | void makeDeclVisibleInContextInternal(NamedDecl *D); |
| 2524 | |
| 2525 | StoredDeclsMap *CreateStoredDeclsMap(ASTContext &C) const; |
| 2526 | |
| 2527 | void loadLazyLocalLexicalLookups(); |
| 2528 | void buildLookupImpl(DeclContext *DCtx, bool Internal); |
| 2529 | void makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal, |
| 2530 | bool Rediscoverable); |
| 2531 | void makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal); |
| 2532 | }; |
| 2533 | |
| 2534 | inline bool Decl::isTemplateParameter() const { |
| 2535 | return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm || |
| 2536 | getKind() == TemplateTemplateParm; |
| 2537 | } |
| 2538 | |
| 2539 | |
| 2540 | template <class ToTy, |
| 2541 | bool IsKnownSubtype = ::std::is_base_of<DeclContext, ToTy>::value> |
| 2542 | struct cast_convert_decl_context { |
| 2543 | static const ToTy *doit(const DeclContext *Val) { |
| 2544 | return static_cast<const ToTy*>(Decl::castFromDeclContext(Val)); |
| 2545 | } |
| 2546 | |
| 2547 | static ToTy *doit(DeclContext *Val) { |
| 2548 | return static_cast<ToTy*>(Decl::castFromDeclContext(Val)); |
| 2549 | } |
| 2550 | }; |
| 2551 | |
| 2552 | |
| 2553 | template <class ToTy> |
| 2554 | struct cast_convert_decl_context<ToTy, true> { |
| 2555 | static const ToTy *doit(const DeclContext *Val) { |
| 2556 | return static_cast<const ToTy*>(Val); |
| 2557 | } |
| 2558 | |
| 2559 | static ToTy *doit(DeclContext *Val) { |
| 2560 | return static_cast<ToTy*>(Val); |
| 2561 | } |
| 2562 | }; |
| 2563 | |
| 2564 | } |
| 2565 | |
| 2566 | namespace llvm { |
| 2567 | |
| 2568 | |
| 2569 | template <typename To> |
| 2570 | struct isa_impl<To, ::clang::DeclContext> { |
| 2571 | static bool doit(const ::clang::DeclContext &Val) { |
| 2572 | return To::classofKind(Val.getDeclKind()); |
| 2573 | } |
| 2574 | }; |
| 2575 | |
| 2576 | |
| 2577 | template<class ToTy> |
| 2578 | struct cast_convert_val<ToTy, |
| 2579 | const ::clang::DeclContext,const ::clang::DeclContext> { |
| 2580 | static const ToTy &doit(const ::clang::DeclContext &Val) { |
| 2581 | return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); |
| 2582 | } |
| 2583 | }; |
| 2584 | |
| 2585 | template<class ToTy> |
| 2586 | struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> { |
| 2587 | static ToTy &doit(::clang::DeclContext &Val) { |
| 2588 | return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); |
| 2589 | } |
| 2590 | }; |
| 2591 | |
| 2592 | template<class ToTy> |
| 2593 | struct cast_convert_val<ToTy, |
| 2594 | const ::clang::DeclContext*, const ::clang::DeclContext*> { |
| 2595 | static const ToTy *doit(const ::clang::DeclContext *Val) { |
| 2596 | return ::clang::cast_convert_decl_context<ToTy>::doit(Val); |
| 2597 | } |
| 2598 | }; |
| 2599 | |
| 2600 | template<class ToTy> |
| 2601 | struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> { |
| 2602 | static ToTy *doit(::clang::DeclContext *Val) { |
| 2603 | return ::clang::cast_convert_decl_context<ToTy>::doit(Val); |
| 2604 | } |
| 2605 | }; |
| 2606 | |
| 2607 | |
| 2608 | template<class FromTy> |
| 2609 | struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { |
| 2610 | static ::clang::DeclContext &doit(const FromTy &Val) { |
| 2611 | return *FromTy::castToDeclContext(&Val); |
| 2612 | } |
| 2613 | }; |
| 2614 | |
| 2615 | template<class FromTy> |
| 2616 | struct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> { |
| 2617 | static ::clang::DeclContext *doit(const FromTy *Val) { |
| 2618 | return FromTy::castToDeclContext(Val); |
| 2619 | } |
| 2620 | }; |
| 2621 | |
| 2622 | template<class FromTy> |
| 2623 | struct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> { |
| 2624 | static const ::clang::DeclContext &doit(const FromTy &Val) { |
| 2625 | return *FromTy::castToDeclContext(&Val); |
| 2626 | } |
| 2627 | }; |
| 2628 | |
| 2629 | template<class FromTy> |
| 2630 | struct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { |
| 2631 | static const ::clang::DeclContext *doit(const FromTy *Val) { |
| 2632 | return FromTy::castToDeclContext(Val); |
| 2633 | } |
| 2634 | }; |
| 2635 | |
| 2636 | } |
| 2637 | |
| 2638 | #endif // LLVM_CLANG_AST_DECLBASE_H |