| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | #ifndef LLVM_CLANG_BASIC_SOURCEMANAGER_H |
| 35 | #define LLVM_CLANG_BASIC_SOURCEMANAGER_H |
| 36 | |
| 37 | #include "clang/Basic/Diagnostic.h" |
| 38 | #include "clang/Basic/FileManager.h" |
| 39 | #include "clang/Basic/SourceLocation.h" |
| 40 | #include "llvm/ADT/ArrayRef.h" |
| 41 | #include "llvm/ADT/BitVector.h" |
| 42 | #include "llvm/ADT/DenseMap.h" |
| 43 | #include "llvm/ADT/DenseSet.h" |
| 44 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
| 45 | #include "llvm/ADT/PointerIntPair.h" |
| 46 | #include "llvm/ADT/SmallVector.h" |
| 47 | #include "llvm/ADT/StringRef.h" |
| 48 | #include "llvm/Support/Allocator.h" |
| 49 | #include "llvm/Support/Compiler.h" |
| 50 | #include "llvm/Support/MemoryBuffer.h" |
| 51 | #include <cassert> |
| 52 | #include <cstddef> |
| 53 | #include <map> |
| 54 | #include <memory> |
| 55 | #include <string> |
| 56 | #include <utility> |
| 57 | #include <vector> |
| 58 | |
| 59 | namespace clang { |
| 60 | |
| 61 | class ASTReader; |
| 62 | class ASTWriter; |
| 63 | class LineTableInfo; |
| 64 | class SourceManager; |
| 65 | |
| 66 | |
| 67 | |
| 68 | namespace SrcMgr { |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | enum CharacteristicKind { |
| 78 | C_User, C_System, C_ExternCSystem, C_User_ModuleMap, C_System_ModuleMap |
| 79 | }; |
| 80 | |
| 81 | |
| 82 | inline bool isSystem(CharacteristicKind CK) { |
| 83 | return CK != C_User && CK != C_User_ModuleMap; |
| 84 | } |
| 85 | |
| 86 | |
| 87 | inline bool isModuleMap(CharacteristicKind CK) { |
| 88 | return CK == C_User_ModuleMap || CK == C_System_ModuleMap; |
| 89 | } |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | class alignas(8) ContentCache { |
| 95 | enum CCFlags { |
| 96 | |
| 97 | InvalidFlag = 0x01, |
| 98 | |
| 99 | |
| 100 | DoNotFreeFlag = 0x02 |
| 101 | }; |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | mutable llvm::PointerIntPair<llvm::MemoryBuffer *, 2> Buffer; |
| 109 | |
| 110 | public: |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | const FileEntry *OrigEntry; |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | const FileEntry *ContentsEntry; |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | unsigned *SourceLineCache = nullptr; |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | unsigned NumLines = 0; |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | unsigned BufferOverridden : 1; |
| 142 | |
| 143 | |
| 144 | |
| 145 | unsigned IsSystemFile : 1; |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | unsigned IsTransient : 1; |
| 151 | |
| 152 | ContentCache(const FileEntry *Ent = nullptr) : ContentCache(Ent, Ent) {} |
| 153 | |
| 154 | ContentCache(const FileEntry *Ent, const FileEntry *contentEnt) |
| 155 | : Buffer(nullptr, false), OrigEntry(Ent), ContentsEntry(contentEnt), |
| 156 | BufferOverridden(false), IsSystemFile(false), IsTransient(false) {} |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | ContentCache(const ContentCache &RHS) |
| 162 | : Buffer(nullptr, false), BufferOverridden(false), IsSystemFile(false), |
| 163 | IsTransient(false) { |
| 164 | OrigEntry = RHS.OrigEntry; |
| 165 | ContentsEntry = RHS.ContentsEntry; |
| 166 | |
| 167 | (0) . __assert_fail ("RHS.Buffer.getPointer() == nullptr && RHS.SourceLineCache == nullptr && \"Passed ContentCache object cannot own a buffer.\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 169, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(RHS.Buffer.getPointer() == nullptr && |
| 168 | (0) . __assert_fail ("RHS.Buffer.getPointer() == nullptr && RHS.SourceLineCache == nullptr && \"Passed ContentCache object cannot own a buffer.\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 169, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> RHS.SourceLineCache == nullptr && |
| 169 | (0) . __assert_fail ("RHS.Buffer.getPointer() == nullptr && RHS.SourceLineCache == nullptr && \"Passed ContentCache object cannot own a buffer.\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 169, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Passed ContentCache object cannot own a buffer."); |
| 170 | |
| 171 | NumLines = RHS.NumLines; |
| 172 | } |
| 173 | |
| 174 | ContentCache &operator=(const ContentCache& RHS) = delete; |
| 175 | |
| 176 | ~ContentCache(); |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | llvm::MemoryBuffer *getBuffer(DiagnosticsEngine &Diag, |
| 188 | const SourceManager &SM, |
| 189 | SourceLocation Loc = SourceLocation(), |
| 190 | bool *Invalid = nullptr) const; |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | unsigned getSize() const; |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | unsigned getSizeBytesMapped() const; |
| 205 | |
| 206 | |
| 207 | |
| 208 | llvm::MemoryBuffer::BufferKind getMemoryBufferKind() const; |
| 209 | |
| 210 | |
| 211 | |
| 212 | llvm::MemoryBuffer *getRawBuffer() const { return Buffer.getPointer(); } |
| 213 | |
| 214 | |
| 215 | |
| 216 | void replaceBuffer(llvm::MemoryBuffer *B, bool DoNotFree = false); |
| 217 | |
| 218 | |
| 219 | bool isBufferInvalid() const { |
| 220 | return Buffer.getInt() & InvalidFlag; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | bool shouldFreeBuffer() const { |
| 225 | return (Buffer.getInt() & DoNotFreeFlag) == 0; |
| 226 | } |
| 227 | }; |
| 228 | |
| 229 | |
| 230 | |
| 231 | static_assert(alignof(ContentCache) >= 8, |
| 232 | "ContentCache must be 8-byte aligned."); |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | class FileInfo { |
| 244 | friend class clang::SourceManager; |
| 245 | friend class clang::ASTWriter; |
| 246 | friend class clang::ASTReader; |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | unsigned IncludeLoc; |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | unsigned NumCreatedFIDs : 31; |
| 258 | |
| 259 | |
| 260 | unsigned HasLineDirectives : 1; |
| 261 | |
| 262 | |
| 263 | llvm::PointerIntPair<const ContentCache*, 3, CharacteristicKind> |
| 264 | ContentAndKind; |
| 265 | |
| 266 | public: |
| 267 | |
| 268 | static FileInfo get(SourceLocation IL, const ContentCache *Con, |
| 269 | CharacteristicKind FileCharacter) { |
| 270 | FileInfo X; |
| 271 | X.IncludeLoc = IL.getRawEncoding(); |
| 272 | X.NumCreatedFIDs = 0; |
| 273 | X.HasLineDirectives = false; |
| 274 | X.ContentAndKind.setPointer(Con); |
| 275 | X.ContentAndKind.setInt(FileCharacter); |
| 276 | return X; |
| 277 | } |
| 278 | |
| 279 | SourceLocation getIncludeLoc() const { |
| 280 | return SourceLocation::getFromRawEncoding(IncludeLoc); |
| 281 | } |
| 282 | |
| 283 | const ContentCache *getContentCache() const { |
| 284 | return ContentAndKind.getPointer(); |
| 285 | } |
| 286 | |
| 287 | |
| 288 | CharacteristicKind getFileCharacteristic() const { |
| 289 | return ContentAndKind.getInt(); |
| 290 | } |
| 291 | |
| 292 | |
| 293 | bool hasLineDirectives() const { return HasLineDirectives; } |
| 294 | |
| 295 | |
| 296 | |
| 297 | void setHasLineDirectives() { |
| 298 | HasLineDirectives = true; |
| 299 | } |
| 300 | }; |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | class ExpansionInfo { |
| 306 | |
| 307 | |
| 308 | |
| 309 | unsigned SpellingLoc; |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | unsigned ExpansionLocStart, ExpansionLocEnd; |
| 318 | |
| 319 | |
| 320 | bool ExpansionIsTokenRange; |
| 321 | |
| 322 | public: |
| 323 | SourceLocation getSpellingLoc() const { |
| 324 | SourceLocation SpellLoc = SourceLocation::getFromRawEncoding(SpellingLoc); |
| 325 | return SpellLoc.isInvalid() ? getExpansionLocStart() : SpellLoc; |
| 326 | } |
| 327 | |
| 328 | SourceLocation getExpansionLocStart() const { |
| 329 | return SourceLocation::getFromRawEncoding(ExpansionLocStart); |
| 330 | } |
| 331 | |
| 332 | SourceLocation getExpansionLocEnd() const { |
| 333 | SourceLocation EndLoc = |
| 334 | SourceLocation::getFromRawEncoding(ExpansionLocEnd); |
| 335 | return EndLoc.isInvalid() ? getExpansionLocStart() : EndLoc; |
| 336 | } |
| 337 | |
| 338 | bool isExpansionTokenRange() const { |
| 339 | return ExpansionIsTokenRange; |
| 340 | } |
| 341 | |
| 342 | CharSourceRange getExpansionLocRange() const { |
| 343 | return CharSourceRange( |
| 344 | SourceRange(getExpansionLocStart(), getExpansionLocEnd()), |
| 345 | isExpansionTokenRange()); |
| 346 | } |
| 347 | |
| 348 | bool isMacroArgExpansion() const { |
| 349 | |
| 350 | return getExpansionLocStart().isValid() && |
| 351 | SourceLocation::getFromRawEncoding(ExpansionLocEnd).isInvalid(); |
| 352 | } |
| 353 | |
| 354 | bool isMacroBodyExpansion() const { |
| 355 | return getExpansionLocStart().isValid() && |
| 356 | SourceLocation::getFromRawEncoding(ExpansionLocEnd).isValid(); |
| 357 | } |
| 358 | |
| 359 | bool isFunctionMacroExpansion() const { |
| 360 | return getExpansionLocStart().isValid() && |
| 361 | getExpansionLocStart() != getExpansionLocEnd(); |
| 362 | } |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | static ExpansionInfo create(SourceLocation SpellingLoc, |
| 371 | SourceLocation Start, SourceLocation End, |
| 372 | bool ExpansionIsTokenRange = true) { |
| 373 | ExpansionInfo X; |
| 374 | X.SpellingLoc = SpellingLoc.getRawEncoding(); |
| 375 | X.ExpansionLocStart = Start.getRawEncoding(); |
| 376 | X.ExpansionLocEnd = End.getRawEncoding(); |
| 377 | X.ExpansionIsTokenRange = ExpansionIsTokenRange; |
| 378 | return X; |
| 379 | } |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | static ExpansionInfo createForMacroArg(SourceLocation SpellingLoc, |
| 401 | SourceLocation ExpansionLoc) { |
| 402 | |
| 403 | |
| 404 | |
| 405 | return create(SpellingLoc, ExpansionLoc, SourceLocation()); |
| 406 | } |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | static ExpansionInfo createForTokenSplit(SourceLocation SpellingLoc, |
| 414 | SourceLocation Start, |
| 415 | SourceLocation End) { |
| 416 | return create(SpellingLoc, Start, End, false); |
| 417 | } |
| 418 | }; |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | class SLocEntry { |
| 425 | unsigned Offset : 31; |
| 426 | unsigned IsExpansion : 1; |
| 427 | union { |
| 428 | FileInfo File; |
| 429 | ExpansionInfo Expansion; |
| 430 | }; |
| 431 | |
| 432 | public: |
| 433 | SLocEntry() : Offset(), IsExpansion(), File() {} |
| 434 | |
| 435 | unsigned getOffset() const { return Offset; } |
| 436 | |
| 437 | bool isExpansion() const { return IsExpansion; } |
| 438 | bool isFile() const { return !isExpansion(); } |
| 439 | |
| 440 | const FileInfo &getFile() const { |
| 441 | (0) . __assert_fail ("isFile() && \"Not a file SLocEntry!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 441, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isFile() && "Not a file SLocEntry!"); |
| 442 | return File; |
| 443 | } |
| 444 | |
| 445 | const ExpansionInfo &getExpansion() const { |
| 446 | (0) . __assert_fail ("isExpansion() && \"Not a macro expansion SLocEntry!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 446, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isExpansion() && "Not a macro expansion SLocEntry!"); |
| 447 | return Expansion; |
| 448 | } |
| 449 | |
| 450 | static SLocEntry get(unsigned Offset, const FileInfo &FI) { |
| 451 | (0) . __assert_fail ("!(Offset & (1u << 31)) && \"Offset is too large\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 451, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!(Offset & (1u << 31)) && "Offset is too large"); |
| 452 | SLocEntry E; |
| 453 | E.Offset = Offset; |
| 454 | E.IsExpansion = false; |
| 455 | E.File = FI; |
| 456 | return E; |
| 457 | } |
| 458 | |
| 459 | static SLocEntry get(unsigned Offset, const ExpansionInfo &Expansion) { |
| 460 | (0) . __assert_fail ("!(Offset & (1u << 31)) && \"Offset is too large\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 460, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!(Offset & (1u << 31)) && "Offset is too large"); |
| 461 | SLocEntry E; |
| 462 | E.Offset = Offset; |
| 463 | E.IsExpansion = true; |
| 464 | E.Expansion = Expansion; |
| 465 | return E; |
| 466 | } |
| 467 | }; |
| 468 | |
| 469 | } |
| 470 | |
| 471 | |
| 472 | class ExternalSLocEntrySource { |
| 473 | public: |
| 474 | virtual ~ExternalSLocEntrySource(); |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | virtual bool ReadSLocEntry(int ID) = 0; |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | virtual std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) = 0; |
| 487 | }; |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | class InBeforeInTUCacheEntry { |
| 494 | |
| 495 | |
| 496 | |
| 497 | FileID LQueryFID, RQueryFID; |
| 498 | |
| 499 | |
| 500 | |
| 501 | |
| 502 | bool IsLQFIDBeforeRQFID; |
| 503 | |
| 504 | |
| 505 | |
| 506 | FileID CommonFID; |
| 507 | |
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 512 | |
| 513 | unsigned LCommonOffset, RCommonOffset; |
| 514 | |
| 515 | public: |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | bool isCacheValid(FileID LHS, FileID RHS) const { |
| 521 | return LQueryFID == LHS && RQueryFID == RHS; |
| 522 | } |
| 523 | |
| 524 | |
| 525 | |
| 526 | bool getCachedResult(unsigned LOffset, unsigned ROffset) const { |
| 527 | |
| 528 | |
| 529 | if (LQueryFID != CommonFID) LOffset = LCommonOffset; |
| 530 | if (RQueryFID != CommonFID) ROffset = RCommonOffset; |
| 531 | |
| 532 | |
| 533 | |
| 534 | |
| 535 | |
| 536 | |
| 537 | if (LOffset == ROffset) |
| 538 | return IsLQFIDBeforeRQFID; |
| 539 | |
| 540 | return LOffset < ROffset; |
| 541 | } |
| 542 | |
| 543 | |
| 544 | void setQueryFIDs(FileID LHS, FileID RHS, bool isLFIDBeforeRFID) { |
| 545 | assert(LHS != RHS); |
| 546 | LQueryFID = LHS; |
| 547 | RQueryFID = RHS; |
| 548 | IsLQFIDBeforeRQFID = isLFIDBeforeRFID; |
| 549 | } |
| 550 | |
| 551 | void clear() { |
| 552 | LQueryFID = RQueryFID = FileID(); |
| 553 | IsLQFIDBeforeRQFID = false; |
| 554 | } |
| 555 | |
| 556 | void setCommonLoc(FileID commonFID, unsigned lCommonOffset, |
| 557 | unsigned rCommonOffset) { |
| 558 | CommonFID = commonFID; |
| 559 | LCommonOffset = lCommonOffset; |
| 560 | RCommonOffset = rCommonOffset; |
| 561 | } |
| 562 | }; |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 | using ModuleBuildStack = ArrayRef<std::pair<std::string, FullSourceLoc>>; |
| 568 | |
| 569 | |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | class SourceManager : public RefCountedBase<SourceManager> { |
| 582 | |
| 583 | DiagnosticsEngine &Diag; |
| 584 | |
| 585 | FileManager &FileMgr; |
| 586 | |
| 587 | mutable llvm::BumpPtrAllocator ContentCacheAlloc; |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*> FileInfos; |
| 596 | |
| 597 | |
| 598 | |
| 599 | bool OverridenFilesKeepOriginalName = true; |
| 600 | |
| 601 | |
| 602 | |
| 603 | bool UserFilesAreVolatile; |
| 604 | |
| 605 | |
| 606 | |
| 607 | |
| 608 | bool FilesAreTransient = false; |
| 609 | |
| 610 | struct OverriddenFilesInfoTy { |
| 611 | |
| 612 | |
| 613 | llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles; |
| 614 | |
| 615 | |
| 616 | llvm::DenseSet<const FileEntry *> OverriddenFilesWithBuffer; |
| 617 | }; |
| 618 | |
| 619 | |
| 620 | |
| 621 | std::unique_ptr<OverriddenFilesInfoTy> OverriddenFilesInfo; |
| 622 | |
| 623 | OverriddenFilesInfoTy &getOverriddenFilesInfo() { |
| 624 | if (!OverriddenFilesInfo) |
| 625 | OverriddenFilesInfo.reset(new OverriddenFilesInfoTy); |
| 626 | return *OverriddenFilesInfo; |
| 627 | } |
| 628 | |
| 629 | |
| 630 | |
| 631 | |
| 632 | |
| 633 | std::vector<SrcMgr::ContentCache*> MemBufferInfos; |
| 634 | |
| 635 | |
| 636 | |
| 637 | |
| 638 | |
| 639 | SmallVector<SrcMgr::SLocEntry, 0> LocalSLocEntryTable; |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | mutable SmallVector<SrcMgr::SLocEntry, 0> LoadedSLocEntryTable; |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | unsigned NextLocalOffset; |
| 651 | |
| 652 | |
| 653 | |
| 654 | |
| 655 | |
| 656 | unsigned CurrentLoadedOffset; |
| 657 | |
| 658 | |
| 659 | |
| 660 | static const unsigned MaxLoadedOffset = 1U << 31U; |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | llvm::BitVector SLocEntryLoaded; |
| 667 | |
| 668 | |
| 669 | ExternalSLocEntrySource *ExternalSLocEntries = nullptr; |
| 670 | |
| 671 | |
| 672 | |
| 673 | |
| 674 | |
| 675 | mutable FileID LastFileIDLookup; |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | LineTableInfo *LineTable = nullptr; |
| 681 | |
| 682 | |
| 683 | |
| 684 | mutable FileID LastLineNoFileIDQuery; |
| 685 | mutable SrcMgr::ContentCache *LastLineNoContentCache; |
| 686 | mutable unsigned LastLineNoFilePos; |
| 687 | mutable unsigned LastLineNoResult; |
| 688 | |
| 689 | |
| 690 | FileID MainFileID; |
| 691 | |
| 692 | |
| 693 | FileID PreambleFileID; |
| 694 | |
| 695 | |
| 696 | mutable unsigned NumLinearScans = 0; |
| 697 | mutable unsigned NumBinaryProbes = 0; |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | mutable llvm::DenseMap<FileID, std::pair<FileID, unsigned>> IncludedLocMap; |
| 705 | |
| 706 | |
| 707 | using IsBeforeInTUCacheKey = std::pair<FileID, FileID>; |
| 708 | |
| 709 | |
| 710 | |
| 711 | using InBeforeInTUCache = |
| 712 | llvm::DenseMap<IsBeforeInTUCacheKey, InBeforeInTUCacheEntry>; |
| 713 | |
| 714 | |
| 715 | mutable InBeforeInTUCache IBTUCache; |
| 716 | mutable InBeforeInTUCacheEntry IBTUCacheOverflow; |
| 717 | |
| 718 | |
| 719 | |
| 720 | InBeforeInTUCacheEntry &getInBeforeInTUCache(FileID LFID, FileID RFID) const; |
| 721 | |
| 722 | |
| 723 | mutable std::unique_ptr<llvm::MemoryBuffer> FakeBufferForRecovery; |
| 724 | |
| 725 | mutable std::unique_ptr<SrcMgr::ContentCache> FakeContentCacheForRecovery; |
| 726 | |
| 727 | |
| 728 | |
| 729 | using MacroArgsMap = std::map<unsigned, SourceLocation>; |
| 730 | |
| 731 | mutable llvm::DenseMap<FileID, std::unique_ptr<MacroArgsMap>> |
| 732 | MacroArgsCacheMap; |
| 733 | |
| 734 | |
| 735 | |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | SmallVector<std::pair<std::string, FullSourceLoc>, 2> StoredModuleBuildStack; |
| 742 | |
| 743 | public: |
| 744 | SourceManager(DiagnosticsEngine &Diag, FileManager &FileMgr, |
| 745 | bool UserFilesAreVolatile = false); |
| 746 | explicit SourceManager(const SourceManager &) = delete; |
| 747 | SourceManager &operator=(const SourceManager &) = delete; |
| 748 | ~SourceManager(); |
| 749 | |
| 750 | void clearIDTables(); |
| 751 | |
| 752 | |
| 753 | |
| 754 | void initializeForReplay(const SourceManager &Old); |
| 755 | |
| 756 | DiagnosticsEngine &getDiagnostics() const { return Diag; } |
| 757 | |
| 758 | FileManager &getFileManager() const { return FileMgr; } |
| 759 | |
| 760 | |
| 761 | |
| 762 | |
| 763 | void setOverridenFilesKeepOriginalName(bool value) { |
| 764 | OverridenFilesKeepOriginalName = value; |
| 765 | } |
| 766 | |
| 767 | |
| 768 | |
| 769 | bool userFilesAreVolatile() const { return UserFilesAreVolatile; } |
| 770 | |
| 771 | |
| 772 | ModuleBuildStack getModuleBuildStack() const { |
| 773 | return StoredModuleBuildStack; |
| 774 | } |
| 775 | |
| 776 | |
| 777 | void setModuleBuildStack(ModuleBuildStack stack) { |
| 778 | StoredModuleBuildStack.clear(); |
| 779 | StoredModuleBuildStack.append(stack.begin(), stack.end()); |
| 780 | } |
| 781 | |
| 782 | |
| 783 | void pushModuleBuildStack(StringRef moduleName, FullSourceLoc importLoc) { |
| 784 | StoredModuleBuildStack.push_back(std::make_pair(moduleName.str(),importLoc)); |
| 785 | } |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | FileID getMainFileID() const { return MainFileID; } |
| 793 | |
| 794 | |
| 795 | void setMainFileID(FileID FID) { |
| 796 | MainFileID = FID; |
| 797 | } |
| 798 | |
| 799 | |
| 800 | void setPreambleFileID(FileID Preamble) { |
| 801 | (0) . __assert_fail ("PreambleFileID.isInvalid() && \"PreambleFileID already set!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 801, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(PreambleFileID.isInvalid() && "PreambleFileID already set!"); |
| 802 | PreambleFileID = Preamble; |
| 803 | } |
| 804 | |
| 805 | |
| 806 | FileID getPreambleFileID() const { return PreambleFileID; } |
| 807 | |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | |
| 815 | |
| 816 | FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, |
| 817 | SrcMgr::CharacteristicKind FileCharacter, |
| 818 | int LoadedID = 0, unsigned LoadedOffset = 0) { |
| 819 | const SrcMgr::ContentCache *IR = |
| 820 | getOrCreateContentCache(SourceFile, isSystem(FileCharacter)); |
| 821 | (0) . __assert_fail ("IR && \"getOrCreateContentCache() cannot return NULL\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 821, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(IR && "getOrCreateContentCache() cannot return NULL"); |
| 822 | return createFileID(IR, IncludePos, FileCharacter, LoadedID, LoadedOffset); |
| 823 | } |
| 824 | |
| 825 | |
| 826 | |
| 827 | |
| 828 | |
| 829 | FileID createFileID(std::unique_ptr<llvm::MemoryBuffer> Buffer, |
| 830 | SrcMgr::CharacteristicKind FileCharacter = SrcMgr::C_User, |
| 831 | int LoadedID = 0, unsigned LoadedOffset = 0, |
| 832 | SourceLocation IncludeLoc = SourceLocation()) { |
| 833 | return createFileID( |
| 834 | createMemBufferContentCache(Buffer.release(), false), |
| 835 | IncludeLoc, FileCharacter, LoadedID, LoadedOffset); |
| 836 | } |
| 837 | |
| 838 | enum UnownedTag { Unowned }; |
| 839 | |
| 840 | |
| 841 | |
| 842 | |
| 843 | |
| 844 | FileID createFileID(UnownedTag, llvm::MemoryBuffer *Buffer, |
| 845 | SrcMgr::CharacteristicKind FileCharacter = SrcMgr::C_User, |
| 846 | int LoadedID = 0, unsigned LoadedOffset = 0, |
| 847 | SourceLocation IncludeLoc = SourceLocation()) { |
| 848 | return createFileID(createMemBufferContentCache(Buffer, ), |
| 849 | IncludeLoc, FileCharacter, LoadedID, LoadedOffset); |
| 850 | } |
| 851 | |
| 852 | |
| 853 | |
| 854 | FileID getOrCreateFileID(const FileEntry *SourceFile, |
| 855 | SrcMgr::CharacteristicKind FileCharacter) { |
| 856 | FileID ID = translateFile(SourceFile); |
| 857 | return ID.isValid() ? ID : createFileID(SourceFile, SourceLocation(), |
| 858 | FileCharacter); |
| 859 | } |
| 860 | |
| 861 | |
| 862 | |
| 863 | |
| 864 | |
| 865 | SourceLocation createMacroArgExpansionLoc(SourceLocation Loc, |
| 866 | SourceLocation ExpansionLoc, |
| 867 | unsigned TokLength); |
| 868 | |
| 869 | |
| 870 | |
| 871 | |
| 872 | SourceLocation createExpansionLoc(SourceLocation Loc, |
| 873 | SourceLocation ExpansionLocStart, |
| 874 | SourceLocation ExpansionLocEnd, |
| 875 | unsigned TokLength, |
| 876 | bool ExpansionIsTokenRange = true, |
| 877 | int LoadedID = 0, |
| 878 | unsigned LoadedOffset = 0); |
| 879 | |
| 880 | |
| 881 | |
| 882 | SourceLocation createTokenSplitLoc(SourceLocation SpellingLoc, |
| 883 | SourceLocation TokenStart, |
| 884 | SourceLocation TokenEnd); |
| 885 | |
| 886 | |
| 887 | |
| 888 | |
| 889 | |
| 890 | llvm::MemoryBuffer *getMemoryBufferForFile(const FileEntry *File, |
| 891 | bool *Invalid = nullptr); |
| 892 | |
| 893 | |
| 894 | |
| 895 | |
| 896 | |
| 897 | |
| 898 | |
| 899 | |
| 900 | |
| 901 | |
| 902 | |
| 903 | void overrideFileContents(const FileEntry *SourceFile, |
| 904 | llvm::MemoryBuffer *Buffer, bool DoNotFree); |
| 905 | void overrideFileContents(const FileEntry *SourceFile, |
| 906 | std::unique_ptr<llvm::MemoryBuffer> Buffer) { |
| 907 | overrideFileContents(SourceFile, Buffer.release(), false); |
| 908 | } |
| 909 | |
| 910 | |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | |
| 916 | void overrideFileContents(const FileEntry *SourceFile, |
| 917 | const FileEntry *NewFile); |
| 918 | |
| 919 | |
| 920 | bool isFileOverridden(const FileEntry *File) const { |
| 921 | if (OverriddenFilesInfo) { |
| 922 | if (OverriddenFilesInfo->OverriddenFilesWithBuffer.count(File)) |
| 923 | return true; |
| 924 | if (OverriddenFilesInfo->OverriddenFiles.find(File) != |
| 925 | OverriddenFilesInfo->OverriddenFiles.end()) |
| 926 | return true; |
| 927 | } |
| 928 | return false; |
| 929 | } |
| 930 | |
| 931 | |
| 932 | |
| 933 | |
| 934 | |
| 935 | void disableFileContentsOverride(const FileEntry *File); |
| 936 | |
| 937 | |
| 938 | void setFileIsTransient(const FileEntry *SourceFile); |
| 939 | |
| 940 | |
| 941 | |
| 942 | void setAllFilesAreTransient(bool Transient) { |
| 943 | FilesAreTransient = Transient; |
| 944 | } |
| 945 | |
| 946 | |
| 947 | |
| 948 | |
| 949 | |
| 950 | |
| 951 | |
| 952 | |
| 953 | |
| 954 | llvm::MemoryBuffer *getBuffer(FileID FID, SourceLocation Loc, |
| 955 | bool *Invalid = nullptr) const { |
| 956 | bool MyInvalid = false; |
| 957 | const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &MyInvalid); |
| 958 | if (MyInvalid || !Entry.isFile()) { |
| 959 | if (Invalid) |
| 960 | *Invalid = true; |
| 961 | |
| 962 | return getFakeBufferForRecovery(); |
| 963 | } |
| 964 | |
| 965 | return Entry.getFile().getContentCache()->getBuffer(Diag, *this, Loc, |
| 966 | Invalid); |
| 967 | } |
| 968 | |
| 969 | llvm::MemoryBuffer *getBuffer(FileID FID, bool *Invalid = nullptr) const { |
| 970 | bool MyInvalid = false; |
| 971 | const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &MyInvalid); |
| 972 | if (MyInvalid || !Entry.isFile()) { |
| 973 | if (Invalid) |
| 974 | *Invalid = true; |
| 975 | |
| 976 | return getFakeBufferForRecovery(); |
| 977 | } |
| 978 | |
| 979 | return Entry.getFile().getContentCache()->getBuffer(Diag, *this, |
| 980 | SourceLocation(), |
| 981 | Invalid); |
| 982 | } |
| 983 | |
| 984 | |
| 985 | const FileEntry *getFileEntryForID(FileID FID) const { |
| 986 | bool MyInvalid = false; |
| 987 | const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &MyInvalid); |
| 988 | if (MyInvalid || !Entry.isFile()) |
| 989 | return nullptr; |
| 990 | |
| 991 | const SrcMgr::ContentCache *Content = Entry.getFile().getContentCache(); |
| 992 | if (!Content) |
| 993 | return nullptr; |
| 994 | return Content->OrigEntry; |
| 995 | } |
| 996 | |
| 997 | |
| 998 | const FileEntry *getFileEntryForSLocEntry(const SrcMgr::SLocEntry &sloc) const |
| 999 | { |
| 1000 | const SrcMgr::ContentCache *Content = sloc.getFile().getContentCache(); |
| 1001 | if (!Content) |
| 1002 | return nullptr; |
| 1003 | return Content->OrigEntry; |
| 1004 | } |
| 1005 | |
| 1006 | |
| 1007 | |
| 1008 | |
| 1009 | |
| 1010 | |
| 1011 | StringRef getBufferData(FileID FID, bool *Invalid = nullptr) const; |
| 1012 | |
| 1013 | |
| 1014 | |
| 1015 | unsigned getNumCreatedFIDsForFileID(FileID FID) const { |
| 1016 | bool Invalid = false; |
| 1017 | const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); |
| 1018 | if (Invalid || !Entry.isFile()) |
| 1019 | return 0; |
| 1020 | |
| 1021 | return Entry.getFile().NumCreatedFIDs; |
| 1022 | } |
| 1023 | |
| 1024 | |
| 1025 | |
| 1026 | void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs, |
| 1027 | bool Force = false) const { |
| 1028 | bool Invalid = false; |
| 1029 | const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); |
| 1030 | if (Invalid || !Entry.isFile()) |
| 1031 | return; |
| 1032 | |
| 1033 | (0) . __assert_fail ("(Force || Entry.getFile().NumCreatedFIDs == 0) && \"Already set!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 1033, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((Force || Entry.getFile().NumCreatedFIDs == 0) && "Already set!"); |
| 1034 | const_cast<SrcMgr::FileInfo &>(Entry.getFile()).NumCreatedFIDs = NumFIDs; |
| 1035 | } |
| 1036 | |
| 1037 | |
| 1038 | |
| 1039 | |
| 1040 | |
| 1041 | |
| 1042 | |
| 1043 | |
| 1044 | |
| 1045 | |
| 1046 | |
| 1047 | FileID getFileID(SourceLocation SpellingLoc) const { |
| 1048 | unsigned SLocOffset = SpellingLoc.getOffset(); |
| 1049 | |
| 1050 | |
| 1051 | if (isOffsetInFileID(LastFileIDLookup, SLocOffset)) |
| 1052 | return LastFileIDLookup; |
| 1053 | |
| 1054 | return getFileIDSlow(SLocOffset); |
| 1055 | } |
| 1056 | |
| 1057 | |
| 1058 | StringRef getFilename(SourceLocation SpellingLoc) const { |
| 1059 | if (const FileEntry *F = getFileEntryForID(getFileID(SpellingLoc))) |
| 1060 | return F->getName(); |
| 1061 | return StringRef(); |
| 1062 | } |
| 1063 | |
| 1064 | |
| 1065 | |
| 1066 | SourceLocation getLocForStartOfFile(FileID FID) const { |
| 1067 | bool Invalid = false; |
| 1068 | const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); |
| 1069 | if (Invalid || !Entry.isFile()) |
| 1070 | return SourceLocation(); |
| 1071 | |
| 1072 | unsigned FileOffset = Entry.getOffset(); |
| 1073 | return SourceLocation::getFileLoc(FileOffset); |
| 1074 | } |
| 1075 | |
| 1076 | |
| 1077 | |
| 1078 | SourceLocation getLocForEndOfFile(FileID FID) const { |
| 1079 | bool Invalid = false; |
| 1080 | const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); |
| 1081 | if (Invalid || !Entry.isFile()) |
| 1082 | return SourceLocation(); |
| 1083 | |
| 1084 | unsigned FileOffset = Entry.getOffset(); |
| 1085 | return SourceLocation::getFileLoc(FileOffset + getFileIDSize(FID)); |
| 1086 | } |
| 1087 | |
| 1088 | |
| 1089 | |
| 1090 | SourceLocation getIncludeLoc(FileID FID) const { |
| 1091 | bool Invalid = false; |
| 1092 | const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); |
| 1093 | if (Invalid || !Entry.isFile()) |
| 1094 | return SourceLocation(); |
| 1095 | |
| 1096 | return Entry.getFile().getIncludeLoc(); |
| 1097 | } |
| 1098 | |
| 1099 | |
| 1100 | |
| 1101 | |
| 1102 | std::pair<SourceLocation, StringRef> |
| 1103 | getModuleImportLoc(SourceLocation Loc) const { |
| 1104 | FileID FID = getFileID(Loc); |
| 1105 | |
| 1106 | |
| 1107 | |
| 1108 | if (FID.ID >= -1) |
| 1109 | return std::make_pair(SourceLocation(), ""); |
| 1110 | |
| 1111 | return ExternalSLocEntries->getModuleImportLoc(FID.ID); |
| 1112 | } |
| 1113 | |
| 1114 | |
| 1115 | |
| 1116 | SourceLocation getExpansionLoc(SourceLocation Loc) const { |
| 1117 | |
| 1118 | |
| 1119 | if (Loc.isFileID()) return Loc; |
| 1120 | return getExpansionLocSlowCase(Loc); |
| 1121 | } |
| 1122 | |
| 1123 | |
| 1124 | |
| 1125 | |
| 1126 | SourceLocation getFileLoc(SourceLocation Loc) const { |
| 1127 | if (Loc.isFileID()) return Loc; |
| 1128 | return getFileLocSlowCase(Loc); |
| 1129 | } |
| 1130 | |
| 1131 | |
| 1132 | |
| 1133 | |
| 1134 | |
| 1135 | CharSourceRange getImmediateExpansionRange(SourceLocation Loc) const; |
| 1136 | |
| 1137 | |
| 1138 | |
| 1139 | CharSourceRange getExpansionRange(SourceLocation Loc) const; |
| 1140 | |
| 1141 | |
| 1142 | |
| 1143 | CharSourceRange getExpansionRange(SourceRange Range) const { |
| 1144 | SourceLocation Begin = getExpansionRange(Range.getBegin()).getBegin(); |
| 1145 | CharSourceRange End = getExpansionRange(Range.getEnd()); |
| 1146 | return CharSourceRange(SourceRange(Begin, End.getEnd()), |
| 1147 | End.isTokenRange()); |
| 1148 | } |
| 1149 | |
| 1150 | |
| 1151 | |
| 1152 | CharSourceRange getExpansionRange(CharSourceRange Range) const { |
| 1153 | CharSourceRange Expansion = getExpansionRange(Range.getAsRange()); |
| 1154 | if (Expansion.getEnd() == Range.getEnd()) |
| 1155 | Expansion.setTokenRange(Range.isTokenRange()); |
| 1156 | return Expansion; |
| 1157 | } |
| 1158 | |
| 1159 | |
| 1160 | |
| 1161 | |
| 1162 | |
| 1163 | |
| 1164 | SourceLocation getSpellingLoc(SourceLocation Loc) const { |
| 1165 | |
| 1166 | |
| 1167 | if (Loc.isFileID()) return Loc; |
| 1168 | return getSpellingLocSlowCase(Loc); |
| 1169 | } |
| 1170 | |
| 1171 | |
| 1172 | |
| 1173 | |
| 1174 | |
| 1175 | |
| 1176 | |
| 1177 | SourceLocation getImmediateSpellingLoc(SourceLocation Loc) const; |
| 1178 | |
| 1179 | |
| 1180 | SourceLocation getComposedLoc(FileID FID, unsigned Offset) const { |
| 1181 | bool Invalid = false; |
| 1182 | const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); |
| 1183 | if (Invalid) |
| 1184 | return SourceLocation(); |
| 1185 | |
| 1186 | unsigned GlobalOffset = Entry.getOffset() + Offset; |
| 1187 | return Entry.isFile() ? SourceLocation::getFileLoc(GlobalOffset) |
| 1188 | : SourceLocation::getMacroLoc(GlobalOffset); |
| 1189 | } |
| 1190 | |
| 1191 | |
| 1192 | |
| 1193 | |
| 1194 | |
| 1195 | std::pair<FileID, unsigned> getDecomposedLoc(SourceLocation Loc) const { |
| 1196 | FileID FID = getFileID(Loc); |
| 1197 | bool Invalid = false; |
| 1198 | const SrcMgr::SLocEntry &E = getSLocEntry(FID, &Invalid); |
| 1199 | if (Invalid) |
| 1200 | return std::make_pair(FileID(), 0); |
| 1201 | return std::make_pair(FID, Loc.getOffset()-E.getOffset()); |
| 1202 | } |
| 1203 | |
| 1204 | |
| 1205 | |
| 1206 | |
| 1207 | |
| 1208 | std::pair<FileID, unsigned> |
| 1209 | getDecomposedExpansionLoc(SourceLocation Loc) const { |
| 1210 | FileID FID = getFileID(Loc); |
| 1211 | bool Invalid = false; |
| 1212 | const SrcMgr::SLocEntry *E = &getSLocEntry(FID, &Invalid); |
| 1213 | if (Invalid) |
| 1214 | return std::make_pair(FileID(), 0); |
| 1215 | |
| 1216 | unsigned Offset = Loc.getOffset()-E->getOffset(); |
| 1217 | if (Loc.isFileID()) |
| 1218 | return std::make_pair(FID, Offset); |
| 1219 | |
| 1220 | return getDecomposedExpansionLocSlowCase(E); |
| 1221 | } |
| 1222 | |
| 1223 | |
| 1224 | |
| 1225 | |
| 1226 | |
| 1227 | std::pair<FileID, unsigned> |
| 1228 | getDecomposedSpellingLoc(SourceLocation Loc) const { |
| 1229 | FileID FID = getFileID(Loc); |
| 1230 | bool Invalid = false; |
| 1231 | const SrcMgr::SLocEntry *E = &getSLocEntry(FID, &Invalid); |
| 1232 | if (Invalid) |
| 1233 | return std::make_pair(FileID(), 0); |
| 1234 | |
| 1235 | unsigned Offset = Loc.getOffset()-E->getOffset(); |
| 1236 | if (Loc.isFileID()) |
| 1237 | return std::make_pair(FID, Offset); |
| 1238 | return getDecomposedSpellingLocSlowCase(E, Offset); |
| 1239 | } |
| 1240 | |
| 1241 | |
| 1242 | |
| 1243 | std::pair<FileID, unsigned> getDecomposedIncludedLoc(FileID FID) const; |
| 1244 | |
| 1245 | |
| 1246 | |
| 1247 | |
| 1248 | |
| 1249 | unsigned getFileOffset(SourceLocation SpellingLoc) const { |
| 1250 | return getDecomposedLoc(SpellingLoc).second; |
| 1251 | } |
| 1252 | |
| 1253 | |
| 1254 | |
| 1255 | |
| 1256 | |
| 1257 | |
| 1258 | |
| 1259 | |
| 1260 | |
| 1261 | |
| 1262 | bool isMacroArgExpansion(SourceLocation Loc, |
| 1263 | SourceLocation *StartLoc = nullptr) const; |
| 1264 | |
| 1265 | |
| 1266 | |
| 1267 | |
| 1268 | |
| 1269 | |
| 1270 | bool isMacroBodyExpansion(SourceLocation Loc) const; |
| 1271 | |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | |
| 1276 | |
| 1277 | bool isAtStartOfImmediateMacroExpansion(SourceLocation Loc, |
| 1278 | SourceLocation *MacroBegin = nullptr) const; |
| 1279 | |
| 1280 | |
| 1281 | |
| 1282 | |
| 1283 | |
| 1284 | |
| 1285 | bool |
| 1286 | isAtEndOfImmediateMacroExpansion(SourceLocation Loc, |
| 1287 | SourceLocation *MacroEnd = nullptr) const; |
| 1288 | |
| 1289 | |
| 1290 | |
| 1291 | |
| 1292 | |
| 1293 | |
| 1294 | bool isInSLocAddrSpace(SourceLocation Loc, |
| 1295 | SourceLocation Start, unsigned Length, |
| 1296 | unsigned *RelativeOffset = nullptr) const { |
| 1297 | (0) . __assert_fail ("((Start.getOffset() < NextLocalOffset && Start.getOffset()+Length <= NextLocalOffset) || (Start.getOffset() >= CurrentLoadedOffset && Start.getOffset()+Length < MaxLoadedOffset)) && \"Chunk is not valid SLoc address space\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 1301, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(((Start.getOffset() < NextLocalOffset && |
| 1298 | (0) . __assert_fail ("((Start.getOffset() < NextLocalOffset && Start.getOffset()+Length <= NextLocalOffset) || (Start.getOffset() >= CurrentLoadedOffset && Start.getOffset()+Length < MaxLoadedOffset)) && \"Chunk is not valid SLoc address space\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 1301, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> Start.getOffset()+Length <= NextLocalOffset) || |
| 1299 | (0) . __assert_fail ("((Start.getOffset() < NextLocalOffset && Start.getOffset()+Length <= NextLocalOffset) || (Start.getOffset() >= CurrentLoadedOffset && Start.getOffset()+Length < MaxLoadedOffset)) && \"Chunk is not valid SLoc address space\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 1301, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> (Start.getOffset() >= CurrentLoadedOffset && |
| 1300 | (0) . __assert_fail ("((Start.getOffset() < NextLocalOffset && Start.getOffset()+Length <= NextLocalOffset) || (Start.getOffset() >= CurrentLoadedOffset && Start.getOffset()+Length < MaxLoadedOffset)) && \"Chunk is not valid SLoc address space\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 1301, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> Start.getOffset()+Length < MaxLoadedOffset)) && |
| 1301 | (0) . __assert_fail ("((Start.getOffset() < NextLocalOffset && Start.getOffset()+Length <= NextLocalOffset) || (Start.getOffset() >= CurrentLoadedOffset && Start.getOffset()+Length < MaxLoadedOffset)) && \"Chunk is not valid SLoc address space\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 1301, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Chunk is not valid SLoc address space"); |
| 1302 | unsigned LocOffs = Loc.getOffset(); |
| 1303 | unsigned BeginOffs = Start.getOffset(); |
| 1304 | unsigned EndOffs = BeginOffs + Length; |
| 1305 | if (LocOffs >= BeginOffs && LocOffs < EndOffs) { |
| 1306 | if (RelativeOffset) |
| 1307 | *RelativeOffset = LocOffs - BeginOffs; |
| 1308 | return true; |
| 1309 | } |
| 1310 | |
| 1311 | return false; |
| 1312 | } |
| 1313 | |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | |
| 1318 | |
| 1319 | bool isInSameSLocAddrSpace(SourceLocation LHS, SourceLocation RHS, |
| 1320 | int *RelativeOffset) const { |
| 1321 | unsigned LHSOffs = LHS.getOffset(), RHSOffs = RHS.getOffset(); |
| 1322 | bool LHSLoaded = LHSOffs >= CurrentLoadedOffset; |
| 1323 | bool RHSLoaded = RHSOffs >= CurrentLoadedOffset; |
| 1324 | |
| 1325 | if (LHSLoaded == RHSLoaded) { |
| 1326 | if (RelativeOffset) |
| 1327 | *RelativeOffset = RHSOffs - LHSOffs; |
| 1328 | return true; |
| 1329 | } |
| 1330 | |
| 1331 | return false; |
| 1332 | } |
| 1333 | |
| 1334 | |
| 1335 | |
| 1336 | |
| 1337 | |
| 1338 | |
| 1339 | |
| 1340 | |
| 1341 | |
| 1342 | const char *getCharacterData(SourceLocation SL, |
| 1343 | bool *Invalid = nullptr) const; |
| 1344 | |
| 1345 | |
| 1346 | |
| 1347 | |
| 1348 | |
| 1349 | |
| 1350 | |
| 1351 | unsigned getColumnNumber(FileID FID, unsigned FilePos, |
| 1352 | bool *Invalid = nullptr) const; |
| 1353 | unsigned getSpellingColumnNumber(SourceLocation Loc, |
| 1354 | bool *Invalid = nullptr) const; |
| 1355 | unsigned getExpansionColumnNumber(SourceLocation Loc, |
| 1356 | bool *Invalid = nullptr) const; |
| 1357 | unsigned getPresumedColumnNumber(SourceLocation Loc, |
| 1358 | bool *Invalid = nullptr) const; |
| 1359 | |
| 1360 | |
| 1361 | |
| 1362 | |
| 1363 | |
| 1364 | |
| 1365 | |
| 1366 | unsigned getLineNumber(FileID FID, unsigned FilePos, bool *Invalid = nullptr) const; |
| 1367 | unsigned getSpellingLineNumber(SourceLocation Loc, bool *Invalid = nullptr) const; |
| 1368 | unsigned getExpansionLineNumber(SourceLocation Loc, bool *Invalid = nullptr) const; |
| 1369 | unsigned getPresumedLineNumber(SourceLocation Loc, bool *Invalid = nullptr) const; |
| 1370 | |
| 1371 | |
| 1372 | |
| 1373 | |
| 1374 | |
| 1375 | |
| 1376 | StringRef getBufferName(SourceLocation Loc, bool *Invalid = nullptr) const; |
| 1377 | |
| 1378 | |
| 1379 | |
| 1380 | |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | |
| 1385 | |
| 1386 | |
| 1387 | |
| 1388 | SrcMgr::CharacteristicKind getFileCharacteristic(SourceLocation Loc) const; |
| 1389 | |
| 1390 | |
| 1391 | |
| 1392 | |
| 1393 | |
| 1394 | |
| 1395 | |
| 1396 | |
| 1397 | |
| 1398 | |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | |
| 1403 | PresumedLoc getPresumedLoc(SourceLocation Loc, |
| 1404 | bool UseLineDirectives = true) const; |
| 1405 | |
| 1406 | |
| 1407 | |
| 1408 | |
| 1409 | |
| 1410 | |
| 1411 | |
| 1412 | |
| 1413 | bool isInMainFile(SourceLocation Loc) const; |
| 1414 | |
| 1415 | |
| 1416 | |
| 1417 | |
| 1418 | |
| 1419 | bool isWrittenInSameFile(SourceLocation Loc1, SourceLocation Loc2) const { |
| 1420 | return getFileID(Loc1) == getFileID(Loc2); |
| 1421 | } |
| 1422 | |
| 1423 | |
| 1424 | |
| 1425 | |
| 1426 | |
| 1427 | bool isWrittenInMainFile(SourceLocation Loc) const { |
| 1428 | return getFileID(Loc) == getMainFileID(); |
| 1429 | } |
| 1430 | |
| 1431 | |
| 1432 | bool isWrittenInBuiltinFile(SourceLocation Loc) const { |
| 1433 | StringRef Filename(getPresumedLoc(Loc).getFilename()); |
| 1434 | return Filename.equals("<built-in>"); |
| 1435 | } |
| 1436 | |
| 1437 | |
| 1438 | bool isWrittenInCommandLineFile(SourceLocation Loc) const { |
| 1439 | StringRef Filename(getPresumedLoc(Loc).getFilename()); |
| 1440 | return Filename.equals("<command line>"); |
| 1441 | } |
| 1442 | |
| 1443 | |
| 1444 | bool isWrittenInScratchSpace(SourceLocation Loc) const { |
| 1445 | StringRef Filename(getPresumedLoc(Loc).getFilename()); |
| 1446 | return Filename.equals("<scratch space>"); |
| 1447 | } |
| 1448 | |
| 1449 | |
| 1450 | bool (SourceLocation Loc) const { |
| 1451 | return isSystem(getFileCharacteristic(Loc)); |
| 1452 | } |
| 1453 | |
| 1454 | |
| 1455 | bool (SourceLocation Loc) const { |
| 1456 | return getFileCharacteristic(Loc) == SrcMgr::C_ExternCSystem; |
| 1457 | } |
| 1458 | |
| 1459 | |
| 1460 | bool isInSystemMacro(SourceLocation loc) const { |
| 1461 | if (!loc.isMacroID()) |
| 1462 | return false; |
| 1463 | |
| 1464 | |
| 1465 | |
| 1466 | if (isWrittenInScratchSpace(getSpellingLoc(loc))) |
| 1467 | return isInSystemHeader(getSpellingLoc(getImmediateMacroCallerLoc(loc))); |
| 1468 | |
| 1469 | return isInSystemHeader(getSpellingLoc(loc)); |
| 1470 | } |
| 1471 | |
| 1472 | |
| 1473 | unsigned getFileIDSize(FileID FID) const; |
| 1474 | |
| 1475 | |
| 1476 | |
| 1477 | |
| 1478 | bool isInFileID(SourceLocation Loc, FileID FID, |
| 1479 | unsigned *RelativeOffset = nullptr) const { |
| 1480 | unsigned Offs = Loc.getOffset(); |
| 1481 | if (isOffsetInFileID(FID, Offs)) { |
| 1482 | if (RelativeOffset) |
| 1483 | *RelativeOffset = Offs - getSLocEntry(FID).getOffset(); |
| 1484 | return true; |
| 1485 | } |
| 1486 | |
| 1487 | return false; |
| 1488 | } |
| 1489 | |
| 1490 | |
| 1491 | |
| 1492 | |
| 1493 | |
| 1494 | |
| 1495 | unsigned getLineTableFilenameID(StringRef Str); |
| 1496 | |
| 1497 | |
| 1498 | |
| 1499 | |
| 1500 | |
| 1501 | void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID, |
| 1502 | bool IsFileEntry, bool IsFileExit, |
| 1503 | SrcMgr::CharacteristicKind FileKind); |
| 1504 | |
| 1505 | |
| 1506 | bool hasLineTable() const { return LineTable != nullptr; } |
| 1507 | |
| 1508 | |
| 1509 | LineTableInfo &getLineTable(); |
| 1510 | |
| 1511 | |
| 1512 | |
| 1513 | |
| 1514 | |
| 1515 | |
| 1516 | |
| 1517 | size_t getContentCacheSize() const { |
| 1518 | return ContentCacheAlloc.getTotalMemory(); |
| 1519 | } |
| 1520 | |
| 1521 | struct MemoryBufferSizes { |
| 1522 | const size_t malloc_bytes; |
| 1523 | const size_t mmap_bytes; |
| 1524 | |
| 1525 | MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes) |
| 1526 | : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {} |
| 1527 | }; |
| 1528 | |
| 1529 | |
| 1530 | |
| 1531 | MemoryBufferSizes getMemoryBufferSizes() const; |
| 1532 | |
| 1533 | |
| 1534 | |
| 1535 | size_t getDataStructureSizes() const; |
| 1536 | |
| 1537 | |
| 1538 | |
| 1539 | |
| 1540 | |
| 1541 | |
| 1542 | |
| 1543 | |
| 1544 | |
| 1545 | SourceLocation translateFileLineCol(const FileEntry *SourceFile, |
| 1546 | unsigned Line, unsigned Col) const; |
| 1547 | |
| 1548 | |
| 1549 | |
| 1550 | |
| 1551 | |
| 1552 | FileID translateFile(const FileEntry *SourceFile) const; |
| 1553 | |
| 1554 | |
| 1555 | |
| 1556 | SourceLocation translateLineCol(FileID FID, |
| 1557 | unsigned Line, unsigned Col) const; |
| 1558 | |
| 1559 | |
| 1560 | |
| 1561 | |
| 1562 | |
| 1563 | |
| 1564 | |
| 1565 | |
| 1566 | |
| 1567 | |
| 1568 | SourceLocation getMacroArgExpandedLocation(SourceLocation Loc) const; |
| 1569 | |
| 1570 | |
| 1571 | |
| 1572 | |
| 1573 | bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const; |
| 1574 | |
| 1575 | |
| 1576 | |
| 1577 | |
| 1578 | |
| 1579 | |
| 1580 | |
| 1581 | |
| 1582 | std::pair<bool, bool> |
| 1583 | isInTheSameTranslationUnit(std::pair<FileID, unsigned> &LOffs, |
| 1584 | std::pair<FileID, unsigned> &ROffs) const; |
| 1585 | |
| 1586 | |
| 1587 | |
| 1588 | bool isBeforeInSLocAddrSpace(SourceLocation LHS, SourceLocation RHS) const { |
| 1589 | return isBeforeInSLocAddrSpace(LHS, RHS.getOffset()); |
| 1590 | } |
| 1591 | |
| 1592 | |
| 1593 | |
| 1594 | |
| 1595 | |
| 1596 | bool isBeforeInSLocAddrSpace(SourceLocation LHS, unsigned RHS) const { |
| 1597 | unsigned LHSOffset = LHS.getOffset(); |
| 1598 | bool LHSLoaded = LHSOffset >= CurrentLoadedOffset; |
| 1599 | bool RHSLoaded = RHS >= CurrentLoadedOffset; |
| 1600 | if (LHSLoaded == RHSLoaded) |
| 1601 | return LHSOffset < RHS; |
| 1602 | |
| 1603 | return LHSLoaded; |
| 1604 | } |
| 1605 | |
| 1606 | |
| 1607 | bool isPointWithin(SourceLocation Location, SourceLocation Start, |
| 1608 | SourceLocation End) const { |
| 1609 | return Location == Start || Location == End || |
| 1610 | (isBeforeInTranslationUnit(Start, Location) && |
| 1611 | isBeforeInTranslationUnit(Location, End)); |
| 1612 | } |
| 1613 | |
| 1614 | |
| 1615 | using fileinfo_iterator = |
| 1616 | llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*>::const_iterator; |
| 1617 | |
| 1618 | fileinfo_iterator fileinfo_begin() const { return FileInfos.begin(); } |
| 1619 | fileinfo_iterator fileinfo_end() const { return FileInfos.end(); } |
| 1620 | bool hasFileInfo(const FileEntry *File) const { |
| 1621 | return FileInfos.find(File) != FileInfos.end(); |
| 1622 | } |
| 1623 | |
| 1624 | |
| 1625 | void PrintStats() const; |
| 1626 | |
| 1627 | void dump() const; |
| 1628 | |
| 1629 | |
| 1630 | unsigned local_sloc_entry_size() const { return LocalSLocEntryTable.size(); } |
| 1631 | |
| 1632 | |
| 1633 | const SrcMgr::SLocEntry &getLocalSLocEntry(unsigned Index, |
| 1634 | bool *Invalid = nullptr) const { |
| 1635 | (0) . __assert_fail ("Index < LocalSLocEntryTable.size() && \"Invalid index\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 1635, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Index < LocalSLocEntryTable.size() && "Invalid index"); |
| 1636 | return LocalSLocEntryTable[Index]; |
| 1637 | } |
| 1638 | |
| 1639 | |
| 1640 | unsigned loaded_sloc_entry_size() const { return LoadedSLocEntryTable.size();} |
| 1641 | |
| 1642 | |
| 1643 | const SrcMgr::SLocEntry &getLoadedSLocEntry(unsigned Index, |
| 1644 | bool *Invalid = nullptr) const { |
| 1645 | (0) . __assert_fail ("Index < LoadedSLocEntryTable.size() && \"Invalid index\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 1645, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Index < LoadedSLocEntryTable.size() && "Invalid index"); |
| 1646 | if (SLocEntryLoaded[Index]) |
| 1647 | return LoadedSLocEntryTable[Index]; |
| 1648 | return loadSLocEntry(Index, Invalid); |
| 1649 | } |
| 1650 | |
| 1651 | const SrcMgr::SLocEntry &getSLocEntry(FileID FID, |
| 1652 | bool *Invalid = nullptr) const { |
| 1653 | if (FID.ID == 0 || FID.ID == -1) { |
| 1654 | if (Invalid) *Invalid = true; |
| 1655 | return LocalSLocEntryTable[0]; |
| 1656 | } |
| 1657 | return getSLocEntryByID(FID.ID, Invalid); |
| 1658 | } |
| 1659 | |
| 1660 | unsigned getNextLocalOffset() const { return NextLocalOffset; } |
| 1661 | |
| 1662 | void setExternalSLocEntrySource(ExternalSLocEntrySource *Source) { |
| 1663 | (0) . __assert_fail ("LoadedSLocEntryTable.empty() && \"Invalidating existing loaded entries\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 1664, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(LoadedSLocEntryTable.empty() && |
| 1664 | (0) . __assert_fail ("LoadedSLocEntryTable.empty() && \"Invalidating existing loaded entries\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 1664, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Invalidating existing loaded entries"); |
| 1665 | ExternalSLocEntries = Source; |
| 1666 | } |
| 1667 | |
| 1668 | |
| 1669 | |
| 1670 | |
| 1671 | |
| 1672 | |
| 1673 | |
| 1674 | std::pair<int, unsigned> |
| 1675 | AllocateLoadedSLocEntries(unsigned NumSLocEntries, unsigned TotalSize); |
| 1676 | |
| 1677 | |
| 1678 | bool isLoadedSourceLocation(SourceLocation Loc) const { |
| 1679 | return Loc.getOffset() >= CurrentLoadedOffset; |
| 1680 | } |
| 1681 | |
| 1682 | |
| 1683 | bool isLocalSourceLocation(SourceLocation Loc) const { |
| 1684 | return Loc.getOffset() < NextLocalOffset; |
| 1685 | } |
| 1686 | |
| 1687 | |
| 1688 | bool isLoadedFileID(FileID FID) const { |
| 1689 | (0) . __assert_fail ("FID.ID != -1 && \"Using FileID sentinel value\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 1689, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(FID.ID != -1 && "Using FileID sentinel value"); |
| 1690 | return FID.ID < 0; |
| 1691 | } |
| 1692 | |
| 1693 | |
| 1694 | bool isLocalFileID(FileID FID) const { |
| 1695 | return !isLoadedFileID(FID); |
| 1696 | } |
| 1697 | |
| 1698 | |
| 1699 | |
| 1700 | SourceLocation getImmediateMacroCallerLoc(SourceLocation Loc) const { |
| 1701 | if (!Loc.isMacroID()) return Loc; |
| 1702 | |
| 1703 | |
| 1704 | |
| 1705 | |
| 1706 | if (isMacroArgExpansion(Loc)) |
| 1707 | return getImmediateSpellingLoc(Loc); |
| 1708 | |
| 1709 | |
| 1710 | |
| 1711 | return getImmediateExpansionRange(Loc).getBegin(); |
| 1712 | } |
| 1713 | |
| 1714 | |
| 1715 | SourceLocation getTopMacroCallerLoc(SourceLocation Loc) const; |
| 1716 | |
| 1717 | private: |
| 1718 | friend class ASTReader; |
| 1719 | friend class ASTWriter; |
| 1720 | |
| 1721 | llvm::MemoryBuffer *getFakeBufferForRecovery() const; |
| 1722 | const SrcMgr::ContentCache *getFakeContentCacheForRecovery() const; |
| 1723 | |
| 1724 | const SrcMgr::SLocEntry &loadSLocEntry(unsigned Index, bool *Invalid) const; |
| 1725 | |
| 1726 | |
| 1727 | const SrcMgr::SLocEntry &getSLocEntryByID(int ID, |
| 1728 | bool *Invalid = nullptr) const { |
| 1729 | (0) . __assert_fail ("ID != -1 && \"Using FileID sentinel value\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManager.h", 1729, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(ID != -1 && "Using FileID sentinel value"); |
| 1730 | if (ID < 0) |
| 1731 | return getLoadedSLocEntryByID(ID, Invalid); |
| 1732 | return getLocalSLocEntry(static_cast<unsigned>(ID), Invalid); |
| 1733 | } |
| 1734 | |
| 1735 | const SrcMgr::SLocEntry & |
| 1736 | getLoadedSLocEntryByID(int ID, bool *Invalid = nullptr) const { |
| 1737 | return getLoadedSLocEntry(static_cast<unsigned>(-ID - 2), Invalid); |
| 1738 | } |
| 1739 | |
| 1740 | |
| 1741 | |
| 1742 | SourceLocation createExpansionLocImpl(const SrcMgr::ExpansionInfo &Expansion, |
| 1743 | unsigned TokLength, |
| 1744 | int LoadedID = 0, |
| 1745 | unsigned LoadedOffset = 0); |
| 1746 | |
| 1747 | |
| 1748 | |
| 1749 | inline bool isOffsetInFileID(FileID FID, unsigned SLocOffset) const { |
| 1750 | const SrcMgr::SLocEntry &Entry = getSLocEntry(FID); |
| 1751 | |
| 1752 | if (SLocOffset < Entry.getOffset()) return false; |
| 1753 | |
| 1754 | |
| 1755 | if (FID.ID == -2) |
| 1756 | return true; |
| 1757 | |
| 1758 | |
| 1759 | if (FID.ID+1 == static_cast<int>(LocalSLocEntryTable.size())) |
| 1760 | return SLocOffset < NextLocalOffset; |
| 1761 | |
| 1762 | |
| 1763 | |
| 1764 | return SLocOffset < getSLocEntryByID(FID.ID+1).getOffset(); |
| 1765 | } |
| 1766 | |
| 1767 | |
| 1768 | |
| 1769 | FileID getPreviousFileID(FileID FID) const; |
| 1770 | |
| 1771 | |
| 1772 | |
| 1773 | FileID getNextFileID(FileID FID) const; |
| 1774 | |
| 1775 | |
| 1776 | |
| 1777 | |
| 1778 | |
| 1779 | |
| 1780 | FileID createFileID(const SrcMgr::ContentCache* File, |
| 1781 | SourceLocation IncludePos, |
| 1782 | SrcMgr::CharacteristicKind DirCharacter, |
| 1783 | int LoadedID, unsigned LoadedOffset); |
| 1784 | |
| 1785 | const SrcMgr::ContentCache * |
| 1786 | getOrCreateContentCache(const FileEntry *SourceFile, |
| 1787 | bool isSystemFile = false); |
| 1788 | |
| 1789 | |
| 1790 | const SrcMgr::ContentCache * |
| 1791 | createMemBufferContentCache(llvm::MemoryBuffer *Buf, bool DoNotFree); |
| 1792 | |
| 1793 | FileID getFileIDSlow(unsigned SLocOffset) const; |
| 1794 | FileID getFileIDLocal(unsigned SLocOffset) const; |
| 1795 | FileID getFileIDLoaded(unsigned SLocOffset) const; |
| 1796 | |
| 1797 | SourceLocation getExpansionLocSlowCase(SourceLocation Loc) const; |
| 1798 | SourceLocation getSpellingLocSlowCase(SourceLocation Loc) const; |
| 1799 | SourceLocation getFileLocSlowCase(SourceLocation Loc) const; |
| 1800 | |
| 1801 | std::pair<FileID, unsigned> |
| 1802 | getDecomposedExpansionLocSlowCase(const SrcMgr::SLocEntry *E) const; |
| 1803 | std::pair<FileID, unsigned> |
| 1804 | getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E, |
| 1805 | unsigned Offset) const; |
| 1806 | void computeMacroArgsCache(MacroArgsMap &MacroArgsCache, FileID FID) const; |
| 1807 | void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache, |
| 1808 | FileID FID, |
| 1809 | SourceLocation SpellLoc, |
| 1810 | SourceLocation ExpansionLoc, |
| 1811 | unsigned ExpansionLength) const; |
| 1812 | }; |
| 1813 | |
| 1814 | |
| 1815 | template<typename T> |
| 1816 | class BeforeThanCompare; |
| 1817 | |
| 1818 | |
| 1819 | template<> |
| 1820 | class BeforeThanCompare<SourceLocation> { |
| 1821 | SourceManager &SM; |
| 1822 | |
| 1823 | public: |
| 1824 | explicit BeforeThanCompare(SourceManager &SM) : SM(SM) {} |
| 1825 | |
| 1826 | bool operator()(SourceLocation LHS, SourceLocation RHS) const { |
| 1827 | return SM.isBeforeInTranslationUnit(LHS, RHS); |
| 1828 | } |
| 1829 | }; |
| 1830 | |
| 1831 | |
| 1832 | template<> |
| 1833 | class BeforeThanCompare<SourceRange> { |
| 1834 | SourceManager &SM; |
| 1835 | |
| 1836 | public: |
| 1837 | explicit BeforeThanCompare(SourceManager &SM) : SM(SM) {} |
| 1838 | |
| 1839 | bool operator()(SourceRange LHS, SourceRange RHS) const { |
| 1840 | return SM.isBeforeInTranslationUnit(LHS.getBegin(), RHS.getBegin()); |
| 1841 | } |
| 1842 | }; |
| 1843 | |
| 1844 | |
| 1845 | |
| 1846 | class SourceManagerForFile { |
| 1847 | public: |
| 1848 | |
| 1849 | |
| 1850 | SourceManagerForFile(StringRef FileName, StringRef Content); |
| 1851 | |
| 1852 | SourceManager &get() { |
| 1853 | assert(SourceMgr); |
| 1854 | return *SourceMgr; |
| 1855 | } |
| 1856 | |
| 1857 | private: |
| 1858 | |
| 1859 | |
| 1860 | |
| 1861 | std::unique_ptr<FileManager> FileMgr; |
| 1862 | std::unique_ptr<DiagnosticsEngine> Diagnostics; |
| 1863 | std::unique_ptr<SourceManager> SourceMgr; |
| 1864 | }; |
| 1865 | |
| 1866 | } |
| 1867 | |
| 1868 | #endif |
| 1869 | |