mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Swift SIL: add some APIs to Location
* `var description` * `func ==` * `func hasSameSourceLocation(as:)`
This commit is contained in:
@@ -151,17 +151,17 @@ SILLocation::FilenameAndLocation *SILLocation::getCompilerGeneratedLoc() {
|
||||
return &compilerGenerated;
|
||||
}
|
||||
|
||||
static void dumpSourceLoc(SourceLoc loc) {
|
||||
static void printSourceLoc(SourceLoc loc, raw_ostream &OS) {
|
||||
if (!loc.isValid()) {
|
||||
llvm::dbgs() << "<invalid loc>";
|
||||
OS << "<invalid loc>";
|
||||
return;
|
||||
}
|
||||
const char *srcPtr = (const char *)loc.getOpaquePointerValue();
|
||||
unsigned len = strnlen(srcPtr, 20);
|
||||
if (len < 20) {
|
||||
llvm::dbgs() << '"' << StringRef(srcPtr, len) << '"';
|
||||
OS << '"' << StringRef(srcPtr, len) << '"';
|
||||
} else {
|
||||
llvm::dbgs() << '"' << StringRef(srcPtr, 20) << "[...]\"";
|
||||
OS << '"' << StringRef(srcPtr, 20) << "[...]\"";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ void SILLocation::dump() const {
|
||||
if (isFilenameAndLocation()) {
|
||||
getFilenameAndLocation()->dump();
|
||||
} else {
|
||||
dumpSourceLoc(getSourceLoc());
|
||||
printSourceLoc(getSourceLoc(), llvm::dbgs());
|
||||
}
|
||||
|
||||
if (isAutoGenerated()) llvm::dbgs() << ":auto";
|
||||
@@ -191,7 +191,7 @@ void SILLocation::dump() const {
|
||||
if (isSILFile()) llvm::dbgs() << ":sil";
|
||||
if (hasASTNodeForDebugging()) {
|
||||
llvm::dbgs() << ":debug[";
|
||||
dumpSourceLoc(getSourceLocForDebugging());
|
||||
printSourceLoc(getSourceLocForDebugging(), llvm::dbgs());
|
||||
llvm::dbgs() << "]\n";
|
||||
}
|
||||
}
|
||||
@@ -206,6 +206,18 @@ void SILLocation::print(raw_ostream &OS, const SourceManager &SM) const {
|
||||
}
|
||||
}
|
||||
|
||||
void SILLocation::print(raw_ostream &OS) const {
|
||||
if (isNull()) {
|
||||
OS << "<no loc>";
|
||||
} else if (isFilenameAndLocation()) {
|
||||
getFilenameAndLocation()->print(OS);
|
||||
} else if (DeclContext *dc = getAsDeclContext()){
|
||||
getSourceLoc().print(OS, dc->getASTContext().SourceMgr);
|
||||
} else {
|
||||
printSourceLoc(getSourceLoc(), OS);
|
||||
}
|
||||
}
|
||||
|
||||
RegularLocation::RegularLocation(Stmt *S, Pattern *P, SILModule &Module) :
|
||||
SILLocation(new (Module) ExtendedASTNodeLoc(S, P), RegularKind) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user