From becf8886d10c41a4605c5e66cd806492eb8b864c Mon Sep 17 00:00:00 2001
From: Ted Kremenek <kremenek@apple.com>
Date: Thu, 26 Mar 2009 21:48:17 +0000
Subject: [PATCH] Implement PathDiagnosticLocation::asRange() and
 PathDiagnosticLocation::asStmt().

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67777 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/clang/Analysis/PathDiagnostic.h |  2 +-
 lib/Analysis/PathDiagnostic.cpp         | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/include/clang/Analysis/PathDiagnostic.h b/include/clang/Analysis/PathDiagnostic.h
index f647be9d6d..1481e25bbd 100644
--- a/include/clang/Analysis/PathDiagnostic.h
+++ b/include/clang/Analysis/PathDiagnostic.h
@@ -67,7 +67,7 @@ public:
     
   FullSourceLoc asLocation() const;
   SourceRange asRange() const;
-  const Stmt *asStmt() const;
+  const Stmt *asStmt() const { return S ? S : 0; }
 };
 
 class PathDiagnostic {
diff --git a/lib/Analysis/PathDiagnostic.cpp b/lib/Analysis/PathDiagnostic.cpp
index 1441088e54..dd9a0a8f46 100644
--- a/lib/Analysis/PathDiagnostic.cpp
+++ b/lib/Analysis/PathDiagnostic.cpp
@@ -152,3 +152,18 @@ FullSourceLoc PathDiagnosticLocation::asLocation() const {
   
   return FullSourceLoc(R.getBegin(), const_cast<SourceManager&>(SM));
 }
+
+SourceRange PathDiagnosticLocation::asRange() const {
+  // Note that we want a 'switch' here so that the compiler can warn us in
+  // case we add more cases.
+  switch (K) {
+    case SingleLoc:
+    case Range:
+      break;
+    case Statement:
+      return S->getSourceRange();
+  }
+  
+  return R;
+}
+
-- 
2.40.0