diff options
author | John McCall <rjmccall@apple.com> | 2011-03-02 11:33:24 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-03-02 11:33:24 +0000 |
commit | d5313b0bbf3948fe7c63bf46a7da330c96d07309 (patch) | |
tree | 3c709dabee53f0861530d2da0a7a91ab0a8918d6 /lib/AST/DeclObjC.cpp | |
parent | 0ae927bdef0d0bd2838e8274938fac8aaa9035ee (diff) |
Provide an attribute, objc_method_family, to allow the inferred family
of an Objective-C method to be overridden on a case-by-case basis. This
is a higher-level tool than ns_returns_retained &c.; it lets users specify
that not only does a method have different retain/release semantics, but
that it semantically acts differently than one might assume from its name.
This in turn is quite useful to static analysis.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126839 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclObjC.cpp')
-rw-r--r-- | lib/AST/DeclObjC.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 3a7c2a6e70..e9d537029b 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -403,6 +403,22 @@ ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const { if (family != InvalidObjCMethodFamily) return family; + // Check for an explicit attribute. + if (const ObjCMethodFamilyAttr *attr = getAttr<ObjCMethodFamilyAttr>()) { + // The unfortunate necessity of mapping between enums here is due + // to the attributes framework. + switch (attr->getFamily()) { + case ObjCMethodFamilyAttr::OMF_None: family = OMF_None; break; + case ObjCMethodFamilyAttr::OMF_alloc: family = OMF_alloc; break; + case ObjCMethodFamilyAttr::OMF_copy: family = OMF_copy; break; + case ObjCMethodFamilyAttr::OMF_init: family = OMF_init; break; + case ObjCMethodFamilyAttr::OMF_mutableCopy: family = OMF_mutableCopy; break; + case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break; + } + Family = static_cast<unsigned>(family); + return family; + } + family = getSelector().getMethodFamily(); switch (family) { case OMF_None: break; |