nitrogen 0.2.23 → 0.29.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -109
- package/lib/Logger.d.ts +10 -0
- package/lib/Logger.js +56 -0
- package/lib/autolinking/Autolinking.d.ts +8 -0
- package/lib/autolinking/Autolinking.js +1 -0
- package/lib/autolinking/android/createCMakeExtension.d.ts +6 -0
- package/lib/autolinking/android/createCMakeExtension.js +106 -0
- package/lib/autolinking/android/createGradleExtension.d.ts +5 -0
- package/lib/autolinking/android/createGradleExtension.js +36 -0
- package/lib/autolinking/android/createHybridObjectInitializer.d.ts +2 -0
- package/lib/autolinking/android/createHybridObjectInitializer.js +159 -0
- package/lib/autolinking/createAndroidAutolinking.d.ts +11 -0
- package/lib/autolinking/createAndroidAutolinking.js +13 -0
- package/lib/autolinking/createIOSAutolinking.d.ts +5 -0
- package/lib/autolinking/createIOSAutolinking.js +19 -0
- package/lib/autolinking/ios/createHybridObjectInitializer.d.ts +9 -0
- package/lib/autolinking/ios/createHybridObjectInitializer.js +97 -0
- package/lib/autolinking/ios/createPodspecRubyExtension.d.ts +5 -0
- package/lib/autolinking/ios/createPodspecRubyExtension.js +69 -0
- package/lib/autolinking/ios/createSwiftCxxBridge.d.ts +2 -0
- package/lib/autolinking/ios/createSwiftCxxBridge.js +117 -0
- package/lib/autolinking/ios/createSwiftUmbrellaHeader.d.ts +3 -0
- package/lib/autolinking/ios/createSwiftUmbrellaHeader.js +74 -0
- package/lib/config/NitroConfig.d.ts +52 -0
- package/lib/config/NitroConfig.js +112 -0
- package/lib/config/NitroUserConfig.d.ts +22 -0
- package/lib/config/NitroUserConfig.js +88 -0
- package/lib/config/getConfig.d.ts +2 -0
- package/lib/config/getConfig.js +84 -0
- package/lib/createGitAttributes.d.ts +1 -0
- package/lib/createGitAttributes.js +11 -0
- package/lib/createPlatformSpec.d.ts +4 -0
- package/lib/createPlatformSpec.js +127 -0
- package/lib/getFiles.d.ts +1 -0
- package/lib/getFiles.js +28 -0
- package/lib/getPlatformSpecs.d.ts +17 -0
- package/lib/getPlatformSpecs.js +153 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +113 -10
- package/lib/init.d.ts +1 -0
- package/lib/init.js +123 -0
- package/lib/nitrogen.d.ts +11 -0
- package/lib/nitrogen.js +165 -0
- package/lib/prettifyDirectory.d.ts +1 -0
- package/lib/prettifyDirectory.js +27 -0
- package/lib/syntax/BridgedType.d.ts +41 -0
- package/lib/syntax/BridgedType.js +1 -0
- package/lib/syntax/CodeNode.d.ts +23 -0
- package/lib/syntax/CodeNode.js +1 -0
- package/lib/syntax/HybridObjectSpec.d.ts +13 -0
- package/lib/syntax/HybridObjectSpec.js +1 -0
- package/lib/syntax/Method.d.ts +41 -0
- package/lib/syntax/Method.js +108 -0
- package/lib/syntax/Parameter.d.ts +15 -0
- package/lib/syntax/Parameter.js +65 -0
- package/lib/syntax/Property.d.ts +50 -0
- package/lib/syntax/Property.js +147 -0
- package/lib/syntax/SourceFile.d.ts +70 -0
- package/lib/syntax/SourceFile.js +7 -0
- package/lib/syntax/c++/CppEnum.d.ts +6 -0
- package/lib/syntax/c++/CppEnum.js +110 -0
- package/lib/syntax/c++/CppHybridObject.d.ts +3 -0
- package/lib/syntax/c++/CppHybridObject.js +146 -0
- package/lib/syntax/c++/CppHybridObjectRegistration.d.ts +17 -0
- package/lib/syntax/c++/CppHybridObjectRegistration.js +18 -0
- package/lib/syntax/c++/CppStruct.d.ts +3 -0
- package/lib/syntax/c++/CppStruct.js +108 -0
- package/lib/syntax/c++/CppUnion.d.ts +6 -0
- package/lib/syntax/c++/CppUnion.js +88 -0
- package/lib/syntax/c++/getForwardDeclaration.d.ts +3 -0
- package/lib/syntax/c++/getForwardDeclaration.js +14 -0
- package/lib/syntax/c++/includeNitroHeader.d.ts +7 -0
- package/lib/syntax/c++/includeNitroHeader.js +34 -0
- package/lib/syntax/createType.d.ts +15 -0
- package/lib/syntax/createType.js +303 -0
- package/lib/syntax/getAllTypes.d.ts +3 -0
- package/lib/syntax/getAllTypes.js +11 -0
- package/lib/syntax/getCustomTypeConfig.d.ts +8 -0
- package/lib/syntax/getCustomTypeConfig.js +53 -0
- package/lib/syntax/getHybridObjectName.d.ts +36 -0
- package/lib/syntax/getHybridObjectName.js +10 -0
- package/lib/syntax/getInterfaceProperties.d.ts +4 -0
- package/lib/syntax/getInterfaceProperties.js +9 -0
- package/lib/syntax/getReferencedTypes.d.ts +2 -0
- package/lib/syntax/getReferencedTypes.js +47 -0
- package/lib/syntax/helpers.d.ts +13 -0
- package/lib/syntax/helpers.js +53 -0
- package/lib/syntax/isCoreType.d.ts +9 -0
- package/lib/syntax/isCoreType.js +47 -0
- package/lib/syntax/kotlin/FbjniHybridObject.d.ts +3 -0
- package/lib/syntax/kotlin/FbjniHybridObject.js +261 -0
- package/lib/syntax/kotlin/JNINativeRegistrations.d.ts +8 -0
- package/lib/syntax/kotlin/JNINativeRegistrations.js +7 -0
- package/lib/syntax/kotlin/KotlinBoxedPrimitive.d.ts +7 -0
- package/lib/syntax/kotlin/KotlinBoxedPrimitive.js +17 -0
- package/lib/syntax/kotlin/KotlinCxxBridgedType.d.ts +19 -0
- package/lib/syntax/kotlin/KotlinCxxBridgedType.js +893 -0
- package/lib/syntax/kotlin/KotlinEnum.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinEnum.js +113 -0
- package/lib/syntax/kotlin/KotlinFunction.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinFunction.js +256 -0
- package/lib/syntax/kotlin/KotlinHybridObject.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinHybridObject.js +177 -0
- package/lib/syntax/kotlin/KotlinHybridObjectRegistration.d.ts +17 -0
- package/lib/syntax/kotlin/KotlinHybridObjectRegistration.js +26 -0
- package/lib/syntax/kotlin/KotlinStruct.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinStruct.js +172 -0
- package/lib/syntax/kotlin/KotlinVariant.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinVariant.js +191 -0
- package/lib/syntax/swift/SwiftCxxBridgedType.d.ts +21 -0
- package/lib/syntax/swift/SwiftCxxBridgedType.js +819 -0
- package/lib/syntax/swift/SwiftCxxTypeHelper.d.ts +17 -0
- package/lib/syntax/swift/SwiftCxxTypeHelper.js +613 -0
- package/lib/syntax/swift/SwiftEnum.d.ts +3 -0
- package/lib/syntax/swift/SwiftEnum.js +52 -0
- package/lib/syntax/swift/SwiftFunction.d.ts +3 -0
- package/lib/syntax/swift/SwiftFunction.js +83 -0
- package/lib/syntax/swift/SwiftHybridObject.d.ts +3 -0
- package/lib/syntax/swift/SwiftHybridObject.js +103 -0
- package/lib/syntax/swift/SwiftHybridObjectBridge.d.ts +11 -0
- package/lib/syntax/swift/SwiftHybridObjectBridge.js +451 -0
- package/lib/syntax/swift/SwiftHybridObjectRegistration.d.ts +19 -0
- package/lib/syntax/swift/SwiftHybridObjectRegistration.js +42 -0
- package/lib/syntax/swift/SwiftStruct.d.ts +3 -0
- package/lib/syntax/swift/SwiftStruct.js +75 -0
- package/lib/syntax/swift/SwiftVariant.d.ts +3 -0
- package/lib/syntax/swift/SwiftVariant.js +58 -0
- package/lib/syntax/types/ArrayBufferType.d.ts +10 -0
- package/lib/syntax/types/ArrayBufferType.js +37 -0
- package/lib/syntax/types/ArrayType.d.ts +12 -0
- package/lib/syntax/types/ArrayType.js +52 -0
- package/lib/syntax/types/BigIntType.d.ts +10 -0
- package/lib/syntax/types/BigIntType.js +27 -0
- package/lib/syntax/types/BooleanType.d.ts +10 -0
- package/lib/syntax/types/BooleanType.js +27 -0
- package/lib/syntax/types/CustomType.d.ts +14 -0
- package/lib/syntax/types/CustomType.js +36 -0
- package/lib/syntax/types/DateType.d.ts +10 -0
- package/lib/syntax/types/DateType.js +35 -0
- package/lib/syntax/types/EnumType.d.ts +23 -0
- package/lib/syntax/types/EnumType.js +101 -0
- package/lib/syntax/types/ErrorType.d.ts +11 -0
- package/lib/syntax/types/ErrorType.js +37 -0
- package/lib/syntax/types/FunctionType.d.ts +29 -0
- package/lib/syntax/types/FunctionType.js +147 -0
- package/lib/syntax/types/HybridObjectBaseType.d.ts +11 -0
- package/lib/syntax/types/HybridObjectBaseType.js +38 -0
- package/lib/syntax/types/HybridObjectType.d.ts +23 -0
- package/lib/syntax/types/HybridObjectType.js +131 -0
- package/lib/syntax/types/MapType.d.ts +10 -0
- package/lib/syntax/types/MapType.js +37 -0
- package/lib/syntax/types/NamedWrappingType.d.ts +14 -0
- package/lib/syntax/types/NamedWrappingType.js +27 -0
- package/lib/syntax/types/NullType.d.ts +10 -0
- package/lib/syntax/types/NullType.js +23 -0
- package/lib/syntax/types/NumberType.d.ts +10 -0
- package/lib/syntax/types/NumberType.js +27 -0
- package/lib/syntax/types/OptionalType.d.ts +13 -0
- package/lib/syntax/types/OptionalType.js +59 -0
- package/lib/syntax/types/PromiseType.d.ts +16 -0
- package/lib/syntax/types/PromiseType.js +62 -0
- package/lib/syntax/types/RecordType.d.ts +13 -0
- package/lib/syntax/types/RecordType.js +47 -0
- package/lib/syntax/types/ResultWrappingType.d.ts +13 -0
- package/lib/syntax/types/ResultWrappingType.js +44 -0
- package/lib/syntax/types/StringType.d.ts +10 -0
- package/lib/syntax/types/StringType.js +35 -0
- package/lib/syntax/types/StructType.d.ts +14 -0
- package/lib/syntax/types/StructType.js +61 -0
- package/lib/syntax/types/TupleType.d.ts +12 -0
- package/lib/syntax/types/TupleType.js +39 -0
- package/lib/syntax/types/Type.d.ts +55 -0
- package/lib/syntax/types/Type.js +1 -0
- package/lib/syntax/types/VariantType.d.ts +19 -0
- package/lib/syntax/types/VariantType.js +75 -0
- package/lib/syntax/types/VoidType.d.ts +10 -0
- package/lib/syntax/types/VoidType.js +27 -0
- package/lib/syntax/types/getTypeAs.d.ts +2 -0
- package/lib/syntax/types/getTypeAs.js +12 -0
- package/lib/utils.d.ts +22 -0
- package/lib/utils.js +126 -0
- package/lib/views/CppHybridViewComponent.d.ts +14 -0
- package/lib/views/CppHybridViewComponent.js +254 -0
- package/lib/views/createHostComponentJs.d.ts +3 -0
- package/lib/views/createHostComponentJs.js +27 -0
- package/lib/views/kotlin/KotlinHybridViewManager.d.ts +3 -0
- package/lib/views/kotlin/KotlinHybridViewManager.js +229 -0
- package/lib/views/swift/SwiftHybridViewManager.d.ts +3 -0
- package/lib/views/swift/SwiftHybridViewManager.js +131 -0
- package/lib/writeFile.d.ts +5 -0
- package/lib/writeFile.js +19 -0
- package/package.json +58 -29
- package/src/Logger.ts +63 -0
- package/src/autolinking/Autolinking.ts +9 -0
- package/src/autolinking/android/createCMakeExtension.ts +123 -0
- package/src/autolinking/android/createGradleExtension.ts +43 -0
- package/src/autolinking/android/createHybridObjectInitializer.ts +174 -0
- package/src/autolinking/createAndroidAutolinking.ts +28 -0
- package/src/autolinking/createIOSAutolinking.ts +24 -0
- package/src/autolinking/ios/createHybridObjectInitializer.ts +112 -0
- package/src/autolinking/ios/createPodspecRubyExtension.ts +76 -0
- package/src/autolinking/ios/createSwiftCxxBridge.ts +137 -0
- package/src/autolinking/ios/createSwiftUmbrellaHeader.ts +90 -0
- package/src/config/NitroConfig.ts +139 -0
- package/src/config/NitroUserConfig.ts +105 -0
- package/src/config/getConfig.ts +91 -0
- package/src/createGitAttributes.ts +15 -0
- package/src/createPlatformSpec.ts +176 -0
- package/src/getFiles.ts +31 -0
- package/src/getPlatformSpecs.ts +202 -0
- package/src/index.ts +146 -0
- package/src/init.ts +186 -0
- package/src/nitrogen.ts +246 -0
- package/src/prettifyDirectory.ts +32 -0
- package/src/syntax/BridgedType.ts +59 -0
- package/src/syntax/CodeNode.ts +24 -0
- package/src/syntax/HybridObjectSpec.ts +14 -0
- package/src/syntax/Method.ts +154 -0
- package/src/syntax/Parameter.ts +81 -0
- package/src/syntax/Property.ts +203 -0
- package/src/syntax/SourceFile.ts +80 -0
- package/src/syntax/c++/CppEnum.ts +128 -0
- package/src/syntax/c++/CppHybridObject.ts +165 -0
- package/src/syntax/c++/CppHybridObjectRegistration.ts +39 -0
- package/src/syntax/c++/CppStruct.ts +129 -0
- package/src/syntax/c++/CppUnion.ts +105 -0
- package/src/syntax/c++/getForwardDeclaration.ts +19 -0
- package/src/syntax/c++/includeNitroHeader.ts +40 -0
- package/src/syntax/createType.ts +365 -0
- package/src/syntax/getAllTypes.ts +18 -0
- package/src/syntax/getCustomTypeConfig.ts +71 -0
- package/src/syntax/getHybridObjectName.ts +48 -0
- package/src/syntax/getInterfaceProperties.ts +21 -0
- package/src/syntax/getReferencedTypes.ts +57 -0
- package/src/syntax/helpers.ts +79 -0
- package/src/syntax/isCoreType.ts +60 -0
- package/src/syntax/kotlin/FbjniHybridObject.ts +313 -0
- package/src/syntax/kotlin/JNINativeRegistrations.ts +19 -0
- package/src/syntax/kotlin/KotlinBoxedPrimitive.ts +19 -0
- package/src/syntax/kotlin/KotlinCxxBridgedType.ts +942 -0
- package/src/syntax/kotlin/KotlinEnum.ts +130 -0
- package/src/syntax/kotlin/KotlinFunction.ts +277 -0
- package/src/syntax/kotlin/KotlinHybridObject.ts +205 -0
- package/src/syntax/kotlin/KotlinHybridObjectRegistration.ts +51 -0
- package/src/syntax/kotlin/KotlinStruct.ts +198 -0
- package/src/syntax/kotlin/KotlinVariant.ts +212 -0
- package/src/syntax/swift/SwiftCxxBridgedType.ts +874 -0
- package/src/syntax/swift/SwiftCxxTypeHelper.ts +674 -0
- package/src/syntax/swift/SwiftEnum.ts +65 -0
- package/src/syntax/swift/SwiftFunction.ts +91 -0
- package/src/syntax/swift/SwiftHybridObject.ts +121 -0
- package/src/syntax/swift/SwiftHybridObjectBridge.ts +522 -0
- package/src/syntax/swift/SwiftHybridObjectRegistration.ts +75 -0
- package/src/syntax/swift/SwiftStruct.ts +85 -0
- package/src/syntax/swift/SwiftVariant.ts +67 -0
- package/src/syntax/types/ArrayBufferType.ts +49 -0
- package/src/syntax/types/ArrayType.ts +62 -0
- package/src/syntax/types/BigIntType.ts +35 -0
- package/src/syntax/types/BooleanType.ts +35 -0
- package/src/syntax/types/CustomType.ts +47 -0
- package/src/syntax/types/DateType.ts +43 -0
- package/src/syntax/types/EnumType.ts +130 -0
- package/src/syntax/types/ErrorType.ts +44 -0
- package/src/syntax/types/FunctionType.ts +167 -0
- package/src/syntax/types/HybridObjectBaseType.ts +54 -0
- package/src/syntax/types/HybridObjectType.ts +198 -0
- package/src/syntax/types/MapType.ts +49 -0
- package/src/syntax/types/NamedWrappingType.ts +33 -0
- package/src/syntax/types/NullType.ts +30 -0
- package/src/syntax/types/NumberType.ts +34 -0
- package/src/syntax/types/OptionalType.ts +66 -0
- package/src/syntax/types/PromiseType.ts +72 -0
- package/src/syntax/types/RecordType.ts +56 -0
- package/src/syntax/types/ResultWrappingType.ts +53 -0
- package/src/syntax/types/StringType.ts +44 -0
- package/src/syntax/types/StructType.ts +83 -0
- package/src/syntax/types/TupleType.ts +53 -0
- package/src/syntax/types/Type.ts +82 -0
- package/src/syntax/types/VariantType.ts +92 -0
- package/src/syntax/types/VoidType.ts +34 -0
- package/src/syntax/types/getTypeAs.ts +15 -0
- package/src/utils.ts +162 -0
- package/src/views/CppHybridViewComponent.ts +301 -0
- package/src/views/createHostComponentJs.ts +34 -0
- package/src/views/kotlin/KotlinHybridViewManager.ts +258 -0
- package/src/views/swift/SwiftHybridViewManager.ts +153 -0
- package/src/writeFile.ts +27 -0
- package/.jshintignore +0 -6
- package/.jshintrc +0 -3
- package/.npmignore +0 -3
- package/.travis.yml +0 -13
- package/LICENSE +0 -13
- package/browser/nitrogen-min.js +0 -3
- package/browser/nitrogen.js +0 -6369
- package/lib/apiKey.js +0 -67
- package/lib/blob.js +0 -57
- package/lib/commandManager.js +0 -350
- package/lib/device.js +0 -19
- package/lib/memoryStore.js +0 -24
- package/lib/message.js +0 -298
- package/lib/permission.js +0 -121
- package/lib/principal.js +0 -330
- package/lib/service.js +0 -349
- package/lib/session.js +0 -494
- package/lib/user.js +0 -20
- package/publish +0 -2
- package/scripts/build-documentation +0 -4
- package/scripts/build-module +0 -27
- package/scripts/module.js +0 -12
- package/scripts/postamble.js +0 -1
- package/scripts/preamble.js +0 -2
- package/scripts/run-test-server +0 -9
- package/test/config.js +0 -12
- package/test/fixtures/images/image.jpg +0 -0
- package/test/fixtures/images/motion0.jpg +0 -0
- package/test/fixtures/images/motion1.jpg +0 -0
- package/test/fixtures/images/motion2.jpg +0 -0
- package/test/fixtures/index.js +0 -76
- package/test/main.js +0 -5
- package/test/memoryStore.js +0 -22
- package/test/mocha.opts +0 -3
- package/test/units/apiKey.js +0 -46
- package/test/units/blob.js +0 -35
- package/test/units/commandManager.js +0 -67
- package/test/units/device.js +0 -26
- package/test/units/heartbeat.js +0 -28
- package/test/units/message.js +0 -79
- package/test/units/permissions.js +0 -43
- package/test/units/principal.js +0 -116
- package/test/units/service.js +0 -92
- package/test/units/session.js +0 -97
- package/test/units/user.js +0 -48
- package/yuidoc.json +0 -8
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { NitroConfig } from '../../config/NitroConfig.js';
|
|
2
|
+
import { indent } from '../../utils.js';
|
|
3
|
+
import { getHybridObjectName } from '../getHybridObjectName.js';
|
|
4
|
+
import { HybridObjectType } from '../types/HybridObjectType.js';
|
|
5
|
+
import { SwiftCxxBridgedType } from './SwiftCxxBridgedType.js';
|
|
6
|
+
export function getHybridObjectConstructorCall(hybridObjectName) {
|
|
7
|
+
const swiftNamespace = NitroConfig.current.getIosModuleName();
|
|
8
|
+
const autolinkingClassName = `${swiftNamespace}Autolinking`;
|
|
9
|
+
return `${swiftNamespace}::${autolinkingClassName}::create${hybridObjectName}();`;
|
|
10
|
+
}
|
|
11
|
+
export function createSwiftHybridObjectRegistration({ hybridObjectName, swiftClassName, }) {
|
|
12
|
+
const { HybridTSpecCxx, HybridTSpecSwift, HybridTSpec } = getHybridObjectName(hybridObjectName);
|
|
13
|
+
const type = new HybridObjectType(hybridObjectName, 'swift', [], NitroConfig.current);
|
|
14
|
+
const bridge = new SwiftCxxBridgedType(type);
|
|
15
|
+
return {
|
|
16
|
+
swiftFunction: `
|
|
17
|
+
/**
|
|
18
|
+
* Creates an instance of a Swift class that implements \`${HybridTSpec}\`,
|
|
19
|
+
* and wraps it in a Swift class that can directly interop with C++ (\`${HybridTSpecCxx}\`)
|
|
20
|
+
*
|
|
21
|
+
* This is generated by Nitrogen and will initialize the class specified
|
|
22
|
+
* in the \`"autolinking"\` property of \`nitro.json\` (in this case, \`${swiftClassName}\`).
|
|
23
|
+
*/
|
|
24
|
+
public static func create${hybridObjectName}() -> ${bridge.getTypeCode('swift')} {
|
|
25
|
+
let hybridObject = ${swiftClassName}()
|
|
26
|
+
return ${indent(bridge.parseFromSwiftToCpp('hybridObject', 'swift'), ' ')}
|
|
27
|
+
}
|
|
28
|
+
`.trim(),
|
|
29
|
+
requiredImports: [
|
|
30
|
+
{ name: `${HybridTSpecSwift}.hpp`, language: 'c++', space: 'user' },
|
|
31
|
+
],
|
|
32
|
+
cppCode: `
|
|
33
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
34
|
+
"${hybridObjectName}",
|
|
35
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
36
|
+
${type.getCode('c++')} hybridObject = ${getHybridObjectConstructorCall(hybridObjectName)}
|
|
37
|
+
return hybridObject;
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
`.trim(),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { NitroConfig } from '../../config/NitroConfig.js';
|
|
2
|
+
import { indent } from '../../utils.js';
|
|
3
|
+
import { createFileMetadataString } from '../helpers.js';
|
|
4
|
+
import { Parameter } from '../Parameter.js';
|
|
5
|
+
import { StructType } from '../types/StructType.js';
|
|
6
|
+
import { SwiftCxxBridgedType } from './SwiftCxxBridgedType.js';
|
|
7
|
+
export function createSwiftStructBridge(struct) {
|
|
8
|
+
const fullName = NitroConfig.current.getCxxNamespace('swift', struct.structName);
|
|
9
|
+
const bridgeNamespace = NitroConfig.current.getSwiftBridgeNamespace('swift');
|
|
10
|
+
const init = createSwiftBridgedConstructor(struct);
|
|
11
|
+
const bridgedProps = struct.properties
|
|
12
|
+
.map((p) => {
|
|
13
|
+
const bridge = new SwiftCxxBridgedType(p, true);
|
|
14
|
+
const cppName = `self.__${p.escapedName}`;
|
|
15
|
+
return `
|
|
16
|
+
var ${p.escapedName}: ${p.getCode('swift')} {
|
|
17
|
+
@inline(__always)
|
|
18
|
+
get {
|
|
19
|
+
return ${indent(bridge.parseFromCppToSwift(cppName, 'swift'), ' ')}
|
|
20
|
+
}
|
|
21
|
+
@inline(__always)
|
|
22
|
+
set {
|
|
23
|
+
${cppName} = ${indent(bridge.parseFromSwiftToCpp('newValue', 'swift'), ' ')}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
`.trim();
|
|
27
|
+
})
|
|
28
|
+
.join('\n\n');
|
|
29
|
+
const code = `
|
|
30
|
+
${createFileMetadataString(`${struct.structName}.swift`)}
|
|
31
|
+
|
|
32
|
+
import NitroModules
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Represents an instance of \`${struct.structName}\`, backed by a C++ struct.
|
|
36
|
+
*/
|
|
37
|
+
public typealias ${struct.structName} = ${fullName}
|
|
38
|
+
|
|
39
|
+
public extension ${struct.structName} {
|
|
40
|
+
private typealias bridge = ${bridgeNamespace}
|
|
41
|
+
|
|
42
|
+
${indent(init, ' ')}
|
|
43
|
+
|
|
44
|
+
${indent(bridgedProps, ' ')}
|
|
45
|
+
}
|
|
46
|
+
`.trim();
|
|
47
|
+
return {
|
|
48
|
+
content: code,
|
|
49
|
+
language: 'swift',
|
|
50
|
+
name: `${struct.structName}.swift`,
|
|
51
|
+
platform: 'ios',
|
|
52
|
+
subdirectory: [],
|
|
53
|
+
referencedTypes: struct.properties,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function createSwiftBridgedConstructor(struct) {
|
|
57
|
+
const params = struct.properties
|
|
58
|
+
.map((p) => new Parameter(p.escapedName, p))
|
|
59
|
+
.map((p) => p.getCode('swift'))
|
|
60
|
+
.join(', ');
|
|
61
|
+
const paramsForward = struct.properties
|
|
62
|
+
.map((p) => {
|
|
63
|
+
const bridged = new SwiftCxxBridgedType(p, true);
|
|
64
|
+
return bridged.parseFromSwiftToCpp(p.escapedName, 'swift');
|
|
65
|
+
})
|
|
66
|
+
.join(', ');
|
|
67
|
+
return `
|
|
68
|
+
/**
|
|
69
|
+
* Create a new instance of \`${struct.structName}\`.
|
|
70
|
+
*/
|
|
71
|
+
init(${params}) {
|
|
72
|
+
self.init(${indent(paramsForward, ' ')})
|
|
73
|
+
}
|
|
74
|
+
`.trim();
|
|
75
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { indent } from '../../utils.js';
|
|
2
|
+
import { createFileMetadataString } from '../helpers.js';
|
|
3
|
+
import { getTypeAs } from '../types/getTypeAs.js';
|
|
4
|
+
import { OptionalType } from '../types/OptionalType.js';
|
|
5
|
+
function isPrimitive(type) {
|
|
6
|
+
switch (type.kind) {
|
|
7
|
+
case 'bigint':
|
|
8
|
+
case 'boolean':
|
|
9
|
+
case 'number':
|
|
10
|
+
case 'string':
|
|
11
|
+
case 'void':
|
|
12
|
+
case 'result-wrapper':
|
|
13
|
+
case 'null':
|
|
14
|
+
case 'error':
|
|
15
|
+
return true;
|
|
16
|
+
case 'optional':
|
|
17
|
+
const optional = getTypeAs(type, OptionalType);
|
|
18
|
+
return isPrimitive(optional.wrappingType);
|
|
19
|
+
default:
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function createSwiftVariant(variant) {
|
|
24
|
+
const typename = variant.getAliasName('swift');
|
|
25
|
+
const cases = variant.cases
|
|
26
|
+
.map(([label, v]) => {
|
|
27
|
+
const type = v.getCode('swift');
|
|
28
|
+
return `case ${label}(${type})`;
|
|
29
|
+
})
|
|
30
|
+
.join('\n');
|
|
31
|
+
const jsSignature = variant.variants.map((t) => t.kind).join(' | ');
|
|
32
|
+
const allPrimitives = variant.variants.every((v) => isPrimitive(v));
|
|
33
|
+
const enumDeclaration = allPrimitives ? 'enum' : 'indirect enum';
|
|
34
|
+
const extraImports = variant.variants
|
|
35
|
+
.flatMap((t) => t.getRequiredImports('swift'))
|
|
36
|
+
.map((i) => `import ${i.name}`);
|
|
37
|
+
const code = `
|
|
38
|
+
${createFileMetadataString(`${typename}.swift`)}
|
|
39
|
+
|
|
40
|
+
${extraImports.join('\n')}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* An Swift enum with associated values representing a Variant/Union type.
|
|
44
|
+
* JS type: \`${jsSignature}\`
|
|
45
|
+
*/
|
|
46
|
+
@frozen
|
|
47
|
+
public ${enumDeclaration} ${typename} {
|
|
48
|
+
${indent(cases, ' ')}
|
|
49
|
+
}
|
|
50
|
+
`.trim();
|
|
51
|
+
return {
|
|
52
|
+
content: code,
|
|
53
|
+
language: 'swift',
|
|
54
|
+
name: `${typename}.swift`,
|
|
55
|
+
platform: 'ios',
|
|
56
|
+
subdirectory: [],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class ArrayBufferType implements Type {
|
|
5
|
+
get canBePassedByReference(): boolean;
|
|
6
|
+
get kind(): TypeKind;
|
|
7
|
+
getCode(language: Language): string;
|
|
8
|
+
getExtraFiles(): SourceFile[];
|
|
9
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getForwardDeclaration } from '../c++/getForwardDeclaration.js';
|
|
2
|
+
export class ArrayBufferType {
|
|
3
|
+
get canBePassedByReference() {
|
|
4
|
+
// It's a shared_ptr.
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
get kind() {
|
|
8
|
+
return 'array-buffer';
|
|
9
|
+
}
|
|
10
|
+
getCode(language) {
|
|
11
|
+
switch (language) {
|
|
12
|
+
case 'c++':
|
|
13
|
+
return 'std::shared_ptr<ArrayBuffer>';
|
|
14
|
+
case 'swift':
|
|
15
|
+
return 'ArrayBuffer';
|
|
16
|
+
case 'kotlin':
|
|
17
|
+
return 'ArrayBuffer';
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`Language ${language} is not yet supported for ArrayBufferType!`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
getExtraFiles() {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
getRequiredImports(language) {
|
|
26
|
+
const imports = [];
|
|
27
|
+
if (language === 'c++') {
|
|
28
|
+
imports.push({
|
|
29
|
+
name: 'NitroModules/ArrayBuffer.hpp',
|
|
30
|
+
forwardDeclaration: getForwardDeclaration('class', 'ArrayBuffer', 'NitroModules'),
|
|
31
|
+
language: 'c++',
|
|
32
|
+
space: 'system',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return imports;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import { type SourceFile, type SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { GetCodeOptions, Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class ArrayType implements Type {
|
|
5
|
+
readonly itemType: Type;
|
|
6
|
+
constructor(itemType: Type);
|
|
7
|
+
get canBePassedByReference(): boolean;
|
|
8
|
+
get kind(): TypeKind;
|
|
9
|
+
getCode(language: Language, options?: GetCodeOptions): string;
|
|
10
|
+
getExtraFiles(): SourceFile[];
|
|
11
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {} from '../SourceFile.js';
|
|
2
|
+
export class ArrayType {
|
|
3
|
+
itemType;
|
|
4
|
+
constructor(itemType) {
|
|
5
|
+
this.itemType = itemType;
|
|
6
|
+
}
|
|
7
|
+
get canBePassedByReference() {
|
|
8
|
+
// It's a vector<..>, heavy to copy
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
get kind() {
|
|
12
|
+
return 'array';
|
|
13
|
+
}
|
|
14
|
+
getCode(language, options) {
|
|
15
|
+
const itemCode = this.itemType.getCode(language, options);
|
|
16
|
+
switch (language) {
|
|
17
|
+
case 'c++':
|
|
18
|
+
return `std::vector<${itemCode}>`;
|
|
19
|
+
case 'swift':
|
|
20
|
+
return `[${itemCode}]`;
|
|
21
|
+
case 'kotlin':
|
|
22
|
+
switch (this.itemType.kind) {
|
|
23
|
+
case 'number':
|
|
24
|
+
return 'DoubleArray';
|
|
25
|
+
case 'boolean':
|
|
26
|
+
return 'BooleanArray';
|
|
27
|
+
case 'bigint':
|
|
28
|
+
return 'LongArray';
|
|
29
|
+
default:
|
|
30
|
+
return `Array<${itemCode}>`;
|
|
31
|
+
}
|
|
32
|
+
default:
|
|
33
|
+
throw new Error(`Language ${language} is not yet supported for ArrayType!`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
getExtraFiles() {
|
|
37
|
+
return this.itemType.getExtraFiles();
|
|
38
|
+
}
|
|
39
|
+
getRequiredImports(language) {
|
|
40
|
+
const imports = [
|
|
41
|
+
...this.itemType.getRequiredImports(language),
|
|
42
|
+
];
|
|
43
|
+
if (language === 'c++') {
|
|
44
|
+
imports.push({
|
|
45
|
+
name: 'vector',
|
|
46
|
+
language: 'c++',
|
|
47
|
+
space: 'system',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return imports;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class BigIntType implements Type {
|
|
5
|
+
get canBePassedByReference(): boolean;
|
|
6
|
+
get kind(): TypeKind;
|
|
7
|
+
getCode(language: Language): string;
|
|
8
|
+
getExtraFiles(): SourceFile[];
|
|
9
|
+
getRequiredImports(): SourceImport[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export class BigIntType {
|
|
2
|
+
get canBePassedByReference() {
|
|
3
|
+
// It's a primitive.
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
get kind() {
|
|
7
|
+
return 'bigint';
|
|
8
|
+
}
|
|
9
|
+
getCode(language) {
|
|
10
|
+
switch (language) {
|
|
11
|
+
case 'c++':
|
|
12
|
+
return 'int64_t';
|
|
13
|
+
case 'swift':
|
|
14
|
+
return 'Int64';
|
|
15
|
+
case 'kotlin':
|
|
16
|
+
return 'Long';
|
|
17
|
+
default:
|
|
18
|
+
throw new Error(`Language ${language} is not yet supported for BigIntType!`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
getExtraFiles() {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
getRequiredImports() {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class BooleanType implements Type {
|
|
5
|
+
get canBePassedByReference(): boolean;
|
|
6
|
+
get kind(): TypeKind;
|
|
7
|
+
getCode(language: Language): string;
|
|
8
|
+
getExtraFiles(): SourceFile[];
|
|
9
|
+
getRequiredImports(): SourceImport[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export class BooleanType {
|
|
2
|
+
get canBePassedByReference() {
|
|
3
|
+
// It's a primitive.
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
get kind() {
|
|
7
|
+
return 'boolean';
|
|
8
|
+
}
|
|
9
|
+
getCode(language) {
|
|
10
|
+
switch (language) {
|
|
11
|
+
case 'c++':
|
|
12
|
+
return 'bool';
|
|
13
|
+
case 'swift':
|
|
14
|
+
return 'Bool';
|
|
15
|
+
case 'kotlin':
|
|
16
|
+
return 'Boolean';
|
|
17
|
+
default:
|
|
18
|
+
throw new Error(`Language ${language} is not yet supported for BooleanType!`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
getExtraFiles() {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
getRequiredImports() {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CustomTypeConfig } from 'react-native-nitro-modules';
|
|
2
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
3
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
4
|
+
import type { Type, TypeKind } from './Type.js';
|
|
5
|
+
export declare class CustomType implements Type {
|
|
6
|
+
typeConfig: CustomTypeConfig;
|
|
7
|
+
typeName: string;
|
|
8
|
+
constructor(typeName: string, typeConfig: CustomTypeConfig);
|
|
9
|
+
get canBePassedByReference(): boolean;
|
|
10
|
+
get kind(): TypeKind;
|
|
11
|
+
getCode(language: Language): string;
|
|
12
|
+
getExtraFiles(): SourceFile[];
|
|
13
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export class CustomType {
|
|
2
|
+
typeConfig;
|
|
3
|
+
typeName;
|
|
4
|
+
constructor(typeName, typeConfig) {
|
|
5
|
+
this.typeName = typeName;
|
|
6
|
+
this.typeConfig = typeConfig;
|
|
7
|
+
}
|
|
8
|
+
get canBePassedByReference() {
|
|
9
|
+
return this.typeConfig.canBePassedByReference ?? false;
|
|
10
|
+
}
|
|
11
|
+
get kind() {
|
|
12
|
+
return 'custom-type';
|
|
13
|
+
}
|
|
14
|
+
getCode(language) {
|
|
15
|
+
switch (language) {
|
|
16
|
+
case 'c++':
|
|
17
|
+
return this.typeName;
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`Language ${language} is not yet supported for CustomType "${this.typeName}"!`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
getExtraFiles() {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
getRequiredImports(language) {
|
|
26
|
+
const imports = [];
|
|
27
|
+
if (language === 'c++') {
|
|
28
|
+
imports.push({
|
|
29
|
+
name: this.typeConfig.include,
|
|
30
|
+
language: 'c++',
|
|
31
|
+
space: 'user',
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return imports;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class DateType implements Type {
|
|
5
|
+
get canBePassedByReference(): boolean;
|
|
6
|
+
get kind(): TypeKind;
|
|
7
|
+
getCode(language: Language): string;
|
|
8
|
+
getExtraFiles(): SourceFile[];
|
|
9
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export class DateType {
|
|
2
|
+
get canBePassedByReference() {
|
|
3
|
+
// simple chrono value type
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
get kind() {
|
|
7
|
+
return 'date';
|
|
8
|
+
}
|
|
9
|
+
getCode(language) {
|
|
10
|
+
switch (language) {
|
|
11
|
+
case 'c++':
|
|
12
|
+
return 'std::chrono::system_clock::time_point';
|
|
13
|
+
case 'swift':
|
|
14
|
+
return 'Date';
|
|
15
|
+
case 'kotlin':
|
|
16
|
+
return 'java.time.Instant';
|
|
17
|
+
default:
|
|
18
|
+
throw new Error(`Language ${language} is not yet supported for DateType!`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
getExtraFiles() {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
getRequiredImports(language) {
|
|
25
|
+
const imports = [];
|
|
26
|
+
if (language === 'c++') {
|
|
27
|
+
imports.push({
|
|
28
|
+
name: 'chrono',
|
|
29
|
+
language: 'c++',
|
|
30
|
+
space: 'system',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return imports;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EnumDeclaration } from 'ts-morph';
|
|
2
|
+
import { Type as TSMorphType, type ts } from 'ts-morph';
|
|
3
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
4
|
+
import { type SourceFile, type SourceImport } from '../SourceFile.js';
|
|
5
|
+
import type { GetCodeOptions, Type, TypeKind } from './Type.js';
|
|
6
|
+
export interface EnumMember {
|
|
7
|
+
name: string;
|
|
8
|
+
value: number;
|
|
9
|
+
stringValue: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class EnumType implements Type {
|
|
12
|
+
readonly enumName: string;
|
|
13
|
+
readonly enumMembers: EnumMember[];
|
|
14
|
+
readonly jsType: 'enum' | 'union';
|
|
15
|
+
readonly declarationFile: SourceFile;
|
|
16
|
+
constructor(enumName: string, enumDeclaration: EnumDeclaration);
|
|
17
|
+
constructor(enumName: string, union: TSMorphType<ts.UnionType>);
|
|
18
|
+
get canBePassedByReference(): boolean;
|
|
19
|
+
get kind(): TypeKind;
|
|
20
|
+
getCode(language: Language, { fullyQualified }?: GetCodeOptions): string;
|
|
21
|
+
getExtraFiles(): SourceFile[];
|
|
22
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
23
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { EnumDeclaration } from 'ts-morph';
|
|
2
|
+
import { Type as TSMorphType } from 'ts-morph';
|
|
3
|
+
import { getForwardDeclaration } from '../c++/getForwardDeclaration.js';
|
|
4
|
+
import {} from '../SourceFile.js';
|
|
5
|
+
import { createCppEnum } from '../c++/CppEnum.js';
|
|
6
|
+
import { escapeCppName } from '../helpers.js';
|
|
7
|
+
import { createCppUnion } from '../c++/CppUnion.js';
|
|
8
|
+
import { NitroConfig } from '../../config/NitroConfig.js';
|
|
9
|
+
export class EnumType {
|
|
10
|
+
enumName;
|
|
11
|
+
enumMembers;
|
|
12
|
+
jsType;
|
|
13
|
+
declarationFile;
|
|
14
|
+
constructor(enumName, declaration) {
|
|
15
|
+
this.enumName = enumName;
|
|
16
|
+
if (declaration instanceof EnumDeclaration) {
|
|
17
|
+
// It's a JS enum { ... }
|
|
18
|
+
this.jsType = 'enum';
|
|
19
|
+
this.enumMembers = declaration.getMembers().map((m) => {
|
|
20
|
+
const name = m.getSymbolOrThrow().getEscapedName();
|
|
21
|
+
const value = m.getValue();
|
|
22
|
+
if (typeof value !== 'number') {
|
|
23
|
+
throw new Error(`Enum member ${enumName}.${name} is ${value} (${typeof value}), which cannot be represented in C++ enums.\n` +
|
|
24
|
+
`Each enum member must be a number! If you want to use strings, use TypeScript unions ("a" | "b") instead!`);
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
name: escapeCppName(name).toUpperCase(),
|
|
28
|
+
value: value,
|
|
29
|
+
stringValue: name,
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
this.declarationFile = createCppEnum(enumName, this.enumMembers);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// It's a TS union '..' | '..'
|
|
36
|
+
this.jsType = 'union';
|
|
37
|
+
this.enumMembers = declaration
|
|
38
|
+
.getNonNullableType()
|
|
39
|
+
.getUnionTypes()
|
|
40
|
+
.map((t, i) => {
|
|
41
|
+
if (t.isStringLiteral()) {
|
|
42
|
+
const literalValue = t.getLiteralValueOrThrow();
|
|
43
|
+
if (typeof literalValue !== 'string')
|
|
44
|
+
throw new Error(`${enumName}: Value "${literalValue}" is not a string - it is ${typeof literalValue}!`);
|
|
45
|
+
return {
|
|
46
|
+
name: escapeCppName(literalValue).toUpperCase(),
|
|
47
|
+
value: i,
|
|
48
|
+
stringValue: literalValue,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new Error(`${enumName}: Value "${t.getText()}" is not a string literal - it cannot be represented in a C++ enum!`);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
this.declarationFile = createCppUnion(enumName, this.enumMembers);
|
|
56
|
+
}
|
|
57
|
+
if (this.enumName.startsWith('__')) {
|
|
58
|
+
throw new Error(`Enum name cannot start with two underscores (__) as this is reserved syntax for Nitrogen! (In ${this.enumName}: ${this.enumMembers.map((m) => m.name).join(' | ')})`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
get canBePassedByReference() {
|
|
62
|
+
// It's a primitive.
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
get kind() {
|
|
66
|
+
return 'enum';
|
|
67
|
+
}
|
|
68
|
+
getCode(language, { fullyQualified } = {}) {
|
|
69
|
+
switch (language) {
|
|
70
|
+
case 'c++':
|
|
71
|
+
if (fullyQualified) {
|
|
72
|
+
return NitroConfig.current.getCxxNamespace('c++', this.enumName);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return this.enumName;
|
|
76
|
+
}
|
|
77
|
+
case 'swift':
|
|
78
|
+
return this.enumName;
|
|
79
|
+
case 'kotlin':
|
|
80
|
+
return this.enumName;
|
|
81
|
+
default:
|
|
82
|
+
throw new Error(`Language ${language} is not yet supported for NumberType!`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
getExtraFiles() {
|
|
86
|
+
return [this.declarationFile];
|
|
87
|
+
}
|
|
88
|
+
getRequiredImports(language) {
|
|
89
|
+
const imports = [];
|
|
90
|
+
if (language === 'c++') {
|
|
91
|
+
const cxxNamespace = NitroConfig.current.getCxxNamespace('c++');
|
|
92
|
+
imports.push({
|
|
93
|
+
name: this.declarationFile.name,
|
|
94
|
+
language: this.declarationFile.language,
|
|
95
|
+
forwardDeclaration: getForwardDeclaration('enum class', this.enumName, cxxNamespace),
|
|
96
|
+
space: 'user',
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return imports;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import { type SourceFile, type SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class ErrorType implements Type {
|
|
5
|
+
constructor();
|
|
6
|
+
get canBePassedByReference(): boolean;
|
|
7
|
+
get kind(): TypeKind;
|
|
8
|
+
getCode(language: Language): string;
|
|
9
|
+
getExtraFiles(): SourceFile[];
|
|
10
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {} from '../SourceFile.js';
|
|
2
|
+
export class ErrorType {
|
|
3
|
+
constructor() { }
|
|
4
|
+
get canBePassedByReference() {
|
|
5
|
+
// It's a exception<..>, pass by reference.
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
get kind() {
|
|
9
|
+
return 'error';
|
|
10
|
+
}
|
|
11
|
+
getCode(language) {
|
|
12
|
+
switch (language) {
|
|
13
|
+
case 'c++':
|
|
14
|
+
return `std::exception_ptr`;
|
|
15
|
+
case 'swift':
|
|
16
|
+
return `Error`;
|
|
17
|
+
case 'kotlin':
|
|
18
|
+
return `Throwable`;
|
|
19
|
+
default:
|
|
20
|
+
throw new Error(`Language ${language} is not yet supported for ThrowableType!`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
getExtraFiles() {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
getRequiredImports(language) {
|
|
27
|
+
const imports = [];
|
|
28
|
+
if (language === 'c++') {
|
|
29
|
+
imports.push({
|
|
30
|
+
language: 'c++',
|
|
31
|
+
name: 'exception',
|
|
32
|
+
space: 'system',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return imports;
|
|
36
|
+
}
|
|
37
|
+
}
|