[cfe-dev] Missing Availability Information for Enums
Jordan Rose
jordan_rose at apple.com
Fri Mar 15 09:11:25 PDT 2013
On Mar 15, 2013, at 7:27 , Sebastian Hagedorn <hagi.dd at web.de> wrote:
> I'm currently working on a Clang modification that analyses the (iOS SDK) version in which certain symbols were introduced. Most of it is based on code that looks similar to this:
>
> decl->getAttr<AvailabilityAttr>()->getIntroduced();
>
> So far, this works fine for ObjC methods, properties, classes, and C functions. One missing piece are enumerations, but I've found that they seem to lack availability information alltogether. Let's pick an example, I'm trying to use the PKPassKitErrorCode enum that was introduced in iOS 6. The framework header declares the following:
>
> typedef NS_ENUM(NSInteger, PKPassKitErrorCode) {
> PKUnknownError = -1,
> PKInvalidDataError = 1,
> PKUnsupportedVersionError,
> PKInvalidSignature,
> } NS_ENUM_AVAILABLE_IOS(6_0);
>
> Obviously, availability information is provided using the usual macros. This is what the preprocessor generates:
>
> typedef enum PKPassKitErrorCode : NSInteger PKPassKitErrorCode; enum PKPassKitErrorCode : NSInteger {
> PKUnknownError = -1,
> PKInvalidDataError = 1,
> PKUnsupportedVersionError,
> PKInvalidSignature,
> } __attribute__((availability(ios,introduced=6.0)));
>
> Still looks ok to me, all the information I'm looking for is included. However, when I try to get the availability information during the compilation process (I'm modifying Sema::DiagnoseUseOfDecl() in SemaExpr.cpp), there is none – getAttr<AvailabilityAttr>() returns NULL for EnumConstantDecls.
>
> I have not started examining the parsing of the declaration, but wanted to ask first whether there's an obvious reason why the information is missing, or there's an obvious mistake/misassumption I'm making?
The attribute here isn't on the EnumConstantDecls; it's on the EnumDecl as a whole. You'll also have to be careful about redeclarations; in this case I would guess that the first EnumDecl (inside the typedef) doesn't have the attribute, but the second one (where the enumerators are actually defined) does.
Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130315/7c7d1104/attachment.html>
More information about the cfe-dev
mailing list