aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Parse/ParseObjc.cpp19
-rw-r--r--lib/Sema/SemaDeclObjC.cpp23
2 files changed, 34 insertions, 8 deletions
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp
index af53d7d592..0aae43adb8 100644
--- a/lib/Parse/ParseObjc.cpp
+++ b/lib/Parse/ParseObjc.cpp
@@ -868,7 +868,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
Decl *Result
- = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
+ = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(),
mType, IDecl, DSRet, ReturnType, Sel,
0,
CParamInfo.data(), CParamInfo.size(),
@@ -879,7 +879,9 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
llvm::SmallVector<Sema::ObjCArgInfo, 12> ArgInfos;
-
+ ParseScope PrototypeScope(this,
+ Scope::FunctionPrototypeScope|Scope::DeclScope);
+
while (1) {
Sema::ObjCArgInfo ArgInfo;
@@ -976,18 +978,25 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
// If attributes exist after the method, parse them.
if (getLang().ObjC2)
MaybeParseGNUAttributes(attrs);
-
- if (KeyIdents.size() == 0)
+
+ if (KeyIdents.size() == 0) {
+ // Leave prototype scope.
+ PrototypeScope.Exit();
return 0;
+ }
+
Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
&KeyIdents[0]);
Decl *Result
- = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
+ = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(),
mType, IDecl, DSRet, ReturnType, Sel,
&ArgInfos[0],
CParamInfo.data(), CParamInfo.size(),
attrs.getList(),
MethodImplKind, isVariadic);
+ // Leave prototype scope.
+ PrototypeScope.Exit();
+
PD.complete(Result);
return Result;
}
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index a2f6b516be..a3d93ab85e 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -1664,6 +1664,7 @@ bool containsInvalidMethodImplAttribute(const AttrVec &A) {
}
Decl *Sema::ActOnMethodDeclaration(
+ Scope *S,
SourceLocation MethodLoc, SourceLocation EndLoc,
tok::TokenKind MethodType, Decl *ClassDecl,
ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
@@ -1721,6 +1722,20 @@ Decl *Sema::ActOnMethodDeclaration(
ArgType = adjustParameterType(ArgType);
}
+ LookupResult R(*this, ArgInfo[i].Name, ArgInfo[i].NameLoc,
+ LookupOrdinaryName, ForRedeclaration);
+ LookupName(R, S);
+ if (R.isSingleResult()) {
+ NamedDecl *PrevDecl = R.getFoundDecl();
+ if (S->isDeclScope(PrevDecl)) {
+ // FIXME. This should be an error; but will break projects.
+ Diag(ArgInfo[i].NameLoc, diag::warn_method_param_redefinition)
+ << ArgInfo[i].Name;
+ Diag(PrevDecl->getLocation(),
+ diag::note_previous_declaration);
+ }
+ }
+
ParmVarDecl* Param
= ParmVarDecl::Create(Context, ObjCMethod, ArgInfo[i].NameLoc,
ArgInfo[i].Name, ArgType, DI,
@@ -1739,9 +1754,12 @@ Decl *Sema::ActOnMethodDeclaration(
// Apply the attributes to the parameter.
ProcessDeclAttributeList(TUScope, Param, ArgInfo[i].ArgAttrs);
+ S->AddDecl(Param);
+ IdResolver.AddDecl(Param);
+
Params.push_back(Param);
}
-
+
for (unsigned i = 0, e = CNumArgs; i != e; ++i) {
ParmVarDecl *Param = cast<ParmVarDecl>(CParamInfo[i].Param);
QualType ArgType = Param->getType();
@@ -1757,8 +1775,7 @@ Decl *Sema::ActOnMethodDeclaration(
Param->setInvalidDecl();
}
Param->setDeclContext(ObjCMethod);
- if (Param->getDeclName())
- IdResolver.RemoveDecl(Param);
+
Params.push_back(Param);
}