De-ASTContext-ify DeclContext.

Remove ASTContext parameter from DeclContext's methods. This change cascaded down to other Decl's methods and changes to call sites started "escalating".
Timings using pre-tokenized "cocoa.h" showed only a ~1% increase in time run between and after this commit.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74506 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/RewriteObjC.cpp b/lib/Frontend/RewriteObjC.cpp
index a48e8e6..cf31f2b 100644
--- a/lib/Frontend/RewriteObjC.cpp
+++ b/lib/Frontend/RewriteObjC.cpp
@@ -597,8 +597,8 @@
     RewriteForwardProtocolDecl(FP);
   } else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) {
     // Recurse into linkage specifications
-    for (DeclContext::decl_iterator DI = LSD->decls_begin(*Context),
-                                 DIEnd = LSD->decls_end(*Context);
+    for (DeclContext::decl_iterator DI = LSD->decls_begin(),
+                                 DIEnd = LSD->decls_end();
          DI != DIEnd; ++DI)
       HandleTopLevelSingleDecl(*DI);
   }
@@ -789,13 +789,11 @@
   ReplaceText(LocStart, 0, "// ", 3);
   
   for (ObjCCategoryDecl::instmeth_iterator 
-         I = CatDecl->instmeth_begin(*Context), 
-         E = CatDecl->instmeth_end(*Context); 
+         I = CatDecl->instmeth_begin(), E = CatDecl->instmeth_end(); 
        I != E; ++I)
     RewriteMethodDeclaration(*I);
   for (ObjCCategoryDecl::classmeth_iterator 
-         I = CatDecl->classmeth_begin(*Context), 
-         E = CatDecl->classmeth_end(*Context);
+         I = CatDecl->classmeth_begin(), E = CatDecl->classmeth_end();
        I != E; ++I)
     RewriteMethodDeclaration(*I);
 
@@ -812,13 +810,11 @@
   ReplaceText(LocStart, 0, "// ", 3);
   
   for (ObjCProtocolDecl::instmeth_iterator 
-         I = PDecl->instmeth_begin(*Context), 
-         E = PDecl->instmeth_end(*Context); 
+         I = PDecl->instmeth_begin(), E = PDecl->instmeth_end(); 
        I != E; ++I)
     RewriteMethodDeclaration(*I);
   for (ObjCProtocolDecl::classmeth_iterator
-         I = PDecl->classmeth_begin(*Context), 
-         E = PDecl->classmeth_end(*Context);
+         I = PDecl->classmeth_begin(), E = PDecl->classmeth_end();
        I != E; ++I)
     RewriteMethodDeclaration(*I);
 
@@ -986,8 +982,8 @@
     InsertText(CID->getLocStart(), "// ", 3);
       
   for (ObjCCategoryImplDecl::instmeth_iterator
-       I = IMD ? IMD->instmeth_begin(*Context) : CID->instmeth_begin(*Context),
-       E = IMD ? IMD->instmeth_end(*Context) : CID->instmeth_end(*Context);
+       I = IMD ? IMD->instmeth_begin() : CID->instmeth_begin(),
+       E = IMD ? IMD->instmeth_end() : CID->instmeth_end();
        I != E; ++I) {
     std::string ResultStr;
     ObjCMethodDecl *OMD = *I;
@@ -1002,8 +998,8 @@
   }
   
   for (ObjCCategoryImplDecl::classmeth_iterator
-       I = IMD ? IMD->classmeth_begin(*Context) : CID->classmeth_begin(*Context),
-       E = IMD ? IMD->classmeth_end(*Context) : CID->classmeth_end(*Context);
+       I = IMD ? IMD->classmeth_begin() : CID->classmeth_begin(),
+       E = IMD ? IMD->classmeth_end() : CID->classmeth_end();
        I != E; ++I) {
     std::string ResultStr;
     ObjCMethodDecl *OMD = *I;
@@ -1017,8 +1013,8 @@
                 ResultStr.c_str(), ResultStr.size());    
   }
   for (ObjCCategoryImplDecl::propimpl_iterator
-       I = IMD ? IMD->propimpl_begin(*Context) : CID->propimpl_begin(*Context),
-       E = IMD ? IMD->propimpl_end(*Context) : CID->propimpl_end(*Context); 
+       I = IMD ? IMD->propimpl_begin() : CID->propimpl_begin(),
+       E = IMD ? IMD->propimpl_end() : CID->propimpl_end(); 
        I != E; ++I) {
     RewritePropertyImplDecl(*I, IMD, CID);
   }
@@ -1047,17 +1043,15 @@
   }
   SynthesizeObjCInternalStruct(ClassDecl, ResultStr);
     
-  for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(*Context), 
-         E = ClassDecl->prop_end(*Context); I != E; ++I)
+  for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(), 
+         E = ClassDecl->prop_end(); I != E; ++I)
     RewriteProperty(*I);
   for (ObjCInterfaceDecl::instmeth_iterator 
-         I = ClassDecl->instmeth_begin(*Context), 
-         E = ClassDecl->instmeth_end(*Context);
+         I = ClassDecl->instmeth_begin(), E = ClassDecl->instmeth_end();
        I != E; ++I)
     RewriteMethodDeclaration(*I);
   for (ObjCInterfaceDecl::classmeth_iterator 
-         I = ClassDecl->classmeth_begin(*Context), 
-         E = ClassDecl->classmeth_end(*Context); 
+         I = ClassDecl->classmeth_begin(), E = ClassDecl->classmeth_end(); 
        I != E; ++I)
     RewriteMethodDeclaration(*I);
 
@@ -1149,8 +1143,7 @@
         dyn_cast<ObjCInterfaceType>(pType->getPointeeType());
       // lookup which class implements the instance variable.
       ObjCInterfaceDecl *clsDeclared = 0;
-      iFaceDecl->getDecl()->lookupInstanceVariable(*Context, 
-                                                   D->getIdentifier(), 
+      iFaceDecl->getDecl()->lookupInstanceVariable(D->getIdentifier(), 
                                                    clsDeclared);
       assert(clsDeclared && "RewriteObjCIvarRefExpr(): Can't find class");
       
@@ -1195,8 +1188,7 @@
       ObjCInterfaceType *iFaceDecl = dyn_cast<ObjCInterfaceType>(pType->getPointeeType());
       // lookup which class implements the instance variable.
       ObjCInterfaceDecl *clsDeclared = 0;
-      iFaceDecl->getDecl()->lookupInstanceVariable(*Context, 
-                                                   D->getIdentifier(), 
+      iFaceDecl->getDecl()->lookupInstanceVariable(D->getIdentifier(), 
                                                    clsDeclared);
       assert(clsDeclared && "RewriteObjCIvarRefExpr(): Can't find class");
       
@@ -2194,8 +2186,7 @@
 
     // Create fields
     for (unsigned i = 0; i < 2; ++i) {
-      SuperStructDecl->addDecl(*Context,
-                               FieldDecl::Create(*Context, SuperStructDecl, 
+      SuperStructDecl->addDecl(FieldDecl::Create(*Context, SuperStructDecl, 
                                                  SourceLocation(), 0, 
                                                  FieldTypes[i], /*BitWidth=*/0,
                                                  /*Mutable=*/false));
@@ -2224,8 +2215,7 @@
 
     // Create fields
     for (unsigned i = 0; i < 4; ++i) {
-      ConstantStringDecl->addDecl(*Context,
-                                  FieldDecl::Create(*Context, 
+      ConstantStringDecl->addDecl(FieldDecl::Create(*Context, 
                                                     ConstantStringDecl, 
                                                     SourceLocation(), 0,
                                                     FieldTypes[i], 
@@ -2891,9 +2881,9 @@
   if (ObjCSynthesizedProtocols.count(PDecl))
     return;
          
-    if (PDecl->instmeth_begin(*Context) != PDecl->instmeth_end(*Context)) {
-      unsigned NumMethods = std::distance(PDecl->instmeth_begin(*Context),
-                                          PDecl->instmeth_end(*Context));
+    if (PDecl->instmeth_begin() != PDecl->instmeth_end()) {
+      unsigned NumMethods = std::distance(PDecl->instmeth_begin(),
+                                          PDecl->instmeth_end());
     /* struct _objc_protocol_method_list {
      int protocol_method_count;
      struct protocol_methods protocols[];
@@ -2910,10 +2900,9 @@
     
     // Output instance methods declared in this protocol.
     for (ObjCProtocolDecl::instmeth_iterator 
-           I = PDecl->instmeth_begin(*Context), 
-           E = PDecl->instmeth_end(*Context); 
+           I = PDecl->instmeth_begin(), E = PDecl->instmeth_end(); 
          I != E; ++I) {
-      if (I == PDecl->instmeth_begin(*Context))
+      if (I == PDecl->instmeth_begin())
         Result += "\t  ,{{(struct objc_selector *)\"";
       else
         Result += "\t  ,{(struct objc_selector *)\"";
@@ -2928,8 +2917,8 @@
   }
   
   // Output class methods declared in this protocol.
-  unsigned NumMethods = std::distance(PDecl->classmeth_begin(*Context),
-                                      PDecl->classmeth_end(*Context));
+  unsigned NumMethods = std::distance(PDecl->classmeth_begin(),
+                                      PDecl->classmeth_end());
   if (NumMethods > 0) {
     /* struct _objc_protocol_method_list {
      int protocol_method_count;
@@ -2949,10 +2938,9 @@
     
     // Output instance methods declared in this protocol.
     for (ObjCProtocolDecl::classmeth_iterator 
-           I = PDecl->classmeth_begin(*Context), 
-           E = PDecl->classmeth_end(*Context);
+           I = PDecl->classmeth_begin(), E = PDecl->classmeth_end();
          I != E; ++I) {
-      if (I == PDecl->classmeth_begin(*Context))
+      if (I == PDecl->classmeth_begin())
         Result += "\t  ,{{(struct objc_selector *)\"";
       else
         Result += "\t  ,{(struct objc_selector *)\"";
@@ -2995,14 +2983,14 @@
     "{\n\t0, \"";
   Result += PDecl->getNameAsString();
   Result += "\", 0, ";
-  if (PDecl->instmeth_begin(*Context) != PDecl->instmeth_end(*Context)) {
+  if (PDecl->instmeth_begin() != PDecl->instmeth_end()) {
     Result += "(struct _objc_protocol_method_list *)&_OBJC_PROTOCOL_INSTANCE_METHODS_";
     Result += PDecl->getNameAsString();
     Result += ", ";
   }
   else
     Result += "0, ";
-  if (PDecl->classmeth_begin(*Context) != PDecl->classmeth_end(*Context)) {
+  if (PDecl->classmeth_begin() != PDecl->classmeth_end()) {
     Result += "(struct _objc_protocol_method_list *)&_OBJC_PROTOCOL_CLASS_METHODS_";
     Result += PDecl->getNameAsString();
     Result += "\n";
@@ -3078,13 +3066,12 @@
     
   // Build _objc_method_list for class's instance methods if needed
   llvm::SmallVector<ObjCMethodDecl *, 32> 
-    InstanceMethods(IDecl->instmeth_begin(*Context),
-                    IDecl->instmeth_end(*Context));
+    InstanceMethods(IDecl->instmeth_begin(), IDecl->instmeth_end());
 
   // If any of our property implementations have associated getters or
   // setters, produce metadata for them as well.
-  for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(*Context),
-         PropEnd = IDecl->propimpl_end(*Context);
+  for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(),
+         PropEnd = IDecl->propimpl_end();
        Prop != PropEnd; ++Prop) {
     if ((*Prop)->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
       continue;
@@ -3105,8 +3092,7 @@
                              Result);
   
   // Build _objc_method_list for class's class methods if needed
-  RewriteObjCMethodsMetaData(IDecl->classmeth_begin(*Context),
-                             IDecl->classmeth_end(*Context),
+  RewriteObjCMethodsMetaData(IDecl->classmeth_begin(), IDecl->classmeth_end(),
                              false, "CATEGORY_", FullCategoryName.c_str(),
                              Result);
   
@@ -3149,7 +3135,7 @@
   Result += ClassDecl->getNameAsString();
   Result += "\"\n";
   
-  if (IDecl->instmeth_begin(*Context) != IDecl->instmeth_end(*Context)) {
+  if (IDecl->instmeth_begin() != IDecl->instmeth_end()) {
     Result += "\t, (struct _objc_method_list *)"
            "&_OBJC_CATEGORY_INSTANCE_METHODS_";
     Result += FullCategoryName;
@@ -3157,7 +3143,7 @@
   }
   else
     Result += "\t, 0\n";
-  if (IDecl->classmeth_begin(*Context) != IDecl->classmeth_end(*Context)) {
+  if (IDecl->classmeth_begin() != IDecl->classmeth_end()) {
     Result += "\t, (struct _objc_method_list *)"
            "&_OBJC_CATEGORY_CLASS_METHODS_";
     Result += FullCategoryName;
@@ -3212,8 +3198,8 @@
   }
   
   // Build _objc_ivar_list metadata for classes ivars if needed
-  unsigned NumIvars = !IDecl->ivar_empty(*Context)
-                      ? IDecl->ivar_size(*Context) 
+  unsigned NumIvars = !IDecl->ivar_empty()
+                      ? IDecl->ivar_size() 
                       : (CDecl ? CDecl->ivar_size() : 0);
   if (NumIvars > 0) {
     static bool objc_ivar = false;
@@ -3251,10 +3237,9 @@
     
     ObjCInterfaceDecl::ivar_iterator IVI, IVE;
     llvm::SmallVector<ObjCIvarDecl *, 8> IVars;
-    if (!IDecl->ivar_empty(*Context)) {
+    if (!IDecl->ivar_empty()) {
       for (ObjCImplementationDecl::ivar_iterator 
-             IV = IDecl->ivar_begin(*Context),
-             IVEnd = IDecl->ivar_end(*Context);
+             IV = IDecl->ivar_begin(), IVEnd = IDecl->ivar_end();
            IV != IVEnd; ++IV)
         IVars.push_back(*IV);
       IVI = IVars.begin();
@@ -3291,13 +3276,12 @@
   
   // Build _objc_method_list for class's instance methods if needed
   llvm::SmallVector<ObjCMethodDecl *, 32> 
-    InstanceMethods(IDecl->instmeth_begin(*Context),
-                    IDecl->instmeth_end(*Context));
+    InstanceMethods(IDecl->instmeth_begin(), IDecl->instmeth_end());
 
   // If any of our property implementations have associated getters or
   // setters, produce metadata for them as well.
-  for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(*Context),
-         PropEnd = IDecl->propimpl_end(*Context);
+  for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(),
+         PropEnd = IDecl->propimpl_end();
        Prop != PropEnd; ++Prop) {
     if ((*Prop)->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
       continue;
@@ -3317,8 +3301,7 @@
                              true, "", IDecl->getNameAsCString(), Result);
   
   // Build _objc_method_list for class's class methods if needed
-  RewriteObjCMethodsMetaData(IDecl->classmeth_begin(*Context), 
-                             IDecl->classmeth_end(*Context),
+  RewriteObjCMethodsMetaData(IDecl->classmeth_begin(), IDecl->classmeth_end(),
                              false, "", IDecl->getNameAsCString(), Result);
     
   // Protocols referenced in class declaration?
@@ -3391,7 +3374,7 @@
   // Set 'ivars' field for root class to 0. ObjC1 runtime does not use it.
   // 'info' field is initialized to CLS_META(2) for metaclass
   Result += ", 0,2, sizeof(struct _objc_class), 0";
-  if (IDecl->classmeth_begin(*Context) != IDecl->classmeth_end(*Context)) {
+  if (IDecl->classmeth_begin() != IDecl->classmeth_end()) {
     Result += "\n\t, (struct _objc_method_list *)&_OBJC_CLASS_METHODS_";
     Result += IDecl->getNameAsString();
     Result += "\n"; 
@@ -3444,7 +3427,7 @@
   }
   else
     Result += ",0";
-  if (IDecl->instmeth_begin(*Context) != IDecl->instmeth_end(*Context)) {
+  if (IDecl->instmeth_begin() != IDecl->instmeth_end()) {
     Result += ", (struct _objc_method_list *)&_OBJC_INSTANCE_METHODS_";
     Result += CDecl->getNameAsString();
     Result += ", 0\n\t"; 
@@ -4638,8 +4621,8 @@
   }
   if (RecordDecl *RD = dyn_cast<RecordDecl>(D)) {
     if (RD->isDefinition()) {
-      for (RecordDecl::field_iterator i = RD->field_begin(*Context), 
-             e = RD->field_end(*Context); i != e; ++i) {
+      for (RecordDecl::field_iterator i = RD->field_begin(), 
+             e = RD->field_end(); i != e; ++i) {
         FieldDecl *FD = *i;
         if (isTopLevelBlockPointerType(FD->getType()))
           RewriteBlockPointerDecl(FD);