Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clang::ObjCIvarDecl *getIvarDeclOrNull(clang::ObjCPropertyRefExpr *prop) {
- // the simple case, it is an explicitproperty and that points us to the ivardecl
- if(prop->getExplicitProperty() && prop->getExplicitProperty()->getPropertyIvarDecl())
- return prop->getExplicitProperty()->getPropertyIvarDecl();
- // the more complicated case...
- // find the corresponding ValueDecl to the Base of the ObjCPropertyRefExpr
- // when the ValueDecls type is a ObjCInterfaceDecl and clang knows the interface-implementation
- // we iterate over all property-implementations and compare their names with the name of the
- // getter-selector
- if(clang::ImplicitCastExpr *base= dyn_cast_or_null<clang::ImplicitCastExpr>(prop->getBase())) {
- if(clang::DeclRefExpr *d= dyn_cast_or_null<clang::DeclRefExpr>(base->getSubExpr())) {
- clang::ValueDecl *val= d->getDecl();
- if(val->getType()->isObjCObjectPointerType()) {
- clang::ObjCInterfaceDecl *iface= val->getType()->getAsObjCInterfacePointerType()->getInterfaceDecl();
- if(iface && iface->getImplementation()) {
- clang::ObjCImplementationDecl *impl= iface->getImplementation();
- for(clang::ObjCImplementationDecl::propimpl_iterator i= impl->propimpl_begin(); i!= impl->propimpl_end(); ++i) {
- // does the property know which ivar it belongs to and does the ivar has the same name as the requested property?
- if((*i)->getPropertyIvarDecl() && (*i)->getPropertyIVarDecl()->getNameAsString()== prop->getGetterSelector().getAsString())
- return (*i)->getPropertyIvarDecl(); // match of the ivar to the corresponding property-getter
- }
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement