Various questions about apinotes

A common pattern in C libraries are typedef-ed pointers, such as typedef void* CXIndex. Is there any way to import this as a wrapper struct in Swift? Here's what I tried so far:

Typedefs:
- Name: CXIndex
  SwiftName: Index
  SwiftCopyable: false
  SwiftDestroyOp: clang_disposeIndex
  SwiftNewtype: struct
  SwiftWrapper: struct

Most of these (SwiftCopyable, SwiftDestroyOp) are only for Tags, SwiftWrapper seems to be only for extensible string NSEnum and I tried SwiftNewtype because of the similarly named attribute swift_newtype attribute used to do this in source code.

Edit: Now newtyping works, the issue was that SwiftCopyable and SwiftDestroyOp aren't valid for a typedef entry. Is there a way I can apply those to the newtyped struct?

1 Like

While I'm here:


Enumerators:
- Name: CXLanguage_Invalid
  SwiftName: invalid
- Name: CXLanguage_C,
  SwiftName: c
- Name: CXLanguage_ObjC,
  SwiftName: objc
- Name: CXLanguage_CPlusPlus
  SwiftName: cpp

This doesn't actually rename ObjC or C, I assume because of case-insensitivity somewhere.

Is there a way to SwiftName into a struct?

I have CXErrorCode which I'm going to turn into a ClangError struct, I want to move CXError_Success and other enumerators to ClangError.success etc.

I don't want it to be an enum because I need to support potentially unknown rawValues

I've tried this:

Tags:
- Name: CXErrorCode
  SwiftName: ClangError
  SwiftConformsTo: Swift.Error
  EnumKind: none
Enumerators:
- Name: CXError_Success
  SwiftName: ClangError.success

The CXErrorCode part does what I want it to do but CXError_Success just disappears. It complains that CXError_Success was renamed to success but trying ClangError.success doesn't work.

How can I annotate struct fields? I'd like to do some renames and a bigger modification:

enum CXTypeKind {
  // ...
}

struct CXType {
  CXTypeKind kind;
  void *data[2];
}

should become:

struct ClangType {
  var kind: Kind
  var data: InlineArray<2, OpaquePointer?>

  enum Kind { /* ... */ }
}