@idlizer/arktscgen 2.1.5 → 2.1.9-arktscgen-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/build/libarkts-copy/generator/options.json5 +34 -0
- package/build/libarkts-copy/native/meson.build +128 -62
- package/build/libarkts-copy/native/meson_options.txt +19 -0
- package/build/libarkts-copy/native/src/bridges.cc +278 -15
- package/build/libarkts-copy/native/src/common.cc +212 -43
- package/build/libarkts-copy/native/src/common.h +95 -2
- package/build/libarkts-copy/native/src/generated/bridges.cc +2801 -466
- package/build/libarkts-copy/package.json +82 -62
- package/build/libarkts-copy/src/Es2pandaNativeModule.ts +97 -3
- package/build/libarkts-copy/src/InteropNativeModule.ts +3 -1
- package/build/libarkts-copy/src/arkts-api/AbstractVisitor.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/ChainExpressionFilter.ts +78 -0
- package/build/libarkts-copy/src/arkts-api/CheckedBackFilter.ts +131 -0
- package/build/libarkts-copy/src/arkts-api/CompileWithCache.ts +193 -0
- package/build/libarkts-copy/src/arkts-api/ImportStorage.ts +78 -0
- package/build/libarkts-copy/src/arkts-api/InferVoidReturnType.ts +89 -0
- package/build/libarkts-copy/src/arkts-api/ProgramProvider.ts +50 -0
- package/build/libarkts-copy/src/arkts-api/SetBaseOverloads.ts +44 -0
- package/build/libarkts-copy/src/arkts-api/class-by-peer.ts +2 -3
- package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +93 -10
- package/build/libarkts-copy/src/arkts-api/index.ts +13 -1
- package/build/libarkts-copy/src/arkts-api/node-cache.ts +8 -4
- package/build/libarkts-copy/src/arkts-api/node-utilities/AnnotationDeclaration.ts +32 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/AnnotationUsage.ts +37 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ArkTsConfig.ts +26 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ArrayExpression.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/BinaryExpression.ts +37 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/BlockExpression.ts +27 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/BlockStatement.ts +29 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/CallExpression.ts +2 -2
- package/build/libarkts-copy/src/arkts-api/node-utilities/ChainExpression.ts +27 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ClassDeclaration.ts +54 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ClassDefinition.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/ClassProperty.ts +27 -4
- package/build/libarkts-copy/src/arkts-api/node-utilities/ConditionalExpression.ts +36 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSFunctionType.ts +2 -2
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSImportDeclaration.ts +3 -27
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSNewClassInstanceExpression.ts +34 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSParameterExpression.ts +3 -9
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSPrimitiveType.ts +28 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSStructDeclaration.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSTuple.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSTypeReference.ts +27 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSTypeReferencePart.ts +36 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSUndefinedType.ts +24 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSUnionType.ts +27 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/Identifier.ts +27 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ImportSpecifier.ts +31 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/MemberExpression.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/MethodDefinition.ts +2 -2
- package/build/libarkts-copy/src/arkts-api/node-utilities/NullLiteral.ts +24 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/NumberLiteral.ts +2 -2
- package/build/libarkts-copy/src/arkts-api/node-utilities/ObjectExpression.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/Program.ts +40 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ReturnStatement.ts +27 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/StringLiteral.ts +27 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/SuperExpression.ts +24 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSAsExpression.ts +36 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSClassImplements.ts +31 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSInterfaceBody.ts +28 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSInterfaceDeclaration.ts +30 -10
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSNonNullExpression.ts +27 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSTypeAliasDeclaration.ts +10 -2
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSTypeParameter.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSTypeParameterDeclaration.ts +31 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSTypeParameterInstantiation.ts +30 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSTypeReferencePart.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/TemplateLiteral.ts +35 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ThisExpression.ts +24 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/UndefinedLiteral.ts +24 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/VariableDeclaration.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/VariableDeclarator.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/peers/ArktsObject.ts +3 -1
- package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +78 -15
- package/build/libarkts-copy/src/arkts-api/peers/Config.ts +8 -1
- package/build/libarkts-copy/src/arkts-api/peers/Context.ts +72 -6
- package/build/libarkts-copy/src/arkts-api/peers/{Program.ts → ExternalSource.ts} +3 -21
- package/build/libarkts-copy/src/arkts-api/peers/Options.ts +34 -0
- package/build/libarkts-copy/src/arkts-api/plugins.ts +62 -0
- package/build/libarkts-copy/src/arkts-api/static/global.ts +9 -5
- package/build/libarkts-copy/src/arkts-api/static/profiler.ts +195 -23
- package/build/libarkts-copy/src/arkts-api/utilities/private.ts +36 -10
- package/build/libarkts-copy/src/arkts-api/utilities/public.ts +68 -20
- package/build/libarkts-copy/src/arkts-api/visitor.ts +162 -18
- package/build/libarkts-copy/src/arkts-api/wrapper-compat.ts +32 -0
- package/build/libarkts-copy/src/checkSdk.ts +25 -0
- package/build/libarkts-copy/src/generated/Es2pandaEnums.ts +448 -436
- package/build/libarkts-copy/src/generated/Es2pandaNativeModule.ts +775 -60
- package/build/libarkts-copy/src/generated/factory.ts +12 -15
- package/build/libarkts-copy/src/generated/index.ts +10 -3
- package/build/libarkts-copy/src/generated/peers/AnnotatedAstNode.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/AnnotatedExpression.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/AnnotatedStatement.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/AnnotationDeclaration.ts +58 -6
- package/build/libarkts-copy/src/generated/peers/AnnotationUsage.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ArkTsConfig.ts +75 -0
- package/build/libarkts-copy/src/generated/peers/ArrayExpression.ts +11 -5
- package/build/libarkts-copy/src/generated/peers/ArrowFunctionExpression.ts +40 -6
- package/build/libarkts-copy/src/generated/peers/AssertStatement.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/AssignmentExpression.ts +11 -5
- package/build/libarkts-copy/src/generated/peers/AstDumper.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/AstVerifier.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/AstVisitor.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/AwaitExpression.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/BigIntLiteral.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/BinaryExpression.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/BindingProps.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/BlockExpression.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/BlockStatement.ts +26 -7
- package/build/libarkts-copy/src/generated/peers/BooleanLiteral.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/BreakStatement.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/CallExpression.ts +20 -3
- package/build/libarkts-copy/src/generated/peers/CatchClause.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ChainExpression.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/CharLiteral.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/ClassDeclaration.ts +33 -4
- package/build/libarkts-copy/src/generated/peers/ClassDefinition.ts +128 -42
- package/build/libarkts-copy/src/generated/peers/ClassElement.ts +28 -4
- package/build/libarkts-copy/src/generated/peers/ClassExpression.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/ClassProperty.ts +39 -5
- package/build/libarkts-copy/src/generated/peers/ClassStaticBlock.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/CodeGen.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/ConditionalExpression.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/ContinueStatement.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/DebuggerStatement.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/Declaration.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/Decorator.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/{OverloadInfo.ts → DiagnosticInfo.ts} +8 -2
- package/build/libarkts-copy/src/generated/peers/DirectEvalExpression.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/DoWhileStatement.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/DynamicImportData.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/ETSClassLiteral.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ETSFunctionType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ETSImportDeclaration.ts +16 -5
- package/build/libarkts-copy/src/generated/peers/ETSKeyofType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ETSModule.ts +59 -4
- package/build/libarkts-copy/src/generated/peers/ETSNewArrayInstanceExpression.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ETSNewClassInstanceExpression.ts +11 -5
- package/build/libarkts-copy/src/generated/peers/ETSNewMultiDimArrayInstanceExpression.ts +11 -5
- package/build/libarkts-copy/src/generated/peers/ETSNullType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ETSPackageDeclaration.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ETSParameterExpression.ts +46 -12
- package/build/libarkts-copy/src/generated/peers/ETSPrimitiveType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ETSReExportDeclaration.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/ETSStringLiteralType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ETSStructDeclaration.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ETSTuple.ts +14 -8
- package/build/libarkts-copy/src/generated/peers/ETSTypeReference.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ETSTypeReferencePart.ts +11 -5
- package/build/libarkts-copy/src/generated/peers/ETSUndefinedType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ETSUnionType.ts +15 -4
- package/build/libarkts-copy/src/generated/peers/ETSWildcardType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/EmptyStatement.ts +16 -4
- package/build/libarkts-copy/src/generated/peers/ErrorLogger.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/ExportAllDeclaration.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/ExportDefaultDeclaration.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/ExportNamedDeclaration.ts +18 -7
- package/build/libarkts-copy/src/generated/peers/ExportSpecifier.ts +26 -3
- package/build/libarkts-copy/src/generated/peers/Expression.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/ExpressionStatement.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/ForInStatement.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/ForOfStatement.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/ForUpdateStatement.ts +8 -2
- package/build/libarkts-copy/src/generated/peers/FunctionDecl.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/FunctionDeclaration.ts +44 -6
- package/build/libarkts-copy/src/generated/peers/FunctionExpression.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/FunctionSignature.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/IRNode.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/Identifier.ts +16 -5
- package/build/libarkts-copy/src/generated/peers/IfStatement.ts +14 -3
- package/build/libarkts-copy/src/generated/peers/ImportDeclaration.ts +28 -4
- package/build/libarkts-copy/src/generated/peers/ImportDefaultSpecifier.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/ImportExpression.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/ImportNamespaceSpecifier.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/ImportSource.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/ImportSpecifier.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/IndexInfo.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/InterfaceDecl.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/LabelPair.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/LabelledStatement.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/Literal.ts +15 -1
- package/build/libarkts-copy/src/generated/peers/LoopStatement.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/MaybeOptionalExpression.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/MemberExpression.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/MetaProperty.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/MethodDefinition.ts +26 -10
- package/build/libarkts-copy/src/generated/peers/NamedType.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/NewExpression.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/NullLiteral.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/NumberLiteral.ts +12 -6
- package/build/libarkts-copy/src/generated/peers/ObjectDescriptor.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/ObjectExpression.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/OmittedExpression.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/OpaqueTypeNode.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/PrefixAssertionExpression.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/Program.ts +194 -0
- package/build/libarkts-copy/src/generated/peers/Property.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/RegExpLiteral.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/ReturnStatement.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ScopeFindResult.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/ScriptFunction.ts +77 -10
- package/build/libarkts-copy/src/generated/peers/ScriptFunctionData.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/SequenceExpression.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/SignatureInfo.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/SourcePosition.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/SourceRange.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/SpreadElement.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/SrcDumper.ts +46 -9
- package/build/libarkts-copy/src/generated/peers/Statement.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/StringLiteral.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/{ETSDynamicFunctionType.ts → SuggestionInfo.ts} +7 -5
- package/build/libarkts-copy/src/generated/peers/SuperExpression.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/SwitchCaseStatement.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/SwitchStatement.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSAnyKeyword.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSArrayType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSAsExpression.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSBigintKeyword.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSBooleanKeyword.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSClassImplements.ts +11 -5
- package/build/libarkts-copy/src/generated/peers/TSConditionalType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSConstructorType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSEnumDeclaration.ts +48 -6
- package/build/libarkts-copy/src/generated/peers/TSEnumMember.ts +11 -5
- package/build/libarkts-copy/src/generated/peers/TSExternalModuleReference.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSFunctionType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSImportEqualsDeclaration.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSImportType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSIndexSignature.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSIndexedAccessType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSInferType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSInterfaceBody.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSInterfaceDeclaration.ts +78 -8
- package/build/libarkts-copy/src/generated/peers/TSInterfaceHeritage.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSIntersectionType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSLiteralType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSMappedType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSMethodSignature.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSModuleBlock.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSModuleDeclaration.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSNamedTupleMember.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSNeverKeyword.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSNonNullExpression.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSNullKeyword.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSNumberKeyword.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSObjectKeyword.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSParameterProperty.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSParenthesizedType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSPropertySignature.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSQualifiedName.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSSignatureDeclaration.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSStringKeyword.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSThisType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSTupleType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeAliasDeclaration.ts +53 -6
- package/build/libarkts-copy/src/generated/peers/TSTypeAssertion.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeLiteral.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeOperator.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeParameter.ts +41 -7
- package/build/libarkts-copy/src/generated/peers/TSTypeParameterDeclaration.ts +15 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeParameterInstantiation.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSTypePredicate.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeQuery.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeReference.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSUndefinedKeyword.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSUnionType.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSUnknownKeyword.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TSVoidKeyword.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TaggedTemplateExpression.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TemplateElement.ts +11 -5
- package/build/libarkts-copy/src/generated/peers/TemplateLiteral.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ThisExpression.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/ThrowStatement.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/TryStatement.ts +11 -5
- package/build/libarkts-copy/src/generated/peers/TypeNode.ts +37 -3
- package/build/libarkts-copy/src/generated/peers/TypedAstNode.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/TypedStatement.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/TypeofExpression.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/UnaryExpression.ts +15 -4
- package/build/libarkts-copy/src/generated/peers/UndefinedLiteral.ts +9 -3
- package/build/libarkts-copy/src/generated/peers/UpdateExpression.ts +10 -4
- package/build/libarkts-copy/src/generated/peers/VReg.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/ValidationInfo.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/VariableDeclaration.ts +48 -8
- package/build/libarkts-copy/src/generated/peers/VariableDeclarator.ts +11 -5
- package/build/libarkts-copy/src/generated/peers/VerificationContext.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/VerifierMessage.ts +7 -1
- package/build/libarkts-copy/src/generated/peers/WhileStatement.ts +15 -4
- package/build/libarkts-copy/src/generated/peers/YieldExpression.ts +10 -4
- package/build/libarkts-copy/src/index.ts +31 -1
- package/build/libarkts-copy/src/plugin-utils.ts +117 -0
- package/build/libarkts-copy/src/ts-api/factory/nodeFactory.ts +15 -0
- package/build/libarkts-copy/src/ts-api/factory/nodeTests.ts +15 -0
- package/build/libarkts-copy/src/ts-api/types.ts +15 -0
- package/build/libarkts-copy/src/utils.ts +24 -41
- package/build/libarkts-copy/src/wrapper-compat/README.md +16 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/class-by-peer.ts +46 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/factory/nodeFactory.ts +454 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/factory/nodeTests.ts +99 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/index.ts +88 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ArrayExpression.ts +38 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ArrowFunctionExpression.ts +35 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/AssignmentExpression.ts +38 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/BlockStatement.ts +27 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/CallExpression.ts +45 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ClassDeclaration.ts +27 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ClassDefinition.ts +73 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ClassProperty.ts +51 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ETSFunctionType.ts +42 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ETSImportDeclaration.ts +39 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ETSParameterExpression.ts +43 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ExpressionStatement.ts +28 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/FunctionDeclaration.ts +37 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/FunctionExpression.ts +28 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/IfStatement.ts +37 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/MemberExpression.ts +42 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/MethodDefinition.ts +46 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/NumberLiteral.ts +30 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ObjectExpression.ts +37 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/Property.ts +27 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/ScriptFunction.ts +46 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/StructDeclaration.ts +28 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/TSInterfaceDeclaration.ts +47 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/TSTypeAliasDeclaration.ts +40 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/TSTypeParameter.ts +36 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/TryStatement.ts +41 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/VariableDeclaration.ts +42 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/node-utilities/VariableDeclarator.ts +39 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/ArktsObject.ts +45 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/AstNode.ts +26 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/Config.ts +53 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/Context.ts +60 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/Diagnostic.ts +39 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/DiagnosticInfo.ts +33 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/DiagnosticKind.ts +33 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/ImportPathManager.ts +34 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/Program.ts +105 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/SourcePosition.ts +38 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/SourceRange.ts +38 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/peers/SuggestionInfo.ts +33 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/static/global.ts +16 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/static/globalUtils.ts +27 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/to-be-generated/MemberExpression.ts +108 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/types.ts +907 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/utilities/nativePtrDecoder.ts +69 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/utilities/performance.ts +190 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/utilities/private.ts +198 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/utilities/public.ts +325 -0
- package/build/libarkts-copy/src/wrapper-compat/arkts-api/visitor.ts +421 -0
- package/build/libarkts-copy/src/wrapper-compat/index.ts +20 -0
- package/build/libarkts-copy/tsconfig.json +2 -1
- package/lib/index.js +1704 -273
- package/package.json +2 -2
- package/templates/Es2pandaEnums.ts +4 -0
- package/templates/Es2pandaNativeModule.ts +5 -1
- package/templates/factory.ts +5 -1
- package/templates/index.ts +5 -1
- package/templates/node-map.ts +5 -1
- package/templates/peer.ts +5 -1
- package/build/libarkts-copy/README.md +0 -36
package/lib/index.js
CHANGED
|
@@ -136,7 +136,7 @@ function error(
|
|
|
136
136
|
: 1;
|
|
137
137
|
|
|
138
138
|
const precedingLastLine = lastLine(
|
|
139
|
-
tokensToText(sliceTokens(-
|
|
139
|
+
tokensToText(sliceTokens(-maxTokens), { precedes: true }),
|
|
140
140
|
);
|
|
141
141
|
|
|
142
142
|
const subsequentTokens = sliceTokens(maxTokens);
|
|
@@ -1605,19 +1605,52 @@ class CallbackFunction extends Base {
|
|
|
1605
1605
|
/**
|
|
1606
1606
|
* @param {import("../tokeniser.js").Tokeniser} tokeniser
|
|
1607
1607
|
*/
|
|
1608
|
-
function
|
|
1608
|
+
function inheritanceItem(tokeniser) {
|
|
1609
|
+
const extAttrs = ExtendedAttributes.parse(tokeniser);
|
|
1610
|
+
const inheritance = tokeniser.consumeKind("identifier");
|
|
1611
|
+
if (!inheritance) {
|
|
1612
|
+
return undefined;
|
|
1613
|
+
}
|
|
1614
|
+
return {
|
|
1615
|
+
extAttrs,
|
|
1616
|
+
inheritance,
|
|
1617
|
+
tokens: {},
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
/**
|
|
1622
|
+
* @param {import("../tokeniser.js").Tokeniser} tokeniser
|
|
1623
|
+
* @param {boolean} multipleInheritance
|
|
1624
|
+
*/
|
|
1625
|
+
function inheritance(tokeniser, multipleInheritance) {
|
|
1609
1626
|
const colon = tokeniser.consume(":");
|
|
1610
1627
|
if (!colon) {
|
|
1611
1628
|
return {};
|
|
1612
1629
|
}
|
|
1613
|
-
const
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1630
|
+
const first =
|
|
1631
|
+
inheritanceItem(tokeniser) || tokeniser.error("Inheritance lacks a type");
|
|
1632
|
+
if (!multipleInheritance) {
|
|
1633
|
+
return {
|
|
1634
|
+
colon,
|
|
1635
|
+
extAttrs: first.extAttrs,
|
|
1636
|
+
inheritance: first.inheritance,
|
|
1637
|
+
};
|
|
1638
|
+
}
|
|
1639
|
+
first.tokens.separator = tokeniser.consume(",");
|
|
1640
|
+
if (!first.tokens.separator) {
|
|
1641
|
+
return {
|
|
1642
|
+
colon,
|
|
1643
|
+
inheritance: [first],
|
|
1644
|
+
};
|
|
1645
|
+
}
|
|
1646
|
+
const rest = list(tokeniser, {
|
|
1647
|
+
parser: inheritanceItem,
|
|
1648
|
+
listName: "inheritance-list",
|
|
1649
|
+
allowDangler: false,
|
|
1650
|
+
});
|
|
1617
1651
|
return {
|
|
1618
1652
|
colon,
|
|
1619
|
-
|
|
1620
|
-
inheritance,
|
|
1653
|
+
inheritance: [first, ...rest],
|
|
1621
1654
|
};
|
|
1622
1655
|
}
|
|
1623
1656
|
|
|
@@ -1640,7 +1673,11 @@ class Container extends Base {
|
|
|
1640
1673
|
* @param {*} instance TODO: This should be {T extends Container}, but see https://github.com/microsoft/TypeScript/issues/4628
|
|
1641
1674
|
* @param {*} args
|
|
1642
1675
|
*/
|
|
1643
|
-
static parse(
|
|
1676
|
+
static parse(
|
|
1677
|
+
tokeniser,
|
|
1678
|
+
instance,
|
|
1679
|
+
{ inheritable, allowedMembers, multipleInheritance = false },
|
|
1680
|
+
) {
|
|
1644
1681
|
const { tokens, type } = instance;
|
|
1645
1682
|
tokens.name =
|
|
1646
1683
|
tokeniser.consumeKind("identifier") ||
|
|
@@ -1648,10 +1685,12 @@ class Container extends Base {
|
|
|
1648
1685
|
tokeniser.current = instance;
|
|
1649
1686
|
instance = autoParenter(instance);
|
|
1650
1687
|
if (inheritable) {
|
|
1651
|
-
const inheritanceParsed = inheritance(tokeniser);
|
|
1688
|
+
const inheritanceParsed = inheritance(tokeniser, multipleInheritance);
|
|
1652
1689
|
tokens.colon = inheritanceParsed.colon;
|
|
1653
1690
|
tokens.inheritance = inheritanceParsed.inheritance;
|
|
1654
|
-
|
|
1691
|
+
if (!multipleInheritance) {
|
|
1692
|
+
instance.inheritanceExtAttrs = inheritanceParsed.extAttrs;
|
|
1693
|
+
}
|
|
1655
1694
|
}
|
|
1656
1695
|
tokens.open = tokeniser.consume("{") || tokeniser.error(`Bodyless ${type}`);
|
|
1657
1696
|
instance.members = [];
|
|
@@ -1694,6 +1733,14 @@ class Container extends Base {
|
|
|
1694
1733
|
if (!this.tokens.inheritance) {
|
|
1695
1734
|
return null;
|
|
1696
1735
|
}
|
|
1736
|
+
if (Array.isArray(this.tokens.inheritance)) {
|
|
1737
|
+
return this.tokens.inheritance.map((it) => {
|
|
1738
|
+
return {
|
|
1739
|
+
extAttrs: it.extAttrs,
|
|
1740
|
+
inheritance: unescape(it.inheritance.value),
|
|
1741
|
+
};
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1697
1744
|
return unescape(this.tokens.inheritance.value);
|
|
1698
1745
|
}
|
|
1699
1746
|
|
|
@@ -2069,6 +2116,7 @@ class Interface extends Container {
|
|
|
2069
2116
|
[Attribute.parse],
|
|
2070
2117
|
[Operation.parse],
|
|
2071
2118
|
],
|
|
2119
|
+
multipleInheritance: true,
|
|
2072
2120
|
},
|
|
2073
2121
|
);
|
|
2074
2122
|
}
|
|
@@ -3015,7 +3063,7 @@ const tokenRe = {
|
|
|
3015
3063
|
decimal:
|
|
3016
3064
|
/-?(?=[0-9]*\.|[0-9]+[eE])(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][-+]?[0-9]+)?|[0-9]+[Ee][-+]?[0-9]+)/y,
|
|
3017
3065
|
integer: /-?(0([Xx][0-9A-Fa-f]+|[0-7]*)|[1-9][0-9]*)/y,
|
|
3018
|
-
identifier: /[
|
|
3066
|
+
identifier: /[-$_A-Za-z](\.?[$0-9A-Z_a-z-])*/y,
|
|
3019
3067
|
string: /"(\\"|[^"])*"/y,
|
|
3020
3068
|
whitespace: /[\t\n\r ]+/y,
|
|
3021
3069
|
comment: /\/\/.*|\/\*[\s\S]*?\*\//y,
|
|
@@ -3123,8 +3171,6 @@ const punctuations = [
|
|
|
3123
3171
|
const reserved = [
|
|
3124
3172
|
// "constructor" is now a keyword
|
|
3125
3173
|
"_constructor",
|
|
3126
|
-
"toString",
|
|
3127
|
-
"_toString",
|
|
3128
3174
|
];
|
|
3129
3175
|
|
|
3130
3176
|
/**
|
|
@@ -3152,7 +3198,7 @@ function tokenise(str) {
|
|
|
3152
3198
|
line += (currentTrivia.match(/\n/g) || []).length;
|
|
3153
3199
|
trivia += currentTrivia;
|
|
3154
3200
|
index -= 1;
|
|
3155
|
-
} else if (/[
|
|
3201
|
+
} else if (/[-$0-9.A-Z_a-z]/.test(nextChar)) {
|
|
3156
3202
|
result = attemptTokenMatch("decimal");
|
|
3157
3203
|
if (result === -1) {
|
|
3158
3204
|
result = attemptTokenMatch("integer");
|
|
@@ -3612,6 +3658,8 @@ class Language {
|
|
|
3612
3658
|
case "java": return Language.JAVA;
|
|
3613
3659
|
case "ts": return Language.TS;
|
|
3614
3660
|
case "cangjie": return Language.CJ;
|
|
3661
|
+
case "cpp": return Language.CPP;
|
|
3662
|
+
case "kotlin": return Language.KOTLIN;
|
|
3615
3663
|
default: throw new Error(`Unsupported language ${name}`);
|
|
3616
3664
|
}
|
|
3617
3665
|
}
|
|
@@ -3621,6 +3669,7 @@ Language.ARKTS = new Language("ArkTS", ".ts", true); // using .ts for ArkTS unti
|
|
|
3621
3669
|
Language.JAVA = new Language("Java", ".java", false);
|
|
3622
3670
|
Language.CPP = new Language("C++", ".cc", false);
|
|
3623
3671
|
Language.CJ = new Language("CangJie", ".cj", false);
|
|
3672
|
+
Language.KOTLIN = new Language("Kotlin", ".kt", false);
|
|
3624
3673
|
|
|
3625
3674
|
/*
|
|
3626
3675
|
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
@@ -3649,11 +3698,20 @@ function generateSyntheticIdlNodeName(type) {
|
|
|
3649
3698
|
}
|
|
3650
3699
|
}
|
|
3651
3700
|
if (isNamedNode(type))
|
|
3652
|
-
return type.name;
|
|
3701
|
+
return type.name.split('.').map(capitalize).join('_');
|
|
3653
3702
|
if (isOptionalType(type))
|
|
3654
3703
|
return `Opt_${generateSyntheticIdlNodeName(type.type)}`;
|
|
3655
3704
|
throw `Can not compute type name of ${IDLKind[type.kind]}`;
|
|
3656
3705
|
}
|
|
3706
|
+
function qualifiedName(decl, languageOrDelimiter, pattern) {
|
|
3707
|
+
if (!isNamedNode(decl))
|
|
3708
|
+
throw new Error("internal error, name required for no-named node");
|
|
3709
|
+
const delimiter = languageOrDelimiter
|
|
3710
|
+
;
|
|
3711
|
+
if (!isEntry(decl))
|
|
3712
|
+
throw new Error(`Expected to have an IDLEntry, got ${IDLKind[decl.kind]}`);
|
|
3713
|
+
return getQualifiedName(decl, pattern).split(".").join(delimiter);
|
|
3714
|
+
}
|
|
3657
3715
|
function collapseTypes(types, name) {
|
|
3658
3716
|
const seenNames = new Set();
|
|
3659
3717
|
const uniqueTypes = types.filter(it => {
|
|
@@ -3763,6 +3821,7 @@ var IDLExtendedAttributes;
|
|
|
3763
3821
|
IDLExtendedAttributes["DtsName"] = "DtsName";
|
|
3764
3822
|
IDLExtendedAttributes["DtsTag"] = "DtsTag";
|
|
3765
3823
|
IDLExtendedAttributes["Entity"] = "Entity";
|
|
3824
|
+
IDLExtendedAttributes["Extends"] = "Extends";
|
|
3766
3825
|
IDLExtendedAttributes["Import"] = "Import";
|
|
3767
3826
|
IDLExtendedAttributes["DefaultExport"] = "DefaultExport";
|
|
3768
3827
|
IDLExtendedAttributes["IndexSignature"] = "IndexSignature";
|
|
@@ -3774,10 +3833,12 @@ var IDLExtendedAttributes;
|
|
|
3774
3833
|
IDLExtendedAttributes["Protected"] = "Protected";
|
|
3775
3834
|
IDLExtendedAttributes["Synthetic"] = "Synthetic";
|
|
3776
3835
|
IDLExtendedAttributes["Throws"] = "Throws";
|
|
3836
|
+
IDLExtendedAttributes["TraceKey"] = "TraceKey";
|
|
3777
3837
|
IDLExtendedAttributes["TypeArguments"] = "TypeArguments";
|
|
3778
3838
|
IDLExtendedAttributes["TypeParameters"] = "TypeParameters";
|
|
3779
3839
|
IDLExtendedAttributes["VerbatimDts"] = "VerbatimDts";
|
|
3780
3840
|
IDLExtendedAttributes["HandWrittenImplementation"] = "HandWrittenImplementation";
|
|
3841
|
+
IDLExtendedAttributes["ExtraMethod"] = "ExtraMethod";
|
|
3781
3842
|
})(IDLExtendedAttributes || (IDLExtendedAttributes = {}));
|
|
3782
3843
|
var IDLAccessorAttribute;
|
|
3783
3844
|
(function (IDLAccessorAttribute) {
|
|
@@ -3794,6 +3855,7 @@ var IDLInterfaceSubkind;
|
|
|
3794
3855
|
})(IDLInterfaceSubkind || (IDLInterfaceSubkind = {}));
|
|
3795
3856
|
/** Updates tree in place! */
|
|
3796
3857
|
function updateEachChild(node, op, cbLeave) {
|
|
3858
|
+
var _a;
|
|
3797
3859
|
const old = node;
|
|
3798
3860
|
node = op(old);
|
|
3799
3861
|
if (node.kind !== old.kind) {
|
|
@@ -3876,7 +3938,11 @@ function updateEachChild(node, op, cbLeave) {
|
|
|
3876
3938
|
concrete.typeArguments = concrete.typeArguments.map(it => updateEachChild(it, op, cbLeave));
|
|
3877
3939
|
break;
|
|
3878
3940
|
}
|
|
3879
|
-
case IDLKind.ReferenceType:
|
|
3941
|
+
case IDLKind.ReferenceType: {
|
|
3942
|
+
const concrete = node;
|
|
3943
|
+
concrete.typeArguments = (_a = concrete.typeArguments) === null || _a === void 0 ? void 0 : _a.map(it => updateEachChild(it, op, cbLeave));
|
|
3944
|
+
break;
|
|
3945
|
+
}
|
|
3880
3946
|
case IDLKind.TypeParameterType:
|
|
3881
3947
|
case IDLKind.EnumMember:
|
|
3882
3948
|
case IDLKind.Import:
|
|
@@ -3922,6 +3988,9 @@ function isUnspecifiedGenericType(type) {
|
|
|
3922
3988
|
function isEnum$1(type) {
|
|
3923
3989
|
return type.kind == IDLKind.Enum;
|
|
3924
3990
|
}
|
|
3991
|
+
function isEnumMember(type) {
|
|
3992
|
+
return type.kind == IDLKind.EnumMember;
|
|
3993
|
+
}
|
|
3925
3994
|
function isUnionType(type) {
|
|
3926
3995
|
return type.kind == IDLKind.UnionType;
|
|
3927
3996
|
}
|
|
@@ -3937,6 +4006,9 @@ function isImport(type) {
|
|
|
3937
4006
|
function isMethod(node) {
|
|
3938
4007
|
return node.kind === IDLKind.Method;
|
|
3939
4008
|
}
|
|
4009
|
+
function isCallback$1(node) {
|
|
4010
|
+
return node.kind === IDLKind.Callback;
|
|
4011
|
+
}
|
|
3940
4012
|
function isInterfaceSubkind(idl) {
|
|
3941
4013
|
return idl.subkind === IDLInterfaceSubkind.Interface;
|
|
3942
4014
|
}
|
|
@@ -3946,6 +4018,9 @@ function isClassSubkind(idl) {
|
|
|
3946
4018
|
function isConstant$1(node) {
|
|
3947
4019
|
return node.kind === IDLKind.Const;
|
|
3948
4020
|
}
|
|
4021
|
+
function isTypedef$1(node) {
|
|
4022
|
+
return node.kind === IDLKind.Typedef;
|
|
4023
|
+
}
|
|
3949
4024
|
function isType(node) {
|
|
3950
4025
|
return "_idlTypeBrand" in node;
|
|
3951
4026
|
}
|
|
@@ -3971,17 +4046,11 @@ function createOptionalType(element, nodeInitializer) {
|
|
|
3971
4046
|
if (isOptionalType(element) && !nodeInitializer) {
|
|
3972
4047
|
return element;
|
|
3973
4048
|
}
|
|
4049
|
+
if (isOptionalType(element)) {
|
|
4050
|
+
return Object.assign(Object.assign({ kind: IDLKind.OptionalType, type: element.type }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol });
|
|
4051
|
+
}
|
|
3974
4052
|
return Object.assign(Object.assign({ kind: IDLKind.OptionalType, type: element }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol });
|
|
3975
4053
|
}
|
|
3976
|
-
/**
|
|
3977
|
-
* This placeholder is used when a class has no superclass.
|
|
3978
|
-
* Examples:
|
|
3979
|
-
* class definition: inheritance:
|
|
3980
|
-
* `C extends T` : [T]
|
|
3981
|
-
* `C implements T` : [Top, T]
|
|
3982
|
-
* `C extends T implements I, J` : [T, I, J]
|
|
3983
|
-
*/
|
|
3984
|
-
const IDLTopType = createReferenceType("__TOP__");
|
|
3985
4054
|
// must match with toIDLType in deserialize.ts
|
|
3986
4055
|
const IDLPointerType = createPrimitiveType('pointer');
|
|
3987
4056
|
const IDLVoidType = createPrimitiveType('void');
|
|
@@ -4003,28 +4072,23 @@ const IDLStringType = createPrimitiveType('String');
|
|
|
4003
4072
|
const IDLAnyType = createPrimitiveType('any');
|
|
4004
4073
|
const IDLUndefinedType = createPrimitiveType('undefined');
|
|
4005
4074
|
const IDLUnknownType = createPrimitiveType('unknown');
|
|
4006
|
-
const IDLObjectType =
|
|
4075
|
+
const IDLObjectType = createPrimitiveType('Object');
|
|
4007
4076
|
const IDLThisType = createPrimitiveType('this');
|
|
4008
4077
|
const IDLDate = createPrimitiveType('date');
|
|
4009
4078
|
const IDLBufferType = createPrimitiveType('buffer');
|
|
4010
4079
|
createContainerType('sequence', [IDLU8Type]);
|
|
4011
4080
|
const IDLSerializerBuffer = createPrimitiveType('SerializerBuffer');
|
|
4012
4081
|
// Stub for IdlPeerLibrary
|
|
4013
|
-
createPrimitiveType('Function');
|
|
4014
|
-
createPrimitiveType('CustomObject');
|
|
4082
|
+
const IDLFunctionType = createPrimitiveType('Function');
|
|
4083
|
+
const IDLCustomObjectType = createPrimitiveType('CustomObject');
|
|
4015
4084
|
createPrimitiveType('InteropReturnBuffer');
|
|
4016
4085
|
function createNamespace(name, members, nodeInitializer) {
|
|
4017
4086
|
return Object.assign(Object.assign({ kind: IDLKind.Namespace, members: members !== null && members !== void 0 ? members : [], name: name }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
4018
4087
|
}
|
|
4019
|
-
function isSpecialNodes(node) {
|
|
4020
|
-
return node === IDLTopType
|
|
4021
|
-
|| node === IDLObjectType
|
|
4022
|
-
|| isPrimitiveType(node);
|
|
4023
|
-
}
|
|
4024
4088
|
function linkParentBack(node) {
|
|
4025
4089
|
const parentStack = [];
|
|
4026
4090
|
updateEachChild(node, (node) => {
|
|
4027
|
-
if (
|
|
4091
|
+
if (isPrimitiveType(node)) {
|
|
4028
4092
|
return node;
|
|
4029
4093
|
}
|
|
4030
4094
|
if (parentStack.length) {
|
|
@@ -4037,7 +4101,7 @@ function linkParentBack(node) {
|
|
|
4037
4101
|
parentStack.push(node);
|
|
4038
4102
|
return node;
|
|
4039
4103
|
}, (node) => {
|
|
4040
|
-
if (
|
|
4104
|
+
if (isPrimitiveType(node)) {
|
|
4041
4105
|
return;
|
|
4042
4106
|
}
|
|
4043
4107
|
parentStack.pop();
|
|
@@ -4115,7 +4179,7 @@ function createFile(entries, fileName, packageClause = [], nodeInitializer) {
|
|
|
4115
4179
|
return Object.assign(Object.assign({ kind: IDLKind.File, packageClause, entries: entries, fileName }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol });
|
|
4116
4180
|
}
|
|
4117
4181
|
function createImport(clause, name, nodeInitializer) {
|
|
4118
|
-
return Object.assign(Object.assign({ kind: IDLKind.Import, name: name
|
|
4182
|
+
return Object.assign(Object.assign({ kind: IDLKind.Import, name: name !== null && name !== void 0 ? name : "", clause }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
4119
4183
|
}
|
|
4120
4184
|
function createEnum(name, elements, nodeInitializer) {
|
|
4121
4185
|
return Object.assign(Object.assign({ kind: IDLKind.Enum, name: name, elements: elements }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
@@ -4169,13 +4233,6 @@ function createConstructor(parameters, returnType, nodeInitializer = {}) {
|
|
|
4169
4233
|
returnType }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
4170
4234
|
}
|
|
4171
4235
|
function createCallback(name, parameters, returnType, nodeInitializer = {}, typeParameters = []) {
|
|
4172
|
-
if (returnType === IDLThisType || isReferenceType(returnType) && returnType.name === "this")
|
|
4173
|
-
returnType = IDLAnyType;
|
|
4174
|
-
parameters = parameters.map(it => {
|
|
4175
|
-
if (it.type && isNamedNode(it.type) && (it.type.name === "T" || it.type.name === "this"))
|
|
4176
|
-
return createParameter(it.name, IDLAnyType, it.isOptional, it.isVariadic, { fileName: it.fileName });
|
|
4177
|
-
return it;
|
|
4178
|
-
});
|
|
4179
4236
|
return Object.assign(Object.assign({ kind: IDLKind.Callback, name, parameters, returnType, typeParameters }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
4180
4237
|
}
|
|
4181
4238
|
function createTypeParameterReference(name, nodeInitializer) {
|
|
@@ -4190,7 +4247,7 @@ function createConstant(name, type, value, nodeInitializer = {}) {
|
|
|
4190
4247
|
value }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
4191
4248
|
}
|
|
4192
4249
|
function clone(node) {
|
|
4193
|
-
var _a, _b, _c, _d;
|
|
4250
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
4194
4251
|
const make = (node) => node;
|
|
4195
4252
|
const get = (node) => node;
|
|
4196
4253
|
switch (node.kind) {
|
|
@@ -4198,7 +4255,7 @@ function clone(node) {
|
|
|
4198
4255
|
const entry = get(node);
|
|
4199
4256
|
return make(createInterface(entry.name, entry.subkind, (_a = entry.inheritance) === null || _a === void 0 ? void 0 : _a.map(clone), (_b = entry.constructors) === null || _b === void 0 ? void 0 : _b.map(clone), entry.constants.map(clone), entry.properties.map(clone), entry.methods.map(clone), entry.callables.map(clone), (_c = entry.typeParameters) === null || _c === void 0 ? void 0 : _c.map(it => it), {
|
|
4200
4257
|
documentation: node.documentation,
|
|
4201
|
-
extendedAttributes: node.extendedAttributes,
|
|
4258
|
+
extendedAttributes: (_d = node.extendedAttributes) === null || _d === void 0 ? void 0 : _d.slice(),
|
|
4202
4259
|
fileName: node.fileName
|
|
4203
4260
|
}));
|
|
4204
4261
|
}
|
|
@@ -4206,7 +4263,7 @@ function clone(node) {
|
|
|
4206
4263
|
const entry = get(node);
|
|
4207
4264
|
return make(createImport(entry.clause, entry.name, {
|
|
4208
4265
|
documentation: entry.documentation,
|
|
4209
|
-
extendedAttributes: entry.extendedAttributes,
|
|
4266
|
+
extendedAttributes: (_e = entry.extendedAttributes) === null || _e === void 0 ? void 0 : _e.slice(),
|
|
4210
4267
|
fileName: entry.fileName
|
|
4211
4268
|
}));
|
|
4212
4269
|
}
|
|
@@ -4214,7 +4271,7 @@ function clone(node) {
|
|
|
4214
4271
|
const entry = get(node);
|
|
4215
4272
|
return make(createCallback(entry.name, entry.parameters.map(clone), clone(entry.returnType), {
|
|
4216
4273
|
documentation: entry.documentation,
|
|
4217
|
-
extendedAttributes: entry.extendedAttributes,
|
|
4274
|
+
extendedAttributes: (_f = entry.extendedAttributes) === null || _f === void 0 ? void 0 : _f.slice(),
|
|
4218
4275
|
fileName: entry.fileName
|
|
4219
4276
|
}, entry.typeParameters));
|
|
4220
4277
|
}
|
|
@@ -4222,7 +4279,7 @@ function clone(node) {
|
|
|
4222
4279
|
const entry = get(node);
|
|
4223
4280
|
return make(createConstant(entry.name, clone(entry.type), entry.value, {
|
|
4224
4281
|
documentation: entry.documentation,
|
|
4225
|
-
extendedAttributes: entry.extendedAttributes,
|
|
4282
|
+
extendedAttributes: (_g = entry.extendedAttributes) === null || _g === void 0 ? void 0 : _g.slice(),
|
|
4226
4283
|
fileName: entry.fileName
|
|
4227
4284
|
}));
|
|
4228
4285
|
}
|
|
@@ -4230,7 +4287,7 @@ function clone(node) {
|
|
|
4230
4287
|
const entry = get(node);
|
|
4231
4288
|
return make(createProperty(entry.name, clone(entry.type), entry.isReadonly, entry.isStatic, entry.isOptional, {
|
|
4232
4289
|
documentation: entry.documentation,
|
|
4233
|
-
extendedAttributes: entry.extendedAttributes,
|
|
4290
|
+
extendedAttributes: (_h = entry.extendedAttributes) === null || _h === void 0 ? void 0 : _h.slice(),
|
|
4234
4291
|
fileName: entry.fileName
|
|
4235
4292
|
}));
|
|
4236
4293
|
}
|
|
@@ -4238,7 +4295,7 @@ function clone(node) {
|
|
|
4238
4295
|
const entry = get(node);
|
|
4239
4296
|
return make(createParameter(entry.name, clone(entry.type), entry.isOptional, entry.isVariadic, {
|
|
4240
4297
|
documentation: entry.documentation,
|
|
4241
|
-
extendedAttributes: entry.extendedAttributes,
|
|
4298
|
+
extendedAttributes: (_j = entry.extendedAttributes) === null || _j === void 0 ? void 0 : _j.slice(),
|
|
4242
4299
|
fileName: entry.fileName
|
|
4243
4300
|
}));
|
|
4244
4301
|
}
|
|
@@ -4251,7 +4308,7 @@ function clone(node) {
|
|
|
4251
4308
|
isStatic: entry.isStatic
|
|
4252
4309
|
}, {
|
|
4253
4310
|
documentation: entry.documentation,
|
|
4254
|
-
extendedAttributes: entry.extendedAttributes,
|
|
4311
|
+
extendedAttributes: (_k = entry.extendedAttributes) === null || _k === void 0 ? void 0 : _k.slice(),
|
|
4255
4312
|
fileName: entry.fileName
|
|
4256
4313
|
}, entry.typeParameters));
|
|
4257
4314
|
}
|
|
@@ -4262,7 +4319,7 @@ function clone(node) {
|
|
|
4262
4319
|
isStatic: entry.isStatic
|
|
4263
4320
|
}, {
|
|
4264
4321
|
documentation: entry.documentation,
|
|
4265
|
-
extendedAttributes: entry.extendedAttributes,
|
|
4322
|
+
extendedAttributes: (_l = entry.extendedAttributes) === null || _l === void 0 ? void 0 : _l.slice(),
|
|
4266
4323
|
fileName: entry.documentation
|
|
4267
4324
|
}, entry.typeParameters));
|
|
4268
4325
|
}
|
|
@@ -4270,7 +4327,7 @@ function clone(node) {
|
|
|
4270
4327
|
const entry = get(node);
|
|
4271
4328
|
return make(createConstructor(entry.parameters.map(clone), entry.returnType ? clone(entry.returnType) : undefined, {
|
|
4272
4329
|
documentation: entry.documentation,
|
|
4273
|
-
extendedAttributes: entry.extendedAttributes,
|
|
4330
|
+
extendedAttributes: (_m = entry.extendedAttributes) === null || _m === void 0 ? void 0 : _m.slice(),
|
|
4274
4331
|
fileName: entry.fileName
|
|
4275
4332
|
}));
|
|
4276
4333
|
}
|
|
@@ -4278,7 +4335,7 @@ function clone(node) {
|
|
|
4278
4335
|
const entry = get(node);
|
|
4279
4336
|
const cloned = createEnum(entry.name, entry.elements.map(clone), {
|
|
4280
4337
|
documentation: entry.documentation,
|
|
4281
|
-
extendedAttributes: entry.extendedAttributes,
|
|
4338
|
+
extendedAttributes: (_o = entry.extendedAttributes) === null || _o === void 0 ? void 0 : _o.slice(),
|
|
4282
4339
|
fileName: entry.fileName
|
|
4283
4340
|
});
|
|
4284
4341
|
cloned.elements.forEach(it => {
|
|
@@ -4290,7 +4347,7 @@ function clone(node) {
|
|
|
4290
4347
|
const entry = get(node);
|
|
4291
4348
|
return make(createEnumMember(entry.name, entry.parent, clone(entry.type), entry.initializer, {
|
|
4292
4349
|
documentation: entry.documentation,
|
|
4293
|
-
extendedAttributes: entry.extendedAttributes,
|
|
4350
|
+
extendedAttributes: (_p = entry.extendedAttributes) === null || _p === void 0 ? void 0 : _p.slice(),
|
|
4294
4351
|
fileName: entry.fileName
|
|
4295
4352
|
}));
|
|
4296
4353
|
}
|
|
@@ -4298,7 +4355,7 @@ function clone(node) {
|
|
|
4298
4355
|
const entry = get(node);
|
|
4299
4356
|
return make(createTypedef(entry.name, clone(entry.type), entry.typeParameters, {
|
|
4300
4357
|
documentation: entry.documentation,
|
|
4301
|
-
extendedAttributes: entry.extendedAttributes,
|
|
4358
|
+
extendedAttributes: (_q = entry.extendedAttributes) === null || _q === void 0 ? void 0 : _q.slice(),
|
|
4302
4359
|
fileName: entry.fileName
|
|
4303
4360
|
}));
|
|
4304
4361
|
}
|
|
@@ -4309,7 +4366,7 @@ function clone(node) {
|
|
|
4309
4366
|
const type = get(node);
|
|
4310
4367
|
return make(createContainerType(type.containerKind, type.elementType.map(clone), {
|
|
4311
4368
|
documentation: type.documentation,
|
|
4312
|
-
extendedAttributes: type.extendedAttributes,
|
|
4369
|
+
extendedAttributes: (_r = type.extendedAttributes) === null || _r === void 0 ? void 0 : _r.slice(),
|
|
4313
4370
|
fileName: type.fileName
|
|
4314
4371
|
}));
|
|
4315
4372
|
}
|
|
@@ -4317,15 +4374,15 @@ function clone(node) {
|
|
|
4317
4374
|
const type = get(node);
|
|
4318
4375
|
return make(createUnspecifiedGenericType(type.name, type.typeArguments.map(clone), {
|
|
4319
4376
|
documentation: type.documentation,
|
|
4320
|
-
extendedAttributes: type.extendedAttributes,
|
|
4377
|
+
extendedAttributes: (_s = type.extendedAttributes) === null || _s === void 0 ? void 0 : _s.slice(),
|
|
4321
4378
|
fileName: type.fileName
|
|
4322
4379
|
}));
|
|
4323
4380
|
}
|
|
4324
4381
|
case IDLKind.ReferenceType: {
|
|
4325
4382
|
const type = get(node);
|
|
4326
|
-
return make(createReferenceType(type.name, (
|
|
4383
|
+
return make(createReferenceType(type.name, (_t = type.typeArguments) === null || _t === void 0 ? void 0 : _t.map(clone), {
|
|
4327
4384
|
documentation: type.documentation,
|
|
4328
|
-
extendedAttributes: type.extendedAttributes,
|
|
4385
|
+
extendedAttributes: (_u = type.extendedAttributes) === null || _u === void 0 ? void 0 : _u.slice(),
|
|
4329
4386
|
fileName: type.fileName
|
|
4330
4387
|
}));
|
|
4331
4388
|
}
|
|
@@ -4333,7 +4390,7 @@ function clone(node) {
|
|
|
4333
4390
|
const type = get(node);
|
|
4334
4391
|
return make(createUnionType(type.types.map(clone), type.name, {
|
|
4335
4392
|
documentation: type.documentation,
|
|
4336
|
-
extendedAttributes: type.extendedAttributes,
|
|
4393
|
+
extendedAttributes: (_v = type.extendedAttributes) === null || _v === void 0 ? void 0 : _v.slice(),
|
|
4337
4394
|
fileName: type.fileName
|
|
4338
4395
|
}));
|
|
4339
4396
|
}
|
|
@@ -4341,7 +4398,7 @@ function clone(node) {
|
|
|
4341
4398
|
const type = get(node);
|
|
4342
4399
|
return make(createTypeParameterReference(type.name, {
|
|
4343
4400
|
documentation: type.documentation,
|
|
4344
|
-
extendedAttributes: type.extendedAttributes,
|
|
4401
|
+
extendedAttributes: (_w = type.extendedAttributes) === null || _w === void 0 ? void 0 : _w.slice(),
|
|
4345
4402
|
fileName: type.fileName
|
|
4346
4403
|
}));
|
|
4347
4404
|
}
|
|
@@ -4349,7 +4406,7 @@ function clone(node) {
|
|
|
4349
4406
|
const type = get(node);
|
|
4350
4407
|
return make(createOptionalType(clone(type.type), {
|
|
4351
4408
|
documentation: type.documentation,
|
|
4352
|
-
extendedAttributes: type.extendedAttributes,
|
|
4409
|
+
extendedAttributes: (_x = type.extendedAttributes) === null || _x === void 0 ? void 0 : _x.slice(),
|
|
4353
4410
|
fileName: type.fileName
|
|
4354
4411
|
}));
|
|
4355
4412
|
}
|
|
@@ -4357,7 +4414,7 @@ function clone(node) {
|
|
|
4357
4414
|
const entry = get(node);
|
|
4358
4415
|
return make(createVersion(entry.value, {
|
|
4359
4416
|
documentation: entry.documentation,
|
|
4360
|
-
extendedAttributes: entry.extendedAttributes,
|
|
4417
|
+
extendedAttributes: (_y = entry.extendedAttributes) === null || _y === void 0 ? void 0 : _y.slice(),
|
|
4361
4418
|
fileName: entry.fileName
|
|
4362
4419
|
}));
|
|
4363
4420
|
}
|
|
@@ -4365,7 +4422,7 @@ function clone(node) {
|
|
|
4365
4422
|
const ns = get(node);
|
|
4366
4423
|
return make(createNamespace(ns.name, ns.members.map(clone), {
|
|
4367
4424
|
documentation: ns.documentation,
|
|
4368
|
-
extendedAttributes: ns.extendedAttributes,
|
|
4425
|
+
extendedAttributes: (_z = ns.extendedAttributes) === null || _z === void 0 ? void 0 : _z.slice(),
|
|
4369
4426
|
fileName: ns.fileName
|
|
4370
4427
|
}));
|
|
4371
4428
|
}
|
|
@@ -4373,7 +4430,7 @@ function clone(node) {
|
|
|
4373
4430
|
const file = get(node);
|
|
4374
4431
|
return make(createFile(file.entries.map(clone), file.fileName, file.packageClause, {
|
|
4375
4432
|
documentation: file.documentation,
|
|
4376
|
-
extendedAttributes: file.extendedAttributes,
|
|
4433
|
+
extendedAttributes: (_0 = file.extendedAttributes) === null || _0 === void 0 ? void 0 : _0.slice(),
|
|
4377
4434
|
fileName: file.fileName
|
|
4378
4435
|
}));
|
|
4379
4436
|
}
|
|
@@ -4422,7 +4479,10 @@ function printParameters(parameters) {
|
|
|
4422
4479
|
return (_b = (_a = parameters === null || parameters === void 0 ? void 0 : parameters.map(it => nameWithType(it, it.isVariadic, it.isOptional))) === null || _a === void 0 ? void 0 : _a.join(", ")) !== null && _b !== void 0 ? _b : "";
|
|
4423
4480
|
}
|
|
4424
4481
|
function printConstructor(idl) {
|
|
4425
|
-
return [
|
|
4482
|
+
return [
|
|
4483
|
+
...printExtendedAttributes(idl),
|
|
4484
|
+
`constructor(${printParameters(idl.parameters)});`
|
|
4485
|
+
];
|
|
4426
4486
|
}
|
|
4427
4487
|
function nameWithType(idl, isVariadic = false, isOptional = false) {
|
|
4428
4488
|
const type = printType(idl.type);
|
|
@@ -4488,6 +4548,7 @@ const attributesToQuote = new Set([
|
|
|
4488
4548
|
IDLExtendedAttributes.DtsTag,
|
|
4489
4549
|
IDLExtendedAttributes.Import,
|
|
4490
4550
|
IDLExtendedAttributes.Interfaces,
|
|
4551
|
+
IDLExtendedAttributes.TraceKey,
|
|
4491
4552
|
IDLExtendedAttributes.TypeArguments,
|
|
4492
4553
|
IDLExtendedAttributes.TypeParameters,
|
|
4493
4554
|
]);
|
|
@@ -4556,10 +4617,17 @@ function printCallback(idl) {
|
|
|
4556
4617
|
`callback ${idl.name} = ${printReturnType(idl.returnType)} (${printParameters(idl.parameters)});`
|
|
4557
4618
|
];
|
|
4558
4619
|
}
|
|
4620
|
+
function printInterfaceInherit(idl) {
|
|
4621
|
+
if (idl.inheritance.length === 0) {
|
|
4622
|
+
return "";
|
|
4623
|
+
}
|
|
4624
|
+
const types = idl.inheritance.map(type => printType(type));
|
|
4625
|
+
return ": " + types.join(', ');
|
|
4626
|
+
}
|
|
4559
4627
|
function printInterface(idl) {
|
|
4560
4628
|
return [
|
|
4561
4629
|
...printExtendedAttributes(idl),
|
|
4562
|
-
`interface ${idl.name}${
|
|
4630
|
+
`interface ${idl.name}${printInterfaceInherit(idl)} {`,
|
|
4563
4631
|
// TODO: type system hack!
|
|
4564
4632
|
]
|
|
4565
4633
|
.concat(printedIndentInc)
|
|
@@ -4571,15 +4639,6 @@ function printInterface(idl) {
|
|
|
4571
4639
|
.concat(printedIndentDec)
|
|
4572
4640
|
.concat(["};"]);
|
|
4573
4641
|
}
|
|
4574
|
-
function getSuperType(idl) {
|
|
4575
|
-
if (!idl.inheritance)
|
|
4576
|
-
return undefined;
|
|
4577
|
-
const parent = idl.inheritance[0];
|
|
4578
|
-
return parent && parent !== IDLTopType ? parent : undefined;
|
|
4579
|
-
}
|
|
4580
|
-
function hasSuperType(idl) {
|
|
4581
|
-
return isDefined(getSuperType(idl));
|
|
4582
|
-
}
|
|
4583
4642
|
function printEnumMember(idl) {
|
|
4584
4643
|
const type = printType(idl.type);
|
|
4585
4644
|
const initializer = idl.initializer === undefined
|
|
@@ -4691,6 +4750,12 @@ function maybeUnwrapOptionalType(type) {
|
|
|
4691
4750
|
}
|
|
4692
4751
|
return type;
|
|
4693
4752
|
}
|
|
4753
|
+
function maybeOptional(type, optional = false) {
|
|
4754
|
+
if (optional) {
|
|
4755
|
+
return createOptionalType(type);
|
|
4756
|
+
}
|
|
4757
|
+
return type;
|
|
4758
|
+
}
|
|
4694
4759
|
const DebugUtils = {
|
|
4695
4760
|
debugPrintType: (type) => {
|
|
4696
4761
|
if (isContainerType(type)) {
|
|
@@ -4699,6 +4764,16 @@ const DebugUtils = {
|
|
|
4699
4764
|
return `[IDLType, name: '${printType(type)}', kind: '${IDLKind[type.kind]}']`;
|
|
4700
4765
|
},
|
|
4701
4766
|
};
|
|
4767
|
+
function asPromise(type) {
|
|
4768
|
+
if (!type)
|
|
4769
|
+
return undefined;
|
|
4770
|
+
if (!isContainerType(type))
|
|
4771
|
+
return undefined;
|
|
4772
|
+
const container = type;
|
|
4773
|
+
if (!IDLContainerUtils.isPromise(container))
|
|
4774
|
+
return undefined;
|
|
4775
|
+
return container;
|
|
4776
|
+
}
|
|
4702
4777
|
function isStringEnum(decl) {
|
|
4703
4778
|
return decl.elements.some(e => e.type === IDLStringType);
|
|
4704
4779
|
}
|
|
@@ -4788,13 +4863,10 @@ function warn(message) {
|
|
|
4788
4863
|
console.log(`WARNING: ${message}`);
|
|
4789
4864
|
}
|
|
4790
4865
|
function forceWriteFile(filePath, content) {
|
|
4791
|
-
path__namespace.dirname(filePath)
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
}
|
|
4796
|
-
return dirPath;
|
|
4797
|
-
}, ".");
|
|
4866
|
+
const dirPath = path__namespace.dirname(filePath);
|
|
4867
|
+
if (!fs__namespace.existsSync(dirPath)) {
|
|
4868
|
+
fs__namespace.mkdirSync(dirPath, { recursive: true });
|
|
4869
|
+
}
|
|
4798
4870
|
fs__namespace.writeFileSync(filePath, content);
|
|
4799
4871
|
}
|
|
4800
4872
|
function rightmostIndexOf(array, predicate) {
|
|
@@ -4834,11 +4906,11 @@ class ValidationBox {
|
|
|
4834
4906
|
success() {
|
|
4835
4907
|
return this.box.success;
|
|
4836
4908
|
}
|
|
4837
|
-
unwrap() {
|
|
4909
|
+
unwrap(message) {
|
|
4838
4910
|
if (this.box.success) {
|
|
4839
4911
|
return this.box.value;
|
|
4840
4912
|
}
|
|
4841
|
-
throw new Error(
|
|
4913
|
+
throw new Error(message !== null && message !== void 0 ? message : 'panic');
|
|
4842
4914
|
}
|
|
4843
4915
|
error() {
|
|
4844
4916
|
if (!this.box.success) {
|
|
@@ -5134,7 +5206,7 @@ const D = {
|
|
|
5134
5206
|
};
|
|
5135
5207
|
});
|
|
5136
5208
|
},
|
|
5137
|
-
null(
|
|
5209
|
+
null() {
|
|
5138
5210
|
return new ConfigDescriberLeaf(xs => {
|
|
5139
5211
|
if (typeof xs === 'object' && xs === null) {
|
|
5140
5212
|
return ValidationBox.ok(null);
|
|
@@ -5202,6 +5274,9 @@ const ModuleConfigurationSchema = D.object({
|
|
|
5202
5274
|
packages: T.stringArray(),
|
|
5203
5275
|
useFoldersLayout: D.maybe(D.boolean()),
|
|
5204
5276
|
});
|
|
5277
|
+
const HookMethodSchema = D.object({
|
|
5278
|
+
hookName: D.string(),
|
|
5279
|
+
});
|
|
5205
5280
|
D.object({
|
|
5206
5281
|
TypePrefix: D.string(),
|
|
5207
5282
|
LibraryPrefix: D.string(),
|
|
@@ -5215,6 +5290,9 @@ D.object({
|
|
|
5215
5290
|
forceCallback: D.map(D.string(), T.stringArray()).onMerge('replace'),
|
|
5216
5291
|
forceResource: T.stringArray(),
|
|
5217
5292
|
forceContext: T.stringArray(),
|
|
5293
|
+
hooks: D.map(D.string(), D.map(D.string(), HookMethodSchema)).onMerge('replace'),
|
|
5294
|
+
externalTypes: D.map(D.string(), D.string()).onMerge('replace'),
|
|
5295
|
+
externalPackages: T.stringArray(),
|
|
5218
5296
|
moduleName: D.string(),
|
|
5219
5297
|
modules: D.map(D.string(), ModuleConfigurationSchema).onMerge('replace'),
|
|
5220
5298
|
globalPackages: T.stringArray()
|
|
@@ -5232,6 +5310,9 @@ const defaultCoreConfiguration = {
|
|
|
5232
5310
|
forceCallback: new Map(),
|
|
5233
5311
|
forceResource: [],
|
|
5234
5312
|
forceContext: [],
|
|
5313
|
+
hooks: new Map(),
|
|
5314
|
+
externalTypes: new Map(),
|
|
5315
|
+
externalPackages: [],
|
|
5235
5316
|
moduleName: "",
|
|
5236
5317
|
modules: new Map(),
|
|
5237
5318
|
globalPackages: []
|
|
@@ -5240,6 +5321,10 @@ let currentConfig = defaultCoreConfiguration;
|
|
|
5240
5321
|
function generatorConfiguration() {
|
|
5241
5322
|
return currentConfig;
|
|
5242
5323
|
}
|
|
5324
|
+
function generatorTypePrefix() {
|
|
5325
|
+
const conf = generatorConfiguration();
|
|
5326
|
+
return `${conf.TypePrefix}${conf.LibraryPrefix}`;
|
|
5327
|
+
}
|
|
5243
5328
|
|
|
5244
5329
|
/*
|
|
5245
5330
|
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
@@ -5495,6 +5580,7 @@ class IndentedPrinter {
|
|
|
5495
5580
|
return this.output;
|
|
5496
5581
|
}
|
|
5497
5582
|
printTo(file) {
|
|
5583
|
+
fs__namespace.mkdirSync(path.dirname(file), { recursive: true });
|
|
5498
5584
|
fs__namespace.writeFileSync(file, this.getOutput().join("\n"));
|
|
5499
5585
|
}
|
|
5500
5586
|
withIndent(prints) {
|
|
@@ -5603,6 +5689,18 @@ class MethodCallExpression extends FunctionCallExpression {
|
|
|
5603
5689
|
return `${this.receiver}${this.nullable ? "?" : ""}.${super.asString()}`;
|
|
5604
5690
|
}
|
|
5605
5691
|
}
|
|
5692
|
+
class MethodStaticCallExpression extends MethodCallExpression {
|
|
5693
|
+
constructor(receiver, method, params, nullable = false) {
|
|
5694
|
+
super(receiver, method, params, nullable);
|
|
5695
|
+
this.receiver = receiver;
|
|
5696
|
+
this.nullable = nullable;
|
|
5697
|
+
}
|
|
5698
|
+
}
|
|
5699
|
+
class ThisCallExpression extends FunctionCallExpression {
|
|
5700
|
+
constructor(params) {
|
|
5701
|
+
super("this", params);
|
|
5702
|
+
}
|
|
5703
|
+
}
|
|
5606
5704
|
class FieldAccessExpression {
|
|
5607
5705
|
constructor(receiver, field, nullable = false) {
|
|
5608
5706
|
this.receiver = receiver;
|
|
@@ -5805,6 +5903,9 @@ class LambdaExpression {
|
|
|
5805
5903
|
stmt.write(writer);
|
|
5806
5904
|
}
|
|
5807
5905
|
}
|
|
5906
|
+
writer.features.forEach(([feature, module]) => {
|
|
5907
|
+
this.originalWriter.addFeature(feature, module);
|
|
5908
|
+
});
|
|
5808
5909
|
return (this.body ? ((_a = this.body) === null || _a === void 0 ? void 0 : _a.length) > 1 ? '\n' : '' : '').concat(writer.getOutput()
|
|
5809
5910
|
.filter(line => line !== "")
|
|
5810
5911
|
.map(line => indentedBy(line.endsWith('{') || line.endsWith('}') || line.endsWith(';') ? line : `${line};`, 1))
|
|
@@ -5842,6 +5943,7 @@ var MethodModifier;
|
|
|
5842
5943
|
MethodModifier[MethodModifier["THROWS"] = 8] = "THROWS";
|
|
5843
5944
|
MethodModifier[MethodModifier["FREE"] = 9] = "FREE";
|
|
5844
5945
|
MethodModifier[MethodModifier["FORCE_CONTEXT"] = 10] = "FORCE_CONTEXT";
|
|
5946
|
+
MethodModifier[MethodModifier["OVERRIDE"] = 11] = "OVERRIDE";
|
|
5845
5947
|
})(MethodModifier || (MethodModifier = {}));
|
|
5846
5948
|
var ClassModifier;
|
|
5847
5949
|
(function (ClassModifier) {
|
|
@@ -5849,6 +5951,11 @@ var ClassModifier;
|
|
|
5849
5951
|
ClassModifier[ClassModifier["PRIVATE"] = 1] = "PRIVATE";
|
|
5850
5952
|
ClassModifier[ClassModifier["PROTECTED"] = 2] = "PROTECTED";
|
|
5851
5953
|
})(ClassModifier || (ClassModifier = {}));
|
|
5954
|
+
var DelegationType;
|
|
5955
|
+
(function (DelegationType) {
|
|
5956
|
+
DelegationType[DelegationType["THIS"] = 0] = "THIS";
|
|
5957
|
+
DelegationType[DelegationType["SUPER"] = 1] = "SUPER";
|
|
5958
|
+
})(DelegationType || (DelegationType = {}));
|
|
5852
5959
|
class Method {
|
|
5853
5960
|
constructor(name, signature, modifiers = undefined, generics) {
|
|
5854
5961
|
this.name = name;
|
|
@@ -5870,6 +5977,7 @@ PrintHint.AsPointer = new PrintHint('AsPointer');
|
|
|
5870
5977
|
PrintHint.AsConstPointer = new PrintHint('AsConstPointer');
|
|
5871
5978
|
PrintHint.AsValue = new PrintHint('AsValue');
|
|
5872
5979
|
PrintHint.AsConstReference = new PrintHint('AsConstReference');
|
|
5980
|
+
PrintHint.AsReference = new PrintHint('AsReference');
|
|
5873
5981
|
class MethodSignature {
|
|
5874
5982
|
constructor(returnType, args, defaults = undefined, argsModifiers = undefined, printHints, argNames) {
|
|
5875
5983
|
this.returnType = returnType;
|
|
@@ -5925,11 +6033,15 @@ class LanguageWriter {
|
|
|
5925
6033
|
this.resolver = resolver;
|
|
5926
6034
|
this.language = language;
|
|
5927
6035
|
this.namespaceStack = [];
|
|
6036
|
+
this.features = [];
|
|
5928
6037
|
}
|
|
5929
6038
|
indentDepth() {
|
|
5930
6039
|
return this.printer.indentDepth();
|
|
5931
6040
|
}
|
|
5932
6041
|
maybeSemicolon() { return ";"; }
|
|
6042
|
+
addFeature(feature, module) {
|
|
6043
|
+
this.features.push([feature, module]);
|
|
6044
|
+
}
|
|
5933
6045
|
// version of makeCast which uses TypeCheck.typeCast<T>(value) call for ETS language writer
|
|
5934
6046
|
// Use it only if TypeChecker class is added as import to the generated file
|
|
5935
6047
|
makeTypeCast(value, type, options) {
|
|
@@ -5956,12 +6068,17 @@ class LanguageWriter {
|
|
|
5956
6068
|
var _a;
|
|
5957
6069
|
this.writeMethodImplementation(new Method(method.name, method.signature, [MethodModifier.SETTER].concat((_a = method.modifiers) !== null && _a !== void 0 ? _a : [])), op);
|
|
5958
6070
|
}
|
|
6071
|
+
// Deprecated
|
|
6072
|
+
// Use instead declarationCall parameter in writeConstructorImplementation(...)
|
|
5959
6073
|
writeSuperCall(params) {
|
|
5960
6074
|
this.printer.print(`super(${params.join(", ")})${this.maybeSemicolon()}`);
|
|
5961
6075
|
}
|
|
5962
6076
|
writeMethodCall(receiver, method, params, nullable = false) {
|
|
5963
6077
|
this.printer.print(`${receiver}${nullable ? "?" : ""}.${method}(${params.join(", ")})`);
|
|
5964
6078
|
}
|
|
6079
|
+
writeStaticMethodCall(receiver, method, params, nullable = false) {
|
|
6080
|
+
this.writeMethodCall(receiver, method, params, nullable);
|
|
6081
|
+
}
|
|
5965
6082
|
writeStatement(stmt) {
|
|
5966
6083
|
stmt.write(this);
|
|
5967
6084
|
}
|
|
@@ -6012,6 +6129,14 @@ class LanguageWriter {
|
|
|
6012
6129
|
makeMethodCall(receiver, method, params, nullable) {
|
|
6013
6130
|
return new MethodCallExpression(receiver, method, params, nullable);
|
|
6014
6131
|
}
|
|
6132
|
+
// Deprecated
|
|
6133
|
+
// Use instead declarationCall parameter in writeConstructorImplementation(...) with DelegationType.THIS
|
|
6134
|
+
makeThisCall(params) {
|
|
6135
|
+
return new ThisCallExpression(params);
|
|
6136
|
+
}
|
|
6137
|
+
makeStaticMethodCall(receiver, method, params, nullable) {
|
|
6138
|
+
return new MethodStaticCallExpression(receiver, method, params, nullable);
|
|
6139
|
+
}
|
|
6015
6140
|
makeFieldAccess(receiver, method, nullable) {
|
|
6016
6141
|
return new FieldAccessExpression(receiver, method, nullable);
|
|
6017
6142
|
}
|
|
@@ -6193,6 +6318,9 @@ class LanguageWriter {
|
|
|
6193
6318
|
makeCallIsObject(value) {
|
|
6194
6319
|
return this.makeString(`typeof ${value} === "object"`);
|
|
6195
6320
|
}
|
|
6321
|
+
makeStaticBlock(op) {
|
|
6322
|
+
op(this);
|
|
6323
|
+
}
|
|
6196
6324
|
instanceOf(convertor, value, _duplicateMembers) {
|
|
6197
6325
|
return this.makeString(`${value} instanceof ${this.getNodeName(convertor.idlType)}`);
|
|
6198
6326
|
}
|
|
@@ -6209,17 +6337,17 @@ class LanguageWriter {
|
|
|
6209
6337
|
* Writes `namespace <namespace> {` and adds extra indent
|
|
6210
6338
|
* @param namespace Namespace to begin
|
|
6211
6339
|
*/
|
|
6212
|
-
pushNamespace(namespace,
|
|
6340
|
+
pushNamespace(namespace, options) {
|
|
6213
6341
|
this.print(`namespace ${namespace} {`);
|
|
6214
|
-
if (ident)
|
|
6342
|
+
if (options.ident)
|
|
6215
6343
|
this.pushIndent();
|
|
6216
6344
|
}
|
|
6217
6345
|
/**
|
|
6218
6346
|
* Writes closing brace of namespace block and removes one level of indent
|
|
6219
6347
|
*/
|
|
6220
|
-
popNamespace(
|
|
6348
|
+
popNamespace(options) {
|
|
6221
6349
|
this.namespaceStack.pop();
|
|
6222
|
-
if (ident)
|
|
6350
|
+
if (options.ident)
|
|
6223
6351
|
this.popIndent();
|
|
6224
6352
|
this.print(`}`);
|
|
6225
6353
|
}
|
|
@@ -6349,6 +6477,27 @@ function convertType(convertor, type) {
|
|
|
6349
6477
|
return convertor.convertPrimitiveType(type);
|
|
6350
6478
|
throw new Error(`Unknown type ${IDLKind[type.kind]}`);
|
|
6351
6479
|
}
|
|
6480
|
+
function convertDeclaration(convertor, decl) {
|
|
6481
|
+
if (isImport(decl))
|
|
6482
|
+
return convertor.convertImport(decl);
|
|
6483
|
+
if (isNamespace(decl))
|
|
6484
|
+
return convertor.convertNamespace(decl);
|
|
6485
|
+
if (isInterface$1(decl))
|
|
6486
|
+
return convertor.convertInterface(decl);
|
|
6487
|
+
if (isEnum$1(decl))
|
|
6488
|
+
return convertor.convertEnum(decl);
|
|
6489
|
+
if (isEnumMember(decl))
|
|
6490
|
+
return convertor.convertEnum(decl.parent);
|
|
6491
|
+
if (isTypedef$1(decl))
|
|
6492
|
+
return convertor.convertTypedef(decl);
|
|
6493
|
+
if (isCallback$1(decl))
|
|
6494
|
+
return convertor.convertCallback(decl);
|
|
6495
|
+
if (isMethod(decl))
|
|
6496
|
+
return convertor.convertMethod(decl);
|
|
6497
|
+
if (isConstant$1(decl))
|
|
6498
|
+
return convertor.convertConstant(decl);
|
|
6499
|
+
throw new Error(`Unknown declaration type ${decl.kind ? IDLKind[decl.kind] : "(undefined kind)"}`);
|
|
6500
|
+
}
|
|
6352
6501
|
|
|
6353
6502
|
/*
|
|
6354
6503
|
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
@@ -6528,6 +6677,11 @@ class CppPointerPropertyAccessExpression {
|
|
|
6528
6677
|
return `${this.expression}->${this.name}`;
|
|
6529
6678
|
}
|
|
6530
6679
|
}
|
|
6680
|
+
class CPPMethodStaticCallExpression extends MethodStaticCallExpression {
|
|
6681
|
+
asString() {
|
|
6682
|
+
return `${this.receiver}::${this.name}(${this.params.map(it => it.asString()).join(', ')})`;
|
|
6683
|
+
}
|
|
6684
|
+
}
|
|
6531
6685
|
////////////////////////////////////////////////////////////////
|
|
6532
6686
|
// STATEMENTS //
|
|
6533
6687
|
////////////////////////////////////////////////////////////////
|
|
@@ -6624,8 +6778,13 @@ class CppLanguageWriter extends CLikeLanguageWriter {
|
|
|
6624
6778
|
constructor(printer, resolver, typeConvertor, primitivesTypes) {
|
|
6625
6779
|
super(printer, resolver, Language.CPP);
|
|
6626
6780
|
this.primitivesTypes = primitivesTypes;
|
|
6781
|
+
this.classMode = 'normal';
|
|
6782
|
+
this.currentClass = [];
|
|
6627
6783
|
this.typeConvertor = typeConvertor;
|
|
6628
6784
|
}
|
|
6785
|
+
changeModeTo(mode) {
|
|
6786
|
+
this.classMode = mode;
|
|
6787
|
+
}
|
|
6629
6788
|
getNodeName(type) {
|
|
6630
6789
|
return this.typeConvertor.convert(type);
|
|
6631
6790
|
}
|
|
@@ -6633,14 +6792,28 @@ class CppLanguageWriter extends CLikeLanguageWriter {
|
|
|
6633
6792
|
var _a;
|
|
6634
6793
|
return new CppLanguageWriter(new IndentedPrinter(), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.primitivesTypes);
|
|
6635
6794
|
}
|
|
6795
|
+
writeDeclaration(name, signature, modifiers, postfix) {
|
|
6796
|
+
const realName = this.classMode === 'normal' ? name : `${this.currentClass.at(0)}::${name}`;
|
|
6797
|
+
const newModifiers = this.classMode === 'normal'
|
|
6798
|
+
? modifiers
|
|
6799
|
+
: (modifiers !== null && modifiers !== void 0 ? modifiers : []).filter(it => it !== MethodModifier.STATIC).concat(MethodModifier.INLINE);
|
|
6800
|
+
super.writeDeclaration(realName, signature, newModifiers, postfix);
|
|
6801
|
+
}
|
|
6636
6802
|
writeClass(name, op, superClass, interfaces) {
|
|
6637
|
-
|
|
6638
|
-
|
|
6639
|
-
|
|
6640
|
-
|
|
6803
|
+
if (this.classMode === 'normal') {
|
|
6804
|
+
const superClasses = (superClass ? [superClass] : []).concat(interfaces !== null && interfaces !== void 0 ? interfaces : []);
|
|
6805
|
+
const extendsClause = superClasses.length > 0 ? ` : ${superClasses.map(c => `public ${c}`).join(", ")}` : '';
|
|
6806
|
+
this.printer.print(`class ${name}${extendsClause} {`);
|
|
6807
|
+
this.pushIndent();
|
|
6808
|
+
}
|
|
6809
|
+
if (this.classMode === 'detached') {
|
|
6810
|
+
this.currentClass.push(name);
|
|
6811
|
+
}
|
|
6641
6812
|
op(this);
|
|
6642
|
-
this.
|
|
6643
|
-
|
|
6813
|
+
if (this.classMode === 'normal') {
|
|
6814
|
+
this.popIndent();
|
|
6815
|
+
this.printer.print(`};`);
|
|
6816
|
+
}
|
|
6644
6817
|
}
|
|
6645
6818
|
writeInterface(name, op, superInterfaces, generics) {
|
|
6646
6819
|
throw new Error("Method not implemented.");
|
|
@@ -6653,6 +6826,9 @@ class CppLanguageWriter extends CLikeLanguageWriter {
|
|
|
6653
6826
|
super.writeMethodCall(receiver, method, params, nullable);
|
|
6654
6827
|
}
|
|
6655
6828
|
}
|
|
6829
|
+
writeStaticMethodCall(receiver, method, params, nullable) {
|
|
6830
|
+
this.printer.print(`${receiver}::${method}(${params.join(', ')});`);
|
|
6831
|
+
}
|
|
6656
6832
|
writeFieldDeclaration(name, type, modifiers, optional, initExpr) {
|
|
6657
6833
|
let filter = function (modifier_name) {
|
|
6658
6834
|
return modifier_name !== FieldModifier.STATIC;
|
|
@@ -6663,9 +6839,9 @@ class CppLanguageWriter extends CLikeLanguageWriter {
|
|
|
6663
6839
|
this.printer.print(`${forceAsNamedNode(type).name} ${name};`);
|
|
6664
6840
|
this.printer.popIndent();
|
|
6665
6841
|
}
|
|
6666
|
-
writeConstructorImplementation(className, signature, op,
|
|
6667
|
-
const superInvocation =
|
|
6668
|
-
? ` : ${
|
|
6842
|
+
writeConstructorImplementation(className, signature, op, delegationCall, modifiers) {
|
|
6843
|
+
const superInvocation = delegationCall
|
|
6844
|
+
? ` : ${delegationCall.delegationName}(${delegationCall.delegationArgs.map(it => it.asString()).join(", ")})`
|
|
6669
6845
|
: "";
|
|
6670
6846
|
const argList = signature.args.map((it, index) => {
|
|
6671
6847
|
var _a;
|
|
@@ -6755,6 +6931,9 @@ class CppLanguageWriter extends CLikeLanguageWriter {
|
|
|
6755
6931
|
makeUnionVariantCast(value, type, convertor, index) {
|
|
6756
6932
|
return this.makeString(`${value}.value${index}`);
|
|
6757
6933
|
}
|
|
6934
|
+
makeStaticMethodCall(receiver, method, params, nullable) {
|
|
6935
|
+
return new CPPMethodStaticCallExpression(receiver, method, params, nullable);
|
|
6936
|
+
}
|
|
6758
6937
|
makeLoop(counter, limit, statement) {
|
|
6759
6938
|
return new CLikeLoopStatement(counter, limit, statement);
|
|
6760
6939
|
}
|
|
@@ -6895,6 +7074,9 @@ class CppLanguageWriter extends CLikeLanguageWriter {
|
|
|
6895
7074
|
case PrintHint.AsPointer:
|
|
6896
7075
|
postfix = '*';
|
|
6897
7076
|
break;
|
|
7077
|
+
case PrintHint.AsReference:
|
|
7078
|
+
postfix = '&';
|
|
7079
|
+
break;
|
|
6898
7080
|
case PrintHint.AsConstPointer:
|
|
6899
7081
|
constModifier = 'const ';
|
|
6900
7082
|
postfix = '*';
|
|
@@ -7046,10 +7228,11 @@ class TSLanguageWriter extends LanguageWriter {
|
|
|
7046
7228
|
this.typeConvertor = typeConvertor;
|
|
7047
7229
|
}
|
|
7048
7230
|
maybeSemicolon() { return ""; }
|
|
7049
|
-
pushNamespace(namespace,
|
|
7231
|
+
pushNamespace(namespace, options) {
|
|
7050
7232
|
this.namespaceStack.push(namespace);
|
|
7051
|
-
|
|
7052
|
-
|
|
7233
|
+
const declaredPrefix = options.isDeclared ? "declare " : "";
|
|
7234
|
+
this.print(`export ${declaredPrefix}namespace ${namespace} {`);
|
|
7235
|
+
if (options.ident)
|
|
7053
7236
|
this.pushIndent();
|
|
7054
7237
|
}
|
|
7055
7238
|
fork(options) {
|
|
@@ -7087,24 +7270,25 @@ class TSLanguageWriter extends LanguageWriter {
|
|
|
7087
7270
|
this.popIndent();
|
|
7088
7271
|
this.printer.print(`}`);
|
|
7089
7272
|
}
|
|
7090
|
-
writeFunctionDeclaration(name, signature) {
|
|
7091
|
-
this.printer.print(this.generateFunctionDeclaration(name, signature));
|
|
7273
|
+
writeFunctionDeclaration(name, signature, generics) {
|
|
7274
|
+
this.printer.print(this.generateFunctionDeclaration(name, signature, generics));
|
|
7092
7275
|
}
|
|
7093
|
-
writeFunctionImplementation(name, signature, op) {
|
|
7094
|
-
this.printer.print(`${this.generateFunctionDeclaration(name, signature)} {`);
|
|
7276
|
+
writeFunctionImplementation(name, signature, op, generics) {
|
|
7277
|
+
this.printer.print(`${this.generateFunctionDeclaration(name, signature, generics)} {`);
|
|
7095
7278
|
this.printer.pushIndent();
|
|
7096
7279
|
op(this);
|
|
7097
7280
|
this.printer.popIndent();
|
|
7098
7281
|
this.printer.print('}');
|
|
7099
7282
|
}
|
|
7100
|
-
generateFunctionDeclaration(name, signature) {
|
|
7283
|
+
generateFunctionDeclaration(name, signature, generics) {
|
|
7101
7284
|
const rightmostRegularParameterIndex = rightmostIndexOf(signature.args, it => !isOptionalType(it));
|
|
7102
7285
|
const args = signature.args.map((it, index) => {
|
|
7103
7286
|
const optionalToken = isOptionalType(it) && index > rightmostRegularParameterIndex ? '?' : '';
|
|
7104
7287
|
return `${signature.argName(index)}${optionalToken}: ${this.getNodeName(it)}`;
|
|
7105
7288
|
});
|
|
7106
7289
|
const returnType = this.getNodeName(signature.returnType);
|
|
7107
|
-
|
|
7290
|
+
const typeParams = generics && generics.length ? '<' + (generics === null || generics === void 0 ? void 0 : generics.join(', ')) + '>' : '';
|
|
7291
|
+
return `export function ${name}${typeParams}(${args.join(", ")}): ${returnType}`;
|
|
7108
7292
|
}
|
|
7109
7293
|
writeEnum(name, members, options) {
|
|
7110
7294
|
this.printer.print(`${options.isExport ? "export " : ""}${options.isDeclare ? "declare " : ""}enum ${name} {`);
|
|
@@ -7144,11 +7328,13 @@ class TSLanguageWriter extends LanguageWriter {
|
|
|
7144
7328
|
writeMethodDeclaration(name, signature, modifiers) {
|
|
7145
7329
|
this.writeDeclaration(name, signature, true, false, modifiers);
|
|
7146
7330
|
}
|
|
7147
|
-
writeConstructorImplementation(className, signature, op,
|
|
7331
|
+
writeConstructorImplementation(className, signature, op, delegationCall, modifiers) {
|
|
7332
|
+
var _a;
|
|
7148
7333
|
this.writeDeclaration(`${modifiers ? modifiers.map((it) => MethodModifier[it].toLowerCase()).join(' ') + ' ' : ''}constructor`, signature, false, true);
|
|
7149
7334
|
this.pushIndent();
|
|
7150
|
-
if (
|
|
7151
|
-
|
|
7335
|
+
if (delegationCall) {
|
|
7336
|
+
const delegationType = ((delegationCall === null || delegationCall === void 0 ? void 0 : delegationCall.delegationType) == DelegationType.THIS) ? "this" : "super";
|
|
7337
|
+
this.print(`${delegationType}(${(_a = delegationCall.delegationArgs) === null || _a === void 0 ? void 0 : _a.map(it => it.asString()).join(", ")})`);
|
|
7152
7338
|
}
|
|
7153
7339
|
op(this);
|
|
7154
7340
|
this.popIndent();
|
|
@@ -7365,31 +7551,91 @@ class TSLanguageWriter extends LanguageWriter {
|
|
|
7365
7551
|
* See the License for the specific language governing permissions and
|
|
7366
7552
|
* limitations under the License.
|
|
7367
7553
|
*/
|
|
7368
|
-
|
|
7369
|
-
(
|
|
7370
|
-
|
|
7371
|
-
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
7375
|
-
|
|
7376
|
-
|
|
7377
|
-
|
|
7378
|
-
|
|
7379
|
-
|
|
7554
|
+
class DeclarationNameConvertor {
|
|
7555
|
+
convertImport(decl) {
|
|
7556
|
+
console.warn("Imports are not implemented yet");
|
|
7557
|
+
return decl.name;
|
|
7558
|
+
}
|
|
7559
|
+
convertInterface(decl) {
|
|
7560
|
+
return decl.name;
|
|
7561
|
+
}
|
|
7562
|
+
convertEnum(decl) {
|
|
7563
|
+
return `${getNamespacesPathFor(decl).join('')}${decl.name}`;
|
|
7564
|
+
}
|
|
7565
|
+
convertTypedef(decl) {
|
|
7566
|
+
return decl.name;
|
|
7567
|
+
}
|
|
7568
|
+
convertCallback(decl) {
|
|
7569
|
+
var _a;
|
|
7570
|
+
return (_a = decl.name) !== null && _a !== void 0 ? _a : "MISSING CALLBACK NAME";
|
|
7571
|
+
}
|
|
7572
|
+
convertNamespace(node) {
|
|
7573
|
+
return node.name;
|
|
7574
|
+
}
|
|
7575
|
+
convertMethod(node) {
|
|
7576
|
+
return node.name;
|
|
7577
|
+
}
|
|
7578
|
+
convertConstant(node) {
|
|
7579
|
+
return node.name;
|
|
7580
|
+
}
|
|
7380
7581
|
}
|
|
7381
|
-
|
|
7382
|
-
|
|
7383
|
-
|
|
7384
|
-
|
|
7385
|
-
|
|
7386
|
-
|
|
7582
|
+
DeclarationNameConvertor.I = new DeclarationNameConvertor();
|
|
7583
|
+
class TSFeatureNameConvertor extends DeclarationNameConvertor {
|
|
7584
|
+
convertEnum(decl) {
|
|
7585
|
+
const namespace = getNamespacesPathFor(decl).map(it => it.name);
|
|
7586
|
+
if (namespace.length > 0)
|
|
7587
|
+
return namespace[0];
|
|
7588
|
+
return decl.name;
|
|
7589
|
+
}
|
|
7387
7590
|
}
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7591
|
+
TSFeatureNameConvertor.I = new TSFeatureNameConvertor();
|
|
7592
|
+
class ETSDeclarationNameConvertor extends DeclarationNameConvertor {
|
|
7593
|
+
convertInterface(decl) {
|
|
7594
|
+
return getQualifiedName(decl, "namespace.name");
|
|
7595
|
+
}
|
|
7596
|
+
convertEnum(decl) {
|
|
7597
|
+
return getQualifiedName(decl, "namespace.name");
|
|
7598
|
+
}
|
|
7599
|
+
}
|
|
7600
|
+
ETSDeclarationNameConvertor.I = new ETSDeclarationNameConvertor();
|
|
7601
|
+
class CJDeclarationNameConvertor extends DeclarationNameConvertor {
|
|
7602
|
+
convertInterface(decl) {
|
|
7603
|
+
return decl.name;
|
|
7604
|
+
}
|
|
7605
|
+
convertEnum(decl) {
|
|
7606
|
+
return decl.name;
|
|
7607
|
+
}
|
|
7608
|
+
}
|
|
7609
|
+
CJDeclarationNameConvertor.I = new CJDeclarationNameConvertor();
|
|
7610
|
+
class ETSFeatureNameConvertor extends DeclarationNameConvertor {
|
|
7611
|
+
convertEnum(decl) {
|
|
7612
|
+
const namespace = getNamespacesPathFor(decl).map(it => it.name);
|
|
7613
|
+
if (namespace.length > 0)
|
|
7614
|
+
return namespace[0];
|
|
7615
|
+
return decl.name;
|
|
7616
|
+
}
|
|
7617
|
+
}
|
|
7618
|
+
ETSFeatureNameConvertor.I = new ETSFeatureNameConvertor();
|
|
7619
|
+
class CJFeatureNameConvertor extends DeclarationNameConvertor {
|
|
7620
|
+
convertEnum(decl) {
|
|
7621
|
+
return decl.name;
|
|
7622
|
+
}
|
|
7623
|
+
}
|
|
7624
|
+
CJFeatureNameConvertor.I = new CJFeatureNameConvertor();
|
|
7625
|
+
class KotlinFeatureNameConvertor extends DeclarationNameConvertor {
|
|
7626
|
+
convertEnum(decl) {
|
|
7627
|
+
return decl.name;
|
|
7628
|
+
}
|
|
7629
|
+
}
|
|
7630
|
+
KotlinFeatureNameConvertor.I = new KotlinFeatureNameConvertor();
|
|
7631
|
+
function createDeclarationNameConvertor(language) {
|
|
7632
|
+
switch (language) {
|
|
7633
|
+
case Language.ARKTS: return ETSDeclarationNameConvertor.I;
|
|
7634
|
+
case Language.JAVA:
|
|
7635
|
+
case Language.CPP:
|
|
7636
|
+
case Language.TS: return DeclarationNameConvertor.I;
|
|
7637
|
+
case Language.CJ: default: throw new Error(`Language ${language.toString()} is not supported`);
|
|
7638
|
+
}
|
|
7393
7639
|
}
|
|
7394
7640
|
|
|
7395
7641
|
/*
|
|
@@ -7406,84 +7652,1134 @@ function isInCurrentModule(nodeOrPackage) {
|
|
|
7406
7652
|
* See the License for the specific language governing permissions and
|
|
7407
7653
|
* limitations under the License.
|
|
7408
7654
|
*/
|
|
7409
|
-
|
|
7410
|
-
|
|
7411
|
-
|
|
7412
|
-
|
|
7413
|
-
|
|
7414
|
-
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
}
|
|
7427
|
-
if (isConstant$1(node)) {
|
|
7428
|
-
line.constants.push(node);
|
|
7429
|
-
}
|
|
7430
|
-
if (isMethod(node)) {
|
|
7431
|
-
line.methods.push(node);
|
|
7432
|
-
}
|
|
7433
|
-
});
|
|
7434
|
-
if (line.constants.length || line.methods.length) {
|
|
7435
|
-
result.push(line);
|
|
7436
|
-
}
|
|
7655
|
+
////////////////////////////////////////////////////////////////
|
|
7656
|
+
// STATEMENTS //
|
|
7657
|
+
////////////////////////////////////////////////////////////////
|
|
7658
|
+
class EtsAssignStatement {
|
|
7659
|
+
constructor(variableName, type, expression, isDeclared = true, isConst = true) {
|
|
7660
|
+
this.variableName = variableName;
|
|
7661
|
+
this.type = type;
|
|
7662
|
+
this.expression = expression;
|
|
7663
|
+
this.isDeclared = isDeclared;
|
|
7664
|
+
this.isConst = isConst;
|
|
7665
|
+
}
|
|
7666
|
+
write(writer) {
|
|
7667
|
+
if (this.isDeclared) {
|
|
7668
|
+
const typeClause = this.type !== undefined ? `: ${writer.getNodeName(this.type)}` : '';
|
|
7669
|
+
const maybeAssign = this.expression !== undefined ? " = " : "";
|
|
7670
|
+
const initValue = this.expression !== undefined ? this.expression : writer.makeString("");
|
|
7671
|
+
writer.print(`${this.isConst ? "const" : "let"} ${this.variableName} ${typeClause}${maybeAssign}${initValue.asString()}`);
|
|
7437
7672
|
}
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
}
|
|
7441
|
-
|
|
7442
|
-
var IDLValidationDiagnosticsCode;
|
|
7443
|
-
(function (IDLValidationDiagnosticsCode) {
|
|
7444
|
-
IDLValidationDiagnosticsCode[IDLValidationDiagnosticsCode["INVALID_EXTENDED_ATTRIBUTE"] = 1000] = "INVALID_EXTENDED_ATTRIBUTE";
|
|
7445
|
-
IDLValidationDiagnosticsCode[IDLValidationDiagnosticsCode["ENUM_IS_NOT_CONSISTENT"] = 1001] = "ENUM_IS_NOT_CONSISTENT";
|
|
7446
|
-
IDLValidationDiagnosticsCode[IDLValidationDiagnosticsCode["REFERENCE_IS_NOT_RESOLVED"] = 1002] = "REFERENCE_IS_NOT_RESOLVED";
|
|
7447
|
-
})(IDLValidationDiagnosticsCode || (IDLValidationDiagnosticsCode = {}));
|
|
7448
|
-
({
|
|
7449
|
-
[IDLValidationDiagnosticsCode.INVALID_EXTENDED_ATTRIBUTE]: "Invalid extended attribute",
|
|
7450
|
-
[IDLValidationDiagnosticsCode.ENUM_IS_NOT_CONSISTENT]: "Enum includes both string and number values",
|
|
7451
|
-
[IDLValidationDiagnosticsCode.REFERENCE_IS_NOT_RESOLVED]: "Can not resolve reference",
|
|
7452
|
-
});
|
|
7453
|
-
[
|
|
7454
|
-
IDLTopType.name,
|
|
7455
|
-
IDLObjectType.name,
|
|
7456
|
-
];
|
|
7457
|
-
|
|
7458
|
-
/*
|
|
7459
|
-
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
7460
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7461
|
-
* you may not use this file except in compliance with the License.
|
|
7462
|
-
* You may obtain a copy of the License at
|
|
7463
|
-
*
|
|
7464
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7465
|
-
*
|
|
7466
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
7467
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7468
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7469
|
-
* See the License for the specific language governing permissions and
|
|
7470
|
-
* limitations under the License.
|
|
7471
|
-
*/
|
|
7472
|
-
function isEnum(node) {
|
|
7473
|
-
return node.type === "enum";
|
|
7474
|
-
}
|
|
7475
|
-
function isInterface(node) {
|
|
7476
|
-
return node.type === "interface";
|
|
7673
|
+
else {
|
|
7674
|
+
writer.print(`${this.variableName} = ${this.expression.asString()}`);
|
|
7675
|
+
}
|
|
7676
|
+
}
|
|
7477
7677
|
}
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7678
|
+
class ArkTSMapForEachStatement {
|
|
7679
|
+
constructor(map, key, value, op) {
|
|
7680
|
+
this.map = map;
|
|
7681
|
+
this.key = key;
|
|
7682
|
+
this.value = value;
|
|
7683
|
+
this.op = op;
|
|
7684
|
+
}
|
|
7685
|
+
write(writer) {
|
|
7686
|
+
writer.print(`for (const pair of ${this.map}) {`);
|
|
7687
|
+
writer.pushIndent();
|
|
7688
|
+
writer.print(`const ${this.key} = pair[0]`);
|
|
7689
|
+
writer.print(`const ${this.value} = pair[1]`);
|
|
7690
|
+
this.op();
|
|
7691
|
+
writer.popIndent();
|
|
7692
|
+
writer.print(`}`);
|
|
7693
|
+
}
|
|
7482
7694
|
}
|
|
7483
|
-
|
|
7484
|
-
|
|
7695
|
+
class ArkTSEnumEntityStatement {
|
|
7696
|
+
constructor(enumEntity, options) {
|
|
7697
|
+
this.enumEntity = enumEntity;
|
|
7698
|
+
this.options = options;
|
|
7699
|
+
}
|
|
7700
|
+
write(writer) {
|
|
7701
|
+
let enumName = convertDeclaration(createDeclarationNameConvertor(Language.ARKTS), this.enumEntity);
|
|
7702
|
+
enumName = enumName.split('.').at(-1);
|
|
7703
|
+
const members = this.enumEntity.elements
|
|
7704
|
+
.flatMap((member, index) => {
|
|
7705
|
+
var _a;
|
|
7706
|
+
const initText = (_a = member.initializer) !== null && _a !== void 0 ? _a : index;
|
|
7707
|
+
const isTypeString = typeof initText !== "number";
|
|
7708
|
+
const originalName = getExtAttribute(member, IDLExtendedAttributes.OriginalEnumMemberName);
|
|
7709
|
+
const res = [{
|
|
7710
|
+
name: member.name,
|
|
7711
|
+
alias: undefined,
|
|
7712
|
+
stringId: isTypeString ? initText : undefined,
|
|
7713
|
+
numberId: initText
|
|
7714
|
+
}];
|
|
7715
|
+
if (originalName !== undefined) {
|
|
7716
|
+
res.push({
|
|
7717
|
+
name: originalName,
|
|
7718
|
+
alias: undefined,
|
|
7719
|
+
stringId: isTypeString ? initText : undefined,
|
|
7720
|
+
numberId: initText
|
|
7721
|
+
});
|
|
7722
|
+
//TODO: enums do not support member aliases
|
|
7723
|
+
// res.push({
|
|
7724
|
+
// name: originalName,
|
|
7725
|
+
// alias: member.name,
|
|
7726
|
+
// stringId: undefined,
|
|
7727
|
+
// numberId: initText as number
|
|
7728
|
+
// })
|
|
7729
|
+
}
|
|
7730
|
+
return res;
|
|
7731
|
+
});
|
|
7732
|
+
writer.writeEnum(enumName, members, { isExport: this.options.isExport, isDeclare: this.options.isDeclare });
|
|
7733
|
+
}
|
|
7485
7734
|
}
|
|
7486
|
-
|
|
7735
|
+
class ETSLambdaExpression extends LambdaExpression {
|
|
7736
|
+
constructor(writer, convertor, signature, resolver, body) {
|
|
7737
|
+
super(writer, signature, resolver, body);
|
|
7738
|
+
this.convertor = convertor;
|
|
7739
|
+
}
|
|
7740
|
+
get statementHasSemicolon() {
|
|
7741
|
+
return false;
|
|
7742
|
+
}
|
|
7743
|
+
asString() {
|
|
7744
|
+
const params = this.signature.args.map((it, i) => {
|
|
7745
|
+
const maybeOptional = isOptionalType(it) ? "?" : "";
|
|
7746
|
+
return `${this.signature.argName(i)}${maybeOptional}: ${this.convertor.convert(it)}`;
|
|
7747
|
+
});
|
|
7748
|
+
// Workaround to fix ArkTS error: SyntaxError: Unexpected token, arrow (=>)
|
|
7749
|
+
// Issue: https://rnd-gitlab-msc.huawei.com/rus-os-team/virtual-machines-and-tools/panda/-/issues/21333
|
|
7750
|
+
let isRetTypeCallback = isCallback$1(this.signature.returnType);
|
|
7751
|
+
if (isReferenceType(this.signature.returnType)) {
|
|
7752
|
+
const resolved = this.resolver.resolveTypeReference(this.signature.returnType);
|
|
7753
|
+
isRetTypeCallback = resolved !== undefined && isCallback$1(resolved);
|
|
7754
|
+
}
|
|
7755
|
+
return `(${params.join(", ")})${isRetTypeCallback
|
|
7756
|
+
? "" : `:${this.convertor.convert(this.signature.returnType)}`} => { ${this.bodyAsString()} }`;
|
|
7757
|
+
}
|
|
7758
|
+
}
|
|
7759
|
+
////////////////////////////////////////////////////////////////
|
|
7760
|
+
// UTILS //
|
|
7761
|
+
////////////////////////////////////////////////////////////////
|
|
7762
|
+
function generateTypeCheckerName(typeName) {
|
|
7763
|
+
typeName = typeName
|
|
7764
|
+
.replaceAll('[]', 'BracketsArray')
|
|
7765
|
+
.split('.').join('_');
|
|
7766
|
+
return `is${typeName.replaceAll('[]', 'Brackets')}`;
|
|
7767
|
+
}
|
|
7768
|
+
function generateEnumToNumericName(entry) {
|
|
7769
|
+
const typeName = getQualifiedName(entry, "namespace.name").split('.').join('_');
|
|
7770
|
+
return `${typeName}_ToNumeric`;
|
|
7771
|
+
}
|
|
7772
|
+
function generateEnumFromNumericName(entry) {
|
|
7773
|
+
const typeName = getQualifiedName(entry, "namespace.name").split('.').join('_');
|
|
7774
|
+
return `${typeName}_FromNumeric`;
|
|
7775
|
+
}
|
|
7776
|
+
function makeArrayTypeCheckCall(valueAccessor, typeName, writer) {
|
|
7777
|
+
return writer.makeMethodCall("TypeChecker", generateTypeCheckerName(typeName), [writer.makeString(valueAccessor)
|
|
7778
|
+
]);
|
|
7779
|
+
}
|
|
7780
|
+
////////////////////////////////////////////////////////////////
|
|
7781
|
+
// WRITER //
|
|
7782
|
+
////////////////////////////////////////////////////////////////
|
|
7783
|
+
class ETSLanguageWriter extends TSLanguageWriter {
|
|
7784
|
+
constructor(printer, resolver, typeConvertor, arrayConvertor) {
|
|
7785
|
+
super(printer, resolver, typeConvertor, Language.ARKTS);
|
|
7786
|
+
this.arrayConvertor = arrayConvertor;
|
|
7787
|
+
}
|
|
7788
|
+
fork(options) {
|
|
7789
|
+
var _a;
|
|
7790
|
+
return new ETSLanguageWriter(new IndentedPrinter(), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.arrayConvertor);
|
|
7791
|
+
}
|
|
7792
|
+
makeAssign(variableName, type, expr, isDeclared = true, isConst = true) {
|
|
7793
|
+
return new EtsAssignStatement(variableName, type, expr, isDeclared, isConst);
|
|
7794
|
+
}
|
|
7795
|
+
makeLambda(signature, body) {
|
|
7796
|
+
return new ETSLambdaExpression(this, this.typeConvertor, signature, this.resolver, body);
|
|
7797
|
+
}
|
|
7798
|
+
makeMapForEach(map, key, value, op) {
|
|
7799
|
+
return new ArkTSMapForEachStatement(map, key, value, op);
|
|
7800
|
+
}
|
|
7801
|
+
makeMapSize(map) {
|
|
7802
|
+
return this.makeString(`${super.makeMapSize(map).asString()}`); // TODO: cast really needed?
|
|
7803
|
+
}
|
|
7804
|
+
get supportedModifiers() {
|
|
7805
|
+
return [MethodModifier.PUBLIC, MethodModifier.PRIVATE, MethodModifier.NATIVE, MethodModifier.STATIC];
|
|
7806
|
+
}
|
|
7807
|
+
runtimeType(param, valueType, value) {
|
|
7808
|
+
super.runtimeType(param, valueType, value);
|
|
7809
|
+
}
|
|
7810
|
+
makeUnionVariantCast(value, type, convertor, index) {
|
|
7811
|
+
return this.makeString(`${value} as ${type}`);
|
|
7812
|
+
}
|
|
7813
|
+
i32FromEnum(value, enumEntry) {
|
|
7814
|
+
if (ETSLanguageWriter.isUseTypeChecker) {
|
|
7815
|
+
return this.makeMethodCall('TypeChecker', generateEnumToNumericName(enumEntry), [value]);
|
|
7816
|
+
}
|
|
7817
|
+
return isStringEnum(enumEntry)
|
|
7818
|
+
? this.makeMethodCall(value.asString(), 'getOrdinal', [])
|
|
7819
|
+
: this.makeMethodCall(value.asString(), 'valueOf', []);
|
|
7820
|
+
}
|
|
7821
|
+
enumFromI32(value, enumEntry) {
|
|
7822
|
+
const enumName = this.getNodeName(enumEntry);
|
|
7823
|
+
if (ETSLanguageWriter.isUseTypeChecker) {
|
|
7824
|
+
return this.makeMethodCall('TypeChecker', generateEnumFromNumericName(enumEntry), [value]);
|
|
7825
|
+
}
|
|
7826
|
+
return isStringEnum(enumEntry)
|
|
7827
|
+
? this.makeString(`${enumName}.values()[${value.asString()}]`)
|
|
7828
|
+
: this.makeMethodCall(enumName, 'fromValue', [value]);
|
|
7829
|
+
}
|
|
7830
|
+
makeDiscriminatorFromFields(convertor, value, accessors, duplicates) {
|
|
7831
|
+
if (convertor instanceof AggregateConvertor
|
|
7832
|
+
|| convertor instanceof InterfaceConvertor
|
|
7833
|
+
|| convertor instanceof MaterializedClassConvertor
|
|
7834
|
+
|| convertor instanceof CustomTypeConvertor) {
|
|
7835
|
+
return this.instanceOf(convertor, value, duplicates);
|
|
7836
|
+
}
|
|
7837
|
+
return this.makeString(`${value} instanceof ${convertor.targetType(this)}`);
|
|
7838
|
+
}
|
|
7839
|
+
makeValueFromOption(value, destinationConvertor) {
|
|
7840
|
+
if (isEnum$1(this.resolver.toDeclaration(destinationConvertor.nativeType()))) {
|
|
7841
|
+
return this.makeCast(this.makeString(value), destinationConvertor.idlType);
|
|
7842
|
+
}
|
|
7843
|
+
return super.makeValueFromOption(value, destinationConvertor);
|
|
7844
|
+
}
|
|
7845
|
+
makeIsTypeCall(value, decl) {
|
|
7846
|
+
return makeInterfaceTypeCheckerCall(value, decl.name, decl.properties.map(it => it.name), new Set(), this);
|
|
7847
|
+
}
|
|
7848
|
+
makeEnumEntity(enumEntity, options) {
|
|
7849
|
+
return new ArkTSEnumEntityStatement(enumEntity, {
|
|
7850
|
+
isExport: options === null || options === void 0 ? void 0 : options.isExport,
|
|
7851
|
+
isDeclare: !!(options === null || options === void 0 ? void 0 : options.isDeclare),
|
|
7852
|
+
});
|
|
7853
|
+
}
|
|
7854
|
+
getObjectAccessor(convertor, value, args) {
|
|
7855
|
+
return super.getObjectAccessor(convertor, value, args);
|
|
7856
|
+
}
|
|
7857
|
+
writeMethodCall(receiver, method, params, nullable = false) {
|
|
7858
|
+
// ArkTS does not support - 'this.?'
|
|
7859
|
+
super.writeMethodCall(receiver, method, params, nullable && receiver !== "this");
|
|
7860
|
+
}
|
|
7861
|
+
isQuickType(type) {
|
|
7862
|
+
return asPromise(type) == undefined;
|
|
7863
|
+
}
|
|
7864
|
+
writeNativeMethodDeclaration(method) {
|
|
7865
|
+
if (method.signature.returnType === IDLThisType) {
|
|
7866
|
+
throw new Error('static method can not return this!');
|
|
7867
|
+
}
|
|
7868
|
+
this.writeMethodDeclaration(method.name, method.signature, [MethodModifier.STATIC, MethodModifier.NATIVE]);
|
|
7869
|
+
}
|
|
7870
|
+
makeUnionVariantCondition(convertor, valueName, valueType, type, convertorIndex, runtimeTypeIndex) {
|
|
7871
|
+
if (isEnum$1(this.resolver.toDeclaration(convertor.nativeType()))) {
|
|
7872
|
+
return this.instanceOf(convertor, valueName);
|
|
7873
|
+
}
|
|
7874
|
+
// TODO: in ArkTS SerializerBase.runtimeType returns RuntimeType.OBJECT for enum type and not RuntimeType.NUMBER as in TS
|
|
7875
|
+
if (convertor instanceof UnionConvertor || convertor instanceof OptionConvertor) {
|
|
7876
|
+
// Unwrapping of type
|
|
7877
|
+
const idlType = convertor instanceof UnionConvertor
|
|
7878
|
+
? convertor.nativeType().types[runtimeTypeIndex]
|
|
7879
|
+
: maybeUnwrapOptionalType(convertor.nativeType());
|
|
7880
|
+
if (idlType !== undefined && isReferenceType(idlType)) {
|
|
7881
|
+
const resolved = this.resolver.resolveTypeReference(idlType);
|
|
7882
|
+
type = resolved != undefined && isEnum$1(resolved) ? RuntimeType[RuntimeType.OBJECT] : type;
|
|
7883
|
+
}
|
|
7884
|
+
}
|
|
7885
|
+
return super.makeUnionVariantCondition(convertor, valueName, valueType, type, convertorIndex);
|
|
7886
|
+
}
|
|
7887
|
+
makeCastCustomObject(customName, isGenericType) {
|
|
7888
|
+
if (isGenericType) {
|
|
7889
|
+
return this.makeCast(this.makeString(customName), IDLObjectType);
|
|
7890
|
+
}
|
|
7891
|
+
return super.makeCastCustomObject(customName, isGenericType);
|
|
7892
|
+
}
|
|
7893
|
+
makeHasOwnProperty(value, valueTypeName, property, propertyTypeName) {
|
|
7894
|
+
return this.makeNaryOp("&&", [
|
|
7895
|
+
this.makeString(`${value} instanceof ${valueTypeName}`),
|
|
7896
|
+
this.makeString(`isInstanceOf("${propertyTypeName}", ${value}.${property})`)
|
|
7897
|
+
]);
|
|
7898
|
+
}
|
|
7899
|
+
makeEquals(args) {
|
|
7900
|
+
// TODO: Error elimination: 'TypeError: Both operands have to be reference types'
|
|
7901
|
+
// the '==' operator must be used when one of the operands is a reference
|
|
7902
|
+
return super.makeNaryOp('==', args);
|
|
7903
|
+
}
|
|
7904
|
+
makeDiscriminatorConvertor(convertor, value, index) {
|
|
7905
|
+
return this.instanceOf(convertor, value);
|
|
7906
|
+
// Or this ????????
|
|
7907
|
+
// return this.discriminatorFromExpressions(value, RuntimeType.OBJECT, [
|
|
7908
|
+
// makeEnumTypeCheckerCall(value, this.getNodeName(convertor.idlType), this)
|
|
7909
|
+
// ])
|
|
7910
|
+
}
|
|
7911
|
+
castToInt(value, bitness) {
|
|
7912
|
+
// This fix is used to avoid unnecessary writeInt8(value as int32) call, which is generated if value is already an int32
|
|
7913
|
+
// The explicit cast forces ui2abc to call valueOf on an int, which fails the compilation
|
|
7914
|
+
// TODO Fix this cast
|
|
7915
|
+
if (bitness === 8)
|
|
7916
|
+
return `(${value}).toChar()`;
|
|
7917
|
+
return `(${value}).toInt()`; // FIXME: is there int8 in ARKTS?
|
|
7918
|
+
}
|
|
7919
|
+
castToBoolean(value) { return `${value} ? 1 : 0`; }
|
|
7920
|
+
instanceOf(convertor, value, duplicateMembers) {
|
|
7921
|
+
if (convertor instanceof CustomTypeConvertor) {
|
|
7922
|
+
return makeInterfaceTypeCheckerCall(value, this.getNodeName(convertor.idlType), [], duplicateMembers, this);
|
|
7923
|
+
}
|
|
7924
|
+
if (convertor instanceof InterfaceConvertor || convertor instanceof MaterializedClassConvertor) {
|
|
7925
|
+
return makeInterfaceTypeCheckerCall(value, this.getNodeName(convertor.idlType), convertor.declaration.properties.filter(it => !it.isStatic).map(it => it.name), duplicateMembers, this);
|
|
7926
|
+
}
|
|
7927
|
+
if (convertor instanceof BufferConvertor) {
|
|
7928
|
+
return makeInterfaceTypeCheckerCall(value, this.getNodeName(convertor.idlType), [], new Set(), this);
|
|
7929
|
+
}
|
|
7930
|
+
if (convertor instanceof AggregateConvertor) {
|
|
7931
|
+
return makeInterfaceTypeCheckerCall(value, convertor.aliasName !== undefined ? convertor.aliasName : this.getNodeName(convertor.idlType), convertor.members.map(it => it[0]), duplicateMembers, this);
|
|
7932
|
+
}
|
|
7933
|
+
if (convertor instanceof ArrayConvertor) {
|
|
7934
|
+
return makeArrayTypeCheckCall(value, this.arrayConvertor.convert(convertor.idlType), this);
|
|
7935
|
+
}
|
|
7936
|
+
if (isEnum$1(this.resolver.toDeclaration(convertor.nativeType()))) {
|
|
7937
|
+
return makeEnumTypeCheckerCall(value, this.getNodeName(convertor.idlType), this);
|
|
7938
|
+
}
|
|
7939
|
+
return super.instanceOf(convertor, value, duplicateMembers);
|
|
7940
|
+
}
|
|
7941
|
+
typeInstanceOf(type, value, members) {
|
|
7942
|
+
if (!members || members.length === 0) {
|
|
7943
|
+
throw new Error("At least one member needs to provided to pass it to TypeChecker!");
|
|
7944
|
+
}
|
|
7945
|
+
const prop = members[0];
|
|
7946
|
+
// Use the same typeInstanceOf<T>(...) method to compile the ETS code by two compilers ArkTS and TS
|
|
7947
|
+
return this.makeString(`TypeChecker.typeInstanceOf<${this.getNodeName(type)}>(value, "${prop}")`);
|
|
7948
|
+
}
|
|
7949
|
+
makeTypeCast(value, type, options) {
|
|
7950
|
+
return this.makeString(`TypeChecker.typeCast<${this.getNodeName(type)}>(value)`);
|
|
7951
|
+
}
|
|
7952
|
+
makeCast(value, node, options) {
|
|
7953
|
+
var _a;
|
|
7954
|
+
if (node === IDLI64Type)
|
|
7955
|
+
return this.makeMethodCall(value.asString(), `toLong`, []);
|
|
7956
|
+
if (node === IDLI32Type)
|
|
7957
|
+
return this.makeMethodCall(value.asString(), `toInt`, []);
|
|
7958
|
+
if (node === IDLI8Type)
|
|
7959
|
+
return this.makeMethodCall(value.asString(), `toByte`, []);
|
|
7960
|
+
if (node === IDLF64Type)
|
|
7961
|
+
return this.makeMethodCall(value.asString(), `toDouble`, []);
|
|
7962
|
+
if (node === IDLF32Type)
|
|
7963
|
+
return this.makeMethodCall(value.asString(), `toFloat`, []);
|
|
7964
|
+
return new TSCastExpression(value, `${this.getNodeName(node)}`, (_a = options === null || options === void 0 ? void 0 : options.unsafe) !== null && _a !== void 0 ? _a : false);
|
|
7965
|
+
}
|
|
7966
|
+
static get isUseTypeChecker() { return this._isUseTypeChecker; }
|
|
7967
|
+
static useTypeChecker(isUseTypeChecker, op) {
|
|
7968
|
+
const prevIsUse = this.isReferenceRelativeToNamespaces;
|
|
7969
|
+
this._isUseTypeChecker = isUseTypeChecker;
|
|
7970
|
+
const result = op();
|
|
7971
|
+
this._isUseTypeChecker = prevIsUse;
|
|
7972
|
+
return result;
|
|
7973
|
+
}
|
|
7974
|
+
}
|
|
7975
|
+
ETSLanguageWriter._isUseTypeChecker = true;
|
|
7976
|
+
function makeInterfaceTypeCheckerCall(valueAccessor, interfaceName, allFields, duplicates, writer) {
|
|
7977
|
+
return writer.makeMethodCall("TypeChecker", generateTypeCheckerName(interfaceName), [writer.makeString(valueAccessor),
|
|
7978
|
+
...allFields.map(it => {
|
|
7979
|
+
return writer.makeString(duplicates.has(it) ? "true" : "false");
|
|
7980
|
+
})
|
|
7981
|
+
]);
|
|
7982
|
+
}
|
|
7983
|
+
function makeEnumTypeCheckerCall(valueAccessor, enumName, writer) {
|
|
7984
|
+
return writer.makeMethodCall("TypeChecker", generateTypeCheckerName(enumName), [writer.makeString(valueAccessor)]);
|
|
7985
|
+
}
|
|
7986
|
+
|
|
7987
|
+
/*
|
|
7988
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
7989
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7990
|
+
* you may not use this file except in compliance with the License.
|
|
7991
|
+
* You may obtain a copy of the License at
|
|
7992
|
+
*
|
|
7993
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7994
|
+
*
|
|
7995
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7996
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7997
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7998
|
+
* See the License for the specific language governing permissions and
|
|
7999
|
+
* limitations under the License.
|
|
8000
|
+
*/
|
|
8001
|
+
class UnionRuntimeTypeChecker {
|
|
8002
|
+
constructor(convertors) {
|
|
8003
|
+
this.convertors = convertors;
|
|
8004
|
+
this.conflictingConvertors = new Set();
|
|
8005
|
+
this.duplicateMembers = new Set();
|
|
8006
|
+
this.discriminators = [];
|
|
8007
|
+
this.checkConflicts();
|
|
8008
|
+
}
|
|
8009
|
+
checkConflicts() {
|
|
8010
|
+
const runtimeTypeConflicts = new Map();
|
|
8011
|
+
this.convertors.forEach(conv => {
|
|
8012
|
+
conv.runtimeTypes.forEach(rtType => {
|
|
8013
|
+
const convertors = runtimeTypeConflicts.get(rtType);
|
|
8014
|
+
if (convertors)
|
|
8015
|
+
convertors.push(conv);
|
|
8016
|
+
else
|
|
8017
|
+
runtimeTypeConflicts.set(rtType, [conv]);
|
|
8018
|
+
});
|
|
8019
|
+
});
|
|
8020
|
+
runtimeTypeConflicts.forEach((convertors, rtType) => {
|
|
8021
|
+
if (convertors.length > 1) {
|
|
8022
|
+
const allMembers = new Set();
|
|
8023
|
+
if (rtType === RuntimeType.OBJECT) {
|
|
8024
|
+
convertors.forEach(convertor => {
|
|
8025
|
+
convertor.getMembers().forEach(member => {
|
|
8026
|
+
if (allMembers.has(member))
|
|
8027
|
+
this.duplicateMembers.add(member);
|
|
8028
|
+
allMembers.add(member);
|
|
8029
|
+
});
|
|
8030
|
+
});
|
|
8031
|
+
}
|
|
8032
|
+
convertors.forEach(convertor => {
|
|
8033
|
+
this.conflictingConvertors.add(convertor);
|
|
8034
|
+
});
|
|
8035
|
+
}
|
|
8036
|
+
});
|
|
8037
|
+
}
|
|
8038
|
+
makeDiscriminator(value, convertorIndex, writer) {
|
|
8039
|
+
const convertor = this.convertors[convertorIndex];
|
|
8040
|
+
if (this.conflictingConvertors.has(convertor) && writer.language.needsUnionDiscrimination) {
|
|
8041
|
+
const discriminator = convertor.unionDiscriminator(value, convertorIndex, writer, this.duplicateMembers);
|
|
8042
|
+
this.discriminators.push([discriminator, convertor, convertorIndex]);
|
|
8043
|
+
if (discriminator)
|
|
8044
|
+
return discriminator;
|
|
8045
|
+
}
|
|
8046
|
+
return writer.makeNaryOp("||", convertor.runtimeTypes.map((it, runtimeTypeIndex) => writer.makeNaryOp("==", [
|
|
8047
|
+
writer.makeUnionVariantCondition(convertor, value, `${value}_type`, RuntimeType[it], convertorIndex, runtimeTypeIndex)
|
|
8048
|
+
])));
|
|
8049
|
+
}
|
|
8050
|
+
reportConflicts(context, writer) {
|
|
8051
|
+
if (this.discriminators.filter(([discriminator, _, __]) => discriminator === undefined).length > 1) {
|
|
8052
|
+
Array.from(this.duplicateMembers).join(",").padEnd(30);
|
|
8053
|
+
this.discriminators.forEach(([discr, conv, n]) => {
|
|
8054
|
+
n.toString().padEnd(3);
|
|
8055
|
+
conv.targetType(writer).padEnd(30);
|
|
8056
|
+
discr ? discr.asString() : "<undefined>";
|
|
8057
|
+
});
|
|
8058
|
+
// throw new Error(report)
|
|
8059
|
+
}
|
|
8060
|
+
}
|
|
8061
|
+
}
|
|
8062
|
+
|
|
8063
|
+
/*
|
|
8064
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
8065
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8066
|
+
* you may not use this file except in compliance with the License.
|
|
8067
|
+
* You may obtain a copy of the License at
|
|
8068
|
+
*
|
|
8069
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8070
|
+
*
|
|
8071
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
8072
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
8073
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8074
|
+
* See the License for the specific language governing permissions and
|
|
8075
|
+
* limitations under the License.
|
|
8076
|
+
*/
|
|
8077
|
+
var LayoutNodeRole;
|
|
8078
|
+
(function (LayoutNodeRole) {
|
|
8079
|
+
LayoutNodeRole[LayoutNodeRole["PEER"] = 0] = "PEER";
|
|
8080
|
+
LayoutNodeRole[LayoutNodeRole["INTERFACE"] = 1] = "INTERFACE";
|
|
8081
|
+
LayoutNodeRole[LayoutNodeRole["GLOBAL"] = 2] = "GLOBAL";
|
|
8082
|
+
LayoutNodeRole[LayoutNodeRole["COMPONENT"] = 3] = "COMPONENT";
|
|
8083
|
+
LayoutNodeRole[LayoutNodeRole["SERIALIZER"] = 4] = "SERIALIZER";
|
|
8084
|
+
})(LayoutNodeRole || (LayoutNodeRole = {}));
|
|
8085
|
+
|
|
8086
|
+
/*
|
|
8087
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
8088
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8089
|
+
* you may not use this file except in compliance with the License.
|
|
8090
|
+
* You may obtain a copy of the License at
|
|
8091
|
+
*
|
|
8092
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8093
|
+
*
|
|
8094
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
8095
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
8096
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8097
|
+
* See the License for the specific language governing permissions and
|
|
8098
|
+
* limitations under the License.
|
|
8099
|
+
*/
|
|
8100
|
+
function getSerializerName(declaration) {
|
|
8101
|
+
return `${getQualifiedName(declaration, "namespace.name").split('.').join('_')}_serializer`;
|
|
8102
|
+
}
|
|
8103
|
+
class BaseArgConvertor {
|
|
8104
|
+
constructor(idlType, runtimeTypes, isScoped, useArray, param) {
|
|
8105
|
+
this.idlType = idlType;
|
|
8106
|
+
this.runtimeTypes = runtimeTypes;
|
|
8107
|
+
this.isScoped = isScoped;
|
|
8108
|
+
this.useArray = useArray;
|
|
8109
|
+
this.param = param;
|
|
8110
|
+
}
|
|
8111
|
+
holdResource(_resourceName, _holder, _writer) { }
|
|
8112
|
+
nativeType() {
|
|
8113
|
+
throw new Error("Define");
|
|
8114
|
+
}
|
|
8115
|
+
isPointerType() {
|
|
8116
|
+
throw new Error("Define");
|
|
8117
|
+
}
|
|
8118
|
+
interopType() {
|
|
8119
|
+
throw new Error("Define");
|
|
8120
|
+
}
|
|
8121
|
+
targetType(writer) {
|
|
8122
|
+
return writer.getNodeName(this.idlType);
|
|
8123
|
+
}
|
|
8124
|
+
unionDiscriminator(value, index, writer, duplicates) {
|
|
8125
|
+
return undefined;
|
|
8126
|
+
}
|
|
8127
|
+
getMembers() { return []; }
|
|
8128
|
+
getObjectAccessor(language, value, args, writer) {
|
|
8129
|
+
if (writer)
|
|
8130
|
+
return writer.getObjectAccessor(this, value, args);
|
|
8131
|
+
return this.useArray && (args === null || args === void 0 ? void 0 : args.index) ? `${value}[${args.index}]` : value;
|
|
8132
|
+
}
|
|
8133
|
+
discriminatorFromFields(value, writer, uniqueFields, nameAccessor, optionalAccessor, duplicates) {
|
|
8134
|
+
if (!uniqueFields || uniqueFields.length === 0)
|
|
8135
|
+
return undefined;
|
|
8136
|
+
const firstNonOptional = uniqueFields.find(it => !optionalAccessor(it));
|
|
8137
|
+
return writer.discriminatorFromExpressions(value, RuntimeType.OBJECT, [
|
|
8138
|
+
writer.makeDiscriminatorFromFields(this, value, firstNonOptional ? [nameAccessor(firstNonOptional)] : uniqueFields.map(it => nameAccessor(it)), duplicates)
|
|
8139
|
+
]);
|
|
8140
|
+
}
|
|
8141
|
+
}
|
|
8142
|
+
class UndefinedConvertor extends BaseArgConvertor {
|
|
8143
|
+
constructor(param) {
|
|
8144
|
+
super(IDLUndefinedType, [RuntimeType.UNDEFINED], false, false, param);
|
|
8145
|
+
}
|
|
8146
|
+
convertorArg(param, writer) {
|
|
8147
|
+
return writer.makeUndefined().asString();
|
|
8148
|
+
}
|
|
8149
|
+
convertorSerialize(param, value, printer) { }
|
|
8150
|
+
convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
|
|
8151
|
+
return assigneer(writer.makeUndefined());
|
|
8152
|
+
}
|
|
8153
|
+
nativeType() {
|
|
8154
|
+
return IDLUndefinedType;
|
|
8155
|
+
}
|
|
8156
|
+
interopType() {
|
|
8157
|
+
return IDLUndefinedType;
|
|
8158
|
+
}
|
|
8159
|
+
isPointerType() {
|
|
8160
|
+
return false;
|
|
8161
|
+
}
|
|
8162
|
+
}
|
|
8163
|
+
class BufferConvertor extends BaseArgConvertor {
|
|
8164
|
+
constructor(param) {
|
|
8165
|
+
super(IDLBufferType, [RuntimeType.OBJECT], false, true, param);
|
|
8166
|
+
}
|
|
8167
|
+
convertorArg(param, _) {
|
|
8168
|
+
return param;
|
|
8169
|
+
}
|
|
8170
|
+
convertorSerialize(param, value, printer) {
|
|
8171
|
+
printer.writeMethodCall(`${param}Serializer`, "writeBuffer", [value]);
|
|
8172
|
+
}
|
|
8173
|
+
convertorDeserialize(_, deserializerName, assigneer, writer) {
|
|
8174
|
+
return assigneer(writer.makeCast(writer.makeString(`${deserializerName}.readBuffer()`), this.idlType, { optional: false }));
|
|
8175
|
+
}
|
|
8176
|
+
nativeType() {
|
|
8177
|
+
return IDLBufferType;
|
|
8178
|
+
}
|
|
8179
|
+
interopType() {
|
|
8180
|
+
return IDLBufferType;
|
|
8181
|
+
}
|
|
8182
|
+
isPointerType() {
|
|
8183
|
+
return true;
|
|
8184
|
+
}
|
|
8185
|
+
unionDiscriminator(value, index, writer, duplicates) {
|
|
8186
|
+
return writer.instanceOf(this, value);
|
|
8187
|
+
}
|
|
8188
|
+
}
|
|
8189
|
+
class AggregateConvertor extends BaseArgConvertor {
|
|
8190
|
+
constructor(library, param, type, decl) {
|
|
8191
|
+
super(type, [RuntimeType.OBJECT], false, true, param);
|
|
8192
|
+
this.library = library;
|
|
8193
|
+
this.decl = decl;
|
|
8194
|
+
this.members = [];
|
|
8195
|
+
// this.aliasName = ts.isTypeAliasDeclaration(this.type.parent) ? identName(this.type.parent.name) : undefined
|
|
8196
|
+
this.memberConvertors = decl
|
|
8197
|
+
.properties
|
|
8198
|
+
// .filter(ts.isPropertySignature)
|
|
8199
|
+
.map((member, index) => {
|
|
8200
|
+
this.members[index] = [member.name, member.isOptional];
|
|
8201
|
+
return library.typeConvertor(param, member.type, member.isOptional);
|
|
8202
|
+
});
|
|
8203
|
+
}
|
|
8204
|
+
convertorArg(param, writer) {
|
|
8205
|
+
throw new Error("Do not use for aggregates");
|
|
8206
|
+
}
|
|
8207
|
+
convertorSerialize(param, value, printer) {
|
|
8208
|
+
this.memberConvertors.forEach((it, index) => {
|
|
8209
|
+
let memberName = this.members[index][0];
|
|
8210
|
+
let memberAccess = `${value}.${printer.escapeKeyword(memberName)}`;
|
|
8211
|
+
printer.writeStatement(printer.makeAssign(`${value}_${memberName}`, undefined, printer.makeString(memberAccess), true));
|
|
8212
|
+
it.convertorSerialize(param, `${value}_${memberName}`, printer);
|
|
8213
|
+
});
|
|
8214
|
+
}
|
|
8215
|
+
convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
|
|
8216
|
+
const statements = [];
|
|
8217
|
+
if (writer.language === Language.CPP) {
|
|
8218
|
+
statements.push(writer.makeAssign(bufferName, this.idlType, undefined, true, false));
|
|
8219
|
+
}
|
|
8220
|
+
// TODO: Needs to be reworked DeserializerBase.readFunction properly
|
|
8221
|
+
if (writer.language === Language.ARKTS
|
|
8222
|
+
&& this.memberConvertors.find(it => it instanceof FunctionConvertor)) {
|
|
8223
|
+
return new BlockStatement([writer.makeThrowError("Not implemented yet")], false);
|
|
8224
|
+
}
|
|
8225
|
+
for (let i = 0; i < this.decl.properties.length; i++) {
|
|
8226
|
+
const prop = this.decl.properties[i];
|
|
8227
|
+
const propConvertor = this.memberConvertors[i];
|
|
8228
|
+
statements.push(propConvertor.convertorDeserialize(`${bufferName}_${prop.name}_buf`, deserializerName, (expr) => {
|
|
8229
|
+
if (writer.language === Language.CPP) {
|
|
8230
|
+
// prefix initialization for CPP, just easier. Waiting for easy work with nullables
|
|
8231
|
+
return writer.makeAssign(`${bufferName}.${writer.escapeKeyword(prop.name)}`, undefined, expr, false);
|
|
8232
|
+
}
|
|
8233
|
+
/**
|
|
8234
|
+
* todo: check UnionType name creation for union of unnamed nodes (isNamedNode() == false)
|
|
8235
|
+
*/
|
|
8236
|
+
const memberType = maybeOptional(prop.type, prop.isOptional);
|
|
8237
|
+
return writer.makeAssign(`${bufferName}_${prop.name}`, memberType, expr, true, true);
|
|
8238
|
+
}, writer));
|
|
8239
|
+
}
|
|
8240
|
+
if (writer.language === Language.CPP) {
|
|
8241
|
+
statements.push(assigneer(writer.makeString(bufferName)));
|
|
8242
|
+
}
|
|
8243
|
+
else if (writer.language == Language.CJ) {
|
|
8244
|
+
const resultExpression = writer.makeString(`${writer.getNodeName(this.idlType)}(${this.decl.properties.map(prop => `${bufferName}_${prop.name}`).join(", ")})`);
|
|
8245
|
+
statements.push(assigneer(resultExpression));
|
|
8246
|
+
}
|
|
8247
|
+
else {
|
|
8248
|
+
const resultExpression = this.makeAssigneeExpression(this.decl.properties.map(prop => {
|
|
8249
|
+
return [prop.name, writer.makeString(`${bufferName}_${prop.name}`)];
|
|
8250
|
+
}), writer);
|
|
8251
|
+
statements.push(assigneer(resultExpression));
|
|
8252
|
+
}
|
|
8253
|
+
return new BlockStatement(statements, false);
|
|
8254
|
+
}
|
|
8255
|
+
makeAssigneeExpression(fields, writer) {
|
|
8256
|
+
const content = fields.map(it => `${it[0]}: ${it[1].asString()}`).join(', ');
|
|
8257
|
+
return writer.makeCast(writer.makeString(`{${content}}`), this.idlType);
|
|
8258
|
+
}
|
|
8259
|
+
nativeType() {
|
|
8260
|
+
return createReferenceType(this.decl);
|
|
8261
|
+
}
|
|
8262
|
+
interopType() {
|
|
8263
|
+
throw new Error("Must never be used");
|
|
8264
|
+
}
|
|
8265
|
+
isPointerType() {
|
|
8266
|
+
return true;
|
|
8267
|
+
}
|
|
8268
|
+
getMembers() {
|
|
8269
|
+
return this.members.map(it => it[0]);
|
|
8270
|
+
}
|
|
8271
|
+
unionDiscriminator(value, index, writer, duplicates) {
|
|
8272
|
+
const uniqueFields = this.members.filter(it => !duplicates.has(it[0]));
|
|
8273
|
+
return this.discriminatorFromFields(value, writer, uniqueFields, it => it[0], it => it[1], duplicates);
|
|
8274
|
+
}
|
|
8275
|
+
}
|
|
8276
|
+
class InterfaceConvertor extends BaseArgConvertor {
|
|
8277
|
+
constructor(library, name /* change to IDLReferenceType */, param, declaration) {
|
|
8278
|
+
super(createReferenceType(declaration), [RuntimeType.OBJECT], false, true, param);
|
|
8279
|
+
this.library = library;
|
|
8280
|
+
this.declaration = declaration;
|
|
8281
|
+
}
|
|
8282
|
+
convertorArg(param, writer) {
|
|
8283
|
+
throw new Error("Must never be used");
|
|
8284
|
+
}
|
|
8285
|
+
convertorSerialize(param, value, printer) {
|
|
8286
|
+
const accessor = getSerializerName(this.declaration);
|
|
8287
|
+
printer.addFeature(accessor, this.library.layout.resolve({ node: this.declaration, role: LayoutNodeRole.SERIALIZER }));
|
|
8288
|
+
printer.writeStaticMethodCall(accessor, 'write', [`${param}Serializer`, value]);
|
|
8289
|
+
}
|
|
8290
|
+
convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
|
|
8291
|
+
const accessor = getSerializerName(this.declaration);
|
|
8292
|
+
writer.addFeature(accessor, this.library.layout.resolve({ node: this.declaration, role: LayoutNodeRole.SERIALIZER }));
|
|
8293
|
+
return assigneer(writer.makeStaticMethodCall(accessor, 'read', [writer.makeString(deserializerName)]));
|
|
8294
|
+
}
|
|
8295
|
+
nativeType() {
|
|
8296
|
+
return this.idlType;
|
|
8297
|
+
}
|
|
8298
|
+
interopType() {
|
|
8299
|
+
// Actually shouldn't be used!
|
|
8300
|
+
// throw new Error("Must never be used")
|
|
8301
|
+
return IDLSerializerBuffer;
|
|
8302
|
+
}
|
|
8303
|
+
isPointerType() {
|
|
8304
|
+
return true;
|
|
8305
|
+
}
|
|
8306
|
+
getMembers() {
|
|
8307
|
+
var _a, _b;
|
|
8308
|
+
return (_b = (_a = this.declaration) === null || _a === void 0 ? void 0 : _a.properties.map(it => it.name)) !== null && _b !== void 0 ? _b : [];
|
|
8309
|
+
}
|
|
8310
|
+
unionDiscriminator(value, index, writer, duplicates) {
|
|
8311
|
+
var _a;
|
|
8312
|
+
// Try to figure out interface by examining field sets
|
|
8313
|
+
const uniqueFields = (_a = this.declaration) === null || _a === void 0 ? void 0 : _a.properties.filter(it => !duplicates.has(it.name));
|
|
8314
|
+
return this.discriminatorFromFields(value, writer, uniqueFields, it => it.name, it => it.isOptional, duplicates);
|
|
8315
|
+
}
|
|
8316
|
+
}
|
|
8317
|
+
class ArrayConvertor extends BaseArgConvertor {
|
|
8318
|
+
constructor(library, param, type, elementType) {
|
|
8319
|
+
super(createContainerType('sequence', [elementType]), [RuntimeType.OBJECT], false, true, param);
|
|
8320
|
+
this.library = library;
|
|
8321
|
+
this.type = type;
|
|
8322
|
+
this.elementType = elementType;
|
|
8323
|
+
this.elementConvertor = library.typeConvertor(param, elementType);
|
|
8324
|
+
}
|
|
8325
|
+
convertorArg(param, writer) {
|
|
8326
|
+
throw new Error("Must never be used");
|
|
8327
|
+
}
|
|
8328
|
+
convertorSerialize(param, value, printer) {
|
|
8329
|
+
// Array length.
|
|
8330
|
+
const valueLength = printer.makeArrayLength(value).asString();
|
|
8331
|
+
const loopCounter = "i";
|
|
8332
|
+
printer.writeMethodCall(`${param}Serializer`, "writeInt32", [printer.castToInt(valueLength, 32)]);
|
|
8333
|
+
printer.writeStatement(printer.makeLoop(loopCounter, valueLength));
|
|
8334
|
+
printer.pushIndent();
|
|
8335
|
+
printer.writeStatement(printer.makeAssign(`${value}_element`, this.elementType, printer.makeArrayAccess(value, loopCounter), true));
|
|
8336
|
+
this.elementConvertor.convertorSerialize(param, `${value}_element`, printer);
|
|
8337
|
+
printer.popIndent();
|
|
8338
|
+
printer.print(`}`);
|
|
8339
|
+
}
|
|
8340
|
+
convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
|
|
8341
|
+
const lengthBuffer = `${bufferName}_length`;
|
|
8342
|
+
const counterBuffer = `${bufferName}_i`;
|
|
8343
|
+
const statements = [];
|
|
8344
|
+
const arrayType = this.idlType;
|
|
8345
|
+
statements.push(writer.makeAssign(lengthBuffer, IDLI32Type, writer.makeString(`${deserializerName}.readInt32()`), true));
|
|
8346
|
+
statements.push(writer.makeAssign(bufferName, arrayType, writer.makeArrayInit(this.type, lengthBuffer), true, false));
|
|
8347
|
+
statements.push(writer.makeArrayResize(bufferName, writer.getNodeName(arrayType), lengthBuffer, deserializerName));
|
|
8348
|
+
statements.push(writer.makeLoop(counterBuffer, lengthBuffer, this.elementConvertor.convertorDeserialize(`${bufferName}_buf`, deserializerName, (expr) => {
|
|
8349
|
+
return writer.makeAssign(writer.makeArrayAccess(bufferName, counterBuffer).asString(), undefined, expr, false);
|
|
8350
|
+
}, writer)));
|
|
8351
|
+
statements.push(assigneer(writer.makeString(bufferName)));
|
|
8352
|
+
return new BlockStatement(statements, false);
|
|
8353
|
+
}
|
|
8354
|
+
nativeType() {
|
|
8355
|
+
return createContainerType('sequence', [this.elementType]);
|
|
8356
|
+
}
|
|
8357
|
+
interopType() {
|
|
8358
|
+
throw new Error("Must never be used");
|
|
8359
|
+
}
|
|
8360
|
+
isPointerType() {
|
|
8361
|
+
return true;
|
|
8362
|
+
}
|
|
8363
|
+
unionDiscriminator(value, index, writer, duplicates) {
|
|
8364
|
+
return writer.discriminatorFromExpressions(value, RuntimeType.OBJECT, [writer.instanceOf(this, value, duplicates)]);
|
|
8365
|
+
}
|
|
8366
|
+
getObjectAccessor(language, value, args) {
|
|
8367
|
+
const array = language === Language.CPP ? ".array" : "";
|
|
8368
|
+
return (args === null || args === void 0 ? void 0 : args.index) ? `${value}${array}${args.index}` : value;
|
|
8369
|
+
}
|
|
8370
|
+
}
|
|
8371
|
+
class ProxyConvertor extends BaseArgConvertor {
|
|
8372
|
+
constructor(convertor, suggestedReference) {
|
|
8373
|
+
super(suggestedReference ? suggestedReference : convertor.idlType, convertor.runtimeTypes, convertor.isScoped, convertor.useArray, convertor.param);
|
|
8374
|
+
this.convertor = convertor;
|
|
8375
|
+
}
|
|
8376
|
+
convertorArg(param, writer) {
|
|
8377
|
+
return this.convertor.convertorArg(param, writer);
|
|
8378
|
+
}
|
|
8379
|
+
convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
|
|
8380
|
+
return this.convertor.convertorDeserialize(bufferName, deserializerName, assigneer, writer);
|
|
8381
|
+
}
|
|
8382
|
+
convertorSerialize(param, value, printer) {
|
|
8383
|
+
this.convertor.convertorSerialize(param, value, printer);
|
|
8384
|
+
}
|
|
8385
|
+
nativeType() {
|
|
8386
|
+
return this.convertor.nativeType();
|
|
8387
|
+
}
|
|
8388
|
+
interopType() {
|
|
8389
|
+
return this.convertor.interopType();
|
|
8390
|
+
}
|
|
8391
|
+
isPointerType() {
|
|
8392
|
+
return this.convertor.isPointerType();
|
|
8393
|
+
}
|
|
8394
|
+
unionDiscriminator(value, index, writer, duplicates) {
|
|
8395
|
+
return this.convertor.unionDiscriminator(value, index, writer, duplicates);
|
|
8396
|
+
}
|
|
8397
|
+
getMembers() {
|
|
8398
|
+
return this.convertor.getMembers();
|
|
8399
|
+
}
|
|
8400
|
+
}
|
|
8401
|
+
class CustomTypeConvertor extends BaseArgConvertor {
|
|
8402
|
+
constructor(param, customTypeName, isGenericType, tsType) {
|
|
8403
|
+
super(createReferenceType(tsType !== null && tsType !== void 0 ? tsType : "Object"), [RuntimeType.OBJECT], false, true, param);
|
|
8404
|
+
this.customTypeName = customTypeName;
|
|
8405
|
+
this.isGenericType = isGenericType;
|
|
8406
|
+
warnCustomObject(`${customTypeName}: ${tsType}`);
|
|
8407
|
+
}
|
|
8408
|
+
convertorArg(param, writer) {
|
|
8409
|
+
throw new Error("Must never be used");
|
|
8410
|
+
}
|
|
8411
|
+
/** todo: check */
|
|
8412
|
+
convertorSerialize(param, value, printer) {
|
|
8413
|
+
printer.writeMethodCall(`${param}Serializer`, `writeCustomObject`, [`"${this.customTypeName}"`, printer.makeCastCustomObject(value, this.isGenericType).asString()]);
|
|
8414
|
+
}
|
|
8415
|
+
convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
|
|
8416
|
+
const type = writer.language === Language.CPP
|
|
8417
|
+
? this.nativeType()
|
|
8418
|
+
: this.idlType;
|
|
8419
|
+
return assigneer(writer.makeCast(writer.makeMethodCall(`${deserializerName}`, "readCustomObject", [writer.makeString(`"${this.customTypeName}"`)]), type, { optional: false }));
|
|
8420
|
+
}
|
|
8421
|
+
nativeType() {
|
|
8422
|
+
return IDLCustomObjectType;
|
|
8423
|
+
}
|
|
8424
|
+
interopType() {
|
|
8425
|
+
throw new Error("Must never be used");
|
|
8426
|
+
}
|
|
8427
|
+
isPointerType() {
|
|
8428
|
+
return true;
|
|
8429
|
+
}
|
|
8430
|
+
}
|
|
8431
|
+
class OptionConvertor extends BaseArgConvertor {
|
|
8432
|
+
// TODO: be smarter here, and for smth like Length|undefined or number|undefined pass without serializer.
|
|
8433
|
+
constructor(library, param, type) {
|
|
8434
|
+
let conv = library.typeConvertor(param, type);
|
|
8435
|
+
let currentConv = conv;
|
|
8436
|
+
while (currentConv instanceof ProxyConvertor) {
|
|
8437
|
+
currentConv = currentConv.convertor;
|
|
8438
|
+
}
|
|
8439
|
+
if (currentConv instanceof OptionConvertor) {
|
|
8440
|
+
conv = currentConv.typeConvertor;
|
|
8441
|
+
}
|
|
8442
|
+
let runtimeTypes = conv.runtimeTypes;
|
|
8443
|
+
if (!runtimeTypes.includes(RuntimeType.UNDEFINED)) {
|
|
8444
|
+
runtimeTypes.push(RuntimeType.UNDEFINED);
|
|
8445
|
+
}
|
|
8446
|
+
super(createOptionalType(conv.idlType), runtimeTypes, conv.isScoped, true, param);
|
|
8447
|
+
this.type = type;
|
|
8448
|
+
this.typeConvertor = conv;
|
|
8449
|
+
}
|
|
8450
|
+
convertorArg(param, writer) {
|
|
8451
|
+
throw new Error("Must never be used");
|
|
8452
|
+
}
|
|
8453
|
+
convertorSerialize(param, value, printer) {
|
|
8454
|
+
const valueType = `${value}_type`.replaceAll('.', '_');
|
|
8455
|
+
const serializedType = (printer.language == Language.JAVA ? undefined : IDLI32Type);
|
|
8456
|
+
printer.writeStatement(printer.makeAssign(valueType, serializedType, printer.makeRuntimeType(RuntimeType.UNDEFINED), true, false));
|
|
8457
|
+
if (printer.language != Language.CJ && printer.language != Language.KOTLIN) {
|
|
8458
|
+
printer.runtimeType(this, valueType, value);
|
|
8459
|
+
printer.writeMethodCall(`${param}Serializer`, "writeInt8", [printer.castToInt(valueType, 8)]);
|
|
8460
|
+
}
|
|
8461
|
+
printer.print(`if (${printer.makeRuntimeTypeCondition(valueType, false, RuntimeType.UNDEFINED, value).asString()}) {`);
|
|
8462
|
+
printer.pushIndent();
|
|
8463
|
+
if (printer.language == Language.CJ || printer.language == Language.KOTLIN) {
|
|
8464
|
+
printer.writeMethodCall(`${param}Serializer`, "writeInt8", ["RuntimeType.OBJECT.ordinal"]); // everything is object, except None<T>
|
|
8465
|
+
}
|
|
8466
|
+
const valueValue = `${value}_value`.replaceAll('.', '_');
|
|
8467
|
+
printer.writeStatement(printer.makeAssign(valueValue, undefined, printer.makeValueFromOption(value, this.typeConvertor), true));
|
|
8468
|
+
this.typeConvertor.convertorSerialize(param, this.typeConvertor.getObjectAccessor(printer.language, valueValue), printer);
|
|
8469
|
+
printer.popIndent();
|
|
8470
|
+
printer.print(`}`);
|
|
8471
|
+
if (printer.language == Language.CJ || printer.language == Language.KOTLIN) {
|
|
8472
|
+
printer.print('else {');
|
|
8473
|
+
printer.pushIndent();
|
|
8474
|
+
printer.writeMethodCall(`${param}Serializer`, "writeInt8", ["RuntimeType.UNDEFINED.ordinal"]); // undefined
|
|
8475
|
+
printer.popIndent();
|
|
8476
|
+
printer.print('}');
|
|
8477
|
+
}
|
|
8478
|
+
}
|
|
8479
|
+
convertorCArg(param) {
|
|
8480
|
+
throw new Error("Must never be used");
|
|
8481
|
+
}
|
|
8482
|
+
convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
|
|
8483
|
+
const runtimeBufferName = `${bufferName}_runtimeType`;
|
|
8484
|
+
const statements = [];
|
|
8485
|
+
statements.push(writer.makeAssign(runtimeBufferName, undefined, writer.makeCast(writer.makeString(`${deserializerName}.readInt8()`), writer.getRuntimeType()), true));
|
|
8486
|
+
const bufferType = this.nativeType();
|
|
8487
|
+
statements.push(writer.makeAssign(bufferName, bufferType, (writer.language == Language.CJ || writer.language == Language.KOTLIN) ? writer.makeNull() : undefined, true, false));
|
|
8488
|
+
const thenStatement = new BlockStatement([
|
|
8489
|
+
this.typeConvertor.convertorDeserialize(`${bufferName}_`, deserializerName, (expr) => {
|
|
8490
|
+
const receiver = writer.language === Language.CPP
|
|
8491
|
+
? `${bufferName}.value` : bufferName;
|
|
8492
|
+
return writer.makeAssign(receiver, undefined, expr, false);
|
|
8493
|
+
}, writer)
|
|
8494
|
+
]);
|
|
8495
|
+
statements.push(writer.makeSetOptionTag(bufferName, writer.makeCast(writer.makeString(runtimeBufferName), writer.getTagType())));
|
|
8496
|
+
statements.push(writer.makeCondition(writer.makeRuntimeTypeDefinedCheck(runtimeBufferName), thenStatement));
|
|
8497
|
+
statements.push(assigneer(writer.makeString(bufferName)));
|
|
8498
|
+
return writer.makeBlock(statements, false);
|
|
8499
|
+
}
|
|
8500
|
+
nativeType() {
|
|
8501
|
+
return createOptionalType(this.type);
|
|
8502
|
+
}
|
|
8503
|
+
interopType() {
|
|
8504
|
+
return createOptionalType(this.type);
|
|
8505
|
+
}
|
|
8506
|
+
isPointerType() {
|
|
8507
|
+
return true;
|
|
8508
|
+
}
|
|
8509
|
+
getObjectAccessor(language, value, args) {
|
|
8510
|
+
return language === Language.CPP ? `${value}.value` : value;
|
|
8511
|
+
}
|
|
8512
|
+
}
|
|
8513
|
+
class UnionConvertor extends BaseArgConvertor {
|
|
8514
|
+
constructor(library, param, type) {
|
|
8515
|
+
super(IDLObjectType, [], false, true, param);
|
|
8516
|
+
this.library = library;
|
|
8517
|
+
this.type = type;
|
|
8518
|
+
this.memberConvertors = type.types.map(member => library.typeConvertor(param, member));
|
|
8519
|
+
this.unionChecker = new UnionRuntimeTypeChecker(this.memberConvertors);
|
|
8520
|
+
this.runtimeTypes = this.memberConvertors.flatMap(it => it.runtimeTypes);
|
|
8521
|
+
this.idlType = type;
|
|
8522
|
+
}
|
|
8523
|
+
convertorArg(param, writer) {
|
|
8524
|
+
throw new Error("Do not use for union");
|
|
8525
|
+
}
|
|
8526
|
+
convertorSerialize(param, value, printer) {
|
|
8527
|
+
var _a;
|
|
8528
|
+
printer.writeStatement(printer.makeAssign(`${value}_type`, IDLI32Type, printer.makeUnionTypeDefaultInitializer(), true, false));
|
|
8529
|
+
printer.writeStatement(printer.makeUnionSelector(value, `${value}_type`));
|
|
8530
|
+
this.memberConvertors.forEach((it, index) => {
|
|
8531
|
+
const maybeElse = (index > 0 && this.memberConvertors[index - 1].runtimeTypes.length > 0) ? "else " : "";
|
|
8532
|
+
const conditions = this.unionChecker.makeDiscriminator(value, index, printer);
|
|
8533
|
+
printer.print(`${maybeElse}if (${conditions.asString()}) {`);
|
|
8534
|
+
printer.pushIndent();
|
|
8535
|
+
printer.writeMethodCall(`${param}Serializer`, "writeInt8", [printer.castToInt(index.toString(), 8)]);
|
|
8536
|
+
if (!(it instanceof UndefinedConvertor)) {
|
|
8537
|
+
printer.writeStatement(printer.makeAssign(`${value}_${index}`, undefined, printer.makeUnionVariantCast(it.getObjectAccessor(printer.language, value), printer.getNodeName(it.idlType), it, index), true));
|
|
8538
|
+
it.convertorSerialize(param, `${value}_${index}`, printer);
|
|
8539
|
+
}
|
|
8540
|
+
printer.popIndent();
|
|
8541
|
+
printer.print(`}`);
|
|
8542
|
+
});
|
|
8543
|
+
this.unionChecker.reportConflicts((_a = this.library.getCurrentContext()) !== null && _a !== void 0 ? _a : "<unknown context>", printer);
|
|
8544
|
+
}
|
|
8545
|
+
convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
|
|
8546
|
+
const statements = [];
|
|
8547
|
+
let selectorBuffer = `${bufferName}_selector`;
|
|
8548
|
+
const maybeOptionalUnion = writer.language === Language.CPP || writer.language == Language.CJ
|
|
8549
|
+
? this.type
|
|
8550
|
+
: createOptionalType(this.type);
|
|
8551
|
+
statements.push(writer.makeAssign(selectorBuffer, IDLI8Type, writer.makeString(`${deserializerName}.readInt8()`), true));
|
|
8552
|
+
statements.push(writer.makeAssign(bufferName, maybeOptionalUnion, undefined, true, false));
|
|
8553
|
+
if (writer.language === Language.CPP)
|
|
8554
|
+
statements.push(writer.makeAssign(`${bufferName}.selector`, undefined, writer.makeString(selectorBuffer), false));
|
|
8555
|
+
const branches = this.memberConvertors.map((it, index) => {
|
|
8556
|
+
const receiver = this.getObjectAccessor(writer.language, bufferName, { index: `${index}` });
|
|
8557
|
+
const expr = writer.makeString(`${selectorBuffer} == ${writer.castToInt(index.toString(), 8)}`);
|
|
8558
|
+
const stmt = new BlockStatement([
|
|
8559
|
+
writer.makeSetUnionSelector(bufferName, `${index}`),
|
|
8560
|
+
it.convertorDeserialize(`${bufferName}_u`, deserializerName, (expr) => {
|
|
8561
|
+
if (writer.language == Language.CJ) {
|
|
8562
|
+
return writer.makeAssign(receiver, undefined, writer.makeFunctionCall(writer.getNodeName(this.type), [expr]), false);
|
|
8563
|
+
}
|
|
8564
|
+
else {
|
|
8565
|
+
return writer.makeAssign(receiver, undefined, expr, false);
|
|
8566
|
+
}
|
|
8567
|
+
}, writer),
|
|
8568
|
+
], false);
|
|
8569
|
+
return { expr, stmt };
|
|
8570
|
+
});
|
|
8571
|
+
statements.push(writer.makeMultiBranchCondition(branches, writer.makeThrowError(`One of the branches for ${bufferName} has to be chosen through deserialisation.`)));
|
|
8572
|
+
statements.push(assigneer(writer.makeCast(writer.makeString(bufferName), this.nativeType())));
|
|
8573
|
+
return new BlockStatement(statements, false);
|
|
8574
|
+
}
|
|
8575
|
+
nativeType() {
|
|
8576
|
+
return this.type;
|
|
8577
|
+
}
|
|
8578
|
+
interopType() {
|
|
8579
|
+
throw new Error("Union");
|
|
8580
|
+
}
|
|
8581
|
+
isPointerType() {
|
|
8582
|
+
return true;
|
|
8583
|
+
}
|
|
8584
|
+
getObjectAccessor(language, value, args) {
|
|
8585
|
+
return language === Language.CPP && (args === null || args === void 0 ? void 0 : args.index) ? `${value}.value${args.index}` : value;
|
|
8586
|
+
}
|
|
8587
|
+
unionDiscriminator(value, index, writer, duplicates) {
|
|
8588
|
+
const checker = new UnionRuntimeTypeChecker(this.memberConvertors);
|
|
8589
|
+
return writer.makeNaryOp("||", this.memberConvertors.map((_, n) => checker.makeDiscriminator(value, n, writer)));
|
|
8590
|
+
}
|
|
8591
|
+
}
|
|
8592
|
+
class FunctionConvertor extends BaseArgConvertor {
|
|
8593
|
+
constructor(library, param) {
|
|
8594
|
+
// TODO: pass functions as integers to native side.
|
|
8595
|
+
super(IDLFunctionType, [RuntimeType.FUNCTION], false, false, param);
|
|
8596
|
+
this.library = library;
|
|
8597
|
+
}
|
|
8598
|
+
convertorArg(param, writer) {
|
|
8599
|
+
return writer.language == Language.CPP ? `makeArkFunctionFromId(${param})` : `registerCallback(${param})`;
|
|
8600
|
+
}
|
|
8601
|
+
convertorSerialize(param, value, writer) {
|
|
8602
|
+
writer.writeMethodCall(`${param}Serializer`, "writeFunction", [value]);
|
|
8603
|
+
}
|
|
8604
|
+
convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
|
|
8605
|
+
return assigneer(writer.makeCast(writer.makeString(`${deserializerName}.readFunction()`), IDLFunctionType, { optional: true }));
|
|
8606
|
+
}
|
|
8607
|
+
nativeType() {
|
|
8608
|
+
return IDLFunctionType;
|
|
8609
|
+
}
|
|
8610
|
+
interopType() {
|
|
8611
|
+
return IDLFunctionType;
|
|
8612
|
+
}
|
|
8613
|
+
isPointerType() {
|
|
8614
|
+
return false;
|
|
8615
|
+
}
|
|
8616
|
+
}
|
|
8617
|
+
class MaterializedClassConvertor extends BaseArgConvertor {
|
|
8618
|
+
constructor(library, param, declaration) {
|
|
8619
|
+
super(createReferenceType(declaration), [RuntimeType.OBJECT], false, false, param);
|
|
8620
|
+
this.library = library;
|
|
8621
|
+
this.declaration = declaration;
|
|
8622
|
+
}
|
|
8623
|
+
convertorArg(param, writer) {
|
|
8624
|
+
switch (writer.language) {
|
|
8625
|
+
case Language.CPP:
|
|
8626
|
+
return `static_cast<${generatorTypePrefix()}${qualifiedName(this.declaration, "_", "namespace.name")}>(${param})`;
|
|
8627
|
+
case Language.JAVA:
|
|
8628
|
+
case Language.CJ:
|
|
8629
|
+
return `MaterializedBase.toPeerPtr(${writer.escapeKeyword(param)})`;
|
|
8630
|
+
default:
|
|
8631
|
+
return `toPeerPtr(${param})`;
|
|
8632
|
+
}
|
|
8633
|
+
}
|
|
8634
|
+
convertorSerialize(param, value, printer) {
|
|
8635
|
+
const accessorRoot = getSerializerName(this.declaration);
|
|
8636
|
+
printer.addFeature(accessorRoot, this.library.layout.resolve({ node: this.declaration, role: LayoutNodeRole.SERIALIZER }));
|
|
8637
|
+
printer.writeStaticMethodCall(accessorRoot, 'write', [`${param}Serializer`, value]);
|
|
8638
|
+
}
|
|
8639
|
+
convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
|
|
8640
|
+
const accessorRoot = getSerializerName(this.declaration);
|
|
8641
|
+
writer.addFeature(accessorRoot, this.library.layout.resolve({ node: this.declaration, role: LayoutNodeRole.SERIALIZER }));
|
|
8642
|
+
const readStatement = writer.makeCast(writer.makeStaticMethodCall(accessorRoot, "read", [writer.makeString(deserializerName)]), this.declaration);
|
|
8643
|
+
return assigneer(readStatement);
|
|
8644
|
+
}
|
|
8645
|
+
nativeType() {
|
|
8646
|
+
return createReferenceType(this.declaration);
|
|
8647
|
+
}
|
|
8648
|
+
interopType() {
|
|
8649
|
+
return IDLPointerType;
|
|
8650
|
+
}
|
|
8651
|
+
isPointerType() {
|
|
8652
|
+
return false;
|
|
8653
|
+
}
|
|
8654
|
+
unionDiscriminator(value, index, writer, duplicates) {
|
|
8655
|
+
if (isInterface$1(this.declaration)) {
|
|
8656
|
+
if (this.declaration.subkind === IDLInterfaceSubkind.Class) {
|
|
8657
|
+
return writer.discriminatorFromExpressions(value, RuntimeType.OBJECT, [writer.instanceOf(this, value, duplicates)]);
|
|
8658
|
+
}
|
|
8659
|
+
if (this.declaration.subkind === IDLInterfaceSubkind.Interface) {
|
|
8660
|
+
const uniqueFields = this.declaration.properties.filter(it => !duplicates.has(it.name));
|
|
8661
|
+
return this.discriminatorFromFields(value, writer, uniqueFields, it => it.name, it => it.isOptional, duplicates);
|
|
8662
|
+
}
|
|
8663
|
+
}
|
|
8664
|
+
}
|
|
8665
|
+
}
|
|
8666
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
8667
|
+
// UTILS
|
|
8668
|
+
const customObjects = new Set();
|
|
8669
|
+
function warnCustomObject(type, msg) {
|
|
8670
|
+
if (!customObjects.has(type)) {
|
|
8671
|
+
warn(`Use CustomObject for ${``}type ${type}`);
|
|
8672
|
+
customObjects.add(type);
|
|
8673
|
+
}
|
|
8674
|
+
}
|
|
8675
|
+
|
|
8676
|
+
function isInModule(nodeOrPackage, module) {
|
|
8677
|
+
if (typeof nodeOrPackage === 'object')
|
|
8678
|
+
return isInModule(getPackageName(nodeOrPackage), module);
|
|
8679
|
+
return module.packages.some(modulePackage => nodeOrPackage.startsWith(modulePackage));
|
|
8680
|
+
}
|
|
8681
|
+
function currentModule() {
|
|
8682
|
+
const conf = generatorConfiguration();
|
|
8683
|
+
const result = conf.modules.get(conf.moduleName);
|
|
8684
|
+
if (!result)
|
|
8685
|
+
throw new Error(`Can not determine current module configuration ${conf.moduleName}`);
|
|
8686
|
+
return result;
|
|
8687
|
+
}
|
|
8688
|
+
function isInCurrentModule(nodeOrPackage) {
|
|
8689
|
+
if (typeof nodeOrPackage === 'string')
|
|
8690
|
+
return isInModule(nodeOrPackage, currentModule());
|
|
8691
|
+
else
|
|
8692
|
+
return isInModule(nodeOrPackage, currentModule());
|
|
8693
|
+
}
|
|
8694
|
+
|
|
8695
|
+
/*
|
|
8696
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
8697
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8698
|
+
* you may not use this file except in compliance with the License.
|
|
8699
|
+
* You may obtain a copy of the License at
|
|
8700
|
+
*
|
|
8701
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8702
|
+
*
|
|
8703
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
8704
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
8705
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8706
|
+
* See the License for the specific language governing permissions and
|
|
8707
|
+
* limitations under the License.
|
|
8708
|
+
*/
|
|
8709
|
+
({
|
|
8710
|
+
globals: lib$1.lens(lib$1.select.files())
|
|
8711
|
+
.pipe(lib$1.select.nodes())
|
|
8712
|
+
.pipe(lib$1.req('globals', (nodes) => {
|
|
8713
|
+
const result = [];
|
|
8714
|
+
const queue = [nodes];
|
|
8715
|
+
while (queue.length) {
|
|
8716
|
+
const line = {
|
|
8717
|
+
constants: [],
|
|
8718
|
+
methods: []
|
|
8719
|
+
};
|
|
8720
|
+
const next = queue.pop();
|
|
8721
|
+
next.forEach(node => {
|
|
8722
|
+
if (!isInCurrentModule(node))
|
|
8723
|
+
return;
|
|
8724
|
+
if (isNamespace(node)) {
|
|
8725
|
+
queue.push(node.members);
|
|
8726
|
+
}
|
|
8727
|
+
if (isConstant$1(node)) {
|
|
8728
|
+
line.constants.push(node);
|
|
8729
|
+
}
|
|
8730
|
+
if (isMethod(node)) {
|
|
8731
|
+
line.methods.push(node);
|
|
8732
|
+
}
|
|
8733
|
+
});
|
|
8734
|
+
if (line.constants.length || line.methods.length) {
|
|
8735
|
+
result.push(line);
|
|
8736
|
+
}
|
|
8737
|
+
}
|
|
8738
|
+
return result;
|
|
8739
|
+
}))
|
|
8740
|
+
});
|
|
8741
|
+
|
|
8742
|
+
var IDLValidationDiagnosticsCode;
|
|
8743
|
+
(function (IDLValidationDiagnosticsCode) {
|
|
8744
|
+
IDLValidationDiagnosticsCode[IDLValidationDiagnosticsCode["INVALID_EXTENDED_ATTRIBUTE"] = 1000] = "INVALID_EXTENDED_ATTRIBUTE";
|
|
8745
|
+
IDLValidationDiagnosticsCode[IDLValidationDiagnosticsCode["ENUM_IS_NOT_CONSISTENT"] = 1001] = "ENUM_IS_NOT_CONSISTENT";
|
|
8746
|
+
IDLValidationDiagnosticsCode[IDLValidationDiagnosticsCode["REFERENCE_IS_NOT_RESOLVED"] = 1002] = "REFERENCE_IS_NOT_RESOLVED";
|
|
8747
|
+
})(IDLValidationDiagnosticsCode || (IDLValidationDiagnosticsCode = {}));
|
|
8748
|
+
({
|
|
8749
|
+
[IDLValidationDiagnosticsCode.INVALID_EXTENDED_ATTRIBUTE]: "Invalid extended attribute",
|
|
8750
|
+
[IDLValidationDiagnosticsCode.ENUM_IS_NOT_CONSISTENT]: "Enum includes both string and number values",
|
|
8751
|
+
[IDLValidationDiagnosticsCode.REFERENCE_IS_NOT_RESOLVED]: "Can not resolve reference",
|
|
8752
|
+
});
|
|
8753
|
+
|
|
8754
|
+
/*
|
|
8755
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
8756
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8757
|
+
* you may not use this file except in compliance with the License.
|
|
8758
|
+
* You may obtain a copy of the License at
|
|
8759
|
+
*
|
|
8760
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8761
|
+
*
|
|
8762
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
8763
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
8764
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8765
|
+
* See the License for the specific language governing permissions and
|
|
8766
|
+
* limitations under the License.
|
|
8767
|
+
*/
|
|
8768
|
+
function isEnum(node) {
|
|
8769
|
+
return node.type === "enum";
|
|
8770
|
+
}
|
|
8771
|
+
function isInterface(node) {
|
|
8772
|
+
return node.type === "interface";
|
|
8773
|
+
}
|
|
8774
|
+
function isClass(node) {
|
|
8775
|
+
var _a, _b;
|
|
8776
|
+
return isInterface(node)
|
|
8777
|
+
&& ((_b = (_a = node.extAttrs.find(it => it.name === "Entity")) === null || _a === void 0 ? void 0 : _a.rhs) === null || _b === void 0 ? void 0 : _b.value) === IDLEntity.Class;
|
|
8778
|
+
}
|
|
8779
|
+
function isCallback(node) {
|
|
8780
|
+
return node.type === "callback";
|
|
8781
|
+
}
|
|
8782
|
+
function isTypedef(node) {
|
|
7487
8783
|
return node.type === "typedef";
|
|
7488
8784
|
}
|
|
7489
8785
|
function isDictionary(node) {
|
|
@@ -7578,8 +8874,12 @@ function addSyntheticType(name, type) {
|
|
|
7578
8874
|
syntheticTypes.set(name, type);
|
|
7579
8875
|
} // check
|
|
7580
8876
|
class IDLDeserializer {
|
|
7581
|
-
|
|
8877
|
+
enterGenericScope(generics) {
|
|
8878
|
+
this.genericsScopes.push(new Set(generics !== null && generics !== void 0 ? generics : []));
|
|
8879
|
+
}
|
|
8880
|
+
constructor(info, inheritanceMode = 'multiple') {
|
|
7582
8881
|
this.info = info;
|
|
8882
|
+
this.inheritanceMode = inheritanceMode;
|
|
7583
8883
|
this.namespacePathNames = [];
|
|
7584
8884
|
this.currentPackage = [];
|
|
7585
8885
|
this.genericsScopes = [];
|
|
@@ -7606,7 +8906,7 @@ class IDLDeserializer {
|
|
|
7606
8906
|
}
|
|
7607
8907
|
extractGenerics(extAttrs) {
|
|
7608
8908
|
var _a, _b;
|
|
7609
|
-
return
|
|
8909
|
+
return (_b = (_a = this.findExtendedAttribute(extAttrs, IDLExtendedAttributes.TypeParameters)) === null || _a === void 0 ? void 0 : _a.split(",")) === null || _b === void 0 ? void 0 : _b.map(it => this.sanitizeTypeParameter(it));
|
|
7610
8910
|
}
|
|
7611
8911
|
///
|
|
7612
8912
|
toIDLNode(file, node) {
|
|
@@ -7652,34 +8952,38 @@ class IDLDeserializer {
|
|
|
7652
8952
|
throw new Error(`unexpected node type: ${toString(node)}`);
|
|
7653
8953
|
}
|
|
7654
8954
|
toIDLImport(node) {
|
|
7655
|
-
// console.log(node)
|
|
7656
8955
|
return this.withInfo(node, createImport(node.clause.split("."), node.alias || undefined));
|
|
7657
8956
|
}
|
|
7658
8957
|
interfaceSubkind(node) {
|
|
7659
8958
|
var _a, _b;
|
|
7660
8959
|
const nodeIDLEntity = (_b = (_a = node.extAttrs.find(it => it.name === "Entity")) === null || _a === void 0 ? void 0 : _a.rhs) === null || _b === void 0 ? void 0 : _b.value;
|
|
7661
|
-
|
|
7662
|
-
return IDLInterfaceSubkind.Class;
|
|
7663
|
-
|
|
7664
|
-
return IDLInterfaceSubkind.
|
|
7665
|
-
|
|
7666
|
-
|
|
7667
|
-
return IDLInterfaceSubkind.Interface;
|
|
8960
|
+
switch (nodeIDLEntity) {
|
|
8961
|
+
case IDLEntity.Class: return IDLInterfaceSubkind.Class;
|
|
8962
|
+
case IDLEntity.Literal: return IDLInterfaceSubkind.AnonymousInterface;
|
|
8963
|
+
case IDLEntity.Tuple: return IDLInterfaceSubkind.Tuple;
|
|
8964
|
+
default: return IDLInterfaceSubkind.Interface;
|
|
8965
|
+
}
|
|
7668
8966
|
}
|
|
7669
8967
|
toIDLInterface(file, node) {
|
|
7670
|
-
var _a;
|
|
7671
8968
|
const generics = this.extractGenerics(node.extAttrs);
|
|
7672
|
-
this.
|
|
7673
|
-
const
|
|
7674
|
-
|
|
7675
|
-
if (!node.inheritance)
|
|
8969
|
+
this.enterGenericScope(generics);
|
|
8970
|
+
const subkind = this.interfaceSubkind(node);
|
|
8971
|
+
const result = createInterface(node.name, subkind, (() => {
|
|
8972
|
+
if (!node.inheritance) {
|
|
7676
8973
|
return [];
|
|
7677
|
-
|
|
7678
|
-
const
|
|
7679
|
-
|
|
7680
|
-
|
|
7681
|
-
|
|
7682
|
-
|
|
8974
|
+
}
|
|
8975
|
+
const implementations = [];
|
|
8976
|
+
node.inheritance.forEach(it => {
|
|
8977
|
+
var _a;
|
|
8978
|
+
const attributes = it.extAttrs;
|
|
8979
|
+
const parentTypeArgs = this.extractTypeArguments(file, attributes !== null && attributes !== void 0 ? attributes : [], IDLExtendedAttributes.TypeArguments);
|
|
8980
|
+
const attrs = (_a = this.toExtendedAttributes(attributes !== null && attributes !== void 0 ? attributes : [])) === null || _a === void 0 ? void 0 : _a.filter(it => it.name !== IDLExtendedAttributes.TypeArguments);
|
|
8981
|
+
const ref = createReferenceType(it.inheritance, parentTypeArgs, {
|
|
8982
|
+
extendedAttributes: attrs
|
|
8983
|
+
});
|
|
8984
|
+
implementations.push(ref);
|
|
8985
|
+
});
|
|
8986
|
+
return implementations;
|
|
7683
8987
|
})(), node.members
|
|
7684
8988
|
.filter(isConstructor)
|
|
7685
8989
|
.map(it => this.toIDLConstructor(file, it)), [], node.members
|
|
@@ -7690,7 +8994,7 @@ class IDLDeserializer {
|
|
|
7690
8994
|
.map(it => this.toIDLMethod(file, it, false)), node.members
|
|
7691
8995
|
.filter(isOperation)
|
|
7692
8996
|
.filter(it => this.isCallable(it))
|
|
7693
|
-
.map(it => this.toIDLCallable(file, it)),
|
|
8997
|
+
.map(it => this.toIDLCallable(file, it)), generics, {
|
|
7694
8998
|
fileName: file,
|
|
7695
8999
|
documentation: this.makeDocs(node),
|
|
7696
9000
|
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
@@ -7703,7 +9007,7 @@ class IDLDeserializer {
|
|
|
7703
9007
|
}
|
|
7704
9008
|
return result;
|
|
7705
9009
|
}
|
|
7706
|
-
toIDLType(file, type, extAttrs) {
|
|
9010
|
+
toIDLType(file, type, extAttrs, suggestedName) {
|
|
7707
9011
|
var _a;
|
|
7708
9012
|
if (typeof type === "string") {
|
|
7709
9013
|
// is it IDLStringType?
|
|
@@ -7723,7 +9027,7 @@ class IDLDeserializer {
|
|
|
7723
9027
|
types = types.filter(it => it !== IDLUndefinedType);
|
|
7724
9028
|
return this.withInfo(type, createOptionalType(collapseTypes(types)));
|
|
7725
9029
|
}
|
|
7726
|
-
const name = generateSyntheticUnionName(types);
|
|
9030
|
+
const name = suggestedName !== null && suggestedName !== void 0 ? suggestedName : generateSyntheticUnionName(types);
|
|
7727
9031
|
return this.withInfo(type, createUnionType(types, name));
|
|
7728
9032
|
}
|
|
7729
9033
|
if (isSingleTypeDescription(type)) {
|
|
@@ -7778,12 +9082,12 @@ class IDLDeserializer {
|
|
|
7778
9082
|
throw new Error(`unexpected type: ${toString(type)}`);
|
|
7779
9083
|
}
|
|
7780
9084
|
toIDLCallable(file, node) {
|
|
7781
|
-
var _a
|
|
9085
|
+
var _a;
|
|
7782
9086
|
if (!node.idlType) {
|
|
7783
9087
|
throw new Error(`method with no type ${toString(node)}`);
|
|
7784
9088
|
}
|
|
7785
9089
|
const generics = this.extractGenerics(node.extAttrs);
|
|
7786
|
-
this.
|
|
9090
|
+
this.enterGenericScope(generics);
|
|
7787
9091
|
const returnType = this.toIDLType(file, node.idlType, node.extAttrs);
|
|
7788
9092
|
if (isReferenceType(returnType)) {
|
|
7789
9093
|
const returnTypeArgs = this.extractTypeArguments(file, node.extAttrs, IDLExtendedAttributes.TypeArguments);
|
|
@@ -7795,17 +9099,17 @@ class IDLDeserializer {
|
|
|
7795
9099
|
}, {
|
|
7796
9100
|
documentation: this.makeDocs(node),
|
|
7797
9101
|
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7798
|
-
},
|
|
9102
|
+
}, generics));
|
|
7799
9103
|
this.genericsScopes.pop();
|
|
7800
9104
|
return result;
|
|
7801
9105
|
}
|
|
7802
9106
|
toIDLMethod(file, node, isFree = false) {
|
|
7803
|
-
var _a
|
|
9107
|
+
var _a;
|
|
7804
9108
|
if (!node.idlType) {
|
|
7805
9109
|
throw new Error(`method with no type ${toString(node)}`);
|
|
7806
9110
|
}
|
|
7807
9111
|
const generics = this.extractGenerics(node.extAttrs);
|
|
7808
|
-
this.
|
|
9112
|
+
this.enterGenericScope(generics);
|
|
7809
9113
|
const returnType = this.toIDLType(file, node.idlType, node.extAttrs);
|
|
7810
9114
|
if (isReferenceType(returnType))
|
|
7811
9115
|
returnType.typeArguments = this.extractTypeArguments(file, node.extAttrs, IDLExtendedAttributes.TypeArguments);
|
|
@@ -7817,7 +9121,7 @@ class IDLDeserializer {
|
|
|
7817
9121
|
}, {
|
|
7818
9122
|
documentation: this.makeDocs(node),
|
|
7819
9123
|
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7820
|
-
},
|
|
9124
|
+
}, generics));
|
|
7821
9125
|
this.genericsScopes.pop();
|
|
7822
9126
|
return result;
|
|
7823
9127
|
}
|
|
@@ -7832,22 +9136,24 @@ class IDLDeserializer {
|
|
|
7832
9136
|
}));
|
|
7833
9137
|
}
|
|
7834
9138
|
toIDLCallback(file, node) {
|
|
9139
|
+
const generics = this.extractGenerics(node.extAttrs);
|
|
9140
|
+
this.enterGenericScope(generics);
|
|
7835
9141
|
const result = createCallback(node.name, node.arguments.map(it => this.toIDLParameter(file, it)), this.toIDLType(file, node.idlType, undefined), {
|
|
7836
9142
|
fileName: file,
|
|
7837
9143
|
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7838
9144
|
documentation: this.makeDocs(node),
|
|
7839
|
-
});
|
|
9145
|
+
}, generics);
|
|
7840
9146
|
if (node.extAttrs.find(it => it.name === "Synthetic")) {
|
|
7841
9147
|
const fqName = this.currentPackage.concat(this.namespacePathNames).concat([node.name]).join('.');
|
|
7842
9148
|
addSyntheticType(fqName, result);
|
|
7843
9149
|
}
|
|
9150
|
+
this.genericsScopes.pop();
|
|
7844
9151
|
return this.withInfo(node, result);
|
|
7845
9152
|
}
|
|
7846
9153
|
toIDLTypedef(file, node) {
|
|
7847
|
-
var _a;
|
|
7848
9154
|
const generics = this.extractGenerics(node.extAttrs);
|
|
7849
|
-
this.
|
|
7850
|
-
const result = this.withInfo(node, createTypedef(node.name, this.toIDLType(file, node.idlType, undefined
|
|
9155
|
+
this.enterGenericScope(generics);
|
|
9156
|
+
const result = this.withInfo(node, createTypedef(node.name, this.toIDLType(file, node.idlType, undefined, node.name), generics, {
|
|
7851
9157
|
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7852
9158
|
documentation: this.makeDocs(node),
|
|
7853
9159
|
fileName: file,
|
|
@@ -7903,7 +9209,7 @@ class IDLDeserializer {
|
|
|
7903
9209
|
initializer = undefined;
|
|
7904
9210
|
}
|
|
7905
9211
|
else {
|
|
7906
|
-
throw new Error(`Not representable enum initializer: ${node.default}`);
|
|
9212
|
+
throw new Error(`Not representable enum initializer: ${JSON.stringify(node.default)}. Found in ${file}`);
|
|
7907
9213
|
}
|
|
7908
9214
|
return this.withInfo(node, createEnumMember(node.name, parent, this.toIDLType(file, node.idlType, undefined), initializer, {
|
|
7909
9215
|
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
@@ -7946,17 +9252,39 @@ class IDLDeserializer {
|
|
|
7946
9252
|
return node.type === 'import';
|
|
7947
9253
|
}
|
|
7948
9254
|
isCallable(node) {
|
|
7949
|
-
return node.extAttrs.some(it => it.name ==
|
|
9255
|
+
return node.extAttrs.some(it => it.name == IDLExtendedAttributes.CallSignature);
|
|
7950
9256
|
}
|
|
7951
9257
|
///
|
|
9258
|
+
splitTypeArguments(line) {
|
|
9259
|
+
let buffer = "";
|
|
9260
|
+
let brackets = 0;
|
|
9261
|
+
const result = [];
|
|
9262
|
+
for (const letter of line) {
|
|
9263
|
+
if (letter === ',' && brackets === 0) {
|
|
9264
|
+
result.push(buffer);
|
|
9265
|
+
buffer = '';
|
|
9266
|
+
continue;
|
|
9267
|
+
}
|
|
9268
|
+
if (letter === '<') {
|
|
9269
|
+
brackets += 1;
|
|
9270
|
+
}
|
|
9271
|
+
if (letter === '>') {
|
|
9272
|
+
brackets -= 1;
|
|
9273
|
+
}
|
|
9274
|
+
buffer += letter;
|
|
9275
|
+
}
|
|
9276
|
+
if (buffer.length) {
|
|
9277
|
+
result.push(buffer);
|
|
9278
|
+
}
|
|
9279
|
+
return result;
|
|
9280
|
+
}
|
|
7952
9281
|
extractTypeArguments(file, extAttrs, attribute) {
|
|
7953
9282
|
var _a;
|
|
7954
9283
|
const attr = extAttrs === null || extAttrs === void 0 ? void 0 : extAttrs.find(it => it.name === attribute);
|
|
7955
9284
|
if (!attr)
|
|
7956
9285
|
return undefined;
|
|
7957
9286
|
let value = this.toExtendedAttributeValue(attr);
|
|
7958
|
-
return (_a = value === null ||
|
|
7959
|
-
) === null || _a === void 0 ? void 0 : _a.map(it => { var _a; return this.toIDLType(file, (_a = parseType(it, file)) !== null && _a !== void 0 ? _a : it); });
|
|
9287
|
+
return (_a = this.splitTypeArguments(value)) === null || _a === void 0 ? void 0 : _a.map(it => { var _a; return this.toIDLType(file, (_a = parseType(it.replaceAll('\'', '"'), file)) !== null && _a !== void 0 ? _a : it); });
|
|
7960
9288
|
}
|
|
7961
9289
|
constantValue(node) {
|
|
7962
9290
|
switch (node.value.type) {
|
|
@@ -8025,9 +9353,9 @@ class IDLDeserializer {
|
|
|
8025
9353
|
return attr ? this.toExtendedAttributeValue(attr) : undefined;
|
|
8026
9354
|
}
|
|
8027
9355
|
}
|
|
8028
|
-
function toIDLFile(fileName, content) {
|
|
9356
|
+
function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } = {}) {
|
|
8029
9357
|
const lexicalInfo = new Map();
|
|
8030
|
-
const deserializer = new IDLDeserializer(lexicalInfo);
|
|
9358
|
+
const deserializer = new IDLDeserializer(lexicalInfo, inheritanceMode);
|
|
8031
9359
|
if (undefined === content)
|
|
8032
9360
|
content = fs__namespace.readFileSync(fileName).toString();
|
|
8033
9361
|
let packageClause = [];
|
|
@@ -8088,10 +9416,10 @@ class BridgesConstructions {
|
|
|
8088
9416
|
return `result`;
|
|
8089
9417
|
}
|
|
8090
9418
|
static stringConstructor(name) {
|
|
8091
|
-
return `
|
|
9419
|
+
return `StageArena::strdup(${name})`;
|
|
8092
9420
|
}
|
|
8093
9421
|
static sequenceConstructor(first, length) {
|
|
8094
|
-
return `
|
|
9422
|
+
return `StageArena::cloneVector(${first}, ${length})`;
|
|
8095
9423
|
}
|
|
8096
9424
|
static referenceTypeCast(type) {
|
|
8097
9425
|
return `reinterpret_cast<${type}>`;
|
|
@@ -8146,10 +9474,11 @@ class BridgesConstructions {
|
|
|
8146
9474
|
* limitations under the License.
|
|
8147
9475
|
*/
|
|
8148
9476
|
class Config {
|
|
8149
|
-
constructor(ignore, nonNullable, irHack) {
|
|
9477
|
+
constructor(ignore, nonNullable, irHack, fragments) {
|
|
8150
9478
|
this.ignore = ignore;
|
|
8151
9479
|
this.nonNullable = nonNullable;
|
|
8152
9480
|
this.irHack = irHack;
|
|
9481
|
+
this.fragments = fragments;
|
|
8153
9482
|
}
|
|
8154
9483
|
static get createPrefix() {
|
|
8155
9484
|
return `Create`;
|
|
@@ -8518,11 +9847,11 @@ class Typechecker {
|
|
|
8518
9847
|
if (declaration === undefined || !isInterface$1(declaration)) {
|
|
8519
9848
|
return false;
|
|
8520
9849
|
}
|
|
8521
|
-
|
|
8522
|
-
|
|
8523
|
-
|
|
8524
|
-
}
|
|
8525
|
-
return
|
|
9850
|
+
let isHeir = declaration.name === ancestor;
|
|
9851
|
+
declaration.inheritance.forEach(parent => {
|
|
9852
|
+
isHeir || (isHeir = this.isHeir(parent.name, ancestor));
|
|
9853
|
+
});
|
|
9854
|
+
return isHeir;
|
|
8526
9855
|
}
|
|
8527
9856
|
isPeer(node) {
|
|
8528
9857
|
if (node === Config.astNodeCommonAncestor)
|
|
@@ -8533,6 +9862,11 @@ class Typechecker {
|
|
|
8533
9862
|
return true;
|
|
8534
9863
|
if (this.isHeir(node, Config.defaultAncestor))
|
|
8535
9864
|
return true;
|
|
9865
|
+
// TODO: fix
|
|
9866
|
+
if (node === "Program")
|
|
9867
|
+
return true;
|
|
9868
|
+
if (node === "ArkTsConfig")
|
|
9869
|
+
return true;
|
|
8536
9870
|
return false;
|
|
8537
9871
|
}
|
|
8538
9872
|
isReferenceTo(type, isTarget) {
|
|
@@ -8556,6 +9890,29 @@ class Typechecker {
|
|
|
8556
9890
|
.find(it => it.name === Config.nodeTypeAttribute);
|
|
8557
9891
|
return (_b = (_a = idlEnum === null || idlEnum === void 0 ? void 0 : idlEnum.elements) === null || _a === void 0 ? void 0 : _a.find(it => { var _a; return ((_a = it.initializer) === null || _a === void 0 ? void 0 : _a.toString()) === value; })) === null || _b === void 0 ? void 0 : _b.name;
|
|
8558
9892
|
}
|
|
9893
|
+
parent(node) {
|
|
9894
|
+
const parentName = parent(node);
|
|
9895
|
+
if (parentName === undefined)
|
|
9896
|
+
return undefined;
|
|
9897
|
+
const decl = this.findRealDeclaration(parentName);
|
|
9898
|
+
if (decl === undefined)
|
|
9899
|
+
return undefined;
|
|
9900
|
+
if (!isInterface$1(decl))
|
|
9901
|
+
return undefined;
|
|
9902
|
+
return decl;
|
|
9903
|
+
}
|
|
9904
|
+
ancestry(node) {
|
|
9905
|
+
let current = node;
|
|
9906
|
+
const res = [];
|
|
9907
|
+
while (true) {
|
|
9908
|
+
res.push(current);
|
|
9909
|
+
const parent = this.parent(current);
|
|
9910
|
+
if (parent === undefined) {
|
|
9911
|
+
return res;
|
|
9912
|
+
}
|
|
9913
|
+
current = parent;
|
|
9914
|
+
}
|
|
9915
|
+
}
|
|
8559
9916
|
}
|
|
8560
9917
|
|
|
8561
9918
|
/*
|
|
@@ -8607,6 +9964,7 @@ class SingleFilePrinter extends AbstractVisitor {
|
|
|
8607
9964
|
this.epilogue();
|
|
8608
9965
|
return [
|
|
8609
9966
|
(_b = (_a = this.importer) === null || _a === void 0 ? void 0 : _a.getOutput()) !== null && _b !== void 0 ? _b : [],
|
|
9967
|
+
[''],
|
|
8610
9968
|
this.writer.getOutput()
|
|
8611
9969
|
]
|
|
8612
9970
|
.flat()
|
|
@@ -8693,6 +10051,7 @@ class BaseTypeConvertor {
|
|
|
8693
10051
|
case IDLStringType: return this.conversions.string(type);
|
|
8694
10052
|
case IDLVoidType: return this.conversions.void(type);
|
|
8695
10053
|
case IDLPointerType: return this.conversions.pointer(type);
|
|
10054
|
+
case IDLUndefinedType: return this.conversions.undefined(type);
|
|
8696
10055
|
}
|
|
8697
10056
|
throwException(`unsupported primitive type: ${JSON.stringify(type)}`);
|
|
8698
10057
|
}
|
|
@@ -8758,7 +10117,8 @@ let ReturnTypeConvertor$1 = class ReturnTypeConvertor extends BaseTypeConvertor
|
|
|
8758
10117
|
f64: (type) => type,
|
|
8759
10118
|
boolean: (type) => type,
|
|
8760
10119
|
void: (type) => type,
|
|
8761
|
-
pointer: (type) => type
|
|
10120
|
+
pointer: (type) => type,
|
|
10121
|
+
undefined: (type) => type
|
|
8762
10122
|
});
|
|
8763
10123
|
}
|
|
8764
10124
|
};
|
|
@@ -8779,7 +10139,7 @@ let ReturnTypeConvertor$1 = class ReturnTypeConvertor extends BaseTypeConvertor
|
|
|
8779
10139
|
*/
|
|
8780
10140
|
class InteropTypeConvertor extends BaseTypeConvertor {
|
|
8781
10141
|
constructor(typechecker, heirConversions) {
|
|
8782
|
-
super(typechecker, Object.assign({ enum: (type) => `KInt`, reference: (type) => `KNativePointer`, optional: (type) => throwException(`no nullable allowed at interop level`), i8: (type) => `KBoolean`, iu8: (type) => 'KInt', i16: (type) => `KInt`, i32: (type) => `KInt`, iu32: (type) => `KUInt`, i64: (type) => `KLong`, iu64: (type) => `KULong`, f32: (type) => `KFloat`, f64: (type) => `KDouble`, boolean: (type) => `KBoolean`, void: (type) => `void`, pointer: (type) => `KNativePointer` }, heirConversions));
|
|
10142
|
+
super(typechecker, Object.assign({ enum: (type) => `KInt`, reference: (type) => `KNativePointer`, optional: (type) => throwException(`no nullable allowed at interop level`), undefined: (type) => throwException(`no nullable allowed at interop level`), i8: (type) => `KBoolean`, iu8: (type) => 'KInt', i16: (type) => `KInt`, i32: (type) => `KInt`, iu32: (type) => `KUInt`, i64: (type) => `KLong`, iu64: (type) => `KULong`, f32: (type) => `KFloat`, f64: (type) => `KDouble`, boolean: (type) => `KBoolean`, void: (type) => `void`, pointer: (type) => `KNativePointer` }, heirConversions));
|
|
8783
10143
|
}
|
|
8784
10144
|
}
|
|
8785
10145
|
|
|
@@ -8863,7 +10223,8 @@ class CastTypeConvertor extends BaseTypeConvertor {
|
|
|
8863
10223
|
string: (type) => BridgesConstructions.stringCast,
|
|
8864
10224
|
optional: (type) => throwException(`no optional type allowed at interop level conversion`),
|
|
8865
10225
|
void: (type) => throwException(`no void typed parameters allowed`),
|
|
8866
|
-
pointer: (type) => throwException(`no pointer typed parameters allowed`)
|
|
10226
|
+
pointer: (type) => throwException(`no pointer typed parameters allowed`),
|
|
10227
|
+
undefined: (type) => throwException(`no undefined typed parameters allowed`)
|
|
8867
10228
|
});
|
|
8868
10229
|
this.castToTypeConvertor = new CastToTypeConvertor(this.typechecker);
|
|
8869
10230
|
}
|
|
@@ -8892,7 +10253,8 @@ class CastToTypeConvertor extends BaseTypeConvertor {
|
|
|
8892
10253
|
optional: (type) => throwException(`no optional type allowed at interop level conversion`),
|
|
8893
10254
|
string: (type) => "const char*",
|
|
8894
10255
|
void: (type) => throwException(`no void typed parameters allowed`),
|
|
8895
|
-
pointer: (type) => throwException(`no pointer typed parameters allowed`)
|
|
10256
|
+
pointer: (type) => throwException(`no pointer typed parameters allowed`),
|
|
10257
|
+
undefined: (type) => throwException(`no undefined typed parameters allowed`)
|
|
8896
10258
|
});
|
|
8897
10259
|
this.nativeTypeConvertor = new NativeTypeConvertor(this.typechecker);
|
|
8898
10260
|
}
|
|
@@ -9170,7 +10532,8 @@ class ReturnTypeConvertor extends BaseTypeConvertor {
|
|
|
9170
10532
|
boolean: (type) => type,
|
|
9171
10533
|
string: (type) => type,
|
|
9172
10534
|
void: (type) => type,
|
|
9173
|
-
pointer: (type) => type
|
|
10535
|
+
pointer: (type) => type,
|
|
10536
|
+
undefined: (type) => throwException(`undefined type is not allowed`)
|
|
9174
10537
|
});
|
|
9175
10538
|
}
|
|
9176
10539
|
}
|
|
@@ -9337,6 +10700,9 @@ class PeersConstructions {
|
|
|
9337
10700
|
static callPeerMethod(iface, method) {
|
|
9338
10701
|
return `${iface}.${method}`;
|
|
9339
10702
|
}
|
|
10703
|
+
static brand(iface) {
|
|
10704
|
+
return `brand${capitalize(iface)}`;
|
|
10705
|
+
}
|
|
9340
10706
|
}
|
|
9341
10707
|
|
|
9342
10708
|
/*
|
|
@@ -9385,6 +10751,14 @@ class Importer {
|
|
|
9385
10751
|
this.import(it, `../Es2pandaEnums`);
|
|
9386
10752
|
return it;
|
|
9387
10753
|
}
|
|
10754
|
+
withReexportImport(it) {
|
|
10755
|
+
if (this.seen.has(it)) {
|
|
10756
|
+
return it;
|
|
10757
|
+
}
|
|
10758
|
+
this.seen.add(it);
|
|
10759
|
+
this.import(it, "../../reexport-for-generated");
|
|
10760
|
+
return it;
|
|
10761
|
+
}
|
|
9388
10762
|
import(name, from) {
|
|
9389
10763
|
this.writer.writeExpressionStatement(this.writer.makeString(PeersConstructions.import(name, path__namespace$1.normalize(path__namespace$1.join(this.dir, from)))));
|
|
9390
10764
|
}
|
|
@@ -9421,7 +10795,8 @@ class TopLevelTypeConvertor extends BaseTypeConvertor {
|
|
|
9421
10795
|
f64: heirConversions.number,
|
|
9422
10796
|
void: heirConversions.void,
|
|
9423
10797
|
boolean: heirConversions.boolean,
|
|
9424
|
-
pointer: heirConversions.pointer
|
|
10798
|
+
pointer: heirConversions.pointer,
|
|
10799
|
+
undefined: heirConversions.undefined
|
|
9425
10800
|
}));
|
|
9426
10801
|
}
|
|
9427
10802
|
}
|
|
@@ -9451,7 +10826,8 @@ class LibraryTypeConvertor extends TopLevelTypeConvertor {
|
|
|
9451
10826
|
number: (type) => `number`,
|
|
9452
10827
|
void: (type) => `void`,
|
|
9453
10828
|
boolean: (type) => `boolean`,
|
|
9454
|
-
pointer: (type) => `KNativePointer
|
|
10829
|
+
pointer: (type) => `KNativePointer`,
|
|
10830
|
+
undefined: (type) => `undefined`
|
|
9455
10831
|
});
|
|
9456
10832
|
}
|
|
9457
10833
|
}
|
|
@@ -9493,7 +10869,8 @@ class ImporterTypeConvertor extends TopLevelTypeConvertor {
|
|
|
9493
10869
|
number: (type) => type,
|
|
9494
10870
|
boolean: (type) => type,
|
|
9495
10871
|
void: (type) => type,
|
|
9496
|
-
pointer: (type) => type
|
|
10872
|
+
pointer: (type) => type,
|
|
10873
|
+
undefined: (type) => type
|
|
9497
10874
|
});
|
|
9498
10875
|
this.importer = importer;
|
|
9499
10876
|
}
|
|
@@ -9533,6 +10910,7 @@ class BindingParameterTypeConvertor extends TopLevelTypeConvertor {
|
|
|
9533
10910
|
void: (type) => (parameter) => parameter,
|
|
9534
10911
|
pointer: (type) => (parameter) => parameter,
|
|
9535
10912
|
boolean: (type) => (parameter) => parameter,
|
|
10913
|
+
undefined: (type) => (parameter) => parameter
|
|
9536
10914
|
});
|
|
9537
10915
|
}
|
|
9538
10916
|
}
|
|
@@ -9575,6 +10953,7 @@ class BindingReturnValueTypeConvertor extends TopLevelTypeConvertor {
|
|
|
9575
10953
|
void: plain,
|
|
9576
10954
|
pointer: plain,
|
|
9577
10955
|
boolean: plain,
|
|
10956
|
+
undefined: plain
|
|
9578
10957
|
});
|
|
9579
10958
|
}
|
|
9580
10959
|
}
|
|
@@ -9609,6 +10988,7 @@ class PeerPrinter extends SingleFilePrinter {
|
|
|
9609
10988
|
return node != this.node;
|
|
9610
10989
|
}
|
|
9611
10990
|
constructor(config, idl, node) {
|
|
10991
|
+
var _a;
|
|
9612
10992
|
super(idl);
|
|
9613
10993
|
this.config = config;
|
|
9614
10994
|
this.node = node;
|
|
@@ -9616,7 +10996,7 @@ class PeerPrinter extends SingleFilePrinter {
|
|
|
9616
10996
|
this.importer = new Importer(this.typechecker, `.`, this.node.name);
|
|
9617
10997
|
this.bindingParameterTypeConvertor = new BindingParameterTypeConvertor(this.typechecker);
|
|
9618
10998
|
this.bindingReturnValueTypeConvertor = new BindingReturnValueTypeConvertor(this.typechecker);
|
|
9619
|
-
this.parent = parent(this.node)
|
|
10999
|
+
this.parent = (_a = parent(this.node)) !== null && _a !== void 0 ? _a : Config.defaultAncestor;
|
|
9620
11000
|
this.writer = new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => composedConvertType(new LibraryTypeConvertor(this.typechecker), new ImporterTypeConvertor(this.importer, this.typechecker), node)
|
|
9621
11001
|
});
|
|
9622
11002
|
}
|
|
@@ -9626,6 +11006,8 @@ class PeerPrinter extends SingleFilePrinter {
|
|
|
9626
11006
|
printBody() {
|
|
9627
11007
|
this.printConstructor();
|
|
9628
11008
|
this.printMethods();
|
|
11009
|
+
this.printFragment();
|
|
11010
|
+
this.printBrand();
|
|
9629
11011
|
}
|
|
9630
11012
|
printConstructor() {
|
|
9631
11013
|
this.writer.writeConstructorImplementation(this.node.name, new MethodSignature(IDLVoidType, [
|
|
@@ -9666,6 +11048,15 @@ class PeerPrinter extends SingleFilePrinter {
|
|
|
9666
11048
|
}
|
|
9667
11049
|
});
|
|
9668
11050
|
}
|
|
11051
|
+
printFragment() {
|
|
11052
|
+
const methods = this.config.fragments.getCodeFragment(this.node.name);
|
|
11053
|
+
if (methods !== undefined) {
|
|
11054
|
+
methods.forEach(it => {
|
|
11055
|
+
this.importer.withReexportImport(it.definition);
|
|
11056
|
+
this.writer.writeLines(`${it.name} = ${it.definition}`);
|
|
11057
|
+
});
|
|
11058
|
+
}
|
|
11059
|
+
}
|
|
9669
11060
|
printGetter(node) {
|
|
9670
11061
|
this.writer.writeMethodImplementation(new Method(peerMethod(node.name), new MethodSignature(flattenType(node.returnType), []), [MethodModifier.GETTER]), () => {
|
|
9671
11062
|
this.writer.writeStatement(this.writer.makeReturn(this.makeReturnBindingCall(node)));
|
|
@@ -9687,9 +11078,13 @@ class PeerPrinter extends SingleFilePrinter {
|
|
|
9687
11078
|
}
|
|
9688
11079
|
printCreateOrUpdate(node) {
|
|
9689
11080
|
this.writer.writeMethodImplementation(makeMethod(PeersConstructions.createOrUpdate(this.node.name, node.name), node.parameters.map(it => createParameter(it.name, flattenType(it.type))), flattenType(node.returnType), [MethodModifier.STATIC]), () => {
|
|
9690
|
-
this.writer.
|
|
11081
|
+
const newExpr = this.writer.makeNewObject(this.node.name, [
|
|
9691
11082
|
this.writer.makeFunctionCall(this.writer.makeString(PeersConstructions.callBinding(this.node.name, node.name, nodeNamespace(this.node))), this.makeBindingArguments(node.parameters))
|
|
9692
|
-
])
|
|
11083
|
+
]);
|
|
11084
|
+
const isAstNode = this.node.inheritance.some(parent => this.typechecker.isHeir(parent.name, Config.astNodeCommonAncestor));
|
|
11085
|
+
const updateMethodName = 'updateChildren';
|
|
11086
|
+
this.writer.writeStatement(this.writer.makeReturn(isAstNode ?
|
|
11087
|
+
this.writer.makeMethodCall(newExpr.asString(), updateMethodName, []) : newExpr));
|
|
9693
11088
|
});
|
|
9694
11089
|
}
|
|
9695
11090
|
makeBindingArguments(parameters) {
|
|
@@ -9709,6 +11104,9 @@ class PeerPrinter extends SingleFilePrinter {
|
|
|
9709
11104
|
const qualified = `${this.importer.withEnumImport(Config.nodeTypeAttribute)}.${enumValue}`;
|
|
9710
11105
|
this.writer.writeExpressionStatements(this.writer.makeString(`if (!nodeByType.has(${qualified})) {`), this.writer.makeString(` nodeByType.set(${qualified}, (peer: KNativePointer) => new ${this.node.name}(peer))`), this.writer.makeString(`}`));
|
|
9711
11106
|
}
|
|
11107
|
+
printBrand() {
|
|
11108
|
+
this.writer.writeProperty(PeersConstructions.brand(this.node.name), IDLUndefinedType, [FieldModifier.PROTECTED, FieldModifier.READONLY]);
|
|
11109
|
+
}
|
|
9712
11110
|
}
|
|
9713
11111
|
|
|
9714
11112
|
/*
|
|
@@ -10021,9 +11419,8 @@ class AddContextDeclarationTransformer extends Transformer {
|
|
|
10021
11419
|
name: Config.nodeNamespaceAttribute,
|
|
10022
11420
|
value: Config.irNamespace
|
|
10023
11421
|
}]
|
|
10024
|
-
})));
|
|
10025
|
-
linkParentBack(file);
|
|
10026
|
-
return file;
|
|
11422
|
+
})), this.file.fileName, this.file.packageClause);
|
|
11423
|
+
return linkParentBack(file);
|
|
10027
11424
|
}
|
|
10028
11425
|
}
|
|
10029
11426
|
|
|
@@ -10209,6 +11606,11 @@ class AstNodeFilterTransformer extends BaseInterfaceFilterTransformer {
|
|
|
10209
11606
|
return false;
|
|
10210
11607
|
if (this.typechecker.isHeir(name, Config.defaultAncestor))
|
|
10211
11608
|
return false;
|
|
11609
|
+
// TODO: fix
|
|
11610
|
+
if (name === "Program")
|
|
11611
|
+
return false;
|
|
11612
|
+
if (name === "ArkTsConfig")
|
|
11613
|
+
return false;
|
|
10212
11614
|
console.log(`FILTERED (AST) ${name}`);
|
|
10213
11615
|
return true;
|
|
10214
11616
|
}
|
|
@@ -12228,6 +13630,35 @@ class NonNullableOptions {
|
|
|
12228
13630
|
}
|
|
12229
13631
|
}
|
|
12230
13632
|
|
|
13633
|
+
/*
|
|
13634
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
|
13635
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13636
|
+
* you may not use this file except in compliance with the License.
|
|
13637
|
+
* You may obtain a copy of the License at
|
|
13638
|
+
*
|
|
13639
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13640
|
+
*
|
|
13641
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13642
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13643
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13644
|
+
* See the License for the specific language governing permissions and
|
|
13645
|
+
* limitations under the License.
|
|
13646
|
+
*/
|
|
13647
|
+
class CodeFragmentOptions {
|
|
13648
|
+
constructor(filePath) {
|
|
13649
|
+
var _a;
|
|
13650
|
+
this.fragments = [];
|
|
13651
|
+
if (filePath === undefined) {
|
|
13652
|
+
return;
|
|
13653
|
+
}
|
|
13654
|
+
this.fragments = (_a = lib.parse(fs__namespace$1.readFileSync(filePath).toString()).fragments) !== null && _a !== void 0 ? _a : [];
|
|
13655
|
+
}
|
|
13656
|
+
getCodeFragment(name) {
|
|
13657
|
+
var _a;
|
|
13658
|
+
return (_a = this.fragments.find(it => it.interface === name)) === null || _a === void 0 ? void 0 : _a.methods;
|
|
13659
|
+
}
|
|
13660
|
+
}
|
|
13661
|
+
|
|
12231
13662
|
/*
|
|
12232
13663
|
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
12233
13664
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -12248,7 +13679,7 @@ function main() {
|
|
|
12248
13679
|
if (options.initialize) {
|
|
12249
13680
|
new StaticEmitter(options.outputDir, options.pandaSdkPath).emit();
|
|
12250
13681
|
}
|
|
12251
|
-
new DynamicEmitter(options.outputDir, toIDLFile(path__namespace$1.join(options.pandaSdkPath, pandaSdkIdlFilePath))[0], new Config(new IgnoreOptions(options.optionsFile), new NonNullableOptions(options.optionsFile), new IrHackOptions(options.optionsFile)), options.debug).emit();
|
|
13682
|
+
new DynamicEmitter(options.outputDir, toIDLFile(path__namespace$1.join(options.pandaSdkPath, pandaSdkIdlFilePath), { inheritanceMode: 'single' })[0], new Config(new IgnoreOptions(options.optionsFile), new NonNullableOptions(options.optionsFile), new IrHackOptions(options.optionsFile), new CodeFragmentOptions(options.optionsFile)), options.debug).emit();
|
|
12252
13683
|
}
|
|
12253
13684
|
main();
|
|
12254
13685
|
//# sourceMappingURL=index.js.map
|