@@ -151,17 +151,17 @@ SILLocation::FilenameAndLocation *SILLocation::getCompilerGeneratedLoc() {
151151 return &compilerGenerated;
152152}
153153
154- static void dumpSourceLoc (SourceLoc loc) {
154+ static void printSourceLoc (SourceLoc loc, raw_ostream &OS ) {
155155 if (!loc.isValid ()) {
156- llvm::dbgs () << " <invalid loc>" ;
156+ OS << " <invalid loc>" ;
157157 return ;
158158 }
159159 const char *srcPtr = (const char *)loc.getOpaquePointerValue ();
160160 unsigned len = strnlen (srcPtr, 20 );
161161 if (len < 20 ) {
162- llvm::dbgs () << ' "' << StringRef (srcPtr, len) << ' "' ;
162+ OS << ' "' << StringRef (srcPtr, len) << ' "' ;
163163 } else {
164- llvm::dbgs () << ' "' << StringRef (srcPtr, 20 ) << " [...]\" " ;
164+ OS << ' "' << StringRef (srcPtr, 20 ) << " [...]\" " ;
165165 }
166166}
167167
@@ -182,7 +182,7 @@ void SILLocation::dump() const {
182182 if (isFilenameAndLocation ()) {
183183 getFilenameAndLocation ()->dump ();
184184 } else {
185- dumpSourceLoc (getSourceLoc ());
185+ printSourceLoc (getSourceLoc (), llvm::dbgs ());
186186 }
187187
188188 if (isAutoGenerated ()) llvm::dbgs () << " :auto" ;
@@ -191,7 +191,7 @@ void SILLocation::dump() const {
191191 if (isSILFile ()) llvm::dbgs () << " :sil" ;
192192 if (hasASTNodeForDebugging ()) {
193193 llvm::dbgs () << " :debug[" ;
194- dumpSourceLoc (getSourceLocForDebugging ());
194+ printSourceLoc (getSourceLocForDebugging (), llvm::dbgs ());
195195 llvm::dbgs () << " ]\n " ;
196196 }
197197}
@@ -206,6 +206,18 @@ void SILLocation::print(raw_ostream &OS, const SourceManager &SM) const {
206206 }
207207}
208208
209+ void SILLocation::print (raw_ostream &OS) const {
210+ if (isNull ()) {
211+ OS << " <no loc>" ;
212+ } else if (isFilenameAndLocation ()) {
213+ getFilenameAndLocation ()->print (OS);
214+ } else if (DeclContext *dc = getAsDeclContext ()){
215+ getSourceLoc ().print (OS, dc->getASTContext ().SourceMgr );
216+ } else {
217+ printSourceLoc (getSourceLoc (), OS);
218+ }
219+ }
220+
209221RegularLocation::RegularLocation (Stmt *S, Pattern *P, SILModule &Module) :
210222 SILLocation(new (Module) ExtendedASTNodeLoc(S, P), RegularKind) {}
211223
0 commit comments