This patch adds an external_source_symbol attribute to Clang. This attribute specifies that a declaration originates
from an external source and describes the nature of that source.
This attribute is useful for mixed-language projects or project that use auto-generated code. For instance, Xcode can use this attribute to provide a correct 'jump-to-definition' feature. For a concrete example, consider a protocol that's defined in a Swift file:
@objc public protocol SwiftProtocol { func method() }
This protocol can be used from Objective-C code by including a header file that was generated by the Swift compiler. The declarations in that header can use the external_source_symbol attribute to make Clang aware of the fact that SwiftProtocol actually originates from a Swift module:
__attribute__((external_source_symbol(language=Swift,defined_in="module"))) @protocol SwiftProtocol @required - (void) method; @end
Consequently, when 'jump-to-definition' is performed at a location that references SwiftProtocol, Xcode can jump to the original definition in the Swift source file rather than jumping to the Objective-C declaration in the auto-generated header file.
his attribute uses custom parsing to specify a varying number of clauses such as 'language', 'defined_in' or 'generated_declaration'. The 'language' clause specifies the source language from which the declaration originates. The 'defined_in' clause specifies the name of the source container in which the declaration was defined (the exact definition of source container is language-specific, e.g. Swift's source containers are modules, so 'defined_in' should specify the Swift module name). The 'generated_declaration' is a flag that specifies that whether this declaration was automatically generated by some tool or not.
Is this supported by GCC? If not, it should be under the clang namespace instead of the gnu namespace. If it is supported by GCC, then you should just use a single GCC spelling.