Introduce a new PresumedLoc class to represent the concept of a location
as reported to the user and as manipulated by #line.  This is what __FILE__,
__INCLUDE_LEVEL__, diagnostics and other things should follow (but not 
dependency generation!).  

This patch also includes several cleanups along the way: 

- SourceLocation now has a dump method, and several other places 
  that did similar things now use it.
- I cleaned up some code in AnalysisConsumer, but it should probably be
  simplified further now that NamedDecl is better.
- TextDiagnosticPrinter is now simplified and cleaned up a bit.

This patch is a prerequisite for #line, but does not actually provide 
any #line functionality.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63098 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/StmtDumper.cpp b/lib/AST/StmtDumper.cpp
index 0a7de35..83313ed 100644
--- a/lib/AST/StmtDumper.cpp
+++ b/lib/AST/StmtDumper.cpp
@@ -153,21 +153,26 @@
 
 void StmtDumper::DumpLocation(SourceLocation Loc) {
   SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
+  
+  if (SpellingLoc.isInvalid()) {
+    fprintf(stderr, "<invalid sloc>");
+    return;
+  }
 
   // The general format we print out is filename:line:col, but we drop pieces
   // that haven't changed since the last loc printed.
-  const char *Filename = SM->getSourceName(SpellingLoc);
-  unsigned LineNo = SM->getLineNumber(SpellingLoc);
-  unsigned ColNo = SM->getColumnNumber(SpellingLoc);
-  if (strcmp(Filename, LastLocFilename) != 0) {
-    fprintf(stderr, "%s:%u:%u", Filename, LineNo, ColNo);
-    LastLocFilename = Filename;
-    LastLocLine = LineNo;
-  } else if (LineNo != LastLocLine) {
-    fprintf(stderr, "line:%u:%u", LineNo, ColNo);
-    LastLocLine = LineNo;
+  PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
+
+  if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
+    fprintf(stderr, "%s:%u:%u", PLoc.getFilename(), PLoc.getLine(),
+            PLoc.getColumn());
+    LastLocFilename = PLoc.getFilename();
+    LastLocLine = PLoc.getLine();
+  } else if (PLoc.getLine() != LastLocLine) {
+    fprintf(stderr, "line:%u:%u", PLoc.getLine(), PLoc.getColumn());
+    LastLocLine = PLoc.getLine();
   } else {
-    fprintf(stderr, "col:%u", ColNo);
+    fprintf(stderr, "col:%u", PLoc.getColumn());
   }
 }