[PATCH] D29819: Introduce an 'external_source_symbol' attribute that describes the origin and the nature of a declaration

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 10 04:48:28 PST 2017


arphaman created this revision.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D29819

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Parse/Parser.h
  lib/Parse/ParseDecl.cpp
  lib/Parse/Parser.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/Parser/attr-external-source-symbol-cxx11.cpp
  test/Parser/attr-external-source-symbol.m
  test/Sema/attr-external-source-symbol.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29819.87981.patch
Type: text/x-patch
Size: 14876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170210/f4c4c082/attachment.bin>


More information about the cfe-commits mailing list