Propagate the ASTContext to various AST traversal and lookup functions.
No functionality change (really).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68726 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/clang-cc/ASTConsumers.cpp b/tools/clang-cc/ASTConsumers.cpp
index 1b5cdd3..74683e3 100644
--- a/tools/clang-cc/ASTConsumers.cpp
+++ b/tools/clang-cc/ASTConsumers.cpp
@@ -125,8 +125,10 @@
     Out << ";\n";
   } else if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
     Out << "enum " << ED->getNameAsString() << " {\n";
-    for (EnumDecl::enumerator_iterator E = ED->enumerator_begin(),
-                                    EEnd = ED->enumerator_end();
+    // FIXME: Shouldn't pass a NULL context
+    ASTContext *Context = 0;
+    for (EnumDecl::enumerator_iterator E = ED->enumerator_begin(*Context),
+                                    EEnd = ED->enumerator_end(*Context);
          E != EEnd; ++E)
       Out << "  " << (*E)->getNameAsString() << ",\n";
     Out << "};\n";
@@ -139,8 +141,10 @@
 
     Out << " {\n";
     ChangeIndent(1);
-    for (DeclContext::decl_iterator i = TD->decls_begin();
-         i != TD->decls_end();
+    // FIXME: Shouldn't pass a NULL context
+    ASTContext *Context = 0;
+    for (DeclContext::decl_iterator i = TD->decls_begin(*Context);
+         i != TD->decls_end(*Context);
          ++i)
       PrintDecl(*i);    
     ChangeIndent(-1);
@@ -198,8 +202,10 @@
 void DeclPrinter::Print(NamespaceDecl *NS) {
   Out << "namespace " << NS->getNameAsString() << " {\n";
   ChangeIndent(1);
-  for (DeclContext::decl_iterator i = NS->decls_begin();
-       i != NS->decls_end();
+  // FIXME: Shouldn't pass a NULL context
+  ASTContext *Context = 0;
+  for (DeclContext::decl_iterator i = NS->decls_begin(*Context);
+       i != NS->decls_end(*Context);
        ++i)
     PrintDecl(*i);    
   ChangeIndent(-1);
@@ -278,8 +284,10 @@
     ChangeIndent(1);
   }
 
-  for (LinkageSpecDecl::decl_iterator D = LS->decls_begin(), 
-                                   DEnd = LS->decls_end();
+  // FIXME: Should not use a NULL DeclContext!
+  ASTContext *Context = 0;
+  for (LinkageSpecDecl::decl_iterator D = LS->decls_begin(*Context), 
+                                   DEnd = LS->decls_end(*Context);
        D != DEnd; ++D)
     PrintDecl(*D);
 
@@ -389,16 +397,18 @@
     Out << "}\n";
   }
   
-  for (ObjCInterfaceDecl::prop_iterator I = OID->prop_begin(),
-       E = OID->prop_end(); I != E; ++I)
+  // FIXME: Should not use a NULL DeclContext!
+  ASTContext *Context = 0;
+  for (ObjCInterfaceDecl::prop_iterator I = OID->prop_begin(*Context),
+       E = OID->prop_end(*Context); I != E; ++I)
     PrintObjCPropertyDecl(*I);
   bool eol_needed = false;
-  for (ObjCInterfaceDecl::classmeth_iterator I = OID->classmeth_begin(),
-       E = OID->classmeth_end(); I != E; ++I)
+  for (ObjCInterfaceDecl::classmeth_iterator I = OID->classmeth_begin(*Context),
+       E = OID->classmeth_end(*Context); I != E; ++I)
     eol_needed = true, PrintObjCMethodDecl(*I);
   
-  for (ObjCInterfaceDecl::instmeth_iterator I = OID->instmeth_begin(),
-       E = OID->instmeth_end(); I != E; ++I)
+  for (ObjCInterfaceDecl::instmeth_iterator I = OID->instmeth_begin(*Context),
+       E = OID->instmeth_end(*Context); I != E; ++I)
     eol_needed = true, PrintObjCMethodDecl(*I);
   
   Out << (eol_needed ? "\n@end\n" : "@end\n");
@@ -408,8 +418,10 @@
 void DeclPrinter::PrintObjCProtocolDecl(ObjCProtocolDecl *PID) {
   Out << "@protocol " << PID->getNameAsString() << '\n';
   
-  for (ObjCProtocolDecl::prop_iterator I = PID->prop_begin(),
-       E = PID->prop_end(); I != E; ++I)
+  // FIXME: Should not use a NULL DeclContext!
+  ASTContext *Context = 0;
+  for (ObjCProtocolDecl::prop_iterator I = PID->prop_begin(*Context),
+       E = PID->prop_end(*Context); I != E; ++I)
     PrintObjCPropertyDecl(*I);
   Out << "@end\n";
   // FIXME: implement the rest...
@@ -427,12 +439,14 @@
 }
 
 void DeclPrinter::PrintObjCCategoryDecl(ObjCCategoryDecl *PID) {
+  // FIXME: Should not use a NULL DeclContext!
+  ASTContext *Context = 0;
   Out << "@interface " 
       << PID->getClassInterface()->getNameAsString()
       << '(' << PID->getNameAsString() << ");\n";
   // Output property declarations.
-  for (ObjCCategoryDecl::prop_iterator I = PID->prop_begin(),
-       E = PID->prop_end(); I != E; ++I)
+  for (ObjCCategoryDecl::prop_iterator I = PID->prop_begin(*Context),
+       E = PID->prop_end(*Context); I != E; ++I)
     PrintObjCPropertyDecl(*I);
   Out << "@end\n";
   
@@ -867,7 +881,10 @@
   Out << "\n";
 
   // Print decls in the DeclContext.
-  for (DeclContext::decl_iterator I = DC->decls_begin(), E = DC->decls_end();
+  // FIXME: Should not use a NULL DeclContext!
+  ASTContext *Context = 0;
+  for (DeclContext::decl_iterator I = DC->decls_begin(*Context), 
+         E = DC->decls_end(*Context);
        I != E; ++I) {
     for (unsigned i = 0; i < Indentation; ++i)
       Out << "  ";
diff --git a/tools/clang-cc/ASTConsumers.h b/tools/clang-cc/ASTConsumers.h
index fd8416d..970dfec 100644
--- a/tools/clang-cc/ASTConsumers.h
+++ b/tools/clang-cc/ASTConsumers.h
@@ -67,7 +67,7 @@
 ASTConsumer *CreateASTSerializer(const std::string& InFile,
                                  const std::string& EmitDir,
                                  Diagnostic &Diags);
-
+  
 ASTConsumer *CreateBlockRewriter(const std::string& InFile,
                                  const std::string& OutFile,
                                  Diagnostic &Diags,
diff --git a/tools/clang-cc/AnalysisConsumer.cpp b/tools/clang-cc/AnalysisConsumer.cpp
index bc38593..c39b1bc 100644
--- a/tools/clang-cc/AnalysisConsumer.cpp
+++ b/tools/clang-cc/AnalysisConsumer.cpp
@@ -459,7 +459,8 @@
   if (!ObjCImplementationActions.empty()) {
     TranslationUnitDecl *TUD = C.getTranslationUnitDecl();
     
-    for (DeclContext::decl_iterator I = TUD->decls_begin(),E = TUD->decls_end();
+    for (DeclContext::decl_iterator I = TUD->decls_begin(C),
+                                    E = TUD->decls_end(C);
          I != E; ++I)
       if (ObjCImplementationDecl* ID = dyn_cast<ObjCImplementationDecl>(*I))
         HandleCode(ID, 0, ObjCImplementationActions);
diff --git a/tools/clang-cc/RewriteBlocks.cpp b/tools/clang-cc/RewriteBlocks.cpp
index f302913..3610da6 100644
--- a/tools/clang-cc/RewriteBlocks.cpp
+++ b/tools/clang-cc/RewriteBlocks.cpp
@@ -310,29 +310,41 @@
 }
 
 void RewriteBlocks::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) {
-  for (ObjCInterfaceDecl::instmeth_iterator I = ClassDecl->instmeth_begin(), 
-       E = ClassDecl->instmeth_end(); I != E; ++I)
+  for (ObjCInterfaceDecl::instmeth_iterator 
+         I = ClassDecl->instmeth_begin(*Context), 
+         E = ClassDecl->instmeth_end(*Context); 
+       I != E; ++I)
     RewriteMethodDecl(*I);
-  for (ObjCInterfaceDecl::classmeth_iterator I = ClassDecl->classmeth_begin(), 
-       E = ClassDecl->classmeth_end(); I != E; ++I)
+  for (ObjCInterfaceDecl::classmeth_iterator 
+         I = ClassDecl->classmeth_begin(*Context), 
+         E = ClassDecl->classmeth_end(*Context);
+       I != E; ++I)
     RewriteMethodDecl(*I);
 }
 
 void RewriteBlocks::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) {
-  for (ObjCCategoryDecl::instmeth_iterator I = CatDecl->instmeth_begin(), 
-       E = CatDecl->instmeth_end(); I != E; ++I)
+  for (ObjCCategoryDecl::instmeth_iterator 
+         I = CatDecl->instmeth_begin(*Context), 
+         E = CatDecl->instmeth_end(*Context); 
+       I != E; ++I)
     RewriteMethodDecl(*I);
-  for (ObjCCategoryDecl::classmeth_iterator I = CatDecl->classmeth_begin(), 
-       E = CatDecl->classmeth_end(); I != E; ++I)
+  for (ObjCCategoryDecl::classmeth_iterator 
+         I = CatDecl->classmeth_begin(*Context), 
+         E = CatDecl->classmeth_end(*Context);
+       I != E; ++I)
     RewriteMethodDecl(*I);
 }
 
 void RewriteBlocks::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) {
-  for (ObjCProtocolDecl::instmeth_iterator I = PDecl->instmeth_begin(), 
-       E = PDecl->instmeth_end(); I != E; ++I)
+  for (ObjCProtocolDecl::instmeth_iterator 
+         I = PDecl->instmeth_begin(*Context), 
+         E = PDecl->instmeth_end(*Context); 
+       I != E; ++I)
     RewriteMethodDecl(*I);
-  for (ObjCProtocolDecl::classmeth_iterator I = PDecl->classmeth_begin(), 
-       E = PDecl->classmeth_end(); I != E; ++I)
+  for (ObjCProtocolDecl::classmeth_iterator 
+         I = PDecl->classmeth_begin(*Context), 
+         E = PDecl->classmeth_end(*Context); 
+       I != E; ++I)
     RewriteMethodDecl(*I);
 }
 
@@ -1138,8 +1150,8 @@
   }
   if (RecordDecl *RD = dyn_cast<RecordDecl>(D)) {
     if (RD->isDefinition()) {
-      for (RecordDecl::field_iterator i = RD->field_begin(), 
-             e = RD->field_end(); i != e; ++i) {
+      for (RecordDecl::field_iterator i = RD->field_begin(*Context), 
+             e = RD->field_end(*Context); i != e; ++i) {
         FieldDecl *FD = *i;
         if (isBlockPointerType(FD->getType()))
           RewriteBlockPointerDecl(FD);
diff --git a/tools/clang-cc/RewriteObjC.cpp b/tools/clang-cc/RewriteObjC.cpp
index 5fcecc6..44c0eb3 100644
--- a/tools/clang-cc/RewriteObjC.cpp
+++ b/tools/clang-cc/RewriteObjC.cpp
@@ -584,8 +584,8 @@
     RewriteForwardProtocolDecl(FP);
   } else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) {
     // Recurse into linkage specifications
-    for (DeclContext::decl_iterator DI = LSD->decls_begin(),
-                                 DIEnd = LSD->decls_end();
+    for (DeclContext::decl_iterator DI = LSD->decls_begin(*Context),
+                                 DIEnd = LSD->decls_end(*Context);
          DI != DIEnd; ++DI)
       HandleTopLevelSingleDecl(*DI);
   }
@@ -791,11 +791,15 @@
   // FIXME: handle category headers that are declared across multiple lines.
   ReplaceText(LocStart, 0, "// ", 3);
   
-  for (ObjCCategoryDecl::instmeth_iterator I = CatDecl->instmeth_begin(), 
-       E = CatDecl->instmeth_end(); I != E; ++I)
+  for (ObjCCategoryDecl::instmeth_iterator 
+         I = CatDecl->instmeth_begin(*Context), 
+         E = CatDecl->instmeth_end(*Context); 
+       I != E; ++I)
     RewriteMethodDeclaration(*I);
-  for (ObjCCategoryDecl::classmeth_iterator I = CatDecl->classmeth_begin(), 
-       E = CatDecl->classmeth_end(); I != E; ++I)
+  for (ObjCCategoryDecl::classmeth_iterator 
+         I = CatDecl->classmeth_begin(*Context), 
+         E = CatDecl->classmeth_end(*Context);
+       I != E; ++I)
     RewriteMethodDeclaration(*I);
 
   // Lastly, comment out the @end.
@@ -810,11 +814,15 @@
   // FIXME: handle protocol headers that are declared across multiple lines.
   ReplaceText(LocStart, 0, "// ", 3);
   
-  for (ObjCProtocolDecl::instmeth_iterator I = PDecl->instmeth_begin(), 
-       E = PDecl->instmeth_end(); I != E; ++I)
+  for (ObjCProtocolDecl::instmeth_iterator 
+         I = PDecl->instmeth_begin(*Context), 
+         E = PDecl->instmeth_end(*Context); 
+       I != E; ++I)
     RewriteMethodDeclaration(*I);
-  for (ObjCProtocolDecl::classmeth_iterator I = PDecl->classmeth_begin(), 
-       E = PDecl->classmeth_end(); I != E; ++I)
+  for (ObjCProtocolDecl::classmeth_iterator
+         I = PDecl->classmeth_begin(*Context), 
+         E = PDecl->classmeth_end(*Context);
+       I != E; ++I)
     RewriteMethodDeclaration(*I);
 
   // Lastly, comment out the @end.
@@ -1038,14 +1046,18 @@
   }
   SynthesizeObjCInternalStruct(ClassDecl, ResultStr);
     
-  for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(), 
-       E = ClassDecl->prop_end(); I != E; ++I)
+  for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(*Context), 
+         E = ClassDecl->prop_end(*Context); I != E; ++I)
     RewriteProperty(*I);
-  for (ObjCInterfaceDecl::instmeth_iterator I = ClassDecl->instmeth_begin(), 
-       E = ClassDecl->instmeth_end(); I != E; ++I)
+  for (ObjCInterfaceDecl::instmeth_iterator 
+         I = ClassDecl->instmeth_begin(*Context), 
+         E = ClassDecl->instmeth_end(*Context);
+       I != E; ++I)
     RewriteMethodDeclaration(*I);
-  for (ObjCInterfaceDecl::classmeth_iterator I = ClassDecl->classmeth_begin(), 
-       E = ClassDecl->classmeth_end(); I != E; ++I)
+  for (ObjCInterfaceDecl::classmeth_iterator 
+         I = ClassDecl->classmeth_begin(*Context), 
+         E = ClassDecl->classmeth_end(*Context); 
+       I != E; ++I)
     RewriteMethodDeclaration(*I);
 
   // Lastly, comment out the @end.
@@ -1136,7 +1148,9 @@
         dyn_cast<ObjCInterfaceType>(pType->getPointeeType());
       // lookup which class implements the instance variable.
       ObjCInterfaceDecl *clsDeclared = 0;
-      iFaceDecl->getDecl()->lookupInstanceVariable(D->getIdentifier(), clsDeclared);
+      iFaceDecl->getDecl()->lookupInstanceVariable(*Context, 
+                                                   D->getIdentifier(), 
+                                                   clsDeclared);
       assert(clsDeclared && "RewriteObjCIvarRefExpr(): Can't find class");
       
       // Synthesize an explicit cast to gain access to the ivar.
@@ -1180,7 +1194,9 @@
       ObjCInterfaceType *iFaceDecl = dyn_cast<ObjCInterfaceType>(pType->getPointeeType());
       // lookup which class implements the instance variable.
       ObjCInterfaceDecl *clsDeclared = 0;
-      iFaceDecl->getDecl()->lookupInstanceVariable(D->getIdentifier(), clsDeclared);
+      iFaceDecl->getDecl()->lookupInstanceVariable(*Context, 
+                                                   D->getIdentifier(), 
+                                                   clsDeclared);
       assert(clsDeclared && "RewriteObjCIvarRefExpr(): Can't find class");
       
       // Synthesize an explicit cast to gain access to the ivar.
@@ -2187,7 +2203,8 @@
 
     // Create fields
     for (unsigned i = 0; i < 2; ++i) {
-      SuperStructDecl->addDecl(FieldDecl::Create(*Context, SuperStructDecl, 
+      SuperStructDecl->addDecl(*Context,
+                               FieldDecl::Create(*Context, SuperStructDecl, 
                                                  SourceLocation(), 0, 
                                                  FieldTypes[i], /*BitWidth=*/0,
                                                  /*Mutable=*/false));
@@ -2216,7 +2233,8 @@
 
     // Create fields
     for (unsigned i = 0; i < 4; ++i) {
-      ConstantStringDecl->addDecl(FieldDecl::Create(*Context, 
+      ConstantStringDecl->addDecl(*Context,
+                                  FieldDecl::Create(*Context, 
                                                     ConstantStringDecl, 
                                                     SourceLocation(), 0,
                                                     FieldTypes[i], 
@@ -2867,9 +2885,9 @@
     if (ObjCSynthesizedProtocols.count(PDecl))
       continue;
            
-    if (PDecl->instmeth_begin() != PDecl->instmeth_end()) {
-      unsigned NumMethods = std::distance(PDecl->instmeth_begin(),
-                                          PDecl->instmeth_end());
+    if (PDecl->instmeth_begin(*Context) != PDecl->instmeth_end(*Context)) {
+      unsigned NumMethods = std::distance(PDecl->instmeth_begin(*Context),
+                                          PDecl->instmeth_end(*Context));
       /* struct _objc_protocol_method_list {
        int protocol_method_count;
        struct protocol_methods protocols[];
@@ -2885,9 +2903,11 @@
         "{\n\t" + utostr(NumMethods) + "\n";
       
       // Output instance methods declared in this protocol.
-      for (ObjCProtocolDecl::instmeth_iterator I = PDecl->instmeth_begin(), 
-           E = PDecl->instmeth_end(); I != E; ++I) {
-        if (I == PDecl->instmeth_begin())
+      for (ObjCProtocolDecl::instmeth_iterator 
+             I = PDecl->instmeth_begin(*Context), 
+             E = PDecl->instmeth_end(*Context); 
+           I != E; ++I) {
+        if (I == PDecl->instmeth_begin(*Context))
           Result += "\t  ,{{(SEL)\"";
         else
           Result += "\t  ,{(SEL)\"";
@@ -2902,8 +2922,8 @@
     }
     
     // Output class methods declared in this protocol.
-    unsigned NumMethods = std::distance(PDecl->classmeth_begin(),
-                                        PDecl->classmeth_end());
+    unsigned NumMethods = std::distance(PDecl->classmeth_begin(*Context),
+                                        PDecl->classmeth_end(*Context));
     if (NumMethods > 0) {
       /* struct _objc_protocol_method_list {
        int protocol_method_count;
@@ -2922,9 +2942,11 @@
       Result += "\n";
       
       // Output instance methods declared in this protocol.
-      for (ObjCProtocolDecl::classmeth_iterator I = PDecl->classmeth_begin(), 
-           E = PDecl->classmeth_end(); I != E; ++I) {
-        if (I == PDecl->classmeth_begin())
+      for (ObjCProtocolDecl::classmeth_iterator 
+             I = PDecl->classmeth_begin(*Context), 
+             E = PDecl->classmeth_end(*Context);
+           I != E; ++I) {
+        if (I == PDecl->classmeth_begin(*Context))
           Result += "\t  ,{{(SEL)\"";
         else
           Result += "\t  ,{(SEL)\"";
@@ -2967,14 +2989,14 @@
       "{\n\t0, \"";
     Result += PDecl->getNameAsString();
     Result += "\", 0, ";
-    if (PDecl->instmeth_begin() != PDecl->instmeth_end()) {
+    if (PDecl->instmeth_begin(*Context) != PDecl->instmeth_end(*Context)) {
       Result += "(struct _objc_protocol_method_list *)&_OBJC_PROTOCOL_INSTANCE_METHODS_";
       Result += PDecl->getNameAsString();
       Result += ", ";
     }
     else
       Result += "0, ";
-    if (PDecl->classmeth_begin() != PDecl->classmeth_end()) {
+    if (PDecl->classmeth_begin(*Context) != PDecl->classmeth_end(*Context)) {
       Result += "(struct _objc_protocol_method_list *)&_OBJC_PROTOCOL_CLASS_METHODS_";
       Result += PDecl->getNameAsString();
       Result += "\n";
@@ -4507,8 +4529,8 @@
   }
   if (RecordDecl *RD = dyn_cast<RecordDecl>(D)) {
     if (RD->isDefinition()) {
-      for (RecordDecl::field_iterator i = RD->field_begin(), 
-             e = RD->field_end(); i != e; ++i) {
+      for (RecordDecl::field_iterator i = RD->field_begin(*Context), 
+             e = RD->field_end(*Context); i != e; ++i) {
         FieldDecl *FD = *i;
         if (isTopLevelBlockPointerType(FD->getType()))
           RewriteBlockPointerDecl(FD);
diff --git a/tools/clang-cc/SerializationTest.cpp b/tools/clang-cc/SerializationTest.cpp
index b4fd8d7..708328d 100644
--- a/tools/clang-cc/SerializationTest.cpp
+++ b/tools/clang-cc/SerializationTest.cpp
@@ -72,7 +72,8 @@
     llvm::OwningPtr<ASTConsumer> FilePrinter(CreateASTPrinter(&DeclPP));
     
     TranslationUnitDecl *TUD = Ctx.getTranslationUnitDecl();
-    for (DeclContext::decl_iterator I = TUD->decls_begin(), E =TUD->decls_end();
+    for (DeclContext::decl_iterator I = TUD->decls_begin(Ctx), 
+                                    E = TUD->decls_end(Ctx);
          I != E; ++I)
       FilePrinter->HandleTopLevelDecl(DeclGroupRef(*I));
   }
@@ -123,7 +124,8 @@
     llvm::OwningPtr<ASTConsumer> FilePrinter(CreateASTPrinter(&DeclPP));
     
     TranslationUnitDecl *TUD = NewCtx->getTranslationUnitDecl();
-    for (DeclContext::decl_iterator I = TUD->decls_begin(), E = TUD->decls_end();
+    for (DeclContext::decl_iterator I = TUD->decls_begin(*NewCtx), 
+                                    E = TUD->decls_end(*NewCtx);
          I != E; ++I)
       FilePrinter->HandleTopLevelDecl(DeclGroupRef(*I));
   }
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index 3c06ea7..b10323a 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -1597,7 +1597,7 @@
     ClearSourceMgr = true;
     break;
   }      
-    
+
   case PrintPreprocessedInput: {      // -E mode.
     llvm::TimeRegion Timer(ClangFrontendTimer);
     DoPrintPreprocessedInput(PP, OutputFile);
@@ -1683,7 +1683,6 @@
                                       PP.getSelectorTable(),
                                       /* FreeMemory = */ !DisableFree));
     
-    
     ParseAST(PP, Consumer.get(), *ContextOwner.get(), Stats);
     
     if (FixItRewrite)
@@ -1763,7 +1762,8 @@
 
   // FIXME: We need to inform Consumer about completed TagDecls as well.
   TranslationUnitDecl *TUD = Ctx->getTranslationUnitDecl();
-  for (DeclContext::decl_iterator I = TUD->decls_begin(), E = TUD->decls_end();
+  for (DeclContext::decl_iterator I = TUD->decls_begin(*Ctx), 
+                                  E = TUD->decls_end(*Ctx);
        I != E; ++I)
     Consumer->HandleTopLevelDecl(DeclGroupRef(*I));
 }