From e3e9add4fd788927df6f545570e7838db59c01d7 Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Mon, 2 Jun 2008 23:03:37 +0000 Subject: [PATCH] Fix clang on xcode: error: use of undeclared identifier 'super' git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51888 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ExprObjC.h | 22 +++++++++++++++++++++ include/clang/AST/StmtNodes.def | 7 ++++--- lib/AST/Expr.cpp | 6 +++++- lib/AST/StmtPrinter.cpp | 4 ++++ lib/AST/StmtSerialization.cpp | 11 +++++++++++ lib/Sema/SemaExpr.cpp | 5 +++++ test/Sema/objc-property-7.m | 34 +++++++++++++++++++++++++++++++++ 7 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 test/Sema/objc-property-7.m diff --git a/include/clang/AST/ExprObjC.h b/include/clang/AST/ExprObjC.h index d00cb9a9a6..0118c38a7a 100644 --- a/include/clang/AST/ExprObjC.h +++ b/include/clang/AST/ExprObjC.h @@ -335,6 +335,28 @@ public: static ObjCMessageExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); }; +/// ObjCSuperRefExpr - A reference to super. +class ObjCSuperRefExpr : public Expr { + SourceLocation Loc; +public: + ObjCSuperRefExpr(QualType t, SourceLocation l) : + Expr(ObjCSuperRefExprClass, t), Loc(l) {} + + virtual SourceRange getSourceRange() const { return SourceRange(Loc); } + + static bool classof(const Stmt *T) { + return T->getStmtClass() == ObjCSuperRefExprClass; + } + static bool classof(const ObjCSuperRefExpr *) { return true; } + + // Iterators + virtual child_iterator child_begin(); + virtual child_iterator child_end(); + + virtual void EmitImpl(llvm::Serializer& S) const; + static ObjCSuperRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); +}; + } // end namespace clang #endif diff --git a/include/clang/AST/StmtNodes.def b/include/clang/AST/StmtNodes.def index 915dc263ff..d156f92fb6 100644 --- a/include/clang/AST/StmtNodes.def +++ b/include/clang/AST/StmtNodes.def @@ -101,12 +101,13 @@ STMT(73, ObjCSelectorExpr , Expr) STMT(74, ObjCProtocolExpr , Expr) STMT(75, ObjCIvarRefExpr , Expr) STMT(76, ObjCPropertyRefExpr , Expr) +STMT(77, ObjCSuperRefExpr , Expr) // Clang Extensions. -STMT(77, OverloadExpr , Expr) -STMT(78, ShuffleVectorExpr , Expr) +STMT(78, OverloadExpr , Expr) +STMT(79, ShuffleVectorExpr , Expr) -LAST_EXPR(78) +LAST_EXPR(79) #undef STMT #undef FIRST_STMT diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 6b0eb048b9..357d711978 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1189,7 +1189,7 @@ Stmt::child_iterator ObjCIvarRefExpr::child_end() { return reinterpret_cast(&Base)+1; } -// ObjCIvarRefExpr +// ObjCPropertyRefExpr Stmt::child_iterator ObjCPropertyRefExpr::child_begin() { return reinterpret_cast(&Base); } @@ -1198,6 +1198,10 @@ Stmt::child_iterator ObjCPropertyRefExpr::child_end() { return reinterpret_cast(&Base)+1; } +// ObjCSuperRefExpr +Stmt::child_iterator ObjCSuperRefExpr::child_begin() { return child_iterator();} +Stmt::child_iterator ObjCSuperRefExpr::child_end() { return child_iterator(); } + // PreDefinedExpr Stmt::child_iterator PreDefinedExpr::child_begin() { return child_iterator(); } Stmt::child_iterator PreDefinedExpr::child_end() { return child_iterator(); } diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index d52f48ed21..a740facf76 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -476,6 +476,10 @@ void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) { OS << Node->getDecl()->getName(); } +void StmtPrinter::VisitObjCSuperRefExpr(ObjCSuperRefExpr *Node) { + OS << "super"; +} + void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) { if (Node->getBase()) { PrintExpr(Node->getBase()); diff --git a/lib/AST/StmtSerialization.cpp b/lib/AST/StmtSerialization.cpp index 25e9514db1..99a890946d 100644 --- a/lib/AST/StmtSerialization.cpp +++ b/lib/AST/StmtSerialization.cpp @@ -518,6 +518,17 @@ DeclRefExpr* DeclRefExpr::CreateImpl(Deserializer& D, ASTContext& C) { return new DeclRefExpr(decl,T,Loc); } +void ObjCSuperRefExpr::EmitImpl(Serializer& S) const { + S.Emit(Loc); + S.Emit(getType()); +} + +ObjCSuperRefExpr* ObjCSuperRefExpr::CreateImpl(Deserializer& D, ASTContext& C) { + SourceLocation Loc = SourceLocation::ReadVal(D); + QualType T = QualType::ReadVal(D); + return new ObjCSuperRefExpr(T, Loc); +} + DeclStmt* DeclStmt::CreateImpl(Deserializer& D, ASTContext& C) { ScopedDecl* decl = cast(D.ReadOwnedPtr(C)); SourceLocation StartLoc = SourceLocation::ReadVal(D); diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index f75c3924a0..626e829044 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -99,6 +99,11 @@ Sema::ExprResult Sema::ActOnIdentifierExpr(Scope *S, SourceLocation Loc, static_cast(SelfExpr.Val), true, true); } } + if (!strncmp(II.getName(), "super", 5)) { + QualType T = Context.getPointerType(Context.getObjCInterfaceType( + CurMethodDecl->getClassInterface())); + return new ObjCSuperRefExpr(T, Loc); + } } if (D == 0) { diff --git a/test/Sema/objc-property-7.m b/test/Sema/objc-property-7.m new file mode 100644 index 0000000000..ef7a98ad89 --- /dev/null +++ b/test/Sema/objc-property-7.m @@ -0,0 +1,34 @@ +// RUN: clang -fsyntax-only -verify %s +typedef signed char BOOL; +typedef struct _NSZone NSZone; + +@protocol NSObject +- (BOOL)isEqual:(id)object; +@end + +@protocol NSCopying +- (id)copyWithZone:(NSZone *)zone; +@end + +@interface NSObject {} +@end + +@class NSString, NSData, NSMutableData, NSMutableDictionary, NSMutableArray; + +@interface SCMObject : NSObject {} + @property(assign) SCMObject *__attribute__((objc_gc(weak))) parent; +@end + +@interface SCMNode : SCMObject +{ + NSString *_name; +} +@property(copy) NSString *name; +@end + +@implementation SCMNode + @synthesize name = _name; + - (void) setParent:(SCMNode*) inParent { + super.parent = inParent; + } +@end