|
| 1 | +//===--- BasicSourceInfo.h - Simple source information ----------*- C++ -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef SWIFT_BASIC_BASIC_SOURCE_INFO_H |
| 14 | +#define SWIFT_BASIC_BASIC_SOURCE_INFO_H |
| 15 | + |
| 16 | +#include "swift/Basic/Fingerprint.h" |
| 17 | +#include "swift/Basic/LLVM.h" |
| 18 | +#include "llvm/ADT/PointerIntPair.h" |
| 19 | +#include "llvm/Support/Chrono.h" |
| 20 | + |
| 21 | +namespace swift { |
| 22 | + |
| 23 | +class SourceFile; |
| 24 | + |
| 25 | +struct SourcePosition { |
| 26 | + uint32_t Line = 0; |
| 27 | + uint32_t Column = 0; |
| 28 | + bool isValid() const { return Line && Column; } |
| 29 | +}; |
| 30 | + |
| 31 | +struct BasicDeclLocs { |
| 32 | + StringRef SourceFilePath; |
| 33 | + SmallVector<std::pair<SourcePosition, uint32_t>, 4> DocRanges; |
| 34 | + SourcePosition Loc; |
| 35 | + SourcePosition StartLoc; |
| 36 | + SourcePosition EndLoc; |
| 37 | +}; |
| 38 | + |
| 39 | +class BasicSourceFileInfo { |
| 40 | + /// If this is non-null, fields other than 'FilePath' hasn't been populated. |
| 41 | + /// The 'getInt()' part indicates this instance is constructed with a |
| 42 | + /// SourceFile. |
| 43 | + llvm::PointerIntPair<const SourceFile *, 1, bool> SFAndIsFromSF; |
| 44 | + |
| 45 | + StringRef FilePath; |
| 46 | + Fingerprint InterfaceHashIncludingTypeMembers = Fingerprint::ZERO(); |
| 47 | + /// Does *not* include the type-body hashes of the top level types. |
| 48 | + /// Just the `SourceFile` hashes. |
| 49 | + /// Used for incremental imports. |
| 50 | + Fingerprint InterfaceHashExcludingTypeMembers = Fingerprint::ZERO(); |
| 51 | + llvm::sys::TimePoint<> LastModified = {}; |
| 52 | + uint64_t FileSize = 0; |
| 53 | + |
| 54 | + // Populate the from 'SF' member if exist. 'SF' will be cleared. |
| 55 | + void populateWithSourceFileIfNeeded(); |
| 56 | + |
| 57 | +public: |
| 58 | + BasicSourceFileInfo(StringRef FilePath, |
| 59 | + Fingerprint InterfaceHashIncludingTypeMembers, |
| 60 | + Fingerprint InterfaceHashExcludingTypeMembers, |
| 61 | + llvm::sys::TimePoint<> LastModified, uint64_t FileSize) |
| 62 | + : FilePath(FilePath), |
| 63 | + InterfaceHashIncludingTypeMembers(InterfaceHashIncludingTypeMembers), |
| 64 | + InterfaceHashExcludingTypeMembers(InterfaceHashExcludingTypeMembers), |
| 65 | + LastModified(LastModified), FileSize(FileSize) {} |
| 66 | + |
| 67 | + /// Construct with a `SourceFile`. `getInterfaceHashIncludingTypeMembers()`, |
| 68 | + /// `getInterfaceHashExcludingTypeMembers()`, `getLastModified()` and |
| 69 | + /// `getFileSize()` are laizily populated when accessed. |
| 70 | + BasicSourceFileInfo(const SourceFile *SF); |
| 71 | + |
| 72 | + bool isFromSourceFile() const; |
| 73 | + |
| 74 | + StringRef getFilePath() const { return FilePath; } |
| 75 | + |
| 76 | + Fingerprint getInterfaceHashIncludingTypeMembers() const { |
| 77 | + const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded(); |
| 78 | + return InterfaceHashIncludingTypeMembers; |
| 79 | + } |
| 80 | + |
| 81 | + Fingerprint getInterfaceHashExcludingTypeMembers() const { |
| 82 | + const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded(); |
| 83 | + return InterfaceHashExcludingTypeMembers; |
| 84 | + } |
| 85 | + |
| 86 | + llvm::sys::TimePoint<> getLastModified() const { |
| 87 | + const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded(); |
| 88 | + return LastModified; |
| 89 | + } |
| 90 | + |
| 91 | + uint64_t getFileSize() const { |
| 92 | + const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded(); |
| 93 | + return FileSize; |
| 94 | + } |
| 95 | +}; |
| 96 | + |
| 97 | +} // namespace swift |
| 98 | + |
| 99 | +#endif // SWIFT_BASIC_BASIC_SOURCE_INFO_H |
| 100 | + |
0 commit comments