Scope *S,
IdentifierInfo *receivingClassName,
Selector Sel,
- SourceLocation lbrac,
+ SourceLocation lbrac,
+ SourceLocation receiverLoc,
SourceLocation rbrac,
ExprTy **ArgExprs, unsigned NumArgs) {
return 0;
ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
ExprResult ParseObjCMessageExpression();
ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
+ SourceLocation NameLoc,
IdentifierInfo *ReceiverName,
ExprTy *ReceiverExpr);
ExprResult ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracloc,
+ SourceLocation NameLoc,
IdentifierInfo *ReceiverName,
ExprTy *ReceiverExpr);
/// expressions and other binary operators for these expressions as well.
Parser::ExprResult
Parser::ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracLoc,
+ SourceLocation NameLoc,
IdentifierInfo *ReceiverName,
ExprTy *ReceiverExpr) {
- ExprResult R = ParseObjCMessageExpressionBody(LBracLoc, ReceiverName,
+ ExprResult R = ParseObjCMessageExpressionBody(LBracLoc, NameLoc, ReceiverName,
ReceiverExpr);
if (R.isInvalid) return R;
R = ParsePostfixExpressionSuffix(R);
}
IdentifierInfo *Name = Tok.getIdentifierInfo();
- ConsumeToken();
- return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, Name, 0);
+ SourceLocation NameLoc = ConsumeToken();
+ return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, NameLoc,
+ Name, 0);
}
// Note that we parse this as an assignment expression, not a constant
Diag(Tok, diag::err_expected_equal_designator);
}
- return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, 0,Idx.Val);
+ return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
+ SourceLocation(),
+ 0, Idx.Val);
}
// Create designation if we haven't already.
// Parse receiver
if (isTokObjCMessageIdentifierReceiver()) {
IdentifierInfo *ReceiverName = Tok.getIdentifierInfo();
- ConsumeToken();
- return ParseObjCMessageExpressionBody(LBracLoc, ReceiverName, 0);
+ SourceLocation NameLoc = ConsumeToken();
+ return ParseObjCMessageExpressionBody(LBracLoc, NameLoc, ReceiverName, 0);
}
ExprResult Res = ParseExpression();
return Res;
}
- return ParseObjCMessageExpressionBody(LBracLoc, 0, Res.Val);
+ return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 0, Res.Val);
}
/// ParseObjCMessageExpressionBody - Having parsed "'[' objc-receiver", parse
///
Parser::ExprResult
Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc,
+ SourceLocation NameLoc,
IdentifierInfo *ReceiverName,
ExprTy *ReceiverExpr) {
// Parse objc-selector
// We've just parsed a keyword message.
if (ReceiverName)
return Actions.ActOnClassMessage(CurScope,
- ReceiverName, Sel, LBracLoc, RBracLoc,
+ ReceiverName, Sel,
+ LBracLoc, NameLoc, RBracLoc,
&KeyExprs[0], KeyExprs.size());
return Actions.ActOnInstanceMessage(ReceiverExpr, Sel, LBracLoc, RBracLoc,
&KeyExprs[0], KeyExprs.size());
virtual ExprResult ActOnClassMessage(
Scope *S,
IdentifierInfo *receivingClassName, Selector Sel,
- SourceLocation lbrac, SourceLocation rbrac,
+ SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac,
ExprTy **ArgExprs, unsigned NumArgs);
// ActOnInstanceMessage - used for both unary and keyword messages.
Sema::ExprResult Sema::ActOnClassMessage(
Scope *S,
IdentifierInfo *receiverName, Selector Sel,
- SourceLocation lbrac, SourceLocation rbrac, ExprTy **Args, unsigned NumArgs)
+ SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac,
+ ExprTy **Args, unsigned NumArgs)
{
assert(receiverName && "missing receiver class name");
ObjCInterfaceDecl* ClassDecl = 0;
bool isSuper = false;
- if (receiverName == SuperID && getCurMethodDecl()) {
- isSuper = true;
- ClassDecl = getCurMethodDecl()->getClassInterface()->getSuperClass();
- if (!ClassDecl)
- return Diag(lbrac, diag::error_no_super_class)
- << getCurMethodDecl()->getClassInterface()->getName();
- if (getCurMethodDecl()->isInstance()) {
- QualType superTy = Context.getObjCInterfaceType(ClassDecl);
- superTy = Context.getPointerType(superTy);
- ExprResult ReceiverExpr = new ObjCSuperExpr(SourceLocation(), superTy);
- // We are really in an instance method, redirect.
- return ActOnInstanceMessage(ReceiverExpr.Val, Sel, lbrac, rbrac,
- Args, NumArgs);
- }
- // We are sending a message to 'super' within a class method. Do nothing,
- // the receiver will pass through as 'super' (how convenient:-).
+ if (receiverName == SuperID) {
+ if (getCurMethodDecl()) {
+ isSuper = true;
+ ClassDecl = getCurMethodDecl()->getClassInterface()->getSuperClass();
+ if (!ClassDecl)
+ return Diag(lbrac, diag::error_no_super_class,
+ getCurMethodDecl()->getClassInterface()->getName());
+ if (getCurMethodDecl()->isInstance()) {
+ QualType superTy = Context.getObjCInterfaceType(ClassDecl);
+ superTy = Context.getPointerType(superTy);
+ ExprResult ReceiverExpr = new ObjCSuperExpr(SourceLocation(), superTy);
+ // We are really in an instance method, redirect.
+ return ActOnInstanceMessage(ReceiverExpr.Val, Sel, lbrac, rbrac,
+ Args, NumArgs);
+ }
+ // We are sending a message to 'super' within a class method. Do nothing,
+ // the receiver will pass through as 'super' (how convenient:-).
+ } else {
+ // 'super' has been used outside a method context. If a variable named
+ // 'super' has been declared, redirect. If not, produce a diagnostic.
+ Decl *SuperDecl = LookupDecl(receiverName, Decl::IDNS_Ordinary, S, false);
+ ValueDecl *VD = dyn_cast_or_null<ValueDecl>(SuperDecl);
+ if (VD) {
+ ExprResult ReceiverExpr = new DeclRefExpr(VD, VD->getType(),
+ receiverLoc);
+ // We are really in an instance method, redirect.
+ return ActOnInstanceMessage(ReceiverExpr.Val, Sel, lbrac, rbrac,
+ Args, NumArgs);
+ }
+ return Diag(receiverLoc, diag::err_undeclared_var_use,
+ receiverName->getName());
+ }
} else
ClassDecl = getObjCInterfaceDecl(receiverName);
[super cMethod]; // expected-warning{{method '+cMethod' not found (return type defaults to 'id')}}
}
@end
+
+@interface XX
+- m;
+@end
+
+void f(id super) {
+ [super m];
+}
+void f0(int super) {
+ [super m]; // expected-error{{bad receiver type 'int'}}
+}
+void f1(int puper) {
+ [super m]; // expected-error{{use of undeclared identifier 'super'}}
+}