Yesterday, I simplified how we stream top-level decls.

After a discussion with Ted, we both came to the conclusion that adding a "HandleTopLevelDeclaration" hook to ASConsumer is far more elegant. The default implementation of HandleTopLevelDeclaration will be responsible for iterating over the ScopedDecl (which has a chain of the decls:-).

TODO: Once Ted adds HandleTopLevelDeclaration, make sure TagDecls are chainged appropriately...



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44445 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/ASTStreamer.cpp b/Sema/ASTStreamer.cpp
index 5a372da..b51874c 100644
--- a/Sema/ASTStreamer.cpp
+++ b/Sema/ASTStreamer.cpp
@@ -24,10 +24,9 @@
 namespace {
   class ASTStreamer {
     Parser P;
-    std::vector<Decl*> TopLevelDeclList;
   public:
     ASTStreamer(Preprocessor &pp, ASTContext &ctxt, unsigned MainFileID)
-      : P(pp, *new Sema(pp, ctxt, TopLevelDeclList)) {
+      : P(pp, *new Sema(pp, ctxt)) {
       pp.EnterMainSourceFile(MainFileID);
       
       // Initialize the parser.
@@ -51,30 +50,14 @@
 Decl *ASTStreamer::ReadTopLevelDecl() {
   Parser::DeclTy *Result;
   
-  /// If the previous time through we read something like 'int X, Y', return
-  /// the next declarator.
-  if (!TopLevelDeclList.empty()) {
-    Result = TopLevelDeclList.back();
-    TopLevelDeclList.pop_back();
-    return static_cast<Decl*>(Result);
-  }
-  
   do {
-    if (P.ParseTopLevelDecl())
+    if (P.ParseTopLevelDecl(Result))
       return 0;  // End of file.
     
     // If we got a null return and something *was* parsed, try again.  This
     // is due to a top-level semicolon, an action override, or a parse error
     // skipping something.
-  } while (TopLevelDeclList.size() == 0);
-  
-  // If we parsed a declspec with multiple declarators, reverse the list and
-  // return the first one.
-  if (TopLevelDeclList.size() > 1)
-    std::reverse(TopLevelDeclList.begin(), TopLevelDeclList.end());
-
-  Result = TopLevelDeclList.back();
-  TopLevelDeclList.pop_back();
+  } while (Result == 0);
   
   return static_cast<Decl*>(Result);
 }