[cfe-dev] Missing Availability Information for Enums
Sebastian Hagedorn
hagi.dd at web.de
Mon Mar 18 09:15:17 PDT 2013
On 15/03/2013, at 17:11 , Jordan Rose <jordan_rose at apple.com> wrote:
>
> 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
>
Thanks for your response!
Re:EnumConstantDecl vs. EnumDecl... my bad. I actually tested both though, and neither the constants nor the declaration have availability information.
Re:Redeclarations: How is this handled in Clang? After looking at the EnumDecl class and the TagDecl class specifically, I assumed Clang keeps all the (re)declarations it finds and makes them accessible via iterators. So I tried to acces the most recent declaration (which should be the one with the constants defined), but also go through all previous declarations and always test whether there's an availability attribute. Looks like this...
EnumDecl *enumD = dyn_cast_or_null<EnumDecl>(decl);
bool hit = false;
if (enumD) {
EnumDecl *prev = enumD->getMostRecentDecl();
while (prev) {
if (prev->getAttr<AvailabilityAttr>()) {
hit = true;
}
prev = prev->getPreviousDecl();
}
}
Unfortunately, prev->getPreviousDecl() always returns NULL, so the while loop executes only once. And it does not find availability information for the most recent declaration.
Is there another way to check all (re)declarations?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130318/75544edf/attachment.html>
More information about the cfe-dev
mailing list