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/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index a4609d4..96ba19b 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -409,7 +409,7 @@
 }
 
 void DeclContext::DestroyDecls(ASTContext &C) {
-  for (decl_iterator D = decls_begin(C); D != decls_end(C); )
+  for (decl_iterator D = decls_begin(); D != decls_end(); )
     (*D++)->Destroy(C);
 }
 
@@ -500,8 +500,8 @@
 /// \brief Load the declarations within this lexical storage from an
 /// external source.
 void 
-DeclContext::LoadLexicalDeclsFromExternalStorage(ASTContext &Context) const {
-  ExternalASTSource *Source = Context.getExternalSource();
+DeclContext::LoadLexicalDeclsFromExternalStorage() const {
+  ExternalASTSource *Source = getParentASTContext().getExternalSource();
   assert(hasExternalLexicalStorage() && Source && "No external storage?");
 
   llvm::SmallVector<uint32_t, 64> Decls;
@@ -538,9 +538,9 @@
 }
 
 void 
-DeclContext::LoadVisibleDeclsFromExternalStorage(ASTContext &Context) const {
+DeclContext::LoadVisibleDeclsFromExternalStorage() const {
   DeclContext *This = const_cast<DeclContext *>(this);
-  ExternalASTSource *Source = Context.getExternalSource();
+  ExternalASTSource *Source = getParentASTContext().getExternalSource();
   assert(hasExternalVisibleStorage() && Source && "No external storage?");
 
   llvm::SmallVector<VisibleDeclaration, 64> Decls;
@@ -560,30 +560,30 @@
   }
 }
 
-DeclContext::decl_iterator DeclContext::decls_begin(ASTContext &Context) const {
+DeclContext::decl_iterator DeclContext::decls_begin() const {
   if (hasExternalLexicalStorage())
-    LoadLexicalDeclsFromExternalStorage(Context);
+    LoadLexicalDeclsFromExternalStorage();
 
   // FIXME: Check whether we need to load some declarations from
   // external storage.
   return decl_iterator(FirstDecl); 
 }
 
-DeclContext::decl_iterator DeclContext::decls_end(ASTContext &Context) const {
+DeclContext::decl_iterator DeclContext::decls_end() const {
   if (hasExternalLexicalStorage())
-    LoadLexicalDeclsFromExternalStorage(Context);
+    LoadLexicalDeclsFromExternalStorage();
 
   return decl_iterator(); 
 }
 
-bool DeclContext::decls_empty(ASTContext &Context) const {
+bool DeclContext::decls_empty() const {
   if (hasExternalLexicalStorage())
-    LoadLexicalDeclsFromExternalStorage(Context);
+    LoadLexicalDeclsFromExternalStorage();
 
   return !FirstDecl;
 }
 
-void DeclContext::addDecl(ASTContext &Context, Decl *D) {
+void DeclContext::addDecl(Decl *D) {
   assert(D->getLexicalDeclContext() == this &&
          "Decl inserted into wrong lexical context");
   assert(!D->getNextDeclInContext() && D != LastDecl && 
@@ -597,44 +597,44 @@
   }
 
   if (NamedDecl *ND = dyn_cast<NamedDecl>(D))
-    ND->getDeclContext()->makeDeclVisibleInContext(Context, ND);
+    ND->getDeclContext()->makeDeclVisibleInContext(ND);
 }
 
 /// buildLookup - Build the lookup data structure with all of the
 /// declarations in DCtx (and any other contexts linked to it or
 /// transparent contexts nested within it).
-void DeclContext::buildLookup(ASTContext &Context, DeclContext *DCtx) {
+void DeclContext::buildLookup(DeclContext *DCtx) {
   for (; DCtx; DCtx = DCtx->getNextContext()) {
-    for (decl_iterator D = DCtx->decls_begin(Context), 
-                    DEnd = DCtx->decls_end(Context); 
+    for (decl_iterator D = DCtx->decls_begin(), 
+                    DEnd = DCtx->decls_end(); 
          D != DEnd; ++D) {
       // Insert this declaration into the lookup structure
       if (NamedDecl *ND = dyn_cast<NamedDecl>(*D))
-        makeDeclVisibleInContextImpl(Context, ND);
+        makeDeclVisibleInContextImpl(ND);
 
       // If this declaration is itself a transparent declaration context,
       // add its members (recursively).
       if (DeclContext *InnerCtx = dyn_cast<DeclContext>(*D))
         if (InnerCtx->isTransparentContext())
-          buildLookup(Context, InnerCtx->getPrimaryContext());
+          buildLookup(InnerCtx->getPrimaryContext());
     }
   }
 }
 
 DeclContext::lookup_result 
-DeclContext::lookup(ASTContext &Context, DeclarationName Name) {
+DeclContext::lookup(DeclarationName Name) {
   DeclContext *PrimaryContext = getPrimaryContext();
   if (PrimaryContext != this)
-    return PrimaryContext->lookup(Context, Name);
+    return PrimaryContext->lookup(Name);
 
   if (hasExternalVisibleStorage())
-    LoadVisibleDeclsFromExternalStorage(Context);
+    LoadVisibleDeclsFromExternalStorage();
 
   /// If there is no lookup data structure, build one now by walking
   /// all of the linked DeclContexts (in declaration order!) and
   /// inserting their values.
   if (!LookupPtr) {
-    buildLookup(Context, this);
+    buildLookup(this);
 
     if (!LookupPtr)
       return lookup_result(0, 0);
@@ -644,12 +644,12 @@
   StoredDeclsMap::iterator Pos = Map->find(Name);
   if (Pos == Map->end())
     return lookup_result(0, 0);
-  return Pos->second.getLookupResult(Context);
+  return Pos->second.getLookupResult(getParentASTContext());
 }
 
 DeclContext::lookup_const_result 
-DeclContext::lookup(ASTContext &Context, DeclarationName Name) const {
-  return const_cast<DeclContext*>(this)->lookup(Context, Name);
+DeclContext::lookup(DeclarationName Name) const {
+  return const_cast<DeclContext*>(this)->lookup(Name);
 }
 
 DeclContext *DeclContext::getLookupContext() {
@@ -668,7 +668,7 @@
   return Ctx->getPrimaryContext();
 }
 
-void DeclContext::makeDeclVisibleInContext(ASTContext &Context, NamedDecl *D) {
+void DeclContext::makeDeclVisibleInContext(NamedDecl *D) {
   // FIXME: This feels like a hack. Should DeclarationName support
   // template-ids, or is there a better way to keep specializations
   // from being visible?
@@ -677,7 +677,7 @@
 
   DeclContext *PrimaryContext = getPrimaryContext();
   if (PrimaryContext != this) {
-    PrimaryContext->makeDeclVisibleInContext(Context, D);
+    PrimaryContext->makeDeclVisibleInContext(D);
     return;
   }
 
@@ -685,16 +685,15 @@
   // into it. Otherwise, be lazy and don't build that structure until
   // someone asks for it.
   if (LookupPtr)
-    makeDeclVisibleInContextImpl(Context, D);
+    makeDeclVisibleInContextImpl(D);
 
   // If we are a transparent context, insert into our parent context,
   // too. This operation is recursive.
   if (isTransparentContext())
-    getParent()->makeDeclVisibleInContext(Context, D);
+    getParent()->makeDeclVisibleInContext(D);
 }
 
-void DeclContext::makeDeclVisibleInContextImpl(ASTContext &Context, 
-                                               NamedDecl *D) {
+void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D) {
   // Skip unnamed declarations.
   if (!D->getDeclName())
     return;
@@ -719,7 +718,7 @@
   // If it is possible that this is a redeclaration, check to see if there is
   // already a decl for which declarationReplaces returns true.  If there is
   // one, just replace it and return.
-  if (DeclNameEntries.HandleRedeclaration(Context, D))
+  if (DeclNameEntries.HandleRedeclaration(getParentASTContext(), D))
     return;
   
   // Put this declaration into the appropriate slot.
@@ -729,8 +728,8 @@
 /// Returns iterator range [First, Last) of UsingDirectiveDecls stored within
 /// this context.
 DeclContext::udir_iterator_range 
-DeclContext::getUsingDirectives(ASTContext &Context) const {
-  lookup_const_result Result = lookup(Context, UsingDirectiveDecl::getName());
+DeclContext::getUsingDirectives() const {
+  lookup_const_result Result = lookup(UsingDirectiveDecl::getName());
   return udir_iterator_range(reinterpret_cast<udir_iterator>(Result.first),
                              reinterpret_cast<udir_iterator>(Result.second));
 }