From dd7fe9185fe3357d950898beff7958e563010b5c Mon Sep 17 00:00:00 2001 From: Ben Greenier Date: Thu, 6 Jan 2022 15:45:18 -0800 Subject: [PATCH 1/2] feat(underlying-type): Use UnderlyingType BREAKING CHANGE: `*Type` declarations now reference their `*Def` peers --- packages/clangffi/src/lib/tsgen/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/clangffi/src/lib/tsgen/index.ts b/packages/clangffi/src/lib/tsgen/index.ts index 82b8aae..5797ae3 100644 --- a/packages/clangffi/src/lib/tsgen/index.ts +++ b/packages/clangffi/src/lib/tsgen/index.ts @@ -55,7 +55,7 @@ export class TsGen implements ISourceGenerator { this.typingsBuilder.appendLine(`import ffi from "ffi-napi";`); this.typingsBuilder.appendLine( - `import ref, {Pointer as TypedPointer} from "ref-napi";` + `import ref, {Pointer as TypedPointer, UnderlyingType} from "ref-napi";` ); this.typingsBuilder.appendLine( `import refStructDi, {StructObject} from "ref-struct-di";` @@ -174,7 +174,7 @@ export class TsGen implements ISourceGenerator { log(`openStruct(${name}): begin`); this.typingsBuilder.appendLine( - `export type ${name}Type = StructObject<${name}>;` + `export type ${name}Type = UnderlyingType;` ); this.typingsBuilder.appendLine(`export interface ${name} {`); this.nativeBuilder.appendLine(`export const ${name}Def = Struct({`); From 89b3988b01b41d3d73555fbe0ae300f35bd4f727 Mon Sep 17 00:00:00 2001 From: Ben Greenier Date: Sat, 8 Jan 2022 15:10:29 -0800 Subject: [PATCH 2/2] fix(libclang): Update to `UnderlyingType` defs --- packages/libclang-bindings/src/libclang.ts | 134 +++++++++++++-------- 1 file changed, 83 insertions(+), 51 deletions(-) diff --git a/packages/libclang-bindings/src/libclang.ts b/packages/libclang-bindings/src/libclang.ts index 5578081..e83c91c 100644 --- a/packages/libclang-bindings/src/libclang.ts +++ b/packages/libclang-bindings/src/libclang.ts @@ -1,5 +1,5 @@ import ffi from "ffi-napi"; -import ref, { Pointer as TypedPointer } from "ref-napi"; +import ref, { Pointer as TypedPointer, UnderlyingType } from "ref-napi"; import refStructDi, { StructObject } from "ref-struct-di"; import refArrayDi, { TypedArray } from "ref-array-di"; @@ -16,33 +16,37 @@ export enum CXErrorCode { CXError_InvalidArguments = 3, CXError_ASTReadError = 4, } -export type CXStringType = StructObject; +export type CXStringType = UnderlyingType; export interface CXString { data: TypedPointer; private_flags: number; } -export type CXStringSetType = StructObject; +export type CXStringSetType = UnderlyingType; export interface CXStringSet { Strings: TypedPointer; Count: number; } -export type CXVirtualFileOverlayImplType = - StructObject; +export type CXVirtualFileOverlayImplType = UnderlyingType< + typeof CXVirtualFileOverlayImplDef +>; export interface CXVirtualFileOverlayImpl {} export type CXVirtualFileOverlay = TypedPointer; -export type CXModuleMapDescriptorImplType = - StructObject; +export type CXModuleMapDescriptorImplType = UnderlyingType< + typeof CXModuleMapDescriptorImplDef +>; export interface CXModuleMapDescriptorImpl {} export type CXModuleMapDescriptor = TypedPointer; export type CXIndex = TypedPointer; -export type CXTargetInfoImplType = StructObject; +export type CXTargetInfoImplType = UnderlyingType; export interface CXTargetInfoImpl {} export type CXTargetInfo = TypedPointer; -export type CXTranslationUnitImplType = StructObject; +export type CXTranslationUnitImplType = UnderlyingType< + typeof CXTranslationUnitImplDef +>; export interface CXTranslationUnitImpl {} export type CXTranslationUnit = TypedPointer; export type CXClientData = TypedPointer; -export type CXUnsavedFileType = StructObject; +export type CXUnsavedFileType = UnderlyingType; export interface CXUnsavedFile { Filename: string; Contents: string; @@ -54,7 +58,7 @@ export enum CXAvailabilityKind { CXAvailability_NotAvailable = 2, CXAvailability_NotAccessible = 3, } -export type CXVersionType = StructObject; +export type CXVersionType = UnderlyingType; export interface CXVersion { Major: number; Minor: number; @@ -79,22 +83,22 @@ export enum CXGlobalOptFlags { CXGlobalOpt_ThreadBackgroundPriorityForAll = 3, } export type CXFile = TypedPointer; -export type CXFileUniqueIDType = StructObject; +export type CXFileUniqueIDType = UnderlyingType; export interface CXFileUniqueID { data: TypedArray; } -export type CXSourceLocationType = StructObject; +export type CXSourceLocationType = UnderlyingType; export interface CXSourceLocation { ptr_data: TypedArray, 2>; int_data: number; } -export type CXSourceRangeType = StructObject; +export type CXSourceRangeType = UnderlyingType; export interface CXSourceRange { ptr_data: TypedArray, 2>; begin_int_data: number; end_int_data: number; } -export type CXSourceRangeListType = StructObject; +export type CXSourceRangeListType = UnderlyingType; export interface CXSourceRangeList { count: number; ranges: TypedPointer; @@ -173,12 +177,14 @@ export enum CXTUResourceUsageKind { CXTUResourceUsage_First = 1, CXTUResourceUsage_Last = 14, } -export type CXTUResourceUsageEntryType = StructObject; +export type CXTUResourceUsageEntryType = UnderlyingType< + typeof CXTUResourceUsageEntryDef +>; export interface CXTUResourceUsageEntry { kind: CXTUResourceUsageKind; amount: number; } -export type CXTUResourceUsageType = StructObject; +export type CXTUResourceUsageType = UnderlyingType; export interface CXTUResourceUsage { data: TypedPointer; numEntries: number; @@ -457,7 +463,7 @@ export enum CXCursorKind { CXCursor_LastExtraDecl = 603, CXCursor_OverloadCandidate = 700, } -export type CXCursorType = StructObject; +export type CXCursorType = UnderlyingType; export interface CXCursor { kind: CXCursorKind; xdata: number; @@ -476,7 +482,9 @@ export enum CXVisibilityKind { CXVisibility_Protected = 2, CXVisibility_Default = 3, } -export type CXPlatformAvailabilityType = StructObject; +export type CXPlatformAvailabilityType = UnderlyingType< + typeof CXPlatformAvailabilityDef +>; export interface CXPlatformAvailability { Platform: CXString; Introduced: CXVersion; @@ -496,7 +504,7 @@ export enum CXTLSKind { CXTLS_Dynamic = 1, CXTLS_Static = 2, } -export type CXCursorSetImplType = StructObject; +export type CXCursorSetImplType = UnderlyingType; export interface CXCursorSetImpl {} export type CXCursorSet = TypedPointer; export enum CXTypeKind { @@ -644,7 +652,7 @@ export enum CXCallingConv { CXCallingConv_Invalid = 100, CXCallingConv_Unexposed = 200, } -export type CXTypeType = StructObject; +export type CXTypeType = UnderlyingType; export interface CXType { kind: CXTypeKind; data: TypedArray, 2>; @@ -775,13 +783,15 @@ export enum CXTokenKind { CXToken_Literal = 3, CXToken_Comment = 4, } -export type CXTokenType = StructObject; +export type CXTokenType = UnderlyingType; export interface CXToken { int_data: TypedArray; ptr_data: TypedPointer; } export type CXCompletionString = TypedPointer; -export type CXCompletionResultType = StructObject; +export type CXCompletionResultType = UnderlyingType< + typeof CXCompletionResultDef +>; export interface CXCompletionResult { CursorKind: CXCursorKind; CompletionString: CXCompletionString; @@ -809,7 +819,9 @@ export enum CXCompletionChunkKind { CXCompletionChunk_HorizontalSpace = 19, CXCompletionChunk_VerticalSpace = 20, } -export type CXCodeCompleteResultsType = StructObject; +export type CXCodeCompleteResultsType = UnderlyingType< + typeof CXCodeCompleteResultsDef +>; export interface CXCodeCompleteResults { Results: TypedPointer; NumResults: number; @@ -869,7 +881,9 @@ export enum CXVisitorResult { CXVisit_Break = 0, CXVisit_Continue = 1, } -export type CXCursorAndRangeVisitorType = StructObject; +export type CXCursorAndRangeVisitorType = UnderlyingType< + typeof CXCursorAndRangeVisitorDef +>; export interface CXCursorAndRangeVisitor { context: TypedPointer; visit: ( @@ -887,12 +901,14 @@ export type CXIdxClientFile = TypedPointer; export type CXIdxClientEntity = TypedPointer; export type CXIdxClientContainer = TypedPointer; export type CXIdxClientASTFile = TypedPointer; -export type CXIdxLocType = StructObject; +export type CXIdxLocType = UnderlyingType; export interface CXIdxLoc { ptr_data: TypedArray, 2>; int_data: number; } -export type CXIdxIncludedFileInfoType = StructObject; +export type CXIdxIncludedFileInfoType = UnderlyingType< + typeof CXIdxIncludedFileInfoDef +>; export interface CXIdxIncludedFileInfo { hashLoc: CXIdxLoc; filename: string; @@ -901,8 +917,9 @@ export interface CXIdxIncludedFileInfo { isAngled: number; isModuleImport: number; } -export type CXIdxImportedASTFileInfoType = - StructObject; +export type CXIdxImportedASTFileInfoType = UnderlyingType< + typeof CXIdxImportedASTFileInfoDef +>; export interface CXIdxImportedASTFileInfo { file: CXFile; module: CXModule; @@ -957,13 +974,13 @@ export enum CXIdxAttrKind { CXIdxAttr_IBOutlet = 2, CXIdxAttr_IBOutletCollection = 3, } -export type CXIdxAttrInfoType = StructObject; +export type CXIdxAttrInfoType = UnderlyingType; export interface CXIdxAttrInfo { kind: CXIdxAttrKind; cursor: CXCursor; loc: CXIdxLoc; } -export type CXIdxEntityInfoType = StructObject; +export type CXIdxEntityInfoType = UnderlyingType; export interface CXIdxEntityInfo { kind: CXIdxEntityKind; templateKind: CXIdxEntityCXXTemplateKind; @@ -974,12 +991,15 @@ export interface CXIdxEntityInfo { attributes: TypedPointer>; numAttributes: number; } -export type CXIdxContainerInfoType = StructObject; +export type CXIdxContainerInfoType = UnderlyingType< + typeof CXIdxContainerInfoDef +>; export interface CXIdxContainerInfo { cursor: CXCursor; } -export type CXIdxIBOutletCollectionAttrInfoType = - StructObject; +export type CXIdxIBOutletCollectionAttrInfoType = UnderlyingType< + typeof CXIdxIBOutletCollectionAttrInfoDef +>; export interface CXIdxIBOutletCollectionAttrInfo { attrInfo: TypedPointer; objcClass: TypedPointer; @@ -989,7 +1009,7 @@ export interface CXIdxIBOutletCollectionAttrInfo { export enum CXIdxDeclInfoFlags { CXIdxDeclFlag_Skipped = 1, } -export type CXIdxDeclInfoType = StructObject; +export type CXIdxDeclInfoType = UnderlyingType; export interface CXIdxDeclInfo { entityInfo: TypedPointer; cursor: CXCursor; @@ -1010,40 +1030,47 @@ export enum CXIdxObjCContainerKind { CXIdxObjCContainer_Interface = 1, CXIdxObjCContainer_Implementation = 2, } -export type CXIdxObjCContainerDeclInfoType = - StructObject; +export type CXIdxObjCContainerDeclInfoType = UnderlyingType< + typeof CXIdxObjCContainerDeclInfoDef +>; export interface CXIdxObjCContainerDeclInfo { declInfo: TypedPointer; kind: CXIdxObjCContainerKind; } -export type CXIdxBaseClassInfoType = StructObject; +export type CXIdxBaseClassInfoType = UnderlyingType< + typeof CXIdxBaseClassInfoDef +>; export interface CXIdxBaseClassInfo { base: TypedPointer; cursor: CXCursor; loc: CXIdxLoc; } -export type CXIdxObjCProtocolRefInfoType = - StructObject; +export type CXIdxObjCProtocolRefInfoType = UnderlyingType< + typeof CXIdxObjCProtocolRefInfoDef +>; export interface CXIdxObjCProtocolRefInfo { protocol: TypedPointer; cursor: CXCursor; loc: CXIdxLoc; } -export type CXIdxObjCProtocolRefListInfoType = - StructObject; +export type CXIdxObjCProtocolRefListInfoType = UnderlyingType< + typeof CXIdxObjCProtocolRefListInfoDef +>; export interface CXIdxObjCProtocolRefListInfo { protocols: TypedPointer>; numProtocols: number; } -export type CXIdxObjCInterfaceDeclInfoType = - StructObject; +export type CXIdxObjCInterfaceDeclInfoType = UnderlyingType< + typeof CXIdxObjCInterfaceDeclInfoDef +>; export interface CXIdxObjCInterfaceDeclInfo { containerInfo: TypedPointer; superInfo: TypedPointer; protocols: TypedPointer; } -export type CXIdxObjCCategoryDeclInfoType = - StructObject; +export type CXIdxObjCCategoryDeclInfoType = UnderlyingType< + typeof CXIdxObjCCategoryDeclInfoDef +>; export interface CXIdxObjCCategoryDeclInfo { containerInfo: TypedPointer; objcClass: TypedPointer; @@ -1051,14 +1078,17 @@ export interface CXIdxObjCCategoryDeclInfo { classLoc: CXIdxLoc; protocols: TypedPointer; } -export type CXIdxObjCPropertyDeclInfoType = - StructObject; +export type CXIdxObjCPropertyDeclInfoType = UnderlyingType< + typeof CXIdxObjCPropertyDeclInfoDef +>; export interface CXIdxObjCPropertyDeclInfo { declInfo: TypedPointer; getter: TypedPointer; setter: TypedPointer; } -export type CXIdxCXXClassDeclInfoType = StructObject; +export type CXIdxCXXClassDeclInfoType = UnderlyingType< + typeof CXIdxCXXClassDeclInfoDef +>; export interface CXIdxCXXClassDeclInfo { declInfo: TypedPointer; bases: TypedPointer>; @@ -1080,7 +1110,9 @@ export enum CXSymbolRole { CXSymbolRole_AddressOf = 128, CXSymbolRole_Implicit = 256, } -export type CXIdxEntityRefInfoType = StructObject; +export type CXIdxEntityRefInfoType = UnderlyingType< + typeof CXIdxEntityRefInfoDef +>; export interface CXIdxEntityRefInfo { kind: CXIdxEntityRefKind; cursor: CXCursor; @@ -1090,7 +1122,7 @@ export interface CXIdxEntityRefInfo { container: TypedPointer; role: CXSymbolRole; } -export type IndexerCallbacksType = StructObject; +export type IndexerCallbacksType = UnderlyingType; export interface IndexerCallbacks { abortQuery: (arg0: CXClientData, arg1: TypedPointer) => number; diagnostic: (