Remove the ASTContext parameter from the attribute-related methods of Decl.
The implementations of these methods can Use Decl::getASTContext() to get the ASTContext.

This commit touches a lot of files since call sites for these methods are everywhere.
I used pre-tokenized "carbon.h" and "cocoa.h" headers to do some timings, and there was no real time difference between before the commit and after it.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74501 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index fc78842..4f78ad9 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -225,7 +225,7 @@
 unsigned ASTContext::getDeclAlignInBytes(const Decl *D) {
   unsigned Align = Target.getCharWidth();
 
-  if (const AlignedAttr* AA = D->getAttr<AlignedAttr>(*this))
+  if (const AlignedAttr* AA = D->getAttr<AlignedAttr>())
     Align = std::max(Align, AA->getAlignment());
 
   if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
@@ -448,7 +448,7 @@
 
   case Type::Typedef: {
     const TypedefDecl *Typedef = cast<TypedefType>(T)->getDecl();
-    if (const AlignedAttr *Aligned = Typedef->getAttr<AlignedAttr>(*this)) {
+    if (const AlignedAttr *Aligned = Typedef->getAttr<AlignedAttr>()) {
       Align = Aligned->getAlignment();
       Width = getTypeSize(Typedef->getUnderlyingType().getTypePtr());
     } else
@@ -512,7 +512,7 @@
 
   // FIXME: Should this override struct packing? Probably we want to
   // take the minimum?
-  if (const PackedAttr *PA = FD->getAttr<PackedAttr>(Context))
+  if (const PackedAttr *PA = FD->getAttr<PackedAttr>())
     FieldPacking = PA->getAlignment();
   
   if (const Expr *BitWidthExpr = FD->getBitWidth()) {
@@ -532,7 +532,7 @@
     FieldAlign = FieldInfo.second;
     if (FieldPacking)
       FieldAlign = std::min(FieldAlign, FieldPacking);
-    if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>(Context))
+    if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>())
       FieldAlign = std::max(FieldAlign, AA->getAlignment());
     
     // Check if we need to add padding to give the field the correct
@@ -572,7 +572,7 @@
     // is smaller than the specified packing?
     if (FieldPacking)
       FieldAlign = std::min(FieldAlign, std::max(8U, FieldPacking));
-    if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>(Context))
+    if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>())
       FieldAlign = std::max(FieldAlign, AA->getAlignment());
     
     // Round up the current record size to the field's alignment boundary.
@@ -738,10 +738,10 @@
   }
 
   unsigned StructPacking = 0;
-  if (const PackedAttr *PA = D->getAttr<PackedAttr>(*this))
+  if (const PackedAttr *PA = D->getAttr<PackedAttr>())
     StructPacking = PA->getAlignment();
 
-  if (const AlignedAttr *AA = D->getAttr<AlignedAttr>(*this))
+  if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
     NewEntry->SetAlignment(std::max(NewEntry->getAlignment(), 
                                     AA->getAlignment()));
 
@@ -790,10 +790,10 @@
   bool IsUnion = D->isUnion();
 
   unsigned StructPacking = 0;
-  if (const PackedAttr *PA = D->getAttr<PackedAttr>(*this))
+  if (const PackedAttr *PA = D->getAttr<PackedAttr>())
     StructPacking = PA->getAlignment();
 
-  if (const AlignedAttr *AA = D->getAttr<AlignedAttr>(*this))
+  if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
     NewEntry->SetAlignment(std::max(NewEntry->getAlignment(), 
                                     AA->getAlignment()));
 
@@ -2832,7 +2832,7 @@
 bool ASTContext::isObjCNSObjectType(QualType Ty) const {
   if (TypedefType *TDT = dyn_cast<TypedefType>(Ty)) {
     if (TypedefDecl *TD = TDT->getDecl())
-      if (TD->getAttr<ObjCNSObjectAttr>(*const_cast<ASTContext*>(this)))
+      if (TD->getAttr<ObjCNSObjectAttr>())
         return true;
   }
   return false;  
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 77fb20c..89b8765 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -412,14 +412,14 @@
   // In C, any non-static, non-overloadable function has external
   // linkage.
   if (!Context.getLangOptions().CPlusPlus)
-    return getStorageClass() != Static && !getAttr<OverloadableAttr>(Context);
+    return getStorageClass() != Static && !getAttr<OverloadableAttr>();
 
   for (const DeclContext *DC = getDeclContext(); !DC->isTranslationUnit(); 
        DC = DC->getParent()) {
     if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC))  {
       if (Linkage->getLanguage() == LinkageSpecDecl::lang_c)
         return getStorageClass() != Static && 
-               !getAttr<OverloadableAttr>(Context);
+               !getAttr<OverloadableAttr>();
 
       break;
     }
@@ -484,7 +484,7 @@
   if (isa<LinkageSpecDecl>(getDeclContext()) &&
       cast<LinkageSpecDecl>(getDeclContext())->getLanguage() 
         == LinkageSpecDecl::lang_c &&
-      !getAttr<OverloadableAttr>(Context))
+      !getAttr<OverloadableAttr>())
     return BuiltinID;
 
   // Not a builtin
@@ -535,12 +535,12 @@
 }
 
 bool FunctionDecl::hasActiveGNUInlineAttribute(ASTContext &Context) const {
-  if (!isInline() || !hasAttr<GNUInlineAttr>(Context))
+  if (!isInline() || !hasAttr<GNUInlineAttr>())
     return false;
 
   for (const FunctionDecl *FD = getPreviousDeclaration(); FD; 
        FD = FD->getPreviousDeclaration()) {
-    if (FD->isInline() && !FD->hasAttr<GNUInlineAttr>(Context))
+    if (FD->isInline() && !FD->hasAttr<GNUInlineAttr>())
       return false;
   }
 
@@ -552,7 +552,7 @@
     return false;
 
   for (const FunctionDecl *FD = this; FD; FD = FD->getPreviousDeclaration())
-    if (FD->getStorageClass() == Extern && FD->hasAttr<GNUInlineAttr>(Context))
+    if (FD->getStorageClass() == Extern && FD->hasAttr<GNUInlineAttr>())
       return true;
 
   return false;
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index 0ccd6b4..d872eae 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -242,8 +242,8 @@
   }
 }
 
-void Decl::addAttr(ASTContext &Context, Attr *NewAttr) {
-  Attr *&ExistingAttr = Context.getDeclAttrs(this);
+void Decl::addAttr(Attr *NewAttr) {
+  Attr *&ExistingAttr = getASTContext().getDeclAttrs(this);
 
   NewAttr->setNext(ExistingAttr);
   ExistingAttr = NewAttr;
@@ -251,19 +251,19 @@
   HasAttrs = true;
 }
 
-void Decl::invalidateAttrs(ASTContext &Context) {
+void Decl::invalidateAttrs() {
   if (!HasAttrs) return;
   
   HasAttrs = false;
-  Context.eraseDeclAttrs(this);
+  getASTContext().eraseDeclAttrs(this);
 }
 
-const Attr *Decl::getAttrsImpl(ASTContext &Context) const {
+const Attr *Decl::getAttrsImpl() const {
   assert(HasAttrs && "getAttrs() should verify this!"); 
-  return Context.getDeclAttrs(this);
+  return getASTContext().getDeclAttrs(this);
 }
 
-void Decl::swapAttrs(ASTContext &Context, Decl *RHS) {
+void Decl::swapAttrs(Decl *RHS) {
   bool HasLHSAttr = this->HasAttrs;
   bool HasRHSAttr = RHS->HasAttrs;
   
@@ -272,7 +272,9 @@
   
   // If 'this' has no attrs, swap the other way.
   if (!HasLHSAttr)
-    return RHS->swapAttrs(Context, this);
+    return RHS->swapAttrs(this);
+  
+  ASTContext &Context = getASTContext();
   
   // Handle the case when both decls have attrs.
   if (HasRHSAttr) {
@@ -292,7 +294,7 @@
   // Free attributes for this decl.
   if (HasAttrs) {
     C.getDeclAttrs(this)->Destroy(C);
-    invalidateAttrs(C);
+    invalidateAttrs();
     HasAttrs = false;
   }
   
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 4d90c7a..482e106 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -455,7 +455,7 @@
 /// with location to warn on and the source range[s] to report with the
 /// warning.
 bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
-                                  SourceRange &R2, ASTContext &Context) const {
+                                  SourceRange &R2) const {
   // Don't warn if the expr is type dependent. The type could end up
   // instantiating to void.
   if (isTypeDependent())
@@ -468,7 +468,7 @@
     return true;
   case ParenExprClass:
     return cast<ParenExpr>(this)->getSubExpr()->
-      isUnusedResultAWarning(Loc, R1, R2, Context);
+      isUnusedResultAWarning(Loc, R1, R2);
   case UnaryOperatorClass: {
     const UnaryOperator *UO = cast<UnaryOperator>(this);
     
@@ -491,7 +491,7 @@
         return false;
       break;
     case UnaryOperator::Extension:
-      return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Context);
+      return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2);
     }
     Loc = UO->getOperatorLoc();
     R1 = UO->getSubExpr()->getSourceRange();
@@ -501,8 +501,8 @@
     const BinaryOperator *BO = cast<BinaryOperator>(this);
     // Consider comma to have side effects if the LHS or RHS does.
     if (BO->getOpcode() == BinaryOperator::Comma)
-      return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Context) ||
-             BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Context);
+      return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2) ||
+             BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2);
       
     if (BO->isAssignmentOp())
       return false;
@@ -519,9 +519,9 @@
     // warning, warn about them.
     const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
     if (Exp->getLHS() && 
-        Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Context))
+        Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2))
       return true;
-    return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Context);
+    return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2);
   }
 
   case MemberExprClass:
@@ -554,8 +554,8 @@
       // If the callee has attribute pure, const, or warn_unused_result, warn
       // about it. void foo() { strlen("bar"); } should warn.
       if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CalleeDRE->getDecl()))
-        if (FD->getAttr<WarnUnusedResultAttr>(Context) ||
-            FD->getAttr<PureAttr>(Context) || FD->getAttr<ConstAttr>(Context)) {
+        if (FD->getAttr<WarnUnusedResultAttr>() ||
+            FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) {
           Loc = CE->getCallee()->getLocStart();
           R1 = CE->getCallee()->getSourceRange();
           
@@ -578,7 +578,7 @@
     const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt();
     if (!CS->body_empty())
       if (const Expr *E = dyn_cast<Expr>(CS->body_back()))
-        return E->isUnusedResultAWarning(Loc, R1, R2, Context);
+        return E->isUnusedResultAWarning(Loc, R1, R2);
     
     Loc = cast<StmtExpr>(this)->getLParenLoc();
     R1 = getSourceRange();
@@ -589,7 +589,7 @@
     // the cast is unused.
     if (getType()->isVoidType())
       return cast<CastExpr>(this)->getSubExpr()
-               ->isUnusedResultAWarning(Loc, R1, R2, Context);
+               ->isUnusedResultAWarning(Loc, R1, R2);
     Loc = cast<CStyleCastExpr>(this)->getLParenLoc();
     R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange();
     return true;
@@ -598,7 +598,7 @@
     // the cast is unused.
     if (getType()->isVoidType())
       return cast<CastExpr>(this)->getSubExpr()
-               ->isUnusedResultAWarning(Loc, R1, R2, Context);
+               ->isUnusedResultAWarning(Loc, R1, R2);
     Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc();
     R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange();
     return true;
@@ -606,11 +606,11 @@
   case ImplicitCastExprClass:
     // Check the operand, since implicit casts are inserted by Sema
     return cast<ImplicitCastExpr>(this)
-      ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Context);
+      ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2);
 
   case CXXDefaultArgExprClass:
     return cast<CXXDefaultArgExpr>(this)
-      ->getExpr()->isUnusedResultAWarning(Loc, R1, R2, Context);
+      ->getExpr()->isUnusedResultAWarning(Loc, R1, R2);
 
   case CXXNewExprClass:
     // FIXME: In theory, there might be new expressions that don't have side
@@ -619,7 +619,7 @@
     return false;
   case CXXExprWithTemporariesClass:
     return cast<CXXExprWithTemporaries>(this)
-      ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Context);
+      ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2);
   }
 }