zcov: / include/clang/Basic/SourceManagerInternals.h


Files: 1 Branches Taken: 50.0% 1 / 2
Generated: 2010-02-10 01:31 Branches Executed: 100.0% 2 / 2
Line Coverage: 77.3% 17 / 22


Programs: 5 Runs 8933


       1                 : //===--- SourceManagerInternals.h - SourceManager Internals -----*- C++ -*-===//
       2                 : //
       3                 : //                     The LLVM Compiler Infrastructure
       4                 : //
       5                 : // This file is distributed under the University of Illinois Open Source
       6                 : // License. See LICENSE.TXT for details.
       7                 : //
       8                 : //===----------------------------------------------------------------------===//
       9                 : //
      10                 : //  This file defines the implementation details of the SourceManager
      11                 : //  class.
      12                 : //
      13                 : //===----------------------------------------------------------------------===//
      14                 : 
      15                 : #ifndef LLVM_CLANG_SOURCEMANAGER_INTERNALS_H
      16                 : #define LLVM_CLANG_SOURCEMANAGER_INTERNALS_H
      17                 : 
      18                 : #include "clang/Basic/SourceManager.h"
      19                 : #include "llvm/ADT/StringMap.h"
      20                 : #include <map>
      21                 : 
      22                 : namespace clang {
      23                 : 
      24                 : //===----------------------------------------------------------------------===//
      25                 : // Line Table Implementation
      26                 : //===----------------------------------------------------------------------===//
      27                 : 
      28                 : struct LineEntry {
      29                 :   /// FileOffset - The offset in this file that the line entry occurs at.
      30                 :   unsigned FileOffset;
      31                 : 
      32                 :   /// LineNo - The presumed line number of this line entry: #line 4.
      33                 :   unsigned LineNo;
      34                 : 
      35                 :   /// FilenameID - The ID of the filename identified by this line entry:
      36                 :   /// #line 4 "foo.c".  This is -1 if not specified.
      37                 :   int FilenameID;
      38                 : 
      39                 :   /// Flags - Set the 0 if no flags, 1 if a system header,
      40                 :   SrcMgr::CharacteristicKind FileKind;
      41                 : 
      42                 :   /// IncludeOffset - This is the offset of the virtual include stack location,
      43                 :   /// which is manipulated by GNU linemarker directives.  If this is 0 then
      44                 :   /// there is no virtual #includer.
      45                 :   unsigned IncludeOffset;
      46                 : 
      47                 :   static LineEntry get(unsigned Offs, unsigned Line, int Filename,
      48                 :                        SrcMgr::CharacteristicKind FileKind,
      49             7764:                        unsigned IncludeOffset) {
      50                 :     LineEntry E;
      51             7764:     E.FileOffset = Offs;
      52             7764:     E.LineNo = Line;
      53             7764:     E.FilenameID = Filename;
      54             7764:     E.FileKind = FileKind;
      55             7764:     E.IncludeOffset = IncludeOffset;
      56                 :     return E;
      57                 :   }
      58                 : };
      59                 : 
      60                 : // needed for FindNearestLineEntry (upper_bound of LineEntry)
      61                 : inline bool operator<(const LineEntry &lhs, const LineEntry &rhs) {
      62                 :   // FIXME: should check the other field?
      63                 :   return lhs.FileOffset < rhs.FileOffset;
      64                 : }
      65                 : 
      66                 : inline bool operator<(const LineEntry &E, unsigned Offset) {
      67                 :   return E.FileOffset < Offset;
      68                 : }
      69                 : 
      70             5143: inline bool operator<(unsigned Offset, const LineEntry &E) {
      71             5143:   return Offset < E.FileOffset;
      72                 : }
      73                 : 
      74                 : /// LineTableInfo - This class is used to hold and unique data used to
      75                 : /// represent #line information.
      76                 : class LineTableInfo {
      77                 :   /// FilenameIDs - This map is used to assign unique IDs to filenames in
      78                 :   /// #line directives.  This allows us to unique the filenames that
      79                 :   /// frequently reoccur and reference them with indices.  FilenameIDs holds
      80                 :   /// the mapping from string -> ID, and FilenamesByID holds the mapping of ID
      81                 :   /// to string.
      82                 :   llvm::StringMap<unsigned, llvm::BumpPtrAllocator> FilenameIDs;
      83                 :   std::vector<llvm::StringMapEntry<unsigned>*> FilenamesByID;
      84                 : 
      85                 :   /// LineEntries - This is a map from FileIDs to a list of line entries (sorted
      86                 :   /// by the offset they occur in the file.
      87                 :   std::map<unsigned, std::vector<LineEntry> > LineEntries;
      88                 : public:
      89             2528:   LineTableInfo() {
      90             2528:   }
      91                 : 
      92                0:   void clear() {
      93                0:     FilenameIDs.clear();
      94                0:     FilenamesByID.clear();
      95                0:     LineEntries.clear();
      96                0:   }
      97                 : 
      98             2525:   ~LineTableInfo() {}
      99                 : 
     100                 :   unsigned getLineTableFilenameID(const char *Ptr, unsigned Len);
     101             4520:   const char *getFilename(unsigned ID) const {
                     4520: branch 1 taken
                        0: branch 2 not taken
     102             4520:     assert(ID < FilenamesByID.size() && "Invalid FilenameID");
     103             4520:     return FilenamesByID[ID]->getKeyData();
     104                 :   }
     105               88:   unsigned getNumFilenames() const { return FilenamesByID.size(); }
     106                 : 
     107                 :   void AddLineNote(unsigned FID, unsigned Offset,
     108                 :                    unsigned LineNo, int FilenameID);
     109                 :   void AddLineNote(unsigned FID, unsigned Offset,
     110                 :                    unsigned LineNo, int FilenameID,
     111                 :                    unsigned EntryExit, SrcMgr::CharacteristicKind FileKind);
     112                 : 
     113                 : 
     114                 :   /// FindNearestLineEntry - Find the line entry nearest to FID that is before
     115                 :   /// it.  If there is no line entry before Offset in FID, return null.
     116                 :   const LineEntry *FindNearestLineEntry(unsigned FID, unsigned Offset);
     117                 : 
     118                 :   // Low-level access
     119                 :   typedef std::map<unsigned, std::vector<LineEntry> >::iterator iterator;
     120               44:   iterator begin() { return LineEntries.begin(); }
     121               44:   iterator end() { return LineEntries.end(); }
     122                 : 
     123                 :   /// \brief Add a new line entry that has already been encoded into
     124                 :   /// the internal representation of the line table.
     125                 :   void AddEntry(unsigned FID, const std::vector<LineEntry> &Entries);
     126                 : };
     127                 : 
     128                 : } // end namespace clang
     129                 : 
     130                 : #endif

Generated: 2010-02-10 01:31 by zcov