diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-06-24 04:05:48 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-06-24 04:05:48 +0000 |
commit | ba5c7ce848b313a3ed284dad37e49bb77f010811 (patch) | |
tree | 39ffe2381faae494f3e44a01cd2c649486fc8ee8 /lib/Sema | |
parent | cdc2235915bde8888291f6fd2090c6509e1b07b5 (diff) | |
download | clang-ba5c7ce848b313a3ed284dad37e49bb77f010811.tar.gz |
Use more ArrayRefs
No functional change is intended, just a small refactoring.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273647 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 7 | ||||
-rw-r--r-- | lib/Sema/SemaCodeComplete.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 47 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 8 | ||||
-rw-r--r-- | lib/Sema/SemaLambda.cpp | 7 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateDeduction.cpp | 8 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 20 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateDecl.cpp | 8 | ||||
-rw-r--r-- | lib/Sema/TreeTransform.h | 46 |
11 files changed, 73 insertions, 92 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 5761ece2fa..49548608a6 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -9186,13 +9186,10 @@ static void diagnoseArrayStarInParamType(Sema &S, QualType PType, /// takes care of any checks that cannot be performed on the /// declaration itself, e.g., that the types of each of the function /// parameters are complete. -bool Sema::CheckParmsForFunctionDef(ParmVarDecl *const *P, - ParmVarDecl *const *PEnd, +bool Sema::CheckParmsForFunctionDef(ArrayRef<ParmVarDecl *> Parameters, bool CheckParameterNames) { bool HasInvalidParm = false; - for (; P != PEnd; ++P) { - ParmVarDecl *Param = *P; - + for (ParmVarDecl *Param : Parameters) { // C99 6.7.5.3p4: the parameters in a parameter type list in a // function declarator that is part of a function definition of // that function shall not have incomplete type. diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 2b226b8e75..d910c6f8ad 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -3208,7 +3208,7 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, // We need to have names for all of the parameters, if we're going to // generate a forwarding call. - for (auto P : Method->params()) + for (auto P : Method->parameters()) if (!P->getDeclName()) return; @@ -3240,7 +3240,7 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, Overridden->getNameAsString())); Builder.AddChunk(CodeCompletionString::CK_LeftParen); bool FirstParam = true; - for (auto P : Method->params()) { + for (auto P : Method->parameters()) { if (FirstParam) FirstParam = false; else diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 0e9e9e55ff..c46e39dc9a 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4134,7 +4134,7 @@ InjectAnonymousStructOrUnionMembers(Sema &SemaRef, Scope *S, DeclContext *Owner, IndirectFieldDecl *IndirectField = IndirectFieldDecl::Create( SemaRef.Context, Owner, VD->getLocation(), VD->getIdentifier(), - VD->getType(), NamedChain, Chaining.size()); + VD->getType(), {NamedChain, Chaining.size()}); for (const auto *Attr : VD->attrs()) IndirectField->addAttr(Attr->clone(SemaRef.Context)); @@ -8529,12 +8529,10 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, } llvm::SmallPtrSet<const Type *, 16> ValidTypes; - for (auto Param : NewFD->params()) + for (auto Param : NewFD->parameters()) checkIsValidOpenCLKernelParameter(*this, D, Param, ValidTypes); } - for (FunctionDecl::param_iterator PI = NewFD->param_begin(), - PE = NewFD->param_end(); PI != PE; ++PI) { - ParmVarDecl *Param = *PI; + for (const ParmVarDecl *Param : NewFD->parameters()) { QualType PT = Param->getType(); // OpenCL 2.0 pipe restrictions forbids pipe packet types to be non-value @@ -10866,26 +10864,23 @@ ParmVarDecl *Sema::BuildParmVarDeclForTypedef(DeclContext *DC, return Param; } -void Sema::DiagnoseUnusedParameters(ParmVarDecl * const *Param, - ParmVarDecl * const *ParamEnd) { +void Sema::DiagnoseUnusedParameters(ArrayRef<ParmVarDecl *> Parameters) { // Don't diagnose unused-parameter errors in template instantiations; we // will already have done so in the template itself. if (!ActiveTemplateInstantiations.empty()) return; - for (; Param != ParamEnd; ++Param) { - if (!(*Param)->isReferenced() && (*Param)->getDeclName() && - !(*Param)->hasAttr<UnusedAttr>()) { - Diag((*Param)->getLocation(), diag::warn_unused_parameter) - << (*Param)->getDeclName(); + for (const ParmVarDecl *Parameter : Parameters) { + if (!Parameter->isReferenced() && Parameter->getDeclName() && + !Parameter->hasAttr<UnusedAttr>()) { + Diag(Parameter->getLocation(), diag::warn_unused_parameter) + << Parameter->getDeclName(); } } } -void Sema::DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Param, - ParmVarDecl * const *ParamEnd, - QualType ReturnTy, - NamedDecl *D) { +void Sema::DiagnoseSizeOfParametersAndReturnValue( + ArrayRef<ParmVarDecl *> Parameters, QualType ReturnTy, NamedDecl *D) { if (LangOpts.NumLargeByValueCopy == 0) // No check. return; @@ -10900,14 +10895,14 @@ void Sema::DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Param, // Warn if any parameter is pass-by-value and larger than the specified // threshold. - for (; Param != ParamEnd; ++Param) { - QualType T = (*Param)->getType(); + for (const ParmVarDecl *Parameter : Parameters) { + QualType T = Parameter->getType(); if (T->isDependentType() || !T.isPODType(Context)) continue; unsigned Size = Context.getTypeSizeInChars(T).getQuantity(); if (Size > LangOpts.NumLargeByValueCopy) - Diag((*Param)->getLocation(), diag::warn_parameter_size) - << (*Param)->getDeclName() << Size; + Diag(Parameter->getLocation(), diag::warn_parameter_size) + << Parameter->getDeclName() << Size; } } @@ -11249,11 +11244,11 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D, PushDeclContext(FnBodyScope, FD); // Check the validity of our function parameters - CheckParmsForFunctionDef(FD->param_begin(), FD->param_end(), + CheckParmsForFunctionDef(FD->parameters(), /*CheckParameterNames=*/true); // Introduce our parameters into the function scope - for (auto Param : FD->params()) { + for (auto Param : FD->parameters()) { Param->setOwningFunction(FD); // If this has an identifier, add it to the scope stack. @@ -11467,8 +11462,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, if (!FD->isInvalidDecl()) { // Don't diagnose unused parameters of defaulted or deleted functions. if (!FD->isDeleted() && !FD->isDefaulted()) - DiagnoseUnusedParameters(FD->param_begin(), FD->param_end()); - DiagnoseSizeOfParametersAndReturnValue(FD->param_begin(), FD->param_end(), + DiagnoseUnusedParameters(FD->parameters()); + DiagnoseSizeOfParametersAndReturnValue(FD->parameters(), FD->getReturnType(), FD); // If this is a structor, we need a vtable. @@ -11539,8 +11534,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, assert(MD == getCurMethodDecl() && "Method parsing confused"); MD->setBody(Body); if (!MD->isInvalidDecl()) { - DiagnoseUnusedParameters(MD->param_begin(), MD->param_end()); - DiagnoseSizeOfParametersAndReturnValue(MD->param_begin(), MD->param_end(), + DiagnoseUnusedParameters(MD->parameters()); + DiagnoseSizeOfParametersAndReturnValue(MD->parameters(), MD->getReturnType(), MD); if (Body) diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 8eeaef7df5..8c0e9eaddf 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -11823,7 +11823,7 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) { diag::err_operator_overload_static) << FnDecl->getDeclName(); } else { bool ClassOrEnumParam = false; - for (auto Param : FnDecl->params()) { + for (auto Param : FnDecl->parameters()) { QualType ParamType = Param->getType().getNonReferenceType(); if (ParamType->isDependentType() || ParamType->isRecordType() || ParamType->isEnumeralType()) { @@ -11845,7 +11845,7 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) { // Only the function-call operator allows default arguments // (C++ [over.call]p1). if (Op != OO_Call) { - for (auto Param : FnDecl->params()) { + for (auto Param : FnDecl->parameters()) { if (Param->hasDefaultArg()) return Diag(Param->getLocation(), diag::err_operator_overload_default_arg) @@ -12110,7 +12110,7 @@ bool Sema::CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl) { // A parameter-declaration-clause containing a default argument is not // equivalent to any of the permitted forms. - for (auto Param : FnDecl->params()) { + for (auto Param : FnDecl->parameters()) { if (Param->hasDefaultArg()) { Diag(Param->getDefaultArgRange().getBegin(), diag::err_literal_operator_default_argument) diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 41166960fa..f4d82b3c31 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -319,11 +319,11 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) { PushOnScopeChains(MDecl->getCmdDecl(), FnBodyScope); // The ObjC parser requires parameter names so there's no need to check. - CheckParmsForFunctionDef(MDecl->param_begin(), MDecl->param_end(), + CheckParmsForFunctionDef(MDecl->parameters(), /*CheckParameterNames=*/false); // Introduce all of the other parameters into this scope. - for (auto *Param : MDecl->params()) { + for (auto *Param : MDecl->parameters()) { if (!Param->isInvalidDecl() && getLangOpts().ObjCAutoRefCount && !HasExplicitOwnershipAttr(*this, Param)) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index ab1180ed99..05aa18c633 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -12028,8 +12028,7 @@ void Sema::ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, // Set the parameters on the block decl. if (!Params.empty()) { CurBlock->TheDecl->setParams(Params); - CheckParmsForFunctionDef(CurBlock->TheDecl->param_begin(), - CurBlock->TheDecl->param_end(), + CheckParmsForFunctionDef(CurBlock->TheDecl->parameters(), /*CheckParameterNames=*/false); } @@ -12037,7 +12036,7 @@ void Sema::ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, ProcessDeclAttributes(CurScope, CurBlock->TheDecl, ParamInfo); // Put the parameter variables in scope. - for (auto AI : CurBlock->TheDecl->params()) { + for (auto AI : CurBlock->TheDecl->parameters()) { AI->setOwningFunction(CurBlock->TheDecl); // If this has an identifier, add it to the scope stack. @@ -12137,8 +12136,7 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, BlockTy = Context.getFunctionType(RetTy, None, EPI); } - DiagnoseUnusedParameters(BSI->TheDecl->param_begin(), - BSI->TheDecl->param_end()); + DiagnoseUnusedParameters(BSI->TheDecl->parameters()); BlockTy = Context.getBlockPointerType(BlockTy); // If needed, diagnose invalid gotos and switches in the block. diff --git a/lib/Sema/SemaLambda.cpp b/lib/Sema/SemaLambda.cpp index 1f5f63a414..73e0077d19 100644 --- a/lib/Sema/SemaLambda.cpp +++ b/lib/Sema/SemaLambda.cpp @@ -415,11 +415,10 @@ CXXMethodDecl *Sema::startLambdaDefinition(CXXRecordDecl *Class, // Add parameters. if (!Params.empty()) { Method->setParams(Params); - CheckParmsForFunctionDef(const_cast<ParmVarDecl **>(Params.begin()), - const_cast<ParmVarDecl **>(Params.end()), + CheckParmsForFunctionDef(Params, /*CheckParameterNames=*/false); - - for (auto P : Method->params()) + + for (auto P : Method->parameters()) P->setOwningFunction(Method); } diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index e5c24252ed..3bfa34c63f 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -2480,7 +2480,7 @@ Sema::SubstituteExplicitTemplateArguments( if (ExplicitTemplateArgs.size() == 0) { // No arguments to substitute; just copy over the parameter types and // fill in the function type. - for (auto P : Function->params()) + for (auto P : Function->parameters()) ParamTypes.push_back(P->getType()); if (FunctionType) @@ -2563,8 +2563,7 @@ Sema::SubstituteExplicitTemplateArguments( // return type, substitute it after the arguments to ensure we substitute // in lexical order. if (Proto->hasTrailingReturn()) { - if (SubstParmTypes(Function->getLocation(), - Function->param_begin(), Function->getNumParams(), + if (SubstParmTypes(Function->getLocation(), Function->parameters(), Proto->getExtParameterInfosOrNull(), MultiLevelTemplateArgumentList(*ExplicitArgumentList), ParamTypes, /*params*/ nullptr, ExtParamInfos)) @@ -2601,8 +2600,7 @@ Sema::SubstituteExplicitTemplateArguments( // Instantiate the types of each of the function parameters given the // explicitly-specified template arguments if we didn't do so earlier. if (!Proto->hasTrailingReturn() && - SubstParmTypes(Function->getLocation(), - Function->param_begin(), Function->getNumParams(), + SubstParmTypes(Function->getLocation(), Function->parameters(), Proto->getExtParameterInfosOrNull(), MultiLevelTemplateArgumentList(*ExplicitArgumentList), ParamTypes, /*params*/ nullptr, ExtParamInfos)) diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 24a47d1942..10a3b865bc 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -1714,23 +1714,21 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm, /// \brief Substitute the given template arguments into the given set of /// parameters, producing the set of parameter types that would be generated /// from such a substitution. -bool Sema::SubstParmTypes(SourceLocation Loc, - ParmVarDecl **Params, unsigned NumParams, - const FunctionProtoType::ExtParameterInfo *ExtParamInfos, - const MultiLevelTemplateArgumentList &TemplateArgs, - SmallVectorImpl<QualType> &ParamTypes, - SmallVectorImpl<ParmVarDecl *> *OutParams, - ExtParameterInfoBuilder &ParamInfos) { +bool Sema::SubstParmTypes( + SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, + const FunctionProtoType::ExtParameterInfo *ExtParamInfos, + const MultiLevelTemplateArgumentList &TemplateArgs, + SmallVectorImpl<QualType> &ParamTypes, + SmallVectorImpl<ParmVarDecl *> *OutParams, + ExtParameterInfoBuilder &ParamInfos) { assert(!ActiveTemplateInstantiations.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack"); TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, DeclarationName()); - return Instantiator.TransformFunctionTypeParams(Loc, Params, NumParams, - nullptr, ExtParamInfos, - ParamTypes, OutParams, - ParamInfos); + return Instantiator.TransformFunctionTypeParams( + Loc, Params, nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos); } /// \brief Perform substitution on the base class specifiers of the diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 78de86e49d..58c0ab027e 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -803,7 +803,7 @@ Decl *TemplateDeclInstantiator::VisitIndirectFieldDecl(IndirectFieldDecl *D) { QualType T = cast<FieldDecl>(NamedChain[i-1])->getType(); IndirectFieldDecl *IndirectField = IndirectFieldDecl::Create( SemaRef.Context, Owner, D->getLocation(), D->getIdentifier(), T, - NamedChain, D->getChainingSize()); + {NamedChain, D->getChainingSize()}); for (const auto *Attr : D->attrs()) IndirectField->addAttr(Attr->clone(SemaRef.Context)); @@ -3301,9 +3301,9 @@ TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D, // synthesized in the method declaration. SmallVector<QualType, 4> ParamTypes; Sema::ExtParameterInfoBuilder ExtParamInfos; - if (SemaRef.SubstParmTypes(D->getLocation(), D->param_begin(), - D->getNumParams(), nullptr, TemplateArgs, - ParamTypes, &Params, ExtParamInfos)) + if (SemaRef.SubstParmTypes(D->getLocation(), D->parameters(), nullptr, + TemplateArgs, ParamTypes, &Params, + ExtParamInfos)) return nullptr; } diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index a7b994d986..c90e0fa2ca 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -612,13 +612,12 @@ public: /// variables vector are acceptable. /// /// Return true on error. - bool TransformFunctionTypeParams(SourceLocation Loc, - ParmVarDecl **Params, unsigned NumParams, - const QualType *ParamTypes, - const FunctionProtoType::ExtParameterInfo *ParamInfos, - SmallVectorImpl<QualType> &PTypes, - SmallVectorImpl<ParmVarDecl*> *PVars, - Sema::ExtParameterInfoBuilder &PInfos); + bool TransformFunctionTypeParams( + SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, + const QualType *ParamTypes, + const FunctionProtoType::ExtParameterInfo *ParamInfos, + SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars, + Sema::ExtParameterInfoBuilder &PInfos); /// \brief Transforms a single function-type parameter. Return null /// on error. @@ -4663,17 +4662,17 @@ ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( return newParm; } -template<typename Derived> -bool TreeTransform<Derived>:: - TransformFunctionTypeParams(SourceLocation Loc, - ParmVarDecl **Params, unsigned NumParams, - const QualType *ParamTypes, - const FunctionProtoType::ExtParameterInfo *ParamInfos, - SmallVectorImpl<QualType> &OutParamTypes, - SmallVectorImpl<ParmVarDecl*> *PVars, - Sema::ExtParameterInfoBuilder &PInfos) { +template <typename Derived> +bool TreeTransform<Derived>::TransformFunctionTypeParams( + SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, + const QualType *ParamTypes, + const FunctionProtoType::ExtParameterInfo *ParamInfos, + SmallVectorImpl<QualType> &OutParamTypes, + SmallVectorImpl<ParmVarDecl *> *PVars, + Sema::ExtParameterInfoBuilder &PInfos) { int indexAdjustment = 0; + unsigned NumParams = Params.size(); for (unsigned i = 0; i != NumParams; ++i) { if (ParmVarDecl *OldParm = Params[i]) { assert(OldParm->getFunctionScopeIndex() == i); @@ -4908,7 +4907,7 @@ QualType TreeTransform<Derived>::TransformFunctionProtoType( if (T->hasTrailingReturn()) { if (getDerived().TransformFunctionTypeParams( - TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(), + TL.getBeginLoc(), TL.getParams(), TL.getTypePtr()->param_type_begin(), T->getExtParameterInfosOrNull(), ParamTypes, &ParamDecls, ExtParamInfos)) @@ -4934,7 +4933,7 @@ QualType TreeTransform<Derived>::TransformFunctionProtoType( return QualType(); if (getDerived().TransformFunctionTypeParams( - TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(), + TL.getBeginLoc(), TL.getParams(), TL.getTypePtr()->param_type_begin(), T->getExtParameterInfosOrNull(), ParamTypes, &ParamDecls, ExtParamInfos)) @@ -11196,13 +11195,10 @@ TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { // Parameter substitution. Sema::ExtParameterInfoBuilder extParamInfos; - if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), - oldBlock->param_begin(), - oldBlock->param_size(), - nullptr, - exprFunctionType->getExtParameterInfosOrNull(), - paramTypes, ¶ms, - extParamInfos)) { + if (getDerived().TransformFunctionTypeParams( + E->getCaretLocation(), oldBlock->parameters(), nullptr, + exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms, + extParamInfos)) { getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); return ExprError(); } |