[cfe-commits] r68960 - in /cfe/trunk: include/clang/Basic/SourceManagerInternals.h lib/Basic/SourceManager.cpp

Douglas Gregor dgregor at apple.com
Mon Apr 13 08:31:25 PDT 2009


Author: dgregor
Date: Mon Apr 13 10:31:25 2009
New Revision: 68960

URL: http://llvm.org/viewvc/llvm-project?rev=68960&view=rev
Log:
Factor the internals of SourceManager (specially, LineTableInfo) into a separate Internals header. No functionality change

Added:
    cfe/trunk/include/clang/Basic/SourceManagerInternals.h   (with props)
Modified:
    cfe/trunk/lib/Basic/SourceManager.cpp

Added: cfe/trunk/include/clang/Basic/SourceManagerInternals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManagerInternals.h?rev=68960&view=auto

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManagerInternals.h (added)
+++ cfe/trunk/include/clang/Basic/SourceManagerInternals.h Mon Apr 13 10:31:25 2009
@@ -0,0 +1,120 @@
+//===--- SourceManagerInternals.h - SourceManager Internals -----*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines the implementation details of the SourceManager
+//  class.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_SOURCEMANAGER_INTERNALS_H
+#define LLVM_CLANG_SOURCEMANAGER_INTERNALS_H
+
+#include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/StringMap.h"
+#include <map>
+
+namespace clang {
+
+//===----------------------------------------------------------------------===//
+// Line Table Implementation
+//===----------------------------------------------------------------------===//
+
+struct LineEntry {
+  /// FileOffset - The offset in this file that the line entry occurs at.
+  unsigned FileOffset;
+  
+  /// LineNo - The presumed line number of this line entry: #line 4.
+  unsigned LineNo;
+  
+  /// FilenameID - The ID of the filename identified by this line entry:
+  /// #line 4 "foo.c".  This is -1 if not specified.
+  int FilenameID;
+  
+  /// Flags - Set the 0 if no flags, 1 if a system header, 
+  SrcMgr::CharacteristicKind FileKind;
+  
+  /// IncludeOffset - This is the offset of the virtual include stack location,
+  /// which is manipulated by GNU linemarker directives.  If this is 0 then
+  /// there is no virtual #includer.
+  unsigned IncludeOffset;
+  
+  static LineEntry get(unsigned Offs, unsigned Line, int Filename,
+                       SrcMgr::CharacteristicKind FileKind,
+                       unsigned IncludeOffset) {
+    LineEntry E;
+    E.FileOffset = Offs;
+    E.LineNo = Line;
+    E.FilenameID = Filename;
+    E.FileKind = FileKind;
+    E.IncludeOffset = IncludeOffset;
+    return E;
+  }
+};
+
+// needed for FindNearestLineEntry (upper_bound of LineEntry)
+inline bool operator<(const LineEntry &lhs, const LineEntry &rhs) {
+  // FIXME: should check the other field?
+  return lhs.FileOffset < rhs.FileOffset;
+}
+
+inline bool operator<(const LineEntry &E, unsigned Offset) {
+  return E.FileOffset < Offset;
+}
+
+inline bool operator<(unsigned Offset, const LineEntry &E) {
+  return Offset < E.FileOffset;
+}
+  
+/// LineTableInfo - This class is used to hold and unique data used to
+/// represent #line information.
+class LineTableInfo {
+  /// FilenameIDs - This map is used to assign unique IDs to filenames in
+  /// #line directives.  This allows us to unique the filenames that
+  /// frequently reoccur and reference them with indices.  FilenameIDs holds
+  /// the mapping from string -> ID, and FilenamesByID holds the mapping of ID
+  /// to string.
+  llvm::StringMap<unsigned, llvm::BumpPtrAllocator> FilenameIDs;
+  std::vector<llvm::StringMapEntry<unsigned>*> FilenamesByID;
+  
+  /// LineEntries - This is a map from FileIDs to a list of line entries (sorted
+  /// by the offset they occur in the file.
+  std::map<unsigned, std::vector<LineEntry> > LineEntries;
+public:
+  LineTableInfo() {
+  }
+  
+  void clear() {
+    FilenameIDs.clear();
+    FilenamesByID.clear();
+    LineEntries.clear();
+  }
+  
+  ~LineTableInfo() {}
+  
+  unsigned getLineTableFilenameID(const char *Ptr, unsigned Len);
+  const char *getFilename(unsigned ID) const {
+    assert(ID < FilenamesByID.size() && "Invalid FilenameID");
+    return FilenamesByID[ID]->getKeyData();
+  }
+  
+  void AddLineNote(unsigned FID, unsigned Offset,
+                   unsigned LineNo, int FilenameID);
+  void AddLineNote(unsigned FID, unsigned Offset,
+                   unsigned LineNo, int FilenameID,
+                   unsigned EntryExit, SrcMgr::CharacteristicKind FileKind);
+
+  
+  /// FindNearestLineEntry - Find the line entry nearest to FID that is before
+  /// it.  If there is no line entry before Offset in FID, return null.
+  const LineEntry *FindNearestLineEntry(unsigned FID, unsigned Offset);
+};
+
+} // end namespace clang
+
+#endif

Propchange: cfe/trunk/include/clang/Basic/SourceManagerInternals.h

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/include/clang/Basic/SourceManagerInternals.h

------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/include/clang/Basic/SourceManagerInternals.h

------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=68960&r1=68959&r2=68960&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Mon Apr 13 10:31:25 2009
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Basic/SourceManager.h"
+#include "clang/Basic/SourceManagerInternals.h"
 #include "clang/Basic/FileManager.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -57,102 +58,6 @@
   return Buffer;
 }
 
-//===----------------------------------------------------------------------===//
-// Line Table Implementation
-//===----------------------------------------------------------------------===//
-
-namespace clang {
-struct LineEntry {
-  /// FileOffset - The offset in this file that the line entry occurs at.
-  unsigned FileOffset;
-  
-  /// LineNo - The presumed line number of this line entry: #line 4.
-  unsigned LineNo;
-  
-  /// FilenameID - The ID of the filename identified by this line entry:
-  /// #line 4 "foo.c".  This is -1 if not specified.
-  int FilenameID;
-  
-  /// Flags - Set the 0 if no flags, 1 if a system header, 
-  SrcMgr::CharacteristicKind FileKind;
-  
-  /// IncludeOffset - This is the offset of the virtual include stack location,
-  /// which is manipulated by GNU linemarker directives.  If this is 0 then
-  /// there is no virtual #includer.
-  unsigned IncludeOffset;
-  
-  static LineEntry get(unsigned Offs, unsigned Line, int Filename,
-                       SrcMgr::CharacteristicKind FileKind,
-                       unsigned IncludeOffset) {
-    LineEntry E;
-    E.FileOffset = Offs;
-    E.LineNo = Line;
-    E.FilenameID = Filename;
-    E.FileKind = FileKind;
-    E.IncludeOffset = IncludeOffset;
-    return E;
-  }
-};
-
-// needed for FindNearestLineEntry (upper_bound of LineEntry)
-inline bool operator<(const LineEntry &lhs, const LineEntry &rhs) {
-  // FIXME: should check the other field?
-  return lhs.FileOffset < rhs.FileOffset;
-}
-
-inline bool operator<(const LineEntry &E, unsigned Offset) {
-  return E.FileOffset < Offset;
-}
-
-inline bool operator<(unsigned Offset, const LineEntry &E) {
-  return Offset < E.FileOffset;
-}
-  
-/// LineTableInfo - This class is used to hold and unique data used to
-/// represent #line information.
-class LineTableInfo {
-  /// FilenameIDs - This map is used to assign unique IDs to filenames in
-  /// #line directives.  This allows us to unique the filenames that
-  /// frequently reoccur and reference them with indices.  FilenameIDs holds
-  /// the mapping from string -> ID, and FilenamesByID holds the mapping of ID
-  /// to string.
-  llvm::StringMap<unsigned, llvm::BumpPtrAllocator> FilenameIDs;
-  std::vector<llvm::StringMapEntry<unsigned>*> FilenamesByID;
-  
-  /// LineEntries - This is a map from FileIDs to a list of line entries (sorted
-  /// by the offset they occur in the file.
-  std::map<unsigned, std::vector<LineEntry> > LineEntries;
-public:
-  LineTableInfo() {
-  }
-  
-  void clear() {
-    FilenameIDs.clear();
-    FilenamesByID.clear();
-    LineEntries.clear();
-  }
-  
-  ~LineTableInfo() {}
-  
-  unsigned getLineTableFilenameID(const char *Ptr, unsigned Len);
-  const char *getFilename(unsigned ID) const {
-    assert(ID < FilenamesByID.size() && "Invalid FilenameID");
-    return FilenamesByID[ID]->getKeyData();
-  }
-  
-  void AddLineNote(unsigned FID, unsigned Offset,
-                   unsigned LineNo, int FilenameID);
-  void AddLineNote(unsigned FID, unsigned Offset,
-                   unsigned LineNo, int FilenameID,
-                   unsigned EntryExit, SrcMgr::CharacteristicKind FileKind);
-
-  
-  /// FindNearestLineEntry - Find the line entry nearest to FID that is before
-  /// it.  If there is no line entry before Offset in FID, return null.
-  const LineEntry *FindNearestLineEntry(unsigned FID, unsigned Offset);
-};
-} // namespace clang
-
 unsigned LineTableInfo::getLineTableFilenameID(const char *Ptr, unsigned Len) {
   // Look up the filename in the string table, returning the pre-existing value
   // if it exists.





More information about the cfe-commits mailing list