]> granicus.if.org Git - clang/commitdiff
Make some methods const, add some helpers to FullSourceLoc,
authorChris Lattner <sabre@nondot.org>
Mon, 29 Sep 2008 21:46:13 +0000 (21:46 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 29 Sep 2008 21:46:13 +0000 (21:46 +0000)
and add a dump method to FullSourceLoc!  Patch by Nico Weber!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56806 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/SourceLocation.h
lib/Basic/SourceLocation.cpp

index 145e1c8487073e73a285d21b13737ee7d7d2a50f..ee6cc145fe7e0bba9ef3dfe61a021b3174573c1c 100644 (file)
@@ -87,7 +87,7 @@ public:
   static bool isValidMacroPhysOffs(int Val) {
     if (Val >= 0)
       return Val < (1 << (MacroPhysOffsBits-1));
-    return -Val < (1 << (MacroPhysOffsBits-1));
+    return -Val <= (1 << (MacroPhysOffsBits-1));
   }
   
   static SourceLocation getMacroLoc(unsigned MacroID, int PhysOffs){
@@ -231,8 +231,9 @@ public:
     return *SrcMgr;
   }
   
-  FullSourceLoc getLogicalLoc();
-  FullSourceLoc getIncludeLoc();
+  FullSourceLoc getLogicalLoc() const;
+  FullSourceLoc getPhysicalLoc() const;
+  FullSourceLoc getIncludeLoc() const;
 
   unsigned getLineNumber() const;
   unsigned getColumnNumber() const;
@@ -240,6 +241,9 @@ public:
   unsigned getLogicalLineNumber() const;
   unsigned getLogicalColumnNumber() const;
 
+  unsigned getPhysicalLineNumber() const;
+  unsigned getPhysicalColumnNumber() const;
+
   const char *getCharacterData() const;
   
   const llvm::MemoryBuffer* getBuffer() const;
@@ -260,6 +264,10 @@ public:
   bool operator!=(const FullSourceLoc& RHS) const {
     return SrcMgr != RHS.SrcMgr || Loc != RHS.Loc;
   }    
+
+  /// Prints information about this FullSourceLoc to stderr. Useful for
+  ///  debugging.
+  void dump() const;
 };
 
 }  // end namespace clang
index 12a49623c6c4c1802b0b2254198a9c30495402e8..5236bfaffba2bb461400ae15141885e1d7d70b94 100644 (file)
@@ -16,7 +16,6 @@
 #include "clang/Basic/SourceManager.h"
 #include "llvm/Bitcode/Serialize.h"
 #include "llvm/Bitcode/Deserialize.h"
-
 using namespace clang;
 
 void SourceLocation::Emit(llvm::Serializer& S) const {
@@ -38,14 +37,19 @@ SourceRange SourceRange::ReadVal(llvm::Deserializer& D) {
   return SourceRange(A,B);
 }
 
-FullSourceLoc FullSourceLoc::getLogicalLoc() {
+FullSourceLoc FullSourceLoc::getLogicalLoc() const {
+  assert (isValid());
+  return FullSourceLoc(SrcMgr->getLogicalLoc(Loc), *SrcMgr);
+}
+
+FullSourceLoc FullSourceLoc::getPhysicalLoc() const {
   assert (isValid());
-  return FullSourceLoc(SrcMgr->getLogicalLoc(Loc),*SrcMgr);
+  return FullSourceLoc(SrcMgr->getPhysicalLoc(Loc), *SrcMgr);
 }
 
-FullSourceLoc FullSourceLoc::getIncludeLoc() {
+FullSourceLoc FullSourceLoc::getIncludeLoc() const {
   assert (isValid());
-  return FullSourceLoc(SrcMgr->getIncludeLoc(Loc),*SrcMgr);
+  return FullSourceLoc(SrcMgr->getIncludeLoc(Loc), *SrcMgr);
 }
 
 unsigned FullSourceLoc::getLineNumber() const {
@@ -69,6 +73,16 @@ unsigned FullSourceLoc::getLogicalColumnNumber() const {
   return SrcMgr->getLogicalColumnNumber(Loc);
 }
 
+unsigned FullSourceLoc::getPhysicalLineNumber() const {
+  assert (isValid());
+  return SrcMgr->getPhysicalLineNumber(Loc);
+}
+
+unsigned FullSourceLoc::getPhysicalColumnNumber() const {
+  assert (isValid());
+  return SrcMgr->getPhysicalColumnNumber(Loc);
+}
+
 const char* FullSourceLoc::getSourceName() const {
   assert (isValid());
   return SrcMgr->getSourceName(Loc);
@@ -98,3 +112,23 @@ const llvm::MemoryBuffer* FullSourceLoc::getBuffer() const {
 unsigned FullSourceLoc::getCanonicalFileID() const {
   return SrcMgr->getCanonicalFileID(Loc);
 }
+
+void FullSourceLoc::dump() const {
+  if (!isValid()) {
+    fprintf(stderr, "Invalid Loc\n");
+    return;
+  }
+  
+  if (isFileID()) {
+    // The logical and physical pos is identical for file locs.
+    fprintf(stderr, "File Loc from '%s': %d: %d\n",
+            getSourceName(), getLogicalLineNumber(),
+            getLogicalColumnNumber());
+  } else {
+    fprintf(stderr, "Macro Loc (\n  Physical: ");
+    getPhysicalLoc().dump();
+    fprintf(stderr, "  Logical: ");
+    getLogicalLoc().dump();
+    fprintf(stderr, ")\n");
+  }
+}