mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The locations stored in .swiftsourceinfo included the presumed file, line, and column. When a location is requested it would read these, open the external file, create a line map, and find the offset corresponding to that line/column. The offset is known during serialization though, so output it as well to avoid having to read the file and generate the line map. Since the serialized location is returned from `Decl::getLoc()`, it should not be the presumed location. Instead, also output the line directives so that the presumed location can be built as per normal locations. Finally, move the cache out of `Decl` and into `ASTContext`, since very few declarations will actually have their locations deserialized. Make sure to actually write to that cache so it's used - the old cache was never written to.
118 lines
3.7 KiB
C++
118 lines
3.7 KiB
C++
//===--- BasicSourceInfo.h - Simple source information ----------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_BASIC_BASIC_SOURCE_INFO_H
|
|
#define SWIFT_BASIC_BASIC_SOURCE_INFO_H
|
|
|
|
#include "swift/Basic/Fingerprint.h"
|
|
#include "swift/Basic/LLVM.h"
|
|
#include "swift/Basic/SourceLoc.h"
|
|
#include "llvm/ADT/PointerIntPair.h"
|
|
#include "llvm/Support/Chrono.h"
|
|
|
|
namespace swift {
|
|
|
|
class SourceFile;
|
|
|
|
struct ExternalSourceLocs {
|
|
struct LocationDirective {
|
|
uint32_t Offset = 0;
|
|
int32_t LineOffset = 0;
|
|
uint32_t Length = 0;
|
|
StringRef Name;
|
|
|
|
bool isValid() const { return Length > 0; }
|
|
};
|
|
|
|
struct RawLoc {
|
|
uint32_t Offset = 0;
|
|
uint32_t Line = 0;
|
|
uint32_t Column = 0;
|
|
LocationDirective Directive;
|
|
};
|
|
|
|
struct RawLocs {
|
|
StringRef SourceFilePath;
|
|
SmallVector<std::pair<RawLoc, uint32_t>, 4> DocRanges;
|
|
RawLoc Loc;
|
|
RawLoc StartLoc;
|
|
RawLoc EndLoc;
|
|
};
|
|
|
|
unsigned BufferID = 0;
|
|
SourceLoc Loc;
|
|
SmallVector<CharSourceRange, 4> DocRanges;
|
|
};
|
|
|
|
class BasicSourceFileInfo {
|
|
/// If this is non-null, fields other than 'FilePath' hasn't been populated.
|
|
/// The 'getInt()' part indicates this instance is constructed with a
|
|
/// SourceFile.
|
|
llvm::PointerIntPair<const SourceFile *, 1, bool> SFAndIsFromSF;
|
|
|
|
StringRef FilePath;
|
|
Fingerprint InterfaceHashIncludingTypeMembers = Fingerprint::ZERO();
|
|
/// Does *not* include the type-body hashes of the top level types.
|
|
/// Just the `SourceFile` hashes.
|
|
/// Used for incremental imports.
|
|
Fingerprint InterfaceHashExcludingTypeMembers = Fingerprint::ZERO();
|
|
llvm::sys::TimePoint<> LastModified = {};
|
|
uint64_t FileSize = 0;
|
|
|
|
// Populate the from 'SF' member if exist. 'SF' will be cleared.
|
|
void populateWithSourceFileIfNeeded();
|
|
|
|
public:
|
|
BasicSourceFileInfo(StringRef FilePath,
|
|
Fingerprint InterfaceHashIncludingTypeMembers,
|
|
Fingerprint InterfaceHashExcludingTypeMembers,
|
|
llvm::sys::TimePoint<> LastModified, uint64_t FileSize)
|
|
: FilePath(FilePath),
|
|
InterfaceHashIncludingTypeMembers(InterfaceHashIncludingTypeMembers),
|
|
InterfaceHashExcludingTypeMembers(InterfaceHashExcludingTypeMembers),
|
|
LastModified(LastModified), FileSize(FileSize) {}
|
|
|
|
/// Construct with a `SourceFile`. `getInterfaceHashIncludingTypeMembers()`,
|
|
/// `getInterfaceHashExcludingTypeMembers()`, `getLastModified()` and
|
|
/// `getFileSize()` are laizily populated when accessed.
|
|
BasicSourceFileInfo(const SourceFile *SF);
|
|
|
|
bool isFromSourceFile() const;
|
|
|
|
StringRef getFilePath() const { return FilePath; }
|
|
|
|
Fingerprint getInterfaceHashIncludingTypeMembers() const {
|
|
const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded();
|
|
return InterfaceHashIncludingTypeMembers;
|
|
}
|
|
|
|
Fingerprint getInterfaceHashExcludingTypeMembers() const {
|
|
const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded();
|
|
return InterfaceHashExcludingTypeMembers;
|
|
}
|
|
|
|
llvm::sys::TimePoint<> getLastModified() const {
|
|
const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded();
|
|
return LastModified;
|
|
}
|
|
|
|
uint64_t getFileSize() const {
|
|
const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded();
|
|
return FileSize;
|
|
}
|
|
};
|
|
|
|
} // namespace swift
|
|
|
|
#endif // SWIFT_BASIC_BASIC_SOURCE_INFO_H
|
|
|