[cfe-commits] r44028 - in /cfe/trunk: AST/StmtPrinter.cpp Sema/SemaExpr.cpp include/clang/AST/Expr.h test/Sema/static-ivar-ref-1.m
Fariborz Jahanian
fjahanian at apple.com
Mon Nov 12 14:29:29 PST 2007
Author: fjahanian
Date: Mon Nov 12 16:29:28 2007
New Revision: 44028
URL: http://llvm.org/viewvc/llvm-project?rev=44028&view=rev
Log:
Patch to do statically typed ivar references.
Added:
cfe/trunk/test/Sema/static-ivar-ref-1.m
Modified:
cfe/trunk/AST/StmtPrinter.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/Expr.h
Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=44028&r1=44027&r2=44028&view=diff
==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Mon Nov 12 16:29:28 2007
@@ -383,6 +383,10 @@
}
void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
+ if (Node->getBase()) {
+ PrintExpr(Node->getBase());
+ OS << (Node->isArrow() ? "->" : ".");
+ }
OS << Node->getDecl()->getName();
}
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=44028&r1=44027&r2=44028&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Mon Nov 12 16:29:28 2007
@@ -519,9 +519,20 @@
if (ret.isNull())
return true;
return new OCUVectorElementExpr(ret, BaseExpr, Member, MemberLoc);
- } else
- return Diag(OpLoc, diag::err_typecheck_member_reference_structUnion,
- SourceRange(MemberLoc));
+ } else if (BaseType->isObjcInterfaceType()) {
+ ObjcInterfaceDecl *IFace;
+ if (isa<ObjcInterfaceType>(BaseType.getCanonicalType()))
+ IFace = dyn_cast<ObjcInterfaceType>(BaseType)->getDecl();
+ else
+ IFace = dyn_cast<ObjcQualifiedInterfaceType>(BaseType)
+ ->getInterfaceType()->getDecl();
+ ObjcInterfaceDecl *clsDeclared;
+ if (ObjcIvarDecl *IV = IFace->lookupInstanceVariable(&Member, clsDeclared))
+ return new ObjCIvarRefExpr(IV, IV->getType(), MemberLoc, BaseExpr,
+ OpKind==tok::arrow);
+ }
+ return Diag(OpLoc, diag::err_typecheck_member_reference_structUnion,
+ SourceRange(MemberLoc));
}
/// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=44028&r1=44027&r2=44028&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Mon Nov 12 16:29:28 2007
@@ -1234,13 +1234,19 @@
class ObjCIvarRefExpr : public Expr {
class ObjcIvarDecl *D;
SourceLocation Loc;
+ Expr *Base;
+ bool IsArrow; // True if this is "X->F", false if this is "X.F".
+
public:
- ObjCIvarRefExpr(ObjcIvarDecl *d, QualType t, SourceLocation l) :
- Expr(ObjCIvarRefExprClass, t), D(d), Loc(l) {}
+ ObjCIvarRefExpr(ObjcIvarDecl *d, QualType t, SourceLocation l, Expr *base=0,
+ bool arrow = false) :
+ Expr(ObjCIvarRefExprClass, t), D(d), Loc(l), Base(base), IsArrow(arrow) {}
ObjcIvarDecl *getDecl() { return D; }
const ObjcIvarDecl *getDecl() const { return D; }
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
+ Expr *const getBase() const { return Base; }
+ const bool isArrow() const { return IsArrow; }
static bool classof(const Stmt *T) {
return T->getStmtClass() == ObjCIvarRefExprClass;
Added: cfe/trunk/test/Sema/static-ivar-ref-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/static-ivar-ref-1.m?rev=44028&view=auto
==============================================================================
--- cfe/trunk/test/Sema/static-ivar-ref-1.m (added)
+++ cfe/trunk/test/Sema/static-ivar-ref-1.m Mon Nov 12 16:29:28 2007
@@ -0,0 +1,16 @@
+// RUN: clang -ast-print %s
+
+ at interface current
+{
+ int ivar;
+ int ivar1;
+ int ivar2;
+}
+ at end
+
+current *pc;
+
+int foo()
+{
+ return pc->ivar2 + (*pc).ivar + pc->ivar1;
+}
More information about the cfe-commits
mailing list