Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clang/include/clang/Sema/SemaObjC.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ class SemaObjC : public SemaBase {
ParsedAttributesView ArgAttrs;
};

ParmVarDecl *ActOnMethodParmDeclaration(Scope *S, ObjCArgInfo &ArgInfo,
int ParamIndex,
bool MethodDefinition);

Decl *ActOnMethodDeclaration(
Scope *S,
SourceLocation BeginLoc, // location of the + or -.
Expand All @@ -371,7 +375,7 @@ class SemaObjC : public SemaBase {
ArrayRef<SourceLocation> SelectorLocs, Selector Sel,
// optional arguments. The number of types/arguments is obtained
// from the Sel.getNumArgs().
ObjCArgInfo *ArgInfo, DeclaratorChunk::ParamInfo *CParamInfo,
ParmVarDecl **ArgInfo, DeclaratorChunk::ParamInfo *CParamInfo,
unsigned CNumArgs, // c-style args
const ParsedAttributesView &AttrList, tok::ObjCKeywordKind MethodImplKind,
bool isVariadic, bool MethodDefinition);
Expand Down
10 changes: 6 additions & 4 deletions clang/lib/Parse/ParseObjc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,

SmallVector<const IdentifierInfo *, 12> KeyIdents;
SmallVector<SourceLocation, 12> KeyLocs;
SmallVector<SemaObjC::ObjCArgInfo, 12> ArgInfos;
SmallVector<ParmVarDecl *, 12> ObjCParamInfo;
ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope |
Scope::FunctionDeclarationScope | Scope::DeclScope);

Expand Down Expand Up @@ -1496,7 +1496,9 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
ArgInfo.NameLoc = Tok.getLocation();
ConsumeToken(); // Eat the identifier.

ArgInfos.push_back(ArgInfo);
ParmVarDecl *Param = Actions.ObjC().ActOnMethodParmDeclaration(
getCurScope(), ArgInfo, ObjCParamInfo.size(), MethodDefinition);
ObjCParamInfo.push_back(Param);
KeyIdents.push_back(SelIdent);
KeyLocs.push_back(selLoc);

Expand Down Expand Up @@ -1568,8 +1570,8 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
&KeyIdents[0]);
Decl *Result = Actions.ObjC().ActOnMethodDeclaration(
getCurScope(), mLoc, Tok.getLocation(), mType, DSRet, ReturnType, KeyLocs,
Sel, &ArgInfos[0], CParamInfo.data(), CParamInfo.size(), methodAttrs,
MethodImplKind, isVariadic, MethodDefinition);
Sel, ObjCParamInfo.data(), CParamInfo.data(), CParamInfo.size(),
methodAttrs, MethodImplKind, isVariadic, MethodDefinition);

PD.complete(Result);
return Result;
Expand Down
112 changes: 58 additions & 54 deletions clang/lib/Sema/SemaDeclObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4770,13 +4770,67 @@ static void checkObjCDirectMethodClashes(Sema &S, ObjCInterfaceDecl *IDecl,
diagClash(IMD);
}

ParmVarDecl *SemaObjC::ActOnMethodParmDeclaration(Scope *S,
ObjCArgInfo &ArgInfo,
int ParamIndex,
bool MethodDefinition) {
ASTContext &Context = getASTContext();
QualType ArgType;
TypeSourceInfo *DI;

if (!ArgInfo.Type) {
ArgType = Context.getObjCIdType();
DI = nullptr;
} else {
ArgType = SemaRef.GetTypeFromParser(ArgInfo.Type, &DI);
}
LookupResult R(SemaRef, ArgInfo.Name, ArgInfo.NameLoc,
Sema::LookupOrdinaryName,
SemaRef.forRedeclarationInCurContext());
SemaRef.LookupName(R, S);
if (R.isSingleResult()) {
NamedDecl *PrevDecl = R.getFoundDecl();
if (S->isDeclScope(PrevDecl)) {
Diag(ArgInfo.NameLoc,
(MethodDefinition ? diag::warn_method_param_redefinition
: diag::warn_method_param_declaration))
<< ArgInfo.Name;
Diag(PrevDecl->getLocation(), diag::note_previous_declaration);
}
}
SourceLocation StartLoc =
DI ? DI->getTypeLoc().getBeginLoc() : ArgInfo.NameLoc;

// Temporarily put parameter variables in the translation unit. This is what
// ActOnParamDeclarator does in the case of C arguments to the Objective-C
// method too.
ParmVarDecl *Param = SemaRef.CheckParameter(
Context.getTranslationUnitDecl(), StartLoc, ArgInfo.NameLoc, ArgInfo.Name,
ArgType, DI, SC_None);
Param->setObjCMethodScopeInfo(ParamIndex);
Param->setObjCDeclQualifier(
CvtQTToAstBitMask(ArgInfo.DeclSpec.getObjCDeclQualifier()));

// Apply the attributes to the parameter.
SemaRef.ProcessDeclAttributeList(SemaRef.TUScope, Param, ArgInfo.ArgAttrs);
SemaRef.AddPragmaAttributes(SemaRef.TUScope, Param);
if (Param->hasAttr<BlocksAttr>()) {
Diag(Param->getLocation(), diag::err_block_on_nonlocal);
Param->setInvalidDecl();
}

S->AddDecl(Param);
SemaRef.IdResolver.AddDecl(Param);
return Param;
}

Decl *SemaObjC::ActOnMethodDeclaration(
Scope *S, SourceLocation MethodLoc, SourceLocation EndLoc,
tok::TokenKind MethodType, ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
ArrayRef<SourceLocation> SelectorLocs, Selector Sel,
// optional arguments. The number of types/arguments is obtained
// from the Sel.getNumArgs().
ObjCArgInfo *ArgInfo, DeclaratorChunk::ParamInfo *CParamInfo,
ParmVarDecl **ArgInfo, DeclaratorChunk::ParamInfo *CParamInfo,
unsigned CNumArgs, // c-style args
const ParsedAttributesView &AttrList, tok::ObjCKeywordKind MethodDeclKind,
bool isVariadic, bool MethodDefinition) {
Expand Down Expand Up @@ -4818,60 +4872,10 @@ Decl *SemaObjC::ActOnMethodDeclaration(
HasRelatedResultType);

SmallVector<ParmVarDecl*, 16> Params;

for (unsigned i = 0, e = Sel.getNumArgs(); i != e; ++i) {
QualType ArgType;
TypeSourceInfo *DI;

if (!ArgInfo[i].Type) {
ArgType = Context.getObjCIdType();
DI = nullptr;
} else {
ArgType = SemaRef.GetTypeFromParser(ArgInfo[i].Type, &DI);
}

LookupResult R(SemaRef, ArgInfo[i].Name, ArgInfo[i].NameLoc,
Sema::LookupOrdinaryName,
SemaRef.forRedeclarationInCurContext());
SemaRef.LookupName(R, S);
if (R.isSingleResult()) {
NamedDecl *PrevDecl = R.getFoundDecl();
if (S->isDeclScope(PrevDecl)) {
Diag(ArgInfo[i].NameLoc,
(MethodDefinition ? diag::warn_method_param_redefinition
: diag::warn_method_param_declaration))
<< ArgInfo[i].Name;
Diag(PrevDecl->getLocation(),
diag::note_previous_declaration);
}
}

SourceLocation StartLoc = DI
? DI->getTypeLoc().getBeginLoc()
: ArgInfo[i].NameLoc;

ParmVarDecl *Param =
SemaRef.CheckParameter(ObjCMethod, StartLoc, ArgInfo[i].NameLoc,
ArgInfo[i].Name, ArgType, DI, SC_None);

Param->setObjCMethodScopeInfo(i);

Param->setObjCDeclQualifier(
CvtQTToAstBitMask(ArgInfo[i].DeclSpec.getObjCDeclQualifier()));

// Apply the attributes to the parameter.
SemaRef.ProcessDeclAttributeList(SemaRef.TUScope, Param,
ArgInfo[i].ArgAttrs);
SemaRef.AddPragmaAttributes(SemaRef.TUScope, Param);
for (unsigned I = 0; I < Sel.getNumArgs(); ++I) {
ParmVarDecl *Param = ArgInfo[I];
Param->setDeclContext(ObjCMethod);
SemaRef.ProcessAPINotes(Param);

if (Param->hasAttr<BlocksAttr>()) {
Diag(Param->getLocation(), diag::err_block_on_nonlocal);
Param->setInvalidDecl();
}
S->AddDecl(Param);
SemaRef.IdResolver.AddDecl(Param);

Params.push_back(Param);
}

Expand Down