Index: lib/AST/ASTImporter.cpp =================================================================== --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -11,6 +11,7 @@ // context into another context. // //===----------------------------------------------------------------------===// + #include "clang/AST/ASTImporter.h" #include "clang/AST/ASTContext.h" #include "clang/AST/ASTDiagnostic.h" @@ -226,7 +227,8 @@ Expr *VisitMemberExpr(MemberExpr *E); Expr *VisitCallExpr(CallExpr *E); }; -} +} // namespace clang + using namespace clang; //---------------------------------------------------------------------------- @@ -299,7 +301,7 @@ return C2.getDiagnostics().Report(Loc, DiagID); } }; -} +} // anonymous namespace static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, QualType T1, QualType T2); @@ -476,8 +478,8 @@ case Type::LValueReference: case Type::RValueReference: { - const ReferenceType *Ref1 = cast(T1); - const ReferenceType *Ref2 = cast(T2); + const auto *Ref1 = cast(T1); + const auto *Ref2 = cast(T2); if (Ref1->isSpelledAsLValue() != Ref2->isSpelledAsLValue()) return false; if (Ref1->isInnerRef() != Ref2->isInnerRef()) @@ -490,8 +492,8 @@ } case Type::MemberPointer: { - const MemberPointerType *MemPtr1 = cast(T1); - const MemberPointerType *MemPtr2 = cast(T2); + const auto *MemPtr1 = cast(T1); + const auto *MemPtr2 = cast(T2); if (!IsStructurallyEquivalent(Context, MemPtr1->getPointeeType(), MemPtr2->getPointeeType())) @@ -504,8 +506,8 @@ } case Type::ConstantArray: { - const ConstantArrayType *Array1 = cast(T1); - const ConstantArrayType *Array2 = cast(T2); + const auto *Array1 = cast(T1); + const auto *Array2 = cast(T2); if (!llvm::APInt::isSameValue(Array1->getSize(), Array2->getSize())) return false; @@ -522,8 +524,8 @@ break; case Type::VariableArray: { - const VariableArrayType *Array1 = cast(T1); - const VariableArrayType *Array2 = cast(T2); + const auto *Array1 = cast(T1); + const auto *Array2 = cast(T2); if (!IsStructurallyEquivalent(Context, Array1->getSizeExpr(), Array2->getSizeExpr())) return false; @@ -535,8 +537,8 @@ } case Type::DependentSizedArray: { - const DependentSizedArrayType *Array1 = cast(T1); - const DependentSizedArrayType *Array2 = cast(T2); + const auto *Array1 = cast(T1); + const auto *Array2 = cast(T2); if (!IsStructurallyEquivalent(Context, Array1->getSizeExpr(), Array2->getSizeExpr())) return false; @@ -548,10 +550,8 @@ } case Type::DependentSizedExtVector: { - const DependentSizedExtVectorType *Vec1 - = cast(T1); - const DependentSizedExtVectorType *Vec2 - = cast(T2); + const auto *Vec1 = cast(T1); + const auto *Vec2 = cast(T2); if (!IsStructurallyEquivalent(Context, Vec1->getSizeExpr(), Vec2->getSizeExpr())) return false; @@ -564,8 +564,8 @@ case Type::Vector: case Type::ExtVector: { - const VectorType *Vec1 = cast(T1); - const VectorType *Vec2 = cast(T2); + const auto *Vec1 = cast(T1); + const auto *Vec2 = cast(T2); if (!IsStructurallyEquivalent(Context, Vec1->getElementType(), Vec2->getElementType())) @@ -578,8 +578,8 @@ } case Type::FunctionProto: { - const FunctionProtoType *Proto1 = cast(T1); - const FunctionProtoType *Proto2 = cast(T2); + const auto *Proto1 = cast(T1); + const auto *Proto2 = cast(T2); if (Proto1->getNumParams() != Proto2->getNumParams()) return false; for (unsigned I = 0, N = Proto1->getNumParams(); I != N; ++I) { @@ -613,8 +613,8 @@ } case Type::FunctionNoProto: { - const FunctionType *Function1 = cast(T1); - const FunctionType *Function2 = cast(T2); + const auto *Function1 = cast(T1); + const auto *Function2 = cast(T2); if (!IsStructurallyEquivalent(Context, Function1->getReturnType(), Function2->getReturnType())) return false; @@ -700,8 +700,8 @@ break; case Type::TemplateTypeParm: { - const TemplateTypeParmType *Parm1 = cast(T1); - const TemplateTypeParmType *Parm2 = cast(T2); + const auto *Parm1 = cast(T1); + const auto *Parm2 = cast(T2); if (Parm1->getDepth() != Parm2->getDepth()) return false; if (Parm1->getIndex() != Parm2->getIndex()) @@ -714,10 +714,8 @@ } case Type::SubstTemplateTypeParm: { - const SubstTemplateTypeParmType *Subst1 - = cast(T1); - const SubstTemplateTypeParmType *Subst2 - = cast(T2); + const auto *Subst1 = cast(T1); + const auto *Subst2 = cast(T2); if (!IsStructurallyEquivalent(Context, QualType(Subst1->getReplacedParameter(), 0), QualType(Subst2->getReplacedParameter(), 0))) @@ -730,10 +728,8 @@ } case Type::SubstTemplateTypeParmPack: { - const SubstTemplateTypeParmPackType *Subst1 - = cast(T1); - const SubstTemplateTypeParmPackType *Subst2 - = cast(T2); + const auto *Subst1 = cast(T1); + const auto *Subst2 = cast(T2); if (!IsStructurallyEquivalent(Context, QualType(Subst1->getReplacedParameter(), 0), QualType(Subst2->getReplacedParameter(), 0))) @@ -745,10 +741,8 @@ break; } case Type::TemplateSpecialization: { - const TemplateSpecializationType *Spec1 - = cast(T1); - const TemplateSpecializationType *Spec2 - = cast(T2); + const auto *Spec1 = cast(T1); + const auto *Spec2 = cast(T2); if (!IsStructurallyEquivalent(Context, Spec1->getTemplateName(), Spec2->getTemplateName())) @@ -764,8 +758,8 @@ } case Type::Elaborated: { - const ElaboratedType *Elab1 = cast(T1); - const ElaboratedType *Elab2 = cast(T2); + const auto *Elab1 = cast(T1); + const auto *Elab2 = cast(T2); // CHECKME: what if a keyword is ETK_None or ETK_typename ? if (Elab1->getKeyword() != Elab2->getKeyword()) return false; @@ -781,8 +775,8 @@ } case Type::InjectedClassName: { - const InjectedClassNameType *Inj1 = cast(T1); - const InjectedClassNameType *Inj2 = cast(T2); + const auto *Inj1 = cast(T1); + const auto *Inj2 = cast(T2); if (!IsStructurallyEquivalent(Context, Inj1->getInjectedSpecializationType(), Inj2->getInjectedSpecializationType())) @@ -791,8 +785,8 @@ } case Type::DependentName: { - const DependentNameType *Typename1 = cast(T1); - const DependentNameType *Typename2 = cast(T2); + const auto *Typename1 = cast(T1); + const auto *Typename2 = cast(T2); if (!IsStructurallyEquivalent(Context, Typename1->getQualifier(), Typename2->getQualifier())) @@ -805,10 +799,8 @@ } case Type::DependentTemplateSpecialization: { - const DependentTemplateSpecializationType *Spec1 = - cast(T1); - const DependentTemplateSpecializationType *Spec2 = - cast(T2); + const auto *Spec1 = cast(T1); + const auto *Spec2 = cast(T2); if (!IsStructurallyEquivalent(Context, Spec1->getQualifier(), Spec2->getQualifier())) @@ -834,8 +826,8 @@ break; case Type::ObjCInterface: { - const ObjCInterfaceType *Iface1 = cast(T1); - const ObjCInterfaceType *Iface2 = cast(T2); + const auto *Iface1 = cast(T1); + const auto *Iface2 = cast(T2); if (!IsStructurallyEquivalent(Context, Iface1->getDecl(), Iface2->getDecl())) return false; @@ -843,8 +835,8 @@ } case Type::ObjCObject: { - const ObjCObjectType *Obj1 = cast(T1); - const ObjCObjectType *Obj2 = cast(T2); + const auto *Obj1 = cast(T1); + const auto *Obj2 = cast(T2); if (!IsStructurallyEquivalent(Context, Obj1->getBaseType(), Obj2->getBaseType())) @@ -861,8 +853,8 @@ } case Type::ObjCObjectPointer: { - const ObjCObjectPointerType *Ptr1 = cast(T1); - const ObjCObjectPointerType *Ptr2 = cast(T2); + const auto *Ptr1 = cast(T1); + const auto *Ptr2 = cast(T2); if (!IsStructurallyEquivalent(Context, Ptr1->getPointeeType(), Ptr2->getPointeeType())) @@ -886,7 +878,7 @@ /// \brief Determine structural equivalence of two fields. static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, FieldDecl *Field1, FieldDecl *Field2) { - RecordDecl *Owner2 = cast(Field2->getDeclContext()); + auto *Owner2 = cast(Field2->getDeclContext()); // For anonymous structs/unions, match up the anonymous struct/union type // declarations directly, so that we don't go off searching for anonymous @@ -970,7 +962,7 @@ ASTContext &Context = Anon->getASTContext(); QualType AnonTy = Context.getRecordType(Anon); - RecordDecl *Owner = dyn_cast(Anon->getDeclContext()); + auto *Owner = dyn_cast(Anon->getDeclContext()); if (!Owner) return None; @@ -1015,10 +1007,8 @@ // If both declarations are class template specializations, we know // the ODR applies, so check the template and template arguments. - ClassTemplateSpecializationDecl *Spec1 - = dyn_cast(D1); - ClassTemplateSpecializationDecl *Spec2 - = dyn_cast(D2); + const auto *Spec1 = dyn_cast(D1); + const auto *Spec2 = dyn_cast(D2); if (Spec1 && Spec2) { // Check that the specialized templates are the same. if (!IsStructurallyEquivalent(Context, Spec1->getSpecializedTemplate(), @@ -1047,8 +1037,8 @@ if (!D1 || !D2) return true; - if (CXXRecordDecl *D1CXX = dyn_cast(D1)) { - if (CXXRecordDecl *D2CXX = dyn_cast(D2)) { + if (auto *D1CXX = dyn_cast(D1)) { + if (auto *D2CXX = dyn_cast(D2)) { if (D1CXX->getNumBases() != D2CXX->getNumBases()) { if (Context.Complain) { Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) @@ -1362,8 +1352,8 @@ // FIXME: Switch on all declaration kinds. For now, we're just going to // check the obvious ones. - if (RecordDecl *Record1 = dyn_cast(D1)) { - if (RecordDecl *Record2 = dyn_cast(D2)) { + if (auto *Record1 = dyn_cast(D1)) { + if (auto *Record2 = dyn_cast(D2)) { // Check for equivalent structure names. IdentifierInfo *Name1 = Record1->getIdentifier(); if (!Name1 && Record1->getTypedefNameForAnonDecl()) @@ -1378,8 +1368,8 @@ // Record/non-record mismatch. Equivalent = false; } - } else if (EnumDecl *Enum1 = dyn_cast(D1)) { - if (EnumDecl *Enum2 = dyn_cast(D2)) { + } else if (auto *Enum1 = dyn_cast(D1)) { + if (auto *Enum2 = dyn_cast(D2)) { // Check for equivalent enum names. IdentifierInfo *Name1 = Enum1->getIdentifier(); if (!Name1 && Enum1->getTypedefNameForAnonDecl()) @@ -1394,8 +1384,8 @@ // Enum/non-enum mismatch Equivalent = false; } - } else if (TypedefNameDecl *Typedef1 = dyn_cast(D1)) { - if (TypedefNameDecl *Typedef2 = dyn_cast(D2)) { + } else if (const auto *Typedef1 = dyn_cast(D1)) { + if (const auto *Typedef2 = dyn_cast(D2)) { if (!::IsStructurallyEquivalent(Typedef1->getIdentifier(), Typedef2->getIdentifier()) || !::IsStructurallyEquivalent(*this, @@ -1406,9 +1396,8 @@ // Typedef/non-typedef mismatch. Equivalent = false; } - } else if (ClassTemplateDecl *ClassTemplate1 - = dyn_cast(D1)) { - if (ClassTemplateDecl *ClassTemplate2 = dyn_cast(D2)) { + } else if (auto *ClassTemplate1 = dyn_cast(D1)) { + if (auto *ClassTemplate2 = dyn_cast(D2)) { if (!::IsStructurallyEquivalent(ClassTemplate1->getIdentifier(), ClassTemplate2->getIdentifier()) || !::IsStructurallyEquivalent(*this, ClassTemplate1, ClassTemplate2)) @@ -1417,28 +1406,24 @@ // Class template/non-class-template mismatch. Equivalent = false; } - } else if (TemplateTypeParmDecl *TTP1= dyn_cast(D1)) { - if (TemplateTypeParmDecl *TTP2 = dyn_cast(D2)) { + } else if (auto *TTP1 = dyn_cast(D1)) { + if (auto *TTP2 = dyn_cast(D2)) { if (!::IsStructurallyEquivalent(*this, TTP1, TTP2)) Equivalent = false; } else { // Kind mismatch. Equivalent = false; } - } else if (NonTypeTemplateParmDecl *NTTP1 - = dyn_cast(D1)) { - if (NonTypeTemplateParmDecl *NTTP2 - = dyn_cast(D2)) { + } else if (auto *NTTP1 = dyn_cast(D1)) { + if (auto *NTTP2 = dyn_cast(D2)) { if (!::IsStructurallyEquivalent(*this, NTTP1, NTTP2)) Equivalent = false; } else { // Kind mismatch. Equivalent = false; } - } else if (TemplateTemplateParmDecl *TTP1 - = dyn_cast(D1)) { - if (TemplateTemplateParmDecl *TTP2 - = dyn_cast(D2)) { + } else if (auto *TTP1 = dyn_cast(D1)) { + if (auto *TTP2 = dyn_cast(D2)) { if (!::IsStructurallyEquivalent(*this, TTP1, TTP2)) Equivalent = false; } else { @@ -1688,7 +1673,7 @@ } QualType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { - TypedefNameDecl *ToDecl + const auto *ToDecl = dyn_cast_or_null(Importer.Import(T->getDecl())); if (!ToDecl) return QualType(); @@ -1751,7 +1736,7 @@ } QualType ASTNodeImporter::VisitRecordType(const RecordType *T) { - RecordDecl *ToDecl + const auto *ToDecl = dyn_cast_or_null(Importer.Import(T->getDecl())); if (!ToDecl) return QualType(); @@ -1760,7 +1745,7 @@ } QualType ASTNodeImporter::VisitEnumType(const EnumType *T) { - EnumDecl *ToDecl + const auto *ToDecl = dyn_cast_or_null(Importer.Import(T->getDecl())); if (!ToDecl) return QualType(); @@ -1831,7 +1816,7 @@ } QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { - ObjCInterfaceDecl *Class + const auto *Class = dyn_cast_or_null(Importer.Import(T->getDecl())); if (!Class) return QualType(); @@ -1855,8 +1840,7 @@ SmallVector Protocols; for (auto *P : T->quals()) { - ObjCProtocolDecl *Protocol - = dyn_cast_or_null(Importer.Import(P)); + auto *Protocol = dyn_cast_or_null(Importer.Import(P)); if (!Protocol) return QualType(); Protocols.push_back(Protocol); @@ -1917,8 +1901,8 @@ return; } - if (RecordDecl *FromRecord = dyn_cast(FromD)) { - if (RecordDecl *ToRecord = cast_or_null(ToD)) { + if (auto *FromRecord = dyn_cast(FromD)) { + if (auto *ToRecord = cast_or_null(ToD)) { if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) { ImportDefinition(FromRecord, ToRecord); } @@ -1926,8 +1910,8 @@ return; } - if (EnumDecl *FromEnum = dyn_cast(FromD)) { - if (EnumDecl *ToEnum = cast_or_null(ToD)) { + if (auto *FromEnum = dyn_cast(FromD)) { + if (auto *ToEnum = cast_or_null(ToD)) { if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { ImportDefinition(FromEnum, ToEnum); } @@ -1992,8 +1976,8 @@ To->startDefinition(); // Add base classes. - if (CXXRecordDecl *ToCXX = dyn_cast(To)) { - CXXRecordDecl *FromCXX = cast(From); + if (auto *ToCXX = dyn_cast(To)) { + const auto *FromCXX = cast(From); struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); @@ -2131,10 +2115,8 @@ TemplateParameterList *Params) { SmallVector ToParams; ToParams.reserve(Params->size()); - for (TemplateParameterList::iterator P = Params->begin(), - PEnd = Params->end(); - P != PEnd; ++P) { - Decl *To = Importer.Import(*P); + for (const auto &P : *Params) { + Decl *To = Importer.Import(P); if (!To) return nullptr; @@ -2169,7 +2151,7 @@ } case TemplateArgument::Declaration: { - ValueDecl *To = cast_or_null(Importer.Import(From.getAsDecl())); + auto *To = cast_or_null(Importer.Import(From.getAsDecl())); QualType ToType = Importer.Import(From.getParamTypeForDecl()); if (!To || ToType.isNull()) return TemplateArgument(); @@ -2239,7 +2221,7 @@ // something we're trying to import while completing ToRecord. Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); if (ToOrigin) { - RecordDecl *ToOriginRecord = dyn_cast(ToOrigin); + auto *ToOriginRecord = dyn_cast(ToOrigin); if (ToOriginRecord) ToRecord = ToOriginRecord; } @@ -2324,7 +2306,7 @@ // This is an anonymous namespace. Adopt an existing anonymous // namespace if we can. // FIXME: Not testable. - if (TranslationUnitDecl *TU = dyn_cast(DC)) + if (const auto *TU = dyn_cast(DC)) MergeWithNamespace = TU->getAnonymousNamespace(); else MergeWithNamespace = cast(DC)->getAnonymousNamespace(); @@ -2336,7 +2318,7 @@ if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Namespace)) continue; - if (NamespaceDecl *FoundNS = dyn_cast(FoundDecls[I])) { + if (auto *FoundNS = dyn_cast(FoundDecls[I])) { MergeWithNamespace = FoundNS; ConflictingDecls.clear(); break; @@ -2366,7 +2348,7 @@ // If this is an anonymous namespace, register it as the anonymous // namespace within its context. if (!Name) { - if (TranslationUnitDecl *TU = dyn_cast(DC)) + if (auto *TU = dyn_cast(DC)) TU->setAnonymousNamespace(ToNamespace); else cast(DC)->setAnonymousNamespace(ToNamespace); @@ -2401,8 +2383,7 @@ for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) continue; - if (TypedefNameDecl *FoundTypedef = - dyn_cast(FoundDecls[I])) { + if (auto *FoundTypedef = dyn_cast(FoundDecls[I])) { if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(), FoundTypedef->getUnderlyingType())) return Importer.Imported(D, FoundTypedef); @@ -2486,12 +2467,12 @@ continue; Decl *Found = FoundDecls[I]; - if (TypedefNameDecl *Typedef = dyn_cast(Found)) { - if (const TagType *Tag = Typedef->getUnderlyingType()->getAs()) + if (const auto *Typedef = dyn_cast(Found)) { + if (const auto *Tag = Typedef->getUnderlyingType()->getAs()) Found = Tag->getDecl(); } - if (EnumDecl *FoundEnum = dyn_cast(Found)) { + if (auto *FoundEnum = dyn_cast(Found)) { if (IsStructuralMatch(D, FoundEnum)) return Importer.Imported(D, FoundEnum); } @@ -2575,12 +2556,12 @@ continue; Decl *Found = FoundDecls[I]; - if (TypedefNameDecl *Typedef = dyn_cast(Found)) { - if (const TagType *Tag = Typedef->getUnderlyingType()->getAs()) + if (const auto *Typedef = dyn_cast(Found)) { + if (const auto *Tag = Typedef->getUnderlyingType()->getAs()) Found = Tag->getDecl(); } - if (RecordDecl *FoundRecord = dyn_cast(Found)) { + if (auto *FoundRecord = dyn_cast(Found)) { if (D->isAnonymousStructOrUnion() && FoundRecord->isAnonymousStructOrUnion()) { // If both anonymous structs/unions are in a record context, make sure @@ -2699,8 +2680,7 @@ if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) continue; - if (EnumConstantDecl *FoundEnumConstant - = dyn_cast(FoundDecls[I])) { + if (auto *FoundEnumConstant = dyn_cast(FoundDecls[I])) { if (IsStructuralMatch(D, FoundEnumConstant)) return Importer.Imported(D, FoundEnumConstant); } @@ -2754,7 +2734,7 @@ if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) continue; - if (FunctionDecl *FoundFunction = dyn_cast(FoundDecls[I])) { + if (auto *FoundFunction = dyn_cast(FoundDecls[I])) { if (FoundFunction->hasExternalFormalLinkage() && D->hasExternalFormalLinkage()) { if (Importer.IsStructurallyEquivalent(D->getType(), @@ -2823,7 +2803,7 @@ // Import the function parameters. SmallVector Parameters; for (auto P : D->params()) { - ParmVarDecl *ToP = cast_or_null(Importer.Import(P)); + auto *ToP = cast_or_null(Importer.Import(P)); if (!ToP) return nullptr; @@ -2834,7 +2814,7 @@ TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); FunctionDecl *ToFunction = nullptr; SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart()); - if (CXXConstructorDecl *FromConstructor = dyn_cast(D)) { + if (const auto *FromConstructor = dyn_cast(D)) { ToFunction = CXXConstructorDecl::Create(Importer.getToContext(), cast(DC), InnerLocStart, @@ -2850,8 +2830,7 @@ NameInfo, T, TInfo, D->isInlineSpecified(), D->isImplicit()); - } else if (CXXConversionDecl *FromConversion - = dyn_cast(D)) { + } else if (const auto *FromConversion = dyn_cast(D)) { ToFunction = CXXConversionDecl::Create(Importer.getToContext(), cast(DC), InnerLocStart, @@ -2860,7 +2839,7 @@ FromConversion->isExplicit(), D->isConstexpr(), Importer.Import(D->getLocEnd())); - } else if (CXXMethodDecl *Method = dyn_cast(D)) { + } else if (const auto *Method = dyn_cast(D)) { ToFunction = CXXMethodDecl::Create(Importer.getToContext(), cast(DC), InnerLocStart, @@ -2934,7 +2913,7 @@ } static unsigned getFieldIndex(Decl *F) { - RecordDecl *Owner = dyn_cast(F->getDeclContext()); + const auto *Owner = dyn_cast(F->getDeclContext()); if (!Owner) return 0; @@ -2965,7 +2944,7 @@ SmallVector FoundDecls; DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { - if (FieldDecl *FoundField = dyn_cast(FoundDecls[I])) { + if (auto *FoundField = dyn_cast(FoundDecls[I])) { // For anonymous fields, match up by index. if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) continue; @@ -3024,8 +3003,7 @@ SmallVector FoundDecls; DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { - if (IndirectFieldDecl *FoundField - = dyn_cast(FoundDecls[I])) { + if (auto *FoundField = dyn_cast(FoundDecls[I])) { // For anonymous indirect fields, match up by index. if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) continue; @@ -3054,7 +3032,7 @@ if (T.isNull()) return nullptr; - NamedDecl **NamedChain = + auto **NamedChain = new (Importer.getToContext())NamedDecl*[D->getChainingSize()]; unsigned i = 0; @@ -3094,7 +3072,7 @@ SmallVector FoundDecls; DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { - if (ObjCIvarDecl *FoundIvar = dyn_cast(FoundDecls[I])) { + if (auto *FoundIvar = dyn_cast(FoundDecls[I])) { if (Importer.IsStructurallyEquivalent(D->getType(), FoundIvar->getType())) { Importer.Imported(D, FoundIvar); @@ -3129,7 +3107,6 @@ Importer.Imported(D, ToIvar); LexicalDC->addDeclInternal(ToIvar); return ToIvar; - } Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) { @@ -3155,7 +3132,7 @@ if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) continue; - if (VarDecl *FoundVar = dyn_cast(FoundDecls[I])) { + if (auto *FoundVar = dyn_cast(FoundDecls[I])) { // We have found a variable that we may need to merge with. Check it. if (FoundVar->hasExternalFormalLinkage() && D->hasExternalFormalLinkage()) { @@ -3333,7 +3310,7 @@ SmallVector FoundDecls; DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { - if (ObjCMethodDecl *FoundMethod = dyn_cast(FoundDecls[I])) { + if (auto *FoundMethod = dyn_cast(FoundDecls[I])) { if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) continue; @@ -3411,7 +3388,7 @@ // Import the parameters SmallVector ToParams; for (auto *FromP : D->params()) { - ParmVarDecl *ToP = cast_or_null(Importer.Import(FromP)); + auto *ToP = cast_or_null(Importer.Import(FromP)); if (!ToP) return nullptr; @@ -3473,7 +3450,7 @@ if (ToD) return ToD; - ObjCInterfaceDecl *ToInterface + auto *ToInterface = cast_or_null(Importer.Import(D->getClassInterface())); if (!ToInterface) return nullptr; @@ -3509,7 +3486,7 @@ FromProtoEnd = D->protocol_end(); FromProto != FromProtoEnd; ++FromProto, ++FromProtoLoc) { - ObjCProtocolDecl *ToProto + auto *ToProto = cast_or_null(Importer.Import(*FromProto)); if (!ToProto) return nullptr; @@ -3520,7 +3497,6 @@ // FIXME: If we're merging, make sure that the protocol list is the same. ToCategory->setProtocolList(Protocols.data(), Protocols.size(), ProtocolLocs.data(), Importer.getToContext()); - } else { Importer.Imported(D, ToCategory); } @@ -3530,7 +3506,7 @@ // If we have an implementation, import it as well. if (D->getImplementation()) { - ObjCCategoryImplDecl *Impl + auto *Impl = cast_or_null( Importer.Import(D->getImplementation())); if (!Impl) @@ -3563,8 +3539,7 @@ FromProtoEnd = From->protocol_end(); FromProto != FromProtoEnd; ++FromProto, ++FromProtoLoc) { - ObjCProtocolDecl *ToProto - = cast_or_null(Importer.Import(*FromProto)); + auto *ToProto = cast_or_null(Importer.Import(*FromProto)); if (!ToProto) return true; Protocols.push_back(ToProto); @@ -3724,8 +3699,7 @@ FromProtoEnd = From->protocol_end(); FromProto != FromProtoEnd; ++FromProto, ++FromProtoLoc) { - ObjCProtocolDecl *ToProto - = cast_or_null(Importer.Import(*FromProto)); + auto *ToProto = cast_or_null(Importer.Import(*FromProto)); if (!ToProto) return true; Protocols.push_back(ToProto); @@ -3743,7 +3717,7 @@ // If we have an @implementation, import it as well. if (From->getImplementation()) { - ObjCImplementationDecl *Impl = cast_or_null( + auto *Impl = cast_or_null( Importer.Import(From->getImplementation())); if (!Impl) return true; @@ -3839,7 +3813,7 @@ } Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { - ObjCCategoryDecl *Category = cast_or_null( + auto *Category = cast_or_null( Importer.Import(D->getCategoryDecl())); if (!Category) return nullptr; @@ -3878,7 +3852,7 @@ Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { // Find the corresponding interface. - ObjCInterfaceDecl *Iface = cast_or_null( + auto *Iface = cast_or_null( Importer.Import(D->getClassInterface())); if (!Iface) return nullptr; @@ -3969,8 +3943,7 @@ SmallVector FoundDecls; DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { - if (ObjCPropertyDecl *FoundProp - = dyn_cast(FoundDecls[I])) { + if (auto *FoundProp = dyn_cast(FoundDecls[I])) { // Check property types. if (!Importer.IsStructurallyEquivalent(D->getType(), FoundProp->getType())) { @@ -4022,7 +3995,7 @@ } Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { - ObjCPropertyDecl *Property = cast_or_null( + auto *Property = cast_or_null( Importer.Import(D->getPropertyDecl())); if (!Property) return nullptr; @@ -4039,7 +4012,7 @@ return nullptr; } - ObjCImplDecl *InImpl = dyn_cast(LexicalDC); + auto *InImpl = dyn_cast(LexicalDC); if (!InImpl) return nullptr; @@ -4179,7 +4152,7 @@ // If this record has a definition in the translation unit we're coming from, // but this particular declaration is not that definition, import the // definition and map to that. - CXXRecordDecl *Definition + auto *Definition = cast_or_null(D->getTemplatedDecl()->getDefinition()); if (Definition && Definition != D->getTemplatedDecl()) { Decl *ImportedDef @@ -4210,8 +4183,7 @@ continue; Decl *Found = FoundDecls[I]; - if (ClassTemplateDecl *FoundTemplate - = dyn_cast(Found)) { + if (auto *FoundTemplate = dyn_cast(Found)) { if (IsStructuralMatch(D, FoundTemplate)) { // The class templates structurally match; call it the same template. // FIXME: We may be filling in a forward declaration here. Handle @@ -4290,7 +4262,7 @@ return Importer.Imported(D, ImportedDef); } - ClassTemplateDecl *ClassTemplate + auto *ClassTemplate = cast_or_null(Importer.Import( D->getSpecializedTemplate())); if (!ClassTemplate) @@ -4371,7 +4343,7 @@ // from, // but this particular declaration is not that definition, import the // definition and map to that. - VarDecl *Definition = + auto *Definition = cast_or_null(D->getTemplatedDecl()->getDefinition()); if (Definition && Definition != D->getTemplatedDecl()) { Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate()); @@ -4402,7 +4374,7 @@ continue; Decl *Found = FoundDecls[I]; - if (VarTemplateDecl *FoundTemplate = dyn_cast(Found)) { + if (auto *FoundTemplate = dyn_cast(Found)) { if (IsStructuralMatch(D, FoundTemplate)) { // The variable templates structurally match; call it the same template. Importer.Imported(D->getTemplatedDecl(), @@ -4488,7 +4460,7 @@ return Importer.Imported(D, ImportedDef); } - VarTemplateDecl *VarTemplate = cast_or_null( + auto *VarTemplate = cast_or_null( Importer.Import(D->getSpecializedTemplate())); if (!VarTemplate) return nullptr; @@ -4654,8 +4626,7 @@ Stmt *ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc()); - LabelDecl *ToLabelDecl = - cast_or_null(Importer.Import(S->getDecl())); + auto *ToLabelDecl = cast_or_null(Importer.Import(S->getDecl())); if (!ToLabelDecl && S->getDecl()) return nullptr; Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); @@ -4721,7 +4692,7 @@ Expr *ToCondition = Importer.Import(S->getCond()); if (!ToCondition && S->getCond()) return nullptr; - SwitchStmt *ToStmt = new (Importer.getToContext()) SwitchStmt( + auto *ToStmt = new (Importer.getToContext()) SwitchStmt( Importer.getToContext(), ToConditionVariable, ToCondition); Stmt *ToBody = Importer.Import(S->getBody()); @@ -4733,7 +4704,7 @@ SwitchCase *LastChainedSwitchCase = nullptr; for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; SC = SC->getNextSwitchCase()) { - SwitchCase *ToSC = dyn_cast_or_null(Importer.Import(SC)); + auto *ToSC = dyn_cast_or_null(Importer.Import(SC)); if (!ToSC) return nullptr; if (LastChainedSwitchCase) @@ -4850,8 +4821,8 @@ Expr *ToRetExpr = Importer.Import(S->getRetValue()); if (!ToRetExpr && S->getRetValue()) return nullptr; - VarDecl *NRVOCandidate = const_cast(S->getNRVOCandidate()); - VarDecl *ToNRVOCandidate = cast_or_null(Importer.Import(NRVOCandidate)); + auto *NRVOCandidate = const_cast(S->getNRVOCandidate()); + auto *ToNRVOCandidate = cast_or_null(Importer.Import(NRVOCandidate)); if (!ToNRVOCandidate && NRVOCandidate) return nullptr; return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr, @@ -4893,11 +4864,11 @@ } Stmt *ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { - DeclStmt *ToRange = + auto *ToRange = dyn_cast_or_null(Importer.Import(S->getRangeStmt())); if (!ToRange && S->getRangeStmt()) return nullptr; - DeclStmt *ToBeginEnd = + auto *ToBeginEnd = dyn_cast_or_null(Importer.Import(S->getBeginEndStmt())); if (!ToBeginEnd && S->getBeginEndStmt()) return nullptr; @@ -4907,7 +4878,7 @@ Expr *ToInc = Importer.Import(S->getInc()); if (!ToInc && S->getInc()) return nullptr; - DeclStmt *ToLoopVar = + auto *ToLoopVar = dyn_cast_or_null(Importer.Import(S->getLoopVarStmt())); if (!ToLoopVar && S->getLoopVarStmt()) return nullptr; @@ -5035,7 +5006,7 @@ } Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { - ValueDecl *ToD = cast_or_null(Importer.Import(E->getDecl())); + auto *ToD = cast_or_null(Importer.Import(E->getDecl())); if (!ToD) return nullptr; @@ -5238,7 +5209,7 @@ if (T.isNull()) return nullptr; - CXXConstructorDecl *ToCCD = + auto *ToCCD = dyn_cast(Importer.Import(E->getConstructor())); if (!ToCCD && E->getConstructor()) return nullptr; @@ -5275,7 +5246,7 @@ if (!ToBase && E->getBase()) return nullptr; - ValueDecl *ToMember = dyn_cast(Importer.Import(E->getMemberDecl())); + auto *ToMember = dyn_cast(Importer.Import(E->getMemberDecl())); if (!ToMember && E->getMemberDecl()) return nullptr; @@ -5322,8 +5293,7 @@ ToArgs[ai] = ToArg; } - Expr **ToArgs_Copied = new (Importer.getToContext()) - Expr*[NumArgs]; + auto **ToArgs_Copied = new (Importer.getToContext()) Expr*[NumArgs]; for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) ToArgs_Copied[ai] = ToArgs[ai]; @@ -5418,11 +5388,11 @@ // Record the imported declaration. ImportedDecls[FromD] = ToD; - if (TagDecl *FromTag = dyn_cast(FromD)) { + if (auto *FromTag = dyn_cast(FromD)) { // Keep track of anonymous tags that have an associated typedef. if (FromTag->getTypedefNameForAnonDecl()) AnonTagsWithPendingTypedefs.push_back(FromTag); - } else if (TypedefNameDecl *FromTypedef = dyn_cast(FromD)) { + } else if (auto *FromTypedef = dyn_cast(FromD)) { // When we've finished transforming a typedef, see whether it was the // typedef for an anonymous tag. for (SmallVectorImpl::iterator @@ -5430,7 +5400,7 @@ FromTagEnd = AnonTagsWithPendingTypedefs.end(); FromTag != FromTagEnd; ++FromTag) { if ((*FromTag)->getTypedefNameForAnonDecl() == FromTypedef) { - if (TagDecl *ToTag = cast_or_null(Import(*FromTag))) { + if (auto *ToTag = cast_or_null(Import(*FromTag))) { // We found the typedef for an anonymous tag; link them. ToTag->setTypedefNameForAnonDecl(cast(ToD)); AnonTagsWithPendingTypedefs.erase(FromTag); @@ -5447,14 +5417,14 @@ if (!FromDC) return FromDC; - DeclContext *ToDC = cast_or_null(Import(cast(FromDC))); + auto *ToDC = cast_or_null(Import(cast(FromDC))); if (!ToDC) return nullptr; // When we're using a record/enum/Objective-C class/protocol as a context, we // need it to have a definition. - if (RecordDecl *ToRecord = dyn_cast(ToDC)) { - RecordDecl *FromRecord = cast(FromDC); + if (auto *ToRecord = dyn_cast(ToDC)) { + auto *FromRecord = cast(FromDC); if (ToRecord->isCompleteDefinition()) { // Do nothing. } else if (FromRecord->isCompleteDefinition()) { @@ -5463,8 +5433,8 @@ } else { CompleteDecl(ToRecord); } - } else if (EnumDecl *ToEnum = dyn_cast(ToDC)) { - EnumDecl *FromEnum = cast(FromDC); + } else if (auto *ToEnum = dyn_cast(ToDC)) { + auto *FromEnum = cast(FromDC); if (ToEnum->isCompleteDefinition()) { // Do nothing. } else if (FromEnum->isCompleteDefinition()) { @@ -5473,8 +5443,8 @@ } else { CompleteDecl(ToEnum); } - } else if (ObjCInterfaceDecl *ToClass = dyn_cast(ToDC)) { - ObjCInterfaceDecl *FromClass = cast(FromDC); + } else if (auto *ToClass = dyn_cast(ToDC)) { + auto *FromClass = cast(FromDC); if (ToClass->getDefinition()) { // Do nothing. } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { @@ -5483,8 +5453,8 @@ } else { CompleteDecl(ToClass); } - } else if (ObjCProtocolDecl *ToProto = dyn_cast(ToDC)) { - ObjCProtocolDecl *FromProto = cast(FromDC); + } else if (auto *ToProto = dyn_cast(ToDC)) { + auto *FromProto = cast(FromDC); if (ToProto->getDefinition()) { // Do nothing. } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { @@ -5539,14 +5509,13 @@ return nullptr; case NestedNameSpecifier::Namespace: - if (NamespaceDecl *NS = - cast(Import(FromNNS->getAsNamespace()))) { + if (auto *NS = cast(Import(FromNNS->getAsNamespace()))) { return NestedNameSpecifier::Create(ToContext, prefix, NS); } return nullptr; case NestedNameSpecifier::NamespaceAlias: - if (NamespaceAliasDecl *NSAD = + if (auto *NSAD = cast(Import(FromNNS->getAsNamespaceAlias()))) { return NestedNameSpecifier::Create(ToContext, prefix, NSAD); } @@ -5556,8 +5525,7 @@ return NestedNameSpecifier::GlobalSpecifier(ToContext); case NestedNameSpecifier::Super: - if (CXXRecordDecl *RD = - cast(Import(FromNNS->getAsRecordDecl()))) { + if (auto *RD = cast(Import(FromNNS->getAsRecordDecl()))) { return NestedNameSpecifier::SuperSpecifier(ToContext, RD); } return nullptr; @@ -5586,7 +5554,7 @@ TemplateName ASTImporter::Import(TemplateName From) { switch (From.getKind()) { case TemplateName::Template: - if (TemplateDecl *ToTemplate + if (auto *ToTemplate = cast_or_null(Import(From.getAsTemplateDecl()))) return TemplateName(ToTemplate); @@ -5595,10 +5563,8 @@ case TemplateName::OverloadedTemplate: { OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); UnresolvedSet<2> ToTemplates; - for (OverloadedTemplateStorage::iterator I = FromStorage->begin(), - E = FromStorage->end(); - I != E; ++I) { - if (NamedDecl *To = cast_or_null(Import(*I))) + for (const auto &I : *FromStorage) { + if (auto *To = cast_or_null(Import(I))) ToTemplates.addDecl(To); else return TemplateName(); @@ -5613,7 +5579,7 @@ if (!Qualifier) return TemplateName(); - if (TemplateDecl *ToTemplate + if (auto *ToTemplate = cast_or_null(Import(From.getAsTemplateDecl()))) return ToContext.getQualifiedTemplateName(Qualifier, QTN->hasTemplateKeyword(), @@ -5639,7 +5605,7 @@ case TemplateName::SubstTemplateTemplateParm: { SubstTemplateTemplateParmStorage *subst = From.getAsSubstTemplateTemplateParm(); - TemplateTemplateParmDecl *param + auto *param = cast_or_null(Import(subst->getParameter())); if (!param) return TemplateName(); @@ -5653,7 +5619,7 @@ case TemplateName::SubstTemplateTemplateParmPack: { SubstTemplateTemplateParmPackStorage *SubstPack = From.getAsSubstTemplateTemplateParmPack(); - TemplateTemplateParmDecl *Param + auto *Param = cast_or_null( Import(SubstPack->getParameterPack())); if (!Param) @@ -5744,10 +5710,10 @@ if (!To) return; - if (DeclContext *FromDC = cast(From)) { + if (auto *FromDC = cast(From)) { ASTNodeImporter Importer(*this); - if (RecordDecl *ToRecord = dyn_cast(To)) { + if (auto *ToRecord = dyn_cast(To)) { if (!ToRecord->getDefinition()) { Importer.ImportDefinition(cast(FromDC), ToRecord, ASTNodeImporter::IDK_Everything); @@ -5755,7 +5721,7 @@ } } - if (EnumDecl *ToEnum = dyn_cast(To)) { + if (auto *ToEnum = dyn_cast(To)) { if (!ToEnum->getDefinition()) { Importer.ImportDefinition(cast(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); @@ -5763,7 +5729,7 @@ } } - if (ObjCInterfaceDecl *ToIFace = dyn_cast(To)) { + if (auto *ToIFace = dyn_cast(To)) { if (!ToIFace->getDefinition()) { Importer.ImportDefinition(cast(FromDC), ToIFace, ASTNodeImporter::IDK_Everything); @@ -5771,7 +5737,7 @@ } } - if (ObjCProtocolDecl *ToProto = dyn_cast(To)) { + if (auto *ToProto = dyn_cast(To)) { if (!ToProto->getDefinition()) { Importer.ImportDefinition(cast(FromDC), ToProto, ASTNodeImporter::IDK_Everything); @@ -5882,15 +5848,15 @@ } void ASTImporter::CompleteDecl (Decl *D) { - if (ObjCInterfaceDecl *ID = dyn_cast(D)) { + if (auto *ID = dyn_cast(D)) { if (!ID->getDefinition()) ID->startDefinition(); } - else if (ObjCProtocolDecl *PD = dyn_cast(D)) { + else if (auto *PD = dyn_cast(D)) { if (!PD->getDefinition()) PD->startDefinition(); } - else if (TagDecl *TD = dyn_cast(D)) { + else if (auto *TD = dyn_cast(D)) { if (!TD->getDefinition() && !TD->isBeingDefined()) { TD->startDefinition(); TD->setCompleteDefinition(true);