[cfe-commits] r63719 - in /cfe/trunk: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp lib/Lex/PPDirectives.cpp

Chris Lattner sabre at nondot.org
Tue Feb 3 21:21:58 PST 2009


Author: lattner
Date: Tue Feb  3 23:21:58 2009
New Revision: 63719

URL: http://llvm.org/viewvc/llvm-project?rev=63719&view=rev
Log:
propagate linemarker flags down into the the line table, currently
ignoring include stack push/pop info though.

Modified:
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/lib/Basic/SourceManager.cpp
    cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=63719&r1=63718&r2=63719&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Tue Feb  3 23:21:58 2009
@@ -541,6 +541,9 @@
   /// specified by Loc.  If FilenameID is -1, it is considered to be
   /// unspecified.
   void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID);
+  void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID,
+                   bool IsFileEntry, bool IsFileExit, 
+                   bool IsSystemHeader, bool IsExternCHeader);
   
   //===--------------------------------------------------------------------===//
   // Other miscellaneous methods.

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

==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue Feb  3 23:21:58 2009
@@ -65,13 +65,19 @@
 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;
   
-  static LineEntry get(unsigned Offs, unsigned Line, int Filename) {
+  /// Flags - Set the 0 if no flags, 1 if a system header, 
+  SrcMgr::CharacteristicKind FileKind;
+  
+  static LineEntry get(unsigned Offs, unsigned Line, int Filename,
+                       SrcMgr::CharacteristicKind FileKind) {
     LineEntry E;
     E.FileOffset = Offs;
     E.LineNo = Line;
@@ -121,6 +127,10 @@
   
   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.
@@ -152,14 +162,45 @@
   assert((Entries.empty() || Entries.back().FileOffset < Offset) &&
          "Adding line entries out of order!");
   
-  // If this is a '#line 4' after '#line 42 "foo.h"', make sure to remember that
-  // we are still in "foo.h".
-  if (FilenameID == -1 && !Entries.empty())
-    FilenameID = Entries.back().FilenameID;
+  SrcMgr::CharacteristicKind Kind = SrcMgr::C_User;
+  
+  if (!Entries.empty()) {
+    // If this is a '#line 4' after '#line 42 "foo.h"', make sure to remember
+    // that we are still in "foo.h".
+    if (FilenameID == -1)
+      FilenameID = Entries.back().FilenameID;
+    
+    // If we are after a line marker that switched us to system header mode,
+    // preserve it.
+    Kind = Entries.back().FileKind;
+  }
+  
+  Entries.push_back(LineEntry::get(Offset, LineNo, FilenameID, Kind));
+}
+
+/// AddLineNote This is the same as the previous version of AddLineNote, but is
+/// used for GNU line markers.  If EntryExit is 0, then this doesn't change the
+/// presumed #include stack.  If it is 1, this is a file entry, if it is 2 then
+/// this is a file exit.  FileKind specifies whether this is a system header or
+/// extern C system header.
+void LineTableInfo::AddLineNote(unsigned FID, unsigned Offset,
+                                unsigned LineNo, int FilenameID,
+                                unsigned EntryExit,
+                                SrcMgr::CharacteristicKind FileKind) {
+  assert(FilenameID != -1 && "Unspecified filename should use other accessor");
+  
+  std::vector<LineEntry> &Entries = LineEntries[FID];
+  
+  assert((Entries.empty() || Entries.back().FileOffset < Offset) &&
+         "Adding line entries out of order!");
+
+  
+  // TODO: Handle EntryExit.
   
-  Entries.push_back(LineEntry::get(Offset, LineNo, FilenameID));
+  Entries.push_back(LineEntry::get(Offset, LineNo, FilenameID, 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 *LineTableInfo::FindNearestLineEntry(unsigned FID, 
@@ -206,6 +247,46 @@
   LineTable->AddLineNote(LocInfo.first.ID, LocInfo.second, LineNo, FilenameID);
 }
 
+/// AddLineNote - Add a GNU line marker to the line table.
+void SourceManager::AddLineNote(SourceLocation Loc, unsigned LineNo,
+                                int FilenameID, bool IsFileEntry,
+                                bool IsFileExit, bool IsSystemHeader,
+                                bool IsExternCHeader) {
+  // If there is no filename and no flags, this is treated just like a #line,
+  // which does not change the flags of the previous line marker.
+  if (FilenameID == -1) {
+    assert(!IsFileEntry && !IsFileExit && !IsSystemHeader && !IsExternCHeader &&
+           "Can't set flags without setting the filename!");
+    return AddLineNote(Loc, LineNo, FilenameID);
+  }
+  
+  std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
+  const SrcMgr::FileInfo &FileInfo = getSLocEntry(LocInfo.first).getFile();
+  
+  // Remember that this file has #line directives now if it doesn't already.
+  const_cast<SrcMgr::FileInfo&>(FileInfo).setHasLineDirectives();
+  
+  if (LineTable == 0)
+    LineTable = new LineTableInfo();
+  
+  SrcMgr::CharacteristicKind FileKind;
+  if (IsExternCHeader)
+    FileKind = SrcMgr::C_ExternCSystem;
+  else if (IsSystemHeader)
+    FileKind = SrcMgr::C_System;
+  else
+    FileKind = SrcMgr::C_User;
+  
+  unsigned EntryExit = 0;
+  if (IsFileEntry)
+    EntryExit = 1;
+  else if (IsFileExit)
+    EntryExit = 2;
+  
+  LineTable->AddLineNote(LocInfo.first.ID, LocInfo.second, LineNo, FilenameID,
+                         EntryExit, FileKind);
+}
+
 
 //===----------------------------------------------------------------------===//
 // Private 'Create' methods.

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=63719&r1=63718&r2=63719&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Feb  3 23:21:58 2009
@@ -693,7 +693,7 @@
   
   PP.Lex(FlagTok);
   if (FlagTok.is(tok::eom)) return false;
-  if (GetLineValue(FlagTok, FlagVal, diag::err_pp_linemarker_invalid_flag,PP))
+  if (GetLineValue(FlagTok, FlagVal, diag::err_pp_linemarker_invalid_flag, PP))
     return true;
 
   // We must have 4 if there is yet another flag.
@@ -761,9 +761,11 @@
                             IsSystemHeader, IsExternCHeader, *this))
       return;
   }
-  
-  // FIXME: do something with the #line flag info.
-  SourceMgr.AddLineNote(DigitTok.getLocation(), LineNo, FilenameID);
+
+  // Create a line note with this information.
+  SourceMgr.AddLineNote(DigitTok.getLocation(), LineNo, FilenameID,
+                        IsFileEntry, IsFileExit, 
+                        IsSystemHeader, IsExternCHeader);
 }
 
 





More information about the cfe-commits mailing list