mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Basic: Untie swift::SourceLoc from llvm::SMLoc
Storing a `llvm::SMLoc` is a superfluous indirection, and getting rid of it enables us to unconditionally import `SourceLoc` into Swift.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 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
|
||||
@@ -242,7 +242,9 @@ public:
|
||||
void diagnose(YAMLNodeTy node, Diag<ArgTypes...> ID,
|
||||
typename detail::PassArgument<ArgTypes>::type... args) {
|
||||
auto smRange = node->getSourceRange();
|
||||
auto range = SourceRange(SourceLoc(smRange.Start), SourceLoc(smRange.End));
|
||||
auto range =
|
||||
SourceRange(SourceLoc::getFromPointer(smRange.Start.getPointer()),
|
||||
SourceLoc::getFromPointer(smRange.End.getPointer()));
|
||||
Diags.diagnose(range.Start, ID, std::forward<ArgTypes>(args)...)
|
||||
.highlight(range);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 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
|
||||
@@ -247,14 +247,12 @@ public:
|
||||
return getDecl()->getLoc();
|
||||
|
||||
case UnsafeConformance:
|
||||
return SourceLoc(
|
||||
llvm::SMLoc::getFromPointer(
|
||||
(const char *)storage.conformance.location));
|
||||
return SourceLoc::getFromPointer(
|
||||
(const char *)storage.conformance.location);
|
||||
|
||||
case TypeWitness:
|
||||
return SourceLoc(
|
||||
llvm::SMLoc::getFromPointer(
|
||||
(const char *)storage.typeWitness.location));
|
||||
return SourceLoc::getFromPointer(
|
||||
(const char *)storage.typeWitness.location);
|
||||
|
||||
case UnownedUnsafe:
|
||||
case ExclusivityUnchecked:
|
||||
@@ -263,8 +261,7 @@ public:
|
||||
case ReferenceToUnsafeStorage:
|
||||
case ReferenceToUnsafeThroughTypealias:
|
||||
case CallToUnsafe:
|
||||
return SourceLoc(
|
||||
llvm::SMLoc::getFromPointer((const char *)storage.entity.location));
|
||||
return SourceLoc::getFromPointer((const char *)storage.entity.location);
|
||||
|
||||
case CallArgument:
|
||||
return storage.callArgument.call->getLoc();
|
||||
|
||||
@@ -46,8 +46,7 @@ BridgedSourceLoc::BridgedSourceLoc(swift::SourceLoc loc)
|
||||
: Raw(loc.getOpaquePointerValue()) {}
|
||||
|
||||
swift::SourceLoc BridgedSourceLoc::unbridged() const {
|
||||
return swift::SourceLoc(
|
||||
llvm::SMLoc::getFromPointer(static_cast<const char *>(Raw)));
|
||||
return swift::SourceLoc::getFromPointer(static_cast<const char *>(Raw));
|
||||
}
|
||||
|
||||
BridgedSourceLoc BridgedSourceLoc::advancedBy(size_t n) const {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 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
|
||||
@@ -26,25 +26,36 @@
|
||||
#include <assert.h>
|
||||
#include <functional>
|
||||
|
||||
namespace swift {
|
||||
class SourceManager;
|
||||
namespace llvm {
|
||||
class SMLoc;
|
||||
}
|
||||
|
||||
/// SourceLoc in swift is just an SMLoc. We define it as a different type
|
||||
/// (instead of as a typedef) just to remove the "getFromPointer" methods and
|
||||
/// enforce purity in the Swift codebase.
|
||||
namespace swift {
|
||||
class SourceManager;
|
||||
|
||||
/// `SourceLoc` just wraps a `const char *`. We define it as a different type
|
||||
/// (instead of as a typedef) from `llvm::SMLoc` to enforce purity in the
|
||||
/// Swift codebase.
|
||||
class SourceLoc {
|
||||
friend class SourceManager;
|
||||
friend class SourceRange;
|
||||
friend class CharSourceRange;
|
||||
friend class DiagnosticConsumer;
|
||||
|
||||
llvm::SMLoc Value;
|
||||
const char *Pointer = nullptr;
|
||||
|
||||
public:
|
||||
SourceLoc() {}
|
||||
explicit SourceLoc(llvm::SMLoc Value) : Value(Value) {}
|
||||
|
||||
bool isValid() const { return Value.isValid(); }
|
||||
|
||||
static SourceLoc getFromPointer(const char *Pointer) {
|
||||
SourceLoc Loc;
|
||||
Loc.Pointer = Pointer;
|
||||
return Loc;
|
||||
}
|
||||
|
||||
const char *getPointer() const { return Pointer; }
|
||||
|
||||
bool isValid() const { return Pointer != nullptr; }
|
||||
bool isInvalid() const { return !isValid(); }
|
||||
|
||||
/// An explicit bool operator so one can check if a SourceLoc is valid in an
|
||||
@@ -53,14 +64,15 @@ public:
|
||||
/// if (auto x = getSourceLoc()) { ... }
|
||||
explicit operator bool() const { return isValid(); }
|
||||
|
||||
bool operator==(const SourceLoc &RHS) const { return RHS.Value == Value; }
|
||||
operator llvm::SMLoc() const { return llvm::SMLoc::getFromPointer(Pointer); }
|
||||
|
||||
bool operator==(const SourceLoc &RHS) const { return RHS.Pointer == Pointer; }
|
||||
bool operator!=(const SourceLoc &RHS) const { return !operator==(RHS); }
|
||||
|
||||
|
||||
/// Return a source location advanced a specified number of bytes.
|
||||
SourceLoc getAdvancedLoc(int ByteOffset) const {
|
||||
assert(isValid() && "Can't advance an invalid location");
|
||||
return SourceLoc(
|
||||
llvm::SMLoc::getFromPointer(Value.getPointer() + ByteOffset));
|
||||
return SourceLoc::getFromPointer(Pointer + ByteOffset);
|
||||
}
|
||||
|
||||
SourceLoc getAdvancedLocOrInvalid(int ByteOffset) const {
|
||||
@@ -69,7 +81,7 @@ public:
|
||||
return SourceLoc();
|
||||
}
|
||||
|
||||
const void *getOpaquePointerValue() const { return Value.getPointer(); }
|
||||
const void *getOpaquePointerValue() const { return Pointer; }
|
||||
|
||||
/// Print out the SourceLoc. If this location is in the same buffer
|
||||
/// as specified by \c LastBufferID, then we don't print the filename. If
|
||||
@@ -88,13 +100,13 @@ public:
|
||||
|
||||
SWIFT_DEBUG_DUMPER(dump(const SourceManager &SM));
|
||||
|
||||
friend size_t hash_value(SourceLoc loc) {
|
||||
return reinterpret_cast<uintptr_t>(loc.getOpaquePointerValue());
|
||||
}
|
||||
friend size_t hash_value(SourceLoc loc) {
|
||||
return reinterpret_cast<uintptr_t>(loc.getOpaquePointerValue());
|
||||
}
|
||||
|
||||
friend void simple_display(raw_ostream &OS, const SourceLoc &loc) {
|
||||
// Nothing meaningful to print.
|
||||
}
|
||||
friend void simple_display(raw_ostream &OS, const SourceLoc &loc) {
|
||||
// Nothing meaningful to print.
|
||||
}
|
||||
};
|
||||
|
||||
/// SourceRange in swift is a pair of locations. However, note that the end
|
||||
@@ -210,27 +222,27 @@ public:
|
||||
bool contains(SourceLoc loc) const {
|
||||
auto less = std::less<const char *>();
|
||||
auto less_equal = std::less_equal<const char *>();
|
||||
return less_equal(getStart().Value.getPointer(), loc.Value.getPointer()) &&
|
||||
less(loc.Value.getPointer(), getEnd().Value.getPointer());
|
||||
return less_equal(getStart().Pointer, loc.Pointer) &&
|
||||
less(loc.Pointer, getEnd().Pointer);
|
||||
}
|
||||
|
||||
bool contains(CharSourceRange Other) const {
|
||||
auto less_equal = std::less_equal<const char *>();
|
||||
return contains(Other.getStart()) &&
|
||||
less_equal(Other.getEnd().Value.getPointer(), getEnd().Value.getPointer());
|
||||
less_equal(Other.getEnd().Pointer, getEnd().Pointer);
|
||||
}
|
||||
|
||||
/// expands *this to cover Other
|
||||
void widen(CharSourceRange Other) {
|
||||
auto Diff = Other.getEnd().Value.getPointer() - getEnd().Value.getPointer();
|
||||
auto Diff = Other.getEnd().Pointer - getEnd().Pointer;
|
||||
if (Diff > 0) {
|
||||
ByteLength += Diff;
|
||||
}
|
||||
const auto MyStartPtr = getStart().Value.getPointer();
|
||||
Diff = MyStartPtr - Other.getStart().Value.getPointer();
|
||||
const auto MyStartPtr = getStart().Pointer;
|
||||
Diff = MyStartPtr - Other.getStart().Pointer;
|
||||
if (Diff > 0) {
|
||||
ByteLength += Diff;
|
||||
Start = SourceLoc(llvm::SMLoc::getFromPointer(MyStartPtr - Diff));
|
||||
Start = SourceLoc::getFromPointer(MyStartPtr - Diff);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,9 +251,7 @@ public:
|
||||
return contains(Other.getStart()) || Other.contains(getStart());
|
||||
}
|
||||
|
||||
StringRef str() const {
|
||||
return StringRef(Start.Value.getPointer(), ByteLength);
|
||||
}
|
||||
StringRef str() const { return StringRef(Start.Pointer, ByteLength); }
|
||||
|
||||
/// Return the length of this valid range in bytes. Can be zero.
|
||||
unsigned getByteLength() const {
|
||||
@@ -272,15 +282,15 @@ template <typename T, typename Enable> struct DenseMapInfo;
|
||||
|
||||
template <> struct DenseMapInfo<swift::SourceLoc> {
|
||||
static swift::SourceLoc getEmptyKey() {
|
||||
return swift::SourceLoc(
|
||||
SMLoc::getFromPointer(DenseMapInfo<const char *>::getEmptyKey()));
|
||||
return swift::SourceLoc::getFromPointer(
|
||||
DenseMapInfo<const char *>::getEmptyKey());
|
||||
}
|
||||
|
||||
static swift::SourceLoc getTombstoneKey() {
|
||||
// Make this different from empty key. See for context:
|
||||
// http://lists.llvm.org/pipermail/llvm-dev/2015-July/088744.html
|
||||
return swift::SourceLoc(
|
||||
SMLoc::getFromPointer(DenseMapInfo<const char *>::getTombstoneKey()));
|
||||
return swift::SourceLoc::getFromPointer(
|
||||
DenseMapInfo<const char *>::getTombstoneKey());
|
||||
}
|
||||
|
||||
static unsigned getHashValue(const swift::SourceLoc &Val) {
|
||||
@@ -296,15 +306,15 @@ template <> struct DenseMapInfo<swift::SourceLoc> {
|
||||
|
||||
template <> struct DenseMapInfo<swift::SourceRange> {
|
||||
static swift::SourceRange getEmptyKey() {
|
||||
return swift::SourceRange(swift::SourceLoc(
|
||||
SMLoc::getFromPointer(DenseMapInfo<const char *>::getEmptyKey())));
|
||||
return swift::SourceRange(swift::SourceLoc::getFromPointer(
|
||||
DenseMapInfo<const char *>::getEmptyKey()));
|
||||
}
|
||||
|
||||
static swift::SourceRange getTombstoneKey() {
|
||||
// Make this different from empty key. See for context:
|
||||
// http://lists.llvm.org/pipermail/llvm-dev/2015-July/088744.html
|
||||
return swift::SourceRange(swift::SourceLoc(
|
||||
SMLoc::getFromPointer(DenseMapInfo<const char *>::getTombstoneKey())));
|
||||
return swift::SourceRange(swift::SourceLoc::getFromPointer(
|
||||
DenseMapInfo<const char *>::getTombstoneKey()));
|
||||
}
|
||||
|
||||
static unsigned getHashValue(const swift::SourceRange &Val) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 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
|
||||
@@ -311,7 +311,7 @@ public:
|
||||
|
||||
/// Returns true if \c LHS is before \c RHS in the same source buffer.
|
||||
bool isBeforeInBuffer(SourceLoc LHS, SourceLoc RHS) const {
|
||||
return LHS.Value.getPointer() < RHS.Value.getPointer();
|
||||
return LHS.getPointer() < RHS.getPointer();
|
||||
}
|
||||
|
||||
/// Returns true if \c range contains the location \c loc. The location
|
||||
@@ -485,7 +485,7 @@ public:
|
||||
assert(Loc.isValid());
|
||||
int LineOffset = getLineOffset(Loc);
|
||||
int l, c;
|
||||
std::tie(l, c) = LLVMSourceMgr.getLineAndColumn(Loc.Value, BufferID);
|
||||
std::tie(l, c) = LLVMSourceMgr.getLineAndColumn(Loc, BufferID);
|
||||
assert(LineOffset+l > 0 && "bogus line offset");
|
||||
return { LineOffset + l, c };
|
||||
}
|
||||
@@ -498,7 +498,7 @@ public:
|
||||
std::pair<unsigned, unsigned>
|
||||
getLineAndColumnInBuffer(SourceLoc Loc, unsigned BufferID = 0) const {
|
||||
assert(Loc.isValid());
|
||||
return LLVMSourceMgr.getLineAndColumn(Loc.Value, BufferID);
|
||||
return LLVMSourceMgr.getLineAndColumn(Loc, BufferID);
|
||||
}
|
||||
|
||||
/// Returns the column for the given source location in the given buffer.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 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
|
||||
@@ -414,7 +414,7 @@ public:
|
||||
static bool isOperator(StringRef string);
|
||||
|
||||
SourceLoc getLocForStartOfBuffer() const {
|
||||
return SourceLoc(llvm::SMLoc::getFromPointer(BufferStart));
|
||||
return SourceLoc::getFromPointer(BufferStart);
|
||||
}
|
||||
|
||||
/// StringSegment - A segment of a (potentially interpolated) string.
|
||||
@@ -516,7 +516,7 @@ public:
|
||||
}
|
||||
|
||||
static SourceLoc getSourceLoc(const char *Loc) {
|
||||
return SourceLoc(llvm::SMLoc::getFromPointer(Loc));
|
||||
return SourceLoc::getFromPointer(Loc);
|
||||
}
|
||||
|
||||
/// Get the token that starts at the given location.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 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
|
||||
@@ -287,9 +287,7 @@ public:
|
||||
|
||||
/// getLoc - Return a source location identifier for the specified
|
||||
/// offset in the current file.
|
||||
SourceLoc getLoc() const {
|
||||
return SourceLoc(llvm::SMLoc::getFromPointer(Text.begin()));
|
||||
}
|
||||
SourceLoc getLoc() const { return SourceLoc::getFromPointer(Text.begin()); }
|
||||
|
||||
unsigned getLength() const { return Text.size(); }
|
||||
|
||||
@@ -303,17 +301,15 @@ public:
|
||||
|
||||
CharSourceRange getCommentRange() const {
|
||||
if (CommentLength == 0)
|
||||
return CharSourceRange(SourceLoc(llvm::SMLoc::getFromPointer(Text.begin())),
|
||||
0);
|
||||
return CharSourceRange(SourceLoc::getFromPointer(Text.begin()), 0);
|
||||
auto TrimedComment = trimComment();
|
||||
return CharSourceRange(
|
||||
SourceLoc(llvm::SMLoc::getFromPointer(TrimedComment.begin())),
|
||||
TrimedComment.size());
|
||||
return CharSourceRange(SourceLoc::getFromPointer(TrimedComment.begin()),
|
||||
TrimedComment.size());
|
||||
}
|
||||
|
||||
SourceLoc getCommentStart() const {
|
||||
if (CommentLength == 0) return SourceLoc();
|
||||
return SourceLoc(llvm::SMLoc::getFromPointer(trimComment().begin()));
|
||||
return SourceLoc::getFromPointer(trimComment().begin());
|
||||
}
|
||||
|
||||
StringRef getRawText() const {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 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
|
||||
@@ -182,7 +182,7 @@ static void
|
||||
convertToErrorAndJoin(const llvm::SMDiagnostic &diag, void *ctxPtr) {
|
||||
ASTContext &ctx = *(ASTContext*)ctxPtr;
|
||||
|
||||
SourceLoc loc{diag.getLoc()};
|
||||
auto loc = SourceLoc::getFromPointer(diag.getLoc().getPointer());
|
||||
assert(ctx.SourceMgr.isOwning(loc));
|
||||
|
||||
switch (diag.getKind()) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 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
|
||||
@@ -40,9 +40,7 @@ DiagnosticInfo::FixIt::FixIt(CharSourceRange R, StringRef Str,
|
||||
formatForFixIts());
|
||||
}
|
||||
|
||||
llvm::SMLoc DiagnosticConsumer::getRawLoc(SourceLoc loc) {
|
||||
return loc.Value;
|
||||
}
|
||||
llvm::SMLoc DiagnosticConsumer::getRawLoc(SourceLoc loc) { return loc; }
|
||||
|
||||
LLVM_ATTRIBUTE_UNUSED
|
||||
static bool hasDuplicateFileNames(
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 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
|
||||
@@ -120,7 +120,7 @@ void SourceManager::createVirtualFile(SourceLoc Loc, StringRef Name,
|
||||
CharSourceRange Range = CharSourceRange(Loc, Length);
|
||||
|
||||
// Skip if this range has already been added
|
||||
VirtualFile &File = VirtualFiles[Range.getEnd().Value.getPointer()];
|
||||
VirtualFile &File = VirtualFiles[Range.getEnd().getPointer()];
|
||||
if (File.Range.isValid()) {
|
||||
assert(Name == StringRef(File.Name));
|
||||
assert(LineOffset == File.LineOffset);
|
||||
@@ -132,8 +132,8 @@ void SourceManager::createVirtualFile(SourceLoc Loc, StringRef Name,
|
||||
File.Name = Name.str();
|
||||
File.LineOffset = LineOffset;
|
||||
|
||||
if (CachedVFile.first && Range.contains(SourceLoc(llvm::SMLoc::getFromPointer(
|
||||
CachedVFile.first)))) {
|
||||
if (CachedVFile.first &&
|
||||
Range.contains(SourceLoc::getFromPointer(CachedVFile.first))) {
|
||||
CachedVFile = {nullptr, nullptr};
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ bool SourceManager::openVirtualFile(SourceLoc loc, StringRef name,
|
||||
CharSourceRange fullRange = getRangeForBuffer(findBufferContainingLoc(loc));
|
||||
SourceLoc end;
|
||||
|
||||
auto nextRangeIter = VirtualFiles.upper_bound(loc.Value.getPointer());
|
||||
auto nextRangeIter = VirtualFiles.upper_bound(loc.getPointer());
|
||||
if (nextRangeIter != VirtualFiles.end() &&
|
||||
fullRange.contains(nextRangeIter->second.Range.getStart())) {
|
||||
const VirtualFile &existingFile = nextRangeIter->second;
|
||||
@@ -160,7 +160,7 @@ bool SourceManager::openVirtualFile(SourceLoc loc, StringRef name,
|
||||
}
|
||||
|
||||
CharSourceRange range = CharSourceRange(*this, loc, end);
|
||||
VirtualFiles[end.Value.getPointer()] = {range, name.str(), lineOffset};
|
||||
VirtualFiles[end.getPointer()] = {range, name.str(), lineOffset};
|
||||
CachedVFile = {nullptr, nullptr};
|
||||
return true;
|
||||
}
|
||||
@@ -183,16 +183,16 @@ void SourceManager::closeVirtualFile(SourceLoc end) {
|
||||
CharSourceRange oldRange = virtualFile->Range;
|
||||
virtualFile->Range = CharSourceRange(*this, virtualFile->Range.getStart(),
|
||||
end);
|
||||
VirtualFiles[end.Value.getPointer()] = std::move(*virtualFile);
|
||||
VirtualFiles[end.getPointer()] = std::move(*virtualFile);
|
||||
|
||||
bool existed = VirtualFiles.erase(oldRange.getEnd().Value.getPointer());
|
||||
bool existed = VirtualFiles.erase(oldRange.getEnd().getPointer());
|
||||
assert(existed);
|
||||
(void)existed;
|
||||
}
|
||||
|
||||
const SourceManager::VirtualFile *
|
||||
SourceManager::getVirtualFile(SourceLoc Loc) const {
|
||||
const char *p = Loc.Value.getPointer();
|
||||
const char *p = Loc.getPointer();
|
||||
|
||||
if (CachedVFile.first == p)
|
||||
return CachedVFile.second;
|
||||
@@ -328,7 +328,7 @@ StringRef SourceManager::getIdentifierForBuffer(
|
||||
|
||||
CharSourceRange SourceManager::getRangeForBuffer(unsigned bufferID) const {
|
||||
auto *buffer = LLVMSourceMgr.getMemoryBuffer(bufferID);
|
||||
SourceLoc start{llvm::SMLoc::getFromPointer(buffer->getBufferStart())};
|
||||
auto start = SourceLoc::getFromPointer(buffer->getBufferStart());
|
||||
return CharSourceRange(start, buffer->getBufferSize());
|
||||
}
|
||||
|
||||
@@ -336,10 +336,10 @@ unsigned SourceManager::getLocOffsetInBuffer(SourceLoc Loc,
|
||||
unsigned BufferID) const {
|
||||
assert(Loc.isValid() && "location should be valid");
|
||||
auto *Buffer = LLVMSourceMgr.getMemoryBuffer(BufferID);
|
||||
assert(Loc.Value.getPointer() >= Buffer->getBuffer().begin() &&
|
||||
Loc.Value.getPointer() <= Buffer->getBuffer().end() &&
|
||||
assert(Loc.getPointer() >= Buffer->getBuffer().begin() &&
|
||||
Loc.getPointer() <= Buffer->getBuffer().end() &&
|
||||
"Location is not from the specified buffer");
|
||||
return Loc.Value.getPointer() - Buffer->getBuffer().begin();
|
||||
return Loc.getPointer() - Buffer->getBuffer().begin();
|
||||
}
|
||||
|
||||
unsigned SourceManager::getByteDistance(SourceLoc Start, SourceLoc End) const {
|
||||
@@ -348,13 +348,13 @@ unsigned SourceManager::getByteDistance(SourceLoc Start, SourceLoc End) const {
|
||||
#ifndef NDEBUG
|
||||
unsigned BufferID = findBufferContainingLoc(Start);
|
||||
auto *Buffer = LLVMSourceMgr.getMemoryBuffer(BufferID);
|
||||
assert(End.Value.getPointer() >= Buffer->getBuffer().begin() &&
|
||||
End.Value.getPointer() <= Buffer->getBuffer().end() &&
|
||||
assert(End.getPointer() >= Buffer->getBuffer().begin() &&
|
||||
End.getPointer() <= Buffer->getBuffer().end() &&
|
||||
"End location is not from the same buffer");
|
||||
#endif
|
||||
// When we have a rope buffer, could be implemented in terms of
|
||||
// getLocOffsetInBuffer().
|
||||
return End.Value.getPointer() - Start.Value.getPointer();
|
||||
return End.getPointer() - Start.getPointer();
|
||||
}
|
||||
|
||||
unsigned SourceManager::getColumnInBuffer(SourceLoc Loc,
|
||||
@@ -512,10 +512,10 @@ SourceManager::findBufferContainingLocInternal(SourceLoc Loc) const {
|
||||
auto less_equal = std::less_equal<const char *>();
|
||||
auto buffer = LLVMSourceMgr.getMemoryBuffer(bufferID);
|
||||
|
||||
return less_equal(buffer->getBufferStart(), Loc.Value.getPointer()) &&
|
||||
return less_equal(buffer->getBufferStart(), Loc.getPointer()) &&
|
||||
// Use <= here so that a pointer to the null at the end of the
|
||||
// buffer is included as part of the buffer.
|
||||
less_equal(Loc.Value.getPointer(), buffer->getBufferEnd());
|
||||
less_equal(Loc.getPointer(), buffer->getBufferEnd());
|
||||
};
|
||||
|
||||
// Check the last buffer we looked in.
|
||||
@@ -569,15 +569,15 @@ SourceRange SourceRange::combine(ArrayRef<SourceRange> ranges) {
|
||||
}
|
||||
|
||||
void SourceRange::widen(SourceRange Other) {
|
||||
if (Other.Start.Value.getPointer() < Start.Value.getPointer())
|
||||
if (Other.Start.getPointer() < Start.getPointer())
|
||||
Start = Other.Start;
|
||||
if (Other.End.Value.getPointer() > End.Value.getPointer())
|
||||
if (Other.End.getPointer() > End.getPointer())
|
||||
End = Other.End;
|
||||
}
|
||||
|
||||
bool SourceRange::contains(SourceLoc Loc) const {
|
||||
return Start.Value.getPointer() <= Loc.Value.getPointer() &&
|
||||
Loc.Value.getPointer() <= End.Value.getPointer();
|
||||
return Start.getPointer() <= Loc.getPointer() &&
|
||||
Loc.getPointer() <= End.getPointer();
|
||||
}
|
||||
|
||||
bool SourceRange::overlaps(SourceRange Other) const {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 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
|
||||
@@ -36,7 +36,6 @@
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/PrefixMapper.h"
|
||||
#include "llvm/Support/SMLoc.h"
|
||||
#include "llvm/Support/VirtualFileSystem.h"
|
||||
#include "llvm/Support/YAMLTraits.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
@@ -340,7 +339,8 @@ unsigned DiagnosticSerializer::getFileIDFromBufferID(SourceManager &SM,
|
||||
|
||||
StringRef FileContent = Buf.Buffer->getBuffer();
|
||||
SerializedFile File = {Filename.str(),
|
||||
convertSourceLoc(SM, SourceLoc(Buf.IncludeLoc)),
|
||||
convertSourceLoc(SM, SourceLoc::getFromPointer(
|
||||
Buf.IncludeLoc.getPointer())),
|
||||
{},
|
||||
IsFileBacked ? "" : FileContent};
|
||||
|
||||
@@ -501,8 +501,7 @@ DiagnosticSerializer::deserializeSourceLoc(const SerializedSourceLoc &Loc) {
|
||||
return createDeserializationError("File doesn't exist in SourceManager");
|
||||
auto &Info = SrcMgr.getLLVMSourceMgr().getBufferInfo(BufID->second);
|
||||
const char *Buffer = Info.Buffer->getBufferStart();
|
||||
llvm::SMLoc SL = llvm::SMLoc::getFromPointer(Buffer + Loc.Offset);
|
||||
return SourceLoc(SL);
|
||||
return SourceLoc::getFromPointer(Buffer + Loc.Offset);
|
||||
}
|
||||
|
||||
llvm::Expected<CharSourceRange> DiagnosticSerializer::deserializeSourceRange(
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2020 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2020 - 2025 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
|
||||
@@ -316,7 +316,7 @@ private:
|
||||
InFlightDiagnostic
|
||||
diagnose(DiagnosticEngine &Diags, const char *LocPtr, Diag<ArgTypes...> ID,
|
||||
typename detail::PassArgument<ArgTypes>::type... Args) const {
|
||||
auto Loc = SourceLoc(llvm::SMLoc::getFromPointer(LocPtr));
|
||||
auto Loc = SourceLoc::getFromPointer(LocPtr);
|
||||
return Diags.diagnose(Loc, ID, std::move(Args)...);
|
||||
}
|
||||
};
|
||||
@@ -486,7 +486,7 @@ bool DependencyVerifier::diagnoseUnfulfilledObligations(
|
||||
// HACK: Diagnosing the end of the buffer will print a carat pointing
|
||||
// at the file path, but not print any of the buffer's contents, which
|
||||
// might be misleading.
|
||||
auto Loc = SourceLoc(llvm::SMLoc::getFromPointer(InputFile.end()));
|
||||
auto Loc = SourceLoc::getFromPointer(InputFile.end());
|
||||
switch (p.getKind()) {
|
||||
case Expectation::Kind::Negative:
|
||||
llvm_unreachable("Obligations may not be negative; only Expectations!");
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 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
|
||||
@@ -612,7 +612,7 @@ DiagnosticVerifier::Result DiagnosticVerifier::verifyFile(unsigned BufferID) {
|
||||
|
||||
auto addError = [&](const char *Loc, const Twine &message,
|
||||
ArrayRef<llvm::SMFixIt> FixIts = {}) {
|
||||
auto loc = SourceLoc(SMLoc::getFromPointer(Loc));
|
||||
auto loc = SourceLoc::getFromPointer(Loc);
|
||||
auto diag = SM.GetMessage(loc, llvm::SourceMgr::DK_Error, message,
|
||||
{}, FixIts);
|
||||
Errors.push_back(diag);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 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
|
||||
@@ -165,14 +165,14 @@ SourceManager::GetMessage(SourceLoc Loc, llvm::SourceMgr::DiagKind Kind,
|
||||
auto CurMB = LLVMSourceMgr.getMemoryBuffer(findBufferContainingLoc(Loc));
|
||||
|
||||
// Scan backward to find the start of the line.
|
||||
const char *LineStart = Loc.Value.getPointer();
|
||||
const char *LineStart = Loc.getPointer();
|
||||
const char *BufStart = CurMB->getBufferStart();
|
||||
while (LineStart != BufStart && LineStart[-1] != '\n' &&
|
||||
LineStart[-1] != '\r')
|
||||
--LineStart;
|
||||
|
||||
// Get the end of the line.
|
||||
const char *LineEnd = Loc.Value.getPointer();
|
||||
const char *LineEnd = Loc.getPointer();
|
||||
const char *BufEnd = CurMB->getBufferEnd();
|
||||
while (LineEnd != BufEnd && LineEnd[0] != '\n' && LineEnd[0] != '\r')
|
||||
++LineEnd;
|
||||
@@ -203,10 +203,9 @@ SourceManager::GetMessage(SourceLoc Loc, llvm::SourceMgr::DiagKind Kind,
|
||||
LineAndCol = getPresumedLineAndColumnForLoc(Loc);
|
||||
}
|
||||
|
||||
return llvm::SMDiagnostic(LLVMSourceMgr, Loc.Value, BufferID,
|
||||
LineAndCol.first,
|
||||
LineAndCol.second-1, Kind, Msg.str(),
|
||||
LineStr, ColRanges, FixIts);
|
||||
return llvm::SMDiagnostic(LLVMSourceMgr, Loc, BufferID, LineAndCol.first,
|
||||
LineAndCol.second - 1, Kind, Msg.str(), LineStr,
|
||||
ColRanges, FixIts);
|
||||
}
|
||||
|
||||
// These must come after the declaration of AnnotatedSourceSnippet due to the
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 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
|
||||
@@ -348,7 +348,7 @@ Lexer::State Lexer::getStateForBeginningOfTokenLoc(SourceLoc Loc) const {
|
||||
}
|
||||
break;
|
||||
}
|
||||
return State(SourceLoc(llvm::SMLoc::getFromPointer(Ptr)));
|
||||
return State(SourceLoc::getFromPointer(Ptr));
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@@ -22,7 +22,7 @@ static std::vector<SourceLoc> tokenize(SourceManager &SM, StringRef Source) {
|
||||
unsigned ID = SM.addMemBufferCopy(Source);
|
||||
const MemoryBuffer *Buf = SM.getLLVMSourceMgr().getMemoryBuffer(ID);
|
||||
|
||||
SourceLoc BeginLoc(SMLoc::getFromPointer(Buf->getBuffer().begin()));
|
||||
auto BeginLoc = SourceLoc::getFromPointer(Buf->getBuffer().begin());
|
||||
std::vector<SourceLoc> Result;
|
||||
Result.push_back(BeginLoc);
|
||||
for (unsigned i = 1, e = Source.size(); i != e; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user