summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/Driver/PrintParserCallbacks.cpp3
-rw-r--r--clang/include/clang/Parse/Action.h3
-rw-r--r--clang/lib/Parse/ParseExpr.cpp3
-rw-r--r--clang/lib/Parse/ParseObjc.cpp7
-rw-r--r--clang/lib/Sema/Sema.h3
-rw-r--r--clang/lib/Sema/SemaExpr.cpp34
-rw-r--r--clang/test/SemaObjC/ivar-access-tests.m2
7 files changed, 32 insertions, 23 deletions
diff --git a/clang/Driver/PrintParserCallbacks.cpp b/clang/Driver/PrintParserCallbacks.cpp
index 0a6d09a02e2..760037806ab 100644
--- a/clang/Driver/PrintParserCallbacks.cpp
+++ b/clang/Driver/PrintParserCallbacks.cpp
@@ -517,7 +517,8 @@ namespace {
SourceLocation OpLoc,
tok::TokenKind OpKind,
SourceLocation MemberLoc,
- IdentifierInfo &Member) {
+ IdentifierInfo &Member,
+ DeclTy *ImplDecl) {
llvm::cout << __FUNCTION__ << "\n";
return ExprEmpty();
}
diff --git a/clang/include/clang/Parse/Action.h b/clang/include/clang/Parse/Action.h
index ab87eb3571a..c5a16288e33 100644
--- a/clang/include/clang/Parse/Action.h
+++ b/clang/include/clang/Parse/Action.h
@@ -642,7 +642,8 @@ public:
SourceLocation OpLoc,
tok::TokenKind OpKind,
SourceLocation MemberLoc,
- IdentifierInfo &Member) {
+ IdentifierInfo &Member,
+ DeclTy *ObjCImpDecl) {
return ExprEmpty();
}
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 6c6842e0be6..4a81d30c846 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -852,7 +852,8 @@ Parser::ParsePostfixExpressionSuffix(OwningExprResult LHS) {
if (!LHS.isInvalid()) {
LHS = Actions.ActOnMemberReferenceExpr(CurScope, move(LHS), OpLoc,
OpKind, Tok.getLocation(),
- *Tok.getIdentifierInfo());
+ *Tok.getIdentifierInfo(),
+ ObjCImpDecl);
}
ConsumeToken();
break;
diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index 3637d144d63..1cbc0e77483 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -1082,12 +1082,15 @@ Parser::DeclTy *Parser::ParseObjCAtImplementationDeclaration(
Parser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) {
assert(Tok.isObjCAtKeyword(tok::objc_end) &&
"ParseObjCAtEndDeclaration(): Expected @end");
+ DeclTy *Result = ObjCImpDecl;
ConsumeToken(); // the "end" identifier
- if (ObjCImpDecl)
+ if (ObjCImpDecl) {
Actions.ActOnAtEnd(atLoc, ObjCImpDecl);
+ ObjCImpDecl = 0;
+ }
else
Diag(atLoc, diag::warn_expected_implementation); // missing @implementation
- return ObjCImpDecl;
+ return Result;
}
/// compatibility-alias-decl:
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h
index f68ef92e962..31a8c3889db 100644
--- a/clang/lib/Sema/Sema.h
+++ b/clang/lib/Sema/Sema.h
@@ -1158,7 +1158,8 @@ public:
SourceLocation OpLoc,
tok::TokenKind OpKind,
SourceLocation MemberLoc,
- IdentifierInfo &Member);
+ IdentifierInfo &Member,
+ DeclTy *ImplDecl=0);
bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
FunctionDecl *FDecl,
const FunctionProtoType *Proto,
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f9d89fdb0be..f71f82daa90 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1666,16 +1666,11 @@ static IdentifierInfo *constructSetterName(IdentifierTable &Idents,
return &Idents.get(&SelectorName[0], &SelectorName[SelectorName.size()]);
}
-ObjCImplementationDecl *getCurImplementationDecl(DeclContext *DC) {
- while (DC && !isa<ObjCImplementationDecl>(DC))
- DC = DC->getParent();
- return dyn_cast_or_null<ObjCImplementationDecl>(DC);
-}
-
Action::OwningExprResult
Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
tok::TokenKind OpKind, SourceLocation MemberLoc,
- IdentifierInfo &Member) {
+ IdentifierInfo &Member,
+ DeclTy *ObjCImpDecl) {
Expr *BaseExpr = static_cast<Expr *>(Base.release());
assert(BaseExpr && "no record expression");
@@ -1803,17 +1798,24 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
ObjCInterfaceDecl *ClassOfMethodDecl = 0;
if (ObjCMethodDecl *MD = getCurMethodDecl())
ClassOfMethodDecl = MD->getClassInterface();
- else if (FunctionDecl *FD = getCurFunctionDecl()) {
- // FIXME: This isn't working yet. Will discuss with Fariborz.
- // FIXME: Should be ObjCImplDecl, so categories can work.
- // Need to fiddle with castToDeclContext/castFromDeclContext.
- ObjCImplementationDecl *ImpDecl = getCurImplementationDecl(FD);
- if (ImpDecl)
- ClassOfMethodDecl = ImpDecl->getClassInterface();
+ else if (ObjCImpDecl && getCurFunctionDecl()) {
+ // Case of a c-function declared inside an objc implementation.
+ // FIXME: For a c-style function nested inside an objc implementation
+ // class, there is no implementation context available, so we pass down
+ // the context as argument to this routine. Ideally, this context need
+ // be passed down in the AST node and somehow calculated from the AST
+ // for a function decl.
+ Decl *ImplDecl = static_cast<Decl *>(ObjCImpDecl);
+ if (ObjCImplementationDecl *IMPD =
+ dyn_cast<ObjCImplementationDecl>(ImplDecl))
+ ClassOfMethodDecl = IMPD->getClassInterface();
+ else if (ObjCCategoryImplDecl* CatImplClass =
+ dyn_cast<ObjCCategoryImplDecl>(ImplDecl))
+ ClassOfMethodDecl = CatImplClass->getClassInterface();
}
- if (IV->getAccessControl() == ObjCIvarDecl::Private) {
+ if (IV->getAccessControl() == ObjCIvarDecl::Private) {
if (ClassDeclared != IFTy->getDecl() ||
- (ClassOfMethodDecl && (ClassOfMethodDecl != ClassDeclared)))
+ ClassOfMethodDecl != ClassDeclared)
Diag(MemberLoc, diag::error_private_ivar_access) << IV->getDeclName();
}
// @protected
diff --git a/clang/test/SemaObjC/ivar-access-tests.m b/clang/test/SemaObjC/ivar-access-tests.m
index 7f5580ddb38..ad8f603772e 100644
--- a/clang/test/SemaObjC/ivar-access-tests.m
+++ b/clang/test/SemaObjC/ivar-access-tests.m
@@ -73,7 +73,7 @@ int main (void)
{
MySuperClass *s = 0;
int access;
- access = s->private; // FIXME: {{instance variable 'private' is private}}
+ access = s->private; // expected-error {{instance variable 'private' is private}}
access = s->protected; // expected-error {{instance variable 'protected' is protected}}
return 0;
}
OpenPOWER on IntegriCloud