mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The Clang importer maps arbitrary attributes spelled with `swift_attr("...")`
over to Swift attributes, using the Swift parser to process those attributes.
Extend this mechanism to allow `swift_attr` to refer to an attached macro,
expanding that macro as needed.
When a macro is applied to an imported declaration, that declaration is
pretty-printed (from the C++ AST) to provide to the macro implementation.
There are a few games we need to place to resolve the macro, and a few more
to lazily perform pretty-printing and adjust source locations to get the
right information to the macro, but this demonstrates that we could
take this path.
As an example, we use this mechanism to add an `async` version of a C
function that delivers its result via completion handler, using the
`@AddAsync` example macro implementation from the swift-syntax
repository.
159 lines
2.3 KiB
Plaintext
159 lines
2.3 KiB
Plaintext
module cfuncs { header "cfuncs.h" }
|
|
module ctypes {
|
|
header "ctypes.h"
|
|
explicit module bits {
|
|
header "ctypes/bits.h"
|
|
export *
|
|
}
|
|
export *
|
|
}
|
|
module stdio { header "stdio.h" }
|
|
module cvars { header "cvars.h" }
|
|
module blocks {
|
|
header "blocks.h"
|
|
export *
|
|
}
|
|
|
|
// Note: The real Darwin includes stdc stuff. This one is just for testing
|
|
// Darwin-specific things.
|
|
module Darwin {
|
|
module MacTypes {
|
|
header "MacTypes.h"
|
|
export *
|
|
}
|
|
}
|
|
|
|
module CoreMIDI {
|
|
header "CoreMIDI.h"
|
|
export *
|
|
}
|
|
|
|
module Dispatch {
|
|
header "dispatch.h"
|
|
export *
|
|
}
|
|
|
|
module MachO {
|
|
header "dyld.h"
|
|
export *
|
|
}
|
|
|
|
module AVFoundation {
|
|
header "AVFoundation.h"
|
|
export *
|
|
}
|
|
module CoreGraphics {
|
|
header "CoreGraphics.h"
|
|
export *
|
|
}
|
|
module CoreFoundation {
|
|
header "CoreFoundation.h"
|
|
export *
|
|
}
|
|
|
|
module Foundation {
|
|
header "Foundation.h"
|
|
export *
|
|
}
|
|
module AppKit {
|
|
header "AppKit.h"
|
|
export *
|
|
}
|
|
module UIKit {
|
|
header "UIKit.h"
|
|
export *
|
|
}
|
|
|
|
module NotificationCenter {
|
|
header "NotificationCenter.h"
|
|
export *
|
|
}
|
|
|
|
module objc_ext { header "objc_ext.h" }
|
|
module macros {
|
|
header "macros.h"
|
|
// Don't re-export macros_private_impl.
|
|
export macros_impl
|
|
}
|
|
module macros_impl { header "macros_impl.h" }
|
|
module macros_private_impl { header "macros_private_impl.h" }
|
|
module user_objc { header "user_objc.h" }
|
|
|
|
module Properties {
|
|
header "Properties.h"
|
|
export *
|
|
}
|
|
|
|
module Security {
|
|
header "Authorization.h"
|
|
header "SecItem.h"
|
|
export *
|
|
}
|
|
|
|
module nullability {
|
|
header "nullability.h"
|
|
export *
|
|
}
|
|
|
|
module objc_structs {
|
|
header "objc_structs.h"
|
|
export *
|
|
}
|
|
|
|
module enums_using_attributes {
|
|
header "enums_using_attributes.h"
|
|
}
|
|
|
|
module errors {
|
|
header "errors.h"
|
|
export *
|
|
}
|
|
|
|
module c_simd {
|
|
header "simd.h"
|
|
export *
|
|
}
|
|
|
|
module objc_generics {
|
|
header "objc_generics.h"
|
|
export *
|
|
}
|
|
|
|
module CoreMedia {
|
|
header "CoreMedia.h"
|
|
export *
|
|
}
|
|
|
|
module OtherSubscripts {
|
|
header "OtherSubscripts.h"
|
|
export *
|
|
}
|
|
|
|
module bridged_typedef {
|
|
header "bridged_typedef.h"
|
|
export *
|
|
}
|
|
|
|
module WinBOOL {
|
|
header "winbool.h"
|
|
export *
|
|
}
|
|
|
|
module ObjCConcurrency {
|
|
header "ObjCConcurrency.h"
|
|
export *
|
|
}
|
|
|
|
module EffectfulProperties {
|
|
header "EffectfulProperties.h"
|
|
export *
|
|
}
|
|
|
|
module IncompleteTypes {
|
|
header "IncompleteTypes.h"
|
|
export *
|
|
}
|
|
|
|
module CompletionHandlerGlobals {
|
|
header "completion_handler_globals.h"
|
|
} |