[cfe-commits] r44016 - in /cfe/trunk: AST/Expr.cpp AST/StmtPrinter.cpp AST/StmtSerialization.cpp Sema/SemaExpr.cpp include/clang/AST/Expr.h include/clang/AST/StmtNodes.def
Steve Naroff
snaroff at apple.com
Mon Nov 12 06:29:39 PST 2007
Author: snaroff
Date: Mon Nov 12 08:29:37 2007
New Revision: 44016
URL: http://llvm.org/viewvc/llvm-project?rev=44016&view=rev
Log:
Implement instance variable references.
Modified:
cfe/trunk/AST/Expr.cpp
cfe/trunk/AST/StmtPrinter.cpp
cfe/trunk/AST/StmtSerialization.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/StmtNodes.def
Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=44016&r1=44015&r2=44016&view=diff
==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Mon Nov 12 08:29:37 2007
@@ -923,6 +923,10 @@
Stmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); }
Stmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); }
+// ObjCIvarRefExpr
+Stmt::child_iterator ObjCIvarRefExpr::child_begin() { return child_iterator(); }
+Stmt::child_iterator ObjCIvarRefExpr::child_end() { return child_iterator(); }
+
// PreDefinedExpr
Stmt::child_iterator PreDefinedExpr::child_begin() { return child_iterator(); }
Stmt::child_iterator PreDefinedExpr::child_end() { return child_iterator(); }
Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=44016&r1=44015&r2=44016&view=diff
==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Mon Nov 12 08:29:37 2007
@@ -382,6 +382,10 @@
OS << Node->getDecl()->getName();
}
+void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
+ OS << Node->getDecl()->getName();
+}
+
void StmtPrinter::VisitPreDefinedExpr(PreDefinedExpr *Node) {
switch (Node->getIdentType()) {
default:
Modified: cfe/trunk/AST/StmtSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtSerialization.cpp?rev=44016&r1=44015&r2=44016&view=diff
==============================================================================
--- cfe/trunk/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/AST/StmtSerialization.cpp Mon Nov 12 08:29:37 2007
@@ -337,6 +337,20 @@
return dr;
}
+void ObjCIvarRefExpr::directEmit(Serializer& S) const {
+ S.Emit(Loc);
+ S.Emit(getType());
+ S.EmitPtr(getDecl());
+}
+
+ObjCIvarRefExpr* ObjCIvarRefExpr::directMaterialize(Deserializer& D) {
+ SourceLocation Loc = SourceLocation::ReadVal(D);
+ QualType T = QualType::ReadVal(D);
+ ObjCIvarRefExpr* dr = new ObjCIvarRefExpr(NULL,T,Loc);
+ D.ReadPtr(dr->D,false);
+ return dr;
+}
+
DeclStmt* DeclStmt::directMaterialize(Deserializer& D) {
ScopedDecl* decl = cast<ScopedDecl>(D.ReadOwnedPtr<Decl>());
return new DeclStmt(decl);
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=44016&r1=44015&r2=44016&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Mon Nov 12 08:29:37 2007
@@ -82,6 +82,12 @@
!getLangOptions().CPlusPlus)
D = ImplicitlyDefineFunction(Loc, II, S);
else {
+ if (CurMethodDecl) {
+ ObjcInterfaceDecl *IFace = CurMethodDecl->getClassInterface();
+ ObjcInterfaceDecl *clsDeclared;
+ if (ObjcIvarDecl *IV = IFace->lookupInstanceVariable(&II, clsDeclared))
+ return new ObjCIvarRefExpr(IV, IV->getType(), Loc);
+ }
// If this name wasn't predeclared and if this is not a function call,
// diagnose the problem.
return Diag(Loc, diag::err_undeclared_var_use, II.getName());
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=44016&r1=44015&r2=44016&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Mon Nov 12 08:29:37 2007
@@ -1229,7 +1229,32 @@
virtual child_iterator child_end();
};
+
+/// ObjCIvarRefExpr - A reference to an ObjC instance variable.
+class ObjCIvarRefExpr : public Expr {
+ class ObjcIvarDecl *D;
+ SourceLocation Loc;
+public:
+ ObjCIvarRefExpr(ObjcIvarDecl *d, QualType t, SourceLocation l) :
+ Expr(ObjCIvarRefExprClass, t), D(d), Loc(l) {}
+
+ ObjcIvarDecl *getDecl() { return D; }
+ const ObjcIvarDecl *getDecl() const { return D; }
+ virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ObjCIvarRefExprClass;
+ }
+ static bool classof(const ObjCIvarRefExpr *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
+
+ virtual void directEmit(llvm::Serializer& S) const;
+ static ObjCIvarRefExpr* directMaterialize(llvm::Deserializer& D);
+};
+
class ObjCMessageExpr : public Expr {
enum { RECEIVER=0, ARGS_START=1 };
Modified: cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtNodes.def?rev=44016&r1=44015&r2=44016&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Mon Nov 12 08:29:37 2007
@@ -94,8 +94,9 @@
STMT(72, ObjCMessageExpr , Expr)
STMT(73, ObjCSelectorExpr , Expr)
STMT(74, ObjCProtocolExpr , Expr)
+STMT(75, ObjCIvarRefExpr , Expr)
-LAST_EXPR(74)
+LAST_EXPR(75)
#undef STMT
#undef FIRST_STMT
More information about the cfe-commits
mailing list