| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | #ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H |
| 16 | #define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H |
| 17 | |
| 18 | #include "clang/Basic/LLVM.h" |
| 19 | #include "clang/Basic/TokenKinds.h" |
| 20 | #include "llvm/ADT/DenseMapInfo.h" |
| 21 | #include "llvm/ADT/SmallString.h" |
| 22 | #include "llvm/ADT/StringMap.h" |
| 23 | #include "llvm/ADT/StringRef.h" |
| 24 | #include "llvm/Support/Allocator.h" |
| 25 | #include "llvm/Support/PointerLikeTypeTraits.h" |
| 26 | #include "llvm/Support/type_traits.h" |
| 27 | #include <cassert> |
| 28 | #include <cstddef> |
| 29 | #include <cstdint> |
| 30 | #include <cstring> |
| 31 | #include <string> |
| 32 | #include <utility> |
| 33 | |
| 34 | namespace clang { |
| 35 | |
| 36 | class DeclarationName; |
| 37 | class DeclarationNameTable; |
| 38 | class IdentifierInfo; |
| 39 | class LangOptions; |
| 40 | class MultiKeywordSelector; |
| 41 | class SourceLocation; |
| 42 | |
| 43 | |
| 44 | using IdentifierLocPair = std::pair<IdentifierInfo *, SourceLocation>; |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | enum { IdentifierInfoAlignment = 8 }; |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | class alignas(IdentifierInfoAlignment) IdentifierInfo { |
| 58 | friend class IdentifierTable; |
| 59 | |
| 60 | |
| 61 | unsigned TokenID : 9; |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | unsigned ObjCOrBuiltinID : 13; |
| 67 | |
| 68 | |
| 69 | unsigned HasMacro : 1; |
| 70 | |
| 71 | |
| 72 | unsigned HadMacro : 1; |
| 73 | |
| 74 | |
| 75 | unsigned IsExtension : 1; |
| 76 | |
| 77 | |
| 78 | unsigned IsFutureCompatKeyword : 1; |
| 79 | |
| 80 | |
| 81 | unsigned IsPoisoned : 1; |
| 82 | |
| 83 | |
| 84 | unsigned IsCPPOperatorKeyword : 1; |
| 85 | |
| 86 | |
| 87 | |
| 88 | unsigned NeedsHandleIdentifier : 1; |
| 89 | |
| 90 | |
| 91 | unsigned IsFromAST : 1; |
| 92 | |
| 93 | |
| 94 | |
| 95 | unsigned ChangedAfterLoad : 1; |
| 96 | |
| 97 | |
| 98 | |
| 99 | unsigned FEChangedAfterLoad : 1; |
| 100 | |
| 101 | |
| 102 | unsigned RevertedTokenID : 1; |
| 103 | |
| 104 | |
| 105 | |
| 106 | unsigned OutOfDate : 1; |
| 107 | |
| 108 | |
| 109 | unsigned IsModulesImport : 1; |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | void *FETokenInfo = nullptr; |
| 115 | |
| 116 | llvm::StringMapEntry<IdentifierInfo *> *Entry = nullptr; |
| 117 | |
| 118 | IdentifierInfo() |
| 119 | : TokenID(tok::identifier), ObjCOrBuiltinID(0), HasMacro(false), |
| 120 | HadMacro(false), IsExtension(false), IsFutureCompatKeyword(false), |
| 121 | IsPoisoned(false), IsCPPOperatorKeyword(false), |
| 122 | NeedsHandleIdentifier(false), IsFromAST(false), ChangedAfterLoad(false), |
| 123 | FEChangedAfterLoad(false), RevertedTokenID(false), OutOfDate(false), |
| 124 | IsModulesImport(false) {} |
| 125 | |
| 126 | public: |
| 127 | IdentifierInfo(const IdentifierInfo &) = delete; |
| 128 | IdentifierInfo &operator=(const IdentifierInfo &) = delete; |
| 129 | IdentifierInfo(IdentifierInfo &&) = delete; |
| 130 | IdentifierInfo &operator=(IdentifierInfo &&) = delete; |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | template <std::size_t StrLen> |
| 136 | bool isStr(const char (&Str)[StrLen]) const { |
| 137 | return getLength() == StrLen-1 && |
| 138 | memcmp(getNameStart(), Str, StrLen-1) == 0; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | bool isStr(llvm::StringRef Str) const { |
| 143 | llvm::StringRef ThisStr(getNameStart(), getLength()); |
| 144 | return ThisStr == Str; |
| 145 | } |
| 146 | |
| 147 | |
| 148 | |
| 149 | const char *getNameStart() const { return Entry->getKeyData(); } |
| 150 | |
| 151 | |
| 152 | unsigned getLength() const { return Entry->getKeyLength(); } |
| 153 | |
| 154 | |
| 155 | StringRef getName() const { |
| 156 | return StringRef(getNameStart(), getLength()); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | |
| 161 | bool hasMacroDefinition() const { |
| 162 | return HasMacro; |
| 163 | } |
| 164 | void setHasMacroDefinition(bool Val) { |
| 165 | if (HasMacro == Val) return; |
| 166 | |
| 167 | HasMacro = Val; |
| 168 | if (Val) { |
| 169 | NeedsHandleIdentifier = true; |
| 170 | HadMacro = true; |
| 171 | } else { |
| 172 | RecomputeNeedsHandleIdentifier(); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | |
| 177 | |
| 178 | bool hadMacroDefinition() const { |
| 179 | return HadMacro; |
| 180 | } |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | tok::TokenKind getTokenID() const { return (tok::TokenKind)TokenID; } |
| 186 | |
| 187 | |
| 188 | bool hasRevertedTokenIDToIdentifier() const { return RevertedTokenID; } |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | void revertTokenIDToIdentifier() { |
| 197 | (0) . __assert_fail ("TokenID != tok..identifier && \"Already at tok..identifier\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/IdentifierTable.h", 197, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(TokenID != tok::identifier && "Already at tok::identifier"); |
| 198 | TokenID = tok::identifier; |
| 199 | RevertedTokenID = true; |
| 200 | } |
| 201 | void revertIdentifierToTokenID(tok::TokenKind TK) { |
| 202 | (0) . __assert_fail ("TokenID == tok..identifier && \"Should be at tok..identifier\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/IdentifierTable.h", 202, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(TokenID == tok::identifier && "Should be at tok::identifier"); |
| 203 | TokenID = TK; |
| 204 | RevertedTokenID = false; |
| 205 | } |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | tok::PPKeywordKind getPPKeywordID() const; |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | tok::ObjCKeywordKind getObjCKeywordID() const { |
| 216 | if (ObjCOrBuiltinID < tok::NUM_OBJC_KEYWORDS) |
| 217 | return tok::ObjCKeywordKind(ObjCOrBuiltinID); |
| 218 | else |
| 219 | return tok::objc_not_keyword; |
| 220 | } |
| 221 | void setObjCKeywordID(tok::ObjCKeywordKind ID) { ObjCOrBuiltinID = ID; } |
| 222 | |
| 223 | |
| 224 | bool hasRevertedBuiltin() const { |
| 225 | return ObjCOrBuiltinID == tok::NUM_OBJC_KEYWORDS; |
| 226 | } |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | void revertBuiltin() { |
| 232 | setBuiltinID(0); |
| 233 | } |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | unsigned getBuiltinID() const { |
| 239 | if (ObjCOrBuiltinID >= tok::NUM_OBJC_KEYWORDS) |
| 240 | return ObjCOrBuiltinID - tok::NUM_OBJC_KEYWORDS; |
| 241 | else |
| 242 | return 0; |
| 243 | } |
| 244 | void setBuiltinID(unsigned ID) { |
| 245 | ObjCOrBuiltinID = ID + tok::NUM_OBJC_KEYWORDS; |
| 246 | (0) . __assert_fail ("ObjCOrBuiltinID - unsigned(tok..NUM_OBJC_KEYWORDS) == ID && \"ID too large for field!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/IdentifierTable.h", 247, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(ObjCOrBuiltinID - unsigned(tok::NUM_OBJC_KEYWORDS) == ID |
| 247 | (0) . __assert_fail ("ObjCOrBuiltinID - unsigned(tok..NUM_OBJC_KEYWORDS) == ID && \"ID too large for field!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/IdentifierTable.h", 247, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> && "ID too large for field!"); |
| 248 | } |
| 249 | |
| 250 | unsigned getObjCOrBuiltinID() const { return ObjCOrBuiltinID; } |
| 251 | void setObjCOrBuiltinID(unsigned ID) { ObjCOrBuiltinID = ID; } |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | bool isExtensionToken() const { return IsExtension; } |
| 257 | void setIsExtensionToken(bool Val) { |
| 258 | IsExtension = Val; |
| 259 | if (Val) |
| 260 | NeedsHandleIdentifier = true; |
| 261 | else |
| 262 | RecomputeNeedsHandleIdentifier(); |
| 263 | } |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | bool isFutureCompatKeyword() const { return IsFutureCompatKeyword; } |
| 271 | void setIsFutureCompatKeyword(bool Val) { |
| 272 | IsFutureCompatKeyword = Val; |
| 273 | if (Val) |
| 274 | NeedsHandleIdentifier = true; |
| 275 | else |
| 276 | RecomputeNeedsHandleIdentifier(); |
| 277 | } |
| 278 | |
| 279 | |
| 280 | |
| 281 | void setIsPoisoned(bool Value = true) { |
| 282 | IsPoisoned = Value; |
| 283 | if (Value) |
| 284 | NeedsHandleIdentifier = true; |
| 285 | else |
| 286 | RecomputeNeedsHandleIdentifier(); |
| 287 | } |
| 288 | |
| 289 | |
| 290 | bool isPoisoned() const { return IsPoisoned; } |
| 291 | |
| 292 | |
| 293 | |
| 294 | void setIsCPlusPlusOperatorKeyword(bool Val = true) { |
| 295 | IsCPPOperatorKeyword = Val; |
| 296 | } |
| 297 | bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; } |
| 298 | |
| 299 | |
| 300 | bool isKeyword(const LangOptions &LangOpts) const; |
| 301 | |
| 302 | |
| 303 | |
| 304 | bool isCPlusPlusKeyword(const LangOptions &LangOpts) const; |
| 305 | |
| 306 | |
| 307 | |
| 308 | void *getFETokenInfo() const { return FETokenInfo; } |
| 309 | void setFETokenInfo(void *T) { FETokenInfo = T; } |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | bool isHandleIdentifierCase() const { return NeedsHandleIdentifier; } |
| 317 | |
| 318 | |
| 319 | |
| 320 | bool isFromAST() const { return IsFromAST; } |
| 321 | |
| 322 | void setIsFromAST() { IsFromAST = true; } |
| 323 | |
| 324 | |
| 325 | |
| 326 | bool hasChangedSinceDeserialization() const { |
| 327 | return ChangedAfterLoad; |
| 328 | } |
| 329 | |
| 330 | |
| 331 | |
| 332 | void setChangedSinceDeserialization() { |
| 333 | ChangedAfterLoad = true; |
| 334 | } |
| 335 | |
| 336 | |
| 337 | |
| 338 | bool hasFETokenInfoChangedSinceDeserialization() const { |
| 339 | return FEChangedAfterLoad; |
| 340 | } |
| 341 | |
| 342 | |
| 343 | |
| 344 | void setFETokenInfoChangedSinceDeserialization() { |
| 345 | FEChangedAfterLoad = true; |
| 346 | } |
| 347 | |
| 348 | |
| 349 | |
| 350 | bool isOutOfDate() const { return OutOfDate; } |
| 351 | |
| 352 | |
| 353 | |
| 354 | void setOutOfDate(bool OOD) { |
| 355 | OutOfDate = OOD; |
| 356 | if (OOD) |
| 357 | NeedsHandleIdentifier = true; |
| 358 | else |
| 359 | RecomputeNeedsHandleIdentifier(); |
| 360 | } |
| 361 | |
| 362 | |
| 363 | bool isModulesImport() const { return IsModulesImport; } |
| 364 | |
| 365 | |
| 366 | void setModulesImport(bool I) { |
| 367 | IsModulesImport = I; |
| 368 | if (I) |
| 369 | NeedsHandleIdentifier = true; |
| 370 | else |
| 371 | RecomputeNeedsHandleIdentifier(); |
| 372 | } |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 | bool isEditorPlaceholder() const { |
| 384 | return getName().startswith("<#") && getName().endswith("#>"); |
| 385 | } |
| 386 | |
| 387 | |
| 388 | bool operator<(const IdentifierInfo &RHS) const { |
| 389 | return getName() < RHS.getName(); |
| 390 | } |
| 391 | |
| 392 | private: |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | void RecomputeNeedsHandleIdentifier() { |
| 400 | NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() || |
| 401 | isExtensionToken() || isFutureCompatKeyword() || |
| 402 | isOutOfDate() || isModulesImport(); |
| 403 | } |
| 404 | }; |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | class PoisonIdentifierRAIIObject { |
| 411 | IdentifierInfo *const II; |
| 412 | const bool OldValue; |
| 413 | |
| 414 | public: |
| 415 | PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue) |
| 416 | : II(II), OldValue(II ? II->isPoisoned() : false) { |
| 417 | if(II) |
| 418 | II->setIsPoisoned(NewValue); |
| 419 | } |
| 420 | |
| 421 | ~PoisonIdentifierRAIIObject() { |
| 422 | if(II) |
| 423 | II->setIsPoisoned(OldValue); |
| 424 | } |
| 425 | }; |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | class IdentifierIterator { |
| 438 | protected: |
| 439 | IdentifierIterator() = default; |
| 440 | |
| 441 | public: |
| 442 | IdentifierIterator(const IdentifierIterator &) = delete; |
| 443 | IdentifierIterator &operator=(const IdentifierIterator &) = delete; |
| 444 | |
| 445 | virtual ~IdentifierIterator(); |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | virtual StringRef Next() = 0; |
| 453 | }; |
| 454 | |
| 455 | |
| 456 | class IdentifierInfoLookup { |
| 457 | public: |
| 458 | virtual ~IdentifierInfoLookup(); |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | virtual IdentifierInfo* get(StringRef Name) = 0; |
| 466 | |
| 467 | |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | virtual IdentifierIterator *getIdentifiers(); |
| 478 | }; |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | class IdentifierTable { |
| 486 | |
| 487 | |
| 488 | using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>; |
| 489 | HashTableTy HashTable; |
| 490 | |
| 491 | IdentifierInfoLookup* ExternalLookup; |
| 492 | |
| 493 | public: |
| 494 | |
| 495 | explicit IdentifierTable(IdentifierInfoLookup *ExternalLookup = nullptr); |
| 496 | |
| 497 | |
| 498 | |
| 499 | explicit IdentifierTable(const LangOptions &LangOpts, |
| 500 | IdentifierInfoLookup *ExternalLookup = nullptr); |
| 501 | |
| 502 | |
| 503 | void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup) { |
| 504 | ExternalLookup = IILookup; |
| 505 | } |
| 506 | |
| 507 | |
| 508 | IdentifierInfoLookup *getExternalIdentifierLookup() const { |
| 509 | return ExternalLookup; |
| 510 | } |
| 511 | |
| 512 | llvm::BumpPtrAllocator& getAllocator() { |
| 513 | return HashTable.getAllocator(); |
| 514 | } |
| 515 | |
| 516 | |
| 517 | |
| 518 | IdentifierInfo &get(StringRef Name) { |
| 519 | auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first; |
| 520 | |
| 521 | IdentifierInfo *&II = Entry.second; |
| 522 | if (II) return *II; |
| 523 | |
| 524 | |
| 525 | if (ExternalLookup) { |
| 526 | II = ExternalLookup->get(Name); |
| 527 | if (II) |
| 528 | return *II; |
| 529 | } |
| 530 | |
| 531 | |
| 532 | void *Mem = getAllocator().Allocate<IdentifierInfo>(); |
| 533 | II = new (Mem) IdentifierInfo(); |
| 534 | |
| 535 | |
| 536 | |
| 537 | II->Entry = &Entry; |
| 538 | |
| 539 | return *II; |
| 540 | } |
| 541 | |
| 542 | IdentifierInfo &get(StringRef Name, tok::TokenKind TokenCode) { |
| 543 | IdentifierInfo &II = get(Name); |
| 544 | II.TokenID = TokenCode; |
| 545 | (0) . __assert_fail ("II.TokenID == (unsigned) TokenCode && \"TokenCode too large\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/IdentifierTable.h", 545, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(II.TokenID == (unsigned) TokenCode && "TokenCode too large"); |
| 546 | return II; |
| 547 | } |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | IdentifierInfo &getOwn(StringRef Name) { |
| 556 | auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first; |
| 557 | |
| 558 | IdentifierInfo *&II = Entry.second; |
| 559 | if (II) |
| 560 | return *II; |
| 561 | |
| 562 | |
| 563 | void *Mem = getAllocator().Allocate<IdentifierInfo>(); |
| 564 | II = new (Mem) IdentifierInfo(); |
| 565 | |
| 566 | |
| 567 | |
| 568 | II->Entry = &Entry; |
| 569 | |
| 570 | |
| 571 | if (Name.equals("import")) |
| 572 | II->setModulesImport(true); |
| 573 | |
| 574 | return *II; |
| 575 | } |
| 576 | |
| 577 | using iterator = HashTableTy::const_iterator; |
| 578 | using const_iterator = HashTableTy::const_iterator; |
| 579 | |
| 580 | iterator begin() const { return HashTable.begin(); } |
| 581 | iterator end() const { return HashTable.end(); } |
| 582 | unsigned size() const { return HashTable.size(); } |
| 583 | |
| 584 | |
| 585 | |
| 586 | void PrintStats() const; |
| 587 | |
| 588 | |
| 589 | |
| 590 | void AddKeywords(const LangOptions &LangOpts); |
| 591 | }; |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | |
| 599 | |
| 600 | |
| 601 | |
| 602 | |
| 603 | |
| 604 | |
| 605 | |
| 606 | |
| 607 | |
| 608 | |
| 609 | |
| 610 | enum ObjCMethodFamily { |
| 611 | |
| 612 | OMF_None, |
| 613 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 618 | OMF_alloc, |
| 619 | OMF_copy, |
| 620 | OMF_init, |
| 621 | OMF_mutableCopy, |
| 622 | OMF_new, |
| 623 | |
| 624 | |
| 625 | |
| 626 | OMF_autorelease, |
| 627 | OMF_dealloc, |
| 628 | OMF_finalize, |
| 629 | OMF_release, |
| 630 | OMF_retain, |
| 631 | OMF_retainCount, |
| 632 | OMF_self, |
| 633 | OMF_initialize, |
| 634 | |
| 635 | |
| 636 | OMF_performSelector |
| 637 | }; |
| 638 | |
| 639 | |
| 640 | |
| 641 | enum { ObjCMethodFamilyBitWidth = 4 }; |
| 642 | |
| 643 | |
| 644 | enum { InvalidObjCMethodFamily = (1 << ObjCMethodFamilyBitWidth) - 1 }; |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | enum ObjCInstanceTypeFamily { |
| 651 | OIT_None, |
| 652 | OIT_Array, |
| 653 | OIT_Dictionary, |
| 654 | OIT_Singleton, |
| 655 | OIT_Init, |
| 656 | OIT_ReturnsSelf |
| 657 | }; |
| 658 | |
| 659 | enum ObjCStringFormatFamily { |
| 660 | SFF_None, |
| 661 | SFF_NSString, |
| 662 | SFF_CFString |
| 663 | }; |
| 664 | |
| 665 | |
| 666 | |
| 667 | |
| 668 | |
| 669 | |
| 670 | |
| 671 | |
| 672 | class Selector { |
| 673 | friend class Diagnostic; |
| 674 | friend class SelectorTable; |
| 675 | friend class DeclarationName; |
| 676 | |
| 677 | enum IdentifierInfoFlag { |
| 678 | |
| 679 | |
| 680 | ZeroArg = 0x01, |
| 681 | OneArg = 0x02, |
| 682 | MultiArg = 0x07, |
| 683 | ArgFlags = 0x07 |
| 684 | }; |
| 685 | |
| 686 | |
| 687 | |
| 688 | |
| 689 | |
| 690 | uintptr_t InfoPtr = 0; |
| 691 | |
| 692 | Selector(IdentifierInfo *II, unsigned nArgs) { |
| 693 | InfoPtr = reinterpret_cast<uintptr_t>(II); |
| 694 | (0) . __assert_fail ("(InfoPtr & ArgFlags) == 0 &&\"Insufficiently aligned IdentifierInfo\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/IdentifierTable.h", 694, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo"); |
| 695 | (0) . __assert_fail ("nArgs < 2 && \"nArgs not equal to 0/1\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/IdentifierTable.h", 695, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(nArgs < 2 && "nArgs not equal to 0/1"); |
| 696 | InfoPtr |= nArgs+1; |
| 697 | } |
| 698 | |
| 699 | Selector(MultiKeywordSelector *SI) { |
| 700 | InfoPtr = reinterpret_cast<uintptr_t>(SI); |
| 701 | (0) . __assert_fail ("(InfoPtr & ArgFlags) == 0 &&\"Insufficiently aligned IdentifierInfo\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/IdentifierTable.h", 701, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo"); |
| 702 | InfoPtr |= MultiArg; |
| 703 | } |
| 704 | |
| 705 | IdentifierInfo *getAsIdentifierInfo() const { |
| 706 | if (getIdentifierInfoFlag() < MultiArg) |
| 707 | return reinterpret_cast<IdentifierInfo *>(InfoPtr & ~ArgFlags); |
| 708 | return nullptr; |
| 709 | } |
| 710 | |
| 711 | MultiKeywordSelector *getMultiKeywordSelector() const { |
| 712 | return reinterpret_cast<MultiKeywordSelector *>(InfoPtr & ~ArgFlags); |
| 713 | } |
| 714 | |
| 715 | unsigned getIdentifierInfoFlag() const { |
| 716 | return InfoPtr & ArgFlags; |
| 717 | } |
| 718 | |
| 719 | static ObjCMethodFamily getMethodFamilyImpl(Selector sel); |
| 720 | |
| 721 | static ObjCStringFormatFamily getStringFormatFamilyImpl(Selector sel); |
| 722 | |
| 723 | public: |
| 724 | |
| 725 | |
| 726 | Selector() = default; |
| 727 | explicit Selector(uintptr_t V) : InfoPtr(V) {} |
| 728 | |
| 729 | |
| 730 | bool operator==(Selector RHS) const { |
| 731 | return InfoPtr == RHS.InfoPtr; |
| 732 | } |
| 733 | bool operator!=(Selector RHS) const { |
| 734 | return InfoPtr != RHS.InfoPtr; |
| 735 | } |
| 736 | |
| 737 | void *getAsOpaquePtr() const { |
| 738 | return reinterpret_cast<void*>(InfoPtr); |
| 739 | } |
| 740 | |
| 741 | |
| 742 | bool isNull() const { return InfoPtr == 0; } |
| 743 | |
| 744 | |
| 745 | bool isKeywordSelector() const { |
| 746 | return getIdentifierInfoFlag() != ZeroArg; |
| 747 | } |
| 748 | |
| 749 | bool isUnarySelector() const { |
| 750 | return getIdentifierInfoFlag() == ZeroArg; |
| 751 | } |
| 752 | |
| 753 | unsigned getNumArgs() const; |
| 754 | |
| 755 | |
| 756 | |
| 757 | |
| 758 | |
| 759 | |
| 760 | |
| 761 | |
| 762 | |
| 763 | |
| 764 | |
| 765 | |
| 766 | |
| 767 | |
| 768 | IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const; |
| 769 | |
| 770 | |
| 771 | |
| 772 | |
| 773 | |
| 774 | |
| 775 | |
| 776 | |
| 777 | |
| 778 | StringRef getNameForSlot(unsigned argIndex) const; |
| 779 | |
| 780 | |
| 781 | |
| 782 | std::string getAsString() const; |
| 783 | |
| 784 | |
| 785 | void print(llvm::raw_ostream &OS) const; |
| 786 | |
| 787 | void dump() const; |
| 788 | |
| 789 | |
| 790 | ObjCMethodFamily getMethodFamily() const { |
| 791 | return getMethodFamilyImpl(*this); |
| 792 | } |
| 793 | |
| 794 | ObjCStringFormatFamily getStringFormatFamily() const { |
| 795 | return getStringFormatFamilyImpl(*this); |
| 796 | } |
| 797 | |
| 798 | static Selector getEmptyMarker() { |
| 799 | return Selector(uintptr_t(-1)); |
| 800 | } |
| 801 | |
| 802 | static Selector getTombstoneMarker() { |
| 803 | return Selector(uintptr_t(-2)); |
| 804 | } |
| 805 | |
| 806 | static ObjCInstanceTypeFamily getInstTypeMethodFamily(Selector sel); |
| 807 | }; |
| 808 | |
| 809 | |
| 810 | |
| 811 | class SelectorTable { |
| 812 | |
| 813 | void *Impl; |
| 814 | |
| 815 | public: |
| 816 | SelectorTable(); |
| 817 | SelectorTable(const SelectorTable &) = delete; |
| 818 | SelectorTable &operator=(const SelectorTable &) = delete; |
| 819 | ~SelectorTable(); |
| 820 | |
| 821 | |
| 822 | |
| 823 | |
| 824 | |
| 825 | Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV); |
| 826 | |
| 827 | Selector getUnarySelector(IdentifierInfo *ID) { |
| 828 | return Selector(ID, 1); |
| 829 | } |
| 830 | |
| 831 | Selector getNullarySelector(IdentifierInfo *ID) { |
| 832 | return Selector(ID, 0); |
| 833 | } |
| 834 | |
| 835 | |
| 836 | size_t getTotalMemory() const; |
| 837 | |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | static SmallString<64> constructSetterName(StringRef Name); |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | static Selector constructSetterSelector(IdentifierTable &Idents, |
| 849 | SelectorTable &SelTable, |
| 850 | const IdentifierInfo *Name); |
| 851 | |
| 852 | |
| 853 | static std::string getPropertyNameFromSetterSelector(Selector Sel); |
| 854 | }; |
| 855 | |
| 856 | namespace detail { |
| 857 | |
| 858 | |
| 859 | |
| 860 | |
| 861 | |
| 862 | |
| 863 | |
| 864 | |
| 865 | |
| 866 | class alignas(IdentifierInfoAlignment) { |
| 867 | friend class clang::DeclarationName; |
| 868 | friend class clang::DeclarationNameTable; |
| 869 | |
| 870 | protected: |
| 871 | |
| 872 | |
| 873 | |
| 874 | |
| 875 | |
| 876 | enum { |
| 877 | , |
| 878 | , |
| 879 | , |
| 880 | |
| 881 | }; |
| 882 | |
| 883 | |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | |
| 889 | |
| 890 | |
| 891 | |
| 892 | |
| 893 | unsigned ; |
| 894 | |
| 895 | DeclarationNameExtra(ExtraKind Kind) : ExtraKindOrNumArgs(Kind) {} |
| 896 | DeclarationNameExtra(unsigned NumArgs) |
| 897 | : ExtraKindOrNumArgs(ObjCMultiArgSelector + NumArgs) {} |
| 898 | |
| 899 | |
| 900 | ExtraKind () const { |
| 901 | return static_cast<ExtraKind>(ExtraKindOrNumArgs > |
| 902 | (unsigned)ObjCMultiArgSelector |
| 903 | ? (unsigned)ObjCMultiArgSelector |
| 904 | : ExtraKindOrNumArgs); |
| 905 | } |
| 906 | |
| 907 | |
| 908 | |
| 909 | unsigned () const { |
| 910 | (0) . __assert_fail ("ExtraKindOrNumArgs >= (unsigned)ObjCMultiArgSelector && \"getNumArgs called but this is not an ObjC selector!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/IdentifierTable.h", 911, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(ExtraKindOrNumArgs >= (unsigned)ObjCMultiArgSelector && |
| 911 | (0) . __assert_fail ("ExtraKindOrNumArgs >= (unsigned)ObjCMultiArgSelector && \"getNumArgs called but this is not an ObjC selector!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/IdentifierTable.h", 911, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "getNumArgs called but this is not an ObjC selector!"); |
| 912 | return ExtraKindOrNumArgs - (unsigned)ObjCMultiArgSelector; |
| 913 | } |
| 914 | }; |
| 915 | |
| 916 | } |
| 917 | |
| 918 | } |
| 919 | |
| 920 | namespace llvm { |
| 921 | |
| 922 | |
| 923 | |
| 924 | template <> |
| 925 | struct DenseMapInfo<clang::Selector> { |
| 926 | static clang::Selector getEmptyKey() { |
| 927 | return clang::Selector::getEmptyMarker(); |
| 928 | } |
| 929 | |
| 930 | static clang::Selector getTombstoneKey() { |
| 931 | return clang::Selector::getTombstoneMarker(); |
| 932 | } |
| 933 | |
| 934 | static unsigned getHashValue(clang::Selector S); |
| 935 | |
| 936 | static bool isEqual(clang::Selector LHS, clang::Selector RHS) { |
| 937 | return LHS == RHS; |
| 938 | } |
| 939 | }; |
| 940 | |
| 941 | template<> |
| 942 | struct PointerLikeTypeTraits<clang::Selector> { |
| 943 | static const void *getAsVoidPointer(clang::Selector P) { |
| 944 | return P.getAsOpaquePtr(); |
| 945 | } |
| 946 | |
| 947 | static clang::Selector getFromVoidPointer(const void *P) { |
| 948 | return clang::Selector(reinterpret_cast<uintptr_t>(P)); |
| 949 | } |
| 950 | |
| 951 | enum { NumLowBitsAvailable = 0 }; |
| 952 | }; |
| 953 | |
| 954 | |
| 955 | |
| 956 | template<> |
| 957 | struct PointerLikeTypeTraits<clang::IdentifierInfo*> { |
| 958 | static void *getAsVoidPointer(clang::IdentifierInfo* P) { |
| 959 | return P; |
| 960 | } |
| 961 | |
| 962 | static clang::IdentifierInfo *getFromVoidPointer(void *P) { |
| 963 | return static_cast<clang::IdentifierInfo*>(P); |
| 964 | } |
| 965 | |
| 966 | enum { NumLowBitsAvailable = 1 }; |
| 967 | }; |
| 968 | |
| 969 | template<> |
| 970 | struct PointerLikeTypeTraits<const clang::IdentifierInfo*> { |
| 971 | static const void *getAsVoidPointer(const clang::IdentifierInfo* P) { |
| 972 | return P; |
| 973 | } |
| 974 | |
| 975 | static const clang::IdentifierInfo *getFromVoidPointer(const void *P) { |
| 976 | return static_cast<const clang::IdentifierInfo*>(P); |
| 977 | } |
| 978 | |
| 979 | enum { NumLowBitsAvailable = 1 }; |
| 980 | }; |
| 981 | |
| 982 | } |
| 983 | |
| 984 | #endif |
| 985 | |