Files
swift-mirror/lib/SIL/SILLocation.cpp
Anna Zaks aaa4b2c332 [SIL Printer] Add optional source location printing.
Added a -v(verbose) option to swift that will trigger verbose printing in SIL
Printer. SIL Printer will print the location info only in the verbose mode.

Here is the example of the format - only the line and colon are displayed for
brevity:

%24 = apply %13(%22) : $[cc(method), thin] ((), [byref] Bool) -> Builtin.Int1 // user: %26 line:46:10

(This will be used to test the validity of SILLocation info.)

Swift SVN r6991
2013-08-07 18:39:48 +00:00

70 lines
2.2 KiB
C++

//===--- SILLocation.cpp - Location information for SIL nodes -------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "swift/SIL/SILLocation.h"
#include "swift/AST/Decl.h"
#include "swift/AST/Expr.h"
#include "swift/AST/Pattern.h"
#include "swift/AST/Stmt.h"
#include "llvm/Support/raw_ostream.h"
using namespace swift;
SourceLoc SILLocation::getSourceLoc() const {
if (ASTNode.isNull())
return SILFileSourceLoc;
if (auto decl = ASTNode.dyn_cast<Decl*>())
return decl->getLoc();
if (auto expr = ASTNode.dyn_cast<Expr*>())
return expr->getLoc();
if (auto stmt = ASTNode.dyn_cast<Stmt*>())
return stmt->getStartLoc();
if (auto patt = ASTNode.dyn_cast<Pattern*>())
return patt->getStartLoc();
llvm_unreachable("impossible SILLocation");
}
SourceLoc SILLocation::getStartSourceLoc() const {
if (ASTNode.isNull())
return SILFileSourceLoc;
if (auto decl = ASTNode.dyn_cast<Decl*>())
return decl->getStartLoc();
if (auto expr = ASTNode.dyn_cast<Expr*>())
return expr->getStartLoc();
if (auto stmt = ASTNode.dyn_cast<Stmt*>())
return stmt->getStartLoc();
if (auto patt = ASTNode.dyn_cast<Pattern*>())
return patt->getStartLoc();
llvm_unreachable("impossible SILLocation");
}
SourceLoc SILLocation::getEndSourceLoc() const {
if (ASTNode.isNull())
return SILFileSourceLoc;
if (auto decl = ASTNode.dyn_cast<Decl*>())
return decl->getEndLoc();
if (auto expr = ASTNode.dyn_cast<Expr*>())
return expr->getEndLoc();
if (auto stmt = ASTNode.dyn_cast<Stmt*>())
return stmt->getEndLoc();
if (auto patt = ASTNode.dyn_cast<Pattern*>())
return patt->getEndLoc();
llvm_unreachable("impossible SILLocation");
}
void SILLocation::dump(const SourceManager &SM) const {
print(llvm::errs(), SM);
}
void SILLocation::print(raw_ostream &OS, const SourceManager &SM) const {
getSourceLoc().print(OS, SM);
}