From b085d898bdfe35097eba45f4072b0f6865f561dc Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 30 Mar 2012 00:19:18 +0000 Subject: Add info to ObjCPropertyRefExpr to indicate whether the dot syntax property reference is going to message the setter, the getter, or both. Having this info on the ObjCPropertyRefExpr node makes it easier for AST clients (like libclang) to reason about the meaning of the property reference. [AST/Sema] -Use 2 bits (with a PointerIntPair) in ObjCPropertyRefExpr to record the above info -Have ObjCPropertyOpBuilder set the info appropriately. [libclang] -When there is an implicit property reference (property syntax using methods) have clang_getCursorReferenced return a cursor for the method. If the property reference is going to result in messaging both the getter and the setter choose to return a cursor for the setter because it is less obvious from source inspection that the setter is getting called. The general idea has the seal of approval by John. rdar://11151621 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153709 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/libclang/CIndex.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 972beaf9e7..2a05b1b6f7 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -2901,8 +2901,17 @@ static Decl *getDeclFromExpr(Stmt *E) { return ME->getMemberDecl(); if (ObjCIvarRefExpr *RE = dyn_cast(E)) return RE->getDecl(); - if (ObjCPropertyRefExpr *PRE = dyn_cast(E)) - return PRE->isExplicitProperty() ? PRE->getExplicitProperty() : 0; + if (ObjCPropertyRefExpr *PRE = dyn_cast(E)) { + if (PRE->isExplicitProperty()) + return PRE->getExplicitProperty(); + // It could be messaging both getter and setter as in: + // ++myobj.myprop; + // in which case prefer to associate the setter since it is less obvious + // from inspecting the source that the setter is going to get called. + if (PRE->isMessagingSetter()) + return PRE->getImplicitPropertySetter(); + return PRE->getImplicitPropertyGetter(); + } if (PseudoObjectExpr *POE = dyn_cast(E)) return getDeclFromExpr(POE->getSyntacticForm()); if (OpaqueValueExpr *OVE = dyn_cast(E)) -- cgit v1.2.3