[swift-dev] determine if decl comes from ObjC header
Rafkind, Jon
jon.rafkind at hpe.com
Fri Feb 19 16:25:41 CST 2016
How can I determine if a swift declaration comes from a header file, such as UITextInputTraits from iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/UIKit.framework/Headers/UITextInputTraits.h?
I tried this
swift::ProtocolDecl * protocol;
if (protocol->getModuleContext() == context->getClangModuleLoader()->getImportedHeaderModule()){
...
}
but the two modules are not equal. protocol->getModuleContext()->isSystemLibrary() is true, but I'm not sure thats enough information to distinguish protocols defined in header files versus ones that come from core swift libraries.
The reason I am asking about this is that properties are treated differently in swift code versus objective-c code.
protocol Test{
var number:Int { get }
}
This protocol will have 3 members, a PatternBindingDecl, a VarDecl, and a FuncDecl that is a getter. The pattern binding and getter seem to be autogenerated by the parser/typechecker.
For a protocol defined in a header file such as
@protocol UITextInputTraits <NSObject>
@property(nonatomic) UITextAutocorrectionType autocorrectionType;
@end
will only have one member, the VarDecl for autocorrectionType.
I would like to deal with the VarDecl only in the case that it is declared inside a header file.
--
More information about the swift-dev
mailing list