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,29 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import { type SourceFile, type SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { GetCodeOptions, NamedType, Type, TypeKind } from './Type.js';
|
|
4
|
+
export interface GetFunctionCodeOptions extends GetCodeOptions {
|
|
5
|
+
includeNameInfo?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare class FunctionType implements Type {
|
|
8
|
+
readonly returnType: Type;
|
|
9
|
+
readonly parameters: NamedType[];
|
|
10
|
+
constructor(returnType: Type, parameters: NamedType[], isSync?: boolean);
|
|
11
|
+
get specializationName(): string;
|
|
12
|
+
get jsName(): string;
|
|
13
|
+
get canBePassedByReference(): boolean;
|
|
14
|
+
get kind(): TypeKind;
|
|
15
|
+
/**
|
|
16
|
+
* For a function, get the forward recreation of it:
|
|
17
|
+
* If variable is called `func`, this would return:
|
|
18
|
+
* ```cpp
|
|
19
|
+
* [func = std::move(func)](Params... params) -> ReturnType {
|
|
20
|
+
* return func(params...);
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
getForwardRecreationCode(variableName: string, language: Language): string;
|
|
25
|
+
getCppFunctionPointerType(name: string, includeNameInfo?: boolean): string;
|
|
26
|
+
getCode(language: Language, options?: GetFunctionCodeOptions): string;
|
|
27
|
+
getExtraFiles(): SourceFile[];
|
|
28
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
29
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { escapeCppName, toReferenceType } from '../helpers.js';
|
|
2
|
+
import { Parameter } from '../Parameter.js';
|
|
3
|
+
import {} from '../SourceFile.js';
|
|
4
|
+
import { PromiseType } from './PromiseType.js';
|
|
5
|
+
export class FunctionType {
|
|
6
|
+
returnType;
|
|
7
|
+
parameters;
|
|
8
|
+
constructor(returnType, parameters, isSync = false) {
|
|
9
|
+
if (returnType.kind === 'void' || isSync) {
|
|
10
|
+
// void callbacks are async, but we don't care about the result.
|
|
11
|
+
this.returnType = returnType;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
// non-void callbacks are async and need to be awaited to get the result from JS.
|
|
15
|
+
this.returnType = new PromiseType(returnType);
|
|
16
|
+
}
|
|
17
|
+
this.parameters = parameters;
|
|
18
|
+
if (isSync && returnType.kind === 'void') {
|
|
19
|
+
throw new Error(`Function \`${this.jsName}\` cannot be sync (\`Sync<...>\`) AND return \`void\`, as this is ambiguous. ` +
|
|
20
|
+
`Either return a value (even if it's just a \`boolean\`) to keep it sync, or make it async.`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
get specializationName() {
|
|
24
|
+
return ('Func_' +
|
|
25
|
+
[this.returnType, ...this.parameters]
|
|
26
|
+
.map((p) => escapeCppName(p.getCode('c++')))
|
|
27
|
+
.join('_'));
|
|
28
|
+
}
|
|
29
|
+
get jsName() {
|
|
30
|
+
const paramsJs = this.parameters
|
|
31
|
+
.map((p) => `${p.name}: ${p.kind}`)
|
|
32
|
+
.join(', ');
|
|
33
|
+
const returnType = this.returnType.getCode('c++');
|
|
34
|
+
return `(${paramsJs}) => ${returnType}`;
|
|
35
|
+
}
|
|
36
|
+
get canBePassedByReference() {
|
|
37
|
+
// It's a function<..>, heavy to copy.
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
get kind() {
|
|
41
|
+
return 'function';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* For a function, get the forward recreation of it:
|
|
45
|
+
* If variable is called `func`, this would return:
|
|
46
|
+
* ```cpp
|
|
47
|
+
* [func = std::move(func)](Params... params) -> ReturnType {
|
|
48
|
+
* return func(params...);
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
getForwardRecreationCode(variableName, language) {
|
|
53
|
+
const returnType = this.returnType.getCode(language);
|
|
54
|
+
const parameters = this.parameters
|
|
55
|
+
.map((p) => new Parameter(p.name, p))
|
|
56
|
+
.map((p) => p.getCode('c++'));
|
|
57
|
+
const forwardedParameters = this.parameters.map((p) => `std::forward<decltype(${p.name})>(${p.name})`);
|
|
58
|
+
switch (language) {
|
|
59
|
+
case 'c++':
|
|
60
|
+
const closure = `[${variableName} = std::move(${variableName})]`;
|
|
61
|
+
const signature = `(${parameters.join(', ')}) -> ${returnType}`;
|
|
62
|
+
const body = `{ return ${variableName}(${forwardedParameters.join(', ')}); }`;
|
|
63
|
+
return `${closure} ${signature} ${body}`;
|
|
64
|
+
default:
|
|
65
|
+
throw new Error(`Language ${language} is not yet supported for function forward recreations!`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
getCppFunctionPointerType(name, includeNameInfo = true) {
|
|
69
|
+
const params = this.parameters
|
|
70
|
+
.map((p) => {
|
|
71
|
+
const type = p.getCode('c++');
|
|
72
|
+
const code = p.canBePassedByReference ? toReferenceType(type) : type;
|
|
73
|
+
if (includeNameInfo)
|
|
74
|
+
return `${code} /* ${p.name} */`;
|
|
75
|
+
else
|
|
76
|
+
return code;
|
|
77
|
+
})
|
|
78
|
+
.join(', ');
|
|
79
|
+
const returnType = this.returnType.getCode('c++');
|
|
80
|
+
return `${returnType}(*${name})(${params})`;
|
|
81
|
+
}
|
|
82
|
+
getCode(language, options = {}) {
|
|
83
|
+
const includeNameInfo = options.includeNameInfo ?? true;
|
|
84
|
+
switch (language) {
|
|
85
|
+
case 'c++': {
|
|
86
|
+
const params = this.parameters
|
|
87
|
+
.map((p) => {
|
|
88
|
+
const type = p.getCode('c++', options);
|
|
89
|
+
const code = p.canBePassedByReference ? toReferenceType(type) : type;
|
|
90
|
+
if (includeNameInfo)
|
|
91
|
+
return `${code} /* ${p.name} */`;
|
|
92
|
+
else
|
|
93
|
+
return code;
|
|
94
|
+
})
|
|
95
|
+
.join(', ');
|
|
96
|
+
const returnType = this.returnType.getCode(language, options);
|
|
97
|
+
return `std::function<${returnType}(${params})>`;
|
|
98
|
+
}
|
|
99
|
+
case 'swift': {
|
|
100
|
+
const params = this.parameters
|
|
101
|
+
.map((p) => {
|
|
102
|
+
if (includeNameInfo)
|
|
103
|
+
return `_ ${p.escapedName}: ${p.getCode(language, options)}`;
|
|
104
|
+
else
|
|
105
|
+
return p.getCode(language, options);
|
|
106
|
+
})
|
|
107
|
+
.join(', ');
|
|
108
|
+
const returnType = this.returnType.getCode(language, options);
|
|
109
|
+
return `(${params}) -> ${returnType}`;
|
|
110
|
+
}
|
|
111
|
+
case 'kotlin': {
|
|
112
|
+
const params = this.parameters
|
|
113
|
+
.map((p) => {
|
|
114
|
+
if (includeNameInfo)
|
|
115
|
+
return `${p.escapedName}: ${p.getCode(language, options)}`;
|
|
116
|
+
else
|
|
117
|
+
return p.getCode(language, options);
|
|
118
|
+
})
|
|
119
|
+
.join(', ');
|
|
120
|
+
const returnType = this.returnType.getCode(language, options);
|
|
121
|
+
return `(${params}) -> ${returnType}`;
|
|
122
|
+
}
|
|
123
|
+
default:
|
|
124
|
+
throw new Error(`Language ${language} is not yet supported for FunctionType!`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
getExtraFiles() {
|
|
128
|
+
return [
|
|
129
|
+
...this.returnType.getExtraFiles(),
|
|
130
|
+
...this.parameters.flatMap((p) => p.getExtraFiles()),
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
getRequiredImports(language) {
|
|
134
|
+
const imports = [
|
|
135
|
+
...this.returnType.getRequiredImports(language),
|
|
136
|
+
...this.parameters.flatMap((p) => p.getRequiredImports(language)),
|
|
137
|
+
];
|
|
138
|
+
if (language === 'c++') {
|
|
139
|
+
imports.push({
|
|
140
|
+
language: 'c++',
|
|
141
|
+
name: 'functional',
|
|
142
|
+
space: 'system',
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return imports;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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 HybridObjectBaseType 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,38 @@
|
|
|
1
|
+
import { getForwardDeclaration } from '../c++/getForwardDeclaration.js';
|
|
2
|
+
export class HybridObjectBaseType {
|
|
3
|
+
constructor() { }
|
|
4
|
+
get canBePassedByReference() {
|
|
5
|
+
// It's a shared_ptr<..>, no copy.
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
get kind() {
|
|
9
|
+
return 'hybrid-object-base';
|
|
10
|
+
}
|
|
11
|
+
getCode(language) {
|
|
12
|
+
switch (language) {
|
|
13
|
+
case 'c++':
|
|
14
|
+
return `std::shared_ptr<HybridObject>`;
|
|
15
|
+
default:
|
|
16
|
+
throw new Error(`The base type \`HybridObject\` cannot be used directly in ${language} yet. Use a specific derived class of \`HybridObject\` instead!`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
getExtraFiles() {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
getRequiredImports(language) {
|
|
23
|
+
const imports = [];
|
|
24
|
+
if (language === 'c++') {
|
|
25
|
+
imports.push({
|
|
26
|
+
language: 'c++',
|
|
27
|
+
name: 'memory',
|
|
28
|
+
space: 'system',
|
|
29
|
+
}, {
|
|
30
|
+
name: `NitroModules/HybridObject.hpp`,
|
|
31
|
+
forwardDeclaration: getForwardDeclaration('class', 'HybridObject', 'margelo::nitro'),
|
|
32
|
+
language: 'c++',
|
|
33
|
+
space: 'system',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return imports;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type NitroConfig } from '../../config/NitroConfig.js';
|
|
2
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
3
|
+
import type { HybridObjectSpec } from '../HybridObjectSpec.js';
|
|
4
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
5
|
+
import type { GetCodeOptions, Type, TypeKind } from './Type.js';
|
|
6
|
+
interface GetHybridObjectCodeOptions extends GetCodeOptions {
|
|
7
|
+
mode?: 'strong' | 'weak';
|
|
8
|
+
}
|
|
9
|
+
export declare class HybridObjectType implements Type {
|
|
10
|
+
readonly hybridObjectName: string;
|
|
11
|
+
readonly implementationLanguage: Language;
|
|
12
|
+
readonly baseTypes: HybridObjectType[];
|
|
13
|
+
readonly sourceConfig: NitroConfig;
|
|
14
|
+
constructor(hybridObjectName: string, implementationLanguage: Language, baseTypes: HybridObjectType[], sourceConfig: NitroConfig);
|
|
15
|
+
constructor(spec: HybridObjectSpec);
|
|
16
|
+
get canBePassedByReference(): boolean;
|
|
17
|
+
get kind(): TypeKind;
|
|
18
|
+
getCode(language: Language, options?: GetHybridObjectCodeOptions): string;
|
|
19
|
+
getExtraFiles(): SourceFile[];
|
|
20
|
+
private getExternalCxxImportName;
|
|
21
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import {} from '../../config/NitroConfig.js';
|
|
2
|
+
import { getForwardDeclaration } from '../c++/getForwardDeclaration.js';
|
|
3
|
+
import { getHybridObjectName } from '../getHybridObjectName.js';
|
|
4
|
+
export class HybridObjectType {
|
|
5
|
+
hybridObjectName;
|
|
6
|
+
implementationLanguage;
|
|
7
|
+
baseTypes;
|
|
8
|
+
sourceConfig;
|
|
9
|
+
constructor(...args) {
|
|
10
|
+
if (args.length === 1) {
|
|
11
|
+
const [spec] = args;
|
|
12
|
+
this.hybridObjectName = spec.name;
|
|
13
|
+
this.implementationLanguage = spec.language;
|
|
14
|
+
this.sourceConfig = spec.config;
|
|
15
|
+
this.baseTypes = spec.baseTypes.map((b) => new HybridObjectType(b));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const [hybridObjectName, implementationLanguage, baseTypes, sourceConfig,] = args;
|
|
19
|
+
this.hybridObjectName = hybridObjectName;
|
|
20
|
+
this.implementationLanguage = implementationLanguage;
|
|
21
|
+
this.baseTypes = baseTypes;
|
|
22
|
+
this.sourceConfig = sourceConfig;
|
|
23
|
+
}
|
|
24
|
+
if (this.hybridObjectName.startsWith('__')) {
|
|
25
|
+
throw new Error(`HybridObject name cannot start with two underscores (__)! (In ${this.hybridObjectName})`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
get canBePassedByReference() {
|
|
29
|
+
// It's a shared_ptr<..>, no copy.
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
get kind() {
|
|
33
|
+
return 'hybrid-object';
|
|
34
|
+
}
|
|
35
|
+
getCode(language, options = {}) {
|
|
36
|
+
const name = getHybridObjectName(this.hybridObjectName);
|
|
37
|
+
const mode = options.mode ?? 'strong';
|
|
38
|
+
const fullyQualified = options.fullyQualified ?? this.sourceConfig.isExternalConfig;
|
|
39
|
+
switch (language) {
|
|
40
|
+
case 'c++': {
|
|
41
|
+
const ptrType = mode === 'strong' ? 'std::shared_ptr' : 'std::weak_ptr';
|
|
42
|
+
if (fullyQualified) {
|
|
43
|
+
const fullName = this.sourceConfig.getCxxNamespace('c++', name.HybridTSpec);
|
|
44
|
+
return `${ptrType}<${fullName}>`;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return `${ptrType}<${name.HybridTSpec}>`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
case 'swift': {
|
|
51
|
+
return `(any ${name.HybridTSpec})`;
|
|
52
|
+
}
|
|
53
|
+
case 'kotlin': {
|
|
54
|
+
if (fullyQualified) {
|
|
55
|
+
// full qualified name: "com.margelo.nitro.image.Image"
|
|
56
|
+
return this.sourceConfig.getAndroidPackage('java/kotlin', name.HybridTSpec);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// "Image"
|
|
60
|
+
return name.HybridTSpec;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
default:
|
|
64
|
+
throw new Error(`Language ${language} is not yet supported for HybridObjectType!`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
getExtraFiles() {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
getExternalCxxImportName() {
|
|
71
|
+
// TODO: We currently don't have a xplat way of handling import paths, therefore iosModuleName and androidCxxLibName need to have the same value.
|
|
72
|
+
if (this.sourceConfig.getIosModuleName() !==
|
|
73
|
+
this.sourceConfig.getAndroidCxxLibName()) {
|
|
74
|
+
throw new Error(`Cannot import external HybridObject "${this.hybridObjectName}" if it's nitro.json's iosModuleName and androidCxxLibName are not the same value!`);
|
|
75
|
+
}
|
|
76
|
+
return this.sourceConfig.getIosModuleName();
|
|
77
|
+
}
|
|
78
|
+
getRequiredImports(language) {
|
|
79
|
+
const name = getHybridObjectName(this.hybridObjectName);
|
|
80
|
+
const cxxNamespace = this.sourceConfig.getCxxNamespace('c++');
|
|
81
|
+
const imports = [];
|
|
82
|
+
switch (language) {
|
|
83
|
+
case 'c++': {
|
|
84
|
+
imports.push({
|
|
85
|
+
language: 'c++',
|
|
86
|
+
name: 'memory',
|
|
87
|
+
space: 'system',
|
|
88
|
+
});
|
|
89
|
+
if (this.sourceConfig.isExternalConfig) {
|
|
90
|
+
const cxxImport = this.getExternalCxxImportName();
|
|
91
|
+
imports.push({
|
|
92
|
+
name: `${cxxImport}/${name.HybridTSpec}.hpp`,
|
|
93
|
+
forwardDeclaration: getForwardDeclaration('class', name.HybridTSpec, cxxNamespace),
|
|
94
|
+
language: 'c++',
|
|
95
|
+
space: 'system',
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
imports.push({
|
|
100
|
+
name: `${name.HybridTSpec}.hpp`,
|
|
101
|
+
forwardDeclaration: getForwardDeclaration('class', name.HybridTSpec, cxxNamespace),
|
|
102
|
+
language: 'c++',
|
|
103
|
+
space: 'user',
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
case 'kotlin': {
|
|
109
|
+
if (this.sourceConfig.isExternalConfig) {
|
|
110
|
+
imports.push({
|
|
111
|
+
language: 'kotlin',
|
|
112
|
+
name: this.sourceConfig.getAndroidPackage('java/kotlin', name.HybridTSpec),
|
|
113
|
+
space: 'system',
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case 'swift': {
|
|
119
|
+
if (this.sourceConfig.isExternalConfig) {
|
|
120
|
+
imports.push({
|
|
121
|
+
language: 'swift',
|
|
122
|
+
name: this.sourceConfig.getIosModuleName(),
|
|
123
|
+
space: 'system',
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return imports;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -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 MapType 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 MapType {
|
|
3
|
+
get canBePassedByReference() {
|
|
4
|
+
// It's a shared_ptr<..>, no ref.
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
get kind() {
|
|
8
|
+
return 'map';
|
|
9
|
+
}
|
|
10
|
+
getCode(language) {
|
|
11
|
+
switch (language) {
|
|
12
|
+
case 'c++':
|
|
13
|
+
return 'std::shared_ptr<AnyMap>';
|
|
14
|
+
case 'swift':
|
|
15
|
+
return 'AnyMap';
|
|
16
|
+
case 'kotlin':
|
|
17
|
+
return 'AnyMap';
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`Language ${language} is not yet supported for MapType!`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
getExtraFiles() {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
getRequiredImports(language) {
|
|
26
|
+
const imports = [];
|
|
27
|
+
if (language === 'c++') {
|
|
28
|
+
imports.push({
|
|
29
|
+
name: 'NitroModules/AnyMap.hpp',
|
|
30
|
+
forwardDeclaration: getForwardDeclaration('class', 'AnyMap', 'NitroModules'),
|
|
31
|
+
language: 'c++',
|
|
32
|
+
space: 'system',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return imports;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { GetCodeOptions, NamedType, Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class NamedWrappingType<T extends Type> implements NamedType {
|
|
5
|
+
readonly type: T;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
constructor(name: string, type: T);
|
|
8
|
+
get escapedName(): string;
|
|
9
|
+
get kind(): TypeKind;
|
|
10
|
+
get canBePassedByReference(): boolean;
|
|
11
|
+
getCode(language: Language, options?: GetCodeOptions): string;
|
|
12
|
+
getExtraFiles(): SourceFile[];
|
|
13
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { escapeCppName } from '../helpers.js';
|
|
2
|
+
export class NamedWrappingType {
|
|
3
|
+
type;
|
|
4
|
+
name;
|
|
5
|
+
constructor(name, type) {
|
|
6
|
+
this.name = name;
|
|
7
|
+
this.type = type;
|
|
8
|
+
}
|
|
9
|
+
get escapedName() {
|
|
10
|
+
return escapeCppName(this.name);
|
|
11
|
+
}
|
|
12
|
+
get kind() {
|
|
13
|
+
return this.type.kind;
|
|
14
|
+
}
|
|
15
|
+
get canBePassedByReference() {
|
|
16
|
+
return this.type.canBePassedByReference;
|
|
17
|
+
}
|
|
18
|
+
getCode(language, options) {
|
|
19
|
+
return this.type.getCode(language, options);
|
|
20
|
+
}
|
|
21
|
+
getExtraFiles() {
|
|
22
|
+
return this.type.getExtraFiles();
|
|
23
|
+
}
|
|
24
|
+
getRequiredImports(language) {
|
|
25
|
+
return this.type.getRequiredImports(language);
|
|
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 NullType 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,23 @@
|
|
|
1
|
+
export class NullType {
|
|
2
|
+
get canBePassedByReference() {
|
|
3
|
+
// It's a primitive.
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
get kind() {
|
|
7
|
+
return 'null';
|
|
8
|
+
}
|
|
9
|
+
getCode(language) {
|
|
10
|
+
switch (language) {
|
|
11
|
+
case 'c++':
|
|
12
|
+
return 'std::nullptr_t';
|
|
13
|
+
default:
|
|
14
|
+
throw new Error(`Language ${language} is not yet supported for NullType!`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
getExtraFiles() {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
getRequiredImports() {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -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 NumberType 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 NumberType {
|
|
2
|
+
get canBePassedByReference() {
|
|
3
|
+
// It's a primitive
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
get kind() {
|
|
7
|
+
return 'number';
|
|
8
|
+
}
|
|
9
|
+
getCode(language) {
|
|
10
|
+
switch (language) {
|
|
11
|
+
case 'c++':
|
|
12
|
+
return 'double';
|
|
13
|
+
case 'swift':
|
|
14
|
+
return 'Double';
|
|
15
|
+
case 'kotlin':
|
|
16
|
+
return 'Double';
|
|
17
|
+
default:
|
|
18
|
+
throw new Error(`Language ${language} is not yet supported for NumberType!`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
getExtraFiles() {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
getRequiredImports() {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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 OptionalType implements Type {
|
|
5
|
+
readonly wrappingType: Type;
|
|
6
|
+
constructor(wrappingType: Type);
|
|
7
|
+
get canBePassedByReference(): boolean;
|
|
8
|
+
get kind(): TypeKind;
|
|
9
|
+
get needsBraces(): boolean;
|
|
10
|
+
getCode(language: Language, options?: GetCodeOptions): string;
|
|
11
|
+
getExtraFiles(): SourceFile[];
|
|
12
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {} from '../SourceFile.js';
|
|
2
|
+
export class OptionalType {
|
|
3
|
+
wrappingType;
|
|
4
|
+
constructor(wrappingType) {
|
|
5
|
+
this.wrappingType = wrappingType;
|
|
6
|
+
}
|
|
7
|
+
get canBePassedByReference() {
|
|
8
|
+
// depends whether the wrapping type is heavy to copy or not.
|
|
9
|
+
return this.wrappingType.canBePassedByReference;
|
|
10
|
+
}
|
|
11
|
+
get kind() {
|
|
12
|
+
return 'optional';
|
|
13
|
+
}
|
|
14
|
+
get needsBraces() {
|
|
15
|
+
switch (this.wrappingType.kind) {
|
|
16
|
+
case 'function':
|
|
17
|
+
return true;
|
|
18
|
+
default:
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
getCode(language, options) {
|
|
23
|
+
const wrapping = this.wrappingType.getCode(language, options);
|
|
24
|
+
switch (language) {
|
|
25
|
+
case 'c++':
|
|
26
|
+
return `std::optional<${wrapping}>`;
|
|
27
|
+
case 'swift':
|
|
28
|
+
if (this.needsBraces) {
|
|
29
|
+
return `(${wrapping})?`;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return `${wrapping}?`;
|
|
33
|
+
}
|
|
34
|
+
case 'kotlin':
|
|
35
|
+
if (this.needsBraces) {
|
|
36
|
+
return `(${wrapping})?`;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return `${wrapping}?`;
|
|
40
|
+
}
|
|
41
|
+
default:
|
|
42
|
+
throw new Error(`Language ${language} is not yet supported for OptionalType!`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
getExtraFiles() {
|
|
46
|
+
return this.wrappingType.getExtraFiles();
|
|
47
|
+
}
|
|
48
|
+
getRequiredImports(language) {
|
|
49
|
+
const imports = this.wrappingType.getRequiredImports(language);
|
|
50
|
+
if (language === 'c++') {
|
|
51
|
+
imports.push({
|
|
52
|
+
language: 'c++',
|
|
53
|
+
name: 'optional',
|
|
54
|
+
space: 'system',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return imports;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import { type SourceFile, type SourceImport } from '../SourceFile.js';
|
|
3
|
+
import { FunctionType } from './FunctionType.js';
|
|
4
|
+
import type { GetCodeOptions, Type, TypeKind } from './Type.js';
|
|
5
|
+
export declare class PromiseType implements Type {
|
|
6
|
+
readonly resultingType: Type;
|
|
7
|
+
readonly errorType: Type;
|
|
8
|
+
constructor(resultingType: Type);
|
|
9
|
+
get canBePassedByReference(): boolean;
|
|
10
|
+
get kind(): TypeKind;
|
|
11
|
+
get resolverFunction(): FunctionType;
|
|
12
|
+
get rejecterFunction(): FunctionType;
|
|
13
|
+
getCode(language: Language, options?: GetCodeOptions): string;
|
|
14
|
+
getExtraFiles(): SourceFile[];
|
|
15
|
+
getRequiredImports(language: Language): SourceImport[];
|
|
16
|
+
}
|