mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Wrap a few functions from LLVM SourceMgr in preparation of making
SourceLoc::Value private Swift SVN r7114
This commit is contained in:
@@ -90,6 +90,14 @@ public:
|
||||
rangeContainsTokenLoc(Enclosing, Inner.End);
|
||||
}
|
||||
|
||||
int findBufferContainingLoc(SourceLoc Loc) const {
|
||||
return LLVMSourceMgr.FindBufferContainingLoc(Loc.Value);
|
||||
}
|
||||
|
||||
size_t addNewSourceBuffer(llvm::MemoryBuffer *Buffer, SourceLoc IncludeLoc) {
|
||||
return LLVMSourceMgr.AddNewSourceBuffer(Buffer, IncludeLoc.Value);
|
||||
}
|
||||
|
||||
/// \brief Returns the SourceLoc for the beginning of the specified buffer
|
||||
/// (at offset zero).
|
||||
///
|
||||
@@ -101,6 +109,11 @@ public:
|
||||
unsigned getLocOffsetInBuffer(SourceLoc Loc, unsigned BufferID) const;
|
||||
|
||||
DecomposedLoc decompose(SourceLoc Loc) const;
|
||||
|
||||
std::pair<unsigned, unsigned> getLineAndColumn(SourceLoc Loc,
|
||||
int BufferID = -1) const {
|
||||
return LLVMSourceMgr.getLineAndColumn(Loc.Value, BufferID);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace swift
|
||||
|
||||
@@ -875,8 +875,8 @@ namespace {
|
||||
|
||||
bool isGoodSourceRange(SourceRange SR) {
|
||||
return SR.isValid() &&
|
||||
Ctx.SourceMgr->FindBufferContainingLoc(SR.Start.Value) != -1 &&
|
||||
Ctx.SourceMgr->FindBufferContainingLoc(SR.End.Value) != -1;
|
||||
Ctx.SourceMgr.findBufferContainingLoc(SR.Start) != -1 &&
|
||||
Ctx.SourceMgr.findBufferContainingLoc(SR.End) != -1;
|
||||
}
|
||||
|
||||
void checkSourceRanges(FuncExpr *FE) {
|
||||
|
||||
@@ -172,7 +172,7 @@ Location getStartLoc(SourceManager &SM, WithLoc *S) {
|
||||
if (S == nullptr) return L;
|
||||
|
||||
SourceLoc Start = S->getStartLoc();
|
||||
int BufferIndex = SM->FindBufferContainingLoc(Start.Value);
|
||||
int BufferIndex = SM.findBufferContainingLoc(Start);
|
||||
if (BufferIndex == -1)
|
||||
// This may be a deserialized or clang-imported decl. And modules
|
||||
// don't come with SourceLocs right now. Get at least the name of
|
||||
@@ -180,7 +180,7 @@ Location getStartLoc(SourceManager &SM, WithLoc *S) {
|
||||
return getDeserializedLoc(S);
|
||||
|
||||
L.Filename = SM->getMemoryBuffer((unsigned)BufferIndex)->getBufferIdentifier();
|
||||
std::tie(L.Line, L.Col) = SM->getLineAndColumn(Start.Value, BufferIndex);
|
||||
std::tie(L.Line, L.Col) = SM.getLineAndColumn(Start, BufferIndex);
|
||||
return L;
|
||||
}
|
||||
|
||||
|
||||
@@ -187,11 +187,11 @@ void Lexer::primeLexer() {
|
||||
}
|
||||
|
||||
void Lexer::initSubLexer(Lexer &Parent, State BeginState, State EndState) {
|
||||
assert(BufferID == static_cast<unsigned>(SourceMgr->FindBufferContainingLoc(
|
||||
BeginState.Loc.Value)) &&
|
||||
assert(BufferID == static_cast<unsigned>(SourceMgr.findBufferContainingLoc(
|
||||
BeginState.Loc)) &&
|
||||
"state for the wrong buffer");
|
||||
assert(BufferID == static_cast<unsigned>(SourceMgr->FindBufferContainingLoc(
|
||||
EndState.Loc.Value)) &&
|
||||
assert(BufferID == static_cast<unsigned>(SourceMgr.findBufferContainingLoc(
|
||||
EndState.Loc)) &&
|
||||
"state for the wrong buffer");
|
||||
|
||||
// If the parent lexer should stop prematurely, and the ArtificialEOF
|
||||
@@ -216,7 +216,7 @@ InFlightDiagnostic Lexer::diagnose(const char *Loc, Diag<> ID) {
|
||||
|
||||
Token Lexer::getTokenAt(SourceLoc Loc) {
|
||||
assert(BufferID == static_cast<unsigned>(
|
||||
SourceMgr->FindBufferContainingLoc(Loc.Value)) &&
|
||||
SourceMgr.findBufferContainingLoc(Loc)) &&
|
||||
"location from the wrong buffer");
|
||||
|
||||
Lexer L(SourceMgr, BufferID, Diags, InSILMode, /*KeepComments=*/false);
|
||||
@@ -1418,7 +1418,7 @@ SourceLoc Lexer::getLocForEndOfToken(SourceManager &SM, SourceLoc Loc) {
|
||||
return Loc;
|
||||
|
||||
// Figure out which buffer contains this location.
|
||||
int BufferID = SM->FindBufferContainingLoc(Loc.Value);
|
||||
int BufferID = SM.findBufferContainingLoc(Loc);
|
||||
if (BufferID < 0)
|
||||
return SourceLoc();
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ private:
|
||||
assert(FE);
|
||||
assert(FE->getBodyKind() == FuncExpr::BodyKind::Unparsed);
|
||||
|
||||
int BufferID = TU->Ctx.SourceMgr->FindBufferContainingLoc(FD->getLoc().Value);
|
||||
int BufferID = TU->Ctx.SourceMgr.findBufferContainingLoc(FD->getLoc());
|
||||
Parser TheParser(BufferID, TU, nullptr, &ParserState);
|
||||
|
||||
std::unique_ptr<CodeCompletionCallbacks> CodeCompletion;
|
||||
@@ -103,7 +103,7 @@ void parseDelayedTopLevelDecl(
|
||||
return;
|
||||
|
||||
int BufferID = TU->Ctx.SourceMgr
|
||||
->FindBufferContainingLoc(ParserState.getDelayedDeclLoc().Value);
|
||||
.findBufferContainingLoc(ParserState.getDelayedDeclLoc());
|
||||
Parser TheParser(BufferID, TU, nullptr, &ParserState);
|
||||
|
||||
std::unique_ptr<CodeCompletionCallbacks> CodeCompletion(
|
||||
@@ -240,7 +240,7 @@ Parser::Parser(unsigned BufferID, TranslationUnit *TU, SILParserState *SIL,
|
||||
|
||||
auto ParserPos = State->takeParserPosition();
|
||||
if (ParserPos.isValid() &&
|
||||
SourceMgr->FindBufferContainingLoc(ParserPos.Loc.Value) == int(BufferID)) {
|
||||
SourceMgr.findBufferContainingLoc(ParserPos.Loc) == int(BufferID)) {
|
||||
auto BeginParserPosition = getParserPosition(ParserPos);
|
||||
restoreParserPosition(BeginParserPosition);
|
||||
}
|
||||
|
||||
@@ -2006,18 +2006,18 @@ RValue RValueEmitter::
|
||||
visitMagicIdentifierLiteralExpr(MagicIdentifierLiteralExpr *E, SGFContext C) {
|
||||
ASTContext &Ctx = SGF.SGM.M.getASTContext();
|
||||
SILType Ty = SGF.getLoweredLoadableType(E->getType());
|
||||
llvm::SMLoc Loc;
|
||||
SourceLoc Loc;
|
||||
|
||||
// If "overrideLocationForMagicIdentifiers" is set, then we use it as the
|
||||
// location point for these magic identifiers.
|
||||
if (SGF.overrideLocationForMagicIdentifiers.isValid())
|
||||
Loc = SGF.overrideLocationForMagicIdentifiers.Value;
|
||||
Loc = SGF.overrideLocationForMagicIdentifiers;
|
||||
else
|
||||
Loc = E->getStartLoc().Value;
|
||||
Loc = E->getStartLoc();
|
||||
|
||||
switch (E->getKind()) {
|
||||
case MagicIdentifierLiteralExpr::File: {
|
||||
int BufferID = Ctx.SourceMgr->FindBufferContainingLoc(Loc);
|
||||
int BufferID = Ctx.SourceMgr.findBufferContainingLoc(Loc);
|
||||
assert(BufferID != -1 && "MagicIdentifierLiteral has invalid location");
|
||||
|
||||
StringRef Value =
|
||||
@@ -2027,12 +2027,12 @@ visitMagicIdentifierLiteralExpr(MagicIdentifierLiteralExpr *E, SGFContext C) {
|
||||
ManagedValue::Unmanaged));
|
||||
}
|
||||
case MagicIdentifierLiteralExpr::Line: {
|
||||
unsigned Value = Ctx.SourceMgr->getLineAndColumn(Loc).first;
|
||||
unsigned Value = Ctx.SourceMgr.getLineAndColumn(Loc).first;
|
||||
return RValue(SGF, ManagedValue(SGF.B.createIntegerLiteral(E, Ty, Value),
|
||||
ManagedValue::Unmanaged));
|
||||
}
|
||||
case MagicIdentifierLiteralExpr::Column: {
|
||||
unsigned Value = Ctx.SourceMgr->getLineAndColumn(Loc).second;
|
||||
unsigned Value = Ctx.SourceMgr.getLineAndColumn(Loc).second;
|
||||
return RValue(SGF, ManagedValue(SGF.B.createIntegerLiteral(E, Ty, Value),
|
||||
ManagedValue::Unmanaged));
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ static llvm::error_code findModule(ASTContext &ctx, StringRef moduleID,
|
||||
|
||||
// First, search in the directory corresponding to the import location.
|
||||
// FIXME: This screams for a proper FileManager abstraction.
|
||||
int currentBufferID = ctx.SourceMgr->FindBufferContainingLoc(importLoc.Value);
|
||||
int currentBufferID = ctx.SourceMgr.findBufferContainingLoc(importLoc);
|
||||
if (currentBufferID >= 0) {
|
||||
const llvm::MemoryBuffer *importingBuffer
|
||||
= ctx.SourceMgr->getBufferInfo(currentBufferID).Buffer;
|
||||
@@ -96,8 +96,8 @@ Module *SourceLoader::loadModule(SourceLoc importLoc,
|
||||
llvm::SaveAndRestore<bool> turnOffDebug(Ctx.LangOpts.DebugConstraintSolver,
|
||||
false);
|
||||
|
||||
unsigned bufferID = Ctx.SourceMgr->AddNewSourceBuffer(inputFile.take(),
|
||||
moduleID.second.Value);
|
||||
unsigned bufferID = Ctx.SourceMgr.addNewSourceBuffer(inputFile.take(),
|
||||
moduleID.second);
|
||||
|
||||
// For now, treat all separate modules as unique components.
|
||||
Component *comp = new (Ctx.Allocate<Component>(1)) Component();
|
||||
|
||||
@@ -46,8 +46,7 @@ static llvm::error_code findModule(ASTContext &ctx, AccessPathElem moduleID,
|
||||
|
||||
// First, search in the directory corresponding to the import location.
|
||||
// FIXME: This screams for a proper FileManager abstraction.
|
||||
llvm::SMLoc rawLoc = moduleID.second.Value;
|
||||
int currentBufferID = ctx.SourceMgr->FindBufferContainingLoc(rawLoc);
|
||||
int currentBufferID = ctx.SourceMgr.findBufferContainingLoc(moduleID.second);
|
||||
if (currentBufferID >= 0) {
|
||||
const llvm::MemoryBuffer *importingBuffer
|
||||
= ctx.SourceMgr->getBufferInfo(currentBufferID).Buffer;
|
||||
@@ -100,9 +99,8 @@ static Module *makeTU(ASTContext &ctx, AccessPathElem moduleID,
|
||||
|
||||
// Transfer ownership of the MemoryBuffer to the SourceMgr.
|
||||
// FIXME: include location
|
||||
llvm::SMLoc rawLoc = moduleID.second.Value;
|
||||
BufferIDs.push_back(ctx.SourceMgr->AddNewSourceBuffer(InputFile.take(),
|
||||
rawLoc));
|
||||
BufferIDs.push_back(ctx.SourceMgr.addNewSourceBuffer(InputFile.take(),
|
||||
moduleID.second));
|
||||
}
|
||||
|
||||
for (auto &BufferID : BufferIDs) {
|
||||
|
||||
Reference in New Issue
Block a user