[cfe-commits] r158732 - in /cfe/trunk: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp lib/Lex/Preprocessor.cpp lib/Parse/ParseAST.cpp

Meador Inge meadori at codesourcery.com
Tue Jun 19 11:17:30 PDT 2012


Author: meadori
Date: Tue Jun 19 13:17:30 2012
New Revision: 158732

URL: http://llvm.org/viewvc/llvm-project?rev=158732&view=rev
Log:
Revert predefined decl tracking.

r158085 added some logic to track predefined declarations.  The main reason we
had predefined declarations in the input was because the __builtin_va_list
declarations were injected into the preprocessor input.  As of r158592 we 
explicitly build the __builtin_va_list declarations.  Therefore the predefined
decl tracking is no longer needed.

Modified:
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/lib/Basic/SourceManager.cpp
    cfe/trunk/lib/Lex/Preprocessor.cpp
    cfe/trunk/lib/Parse/ParseAST.cpp

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=158732&r1=158731&r2=158732&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Tue Jun 19 13:17:30 2012
@@ -591,9 +591,6 @@
   /// \brief The file ID for the precompiled preamble there is one.
   FileID PreambleFileID;
 
-  /// \brief The file ID for the preprocessor's predefines.
-  FileID PredefinesFileID;
-
   // Statistics for -print-stats.
   mutable unsigned NumLinearScans, NumBinaryProbes;
 
@@ -638,14 +635,6 @@
     MainFileID = createFileIDForMemBuffer(Buffer);
     return MainFileID;
   }
-  
-  /// \brief Create the FileID for a memory buffer that contains the
-  /// preprocessor's predefines.
-  FileID createPredefinesFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer) {
-    assert(PredefinesFileID.isInvalid() && "PredefinesFileID already set!");
-    PredefinesFileID = createFileIDForMemBuffer(Buffer);
-    return PredefinesFileID;
-  }
 
   //===--------------------------------------------------------------------===//
   // MainFileID creation and querying methods.
@@ -654,9 +643,6 @@
   /// getMainFileID - Returns the FileID of the main source file.
   FileID getMainFileID() const { return MainFileID; }
 
-  /// \brief Returns the FileID of the preprocessor predefines buffer.
-  FileID getPredefinesFileID() const { return PredefinesFileID; }
-
   /// createMainFileID - Create the FileID for the main source file.
   FileID createMainFileID(const FileEntry *SourceFile, 
                           SrcMgr::CharacteristicKind Kind = SrcMgr::C_User) {
@@ -1138,12 +1124,6 @@
     return getFileID(Loc) == getMainFileID();
   }
 
-  /// isFromPredefines - Returns true if the provided SourceLocation is
-  ///   within the processor's predefines buffer.
-  bool isFromPredefines(SourceLocation Loc) const {
-    return getFileID(Loc) == getPredefinesFileID();
-  }
-
   /// isInSystemHeader - Returns if a SourceLocation is in a system header.
   bool isInSystemHeader(SourceLocation Loc) const {
     return getFileCharacteristic(Loc) != SrcMgr::C_User;

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=158732&r1=158731&r2=158732&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue Jun 19 13:17:30 2012
@@ -407,7 +407,6 @@
 
 void SourceManager::clearIDTables() {
   MainFileID = FileID();
-  PredefinesFileID = FileID();
   LocalSLocEntryTable.clear();
   LoadedSLocEntryTable.clear();
   SLocEntryLoaded.clear();

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=158732&r1=158731&r2=158732&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Tue Jun 19 13:17:30 2012
@@ -427,7 +427,7 @@
   llvm::MemoryBuffer *SB =
     llvm::MemoryBuffer::getMemBufferCopy(Predefines, "<built-in>");
   assert(SB && "Cannot create predefined source buffer");
-  FileID FID = SourceMgr.createPredefinesFileIDForMemBuffer(SB);
+  FileID FID = SourceMgr.createFileIDForMemBuffer(SB);
   assert(!FID.isInvalid() && "Could not create FileID for predefines?");
 
   // Start parsing the predefines.

Modified: cfe/trunk/lib/Parse/ParseAST.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseAST.cpp?rev=158732&r1=158731&r2=158732&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseAST.cpp (original)
+++ cfe/trunk/lib/Parse/ParseAST.cpp Tue Jun 19 13:17:30 2012
@@ -83,46 +83,24 @@
   // declaration. C++ doesn't have this restriction. We also don't want to
   // complain if we have a precompiled header, although technically if the PCH
   // is empty we should still emit the (pedantic) diagnostic.
-  bool WarnForEmptyTU = !S.getLangOpts().CPlusPlus;
-  if (ExternalASTSource *External = S.getASTContext().getExternalSource()) {
-    External->StartTranslationUnit(Consumer);
-    WarnForEmptyTU = false;
-  }
-
-  // Clang's predefines contain top-level declarations for things like va_list,
-  // making it hard to tell if the /user's/ translation unit has at least one
-  // top-level declaration. So we parse cautiously, looking for a declaration
-  // that doesn't come from our predefines.
-  // Note that ParseTopLevelDecl returns 'true' at EOF.
-  SourceManager &SM = S.getSourceManager();
   Parser::DeclGroupPtrTy ADecl;
-  while (WarnForEmptyTU && !P.ParseTopLevelDecl(ADecl)) {
-    if (ADecl) {
-      if (!Consumer->HandleTopLevelDecl(ADecl.get()))
-        return;
-      if (DeclGroupRef::iterator FirstDecl = ADecl.get().begin()) {
-        SourceLocation DeclLoc = (*FirstDecl)->getLocation();
-        WarnForEmptyTU = SM.isFromPredefines(DeclLoc);
-      }
-    }
-  }
+  ExternalASTSource *External = S.getASTContext().getExternalSource();
+  if (External)
+    External->StartTranslationUnit(Consumer);
 
-  // If we ended up seeing EOF before any top-level declarations, emit our
-  // diagnostic. Otherwise, parse the rest of the file normally.
-  if (WarnForEmptyTU) {
-    P.Diag(diag::ext_empty_translation_unit);
+  if (P.ParseTopLevelDecl(ADecl)) {
+    if (!External && !S.getLangOpts().CPlusPlus)
+      P.Diag(diag::ext_empty_translation_unit);
   } else {
-    while (!P.ParseTopLevelDecl(ADecl)) {  // Not end of file.
+    do {
       // If we got a null return and something *was* parsed, ignore it.  This
       // is due to a top-level semicolon, an action override, or a parse error
       // skipping something.
-      if (ADecl) {
-        if (!Consumer->HandleTopLevelDecl(ADecl.get())) 
-          return;
-      }
-    };
+      if (ADecl && !Consumer->HandleTopLevelDecl(ADecl.get()))
+	return;
+    } while (!P.ParseTopLevelDecl(ADecl));
   }
-  
+
   // Process any TopLevelDecls generated by #pragma weak.
   for (SmallVector<Decl*,2>::iterator
        I = S.WeakTopLevelDecls().begin(),





More information about the cfe-commits mailing list