@idlizer/arktscgen 2.1.2 → 2.1.5
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/README.md +36 -0
- package/build/libarkts-copy/generator/options.json5 +113 -44
- package/build/libarkts-copy/native/src/bridges.cc +70 -2
- package/build/libarkts-copy/native/src/generated/bridges.cc +700 -200
- package/build/libarkts-copy/package.json +27 -15
- package/build/libarkts-copy/src/Es2pandaNativeModule.ts +42 -4
- package/build/libarkts-copy/src/InteropNativeModule.ts +2 -1
- package/build/libarkts-copy/src/arkts-api/AbstractVisitor.ts +50 -0
- package/build/libarkts-copy/src/arkts-api/class-by-peer.ts +8 -6
- package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +95 -117
- package/build/libarkts-copy/src/arkts-api/index.ts +3 -1
- package/build/libarkts-copy/src/arkts-api/node-cache.ts +35 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ArrayExpression.ts +42 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ArrowFunctionExpression.ts +49 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/AssignmentExpression.ts +50 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/{createCallExpression.ts → CallExpression.ts} +27 -4
- package/build/libarkts-copy/src/arkts-api/node-utilities/ClassDefinition.ts +73 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ClassProperty.ts +41 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSFunctionType.ts +65 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSImportDeclaration.ts +63 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSParameterExpression.ts +60 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSStructDeclaration.ts +31 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSTuple.ts +31 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/MemberExpression.ts +41 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/MethodDefinition.ts +75 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/{createNumberLiteral.ts → NumberLiteral.ts} +15 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ObjectExpression.ts +34 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ScriptFunction.ts +99 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSInterfaceDeclaration.ts +61 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSTypeAliasDeclaration.ts +60 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSTypeParameter.ts +39 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSTypeReferencePart.ts +36 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TryStatement.ts +44 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/VariableDeclaration.ts +54 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/VariableDeclarator.ts +37 -0
- package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +15 -14
- package/build/libarkts-copy/src/arkts-api/peers/ImportPathManager.ts +30 -0
- package/build/libarkts-copy/src/arkts-api/peers/Program.ts +4 -4
- package/build/libarkts-copy/src/arkts-api/peers/SourcePosition.ts +38 -0
- package/build/libarkts-copy/src/arkts-api/static/global.ts +5 -0
- package/build/libarkts-copy/src/arkts-api/static/profiler.ts +25 -0
- package/build/libarkts-copy/src/arkts-api/utilities/private.ts +13 -11
- package/build/libarkts-copy/src/arkts-api/utilities/public.ts +68 -10
- package/build/libarkts-copy/src/arkts-api/visitor.ts +175 -42
- package/build/libarkts-copy/src/generated/Es2pandaEnums.ts +504 -458
- package/build/libarkts-copy/src/generated/Es2pandaNativeModule.ts +225 -75
- package/build/libarkts-copy/src/generated/factory.ts +21 -43
- package/build/libarkts-copy/src/generated/index.ts +24 -3
- package/build/libarkts-copy/src/generated/peers/AnnotatedAstNode.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/AnnotatedExpression.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/AnnotatedStatement.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/AnnotationDeclaration.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/AnnotationUsage.ts +12 -12
- package/build/libarkts-copy/src/generated/peers/ArrayExpression.ts +10 -5
- package/build/libarkts-copy/src/generated/peers/ArrowFunctionExpression.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/AssertStatement.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/AssignmentExpression.ts +13 -7
- package/build/libarkts-copy/src/generated/peers/AstDumper.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/AstVerifier.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/AstVisitor.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/AwaitExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/BigIntLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/BinaryExpression.ts +14 -7
- package/build/libarkts-copy/src/generated/peers/BindingProps.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/BlockExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/BlockStatement.ts +15 -5
- package/build/libarkts-copy/src/generated/peers/BooleanLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/BreakStatement.ts +8 -5
- package/build/libarkts-copy/src/generated/peers/CallExpression.ts +8 -8
- package/build/libarkts-copy/src/generated/peers/CatchClause.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/ChainExpression.ts +12 -5
- package/build/libarkts-copy/src/generated/peers/CharLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ClassDeclaration.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ClassDefinition.ts +30 -15
- package/build/libarkts-copy/src/generated/peers/ClassElement.ts +7 -8
- package/build/libarkts-copy/src/generated/peers/ClassExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ClassProperty.ts +21 -5
- package/build/libarkts-copy/src/generated/peers/ClassStaticBlock.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/CodeGen.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/ConditionalExpression.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/ContinueStatement.ts +8 -5
- package/build/libarkts-copy/src/generated/peers/DebuggerStatement.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/Declaration.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/Decorator.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/DirectEvalExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/DoWhileStatement.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/DynamicImportData.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/ETSClassLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ETSDynamicFunctionType.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/ETSFunctionType.ts +15 -15
- package/build/libarkts-copy/src/generated/peers/ETSImportDeclaration.ts +26 -17
- package/build/libarkts-copy/src/generated/peers/ETSKeyofType.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/ETSModule.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/ETSNewArrayInstanceExpression.ts +11 -6
- package/build/libarkts-copy/src/generated/peers/ETSNewClassInstanceExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ETSNewMultiDimArrayInstanceExpression.ts +11 -6
- package/build/libarkts-copy/src/generated/peers/ETSNullType.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/ETSPackageDeclaration.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ETSParameterExpression.ts +10 -10
- package/build/libarkts-copy/src/generated/peers/ETSPrimitiveType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ETSReExportDeclaration.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ETSStringLiteralType.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/ETSStructDeclaration.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ETSTuple.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ETSTypeReference.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ETSTypeReferencePart.ts +8 -8
- package/build/libarkts-copy/src/generated/peers/ETSUndefinedType.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/ETSUnionType.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/ETSWildcardType.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/EmptyStatement.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ErrorLogger.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/ExportAllDeclaration.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ExportDefaultDeclaration.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ExportNamedDeclaration.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ExportSpecifier.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/Expression.ts +4 -5
- package/build/libarkts-copy/src/generated/peers/ExpressionStatement.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/ForInStatement.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/ForOfStatement.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/ForUpdateStatement.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/FunctionDecl.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/FunctionDeclaration.ts +8 -8
- package/build/libarkts-copy/src/generated/peers/FunctionExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/FunctionSignature.ts +6 -7
- package/build/libarkts-copy/src/generated/peers/IRNode.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/Identifier.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/IfStatement.ts +9 -9
- package/build/libarkts-copy/src/generated/peers/ImportDeclaration.ts +10 -10
- package/build/libarkts-copy/src/generated/peers/ImportDefaultSpecifier.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ImportExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ImportNamespaceSpecifier.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ImportSource.ts +1 -15
- package/build/libarkts-copy/src/generated/peers/ImportSpecifier.ts +14 -6
- package/build/libarkts-copy/src/generated/peers/IndexInfo.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/InterfaceDecl.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/LabelPair.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/LabelledStatement.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/Literal.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/LoopStatement.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/MaybeOptionalExpression.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/MemberExpression.ts +24 -8
- package/build/libarkts-copy/src/generated/peers/MetaProperty.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/MethodDefinition.ts +25 -8
- package/build/libarkts-copy/src/generated/peers/NamedType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/NewExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/NullLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/NumberLiteral.ts +19 -4
- package/build/libarkts-copy/src/generated/peers/ObjectDescriptor.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/ObjectExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/OmittedExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/OpaqueTypeNode.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/OverloadInfo.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/PrefixAssertionExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/Property.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/RegExpLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ReturnStatement.ts +8 -5
- package/build/libarkts-copy/src/generated/peers/ScopeFindResult.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/ScriptFunction.ts +16 -11
- package/build/libarkts-copy/src/generated/peers/ScriptFunctionData.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/SequenceExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/SignatureInfo.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/SourcePosition.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/SourceRange.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/SpreadElement.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/SrcDumper.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/Statement.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/StringLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/SuperExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/SwitchCaseStatement.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/SwitchStatement.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/TSAnyKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSArrayType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSAsExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSBigintKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSBooleanKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSClassImplements.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSConditionalType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSConstructorType.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/TSEnumDeclaration.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSEnumMember.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/TSExternalModuleReference.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSFunctionType.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/TSImportEqualsDeclaration.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSImportType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSIndexSignature.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSIndexedAccessType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSInferType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSInterfaceBody.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSInterfaceDeclaration.ts +10 -10
- package/build/libarkts-copy/src/generated/peers/TSInterfaceHeritage.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSIntersectionType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSLiteralType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSMappedType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSMethodSignature.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/TSModuleBlock.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSModuleDeclaration.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSNamedTupleMember.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSNeverKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSNonNullExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSNullKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSNumberKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSObjectKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSParameterProperty.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSParenthesizedType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSPropertySignature.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSQualifiedName.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/TSSignatureDeclaration.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/TSStringKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSThisType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTupleType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeAliasDeclaration.ts +8 -8
- package/build/libarkts-copy/src/generated/peers/TSTypeAssertion.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeOperator.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeParameter.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/TSTypeParameterDeclaration.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeParameterInstantiation.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypePredicate.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeQuery.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeReference.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSUndefinedKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSUnionType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSUnknownKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSVoidKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TaggedTemplateExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TemplateElement.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TemplateLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ThisExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ThrowStatement.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TryStatement.ts +10 -6
- package/build/libarkts-copy/src/generated/peers/TypeNode.ts +2 -3
- package/build/libarkts-copy/src/generated/peers/TypedAstNode.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TypedStatement.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TypeofExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/UnaryExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/UndefinedLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/UpdateExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/VReg.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/ValidationInfo.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/VariableDeclaration.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/VariableDeclarator.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/VerificationContext.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/VerifierMessage.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/WhileStatement.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/YieldExpression.ts +4 -4
- package/build/libarkts-copy/src/index.ts +17 -0
- package/build/libarkts-copy/src/reexport-for-generated.ts +1 -1
- package/build/libarkts-copy/src/utils.ts +307 -9
- package/build/libarkts-copy/tsconfig.json +4 -4
- package/lib/index.js +1516 -1120
- package/package.json +6 -6
- package/templates/factory.ts +0 -1
- package/templates/peer.ts +0 -1
- package/build/libarkts-copy/src/Es2pandaEnums.ts +0 -183
- package/build/libarkts-copy/src/arkts-api/node-utilities/createScriptFunction.ts +0 -55
- package/build/libarkts-copy/src/es2panda.ts +0 -277
- package/build/libarkts-copy/src/generated/node-map.ts +0 -182
- package/build/libarkts-copy/src/generated/peers/ETSLaunchExpression.ts +0 -57
package/lib/index.js
CHANGED
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
|
|
20
20
|
'use strict';
|
|
21
21
|
|
|
22
|
+
var path$1 = require('node:path');
|
|
22
23
|
var path = require('path');
|
|
23
24
|
var fs = require('fs');
|
|
24
25
|
var ts = require('typescript');
|
|
25
26
|
require('console');
|
|
26
|
-
|
|
27
|
+
require('node:os');
|
|
27
28
|
var fs$1 = require('node:fs');
|
|
28
29
|
var commander = require('commander');
|
|
29
30
|
|
|
@@ -44,10 +45,10 @@ function _interopNamespaceDefault(e) {
|
|
|
44
45
|
return Object.freeze(n);
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
var path__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(path$1);
|
|
47
49
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
48
50
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
49
51
|
var ts__namespace = /*#__PURE__*/_interopNamespaceDefault(ts);
|
|
50
|
-
var path__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(path$1);
|
|
51
52
|
var fs__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(fs$1);
|
|
52
53
|
|
|
53
54
|
/**
|
|
@@ -802,9 +803,8 @@ function generic_type(tokeniser, typeName) {
|
|
|
802
803
|
tokeniser.error(`No opening bracket after ${base.value}`);
|
|
803
804
|
switch (base.value) {
|
|
804
805
|
case "Promise": {
|
|
805
|
-
if (tokeniser.probe("["))
|
|
806
|
-
tokeniser.error("Promise type cannot have extended attribute");
|
|
807
806
|
const subtype =
|
|
807
|
+
type_with_extended_attributes(tokeniser, typeName) ||
|
|
808
808
|
return_type(tokeniser, typeName) ||
|
|
809
809
|
tokeniser.error("Missing Promise subtype");
|
|
810
810
|
ret.subtype.push(subtype);
|
|
@@ -2044,7 +2044,7 @@ function static_member(tokeniser) {
|
|
|
2044
2044
|
return member;
|
|
2045
2045
|
}
|
|
2046
2046
|
|
|
2047
|
-
|
|
2047
|
+
class Interface extends Container {
|
|
2048
2048
|
/**
|
|
2049
2049
|
* @param {import("../tokeniser.js").Tokeniser} tokeniser
|
|
2050
2050
|
* @param {import("../tokeniser.js").Token} base
|
|
@@ -2151,7 +2151,7 @@ for more information.`;
|
|
|
2151
2151
|
yield* checkInterfaceMemberDuplication(defs, this);
|
|
2152
2152
|
}
|
|
2153
2153
|
}
|
|
2154
|
-
}
|
|
2154
|
+
}
|
|
2155
2155
|
|
|
2156
2156
|
function autofixConstructor(interfaceDef, constructorExtAttr) {
|
|
2157
2157
|
interfaceDef = autoParenter(interfaceDef);
|
|
@@ -2620,7 +2620,7 @@ for more information.`;
|
|
|
2620
2620
|
* @param {string} identifier
|
|
2621
2621
|
*/
|
|
2622
2622
|
function unescape(identifier) {
|
|
2623
|
-
return identifier
|
|
2623
|
+
return identifier;
|
|
2624
2624
|
}
|
|
2625
2625
|
|
|
2626
2626
|
/** @typedef {'callbackInterface'|'dictionary'|'interface'|'mixin'|'namespace'} ExtendableInterfaces */
|
|
@@ -2978,7 +2978,7 @@ function parseInterface(tokeniser, options, opts) {
|
|
|
2978
2978
|
...opts,
|
|
2979
2979
|
...options?.extensions?.mixin,
|
|
2980
2980
|
}) ||
|
|
2981
|
-
Interface
|
|
2981
|
+
Interface.parse(tokeniser, base, {
|
|
2982
2982
|
...opts,
|
|
2983
2983
|
...options?.extensions?.interface,
|
|
2984
2984
|
}) ||
|
|
@@ -3184,6 +3184,7 @@ function tokenise(str) {
|
|
|
3184
3184
|
trivia,
|
|
3185
3185
|
line,
|
|
3186
3186
|
index,
|
|
3187
|
+
position: lastCharIndex,
|
|
3187
3188
|
});
|
|
3188
3189
|
trivia = "";
|
|
3189
3190
|
lastCharIndex += punctuation.length;
|
|
@@ -3210,6 +3211,7 @@ function tokenise(str) {
|
|
|
3210
3211
|
trivia,
|
|
3211
3212
|
line,
|
|
3212
3213
|
index,
|
|
3214
|
+
position: lastCharIndex,
|
|
3213
3215
|
});
|
|
3214
3216
|
|
|
3215
3217
|
return tokens;
|
|
@@ -3224,7 +3226,14 @@ function tokenise(str) {
|
|
|
3224
3226
|
re.lastIndex = lastCharIndex;
|
|
3225
3227
|
const result = re.exec(str);
|
|
3226
3228
|
if (result) {
|
|
3227
|
-
tokens.push({
|
|
3229
|
+
tokens.push({
|
|
3230
|
+
type,
|
|
3231
|
+
value: result[0],
|
|
3232
|
+
trivia,
|
|
3233
|
+
line,
|
|
3234
|
+
index,
|
|
3235
|
+
position: lastCharIndex,
|
|
3236
|
+
});
|
|
3228
3237
|
if (!noFlushTrivia) {
|
|
3229
3238
|
trivia = "";
|
|
3230
3239
|
}
|
|
@@ -3557,6 +3566,20 @@ function parse$1(str, options = {}) {
|
|
|
3557
3566
|
return parseByTokens(tokeniser, options);
|
|
3558
3567
|
}
|
|
3559
3568
|
|
|
3569
|
+
/**
|
|
3570
|
+
* @param {string} str
|
|
3571
|
+
* @param {string} fileName
|
|
3572
|
+
*/
|
|
3573
|
+
function parseType(str, fileName) {
|
|
3574
|
+
const tokeniser = new Tokeniser(str);
|
|
3575
|
+
// @ts-ignore (See Tokeniser.source in supplement.d.ts)
|
|
3576
|
+
tokeniser.source.name = fileName;
|
|
3577
|
+
return (
|
|
3578
|
+
type_with_extended_attributes(tokeniser, "type") ||
|
|
3579
|
+
return_type(tokeniser, "return-type")
|
|
3580
|
+
);
|
|
3581
|
+
}
|
|
3582
|
+
|
|
3560
3583
|
/*
|
|
3561
3584
|
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3562
3585
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -3631,6 +3654,17 @@ function generateSyntheticIdlNodeName(type) {
|
|
|
3631
3654
|
return `Opt_${generateSyntheticIdlNodeName(type.type)}`;
|
|
3632
3655
|
throw `Can not compute type name of ${IDLKind[type.kind]}`;
|
|
3633
3656
|
}
|
|
3657
|
+
function collapseTypes(types, name) {
|
|
3658
|
+
const seenNames = new Set();
|
|
3659
|
+
const uniqueTypes = types.filter(it => {
|
|
3660
|
+
const typeName = printType(it);
|
|
3661
|
+
if (seenNames.has(typeName))
|
|
3662
|
+
return false;
|
|
3663
|
+
seenNames.add(typeName);
|
|
3664
|
+
return true;
|
|
3665
|
+
});
|
|
3666
|
+
return uniqueTypes.length === 1 ? uniqueTypes[0] : createUnionType(uniqueTypes, name);
|
|
3667
|
+
}
|
|
3634
3668
|
function generateSyntheticUnionName(types) {
|
|
3635
3669
|
return `Union_${types.map(it => generateSyntheticIdlNodeName(it)).join("_").replaceAll(".", "_")}`;
|
|
3636
3670
|
}
|
|
@@ -3730,6 +3764,7 @@ var IDLExtendedAttributes;
|
|
|
3730
3764
|
IDLExtendedAttributes["DtsTag"] = "DtsTag";
|
|
3731
3765
|
IDLExtendedAttributes["Entity"] = "Entity";
|
|
3732
3766
|
IDLExtendedAttributes["Import"] = "Import";
|
|
3767
|
+
IDLExtendedAttributes["DefaultExport"] = "DefaultExport";
|
|
3733
3768
|
IDLExtendedAttributes["IndexSignature"] = "IndexSignature";
|
|
3734
3769
|
IDLExtendedAttributes["Interfaces"] = "Interfaces";
|
|
3735
3770
|
IDLExtendedAttributes["NativeModule"] = "NativeModule";
|
|
@@ -3757,73 +3792,88 @@ var IDLInterfaceSubkind;
|
|
|
3757
3792
|
IDLInterfaceSubkind[IDLInterfaceSubkind["AnonymousInterface"] = 2] = "AnonymousInterface";
|
|
3758
3793
|
IDLInterfaceSubkind[IDLInterfaceSubkind["Tuple"] = 3] = "Tuple";
|
|
3759
3794
|
})(IDLInterfaceSubkind || (IDLInterfaceSubkind = {}));
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3795
|
+
/** Updates tree in place! */
|
|
3796
|
+
function updateEachChild(node, op, cbLeave) {
|
|
3797
|
+
const old = node;
|
|
3798
|
+
node = op(old);
|
|
3799
|
+
if (node.kind !== old.kind) {
|
|
3800
|
+
throw new Error("Kinds must be the same!");
|
|
3801
|
+
}
|
|
3763
3802
|
switch (node.kind) {
|
|
3764
|
-
case IDLKind.File:
|
|
3765
|
-
|
|
3803
|
+
case IDLKind.File: {
|
|
3804
|
+
const concrete = node;
|
|
3805
|
+
concrete.entries = concrete.entries.map(it => updateEachChild(it, op, cbLeave));
|
|
3766
3806
|
break;
|
|
3767
|
-
|
|
3768
|
-
|
|
3807
|
+
}
|
|
3808
|
+
case IDLKind.Namespace: {
|
|
3809
|
+
const concrete = node;
|
|
3810
|
+
concrete.members = concrete.members.map((it) => updateEachChild(it, op, cbLeave));
|
|
3769
3811
|
break;
|
|
3812
|
+
}
|
|
3770
3813
|
case IDLKind.Interface: {
|
|
3771
|
-
|
|
3772
|
-
concrete.inheritance.
|
|
3773
|
-
concrete.constructors.
|
|
3774
|
-
concrete.properties.
|
|
3775
|
-
concrete.methods.
|
|
3776
|
-
concrete.callables.
|
|
3814
|
+
const concrete = node;
|
|
3815
|
+
concrete.inheritance = concrete.inheritance.map((it) => updateEachChild(it, op, cbLeave));
|
|
3816
|
+
concrete.constructors = concrete.constructors.map((it) => updateEachChild(it, op, cbLeave));
|
|
3817
|
+
concrete.properties = concrete.properties.map((it) => updateEachChild(it, op, cbLeave));
|
|
3818
|
+
concrete.methods = concrete.methods.map((it) => updateEachChild(it, op, cbLeave));
|
|
3819
|
+
concrete.callables = concrete.callables.map((it) => updateEachChild(it, op, cbLeave));
|
|
3777
3820
|
break;
|
|
3778
3821
|
}
|
|
3779
3822
|
case IDLKind.Method:
|
|
3780
3823
|
case IDLKind.Callable:
|
|
3781
3824
|
case IDLKind.Callback:
|
|
3782
3825
|
case IDLKind.Constructor: {
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
if (concrete.returnType)
|
|
3786
|
-
|
|
3826
|
+
const concrete = node;
|
|
3827
|
+
concrete.parameters = concrete.parameters.map((it) => updateEachChild(it, op, cbLeave));
|
|
3828
|
+
if (concrete.returnType) {
|
|
3829
|
+
concrete.returnType = updateEachChild(concrete.returnType, op, cbLeave);
|
|
3830
|
+
}
|
|
3787
3831
|
break;
|
|
3788
3832
|
}
|
|
3789
3833
|
case IDLKind.UnionType: {
|
|
3790
|
-
|
|
3791
|
-
|
|
3834
|
+
const concrete = node;
|
|
3835
|
+
concrete.types = concrete.types.map((it) => updateEachChild(it, op, cbLeave));
|
|
3792
3836
|
break;
|
|
3793
3837
|
}
|
|
3794
3838
|
case IDLKind.OptionalType: {
|
|
3795
|
-
|
|
3796
|
-
|
|
3839
|
+
const concrete = node;
|
|
3840
|
+
concrete.type = updateEachChild(concrete.type, op, cbLeave);
|
|
3797
3841
|
break;
|
|
3798
3842
|
}
|
|
3799
3843
|
case IDLKind.Const: {
|
|
3800
|
-
|
|
3844
|
+
const concrete = node;
|
|
3845
|
+
concrete.type = updateEachChild(concrete.type, op, cbLeave);
|
|
3801
3846
|
break;
|
|
3802
3847
|
}
|
|
3803
3848
|
case IDLKind.Enum: {
|
|
3804
|
-
|
|
3849
|
+
const concrete = node;
|
|
3850
|
+
concrete.elements = concrete.elements.map((it) => updateEachChild(it, op, cbLeave));
|
|
3805
3851
|
break;
|
|
3806
3852
|
}
|
|
3807
3853
|
case IDLKind.Property: {
|
|
3808
|
-
|
|
3854
|
+
const concrete = node;
|
|
3855
|
+
concrete.type = updateEachChild(concrete.type, op, cbLeave);
|
|
3809
3856
|
break;
|
|
3810
3857
|
}
|
|
3811
3858
|
case IDLKind.Parameter: {
|
|
3812
3859
|
const concrete = node;
|
|
3813
3860
|
if (concrete.type)
|
|
3814
|
-
|
|
3861
|
+
concrete.type = updateEachChild(concrete.type, op, cbLeave);
|
|
3815
3862
|
break;
|
|
3816
3863
|
}
|
|
3817
3864
|
case IDLKind.Typedef: {
|
|
3818
|
-
|
|
3865
|
+
const concrete = node;
|
|
3866
|
+
concrete.type = updateEachChild(concrete.type, op, cbLeave);
|
|
3819
3867
|
break;
|
|
3820
3868
|
}
|
|
3821
3869
|
case IDLKind.ContainerType: {
|
|
3822
|
-
|
|
3870
|
+
const concrete = node;
|
|
3871
|
+
concrete.elementType = concrete.elementType.map(it => updateEachChild(it, op, cbLeave));
|
|
3823
3872
|
break;
|
|
3824
3873
|
}
|
|
3825
3874
|
case IDLKind.UnspecifiedGenericType: {
|
|
3826
|
-
|
|
3875
|
+
const concrete = node;
|
|
3876
|
+
concrete.typeArguments = concrete.typeArguments.map(it => updateEachChild(it, op, cbLeave));
|
|
3827
3877
|
break;
|
|
3828
3878
|
}
|
|
3829
3879
|
case IDLKind.ReferenceType:
|
|
@@ -3837,8 +3887,10 @@ function forEachChild(node, cbEnter, cbLeave) {
|
|
|
3837
3887
|
throw new Error(`Unhandled ${node.kind}`);
|
|
3838
3888
|
}
|
|
3839
3889
|
}
|
|
3840
|
-
if (cbLeave)
|
|
3841
|
-
cbLeave(node);
|
|
3890
|
+
if (cbLeave) {
|
|
3891
|
+
cbLeave === null || cbLeave === void 0 ? void 0 : cbLeave(node);
|
|
3892
|
+
}
|
|
3893
|
+
return node;
|
|
3842
3894
|
}
|
|
3843
3895
|
function isNamedNode(type) {
|
|
3844
3896
|
return "_idlNamedNodeBrand" in type;
|
|
@@ -3879,6 +3931,9 @@ function isTypeParameterType(type) {
|
|
|
3879
3931
|
function isInterface$1(node) {
|
|
3880
3932
|
return node.kind === IDLKind.Interface;
|
|
3881
3933
|
}
|
|
3934
|
+
function isImport(type) {
|
|
3935
|
+
return type.kind == IDLKind.Import;
|
|
3936
|
+
}
|
|
3882
3937
|
function isMethod(node) {
|
|
3883
3938
|
return node.kind === IDLKind.Method;
|
|
3884
3939
|
}
|
|
@@ -3891,13 +3946,13 @@ function isClassSubkind(idl) {
|
|
|
3891
3946
|
function isConstant$1(node) {
|
|
3892
3947
|
return node.kind === IDLKind.Const;
|
|
3893
3948
|
}
|
|
3894
|
-
function
|
|
3895
|
-
return
|
|
3949
|
+
function isType(node) {
|
|
3950
|
+
return "_idlTypeBrand" in node;
|
|
3896
3951
|
}
|
|
3897
3952
|
function isEntry(node) {
|
|
3898
3953
|
return "_idlEntryBrand" in node;
|
|
3899
3954
|
}
|
|
3900
|
-
function isNamespace
|
|
3955
|
+
function isNamespace(node) {
|
|
3901
3956
|
return node.kind === IDLKind.Namespace;
|
|
3902
3957
|
}
|
|
3903
3958
|
function isOptionalType(type) {
|
|
@@ -3912,16 +3967,11 @@ function createPrimitiveType(name) {
|
|
|
3912
3967
|
_idlNamedNodeBrand: innerIdlSymbol,
|
|
3913
3968
|
};
|
|
3914
3969
|
}
|
|
3915
|
-
function createOptionalType(element) {
|
|
3916
|
-
if (isOptionalType(element)) {
|
|
3970
|
+
function createOptionalType(element, nodeInitializer) {
|
|
3971
|
+
if (isOptionalType(element) && !nodeInitializer) {
|
|
3917
3972
|
return element;
|
|
3918
3973
|
}
|
|
3919
|
-
return {
|
|
3920
|
-
kind: IDLKind.OptionalType,
|
|
3921
|
-
type: element,
|
|
3922
|
-
_idlNodeBrand: innerIdlSymbol,
|
|
3923
|
-
_idlTypeBrand: innerIdlSymbol,
|
|
3924
|
-
};
|
|
3974
|
+
return Object.assign(Object.assign({ kind: IDLKind.OptionalType, type: element }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol });
|
|
3925
3975
|
}
|
|
3926
3976
|
/**
|
|
3927
3977
|
* This placeholder is used when a class has no superclass.
|
|
@@ -3932,6 +3982,7 @@ function createOptionalType(element) {
|
|
|
3932
3982
|
* `C extends T implements I, J` : [T, I, J]
|
|
3933
3983
|
*/
|
|
3934
3984
|
const IDLTopType = createReferenceType("__TOP__");
|
|
3985
|
+
// must match with toIDLType in deserialize.ts
|
|
3935
3986
|
const IDLPointerType = createPrimitiveType('pointer');
|
|
3936
3987
|
const IDLVoidType = createPrimitiveType('void');
|
|
3937
3988
|
const IDLBooleanType = createPrimitiveType('boolean');
|
|
@@ -3946,7 +3997,7 @@ const IDLU64Type = createPrimitiveType('u64');
|
|
|
3946
3997
|
createPrimitiveType('f16');
|
|
3947
3998
|
const IDLF32Type = createPrimitiveType('f32');
|
|
3948
3999
|
const IDLF64Type = createPrimitiveType('f64');
|
|
3949
|
-
createPrimitiveType("bigint");
|
|
4000
|
+
const IDLBigintType = createPrimitiveType("bigint");
|
|
3950
4001
|
const IDLNumberType = createPrimitiveType('number');
|
|
3951
4002
|
const IDLStringType = createPrimitiveType('String');
|
|
3952
4003
|
const IDLAnyType = createPrimitiveType('any');
|
|
@@ -3954,87 +4005,90 @@ const IDLUndefinedType = createPrimitiveType('undefined');
|
|
|
3954
4005
|
const IDLUnknownType = createPrimitiveType('unknown');
|
|
3955
4006
|
const IDLObjectType = createReferenceType('Object');
|
|
3956
4007
|
const IDLThisType = createPrimitiveType('this');
|
|
3957
|
-
createPrimitiveType('date');
|
|
4008
|
+
const IDLDate = createPrimitiveType('date');
|
|
3958
4009
|
const IDLBufferType = createPrimitiveType('buffer');
|
|
3959
4010
|
createContainerType('sequence', [IDLU8Type]);
|
|
3960
4011
|
const IDLSerializerBuffer = createPrimitiveType('SerializerBuffer');
|
|
3961
4012
|
// Stub for IdlPeerLibrary
|
|
3962
4013
|
createPrimitiveType('Function');
|
|
3963
|
-
createPrimitiveType('Length');
|
|
3964
4014
|
createPrimitiveType('CustomObject');
|
|
3965
4015
|
createPrimitiveType('InteropReturnBuffer');
|
|
3966
|
-
function createNamespace(name,
|
|
3967
|
-
return {
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
_idlNodeBrand: innerIdlSymbol,
|
|
3974
|
-
_idlEntryBrand: innerIdlSymbol,
|
|
3975
|
-
_idlNamedNodeBrand: innerIdlSymbol,
|
|
3976
|
-
};
|
|
4016
|
+
function createNamespace(name, members, nodeInitializer) {
|
|
4017
|
+
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
|
+
}
|
|
4019
|
+
function isSpecialNodes(node) {
|
|
4020
|
+
return node === IDLTopType
|
|
4021
|
+
|| node === IDLObjectType
|
|
4022
|
+
|| isPrimitiveType(node);
|
|
3977
4023
|
}
|
|
3978
4024
|
function linkParentBack(node) {
|
|
3979
4025
|
const parentStack = [];
|
|
3980
|
-
|
|
3981
|
-
if (
|
|
3982
|
-
return;
|
|
3983
|
-
|
|
3984
|
-
|
|
4026
|
+
updateEachChild(node, (node) => {
|
|
4027
|
+
if (isSpecialNodes(node)) {
|
|
4028
|
+
return node;
|
|
4029
|
+
}
|
|
4030
|
+
if (parentStack.length) {
|
|
4031
|
+
const top = parentStack[parentStack.length - 1];
|
|
4032
|
+
if (node.parent !== undefined && node.parent !== top) {
|
|
4033
|
+
node = clone(node);
|
|
4034
|
+
}
|
|
4035
|
+
node.parent = top;
|
|
4036
|
+
}
|
|
3985
4037
|
parentStack.push(node);
|
|
4038
|
+
return node;
|
|
3986
4039
|
}, (node) => {
|
|
3987
|
-
if (
|
|
4040
|
+
if (isSpecialNodes(node)) {
|
|
3988
4041
|
return;
|
|
4042
|
+
}
|
|
3989
4043
|
parentStack.pop();
|
|
3990
4044
|
});
|
|
3991
4045
|
return node;
|
|
3992
4046
|
}
|
|
3993
|
-
function getNamespacesPathFor(
|
|
3994
|
-
let iterator =
|
|
4047
|
+
function getNamespacesPathFor(node) {
|
|
4048
|
+
let iterator = node.parent;
|
|
3995
4049
|
const result = [];
|
|
3996
4050
|
while (iterator) {
|
|
3997
|
-
if (isNamespace
|
|
4051
|
+
if (isNamespace(iterator))
|
|
3998
4052
|
result.unshift(iterator);
|
|
3999
4053
|
iterator = iterator.parent;
|
|
4000
4054
|
}
|
|
4001
4055
|
return result;
|
|
4002
4056
|
}
|
|
4003
|
-
function getFileFor(
|
|
4004
|
-
let iterator =
|
|
4057
|
+
function getFileFor(node) {
|
|
4058
|
+
let iterator = node;
|
|
4005
4059
|
while (iterator) {
|
|
4006
4060
|
if (isFile(iterator))
|
|
4007
4061
|
return iterator;
|
|
4008
4062
|
iterator = iterator.parent;
|
|
4009
4063
|
}
|
|
4010
|
-
console.warn(`
|
|
4064
|
+
console.warn(`Node ${getQualifiedName(node, "namespace.name")} does not have IDLFile in parents`);
|
|
4011
4065
|
return undefined;
|
|
4012
4066
|
}
|
|
4013
|
-
function getPackageClause(
|
|
4014
|
-
|
|
4015
|
-
|
|
4067
|
+
function getPackageClause(node) {
|
|
4068
|
+
var _a;
|
|
4069
|
+
const file = getFileFor(node);
|
|
4070
|
+
return (_a = file === null || file === void 0 ? void 0 : file.packageClause) !== null && _a !== void 0 ? _a : [];
|
|
4016
4071
|
}
|
|
4017
4072
|
function getPackageName(node) {
|
|
4018
4073
|
return getPackageClause(node).join(".");
|
|
4019
4074
|
}
|
|
4075
|
+
function getQualifiedName(a, pattern) {
|
|
4076
|
+
const result = [];
|
|
4077
|
+
if ("package.namespace.name" === pattern)
|
|
4078
|
+
result.push(...getPackageClause(a), ...getNamespacesPathFor(a).map(it => it.name));
|
|
4079
|
+
else if ("namespace.name" === pattern)
|
|
4080
|
+
result.push(...getNamespacesPathFor(a).map(it => it.name));
|
|
4081
|
+
if (isNamedNode(a) && a.name)
|
|
4082
|
+
result.push(a.name);
|
|
4083
|
+
return result.join(".");
|
|
4084
|
+
}
|
|
4020
4085
|
function getFQName(a) {
|
|
4021
|
-
|
|
4022
|
-
// return [...getPackageClause(a), ...getNamespacesPathFor(a).map(it => it.name), a.name].join('.')
|
|
4023
|
-
return [...getNamespacesPathFor(a).map(it => it.name), a.name].join('.');
|
|
4086
|
+
return getQualifiedName(a, "package.namespace.name");
|
|
4024
4087
|
}
|
|
4025
|
-
function createVersion(value,
|
|
4026
|
-
return {
|
|
4027
|
-
kind: IDLKind.Version,
|
|
4028
|
-
value,
|
|
4029
|
-
name: "version",
|
|
4030
|
-
extendedAttributes,
|
|
4031
|
-
fileName,
|
|
4032
|
-
_idlNodeBrand: innerIdlSymbol,
|
|
4033
|
-
_idlEntryBrand: innerIdlSymbol,
|
|
4034
|
-
_idlNamedNodeBrand: innerIdlSymbol,
|
|
4035
|
-
};
|
|
4088
|
+
function createVersion(value, nodeInitializer) {
|
|
4089
|
+
return Object.assign(Object.assign({ kind: IDLKind.Version, value, name: "version" }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
4036
4090
|
}
|
|
4037
|
-
function createReferenceType(nameOrSource, typeArguments) {
|
|
4091
|
+
function createReferenceType(nameOrSource, typeArguments, nodeInitializer) {
|
|
4038
4092
|
let name;
|
|
4039
4093
|
if (typeof nameOrSource === 'string') {
|
|
4040
4094
|
name = nameOrSource;
|
|
@@ -4042,54 +4096,23 @@ function createReferenceType(nameOrSource, typeArguments) {
|
|
|
4042
4096
|
else {
|
|
4043
4097
|
name = getFQName(nameOrSource);
|
|
4044
4098
|
}
|
|
4045
|
-
return {
|
|
4046
|
-
|
|
4047
|
-
name,
|
|
4048
|
-
typeArguments,
|
|
4049
|
-
_idlNodeBrand: innerIdlSymbol,
|
|
4050
|
-
_idlTypeBrand: innerIdlSymbol,
|
|
4051
|
-
_idlNamedNodeBrand: innerIdlSymbol,
|
|
4052
|
-
};
|
|
4099
|
+
return Object.assign(Object.assign({ kind: IDLKind.ReferenceType, name,
|
|
4100
|
+
typeArguments }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
4053
4101
|
}
|
|
4054
|
-
function createUnspecifiedGenericType(name, typeArguments) {
|
|
4055
|
-
return {
|
|
4056
|
-
|
|
4057
|
-
name,
|
|
4058
|
-
typeArguments,
|
|
4059
|
-
_idlNodeBrand: innerIdlSymbol,
|
|
4060
|
-
_idlTypeBrand: innerIdlSymbol,
|
|
4061
|
-
_idlNamedNodeBrand: innerIdlSymbol,
|
|
4062
|
-
};
|
|
4102
|
+
function createUnspecifiedGenericType(name, typeArguments, nodeInitializer) {
|
|
4103
|
+
return Object.assign(Object.assign({ kind: IDLKind.UnspecifiedGenericType, name,
|
|
4104
|
+
typeArguments }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
4063
4105
|
}
|
|
4064
|
-
function createContainerType(container, element) {
|
|
4065
|
-
return {
|
|
4066
|
-
kind: IDLKind.ContainerType,
|
|
4067
|
-
containerKind: container,
|
|
4068
|
-
elementType: element,
|
|
4069
|
-
_idlNodeBrand: innerIdlSymbol,
|
|
4070
|
-
_idlTypeBrand: innerIdlSymbol,
|
|
4071
|
-
};
|
|
4106
|
+
function createContainerType(container, element, nodeInitializer) {
|
|
4107
|
+
return Object.assign(Object.assign({ kind: IDLKind.ContainerType, containerKind: container, elementType: element }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol });
|
|
4072
4108
|
}
|
|
4073
|
-
function createUnionType(types, name) {
|
|
4109
|
+
function createUnionType(types, name, nodeInitializer) {
|
|
4074
4110
|
if (types.length < 2)
|
|
4075
4111
|
throw new Error("IDLUnionType should contain at least 2 types");
|
|
4076
|
-
return {
|
|
4077
|
-
kind: IDLKind.UnionType,
|
|
4078
|
-
name: name !== null && name !== void 0 ? name : "Union_" + types.map(it => generateSyntheticIdlNodeName(it)).join("_"),
|
|
4079
|
-
types: types,
|
|
4080
|
-
_idlNodeBrand: innerIdlSymbol,
|
|
4081
|
-
_idlTypeBrand: innerIdlSymbol,
|
|
4082
|
-
_idlNamedNodeBrand: innerIdlSymbol,
|
|
4083
|
-
};
|
|
4112
|
+
return Object.assign(Object.assign({ kind: IDLKind.UnionType, name: name !== null && name !== void 0 ? name : "Union_" + types.map(it => generateSyntheticIdlNodeName(it)).join("_"), types: types }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
4084
4113
|
}
|
|
4085
|
-
function createFile(entries, fileName, packageClause = []) {
|
|
4086
|
-
return {
|
|
4087
|
-
kind: IDLKind.File,
|
|
4088
|
-
packageClause,
|
|
4089
|
-
entries: entries,
|
|
4090
|
-
fileName,
|
|
4091
|
-
_idlNodeBrand: innerIdlSymbol,
|
|
4092
|
-
};
|
|
4114
|
+
function createFile(entries, fileName, packageClause = [], nodeInitializer) {
|
|
4115
|
+
return Object.assign(Object.assign({ kind: IDLKind.File, packageClause, entries: entries, fileName }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol });
|
|
4093
4116
|
}
|
|
4094
4117
|
function createImport(clause, name, nodeInitializer) {
|
|
4095
4118
|
return Object.assign(Object.assign({ kind: IDLKind.Import, name: name || "", clause }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
@@ -4155,6 +4178,9 @@ function createCallback(name, parameters, returnType, nodeInitializer = {}, type
|
|
|
4155
4178
|
});
|
|
4156
4179
|
return Object.assign(Object.assign({ kind: IDLKind.Callback, name, parameters, returnType, typeParameters }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
4157
4180
|
}
|
|
4181
|
+
function createTypeParameterReference(name, nodeInitializer) {
|
|
4182
|
+
return Object.assign(Object.assign({ kind: IDLKind.TypeParameterType, name: name }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
4183
|
+
}
|
|
4158
4184
|
function createTypedef(name, type, typeParameters = [], nodeInitializer = {}) {
|
|
4159
4185
|
return Object.assign(Object.assign({ name, type, typeParameters, kind: IDLKind.Typedef }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
4160
4186
|
}
|
|
@@ -4163,6 +4189,196 @@ function createConstant(name, type, value, nodeInitializer = {}) {
|
|
|
4163
4189
|
type,
|
|
4164
4190
|
value }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
4165
4191
|
}
|
|
4192
|
+
function clone(node) {
|
|
4193
|
+
var _a, _b, _c, _d;
|
|
4194
|
+
const make = (node) => node;
|
|
4195
|
+
const get = (node) => node;
|
|
4196
|
+
switch (node.kind) {
|
|
4197
|
+
case IDLKind.Interface: {
|
|
4198
|
+
const entry = get(node);
|
|
4199
|
+
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
|
+
documentation: node.documentation,
|
|
4201
|
+
extendedAttributes: node.extendedAttributes,
|
|
4202
|
+
fileName: node.fileName
|
|
4203
|
+
}));
|
|
4204
|
+
}
|
|
4205
|
+
case IDLKind.Import: {
|
|
4206
|
+
const entry = get(node);
|
|
4207
|
+
return make(createImport(entry.clause, entry.name, {
|
|
4208
|
+
documentation: entry.documentation,
|
|
4209
|
+
extendedAttributes: entry.extendedAttributes,
|
|
4210
|
+
fileName: entry.fileName
|
|
4211
|
+
}));
|
|
4212
|
+
}
|
|
4213
|
+
case IDLKind.Callback: {
|
|
4214
|
+
const entry = get(node);
|
|
4215
|
+
return make(createCallback(entry.name, entry.parameters.map(clone), clone(entry.returnType), {
|
|
4216
|
+
documentation: entry.documentation,
|
|
4217
|
+
extendedAttributes: entry.extendedAttributes,
|
|
4218
|
+
fileName: entry.fileName
|
|
4219
|
+
}, entry.typeParameters));
|
|
4220
|
+
}
|
|
4221
|
+
case IDLKind.Const: {
|
|
4222
|
+
const entry = get(node);
|
|
4223
|
+
return make(createConstant(entry.name, clone(entry.type), entry.value, {
|
|
4224
|
+
documentation: entry.documentation,
|
|
4225
|
+
extendedAttributes: entry.extendedAttributes,
|
|
4226
|
+
fileName: entry.fileName
|
|
4227
|
+
}));
|
|
4228
|
+
}
|
|
4229
|
+
case IDLKind.Property: {
|
|
4230
|
+
const entry = get(node);
|
|
4231
|
+
return make(createProperty(entry.name, clone(entry.type), entry.isReadonly, entry.isStatic, entry.isOptional, {
|
|
4232
|
+
documentation: entry.documentation,
|
|
4233
|
+
extendedAttributes: entry.extendedAttributes,
|
|
4234
|
+
fileName: entry.fileName
|
|
4235
|
+
}));
|
|
4236
|
+
}
|
|
4237
|
+
case IDLKind.Parameter: {
|
|
4238
|
+
const entry = get(node);
|
|
4239
|
+
return make(createParameter(entry.name, clone(entry.type), entry.isOptional, entry.isVariadic, {
|
|
4240
|
+
documentation: entry.documentation,
|
|
4241
|
+
extendedAttributes: entry.extendedAttributes,
|
|
4242
|
+
fileName: entry.fileName
|
|
4243
|
+
}));
|
|
4244
|
+
}
|
|
4245
|
+
case IDLKind.Method: {
|
|
4246
|
+
const entry = get(node);
|
|
4247
|
+
return make(createMethod(entry.name, entry.parameters.map(clone), clone(entry.returnType), {
|
|
4248
|
+
isAsync: entry.isAsync,
|
|
4249
|
+
isFree: entry.isFree,
|
|
4250
|
+
isOptional: entry.isOptional,
|
|
4251
|
+
isStatic: entry.isStatic
|
|
4252
|
+
}, {
|
|
4253
|
+
documentation: entry.documentation,
|
|
4254
|
+
extendedAttributes: entry.extendedAttributes,
|
|
4255
|
+
fileName: entry.fileName
|
|
4256
|
+
}, entry.typeParameters));
|
|
4257
|
+
}
|
|
4258
|
+
case IDLKind.Callable: {
|
|
4259
|
+
const entry = get(node);
|
|
4260
|
+
return make(createCallable(entry.name, entry.parameters.map(clone), clone(entry.returnType), {
|
|
4261
|
+
isAsync: entry.isAsync,
|
|
4262
|
+
isStatic: entry.isStatic
|
|
4263
|
+
}, {
|
|
4264
|
+
documentation: entry.documentation,
|
|
4265
|
+
extendedAttributes: entry.extendedAttributes,
|
|
4266
|
+
fileName: entry.documentation
|
|
4267
|
+
}, entry.typeParameters));
|
|
4268
|
+
}
|
|
4269
|
+
case IDLKind.Constructor: {
|
|
4270
|
+
const entry = get(node);
|
|
4271
|
+
return make(createConstructor(entry.parameters.map(clone), entry.returnType ? clone(entry.returnType) : undefined, {
|
|
4272
|
+
documentation: entry.documentation,
|
|
4273
|
+
extendedAttributes: entry.extendedAttributes,
|
|
4274
|
+
fileName: entry.fileName
|
|
4275
|
+
}));
|
|
4276
|
+
}
|
|
4277
|
+
case IDLKind.Enum: {
|
|
4278
|
+
const entry = get(node);
|
|
4279
|
+
const cloned = createEnum(entry.name, entry.elements.map(clone), {
|
|
4280
|
+
documentation: entry.documentation,
|
|
4281
|
+
extendedAttributes: entry.extendedAttributes,
|
|
4282
|
+
fileName: entry.fileName
|
|
4283
|
+
});
|
|
4284
|
+
cloned.elements.forEach(it => {
|
|
4285
|
+
it.parent = cloned;
|
|
4286
|
+
});
|
|
4287
|
+
return make(cloned);
|
|
4288
|
+
}
|
|
4289
|
+
case IDLKind.EnumMember: {
|
|
4290
|
+
const entry = get(node);
|
|
4291
|
+
return make(createEnumMember(entry.name, entry.parent, clone(entry.type), entry.initializer, {
|
|
4292
|
+
documentation: entry.documentation,
|
|
4293
|
+
extendedAttributes: entry.extendedAttributes,
|
|
4294
|
+
fileName: entry.fileName
|
|
4295
|
+
}));
|
|
4296
|
+
}
|
|
4297
|
+
case IDLKind.Typedef: {
|
|
4298
|
+
const entry = get(node);
|
|
4299
|
+
return make(createTypedef(entry.name, clone(entry.type), entry.typeParameters, {
|
|
4300
|
+
documentation: entry.documentation,
|
|
4301
|
+
extendedAttributes: entry.extendedAttributes,
|
|
4302
|
+
fileName: entry.fileName
|
|
4303
|
+
}));
|
|
4304
|
+
}
|
|
4305
|
+
case IDLKind.PrimitiveType: {
|
|
4306
|
+
return node;
|
|
4307
|
+
}
|
|
4308
|
+
case IDLKind.ContainerType: {
|
|
4309
|
+
const type = get(node);
|
|
4310
|
+
return make(createContainerType(type.containerKind, type.elementType.map(clone), {
|
|
4311
|
+
documentation: type.documentation,
|
|
4312
|
+
extendedAttributes: type.extendedAttributes,
|
|
4313
|
+
fileName: type.fileName
|
|
4314
|
+
}));
|
|
4315
|
+
}
|
|
4316
|
+
case IDLKind.UnspecifiedGenericType: {
|
|
4317
|
+
const type = get(node);
|
|
4318
|
+
return make(createUnspecifiedGenericType(type.name, type.typeArguments.map(clone), {
|
|
4319
|
+
documentation: type.documentation,
|
|
4320
|
+
extendedAttributes: type.extendedAttributes,
|
|
4321
|
+
fileName: type.fileName
|
|
4322
|
+
}));
|
|
4323
|
+
}
|
|
4324
|
+
case IDLKind.ReferenceType: {
|
|
4325
|
+
const type = get(node);
|
|
4326
|
+
return make(createReferenceType(type.name, (_d = type.typeArguments) === null || _d === void 0 ? void 0 : _d.map(clone), {
|
|
4327
|
+
documentation: type.documentation,
|
|
4328
|
+
extendedAttributes: type.extendedAttributes,
|
|
4329
|
+
fileName: type.fileName
|
|
4330
|
+
}));
|
|
4331
|
+
}
|
|
4332
|
+
case IDLKind.UnionType: {
|
|
4333
|
+
const type = get(node);
|
|
4334
|
+
return make(createUnionType(type.types.map(clone), type.name, {
|
|
4335
|
+
documentation: type.documentation,
|
|
4336
|
+
extendedAttributes: type.extendedAttributes,
|
|
4337
|
+
fileName: type.fileName
|
|
4338
|
+
}));
|
|
4339
|
+
}
|
|
4340
|
+
case IDLKind.TypeParameterType: {
|
|
4341
|
+
const type = get(node);
|
|
4342
|
+
return make(createTypeParameterReference(type.name, {
|
|
4343
|
+
documentation: type.documentation,
|
|
4344
|
+
extendedAttributes: type.extendedAttributes,
|
|
4345
|
+
fileName: type.fileName
|
|
4346
|
+
}));
|
|
4347
|
+
}
|
|
4348
|
+
case IDLKind.OptionalType: {
|
|
4349
|
+
const type = get(node);
|
|
4350
|
+
return make(createOptionalType(clone(type.type), {
|
|
4351
|
+
documentation: type.documentation,
|
|
4352
|
+
extendedAttributes: type.extendedAttributes,
|
|
4353
|
+
fileName: type.fileName
|
|
4354
|
+
}));
|
|
4355
|
+
}
|
|
4356
|
+
case IDLKind.Version: {
|
|
4357
|
+
const entry = get(node);
|
|
4358
|
+
return make(createVersion(entry.value, {
|
|
4359
|
+
documentation: entry.documentation,
|
|
4360
|
+
extendedAttributes: entry.extendedAttributes,
|
|
4361
|
+
fileName: entry.fileName
|
|
4362
|
+
}));
|
|
4363
|
+
}
|
|
4364
|
+
case IDLKind.Namespace: {
|
|
4365
|
+
const ns = get(node);
|
|
4366
|
+
return make(createNamespace(ns.name, ns.members.map(clone), {
|
|
4367
|
+
documentation: ns.documentation,
|
|
4368
|
+
extendedAttributes: ns.extendedAttributes,
|
|
4369
|
+
fileName: ns.fileName
|
|
4370
|
+
}));
|
|
4371
|
+
}
|
|
4372
|
+
case IDLKind.File: {
|
|
4373
|
+
const file = get(node);
|
|
4374
|
+
return make(createFile(file.entries.map(clone), file.fileName, file.packageClause, {
|
|
4375
|
+
documentation: file.documentation,
|
|
4376
|
+
extendedAttributes: file.extendedAttributes,
|
|
4377
|
+
fileName: file.fileName
|
|
4378
|
+
}));
|
|
4379
|
+
}
|
|
4380
|
+
}
|
|
4381
|
+
}
|
|
4166
4382
|
function escapeIDLKeyword(name) {
|
|
4167
4383
|
return name + (IDLKeywords.has(name) ? "_" : "");
|
|
4168
4384
|
}
|
|
@@ -4311,15 +4527,17 @@ function printMethod(idl) {
|
|
|
4311
4527
|
];
|
|
4312
4528
|
}
|
|
4313
4529
|
function printPackage(idl) {
|
|
4314
|
-
|
|
4530
|
+
const effectiveClause = idl.packageClause.filter(it => !!it);
|
|
4531
|
+
if (!effectiveClause.length)
|
|
4315
4532
|
return [];
|
|
4316
4533
|
return [
|
|
4317
|
-
`package ${
|
|
4534
|
+
`package ${effectiveClause.join(".")};`
|
|
4318
4535
|
];
|
|
4319
4536
|
}
|
|
4320
4537
|
function printImport(idl) {
|
|
4538
|
+
const effectiveClause = idl.clause.filter(it => !!it);
|
|
4321
4539
|
return [
|
|
4322
|
-
`import ${
|
|
4540
|
+
`import ${effectiveClause.join(".") || "NULL_IMPORT"}${idl.name ? " as " : ""}${idl.name};`
|
|
4323
4541
|
];
|
|
4324
4542
|
}
|
|
4325
4543
|
function printNamespace(idl) {
|
|
@@ -4484,6 +4702,15 @@ const DebugUtils = {
|
|
|
4484
4702
|
function isStringEnum(decl) {
|
|
4485
4703
|
return decl.elements.some(e => e.type === IDLStringType);
|
|
4486
4704
|
}
|
|
4705
|
+
function linearizeNamespaceMembers(entries) {
|
|
4706
|
+
const linearized = [];
|
|
4707
|
+
for (const entry of entries) {
|
|
4708
|
+
linearized.push(entry);
|
|
4709
|
+
if (isNamespace(entry))
|
|
4710
|
+
linearized.push(...linearizeNamespaceMembers(entry.members));
|
|
4711
|
+
}
|
|
4712
|
+
return linearized;
|
|
4713
|
+
}
|
|
4487
4714
|
function extremumOfOrdinals(enumEntry) {
|
|
4488
4715
|
let low = 0;
|
|
4489
4716
|
let high = 0;
|
|
@@ -4632,8 +4859,20 @@ class ValidationBox {
|
|
|
4632
4859
|
});
|
|
4633
4860
|
}
|
|
4634
4861
|
}
|
|
4635
|
-
class
|
|
4862
|
+
class ConfigDescriberBase {
|
|
4863
|
+
constructor() {
|
|
4864
|
+
this.$ = {
|
|
4865
|
+
mergeStrategy: 'merge'
|
|
4866
|
+
};
|
|
4867
|
+
}
|
|
4868
|
+
onMerge(strategy) {
|
|
4869
|
+
this.$.mergeStrategy = strategy;
|
|
4870
|
+
return this;
|
|
4871
|
+
}
|
|
4872
|
+
}
|
|
4873
|
+
class ConfigDescriberLeaf extends ConfigDescriberBase {
|
|
4636
4874
|
constructor(validate, printSchema) {
|
|
4875
|
+
super();
|
|
4637
4876
|
this.validate = validate;
|
|
4638
4877
|
this.printSchema = printSchema;
|
|
4639
4878
|
}
|
|
@@ -4843,6 +5082,71 @@ const D = {
|
|
|
4843
5082
|
};
|
|
4844
5083
|
});
|
|
4845
5084
|
},
|
|
5085
|
+
union(...items) {
|
|
5086
|
+
return new ConfigDescriberLeaf(xs => {
|
|
5087
|
+
for (const item of items) {
|
|
5088
|
+
const r = item.validate(xs);
|
|
5089
|
+
if (r.success()) {
|
|
5090
|
+
return r;
|
|
5091
|
+
}
|
|
5092
|
+
}
|
|
5093
|
+
return ValidationBox.fail('Not matched');
|
|
5094
|
+
}, () => {
|
|
5095
|
+
return {
|
|
5096
|
+
oneOf: items.map(it => it.printSchema())
|
|
5097
|
+
};
|
|
5098
|
+
});
|
|
5099
|
+
},
|
|
5100
|
+
literal: {
|
|
5101
|
+
string(x) {
|
|
5102
|
+
return new ConfigDescriberLeaf(xs => {
|
|
5103
|
+
if (typeof xs === 'string' && x === xs) {
|
|
5104
|
+
return ValidationBox.ok(xs);
|
|
5105
|
+
}
|
|
5106
|
+
return ValidationBox.fail('Not matched');
|
|
5107
|
+
}, () => {
|
|
5108
|
+
return {
|
|
5109
|
+
'const': x
|
|
5110
|
+
};
|
|
5111
|
+
});
|
|
5112
|
+
},
|
|
5113
|
+
number(x) {
|
|
5114
|
+
return new ConfigDescriberLeaf(xs => {
|
|
5115
|
+
if (typeof xs === 'number' && x === xs) {
|
|
5116
|
+
return ValidationBox.ok(xs);
|
|
5117
|
+
}
|
|
5118
|
+
return ValidationBox.fail('Not matched');
|
|
5119
|
+
}, () => {
|
|
5120
|
+
return {
|
|
5121
|
+
'const': x
|
|
5122
|
+
};
|
|
5123
|
+
});
|
|
5124
|
+
},
|
|
5125
|
+
boolean(x) {
|
|
5126
|
+
return new ConfigDescriberLeaf(xs => {
|
|
5127
|
+
if (typeof xs === 'boolean' && x === xs) {
|
|
5128
|
+
return ValidationBox.ok(xs);
|
|
5129
|
+
}
|
|
5130
|
+
return ValidationBox.fail('Not matched');
|
|
5131
|
+
}, () => {
|
|
5132
|
+
return {
|
|
5133
|
+
'const': x
|
|
5134
|
+
};
|
|
5135
|
+
});
|
|
5136
|
+
},
|
|
5137
|
+
null(x) {
|
|
5138
|
+
return new ConfigDescriberLeaf(xs => {
|
|
5139
|
+
if (typeof xs === 'object' && xs === null) {
|
|
5140
|
+
return ValidationBox.ok(null);
|
|
5141
|
+
}
|
|
5142
|
+
return ValidationBox.fail('Expected null');
|
|
5143
|
+
}, () => {
|
|
5144
|
+
return {
|
|
5145
|
+
'const': null
|
|
5146
|
+
};
|
|
5147
|
+
});
|
|
5148
|
+
}
|
|
5149
|
+
},
|
|
4846
5150
|
////////////////////////////////////////
|
|
4847
5151
|
// Utils
|
|
4848
5152
|
combine(a, b) {
|
|
@@ -4908,10 +5212,12 @@ D.object({
|
|
|
4908
5212
|
ignoreMaterialized: T.stringArray(),
|
|
4909
5213
|
builderClasses: T.stringArray(),
|
|
4910
5214
|
forceMaterialized: T.stringArray(),
|
|
4911
|
-
forceCallback: T.stringArray(),
|
|
5215
|
+
forceCallback: D.map(D.string(), T.stringArray()).onMerge('replace'),
|
|
5216
|
+
forceResource: T.stringArray(),
|
|
4912
5217
|
forceContext: T.stringArray(),
|
|
4913
5218
|
moduleName: D.string(),
|
|
4914
|
-
modules: D.map(D.string(), ModuleConfigurationSchema)
|
|
5219
|
+
modules: D.map(D.string(), ModuleConfigurationSchema).onMerge('replace'),
|
|
5220
|
+
globalPackages: T.stringArray()
|
|
4915
5221
|
});
|
|
4916
5222
|
const defaultCoreConfiguration = {
|
|
4917
5223
|
TypePrefix: "",
|
|
@@ -4923,10 +5229,12 @@ const defaultCoreConfiguration = {
|
|
|
4923
5229
|
ignoreMaterialized: [],
|
|
4924
5230
|
builderClasses: [],
|
|
4925
5231
|
forceMaterialized: [],
|
|
4926
|
-
forceCallback:
|
|
5232
|
+
forceCallback: new Map(),
|
|
5233
|
+
forceResource: [],
|
|
4927
5234
|
forceContext: [],
|
|
4928
5235
|
moduleName: "",
|
|
4929
5236
|
modules: new Map(),
|
|
5237
|
+
globalPackages: []
|
|
4930
5238
|
};
|
|
4931
5239
|
let currentConfig = defaultCoreConfiguration;
|
|
4932
5240
|
function generatorConfiguration() {
|
|
@@ -5073,7 +5381,7 @@ const select = {
|
|
|
5073
5381
|
nodes(params) {
|
|
5074
5382
|
const key = 'entities' + serializeParam(params);
|
|
5075
5383
|
function go(node) {
|
|
5076
|
-
if (isNamespace
|
|
5384
|
+
if (isNamespace(node) && (params === null || params === void 0 ? void 0 : params.expandNamespaces)) {
|
|
5077
5385
|
return node.members.flatMap(go);
|
|
5078
5386
|
}
|
|
5079
5387
|
return [node];
|
|
@@ -5445,14 +5753,13 @@ class CheckOptionalStatement {
|
|
|
5445
5753
|
}
|
|
5446
5754
|
// maybe rename or move of fix
|
|
5447
5755
|
class TsEnumEntityStatement {
|
|
5448
|
-
constructor(enumEntity,
|
|
5756
|
+
constructor(enumEntity, options) {
|
|
5449
5757
|
this.enumEntity = enumEntity;
|
|
5450
|
-
this.
|
|
5758
|
+
this.options = options;
|
|
5451
5759
|
}
|
|
5452
5760
|
write(writer) {
|
|
5453
5761
|
// writer.print(this.enumEntity.comment)
|
|
5454
|
-
|
|
5455
|
-
writer.print(`${this.isExport ? "export " : ""}enum ${this.enumEntity.name} {`);
|
|
5762
|
+
writer.print(`${this.options.isExport ? "export " : ""}${this.options.isDeclare ? "declare " : ""}enum ${this.enumEntity.name} {`);
|
|
5456
5763
|
writer.pushIndent();
|
|
5457
5764
|
this.enumEntity.elements.forEach((member, index) => {
|
|
5458
5765
|
// writer.print(member.comment)
|
|
@@ -5467,7 +5774,6 @@ class TsEnumEntityStatement {
|
|
|
5467
5774
|
});
|
|
5468
5775
|
writer.popIndent();
|
|
5469
5776
|
writer.print(`}`);
|
|
5470
|
-
getNamespacesPathFor(this.enumEntity).forEach(it => writer.popNamespace());
|
|
5471
5777
|
}
|
|
5472
5778
|
maybeQuoted(value) {
|
|
5473
5779
|
if (typeof value == "string")
|
|
@@ -5508,6 +5814,10 @@ class LambdaExpression {
|
|
|
5508
5814
|
////////////////////////////////////////////////////////////////
|
|
5509
5815
|
// SIGNATURES //
|
|
5510
5816
|
////////////////////////////////////////////////////////////////
|
|
5817
|
+
var ArgumentModifier;
|
|
5818
|
+
(function (ArgumentModifier) {
|
|
5819
|
+
ArgumentModifier[ArgumentModifier["OPTIONAL"] = 0] = "OPTIONAL";
|
|
5820
|
+
})(ArgumentModifier || (ArgumentModifier = {}));
|
|
5511
5821
|
var FieldModifier;
|
|
5512
5822
|
(function (FieldModifier) {
|
|
5513
5823
|
FieldModifier[FieldModifier["READONLY"] = 0] = "READONLY";
|
|
@@ -5561,12 +5871,13 @@ PrintHint.AsConstPointer = new PrintHint('AsConstPointer');
|
|
|
5561
5871
|
PrintHint.AsValue = new PrintHint('AsValue');
|
|
5562
5872
|
PrintHint.AsConstReference = new PrintHint('AsConstReference');
|
|
5563
5873
|
class MethodSignature {
|
|
5564
|
-
constructor(returnType, args, defaults = undefined, printHints, argNames) {
|
|
5874
|
+
constructor(returnType, args, defaults = undefined, argsModifiers = undefined, printHints, argNames) {
|
|
5565
5875
|
this.returnType = returnType;
|
|
5566
5876
|
this.args = args;
|
|
5567
5877
|
this.defaults = defaults;
|
|
5568
5878
|
this.printHints = printHints;
|
|
5569
5879
|
this.argNames = argNames;
|
|
5880
|
+
this.argsModifiers = argsModifiers === null || argsModifiers === void 0 ? void 0 : argsModifiers.map(it => it === undefined ? [] : Array.isArray(it) ? it : [it]);
|
|
5570
5881
|
}
|
|
5571
5882
|
argName(index) {
|
|
5572
5883
|
var _a, _b;
|
|
@@ -5576,6 +5887,10 @@ class MethodSignature {
|
|
|
5576
5887
|
var _a;
|
|
5577
5888
|
return (_a = this.defaults) === null || _a === void 0 ? void 0 : _a[index];
|
|
5578
5889
|
}
|
|
5890
|
+
isArgOptional(index) {
|
|
5891
|
+
var _a, _b, _c;
|
|
5892
|
+
return (_c = (_b = (_a = this.argsModifiers) === null || _a === void 0 ? void 0 : _a[index]) === null || _b === void 0 ? void 0 : _b.includes(ArgumentModifier.OPTIONAL)) !== null && _c !== void 0 ? _c : false;
|
|
5893
|
+
}
|
|
5579
5894
|
retHint() {
|
|
5580
5895
|
var _a;
|
|
5581
5896
|
return (_a = this.printHints) === null || _a === void 0 ? void 0 : _a[0];
|
|
@@ -5589,8 +5904,8 @@ class MethodSignature {
|
|
|
5589
5904
|
}
|
|
5590
5905
|
}
|
|
5591
5906
|
class NamedMethodSignature extends MethodSignature {
|
|
5592
|
-
constructor(returnType, args = [], argsNames = [], defaults = undefined, printHints) {
|
|
5593
|
-
super(returnType, args, defaults, printHints);
|
|
5907
|
+
constructor(returnType, args = [], argsNames = [], defaults = undefined, argsModifiers = undefined, printHints) {
|
|
5908
|
+
super(returnType, args, defaults, argsModifiers, printHints);
|
|
5594
5909
|
this.argsNames = argsNames;
|
|
5595
5910
|
}
|
|
5596
5911
|
static make(returnType, args) {
|
|
@@ -5745,9 +6060,6 @@ class LanguageWriter {
|
|
|
5745
6060
|
makeUnionTypeDefaultInitializer() {
|
|
5746
6061
|
return this.makeRuntimeType(RuntimeType.UNDEFINED);
|
|
5747
6062
|
}
|
|
5748
|
-
makeRuntimeTypeGetterCall(value) {
|
|
5749
|
-
return this.makeFunctionCall("runtimeType", [this.makeString(value)]);
|
|
5750
|
-
}
|
|
5751
6063
|
makeArrayResize(array, arrayType, length, deserializer) {
|
|
5752
6064
|
return new ExpressionStatement(new StringExpression(""));
|
|
5753
6065
|
}
|
|
@@ -5834,8 +6146,8 @@ class LanguageWriter {
|
|
|
5834
6146
|
makeIsTypeCall(value, decl) {
|
|
5835
6147
|
return this.makeString(`is${decl.name}(${value})`);
|
|
5836
6148
|
}
|
|
5837
|
-
makeEnumEntity(enumEntity,
|
|
5838
|
-
return new TsEnumEntityStatement(enumEntity, isExport);
|
|
6149
|
+
makeEnumEntity(enumEntity, options) {
|
|
6150
|
+
return new TsEnumEntityStatement(enumEntity, { isExport: options.isExport, isDeclare: !!options.isDeclare });
|
|
5839
6151
|
}
|
|
5840
6152
|
makeFieldModifiersList(modifiers, customFieldFilter) {
|
|
5841
6153
|
let allowedModifiers = this.supportedFieldModifiers;
|
|
@@ -5888,45 +6200,6 @@ class LanguageWriter {
|
|
|
5888
6200
|
typeInstanceOf(type, value, members) {
|
|
5889
6201
|
return this.makeString(`${value} instanceof ${this.getNodeName(type)}`);
|
|
5890
6202
|
}
|
|
5891
|
-
makeLengthSerializer(serializer, value) {
|
|
5892
|
-
const valueType = "valueType";
|
|
5893
|
-
return this.makeBlock([
|
|
5894
|
-
this.makeAssign(valueType, undefined, this.makeFunctionCall("runtimeType", [this.makeString(value)]), true),
|
|
5895
|
-
this.makeStatement(this.makeMethodCall(serializer, "writeInt8", [this.makeString(valueType)])),
|
|
5896
|
-
this.makeMultiBranchCondition([
|
|
5897
|
-
{
|
|
5898
|
-
expr: this.makeRuntimeTypeCondition(valueType, true, RuntimeType.NUMBER),
|
|
5899
|
-
stmt: this.makeStatement(this.makeMethodCall(serializer, "writeFloat32", [this.makeString(`${value} as float32`)]))
|
|
5900
|
-
},
|
|
5901
|
-
{
|
|
5902
|
-
expr: this.makeRuntimeTypeCondition(valueType, true, RuntimeType.STRING),
|
|
5903
|
-
stmt: this.makeStatement(this.makeMethodCall(serializer, "writeString", [this.makeString(`${value} as string`)]))
|
|
5904
|
-
},
|
|
5905
|
-
{
|
|
5906
|
-
expr: this.makeRuntimeTypeCondition(valueType, true, RuntimeType.OBJECT),
|
|
5907
|
-
stmt: this.makeStatement(this.makeMethodCall(serializer, "writeInt32", [this.makeString(`(${value} as Resource).id as int32`)]))
|
|
5908
|
-
},
|
|
5909
|
-
]),
|
|
5910
|
-
], false);
|
|
5911
|
-
}
|
|
5912
|
-
makeLengthDeserializer(deserializer) {
|
|
5913
|
-
const valueType = "valueType";
|
|
5914
|
-
return this.makeBlock([
|
|
5915
|
-
this.makeAssign(valueType, undefined, this.makeMethodCall(deserializer, "readInt8", []), true),
|
|
5916
|
-
this.makeMultiBranchCondition([{
|
|
5917
|
-
expr: this.makeRuntimeTypeCondition(valueType, true, RuntimeType.NUMBER),
|
|
5918
|
-
stmt: this.makeReturn(this.makeString(`${deserializer}.readFloat32() as number`))
|
|
5919
|
-
},
|
|
5920
|
-
{
|
|
5921
|
-
expr: this.makeRuntimeTypeCondition(valueType, true, RuntimeType.STRING),
|
|
5922
|
-
stmt: this.makeReturn(this.makeMethodCall(deserializer, "readString", []))
|
|
5923
|
-
},
|
|
5924
|
-
{
|
|
5925
|
-
expr: this.makeRuntimeTypeCondition(valueType, true, RuntimeType.OBJECT),
|
|
5926
|
-
stmt: this.makeReturn(this.makeString(`({id: ${deserializer}.readInt32(), bundleName: "", moduleName: ""}) as Resource`))
|
|
5927
|
-
}], this.makeReturn(this.makeUndefined())),
|
|
5928
|
-
], false);
|
|
5929
|
-
}
|
|
5930
6203
|
stringifyTypeOrEmpty(type) {
|
|
5931
6204
|
if (type === undefined)
|
|
5932
6205
|
return "";
|
|
@@ -5950,7 +6223,16 @@ class LanguageWriter {
|
|
|
5950
6223
|
this.popIndent();
|
|
5951
6224
|
this.print(`}`);
|
|
5952
6225
|
}
|
|
6226
|
+
static get isReferenceRelativeToNamespaces() { return this._isReferenceRelativeToNamespaces; }
|
|
6227
|
+
static relativeReferences(isRelative, op) {
|
|
6228
|
+
const prevIsRelative = this.isReferenceRelativeToNamespaces;
|
|
6229
|
+
this._isReferenceRelativeToNamespaces = isRelative;
|
|
6230
|
+
const result = op();
|
|
6231
|
+
this._isReferenceRelativeToNamespaces = prevIsRelative;
|
|
6232
|
+
return result;
|
|
6233
|
+
}
|
|
5953
6234
|
}
|
|
6235
|
+
LanguageWriter._isReferenceRelativeToNamespaces = false;
|
|
5954
6236
|
|
|
5955
6237
|
/*
|
|
5956
6238
|
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
@@ -6053,10 +6335,12 @@ function convertType(convertor, type) {
|
|
|
6053
6335
|
return convertor.convertUnion(type);
|
|
6054
6336
|
if (isContainerType(type))
|
|
6055
6337
|
return convertor.convertContainer(type);
|
|
6338
|
+
if (isImport(type))
|
|
6339
|
+
return convertor.convertImport(type);
|
|
6056
6340
|
if (isReferenceType(type)) {
|
|
6057
6341
|
const importAttr = getExtAttribute(type, IDLExtendedAttributes.Import);
|
|
6058
6342
|
return importAttr
|
|
6059
|
-
? convertor.
|
|
6343
|
+
? convertor.convertTypeReferenceAsImport(type, importAttr)
|
|
6060
6344
|
: convertor.convertTypeReference(type);
|
|
6061
6345
|
}
|
|
6062
6346
|
if (isTypeParameterType(type))
|
|
@@ -6161,7 +6445,7 @@ class CLikeLanguageWriter extends LanguageWriter {
|
|
|
6161
6445
|
writeMethodDeclaration(name, signature, modifiers) {
|
|
6162
6446
|
this.writeDeclaration(name, signature, modifiers, ";");
|
|
6163
6447
|
}
|
|
6164
|
-
writeEnum(name, members, op) {
|
|
6448
|
+
writeEnum(name, members, options, op) {
|
|
6165
6449
|
throw new Error("WriteEnum for C-family languages is not implemented");
|
|
6166
6450
|
}
|
|
6167
6451
|
writeMethodImplementation(method, op) {
|
|
@@ -6203,15 +6487,15 @@ class CLikeLanguageWriter extends LanguageWriter {
|
|
|
6203
6487
|
// EXPRESSIONS //
|
|
6204
6488
|
////////////////////////////////////////////////////////////////
|
|
6205
6489
|
class CppCastExpression {
|
|
6206
|
-
constructor(convertor, value,
|
|
6490
|
+
constructor(convertor, value, node, options) {
|
|
6207
6491
|
this.convertor = convertor;
|
|
6208
6492
|
this.value = value;
|
|
6209
|
-
this.
|
|
6493
|
+
this.node = node;
|
|
6210
6494
|
this.options = options;
|
|
6211
6495
|
}
|
|
6212
6496
|
asString() {
|
|
6213
6497
|
var _a, _b, _c, _d;
|
|
6214
|
-
if (forceAsNamedNode(this.
|
|
6498
|
+
if (forceAsNamedNode(this.node).name === "Tag") {
|
|
6215
6499
|
return `${this.value.asString()} == ${PrimitiveTypeList.UndefinedRuntime} ? ${PrimitiveTypeList.UndefinedTag} : ${PrimitiveTypeList.ObjectTag}`;
|
|
6216
6500
|
}
|
|
6217
6501
|
let resultName = '';
|
|
@@ -6219,7 +6503,7 @@ class CppCastExpression {
|
|
|
6219
6503
|
resultName = this.options.overrideTypeName;
|
|
6220
6504
|
}
|
|
6221
6505
|
else {
|
|
6222
|
-
const pureName = this.mapTypeWithReceiver(
|
|
6506
|
+
const pureName = this.mapTypeWithReceiver((_b = this.options) === null || _b === void 0 ? void 0 : _b.receiver);
|
|
6223
6507
|
const qualifiedName = ((_c = this.options) === null || _c === void 0 ? void 0 : _c.toRef) ? `${pureName}&` : pureName;
|
|
6224
6508
|
resultName = qualifiedName;
|
|
6225
6509
|
}
|
|
@@ -6227,12 +6511,12 @@ class CppCastExpression {
|
|
|
6227
6511
|
? `reinterpret_cast<${resultName}>(${this.value.asString()})`
|
|
6228
6512
|
: `static_cast<${resultName}>(${this.value.asString()})`;
|
|
6229
6513
|
}
|
|
6230
|
-
mapTypeWithReceiver(
|
|
6514
|
+
mapTypeWithReceiver(receiver) {
|
|
6231
6515
|
// make deducing type from receiver
|
|
6232
6516
|
if (receiver !== undefined) {
|
|
6233
6517
|
return `std::decay<decltype(${receiver})>::type`;
|
|
6234
6518
|
}
|
|
6235
|
-
return this.convertor.convert(
|
|
6519
|
+
return this.convertor.convert(this.node);
|
|
6236
6520
|
}
|
|
6237
6521
|
}
|
|
6238
6522
|
class CppPointerPropertyAccessExpression {
|
|
@@ -6492,8 +6776,8 @@ class CppLanguageWriter extends CLikeLanguageWriter {
|
|
|
6492
6776
|
makeMapResize(mapTypeName, keyType, valueType, map, size, deserializer) {
|
|
6493
6777
|
return new CppMapResizeStatement(mapTypeName, keyType, valueType, map, size, deserializer);
|
|
6494
6778
|
}
|
|
6495
|
-
makeCast(expr,
|
|
6496
|
-
return new CppCastExpression(this.typeConvertor, expr,
|
|
6779
|
+
makeCast(expr, node, options) {
|
|
6780
|
+
return new CppCastExpression(this.typeConvertor, expr, node, options);
|
|
6497
6781
|
}
|
|
6498
6782
|
makePointerPropertyAccessExpression(expression, name) {
|
|
6499
6783
|
return new CppPointerPropertyAccessExpression(expression, name);
|
|
@@ -6548,11 +6832,8 @@ class CppLanguageWriter extends CLikeLanguageWriter {
|
|
|
6548
6832
|
get supportedFieldModifiers() {
|
|
6549
6833
|
return [];
|
|
6550
6834
|
}
|
|
6551
|
-
|
|
6552
|
-
return this.makeString(`static_cast<${this.typeConvertor.convert(
|
|
6553
|
-
}
|
|
6554
|
-
ordinalFromEnum(value, _) {
|
|
6555
|
-
return value;
|
|
6835
|
+
enumFromI32(value, enumEntry) {
|
|
6836
|
+
return this.makeString(`static_cast<${this.typeConvertor.convert(enumEntry)}>(` + value.asString() + `)`);
|
|
6556
6837
|
}
|
|
6557
6838
|
makeUnsafeCast(param) {
|
|
6558
6839
|
return param;
|
|
@@ -6572,13 +6853,13 @@ class CppLanguageWriter extends CLikeLanguageWriter {
|
|
|
6572
6853
|
}
|
|
6573
6854
|
return `(${typeName}) (${value.asString()})`;
|
|
6574
6855
|
}
|
|
6575
|
-
|
|
6576
|
-
return `static_cast<${this.typeConvertor.convert(createReferenceType(enumEntry))}>(${value})
|
|
6856
|
+
i32FromEnum(value, enumEntry) {
|
|
6857
|
+
return this.makeString(`static_cast<${this.typeConvertor.convert(createReferenceType(enumEntry))}>(${value.asString()})`);
|
|
6577
6858
|
}
|
|
6578
6859
|
escapeKeyword(name) {
|
|
6579
6860
|
return cppKeywords.has(name) ? name + "_" : name;
|
|
6580
6861
|
}
|
|
6581
|
-
makeEnumEntity(enumEntity,
|
|
6862
|
+
makeEnumEntity(enumEntity, options) {
|
|
6582
6863
|
return new CppEnumEntityStatement(enumEntity);
|
|
6583
6864
|
}
|
|
6584
6865
|
decayTypeName(typeName) {
|
|
@@ -6639,43 +6920,12 @@ class CppLanguageWriter extends CLikeLanguageWriter {
|
|
|
6639
6920
|
IDLSerializerBuffer,
|
|
6640
6921
|
IDLU32Type,
|
|
6641
6922
|
createReferenceType("CallbackResourceHolder")
|
|
6642
|
-
], ["data", "dataLength", "resourceHolder"], [undefined, `0`, `nullptr`], [undefined, undefined, undefined, PrintHint.AsPointer]);
|
|
6923
|
+
], ["data", "dataLength", "resourceHolder"], [undefined, `0`, `nullptr`], undefined, [undefined, undefined, undefined, PrintHint.AsPointer]);
|
|
6643
6924
|
const ownedDataCtor = new NamedMethodSignature(IDLVoidType, [
|
|
6644
6925
|
createReferenceType("CallbackResourceHolder")
|
|
6645
|
-
], ["resourceHolder"], [`nullptr`], [undefined, PrintHint.AsPointer]);
|
|
6926
|
+
], ["resourceHolder"], [`nullptr`], undefined, [undefined, PrintHint.AsPointer]);
|
|
6646
6927
|
return [ownedDataCtor, fromBufferCtor];
|
|
6647
6928
|
}
|
|
6648
|
-
makeLengthSerializer(serializer, value) {
|
|
6649
|
-
return undefined;
|
|
6650
|
-
}
|
|
6651
|
-
makeLengthDeserializer(deserializer) {
|
|
6652
|
-
return undefined;
|
|
6653
|
-
}
|
|
6654
|
-
}
|
|
6655
|
-
|
|
6656
|
-
/*
|
|
6657
|
-
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
|
6658
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6659
|
-
* you may not use this file except in compliance with the License.
|
|
6660
|
-
* You may obtain a copy of the License at
|
|
6661
|
-
*
|
|
6662
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
6663
|
-
*
|
|
6664
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
6665
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
6666
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
6667
|
-
* See the License for the specific language governing permissions and
|
|
6668
|
-
* limitations under the License.
|
|
6669
|
-
*/
|
|
6670
|
-
function isStringEnumType(type, resolver) {
|
|
6671
|
-
const enumNode = toEnum(type, resolver);
|
|
6672
|
-
return enumNode ? isStringEnum(enumNode) : false;
|
|
6673
|
-
}
|
|
6674
|
-
function toEnum(type, resolver) {
|
|
6675
|
-
if (!isReferenceType(type))
|
|
6676
|
-
return undefined;
|
|
6677
|
-
const resolved = resolver.resolveTypeReference(type);
|
|
6678
|
-
return resolved && isEnum$1(resolved) ? resolved : undefined;
|
|
6679
6929
|
}
|
|
6680
6930
|
|
|
6681
6931
|
/*
|
|
@@ -6807,14 +7057,14 @@ class TSLanguageWriter extends LanguageWriter {
|
|
|
6807
7057
|
return new TSLanguageWriter(new IndentedPrinter(), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.language);
|
|
6808
7058
|
}
|
|
6809
7059
|
getNodeName(type) {
|
|
6810
|
-
//
|
|
6811
|
-
//
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
|
|
7060
|
+
// another stub. Bad one.
|
|
7061
|
+
// I hope that I will rewrite LWs soon
|
|
7062
|
+
if (isType(type) && isReferenceType(type)) {
|
|
7063
|
+
if (type.name.startsWith('%TEXT%:')) {
|
|
7064
|
+
return type.name.substring(7);
|
|
7065
|
+
}
|
|
6816
7066
|
}
|
|
6817
|
-
return
|
|
7067
|
+
return this.typeConvertor.convert(type);
|
|
6818
7068
|
}
|
|
6819
7069
|
writeClass(name, op, superClass, interfaces, generics, isDeclared, isAbstract) {
|
|
6820
7070
|
let extendsClause = superClass ? ` extends ${superClass}` : '';
|
|
@@ -6856,8 +7106,8 @@ class TSLanguageWriter extends LanguageWriter {
|
|
|
6856
7106
|
const returnType = this.getNodeName(signature.returnType);
|
|
6857
7107
|
return `export function ${name}(${args.join(", ")}): ${returnType}`;
|
|
6858
7108
|
}
|
|
6859
|
-
writeEnum(name, members) {
|
|
6860
|
-
this.printer.print(
|
|
7109
|
+
writeEnum(name, members, options) {
|
|
7110
|
+
this.printer.print(`${options.isExport ? "export " : ""}${options.isDeclare ? "declare " : ""}enum ${name} {`);
|
|
6861
7111
|
this.printer.pushIndent();
|
|
6862
7112
|
for (const [index, member] of members.entries()) {
|
|
6863
7113
|
let value;
|
|
@@ -6945,7 +7195,6 @@ class TSLanguageWriter extends LanguageWriter {
|
|
|
6945
7195
|
this.print(`export const ${constName}: ${this.getNodeName(constType)}${constVal ? ' = ' + constVal : ''}`);
|
|
6946
7196
|
}
|
|
6947
7197
|
writeDeclaration(name, signature, needReturn, needBracket, modifiers, generics) {
|
|
6948
|
-
var _a;
|
|
6949
7198
|
let prefix = !modifiers ? undefined : this.supportedModifiers
|
|
6950
7199
|
.filter(it => modifiers.includes(it))
|
|
6951
7200
|
.map(it => this.mapMethodModifier(it)).join(" ");
|
|
@@ -6961,19 +7210,8 @@ class TSLanguageWriter extends LanguageWriter {
|
|
|
6961
7210
|
}
|
|
6962
7211
|
prefix = prefix ? prefix.trim() + " " : "";
|
|
6963
7212
|
const typeParams = (generics === null || generics === void 0 ? void 0 : generics.length) ? `<${generics.join(", ")}>` : "";
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
const canBeOptional = [];
|
|
6967
|
-
for (let i = signature.args.length - 1; i >= 0; --i) {
|
|
6968
|
-
const prevCanBeOptional = (_a = canBeOptional.at(-1)) !== null && _a !== void 0 ? _a : true;
|
|
6969
|
-
const curr = signature.args[i];
|
|
6970
|
-
const result = prevCanBeOptional && (isOptionalType(curr) || signature.argDefault(i) !== undefined);
|
|
6971
|
-
canBeOptional.push(result);
|
|
6972
|
-
}
|
|
6973
|
-
canBeOptional.reverse();
|
|
6974
|
-
const isOptional = signature.args.map((it, i) => isOptionalType(it) && canBeOptional[i] && !isSetter);
|
|
6975
|
-
const normalizedArgs = signature.args.map((it, i) => isOptionalType(it) && isOptional[i] ? maybeUnwrapOptionalType(it) : it);
|
|
6976
|
-
this.printer.print(`${prefix}${name}${typeParams}(${normalizedArgs.map((it, index) => `${this.escapeKeyword(signature.argName(index))}${isOptional[index] ? "?" : ""}: ${this.getNodeName(it)}${signature.argDefault(index) ? ' = ' + signature.argDefault(index) : ""}`).join(", ")})${needReturn ? ": " + this.getNodeName(signature.returnType) : ""}${needBracket ? " {" : ""}`);
|
|
7213
|
+
const normalizedArgs = signature.args.map((it, i) => isOptionalType(it) && signature.isArgOptional(i) ? maybeUnwrapOptionalType(it) : it);
|
|
7214
|
+
this.printer.print(`${prefix}${name}${typeParams}(${normalizedArgs.map((it, index) => `${this.escapeKeyword(signature.argName(index))}${signature.isArgOptional(index) ? "?" : ``}: ${this.getNodeName(it)}${signature.argDefault(index) ? ' = ' + signature.argDefault(index) : ""}`).join(", ")})${needReturn ? ": " + this.getNodeName(signature.returnType) : ""}${needBracket ? " {" : ""}`);
|
|
6977
7215
|
}
|
|
6978
7216
|
makeNull() {
|
|
6979
7217
|
return new StringExpression("undefined");
|
|
@@ -7005,9 +7243,9 @@ class TSLanguageWriter extends LanguageWriter {
|
|
|
7005
7243
|
writePrintLog(message) {
|
|
7006
7244
|
this.print(`console.log("${message}")`);
|
|
7007
7245
|
}
|
|
7008
|
-
makeCast(value,
|
|
7246
|
+
makeCast(value, node, options) {
|
|
7009
7247
|
var _a;
|
|
7010
|
-
return new TSCastExpression(value, this.getNodeName(
|
|
7248
|
+
return new TSCastExpression(value, this.getNodeName(node), (_a = options === null || options === void 0 ? void 0 : options.unsafe) !== null && _a !== void 0 ? _a : false);
|
|
7011
7249
|
}
|
|
7012
7250
|
typeInstanceOf(type, value, members) {
|
|
7013
7251
|
if (isInterface$1(type)) {
|
|
@@ -7070,27 +7308,19 @@ class TSLanguageWriter extends LanguageWriter {
|
|
|
7070
7308
|
get supportedFieldModifiers() {
|
|
7071
7309
|
return [FieldModifier.PUBLIC, FieldModifier.PRIVATE, FieldModifier.PROTECTED, FieldModifier.READONLY, FieldModifier.STATIC];
|
|
7072
7310
|
}
|
|
7073
|
-
|
|
7074
|
-
const enumName =
|
|
7311
|
+
enumFromI32(value, enumEntry) {
|
|
7312
|
+
const enumName = enumEntry.name;
|
|
7075
7313
|
const ordinal = value.asString();
|
|
7076
|
-
return
|
|
7314
|
+
return isStringEnum(enumEntry)
|
|
7077
7315
|
? this.makeString(`Object.values(${enumName})[${ordinal}]`)
|
|
7078
|
-
: this.makeString(
|
|
7316
|
+
: this.makeString(ordinal);
|
|
7079
7317
|
}
|
|
7080
|
-
|
|
7081
|
-
const enumName =
|
|
7082
|
-
|
|
7083
|
-
if (decl && isEnum$1(decl) && isStringEnum(decl)) {
|
|
7318
|
+
i32FromEnum(value, enumEntry) {
|
|
7319
|
+
const enumName = this.getNodeName(enumEntry);
|
|
7320
|
+
if (isEnum$1(enumEntry) && isStringEnum(enumEntry)) {
|
|
7084
7321
|
return this.makeString(`Object.values(${enumName}).indexOf(${value.asString()})`);
|
|
7085
7322
|
}
|
|
7086
|
-
return value;
|
|
7087
|
-
}
|
|
7088
|
-
makeEnumCast(enumEntry, param) {
|
|
7089
|
-
// Take the ordinal value if Enum is a string, and valueOf when it is an integer
|
|
7090
|
-
// Enum.valueOf() - compatible with ArkTS/TS
|
|
7091
|
-
return isStringEnum(enumEntry)
|
|
7092
|
-
? this.ordinalFromEnum(this.makeString(param), createReferenceType(enumEntry)).asString()
|
|
7093
|
-
: `${param}.valueOf()`;
|
|
7323
|
+
return this.makeString(`${value.asString()}.valueOf()`);
|
|
7094
7324
|
}
|
|
7095
7325
|
castToBoolean(value) { return `+${value}`; }
|
|
7096
7326
|
makeCallIsObject(value) {
|
|
@@ -7108,7 +7338,7 @@ class TSLanguageWriter extends LanguageWriter {
|
|
|
7108
7338
|
throwException(`The type reference ${decl === null || decl === void 0 ? void 0 : decl.name} must be Enum`);
|
|
7109
7339
|
}
|
|
7110
7340
|
const ordinal = isStringEnum(decl)
|
|
7111
|
-
? this.
|
|
7341
|
+
? this.i32FromEnum(this.makeCast(this.makeString(this.getObjectAccessor(convertor, value)), convertor.idlType), decl)
|
|
7112
7342
|
: this.makeUnionVariantCast(this.getObjectAccessor(convertor, value), this.getNodeName(IDLI32Type), convertor, index);
|
|
7113
7343
|
const { low, high } = extremumOfOrdinals(decl);
|
|
7114
7344
|
return this.discriminatorFromExpressions(value, convertor.runtimeTypes[0], [
|
|
@@ -7140,6 +7370,7 @@ var LayoutNodeRole;
|
|
|
7140
7370
|
LayoutNodeRole[LayoutNodeRole["PEER"] = 0] = "PEER";
|
|
7141
7371
|
LayoutNodeRole[LayoutNodeRole["INTERFACE"] = 1] = "INTERFACE";
|
|
7142
7372
|
LayoutNodeRole[LayoutNodeRole["GLOBAL"] = 2] = "GLOBAL";
|
|
7373
|
+
LayoutNodeRole[LayoutNodeRole["COMPONENT"] = 3] = "COMPONENT";
|
|
7143
7374
|
})(LayoutNodeRole || (LayoutNodeRole = {}));
|
|
7144
7375
|
|
|
7145
7376
|
function isInModule(nodeOrPackage, module) {
|
|
@@ -7190,7 +7421,7 @@ function isInCurrentModule(nodeOrPackage) {
|
|
|
7190
7421
|
next.forEach(node => {
|
|
7191
7422
|
if (!isInCurrentModule(node))
|
|
7192
7423
|
return;
|
|
7193
|
-
if (isNamespace
|
|
7424
|
+
if (isNamespace(node)) {
|
|
7194
7425
|
queue.push(node.members);
|
|
7195
7426
|
}
|
|
7196
7427
|
if (isConstant$1(node)) {
|
|
@@ -7208,6 +7439,17 @@ function isInCurrentModule(nodeOrPackage) {
|
|
|
7208
7439
|
}))
|
|
7209
7440
|
});
|
|
7210
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
|
+
});
|
|
7211
7453
|
[
|
|
7212
7454
|
IDLTopType.name,
|
|
7213
7455
|
IDLObjectType.name,
|
|
@@ -7325,381 +7567,467 @@ function toString(node) {
|
|
|
7325
7567
|
* See the License for the specific language governing permissions and
|
|
7326
7568
|
* limitations under the License.
|
|
7327
7569
|
*/
|
|
7570
|
+
function getTokens(node) {
|
|
7571
|
+
return node.tokens;
|
|
7572
|
+
}
|
|
7328
7573
|
const syntheticTypes = new Map();
|
|
7329
7574
|
function addSyntheticType(name, type) {
|
|
7330
|
-
if (syntheticTypes.has(name))
|
|
7331
|
-
warn(`duplicate synthetic type name "${name}"`);
|
|
7575
|
+
if (syntheticTypes.has(name)) {
|
|
7576
|
+
warn(`duplicate synthetic type name "${name}"`);
|
|
7577
|
+
}
|
|
7332
7578
|
syntheticTypes.set(name, type);
|
|
7333
7579
|
} // check
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
|
|
7340
|
-
}
|
|
7341
|
-
|
|
7342
|
-
|
|
7580
|
+
class IDLDeserializer {
|
|
7581
|
+
constructor(info) {
|
|
7582
|
+
this.info = info;
|
|
7583
|
+
this.namespacePathNames = [];
|
|
7584
|
+
this.currentPackage = [];
|
|
7585
|
+
this.genericsScopes = [];
|
|
7586
|
+
}
|
|
7587
|
+
///
|
|
7588
|
+
withInfo(from, result) {
|
|
7589
|
+
this.info.set(result, getTokens(from));
|
|
7590
|
+
return result;
|
|
7343
7591
|
}
|
|
7344
|
-
|
|
7345
|
-
|
|
7592
|
+
setPackage(pkg) {
|
|
7593
|
+
this.currentPackage = pkg;
|
|
7346
7594
|
}
|
|
7347
|
-
|
|
7348
|
-
|
|
7595
|
+
///
|
|
7596
|
+
sanitizeTypeParameter(param) {
|
|
7597
|
+
const extendsIdx = param.indexOf('extends');
|
|
7598
|
+
if (extendsIdx !== -1) {
|
|
7599
|
+
return param.substring(0, extendsIdx).trim();
|
|
7600
|
+
}
|
|
7601
|
+
const eqIdx = param.indexOf('=');
|
|
7602
|
+
if (eqIdx !== -1) {
|
|
7603
|
+
return param.substring(0, eqIdx).trim();
|
|
7604
|
+
}
|
|
7605
|
+
return param;
|
|
7349
7606
|
}
|
|
7350
|
-
|
|
7351
|
-
|
|
7607
|
+
extractGenerics(extAttrs) {
|
|
7608
|
+
var _a, _b;
|
|
7609
|
+
return new Set((_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)));
|
|
7352
7610
|
}
|
|
7353
|
-
|
|
7354
|
-
|
|
7611
|
+
///
|
|
7612
|
+
toIDLNode(file, node) {
|
|
7613
|
+
return this.toIDLNodeForward(file, node);
|
|
7355
7614
|
}
|
|
7356
|
-
|
|
7357
|
-
|
|
7615
|
+
toIDLNodeForward(file, node) {
|
|
7616
|
+
if (isEnum(node)) {
|
|
7617
|
+
return this.toIDLEnum(file, node);
|
|
7618
|
+
}
|
|
7619
|
+
if (this.isImport(node)) {
|
|
7620
|
+
return this.toIDLImport(node);
|
|
7621
|
+
}
|
|
7622
|
+
if (isClass(node)) {
|
|
7623
|
+
return this.toIDLInterface(file, node);
|
|
7624
|
+
}
|
|
7625
|
+
if (isInterface(node)) {
|
|
7626
|
+
return this.toIDLInterface(file, node);
|
|
7627
|
+
}
|
|
7628
|
+
if (isCallback(node)) {
|
|
7629
|
+
return this.toIDLCallback(file, node);
|
|
7630
|
+
}
|
|
7631
|
+
if (isTypedef(node)) {
|
|
7632
|
+
return this.toIDLTypedef(file, node);
|
|
7633
|
+
}
|
|
7634
|
+
if (isDictionary(node)) {
|
|
7635
|
+
return this.toIDLDictionary(file, node);
|
|
7636
|
+
}
|
|
7637
|
+
if (this.isNamespace(node)) {
|
|
7638
|
+
return this.toIDLNamespace(file, node);
|
|
7639
|
+
}
|
|
7640
|
+
if (this.isVersion(node)) {
|
|
7641
|
+
return this.toIDLVersion(file, node);
|
|
7642
|
+
}
|
|
7643
|
+
if (isAttribute(node)) {
|
|
7644
|
+
return this.toIDLProperty(file, node);
|
|
7645
|
+
}
|
|
7646
|
+
if (isOperation(node)) {
|
|
7647
|
+
return this.toIDLMethod(file, node, true);
|
|
7648
|
+
}
|
|
7649
|
+
if (isConstant(node)) {
|
|
7650
|
+
return this.toIDLConstant(file, node);
|
|
7651
|
+
}
|
|
7652
|
+
throw new Error(`unexpected node type: ${toString(node)}`);
|
|
7358
7653
|
}
|
|
7359
|
-
|
|
7360
|
-
|
|
7654
|
+
toIDLImport(node) {
|
|
7655
|
+
// console.log(node)
|
|
7656
|
+
return this.withInfo(node, createImport(node.clause.split("."), node.alias || undefined));
|
|
7361
7657
|
}
|
|
7362
|
-
|
|
7363
|
-
|
|
7658
|
+
interfaceSubkind(node) {
|
|
7659
|
+
var _a, _b;
|
|
7660
|
+
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
|
+
if (nodeIDLEntity == IDLEntity.Class)
|
|
7662
|
+
return IDLInterfaceSubkind.Class;
|
|
7663
|
+
if (nodeIDLEntity == IDLEntity.Interface)
|
|
7664
|
+
return IDLInterfaceSubkind.Interface;
|
|
7665
|
+
if (nodeIDLEntity == IDLEntity.Tuple)
|
|
7666
|
+
return IDLInterfaceSubkind.Tuple;
|
|
7667
|
+
return IDLInterfaceSubkind.Interface;
|
|
7364
7668
|
}
|
|
7365
|
-
|
|
7366
|
-
|
|
7669
|
+
toIDLInterface(file, node) {
|
|
7670
|
+
var _a;
|
|
7671
|
+
const generics = this.extractGenerics(node.extAttrs);
|
|
7672
|
+
this.genericsScopes.push(generics);
|
|
7673
|
+
const result = createInterface(node.name, this.interfaceSubkind(node), (() => {
|
|
7674
|
+
var _a, _b;
|
|
7675
|
+
if (!node.inheritance)
|
|
7676
|
+
return [];
|
|
7677
|
+
const parentTypeArgs = this.extractTypeArguments(file, (_a = node.inheritanceExtAttrs) !== null && _a !== void 0 ? _a : [], IDLExtendedAttributes.TypeArguments);
|
|
7678
|
+
const parentType = createReferenceType(node.inheritance, parentTypeArgs);
|
|
7679
|
+
parentType.fileName = file;
|
|
7680
|
+
if (node.inheritanceExtAttrs)
|
|
7681
|
+
parentType.extendedAttributes = (_b = this.toExtendedAttributes(node.inheritanceExtAttrs)) === null || _b === void 0 ? void 0 : _b.filter(it => it.name !== IDLExtendedAttributes.TypeArguments);
|
|
7682
|
+
return [parentType];
|
|
7683
|
+
})(), node.members
|
|
7684
|
+
.filter(isConstructor)
|
|
7685
|
+
.map(it => this.toIDLConstructor(file, it)), [], node.members
|
|
7686
|
+
.filter(isAttribute)
|
|
7687
|
+
.map(it => this.toIDLProperty(file, it)), node.members
|
|
7688
|
+
.filter(isOperation)
|
|
7689
|
+
.filter(it => !this.isCallable(it))
|
|
7690
|
+
.map(it => this.toIDLMethod(file, it, false)), node.members
|
|
7691
|
+
.filter(isOperation)
|
|
7692
|
+
.filter(it => this.isCallable(it))
|
|
7693
|
+
.map(it => this.toIDLCallable(file, it)), (_a = this.findExtendedAttribute(node.extAttrs, IDLExtendedAttributes.TypeParameters)) === null || _a === void 0 ? void 0 : _a.split(","), {
|
|
7694
|
+
fileName: file,
|
|
7695
|
+
documentation: this.makeDocs(node),
|
|
7696
|
+
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7697
|
+
});
|
|
7698
|
+
this.genericsScopes.pop();
|
|
7699
|
+
this.info.set(result, getTokens(node));
|
|
7700
|
+
if (node.extAttrs.find(it => it.name === "Synthetic")) {
|
|
7701
|
+
const fqName = this.currentPackage.concat(this.namespacePathNames).concat([node.name]).join('.');
|
|
7702
|
+
addSyntheticType(fqName, result);
|
|
7703
|
+
}
|
|
7704
|
+
return result;
|
|
7367
7705
|
}
|
|
7368
|
-
|
|
7369
|
-
|
|
7706
|
+
toIDLType(file, type, extAttrs) {
|
|
7707
|
+
var _a;
|
|
7708
|
+
if (typeof type === "string") {
|
|
7709
|
+
// is it IDLStringType?
|
|
7710
|
+
const refType = createReferenceType(type);
|
|
7711
|
+
refType.fileName = file;
|
|
7712
|
+
refType.typeArguments = this.extractTypeArguments(file, extAttrs, IDLExtendedAttributes.TypeArguments);
|
|
7713
|
+
return refType;
|
|
7714
|
+
}
|
|
7715
|
+
if (type.nullable) {
|
|
7716
|
+
return this.withInfo(type, createOptionalType(this.toIDLType(file, Object.assign(Object.assign({}, type), { nullable: false }), extAttrs)));
|
|
7717
|
+
}
|
|
7718
|
+
if (isUnionTypeDescription(type)) {
|
|
7719
|
+
let types = type.idlType
|
|
7720
|
+
.map(it => this.toIDLType(file, it, undefined))
|
|
7721
|
+
.filter(isDefined);
|
|
7722
|
+
if (types.includes(IDLUndefinedType)) {
|
|
7723
|
+
types = types.filter(it => it !== IDLUndefinedType);
|
|
7724
|
+
return this.withInfo(type, createOptionalType(collapseTypes(types)));
|
|
7725
|
+
}
|
|
7726
|
+
const name = generateSyntheticUnionName(types);
|
|
7727
|
+
return this.withInfo(type, createUnionType(types, name));
|
|
7728
|
+
}
|
|
7729
|
+
if (isSingleTypeDescription(type)) {
|
|
7730
|
+
// must match with primitive types in idl.ts
|
|
7731
|
+
switch (type.idlType) {
|
|
7732
|
+
case IDLPointerType.name: return IDLPointerType;
|
|
7733
|
+
case IDLVoidType.name: return IDLVoidType;
|
|
7734
|
+
case IDLBooleanType.name: return IDLBooleanType;
|
|
7735
|
+
case IDLObjectType.name: return IDLObjectType;
|
|
7736
|
+
case IDLI8Type.name: return IDLI8Type;
|
|
7737
|
+
case IDLU8Type.name: return IDLU8Type;
|
|
7738
|
+
case IDLI16Type.name: return IDLI16Type;
|
|
7739
|
+
case IDLU16Type.name: return IDLU16Type;
|
|
7740
|
+
case IDLI32Type.name: return IDLI32Type;
|
|
7741
|
+
case IDLU32Type.name: return IDLU32Type;
|
|
7742
|
+
case IDLI64Type.name: return IDLI64Type;
|
|
7743
|
+
case IDLU64Type.name: return IDLU64Type;
|
|
7744
|
+
case IDLF32Type.name: return IDLF32Type;
|
|
7745
|
+
case IDLF64Type.name: return IDLF64Type;
|
|
7746
|
+
case IDLBigintType.name: return IDLBigintType;
|
|
7747
|
+
case IDLNumberType.name: return IDLNumberType;
|
|
7748
|
+
case IDLStringType.name: return IDLStringType;
|
|
7749
|
+
case IDLAnyType.name: return IDLAnyType;
|
|
7750
|
+
case IDLUndefinedType.name: return IDLUndefinedType;
|
|
7751
|
+
case IDLUnknownType.name: return IDLUnknownType;
|
|
7752
|
+
case IDLObjectType.name: return IDLObjectType;
|
|
7753
|
+
case IDLThisType.name: return IDLThisType;
|
|
7754
|
+
case IDLDate.name: return IDLDate;
|
|
7755
|
+
case IDLBufferType.name: return IDLBufferType;
|
|
7756
|
+
case IDLSerializerBuffer.name: return IDLSerializerBuffer;
|
|
7757
|
+
}
|
|
7758
|
+
const combinedExtAttrs = ((_a = type.extAttrs) !== null && _a !== void 0 ? _a : []).concat(extAttrs !== null && extAttrs !== void 0 ? extAttrs : []);
|
|
7759
|
+
let idlRefType;
|
|
7760
|
+
if (this.genericsScopes.some(it => it.has(type.idlType))) {
|
|
7761
|
+
idlRefType = createTypeParameterReference(type.idlType);
|
|
7762
|
+
}
|
|
7763
|
+
else {
|
|
7764
|
+
const ref = createReferenceType(type.idlType);
|
|
7765
|
+
ref.typeArguments = this.extractTypeArguments(file, combinedExtAttrs, IDLExtendedAttributes.TypeArguments);
|
|
7766
|
+
idlRefType = ref;
|
|
7767
|
+
}
|
|
7768
|
+
idlRefType.fileName = file;
|
|
7769
|
+
idlRefType.extendedAttributes = this.toExtendedAttributes(combinedExtAttrs);
|
|
7770
|
+
return this.withInfo(type, idlRefType);
|
|
7771
|
+
}
|
|
7772
|
+
if (isSequenceTypeDescription(type) || isPromiseTypeDescription(type) || isRecordTypeDescription(type)) {
|
|
7773
|
+
return this.withInfo(type, createContainerType(type.generic, type.idlType.map(it => this.toIDLType(file, it, undefined))));
|
|
7774
|
+
}
|
|
7775
|
+
if (isUnspecifiedGenericTypeDescription(type)) {
|
|
7776
|
+
return this.withInfo(type, createUnspecifiedGenericType(type.generic, type.idlType.map(it => this.toIDLType(file, it, undefined))));
|
|
7777
|
+
}
|
|
7778
|
+
throw new Error(`unexpected type: ${toString(type)}`);
|
|
7370
7779
|
}
|
|
7371
|
-
|
|
7372
|
-
|
|
7780
|
+
toIDLCallable(file, node) {
|
|
7781
|
+
var _a, _b;
|
|
7782
|
+
if (!node.idlType) {
|
|
7783
|
+
throw new Error(`method with no type ${toString(node)}`);
|
|
7784
|
+
}
|
|
7785
|
+
const generics = this.extractGenerics(node.extAttrs);
|
|
7786
|
+
this.genericsScopes.push(generics);
|
|
7787
|
+
const returnType = this.toIDLType(file, node.idlType, node.extAttrs);
|
|
7788
|
+
if (isReferenceType(returnType)) {
|
|
7789
|
+
const returnTypeArgs = this.extractTypeArguments(file, node.extAttrs, IDLExtendedAttributes.TypeArguments);
|
|
7790
|
+
returnType.typeArguments = returnTypeArgs;
|
|
7791
|
+
}
|
|
7792
|
+
const result = this.withInfo(node, createCallable((_a = node.name) !== null && _a !== void 0 ? _a : "", node.arguments.map(it => this.toIDLParameter(file, it)), returnType, {
|
|
7793
|
+
isStatic: node.special === "static",
|
|
7794
|
+
isAsync: node.async,
|
|
7795
|
+
}, {
|
|
7796
|
+
documentation: this.makeDocs(node),
|
|
7797
|
+
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7798
|
+
}, (_b = this.findExtendedAttribute(node.extAttrs, IDLExtendedAttributes.TypeParameters)) === null || _b === void 0 ? void 0 : _b.split(",")));
|
|
7799
|
+
this.genericsScopes.pop();
|
|
7800
|
+
return result;
|
|
7373
7801
|
}
|
|
7374
|
-
|
|
7375
|
-
}
|
|
7376
|
-
function isNamespace(node) {
|
|
7377
|
-
return node.type === 'namespace';
|
|
7378
|
-
}
|
|
7379
|
-
function isVersion(node) {
|
|
7380
|
-
return node.type === 'version';
|
|
7381
|
-
}
|
|
7382
|
-
function isPackage(node) {
|
|
7383
|
-
return node.type === 'package';
|
|
7384
|
-
}
|
|
7385
|
-
function isImport(node) {
|
|
7386
|
-
return node.type === 'import';
|
|
7387
|
-
}
|
|
7388
|
-
function isCallable(node) {
|
|
7389
|
-
return node.extAttrs.some(it => it.name == "Invoke");
|
|
7390
|
-
}
|
|
7391
|
-
function toIDLImport(node) {
|
|
7392
|
-
// console.log(node)
|
|
7393
|
-
return createImport(node.clause.split("."), node.alias || undefined);
|
|
7394
|
-
}
|
|
7395
|
-
function interfaceSubkind(node) {
|
|
7396
|
-
var _a, _b;
|
|
7397
|
-
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;
|
|
7398
|
-
if (nodeIDLEntity == IDLEntity.Class)
|
|
7399
|
-
return IDLInterfaceSubkind.Class;
|
|
7400
|
-
if (nodeIDLEntity == IDLEntity.Interface)
|
|
7401
|
-
return IDLInterfaceSubkind.Interface;
|
|
7402
|
-
if (nodeIDLEntity == IDLEntity.Tuple)
|
|
7403
|
-
return IDLInterfaceSubkind.Tuple;
|
|
7404
|
-
return IDLInterfaceSubkind.Interface;
|
|
7405
|
-
}
|
|
7406
|
-
function toIDLInterface(file, node) {
|
|
7407
|
-
var _a;
|
|
7408
|
-
const result = createInterface(node.name, interfaceSubkind(node), (() => {
|
|
7802
|
+
toIDLMethod(file, node, isFree = false) {
|
|
7409
7803
|
var _a, _b;
|
|
7410
|
-
if (!node.
|
|
7411
|
-
|
|
7412
|
-
|
|
7413
|
-
const
|
|
7414
|
-
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
.
|
|
7427
|
-
.
|
|
7428
|
-
|
|
7429
|
-
fileName: file,
|
|
7430
|
-
documentation: makeDocs(node),
|
|
7431
|
-
extendedAttributes: toExtendedAttributes(node.extAttrs),
|
|
7432
|
-
});
|
|
7433
|
-
if (node.extAttrs.find(it => it.name === "Synthetic"))
|
|
7434
|
-
addSyntheticType(node.name, result);
|
|
7435
|
-
return result;
|
|
7436
|
-
}
|
|
7437
|
-
function extractTypeArguments(file, extAttrs, attribute) {
|
|
7438
|
-
var _a;
|
|
7439
|
-
const attr = extAttrs === null || extAttrs === void 0 ? void 0 : extAttrs.find(it => it.name === attribute);
|
|
7440
|
-
if (!attr)
|
|
7441
|
-
return undefined;
|
|
7442
|
-
let value = toExtendedAttributeValue(attr);
|
|
7443
|
-
return (_a = value === null || value === void 0 ? void 0 : value.split(",") // TODO need real parsing here. What about "<T, Map<K, Callback<K,R>>, U>"
|
|
7444
|
-
) === null || _a === void 0 ? void 0 : _a.map(it => toIDLType(file, it));
|
|
7445
|
-
}
|
|
7446
|
-
function toIDLType(file, type, extAttrs) {
|
|
7447
|
-
var _a;
|
|
7448
|
-
if (typeof type === "string") {
|
|
7449
|
-
// is it IDLStringType?
|
|
7450
|
-
const refType = createReferenceType(type);
|
|
7451
|
-
refType.fileName = file;
|
|
7452
|
-
refType.typeArguments = extractTypeArguments(file, extAttrs, IDLExtendedAttributes.TypeArguments);
|
|
7453
|
-
return refType;
|
|
7454
|
-
}
|
|
7455
|
-
if (type.nullable) {
|
|
7456
|
-
return createOptionalType(toIDLType(file, Object.assign(Object.assign({}, type), { nullable: false }), extAttrs));
|
|
7457
|
-
}
|
|
7458
|
-
if (isUnionTypeDescription(type)) {
|
|
7459
|
-
const types = type.idlType
|
|
7460
|
-
.map(it => toIDLType(file, it))
|
|
7461
|
-
.filter(isDefined);
|
|
7462
|
-
const name = generateSyntheticUnionName(types);
|
|
7463
|
-
return createUnionType(types, name);
|
|
7464
|
-
}
|
|
7465
|
-
if (isSingleTypeDescription(type)) {
|
|
7466
|
-
switch (type.idlType) {
|
|
7467
|
-
case IDLUnknownType.name: return IDLUnknownType;
|
|
7468
|
-
case IDLObjectType.name: return IDLObjectType;
|
|
7469
|
-
case IDLAnyType.name: return IDLAnyType;
|
|
7470
|
-
case IDLBooleanType.name: return IDLBooleanType;
|
|
7471
|
-
case IDLNumberType.name: return IDLNumberType;
|
|
7472
|
-
case IDLStringType.name: return IDLStringType;
|
|
7473
|
-
case IDLUndefinedType.name: return IDLUndefinedType;
|
|
7474
|
-
case IDLVoidType.name: return IDLVoidType;
|
|
7475
|
-
case IDLI8Type.name: return IDLI8Type;
|
|
7476
|
-
case IDLU8Type.name: return IDLU8Type;
|
|
7477
|
-
case IDLI16Type.name: return IDLI16Type;
|
|
7478
|
-
case IDLU16Type.name: return IDLU16Type;
|
|
7479
|
-
case IDLI32Type.name: return IDLI32Type;
|
|
7480
|
-
case IDLU32Type.name: return IDLU32Type;
|
|
7481
|
-
case IDLI64Type.name: return IDLI64Type;
|
|
7482
|
-
case IDLU64Type.name: return IDLU64Type;
|
|
7483
|
-
case IDLF32Type.name: return IDLF32Type;
|
|
7484
|
-
case IDLF64Type.name: return IDLF64Type;
|
|
7485
|
-
case IDLPointerType.name: return IDLPointerType;
|
|
7486
|
-
case IDLBufferType.name: return IDLBufferType;
|
|
7487
|
-
}
|
|
7488
|
-
const combinedExtAttrs = ((_a = type.extAttrs) !== null && _a !== void 0 ? _a : []).concat(extAttrs !== null && extAttrs !== void 0 ? extAttrs : []);
|
|
7489
|
-
const idlRefType = createReferenceType(type.idlType);
|
|
7490
|
-
idlRefType.fileName = file;
|
|
7491
|
-
idlRefType.typeArguments = extractTypeArguments(file, combinedExtAttrs, IDLExtendedAttributes.TypeArguments);
|
|
7492
|
-
idlRefType.extendedAttributes = toExtendedAttributes(combinedExtAttrs);
|
|
7493
|
-
return idlRefType;
|
|
7494
|
-
}
|
|
7495
|
-
if (isSequenceTypeDescription(type) || isPromiseTypeDescription(type) || isRecordTypeDescription(type)) {
|
|
7496
|
-
return createContainerType(type.generic, type.idlType.map(it => toIDLType(file, it)));
|
|
7497
|
-
}
|
|
7498
|
-
if (isUnspecifiedGenericTypeDescription(type)) {
|
|
7499
|
-
return createUnspecifiedGenericType(type.generic, type.idlType.map(it => toIDLType(file, it)));
|
|
7500
|
-
}
|
|
7501
|
-
throw new Error(`unexpected type: ${toString(type)}`);
|
|
7502
|
-
}
|
|
7503
|
-
function toIDLCallable(file, node) {
|
|
7504
|
-
var _a, _b;
|
|
7505
|
-
if (!node.idlType) {
|
|
7506
|
-
throw new Error(`method with no type ${toString(node)}`);
|
|
7804
|
+
if (!node.idlType) {
|
|
7805
|
+
throw new Error(`method with no type ${toString(node)}`);
|
|
7806
|
+
}
|
|
7807
|
+
const generics = this.extractGenerics(node.extAttrs);
|
|
7808
|
+
this.genericsScopes.push(generics);
|
|
7809
|
+
const returnType = this.toIDLType(file, node.idlType, node.extAttrs);
|
|
7810
|
+
if (isReferenceType(returnType))
|
|
7811
|
+
returnType.typeArguments = this.extractTypeArguments(file, node.extAttrs, IDLExtendedAttributes.TypeArguments);
|
|
7812
|
+
const result = this.withInfo(node, createMethod((_a = node.name) !== null && _a !== void 0 ? _a : "", node.arguments.map(it => this.toIDLParameter(file, it !== null && it !== void 0 ? it : new Map())), returnType, {
|
|
7813
|
+
isStatic: node.special === "static",
|
|
7814
|
+
isAsync: node.async,
|
|
7815
|
+
isOptional: isOptional(node),
|
|
7816
|
+
isFree
|
|
7817
|
+
}, {
|
|
7818
|
+
documentation: this.makeDocs(node),
|
|
7819
|
+
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7820
|
+
}, (_b = this.findExtendedAttribute(node.extAttrs, IDLExtendedAttributes.TypeParameters)) === null || _b === void 0 ? void 0 : _b.split(",")));
|
|
7821
|
+
this.genericsScopes.pop();
|
|
7822
|
+
return result;
|
|
7507
7823
|
}
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
|
|
7824
|
+
toIDLConstructor(file, node) {
|
|
7825
|
+
return this.withInfo(node, createConstructor(node.arguments.map(it => this.toIDLParameter(file, it)), undefined, {
|
|
7826
|
+
documentation: this.makeDocs(node),
|
|
7827
|
+
}));
|
|
7512
7828
|
}
|
|
7513
|
-
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
documentation: makeDocs(node),
|
|
7518
|
-
extendedAttributes: toExtendedAttributes(node.extAttrs),
|
|
7519
|
-
}, (_b = findExtendedAttribute(node.extAttrs, IDLExtendedAttributes.TypeParameters)) === null || _b === void 0 ? void 0 : _b.split(","));
|
|
7520
|
-
}
|
|
7521
|
-
function toIDLMethod(file, node) {
|
|
7522
|
-
var _a, _b;
|
|
7523
|
-
if (!node.idlType) {
|
|
7524
|
-
throw new Error(`method with no type ${toString(node)}`);
|
|
7525
|
-
}
|
|
7526
|
-
const returnType = toIDLType(file, node.idlType, node.extAttrs);
|
|
7527
|
-
if (isReferenceType(returnType))
|
|
7528
|
-
returnType.typeArguments = extractTypeArguments(file, node.extAttrs, IDLExtendedAttributes.TypeArguments);
|
|
7529
|
-
return createMethod((_a = node.name) !== null && _a !== void 0 ? _a : "", node.arguments.map(it => toIDLParameter(file, it)), returnType, {
|
|
7530
|
-
isStatic: node.special === "static",
|
|
7531
|
-
isAsync: node.async,
|
|
7532
|
-
isOptional: isOptional(node),
|
|
7533
|
-
isFree: false, // TODO: namespace-related-to-rework
|
|
7534
|
-
}, {
|
|
7535
|
-
documentation: makeDocs(node),
|
|
7536
|
-
extendedAttributes: toExtendedAttributes(node.extAttrs),
|
|
7537
|
-
}, (_b = findExtendedAttribute(node.extAttrs, IDLExtendedAttributes.TypeParameters)) === null || _b === void 0 ? void 0 : _b.split(","));
|
|
7538
|
-
}
|
|
7539
|
-
function toIDLConstructor(file, node) {
|
|
7540
|
-
return createConstructor(node.arguments.map(it => toIDLParameter(file, it)), undefined, {
|
|
7541
|
-
documentation: makeDocs(node),
|
|
7542
|
-
});
|
|
7543
|
-
}
|
|
7544
|
-
function toIDLParameter(file, node) {
|
|
7545
|
-
return createParameter(node.name, toIDLType(file, node.idlType, node.extAttrs), node.optional, node.variadic, {
|
|
7546
|
-
fileName: file,
|
|
7547
|
-
});
|
|
7548
|
-
}
|
|
7549
|
-
function toIDLCallback(file, node) {
|
|
7550
|
-
const result = createCallback(node.name, node.arguments.map(it => toIDLParameter(file, it)), toIDLType(file, node.idlType), {
|
|
7551
|
-
fileName: file,
|
|
7552
|
-
extendedAttributes: toExtendedAttributes(node.extAttrs),
|
|
7553
|
-
documentation: makeDocs(node),
|
|
7554
|
-
});
|
|
7555
|
-
if (node.extAttrs.find(it => it.name === "Synthetic"))
|
|
7556
|
-
addSyntheticType(node.name, result);
|
|
7557
|
-
return result;
|
|
7558
|
-
}
|
|
7559
|
-
function toIDLTypedef(file, node) {
|
|
7560
|
-
var _a;
|
|
7561
|
-
return createTypedef(node.name, toIDLType(file, node.idlType), (_a = findExtendedAttribute(node.extAttrs, IDLExtendedAttributes.TypeParameters)) === null || _a === void 0 ? void 0 : _a.split(","), {
|
|
7562
|
-
extendedAttributes: toExtendedAttributes(node.extAttrs),
|
|
7563
|
-
documentation: makeDocs(node),
|
|
7564
|
-
fileName: file,
|
|
7565
|
-
});
|
|
7566
|
-
}
|
|
7567
|
-
function toIDLConstant(file, node) {
|
|
7568
|
-
return createConstant(node.name, toIDLType(file, node.idlType), constantValue(node));
|
|
7569
|
-
}
|
|
7570
|
-
function constantValue(node) {
|
|
7571
|
-
switch (node.value.type) {
|
|
7572
|
-
case "string":
|
|
7573
|
-
return `"${node.value.value}"`;
|
|
7574
|
-
case "number":
|
|
7575
|
-
return node.value.value;
|
|
7576
|
-
case "boolean":
|
|
7577
|
-
return node.value.value.toString();
|
|
7578
|
-
case "null":
|
|
7579
|
-
return "null";
|
|
7580
|
-
case "Infinity":
|
|
7581
|
-
return "Infinity";
|
|
7582
|
-
case "NaN":
|
|
7583
|
-
return "NaN";
|
|
7584
|
-
case "sequence":
|
|
7585
|
-
return `[${node.value.value.join(',')}]`;
|
|
7586
|
-
case "dictionary":
|
|
7587
|
-
return `new Map()`;
|
|
7588
|
-
default:
|
|
7589
|
-
return "undefined";
|
|
7829
|
+
toIDLParameter(file, node) {
|
|
7830
|
+
return this.withInfo(node, createParameter(node.name, this.toIDLType(file, node.idlType, node.extAttrs), node.optional, node.variadic, {
|
|
7831
|
+
fileName: file,
|
|
7832
|
+
}));
|
|
7590
7833
|
}
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7600
|
-
}
|
|
7601
|
-
function toIDLNamespace(file, node) {
|
|
7602
|
-
const namespace = createNamespace(node.name, toExtendedAttributes(node.extAttrs), file);
|
|
7603
|
-
namespace.members = node.members.map(it => toIDLNodeForward(file, it));
|
|
7604
|
-
return namespace;
|
|
7605
|
-
}
|
|
7606
|
-
function toIDLVersion(file, node) {
|
|
7607
|
-
return createVersion(node.value, toExtendedAttributes(node.extAttrs), file);
|
|
7608
|
-
}
|
|
7609
|
-
function toIDLProperty(file, node) {
|
|
7610
|
-
return createProperty(node.name, toIDLType(file, node.idlType), node.readonly, node.special === "static", isOptional(node), {
|
|
7611
|
-
documentation: makeDocs(node),
|
|
7612
|
-
fileName: file,
|
|
7613
|
-
extendedAttributes: toExtendedAttributes(node.extAttrs)
|
|
7614
|
-
});
|
|
7615
|
-
}
|
|
7616
|
-
function unescapeString(value) {
|
|
7617
|
-
if (!value.length || value[0] !== '"')
|
|
7618
|
-
return value;
|
|
7619
|
-
value = value.slice(1, -1);
|
|
7620
|
-
value = value.replace(/\\((['"\\bfnrtv])|([0-7]{1-3})|x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/g, (_, all, c, oct, h2, u4) => {
|
|
7621
|
-
if (c !== undefined) {
|
|
7622
|
-
switch (c) {
|
|
7623
|
-
case "'": return "'";
|
|
7624
|
-
case '"': return '"';
|
|
7625
|
-
case "\\": return "\\";
|
|
7626
|
-
case "b": return "\b";
|
|
7627
|
-
case "f": return "\f";
|
|
7628
|
-
case "n": return "\n";
|
|
7629
|
-
case "r": return "\r";
|
|
7630
|
-
case "t": return "\t";
|
|
7631
|
-
case "v": return "\v";
|
|
7632
|
-
}
|
|
7834
|
+
toIDLCallback(file, node) {
|
|
7835
|
+
const result = createCallback(node.name, node.arguments.map(it => this.toIDLParameter(file, it)), this.toIDLType(file, node.idlType, undefined), {
|
|
7836
|
+
fileName: file,
|
|
7837
|
+
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7838
|
+
documentation: this.makeDocs(node),
|
|
7839
|
+
});
|
|
7840
|
+
if (node.extAttrs.find(it => it.name === "Synthetic")) {
|
|
7841
|
+
const fqName = this.currentPackage.concat(this.namespacePathNames).concat([node.name]).join('.');
|
|
7842
|
+
addSyntheticType(fqName, result);
|
|
7633
7843
|
}
|
|
7634
|
-
|
|
7635
|
-
|
|
7844
|
+
return this.withInfo(node, result);
|
|
7845
|
+
}
|
|
7846
|
+
toIDLTypedef(file, node) {
|
|
7847
|
+
var _a;
|
|
7848
|
+
const generics = this.extractGenerics(node.extAttrs);
|
|
7849
|
+
this.genericsScopes.push(generics);
|
|
7850
|
+
const result = this.withInfo(node, createTypedef(node.name, this.toIDLType(file, node.idlType, undefined), (_a = this.findExtendedAttribute(node.extAttrs, IDLExtendedAttributes.TypeParameters)) === null || _a === void 0 ? void 0 : _a.split(","), {
|
|
7851
|
+
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7852
|
+
documentation: this.makeDocs(node),
|
|
7853
|
+
fileName: file,
|
|
7854
|
+
}));
|
|
7855
|
+
this.genericsScopes.pop();
|
|
7856
|
+
return result;
|
|
7857
|
+
}
|
|
7858
|
+
toIDLConstant(file, node) {
|
|
7859
|
+
return this.withInfo(node, createConstant(node.name, this.toIDLType(file, node.idlType, undefined), this.constantValue(node)));
|
|
7860
|
+
}
|
|
7861
|
+
toIDLDictionary(file, node) {
|
|
7862
|
+
const result = createEnum(node.name, [], {
|
|
7863
|
+
documentation: this.makeDocs(node),
|
|
7864
|
+
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7865
|
+
fileName: file,
|
|
7866
|
+
});
|
|
7867
|
+
result.elements = node.members.map(it => this.toIDLEnumMember(file, it, result));
|
|
7868
|
+
return this.withInfo(node, result);
|
|
7869
|
+
}
|
|
7870
|
+
toIDLNamespace(file, node) {
|
|
7871
|
+
const namespace = createNamespace(node.name, [], {
|
|
7872
|
+
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7873
|
+
fileName: file
|
|
7874
|
+
});
|
|
7875
|
+
this.namespacePathNames.push(node.name);
|
|
7876
|
+
namespace.members = node.members.map(it => this.toIDLNodeForward(file, it));
|
|
7877
|
+
this.namespacePathNames.pop();
|
|
7878
|
+
return this.withInfo(node, namespace);
|
|
7879
|
+
}
|
|
7880
|
+
toIDLVersion(file, node) {
|
|
7881
|
+
return this.withInfo(node, createVersion(node.value, {
|
|
7882
|
+
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7883
|
+
fileName: file
|
|
7884
|
+
}));
|
|
7885
|
+
}
|
|
7886
|
+
toIDLProperty(file, node) {
|
|
7887
|
+
return this.withInfo(node, createProperty(node.name, this.toIDLType(file, node.idlType, undefined), node.readonly, node.special === "static", isOptional(node), {
|
|
7888
|
+
documentation: this.makeDocs(node),
|
|
7889
|
+
fileName: file,
|
|
7890
|
+
extendedAttributes: this.toExtendedAttributes(node.extAttrs)
|
|
7891
|
+
}));
|
|
7892
|
+
}
|
|
7893
|
+
toIDLEnumMember(file, node, parent) {
|
|
7894
|
+
var _a, _b, _c;
|
|
7895
|
+
let initializer = undefined;
|
|
7896
|
+
if (((_a = node.default) === null || _a === void 0 ? void 0 : _a.type) == "string") {
|
|
7897
|
+
initializer = this.unescapeString(node.default.value);
|
|
7636
7898
|
}
|
|
7637
|
-
else if (
|
|
7638
|
-
|
|
7899
|
+
else if (((_b = node.default) === null || _b === void 0 ? void 0 : _b.type) == "number") {
|
|
7900
|
+
initializer = +((_c = node.default) === null || _c === void 0 ? void 0 : _c.value);
|
|
7639
7901
|
}
|
|
7640
|
-
else if (
|
|
7641
|
-
|
|
7902
|
+
else if (node.default == null) {
|
|
7903
|
+
initializer = undefined;
|
|
7642
7904
|
}
|
|
7643
|
-
|
|
7644
|
-
|
|
7645
|
-
|
|
7646
|
-
|
|
7647
|
-
|
|
7648
|
-
|
|
7649
|
-
let initializer = undefined;
|
|
7650
|
-
if (((_a = node.default) === null || _a === void 0 ? void 0 : _a.type) == "string") {
|
|
7651
|
-
initializer = unescapeString(node.default.value);
|
|
7905
|
+
else {
|
|
7906
|
+
throw new Error(`Not representable enum initializer: ${node.default}`);
|
|
7907
|
+
}
|
|
7908
|
+
return this.withInfo(node, createEnumMember(node.name, parent, this.toIDLType(file, node.idlType, undefined), initializer, {
|
|
7909
|
+
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7910
|
+
}));
|
|
7652
7911
|
}
|
|
7653
|
-
|
|
7654
|
-
|
|
7912
|
+
toExtendedAttributes(extAttrs) {
|
|
7913
|
+
return extAttrs.map(it => {
|
|
7914
|
+
return this.withInfo(it, { name: it.name, value: this.toExtendedAttributeValue(it) });
|
|
7915
|
+
});
|
|
7655
7916
|
}
|
|
7656
|
-
|
|
7657
|
-
|
|
7917
|
+
toExtendedAttributeValue(attr) {
|
|
7918
|
+
var _a, _b;
|
|
7919
|
+
// TODO: be smarter about RHS.
|
|
7920
|
+
if (((_a = attr.rhs) === null || _a === void 0 ? void 0 : _a.value) instanceof Array)
|
|
7921
|
+
return attr.rhs.value.map(v => v.value).join(",");
|
|
7922
|
+
if (typeof ((_b = attr.rhs) === null || _b === void 0 ? void 0 : _b.value) === 'string')
|
|
7923
|
+
return this.unescapeString(attr.rhs.value);
|
|
7924
|
+
return;
|
|
7658
7925
|
}
|
|
7659
|
-
|
|
7660
|
-
|
|
7926
|
+
toIDLEnum(file, node) {
|
|
7927
|
+
const result = createEnum(node.name, [], {
|
|
7928
|
+
fileName: file,
|
|
7929
|
+
documentation: this.makeDocs(node),
|
|
7930
|
+
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7931
|
+
});
|
|
7932
|
+
result.elements = node.values.map((it) => createEnumMember(it.value, result, IDLNumberType, undefined));
|
|
7933
|
+
return this.withInfo(node, result);
|
|
7661
7934
|
}
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
|
|
7665
|
-
}
|
|
7666
|
-
|
|
7667
|
-
|
|
7668
|
-
|
|
7669
|
-
|
|
7670
|
-
|
|
7671
|
-
|
|
7672
|
-
|
|
7673
|
-
|
|
7674
|
-
|
|
7675
|
-
|
|
7676
|
-
|
|
7677
|
-
|
|
7678
|
-
|
|
7679
|
-
|
|
7680
|
-
function makeDocs(node) {
|
|
7681
|
-
let docs = undefined;
|
|
7682
|
-
node.extAttrs.forEach(it => {
|
|
7935
|
+
///
|
|
7936
|
+
isNamespace(node) {
|
|
7937
|
+
return node.type === 'namespace';
|
|
7938
|
+
}
|
|
7939
|
+
isVersion(node) {
|
|
7940
|
+
return node.type === 'version';
|
|
7941
|
+
}
|
|
7942
|
+
isPackage(node) {
|
|
7943
|
+
return node.type === 'package';
|
|
7944
|
+
}
|
|
7945
|
+
isImport(node) {
|
|
7946
|
+
return node.type === 'import';
|
|
7947
|
+
}
|
|
7948
|
+
isCallable(node) {
|
|
7949
|
+
return node.extAttrs.some(it => it.name == "Invoke");
|
|
7950
|
+
}
|
|
7951
|
+
///
|
|
7952
|
+
extractTypeArguments(file, extAttrs, attribute) {
|
|
7683
7953
|
var _a;
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
|
|
7693
|
-
|
|
7694
|
-
|
|
7695
|
-
|
|
7696
|
-
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7954
|
+
const attr = extAttrs === null || extAttrs === void 0 ? void 0 : extAttrs.find(it => it.name === attribute);
|
|
7955
|
+
if (!attr)
|
|
7956
|
+
return undefined;
|
|
7957
|
+
let value = this.toExtendedAttributeValue(attr);
|
|
7958
|
+
return (_a = value === null || value === void 0 ? void 0 : value.split(",") // TODO need real parsing here. What about "<T, Map<K, Callback<K,R>>, U>"
|
|
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); });
|
|
7960
|
+
}
|
|
7961
|
+
constantValue(node) {
|
|
7962
|
+
switch (node.value.type) {
|
|
7963
|
+
case "string":
|
|
7964
|
+
return `"${node.value.value}"`;
|
|
7965
|
+
case "number":
|
|
7966
|
+
return node.value.value;
|
|
7967
|
+
case "boolean":
|
|
7968
|
+
return node.value.value.toString();
|
|
7969
|
+
case "null":
|
|
7970
|
+
return "null";
|
|
7971
|
+
case "Infinity":
|
|
7972
|
+
return "Infinity";
|
|
7973
|
+
case "NaN":
|
|
7974
|
+
return "NaN";
|
|
7975
|
+
case "sequence":
|
|
7976
|
+
return `[${node.value.value.join(',')}]`;
|
|
7977
|
+
case "dictionary":
|
|
7978
|
+
return `new Map()`;
|
|
7979
|
+
default:
|
|
7980
|
+
return "undefined";
|
|
7981
|
+
}
|
|
7982
|
+
}
|
|
7983
|
+
unescapeString(value) {
|
|
7984
|
+
if (!value.length || value[0] !== '"')
|
|
7985
|
+
return value;
|
|
7986
|
+
value = value.slice(1, -1);
|
|
7987
|
+
value = value.replace(/\\((['"\\bfnrtv])|([0-7]{1-3})|x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/g, (_, all, c, oct, h2, u4) => {
|
|
7988
|
+
if (c !== undefined) {
|
|
7989
|
+
switch (c) {
|
|
7990
|
+
case "'": return "'";
|
|
7991
|
+
case '"': return '"';
|
|
7992
|
+
case "\\": return "\\";
|
|
7993
|
+
case "b": return "\b";
|
|
7994
|
+
case "f": return "\f";
|
|
7995
|
+
case "n": return "\n";
|
|
7996
|
+
case "r": return "\r";
|
|
7997
|
+
case "t": return "\t";
|
|
7998
|
+
case "v": return "\v";
|
|
7999
|
+
}
|
|
8000
|
+
}
|
|
8001
|
+
else if (oct !== undefined) {
|
|
8002
|
+
return String.fromCharCode(parseInt(oct, 8));
|
|
8003
|
+
}
|
|
8004
|
+
else if (h2 !== undefined) {
|
|
8005
|
+
return String.fromCharCode(parseInt(h2, 16));
|
|
8006
|
+
}
|
|
8007
|
+
else if (u4 !== undefined) {
|
|
8008
|
+
return String.fromCharCode(parseInt(u4, 16));
|
|
8009
|
+
}
|
|
8010
|
+
throw new Error(`unknown escape sequence: ${_}`);
|
|
8011
|
+
});
|
|
8012
|
+
return value;
|
|
8013
|
+
}
|
|
8014
|
+
makeDocs(node) {
|
|
8015
|
+
let docs = undefined;
|
|
8016
|
+
node.extAttrs.forEach(it => {
|
|
8017
|
+
var _a;
|
|
8018
|
+
if (it.name == "Documentation")
|
|
8019
|
+
docs = (_a = it.rhs) === null || _a === void 0 ? void 0 : _a.value;
|
|
8020
|
+
});
|
|
8021
|
+
return docs;
|
|
8022
|
+
}
|
|
8023
|
+
findExtendedAttribute(extAttrs, name) {
|
|
8024
|
+
const attr = extAttrs.find(it => it.name === name);
|
|
8025
|
+
return attr ? this.toExtendedAttributeValue(attr) : undefined;
|
|
8026
|
+
}
|
|
7701
8027
|
}
|
|
7702
8028
|
function toIDLFile(fileName, content) {
|
|
8029
|
+
const lexicalInfo = new Map();
|
|
8030
|
+
const deserializer = new IDLDeserializer(lexicalInfo);
|
|
7703
8031
|
if (undefined === content)
|
|
7704
8032
|
content = fs__namespace.readFileSync(fileName).toString();
|
|
7705
8033
|
let packageClause = [];
|
|
@@ -7707,15 +8035,17 @@ function toIDLFile(fileName, content) {
|
|
|
7707
8035
|
.filter(it => {
|
|
7708
8036
|
if (!it.type)
|
|
7709
8037
|
return false;
|
|
7710
|
-
if (isPackage(it)) {
|
|
8038
|
+
if (deserializer.isPackage(it)) {
|
|
7711
8039
|
packageClause = it.clause.split(".");
|
|
8040
|
+
deserializer.setPackage(packageClause);
|
|
7712
8041
|
return false;
|
|
7713
8042
|
}
|
|
7714
8043
|
return true;
|
|
7715
8044
|
})
|
|
7716
|
-
.map(it => toIDLNode(fileName, it));
|
|
8045
|
+
.map(it => deserializer.toIDLNode(fileName, it));
|
|
7717
8046
|
const file = createFile(entries, fileName, packageClause);
|
|
7718
|
-
|
|
8047
|
+
file.text = content;
|
|
8048
|
+
return [linkParentBack(file), lexicalInfo];
|
|
7719
8049
|
}
|
|
7720
8050
|
|
|
7721
8051
|
/*
|
|
@@ -7801,6 +8131,61 @@ class BridgesConstructions {
|
|
|
7801
8131
|
}
|
|
7802
8132
|
}
|
|
7803
8133
|
|
|
8134
|
+
/*
|
|
8135
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
8136
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8137
|
+
* you may not use this file except in compliance with the License.
|
|
8138
|
+
* You may obtain a copy of the License at
|
|
8139
|
+
*
|
|
8140
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8141
|
+
*
|
|
8142
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
8143
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
8144
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8145
|
+
* See the License for the specific language governing permissions and
|
|
8146
|
+
* limitations under the License.
|
|
8147
|
+
*/
|
|
8148
|
+
class Config {
|
|
8149
|
+
constructor(ignore, nonNullable, irHack) {
|
|
8150
|
+
this.ignore = ignore;
|
|
8151
|
+
this.nonNullable = nonNullable;
|
|
8152
|
+
this.irHack = irHack;
|
|
8153
|
+
}
|
|
8154
|
+
static get createPrefix() {
|
|
8155
|
+
return `Create`;
|
|
8156
|
+
}
|
|
8157
|
+
static get updatePrefix() {
|
|
8158
|
+
return `Update`;
|
|
8159
|
+
}
|
|
8160
|
+
static get constPostfix() {
|
|
8161
|
+
return `Const`;
|
|
8162
|
+
}
|
|
8163
|
+
static get nodeTypeAttribute() {
|
|
8164
|
+
return `Es2pandaAstNodeType`;
|
|
8165
|
+
}
|
|
8166
|
+
static get nodeNamespaceAttribute() {
|
|
8167
|
+
return `cpp_namespace`;
|
|
8168
|
+
}
|
|
8169
|
+
static get uselessPrefix() {
|
|
8170
|
+
return `Get`;
|
|
8171
|
+
}
|
|
8172
|
+
static get astNodeCommonAncestor() {
|
|
8173
|
+
return `AstNode`;
|
|
8174
|
+
}
|
|
8175
|
+
static get context() {
|
|
8176
|
+
return `Context`;
|
|
8177
|
+
}
|
|
8178
|
+
static get dataClassPrefix() {
|
|
8179
|
+
return `es2panda_`;
|
|
8180
|
+
}
|
|
8181
|
+
static get defaultAncestor() {
|
|
8182
|
+
return `ArktsObject`;
|
|
8183
|
+
}
|
|
8184
|
+
static get irNamespace() {
|
|
8185
|
+
return `ir`;
|
|
8186
|
+
}
|
|
8187
|
+
}
|
|
8188
|
+
|
|
7804
8189
|
/*
|
|
7805
8190
|
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
7806
8191
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -7832,11 +8217,11 @@ class InteropConstructions {
|
|
|
7832
8217
|
return `${parameter}SequenceLength`;
|
|
7833
8218
|
}
|
|
7834
8219
|
static method(interfaceName, methodName, namespaceName = "") {
|
|
7835
|
-
if (
|
|
8220
|
+
if (isCreateOrUpdate(methodName)) {
|
|
7836
8221
|
const { createOrUpdate, rest } = splitCreateOrUpdate(methodName);
|
|
7837
|
-
return `${createOrUpdate}${interfaceName}${
|
|
8222
|
+
return `${createOrUpdate}${interfaceName}${rest}`;
|
|
7838
8223
|
}
|
|
7839
|
-
return `${interfaceName}${
|
|
8224
|
+
return `${interfaceName}${methodName}`;
|
|
7840
8225
|
}
|
|
7841
8226
|
static get keywords() {
|
|
7842
8227
|
return [
|
|
@@ -7856,91 +8241,6 @@ InteropConstructions.context = {
|
|
|
7856
8241
|
name: `context`
|
|
7857
8242
|
};
|
|
7858
8243
|
|
|
7859
|
-
/*
|
|
7860
|
-
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
7861
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7862
|
-
* you may not use this file except in compliance with the License.
|
|
7863
|
-
* You may obtain a copy of the License at
|
|
7864
|
-
*
|
|
7865
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7866
|
-
*
|
|
7867
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
7868
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7869
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7870
|
-
* See the License for the specific language governing permissions and
|
|
7871
|
-
* limitations under the License.
|
|
7872
|
-
*/
|
|
7873
|
-
function isString(node) {
|
|
7874
|
-
return isPrimitiveType(node) && node.name === `String`;
|
|
7875
|
-
}
|
|
7876
|
-
function isSequence(node) {
|
|
7877
|
-
return IDLContainerUtils.isSequence(node);
|
|
7878
|
-
}
|
|
7879
|
-
function createUpdatedInterface(node, methods, name, inheritance, extendedAttributes, properties) {
|
|
7880
|
-
return createInterface(name !== null && name !== void 0 ? name : node.name, node.subkind, inheritance !== null && inheritance !== void 0 ? inheritance : node.inheritance, node.constructors, node.constants, properties !== null && properties !== void 0 ? properties : node.properties, methods !== null && methods !== void 0 ? methods : node.methods, node.callables, node.typeParameters, {
|
|
7881
|
-
extendedAttributes: node.extendedAttributes,
|
|
7882
|
-
fileName: node.fileName,
|
|
7883
|
-
documentation: node.documentation
|
|
7884
|
-
});
|
|
7885
|
-
}
|
|
7886
|
-
function createUpdatedMethod(node, name, parameters, returnType, extendedAttributes) {
|
|
7887
|
-
return createMethod(name !== null && name !== void 0 ? name : node.name, parameters !== null && parameters !== void 0 ? parameters : node.parameters, returnType !== null && returnType !== void 0 ? returnType : node.returnType, {
|
|
7888
|
-
isAsync: node.isAsync,
|
|
7889
|
-
isFree: node.isFree,
|
|
7890
|
-
isStatic: node.isStatic,
|
|
7891
|
-
isOptional: node.isOptional,
|
|
7892
|
-
}, {
|
|
7893
|
-
extendedAttributes: node.extendedAttributes,
|
|
7894
|
-
fileName: node.fileName,
|
|
7895
|
-
documentation: node.documentation,
|
|
7896
|
-
}, node.typeParameters);
|
|
7897
|
-
}
|
|
7898
|
-
function nodeType(node) {
|
|
7899
|
-
var _a, _b;
|
|
7900
|
-
return (_b = (_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.find(it => it.name === Config.nodeTypeAttribute)) === null || _b === void 0 ? void 0 : _b.value;
|
|
7901
|
-
}
|
|
7902
|
-
function nodeNamespace(node) {
|
|
7903
|
-
var _a, _b;
|
|
7904
|
-
return (_b = (_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.find(it => it.name === Config.nodeNamespaceAttribute)) === null || _b === void 0 ? void 0 : _b.value;
|
|
7905
|
-
}
|
|
7906
|
-
function dropNamespace(node) {
|
|
7907
|
-
var _a, _b;
|
|
7908
|
-
const index = (_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.findIndex(it => it.name === Config.nodeNamespaceAttribute);
|
|
7909
|
-
if (index == undefined || index == -1)
|
|
7910
|
-
return;
|
|
7911
|
-
(_b = node.extendedAttributes) === null || _b === void 0 ? void 0 : _b.splice(index, 1);
|
|
7912
|
-
}
|
|
7913
|
-
function parent(node) {
|
|
7914
|
-
var _a;
|
|
7915
|
-
return (_a = node.inheritance[0]) === null || _a === void 0 ? void 0 : _a.name;
|
|
7916
|
-
}
|
|
7917
|
-
function createDefaultTypescriptWriter() {
|
|
7918
|
-
return new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => throwException(`unexpected type conversion`) });
|
|
7919
|
-
}
|
|
7920
|
-
function isIrNamespace(node) {
|
|
7921
|
-
return nodeNamespace(node) === Config.irNamespace;
|
|
7922
|
-
}
|
|
7923
|
-
function createSequence(inner) {
|
|
7924
|
-
return createContainerType(`sequence`, [inner]);
|
|
7925
|
-
}
|
|
7926
|
-
function innerType(node) {
|
|
7927
|
-
return node.elementType[0];
|
|
7928
|
-
}
|
|
7929
|
-
function innerTypeIfContainer(node) {
|
|
7930
|
-
if (isContainerType(node)) {
|
|
7931
|
-
return innerType(node);
|
|
7932
|
-
}
|
|
7933
|
-
return node;
|
|
7934
|
-
}
|
|
7935
|
-
function makeMethod(name, parameters, returnType, modifiers) {
|
|
7936
|
-
return new Method(name, makeSignature(parameters, returnType), modifiers !== null && modifiers !== void 0 ? modifiers : []);
|
|
7937
|
-
}
|
|
7938
|
-
function makeSignature(parameters, returnType) {
|
|
7939
|
-
return new MethodSignature(returnType, parameters.map(it => it.type), undefined, undefined, parameters
|
|
7940
|
-
.map(it => it.name)
|
|
7941
|
-
.map(mangleIfKeyword));
|
|
7942
|
-
}
|
|
7943
|
-
|
|
7944
8244
|
/*
|
|
7945
8245
|
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
7946
8246
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -8040,6 +8340,23 @@ function isReal(node) {
|
|
|
8040
8340
|
function isDataClass(node) {
|
|
8041
8341
|
return parent(node) === Config.defaultAncestor;
|
|
8042
8342
|
}
|
|
8343
|
+
function isCreate(name) {
|
|
8344
|
+
return isCreateOrUpdate(name) && name.startsWith(Config.createPrefix);
|
|
8345
|
+
}
|
|
8346
|
+
function isCreateOrUpdate(sourceMethodName) {
|
|
8347
|
+
if (!sourceMethodName.startsWith(Config.createPrefix) && !sourceMethodName.startsWith(Config.updatePrefix)) {
|
|
8348
|
+
return false;
|
|
8349
|
+
}
|
|
8350
|
+
const { rest } = splitCreateOrUpdate(sourceMethodName);
|
|
8351
|
+
return rest.length <= 1;
|
|
8352
|
+
}
|
|
8353
|
+
function fixEnumPrefix(name) {
|
|
8354
|
+
if (name.startsWith(`es2panda_`)) {
|
|
8355
|
+
name = dropPrefix(name, `es2panda_`);
|
|
8356
|
+
name = `Es2panda${name}`;
|
|
8357
|
+
}
|
|
8358
|
+
return name;
|
|
8359
|
+
}
|
|
8043
8360
|
|
|
8044
8361
|
/*
|
|
8045
8362
|
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
@@ -8055,57 +8372,108 @@ function isDataClass(node) {
|
|
|
8055
8372
|
* See the License for the specific language governing permissions and
|
|
8056
8373
|
* limitations under the License.
|
|
8057
8374
|
*/
|
|
8058
|
-
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
|
|
8062
|
-
|
|
8063
|
-
|
|
8064
|
-
|
|
8065
|
-
|
|
8066
|
-
|
|
8067
|
-
|
|
8068
|
-
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
return
|
|
8077
|
-
}
|
|
8078
|
-
static get getterAttribute() {
|
|
8079
|
-
return `get`;
|
|
8080
|
-
}
|
|
8081
|
-
static get uselessPrefix() {
|
|
8082
|
-
return `Get`;
|
|
8083
|
-
}
|
|
8084
|
-
static get astNodeCommonAncestor() {
|
|
8085
|
-
return `AstNode`;
|
|
8086
|
-
}
|
|
8087
|
-
static get context() {
|
|
8088
|
-
return `Context`;
|
|
8375
|
+
function isString(node) {
|
|
8376
|
+
return isPrimitiveType(node) && node.name === `String`;
|
|
8377
|
+
}
|
|
8378
|
+
function isSequence(node) {
|
|
8379
|
+
return IDLContainerUtils.isSequence(node);
|
|
8380
|
+
}
|
|
8381
|
+
function createUpdatedInterface(node, methods, name, inheritance, extendedAttributes, properties) {
|
|
8382
|
+
return createInterface(name !== null && name !== void 0 ? name : node.name, node.subkind, inheritance !== null && inheritance !== void 0 ? inheritance : node.inheritance, node.constructors, node.constants, properties !== null && properties !== void 0 ? properties : node.properties, methods !== null && methods !== void 0 ? methods : node.methods, node.callables, node.typeParameters, {
|
|
8383
|
+
extendedAttributes: extendedAttributes !== null && extendedAttributes !== void 0 ? extendedAttributes : node.extendedAttributes,
|
|
8384
|
+
fileName: node.fileName,
|
|
8385
|
+
documentation: node.documentation
|
|
8386
|
+
});
|
|
8387
|
+
}
|
|
8388
|
+
function baseName(type) {
|
|
8389
|
+
return baseNameString(type.name);
|
|
8390
|
+
}
|
|
8391
|
+
function baseNameString(name) {
|
|
8392
|
+
if (name.indexOf('.') > 0) {
|
|
8393
|
+
return name.substring(name.lastIndexOf('.') + 1);
|
|
8089
8394
|
}
|
|
8090
|
-
|
|
8091
|
-
return
|
|
8395
|
+
else {
|
|
8396
|
+
return name;
|
|
8092
8397
|
}
|
|
8093
|
-
|
|
8094
|
-
|
|
8095
|
-
|
|
8398
|
+
}
|
|
8399
|
+
// A bit of a hack, use namespaces for real later.
|
|
8400
|
+
function flattenType(type) {
|
|
8401
|
+
if (isUnionType(type))
|
|
8402
|
+
return createUnionType(type.types.map(flattenType), type.name);
|
|
8403
|
+
if (isOptionalType(type))
|
|
8404
|
+
return createOptionalType(flattenType(type.type));
|
|
8405
|
+
if (isContainerType(type))
|
|
8406
|
+
return createContainerType(type.containerKind, type.elementType.map(flattenType));
|
|
8407
|
+
if (isReferenceType(type)) {
|
|
8408
|
+
if (type.name.indexOf(".") > 0) {
|
|
8409
|
+
let result = createReferenceType(baseName(type));
|
|
8410
|
+
//console.log(`flatten ${type.name} to ${result.name}`)
|
|
8411
|
+
return result;
|
|
8096
8412
|
}
|
|
8097
|
-
const { rest } = splitCreateOrUpdate(sourceMethodName);
|
|
8098
|
-
return rest.length <= 1;
|
|
8099
8413
|
}
|
|
8100
|
-
|
|
8101
|
-
|
|
8414
|
+
return type;
|
|
8415
|
+
}
|
|
8416
|
+
function createUpdatedMethod(node, name, parameters, returnType, extendedAttributes) {
|
|
8417
|
+
return createMethod(name !== null && name !== void 0 ? name : node.name, parameters !== null && parameters !== void 0 ? parameters : node.parameters, returnType !== null && returnType !== void 0 ? returnType : node.returnType, {
|
|
8418
|
+
isAsync: node.isAsync,
|
|
8419
|
+
isFree: node.isFree,
|
|
8420
|
+
isStatic: node.isStatic,
|
|
8421
|
+
isOptional: node.isOptional,
|
|
8422
|
+
}, {
|
|
8423
|
+
extendedAttributes: node.extendedAttributes,
|
|
8424
|
+
fileName: node.fileName,
|
|
8425
|
+
documentation: node.documentation,
|
|
8426
|
+
}, node.typeParameters);
|
|
8427
|
+
}
|
|
8428
|
+
function nodeType(node) {
|
|
8429
|
+
var _a, _b;
|
|
8430
|
+
return (_b = (_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.find(it => it.name === Config.nodeTypeAttribute)) === null || _b === void 0 ? void 0 : _b.value;
|
|
8431
|
+
}
|
|
8432
|
+
function nodeNamespace(node) {
|
|
8433
|
+
var _a;
|
|
8434
|
+
return (_a = getNamespacesPathFor(node)[0]) === null || _a === void 0 ? void 0 : _a.name;
|
|
8435
|
+
}
|
|
8436
|
+
function parent(node) {
|
|
8437
|
+
var _a;
|
|
8438
|
+
return (_a = node.inheritance[0]) === null || _a === void 0 ? void 0 : _a.name;
|
|
8439
|
+
}
|
|
8440
|
+
function createDefaultTypescriptWriter() {
|
|
8441
|
+
return new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => throwException(`unexpected type conversion`) });
|
|
8442
|
+
}
|
|
8443
|
+
function isIrNamespace(node) {
|
|
8444
|
+
var _a, _b;
|
|
8445
|
+
let cppNamespace = (_b = (_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.find(it => it.name == Config.nodeNamespaceAttribute)) === null || _b === void 0 ? void 0 : _b.value;
|
|
8446
|
+
return nodeNamespace(node) === Config.irNamespace || cppNamespace == Config.irNamespace;
|
|
8447
|
+
}
|
|
8448
|
+
function createSequence(inner) {
|
|
8449
|
+
return createContainerType(`sequence`, [inner]);
|
|
8450
|
+
}
|
|
8451
|
+
function innerType(node) {
|
|
8452
|
+
return node.elementType[0];
|
|
8453
|
+
}
|
|
8454
|
+
function innerTypeIfContainer(node) {
|
|
8455
|
+
if (isContainerType(node)) {
|
|
8456
|
+
return innerType(node);
|
|
8102
8457
|
}
|
|
8103
|
-
|
|
8104
|
-
|
|
8458
|
+
return node;
|
|
8459
|
+
}
|
|
8460
|
+
function makeMethod(name, parameters, returnType, modifiers) {
|
|
8461
|
+
return new Method(name, makeSignature(parameters, returnType), modifiers !== null && modifiers !== void 0 ? modifiers : []);
|
|
8462
|
+
}
|
|
8463
|
+
function makeSignature(parameters, returnType) {
|
|
8464
|
+
let parameterModifiers = parameters.map(it => it.isOptional || isOptionalType(it.type) ? ArgumentModifier.OPTIONAL : undefined);
|
|
8465
|
+
let lastNonOptional = -1;
|
|
8466
|
+
for (let i = 0; i < parameterModifiers.length; i++) {
|
|
8467
|
+
if (parameterModifiers[i] == undefined)
|
|
8468
|
+
lastNonOptional = i;
|
|
8105
8469
|
}
|
|
8106
|
-
|
|
8107
|
-
|
|
8470
|
+
if (lastNonOptional != -1) {
|
|
8471
|
+
for (let i = 0; i < lastNonOptional; i++)
|
|
8472
|
+
parameterModifiers[i] = undefined;
|
|
8108
8473
|
}
|
|
8474
|
+
return new MethodSignature(returnType, parameters.map(it => it.type), undefined, parameterModifiers, undefined, parameters
|
|
8475
|
+
.map(it => it.name)
|
|
8476
|
+
.map(mangleIfKeyword));
|
|
8109
8477
|
}
|
|
8110
8478
|
|
|
8111
8479
|
/*
|
|
@@ -8125,16 +8493,19 @@ class Config {
|
|
|
8125
8493
|
class Typechecker {
|
|
8126
8494
|
constructor(idl) {
|
|
8127
8495
|
this.idl = idl;
|
|
8496
|
+
this.idl = linearizeNamespaceMembers(idl);
|
|
8128
8497
|
}
|
|
8129
8498
|
findRealDeclaration(name) {
|
|
8130
|
-
|
|
8499
|
+
// Poor man's namespace-aware resolve.
|
|
8500
|
+
// TODO: REWORK IT ALL!
|
|
8501
|
+
const declarations = this.idl.filter(it => (name === it.name) || (baseNameString(name) == baseNameString(it.name)));
|
|
8131
8502
|
if (declarations.length === 1) {
|
|
8132
8503
|
return declarations[0];
|
|
8133
8504
|
}
|
|
8134
8505
|
const ir = declarations
|
|
8135
8506
|
.filter(isInterface$1)
|
|
8136
8507
|
.filter(it => isIrNamespace(it));
|
|
8137
|
-
if (ir.length
|
|
8508
|
+
if (ir.length > 0) {
|
|
8138
8509
|
return ir[0];
|
|
8139
8510
|
}
|
|
8140
8511
|
return undefined;
|
|
@@ -8151,31 +8522,95 @@ class Typechecker {
|
|
|
8151
8522
|
if (parent === undefined) {
|
|
8152
8523
|
return declaration.name === ancestor;
|
|
8153
8524
|
}
|
|
8154
|
-
return this.isHeir(parent.name, ancestor);
|
|
8525
|
+
return this.isHeir(parent.name, ancestor);
|
|
8526
|
+
}
|
|
8527
|
+
isPeer(node) {
|
|
8528
|
+
if (node === Config.astNodeCommonAncestor)
|
|
8529
|
+
return false; // TODO: is handwritten
|
|
8530
|
+
if (node === Config.context)
|
|
8531
|
+
return false; // TODO: is handwritten
|
|
8532
|
+
if (this.isHeir(node, Config.astNodeCommonAncestor))
|
|
8533
|
+
return true;
|
|
8534
|
+
if (this.isHeir(node, Config.defaultAncestor))
|
|
8535
|
+
return true;
|
|
8536
|
+
return false;
|
|
8537
|
+
}
|
|
8538
|
+
isReferenceTo(type, isTarget) {
|
|
8539
|
+
if (!isReferenceType(type)) {
|
|
8540
|
+
return false;
|
|
8541
|
+
}
|
|
8542
|
+
const declaration = this.findRealDeclaration(type.name);
|
|
8543
|
+
return declaration !== undefined && isTarget(declaration);
|
|
8544
|
+
}
|
|
8545
|
+
isConstReturnValue(node) {
|
|
8546
|
+
if (isPrimitiveType(node.returnType) || this.isReferenceTo(node.returnType, isEnum$1)) {
|
|
8547
|
+
return false;
|
|
8548
|
+
}
|
|
8549
|
+
return node.name.endsWith(Config.constPostfix);
|
|
8550
|
+
}
|
|
8551
|
+
nodeTypeName(node) {
|
|
8552
|
+
var _a, _b;
|
|
8553
|
+
const value = nodeType(node);
|
|
8554
|
+
const idlEnum = this.idl
|
|
8555
|
+
.filter(isEnum$1)
|
|
8556
|
+
.find(it => it.name === Config.nodeTypeAttribute);
|
|
8557
|
+
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
|
+
}
|
|
8559
|
+
}
|
|
8560
|
+
|
|
8561
|
+
/*
|
|
8562
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
8563
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8564
|
+
* you may not use this file except in compliance with the License.
|
|
8565
|
+
* You may obtain a copy of the License at
|
|
8566
|
+
*
|
|
8567
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8568
|
+
*
|
|
8569
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
8570
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
8571
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8572
|
+
* See the License for the specific language governing permissions and
|
|
8573
|
+
* limitations under the License.
|
|
8574
|
+
*/
|
|
8575
|
+
class AbstractVisitor {
|
|
8576
|
+
visitChildren(entry) {
|
|
8577
|
+
if (isFile(entry)) {
|
|
8578
|
+
entry.entries.forEach(it => this.visit(it));
|
|
8579
|
+
}
|
|
8580
|
+
if (isNamespace(entry)) {
|
|
8581
|
+
entry.members.forEach(it => this.visit(it));
|
|
8582
|
+
}
|
|
8155
8583
|
}
|
|
8156
|
-
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
return true;
|
|
8163
|
-
if (this.isHeir(node, Config.defaultAncestor))
|
|
8164
|
-
return true;
|
|
8165
|
-
return false;
|
|
8584
|
+
}
|
|
8585
|
+
class SingleFilePrinter extends AbstractVisitor {
|
|
8586
|
+
constructor(idl) {
|
|
8587
|
+
super();
|
|
8588
|
+
this.idl = idl;
|
|
8589
|
+
this.typechecker = new Typechecker(this.idl.entries);
|
|
8166
8590
|
}
|
|
8167
|
-
|
|
8168
|
-
|
|
8169
|
-
|
|
8591
|
+
printEnum(node) { }
|
|
8592
|
+
visit(node) {
|
|
8593
|
+
if (isInterface$1(node) && !this.filterInterface(node)) {
|
|
8594
|
+
this.printInterface(node);
|
|
8170
8595
|
}
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
}
|
|
8174
|
-
isConstReturnValue(node) {
|
|
8175
|
-
if (isPrimitiveType(node.returnType) || this.isReferenceTo(node.returnType, isEnum$1)) {
|
|
8176
|
-
return false;
|
|
8596
|
+
if (isEnum$1(node)) {
|
|
8597
|
+
this.printEnum(node);
|
|
8177
8598
|
}
|
|
8178
|
-
|
|
8599
|
+
this.visitChildren(node);
|
|
8600
|
+
}
|
|
8601
|
+
prologue() { }
|
|
8602
|
+
epilogue() { }
|
|
8603
|
+
print() {
|
|
8604
|
+
var _a, _b;
|
|
8605
|
+
this.prologue();
|
|
8606
|
+
this.visit(this.idl);
|
|
8607
|
+
this.epilogue();
|
|
8608
|
+
return [
|
|
8609
|
+
(_b = (_a = this.importer) === null || _a === void 0 ? void 0 : _a.getOutput()) !== null && _b !== void 0 ? _b : [],
|
|
8610
|
+
this.writer.getOutput()
|
|
8611
|
+
]
|
|
8612
|
+
.flat()
|
|
8613
|
+
.join(`\n`);
|
|
8179
8614
|
}
|
|
8180
8615
|
}
|
|
8181
8616
|
|
|
@@ -8193,8 +8628,9 @@ class Typechecker {
|
|
|
8193
8628
|
* See the License for the specific language governing permissions and
|
|
8194
8629
|
* limitations under the License.
|
|
8195
8630
|
*/
|
|
8196
|
-
class InteropPrinter {
|
|
8631
|
+
class InteropPrinter extends AbstractVisitor {
|
|
8197
8632
|
constructor(file) {
|
|
8633
|
+
super();
|
|
8198
8634
|
this.file = file;
|
|
8199
8635
|
this.typechecker = new Typechecker(this.file.entries);
|
|
8200
8636
|
}
|
|
@@ -8204,23 +8640,17 @@ class InteropPrinter {
|
|
|
8204
8640
|
}
|
|
8205
8641
|
visit(node) {
|
|
8206
8642
|
if (isInterface$1(node)) {
|
|
8207
|
-
|
|
8208
|
-
}
|
|
8209
|
-
if (isEnum$1(node)) {
|
|
8210
|
-
return;
|
|
8211
|
-
}
|
|
8212
|
-
if (isTypedef$1(node)) {
|
|
8213
|
-
return;
|
|
8643
|
+
this.visitInterface(node);
|
|
8214
8644
|
}
|
|
8215
|
-
|
|
8645
|
+
this.visitChildren(node);
|
|
8216
8646
|
}
|
|
8217
8647
|
visitInterface(node) {
|
|
8218
|
-
node.methods.forEach(it => this.visitMethod(it));
|
|
8648
|
+
node.methods.forEach(it => this.visitMethod(node, it));
|
|
8219
8649
|
}
|
|
8220
|
-
visitMethod(node) {
|
|
8221
|
-
this.printMethod(node);
|
|
8650
|
+
visitMethod(iface, node) {
|
|
8651
|
+
this.printMethod(iface, node);
|
|
8222
8652
|
}
|
|
8223
|
-
printMethod(node) { }
|
|
8653
|
+
printMethod(iface, node) { }
|
|
8224
8654
|
}
|
|
8225
8655
|
|
|
8226
8656
|
/*
|
|
@@ -8251,9 +8681,11 @@ class BaseTypeConvertor {
|
|
|
8251
8681
|
convertPrimitiveType(type) {
|
|
8252
8682
|
switch (type) {
|
|
8253
8683
|
case IDLI8Type: return this.conversions.i8(type);
|
|
8684
|
+
case IDLU8Type: return this.conversions.iu8(type);
|
|
8254
8685
|
case IDLI16Type: return this.conversions.i16(type);
|
|
8255
8686
|
case IDLI32Type: return this.conversions.i32(type);
|
|
8256
8687
|
case IDLU32Type: return this.conversions.iu32(type);
|
|
8688
|
+
case IDLU64Type: return this.conversions.iu64(type);
|
|
8257
8689
|
case IDLI64Type: return this.conversions.i64(type);
|
|
8258
8690
|
case IDLF32Type: return this.conversions.f32(type);
|
|
8259
8691
|
case IDLF64Type: return this.conversions.f64(type);
|
|
@@ -8264,6 +8696,9 @@ class BaseTypeConvertor {
|
|
|
8264
8696
|
}
|
|
8265
8697
|
throwException(`unsupported primitive type: ${JSON.stringify(type)}`);
|
|
8266
8698
|
}
|
|
8699
|
+
convertTypeReferenceAsImport(type, importClause) {
|
|
8700
|
+
return this.convertTypeReference(type);
|
|
8701
|
+
}
|
|
8267
8702
|
convertTypeReference(type) {
|
|
8268
8703
|
if (this.typechecker.isReferenceTo(type, isEnum$1)) {
|
|
8269
8704
|
return this.conversions.enum(type);
|
|
@@ -8276,8 +8711,8 @@ class BaseTypeConvertor {
|
|
|
8276
8711
|
convertUnion(type) {
|
|
8277
8712
|
throwException("union type is not supported");
|
|
8278
8713
|
}
|
|
8279
|
-
convertImport(type
|
|
8280
|
-
throw new Error("
|
|
8714
|
+
convertImport(type) {
|
|
8715
|
+
throw new Error("Import is not supported");
|
|
8281
8716
|
}
|
|
8282
8717
|
convertTypeParameter(type) {
|
|
8283
8718
|
throw new Error("type parameters are not supported");
|
|
@@ -8313,6 +8748,7 @@ let ReturnTypeConvertor$1 = class ReturnTypeConvertor extends BaseTypeConvertor
|
|
|
8313
8748
|
reference: (type) => type,
|
|
8314
8749
|
optional: (type) => type,
|
|
8315
8750
|
i8: (type) => type,
|
|
8751
|
+
iu8: (type) => type,
|
|
8316
8752
|
i16: (type) => type,
|
|
8317
8753
|
i32: (type) => type,
|
|
8318
8754
|
iu32: (type) => type,
|
|
@@ -8343,7 +8779,7 @@ let ReturnTypeConvertor$1 = class ReturnTypeConvertor extends BaseTypeConvertor
|
|
|
8343
8779
|
*/
|
|
8344
8780
|
class InteropTypeConvertor extends BaseTypeConvertor {
|
|
8345
8781
|
constructor(typechecker, heirConversions) {
|
|
8346
|
-
super(typechecker, Object.assign({ enum: (type) => `KInt`, reference: (type) => `KNativePointer`, optional: (type) => throwException(`no nullable allowed at interop level`), i8: (type) => `KBoolean`, 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));
|
|
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));
|
|
8347
8783
|
}
|
|
8348
8784
|
}
|
|
8349
8785
|
|
|
@@ -8415,6 +8851,7 @@ class CastTypeConvertor extends BaseTypeConvertor {
|
|
|
8415
8851
|
enum: (type) => BridgesConstructions.enumCast(this.castToTypeConvertor.convertType(type)),
|
|
8416
8852
|
reference: (type) => BridgesConstructions.referenceTypeCast(this.castToTypeConvertor.convertType(type)),
|
|
8417
8853
|
i8: primitive,
|
|
8854
|
+
iu8: primitive,
|
|
8418
8855
|
i16: primitive,
|
|
8419
8856
|
i32: primitive,
|
|
8420
8857
|
iu32: primitive,
|
|
@@ -8437,10 +8874,13 @@ class CastToTypeConvertor extends BaseTypeConvertor {
|
|
|
8437
8874
|
super(typechecker, {
|
|
8438
8875
|
sequence: (type) => BridgesConstructions.arrayOf(this.convertType(innerType(type))),
|
|
8439
8876
|
enum: (type) => type.name,
|
|
8440
|
-
reference: (type) =>
|
|
8441
|
-
|
|
8442
|
-
|
|
8877
|
+
reference: (type) => {
|
|
8878
|
+
return BridgesConstructions.referenceType(typechecker.isHeir(type.name, Config.astNodeCommonAncestor)
|
|
8879
|
+
? Config.astNodeCommonAncestor
|
|
8880
|
+
: baseName(type));
|
|
8881
|
+
},
|
|
8443
8882
|
i8: primitive,
|
|
8883
|
+
iu8: primitive,
|
|
8444
8884
|
i16: primitive,
|
|
8445
8885
|
i32: primitive,
|
|
8446
8886
|
iu32: primitive,
|
|
@@ -8450,7 +8890,7 @@ class CastToTypeConvertor extends BaseTypeConvertor {
|
|
|
8450
8890
|
f64: primitive,
|
|
8451
8891
|
boolean: primitive,
|
|
8452
8892
|
optional: (type) => throwException(`no optional type allowed at interop level conversion`),
|
|
8453
|
-
string: (type) =>
|
|
8893
|
+
string: (type) => "const char*",
|
|
8454
8894
|
void: (type) => throwException(`no void typed parameters allowed`),
|
|
8455
8895
|
pointer: (type) => throwException(`no pointer typed parameters allowed`)
|
|
8456
8896
|
});
|
|
@@ -8473,8 +8913,9 @@ class CastToTypeConvertor extends BaseTypeConvertor {
|
|
|
8473
8913
|
* limitations under the License.
|
|
8474
8914
|
*/
|
|
8475
8915
|
class BridgesPrinter extends InteropPrinter {
|
|
8476
|
-
constructor() {
|
|
8477
|
-
super(
|
|
8916
|
+
constructor(config, file) {
|
|
8917
|
+
super(file);
|
|
8918
|
+
this.config = config;
|
|
8478
8919
|
this.castTypeConvertor = new CastTypeConvertor(this.typechecker);
|
|
8479
8920
|
this.nativeTypeConvertor = new NativeTypeConvertor(this.typechecker);
|
|
8480
8921
|
this.writer = new CppLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => this.nativeTypeConvertor.convertType(node) }, new class extends PrimitiveTypeList {
|
|
@@ -8499,15 +8940,15 @@ class BridgesPrinter extends InteropPrinter {
|
|
|
8499
8940
|
.map(it => this.interopMacroConvertor.convertType(it)))
|
|
8500
8941
|
.map(it => this.writer.makeString(it))));
|
|
8501
8942
|
}
|
|
8502
|
-
printMethod(node) {
|
|
8503
|
-
this.writer.writeFunctionImplementation(BridgesConstructions.implFunction(node.name), new MethodSignature(this.returnTypeConvertor.convertType(node.returnType), node.parameters.map(it => it.type), undefined, undefined, node.parameters.map(it => it.name)), (_) => this.printBody(node));
|
|
8943
|
+
printMethod(iface, node) {
|
|
8944
|
+
this.writer.writeFunctionImplementation(BridgesConstructions.implFunction(node.name), new MethodSignature(this.returnTypeConvertor.convertType(node.returnType), node.parameters.map(it => it.type), undefined, node.parameters.map(it => it.isOptional ? ArgumentModifier.OPTIONAL : undefined), undefined, node.parameters.map(it => it.name)), (_) => this.printBody(iface, node));
|
|
8504
8945
|
this.printInteropMacro(node);
|
|
8505
8946
|
this.writer.writeLines(``);
|
|
8506
8947
|
}
|
|
8507
|
-
printBody(node) {
|
|
8948
|
+
printBody(iface, node) {
|
|
8508
8949
|
this.printParameters(node);
|
|
8509
8950
|
this.printDeclarations(node);
|
|
8510
|
-
this.printEs2pandaCall(node);
|
|
8951
|
+
this.printEs2pandaCall(iface, node);
|
|
8511
8952
|
this.printReturn(node);
|
|
8512
8953
|
}
|
|
8513
8954
|
printParameters(node) {
|
|
@@ -8519,15 +8960,18 @@ class BridgesPrinter extends InteropPrinter {
|
|
|
8519
8960
|
this.writer.writeExpressionStatement(this.writer.makeString(BridgesConstructions.sequenceLengthDeclaration));
|
|
8520
8961
|
}
|
|
8521
8962
|
}
|
|
8522
|
-
printEs2pandaCall(node) {
|
|
8963
|
+
printEs2pandaCall(iface, node) {
|
|
8523
8964
|
if (isVoidType(node.returnType)) {
|
|
8524
|
-
this.writer.writeExpressionStatement(this.makeEs2pandaMethodCall(node));
|
|
8965
|
+
this.writer.writeExpressionStatement(this.makeEs2pandaMethodCall(iface, node));
|
|
8525
8966
|
return;
|
|
8526
8967
|
}
|
|
8527
|
-
this.writer.writeExpressionStatement(this.writer.makeString(BridgesConstructions.resultAssignment(this.makeEs2pandaMethodCall(node).asString())));
|
|
8968
|
+
this.writer.writeExpressionStatement(this.writer.makeString(BridgesConstructions.resultAssignment(this.makeEs2pandaMethodCall(iface, node).asString())));
|
|
8528
8969
|
}
|
|
8529
|
-
makeEs2pandaMethodCall(node) {
|
|
8530
|
-
|
|
8970
|
+
makeEs2pandaMethodCall(iface, node) {
|
|
8971
|
+
let suffix = this.config.irHack.isIrHackInterface(iface.name) ? 'Ir' : '';
|
|
8972
|
+
let method = BridgesConstructions.callMethod(node.name);
|
|
8973
|
+
method = method.replace(iface.name, iface.name + suffix);
|
|
8974
|
+
return this.writer.makeFunctionCall(method, node.parameters
|
|
8531
8975
|
.map(it => ({
|
|
8532
8976
|
asString: () => BridgesConstructions.castedParameter(it.name),
|
|
8533
8977
|
}))
|
|
@@ -8559,37 +9003,6 @@ class BridgesPrinter extends InteropPrinter {
|
|
|
8559
9003
|
}
|
|
8560
9004
|
}
|
|
8561
9005
|
|
|
8562
|
-
/*
|
|
8563
|
-
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
8564
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8565
|
-
* you may not use this file except in compliance with the License.
|
|
8566
|
-
* You may obtain a copy of the License at
|
|
8567
|
-
*
|
|
8568
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8569
|
-
*
|
|
8570
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
8571
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
8572
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8573
|
-
* See the License for the specific language governing permissions and
|
|
8574
|
-
* limitations under the License.
|
|
8575
|
-
*/
|
|
8576
|
-
class SingleFilePrinter {
|
|
8577
|
-
constructor(idl) {
|
|
8578
|
-
this.idl = idl;
|
|
8579
|
-
this.typechecker = new Typechecker(this.idl.entries);
|
|
8580
|
-
}
|
|
8581
|
-
print() {
|
|
8582
|
-
var _a, _b;
|
|
8583
|
-
this.visit();
|
|
8584
|
-
return [
|
|
8585
|
-
(_b = (_a = this.importer) === null || _a === void 0 ? void 0 : _a.getOutput()) !== null && _b !== void 0 ? _b : [],
|
|
8586
|
-
this.writer.getOutput()
|
|
8587
|
-
]
|
|
8588
|
-
.flat()
|
|
8589
|
-
.join(`\n`);
|
|
8590
|
-
}
|
|
8591
|
-
}
|
|
8592
|
-
|
|
8593
9006
|
/*
|
|
8594
9007
|
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
8595
9008
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -8630,13 +9043,12 @@ class EnumsPrinter extends SingleFilePrinter {
|
|
|
8630
9043
|
super(...arguments);
|
|
8631
9044
|
this.writer = new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => { throwException(`Unexpected call to covert type`); } });
|
|
8632
9045
|
}
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
.forEach(it => this.printEnum(it));
|
|
9046
|
+
printInterface(node) { }
|
|
9047
|
+
filterInterface(node) {
|
|
9048
|
+
return true;
|
|
8637
9049
|
}
|
|
8638
9050
|
printEnum(node) {
|
|
8639
|
-
this.writer.writeEnum(node.name, node.elements.map(it => {
|
|
9051
|
+
this.writer.writeEnum(fixEnumPrefix(node.name), node.elements.map(it => {
|
|
8640
9052
|
if (!isNumber(it.initializer)) {
|
|
8641
9053
|
throwException(`unexpected initializer value: ${it.initializer}`);
|
|
8642
9054
|
}
|
|
@@ -8645,7 +9057,7 @@ class EnumsPrinter extends SingleFilePrinter {
|
|
|
8645
9057
|
stringId: undefined,
|
|
8646
9058
|
numberId: it.initializer,
|
|
8647
9059
|
};
|
|
8648
|
-
}));
|
|
9060
|
+
}), { isExport: true });
|
|
8649
9061
|
}
|
|
8650
9062
|
}
|
|
8651
9063
|
|
|
@@ -8668,11 +9080,8 @@ class IndexPrinter extends SingleFilePrinter {
|
|
|
8668
9080
|
super(...arguments);
|
|
8669
9081
|
this.writer = createDefaultTypescriptWriter();
|
|
8670
9082
|
}
|
|
8671
|
-
|
|
8672
|
-
this.
|
|
8673
|
-
.filter(isInterface$1)
|
|
8674
|
-
.filter(it => this.typechecker.isPeer(it.name))
|
|
8675
|
-
.forEach(it => this.printInterface(it));
|
|
9083
|
+
filterInterface(node) {
|
|
9084
|
+
return !this.typechecker.isPeer(node.name);
|
|
8676
9085
|
}
|
|
8677
9086
|
printInterface(node) {
|
|
8678
9087
|
this.writer.writeExpressionStatement(this.writer.makeString(`export * from "./peers/${node.name}"`));
|
|
@@ -8750,6 +9159,7 @@ class ReturnTypeConvertor extends BaseTypeConvertor {
|
|
|
8750
9159
|
reference: (type) => type,
|
|
8751
9160
|
optional: (type) => type,
|
|
8752
9161
|
i8: (type) => type,
|
|
9162
|
+
iu8: (type) => type,
|
|
8753
9163
|
i16: (type) => type,
|
|
8754
9164
|
i32: (type) => type,
|
|
8755
9165
|
iu32: (type) => type,
|
|
@@ -8787,8 +9197,8 @@ class BindingsPrinter extends InteropPrinter {
|
|
|
8787
9197
|
this.returnConvertor = new ReturnTypeConvertor(this.typechecker);
|
|
8788
9198
|
this.writer.pushIndent();
|
|
8789
9199
|
}
|
|
8790
|
-
printMethod(node) {
|
|
8791
|
-
this.writer.writeMethodImplementation(new Method(BindingsConstructions.method(node.name), new MethodSignature(this.returnConvertor.convertType(node.returnType), node.parameters.map(it => it.type), undefined, undefined, node.parameters.map(it => it.name))), (writer) => {
|
|
9200
|
+
printMethod(iface, node) {
|
|
9201
|
+
this.writer.writeMethodImplementation(new Method(BindingsConstructions.method(node.name), new MethodSignature(this.returnConvertor.convertType(node.returnType), node.parameters.map(it => it.type), undefined, node.parameters.map(it => it.isOptional ? ArgumentModifier.OPTIONAL : undefined), undefined, node.parameters.map(it => it.name))), (writer) => {
|
|
8792
9202
|
writer.writeExpressionStatement(writer.makeString(BindingsConstructions.unimplemented));
|
|
8793
9203
|
});
|
|
8794
9204
|
}
|
|
@@ -8808,10 +9218,22 @@ class BindingsPrinter extends InteropPrinter {
|
|
|
8808
9218
|
* See the License for the specific language governing permissions and
|
|
8809
9219
|
* limitations under the License.
|
|
8810
9220
|
*/
|
|
8811
|
-
class MultiFilePrinter {
|
|
9221
|
+
class MultiFilePrinter extends AbstractVisitor {
|
|
8812
9222
|
constructor(idl) {
|
|
9223
|
+
super();
|
|
8813
9224
|
this.idl = idl;
|
|
8814
9225
|
this.typechecker = new Typechecker(this.idl.entries);
|
|
9226
|
+
this.output = [];
|
|
9227
|
+
}
|
|
9228
|
+
visit(node) {
|
|
9229
|
+
if (isInterface$1(node) && !this.filterInterface(node)) {
|
|
9230
|
+
this.output.push(this.printInterface(node));
|
|
9231
|
+
}
|
|
9232
|
+
this.visitChildren(node);
|
|
9233
|
+
}
|
|
9234
|
+
print() {
|
|
9235
|
+
this.visit(this.idl);
|
|
9236
|
+
return this.output;
|
|
8815
9237
|
}
|
|
8816
9238
|
}
|
|
8817
9239
|
|
|
@@ -8938,8 +9360,7 @@ class Importer {
|
|
|
8938
9360
|
this.writer = createDefaultTypescriptWriter();
|
|
8939
9361
|
this.seen = new Set([
|
|
8940
9362
|
Config.astNodeCommonAncestor,
|
|
8941
|
-
Config.defaultAncestor,
|
|
8942
|
-
`Es2pandaAstNodeType` // TODO: remove once enum generation is fixed
|
|
9363
|
+
Config.defaultAncestor, // TODO: handwritten
|
|
8943
9364
|
]);
|
|
8944
9365
|
if (self !== undefined) {
|
|
8945
9366
|
this.seen.add(self);
|
|
@@ -8990,6 +9411,7 @@ class TopLevelTypeConvertor extends BaseTypeConvertor {
|
|
|
8990
9411
|
constructor(typechecker, heirConversions) {
|
|
8991
9412
|
super(typechecker, Object.assign(Object.assign({}, heirConversions), {
|
|
8992
9413
|
i8: heirConversions.number,
|
|
9414
|
+
iu8: heirConversions.number,
|
|
8993
9415
|
i16: heirConversions.number,
|
|
8994
9416
|
i32: heirConversions.number,
|
|
8995
9417
|
iu32: heirConversions.number,
|
|
@@ -9064,7 +9486,7 @@ class ImporterTypeConvertor extends TopLevelTypeConvertor {
|
|
|
9064
9486
|
return type;
|
|
9065
9487
|
},
|
|
9066
9488
|
reference: (type) => {
|
|
9067
|
-
this.importer.withPeerImport(type
|
|
9489
|
+
this.importer.withPeerImport(baseName(type));
|
|
9068
9490
|
return type;
|
|
9069
9491
|
},
|
|
9070
9492
|
string: (type) => type,
|
|
@@ -9172,29 +9594,34 @@ class BindingReturnValueTypeConvertor extends TopLevelTypeConvertor {
|
|
|
9172
9594
|
* limitations under the License.
|
|
9173
9595
|
*/
|
|
9174
9596
|
class PeerPrinter extends SingleFilePrinter {
|
|
9175
|
-
|
|
9176
|
-
|
|
9597
|
+
printInterface(node) {
|
|
9598
|
+
if (node != this.node)
|
|
9599
|
+
throw new Error("Must match");
|
|
9600
|
+
this.printPeer();
|
|
9601
|
+
if (!isDataClass(this.node)) {
|
|
9602
|
+
this.printTypeGuard();
|
|
9603
|
+
}
|
|
9604
|
+
if (isReal(this.node)) {
|
|
9605
|
+
this.printAddToNodeMap();
|
|
9606
|
+
}
|
|
9607
|
+
}
|
|
9608
|
+
filterInterface(node) {
|
|
9609
|
+
return node != this.node;
|
|
9610
|
+
}
|
|
9611
|
+
constructor(config, idl, node) {
|
|
9177
9612
|
super(idl);
|
|
9613
|
+
this.config = config;
|
|
9178
9614
|
this.node = node;
|
|
9179
9615
|
this.typechecker = new Typechecker(this.idl.entries);
|
|
9180
9616
|
this.importer = new Importer(this.typechecker, `.`, this.node.name);
|
|
9181
9617
|
this.bindingParameterTypeConvertor = new BindingParameterTypeConvertor(this.typechecker);
|
|
9182
9618
|
this.bindingReturnValueTypeConvertor = new BindingReturnValueTypeConvertor(this.typechecker);
|
|
9183
|
-
this.parent =
|
|
9619
|
+
this.parent = parent(this.node); // ?? throwException(`expected peer to have parent: ${this.node.name}`)
|
|
9184
9620
|
this.writer = new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => composedConvertType(new LibraryTypeConvertor(this.typechecker), new ImporterTypeConvertor(this.importer, this.typechecker), node)
|
|
9185
9621
|
});
|
|
9186
9622
|
}
|
|
9187
|
-
visit() {
|
|
9188
|
-
this.printPeer();
|
|
9189
|
-
if (!isDataClass(this.node)) {
|
|
9190
|
-
this.printTypeGuard();
|
|
9191
|
-
}
|
|
9192
|
-
if (isReal(this.node)) {
|
|
9193
|
-
this.printAddToNodeMap();
|
|
9194
|
-
}
|
|
9195
|
-
}
|
|
9196
9623
|
printPeer() {
|
|
9197
|
-
this.writer.writeClass(this.node.name, () => this.printBody(), this.importer.withPeerImport(this.parent));
|
|
9624
|
+
this.writer.writeClass(this.node.name, () => this.printBody(), this.parent ? this.importer.withPeerImport(this.parent) : undefined);
|
|
9198
9625
|
}
|
|
9199
9626
|
printBody() {
|
|
9200
9627
|
this.printConstructor();
|
|
@@ -9203,7 +9630,7 @@ class PeerPrinter extends SingleFilePrinter {
|
|
|
9203
9630
|
printConstructor() {
|
|
9204
9631
|
this.writer.writeConstructorImplementation(this.node.name, new MethodSignature(IDLVoidType, [
|
|
9205
9632
|
IDLPointerType
|
|
9206
|
-
], undefined, undefined, [
|
|
9633
|
+
], undefined, undefined, undefined, [
|
|
9207
9634
|
PeersConstructions.pointerParameter
|
|
9208
9635
|
]), () => {
|
|
9209
9636
|
var _a;
|
|
@@ -9219,13 +9646,13 @@ class PeerPrinter extends SingleFilePrinter {
|
|
|
9219
9646
|
});
|
|
9220
9647
|
}
|
|
9221
9648
|
printTypeGuard() {
|
|
9222
|
-
this.writer.writeFunctionImplementation(PeersConstructions.typeGuard.name(this.node.name), new MethodSignature(createReferenceType(PeersConstructions.typeGuard.returnType(this.node.name)), [createReferenceType(PeersConstructions.typeGuard.parameter.type)], undefined, undefined, [PeersConstructions.typeGuard.parameter.name]), () => {
|
|
9649
|
+
this.writer.writeFunctionImplementation(PeersConstructions.typeGuard.name(this.node.name), new MethodSignature(createReferenceType(PeersConstructions.typeGuard.returnType(this.node.name)), [createReferenceType(PeersConstructions.typeGuard.parameter.type)], undefined, undefined, undefined, [PeersConstructions.typeGuard.parameter.name]), () => {
|
|
9223
9650
|
this.writer.writeStatement(this.writer.makeReturn(this.writer.makeString(PeersConstructions.typeGuard.body(this.node.name))));
|
|
9224
9651
|
});
|
|
9225
9652
|
}
|
|
9226
9653
|
printMethods() {
|
|
9227
9654
|
this.node.methods.forEach(it => {
|
|
9228
|
-
if (
|
|
9655
|
+
if (isCreateOrUpdate(it.name)) {
|
|
9229
9656
|
if (isAbstract(this.node)) {
|
|
9230
9657
|
return;
|
|
9231
9658
|
}
|
|
@@ -9240,13 +9667,13 @@ class PeerPrinter extends SingleFilePrinter {
|
|
|
9240
9667
|
});
|
|
9241
9668
|
}
|
|
9242
9669
|
printGetter(node) {
|
|
9243
|
-
this.writer.writeMethodImplementation(new Method(peerMethod(node.name), new MethodSignature(node.returnType, []), [MethodModifier.GETTER]), () => {
|
|
9670
|
+
this.writer.writeMethodImplementation(new Method(peerMethod(node.name), new MethodSignature(flattenType(node.returnType), []), [MethodModifier.GETTER]), () => {
|
|
9244
9671
|
this.writer.writeStatement(this.writer.makeReturn(this.makeReturnBindingCall(node)));
|
|
9245
9672
|
});
|
|
9246
9673
|
}
|
|
9247
9674
|
printRegular(node) {
|
|
9248
9675
|
this.writer.writeExpressionStatement(this.writer.makeString(`/** @deprecated */`));
|
|
9249
|
-
this.writer.writeMethodImplementation(makeMethod(peerMethod(node.name), node.parameters, PeersConstructions.this.type), () => {
|
|
9676
|
+
this.writer.writeMethodImplementation(makeMethod(peerMethod(node.name), node.parameters.map(it => createParameter(it.name, flattenType(it.type))), flattenType(PeersConstructions.this.type)), () => {
|
|
9250
9677
|
this.writer.writeExpressionStatement(this.makeReturnBindingCall(node));
|
|
9251
9678
|
this.writer.writeStatement(this.writer.makeReturn(this.writer.makeString(PeersConstructions.this.name)));
|
|
9252
9679
|
});
|
|
@@ -9259,7 +9686,7 @@ class PeerPrinter extends SingleFilePrinter {
|
|
|
9259
9686
|
return this.bindingReturnValueTypeConvertor.convertType(node.returnType)(this.writer, nativeCall);
|
|
9260
9687
|
}
|
|
9261
9688
|
printCreateOrUpdate(node) {
|
|
9262
|
-
this.writer.writeMethodImplementation(makeMethod(PeersConstructions.createOrUpdate(this.node.name, node.name), node.parameters, node.returnType, [MethodModifier.STATIC]), () => {
|
|
9689
|
+
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]), () => {
|
|
9263
9690
|
this.writer.writeStatement(this.writer.makeReturn(this.writer.makeNewObject(this.node.name, [
|
|
9264
9691
|
this.writer.makeFunctionCall(this.writer.makeString(PeersConstructions.callBinding(this.node.name, node.name, nodeNamespace(this.node))), this.makeBindingArguments(node.parameters))
|
|
9265
9692
|
])));
|
|
@@ -9275,7 +9702,12 @@ class PeerPrinter extends SingleFilePrinter {
|
|
|
9275
9702
|
.map(it => this.writer.makeString(it));
|
|
9276
9703
|
}
|
|
9277
9704
|
printAddToNodeMap() {
|
|
9278
|
-
|
|
9705
|
+
const enumValue = this.typechecker.nodeTypeName(this.node);
|
|
9706
|
+
if (enumValue === undefined) {
|
|
9707
|
+
return;
|
|
9708
|
+
}
|
|
9709
|
+
const qualified = `${this.importer.withEnumImport(Config.nodeTypeAttribute)}.${enumValue}`;
|
|
9710
|
+
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(`}`));
|
|
9279
9711
|
}
|
|
9280
9712
|
}
|
|
9281
9713
|
|
|
@@ -9294,16 +9726,17 @@ class PeerPrinter extends SingleFilePrinter {
|
|
|
9294
9726
|
* limitations under the License.
|
|
9295
9727
|
*/
|
|
9296
9728
|
class AllPeersPrinter extends MultiFilePrinter {
|
|
9297
|
-
|
|
9298
|
-
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
|
|
9729
|
+
constructor(config, idl) {
|
|
9730
|
+
super(idl);
|
|
9731
|
+
this.config = config;
|
|
9732
|
+
}
|
|
9733
|
+
filterInterface(node) {
|
|
9734
|
+
return !this.typechecker.isPeer(node.name);
|
|
9302
9735
|
}
|
|
9303
9736
|
printInterface(node) {
|
|
9304
9737
|
return {
|
|
9305
9738
|
fileName: PeersConstructions.fileName(node.name),
|
|
9306
|
-
output: new PeerPrinter(this.idl, node).print()
|
|
9739
|
+
output: new PeerPrinter(this.config, this.idl, node).print()
|
|
9307
9740
|
};
|
|
9308
9741
|
}
|
|
9309
9742
|
}
|
|
@@ -9364,36 +9797,41 @@ class FactoryPrinter extends SingleFilePrinter {
|
|
|
9364
9797
|
this.writer = new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => composedConvertType(new LibraryTypeConvertor(this.typechecker), new ImporterTypeConvertor(this.importer, this.typechecker), node)
|
|
9365
9798
|
});
|
|
9366
9799
|
}
|
|
9367
|
-
|
|
9800
|
+
prologue() {
|
|
9368
9801
|
this.writer.writeExpressionStatements(this.writer.makeString(FactoryConstructions.prologue));
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
9372
|
-
|
|
9802
|
+
this.writer.pushIndent();
|
|
9803
|
+
}
|
|
9804
|
+
epilogue() {
|
|
9805
|
+
this.writer.popIndent();
|
|
9373
9806
|
this.writer.writeExpressionStatements(this.writer.makeString(FactoryConstructions.epilogue));
|
|
9374
9807
|
}
|
|
9375
|
-
|
|
9376
|
-
this.
|
|
9377
|
-
|
|
9378
|
-
|
|
9379
|
-
|
|
9380
|
-
|
|
9381
|
-
|
|
9382
|
-
|
|
9383
|
-
]));
|
|
9808
|
+
filterInterface(node) {
|
|
9809
|
+
return !this.typechecker.isPeer(node.name) || FactoryPrinter.getUniversalCreate(node) == undefined;
|
|
9810
|
+
}
|
|
9811
|
+
printInterface(node) {
|
|
9812
|
+
this.printCreate(node);
|
|
9813
|
+
this.writer.print(',');
|
|
9814
|
+
this.printUpdate(node);
|
|
9815
|
+
this.writer.print(',');
|
|
9384
9816
|
}
|
|
9385
9817
|
printCreate(node) {
|
|
9386
|
-
this.writer.writeMethodImplementation(makeMethod(PeersConstructions.universalCreate(node.name), node.properties, createReferenceType(node.name)), () => this.writer.writeStatement(this.writer.makeReturn(this.writer.makeFunctionCall(FactoryPrinter.callUniversalCreate(node), node.properties
|
|
9818
|
+
this.writer.writeMethodImplementation(makeMethod(PeersConstructions.universalCreate(node.name), this.makeParameters(node.properties), flattenType(createReferenceType(node.name))), () => this.writer.writeStatement(this.writer.makeReturn(this.writer.makeFunctionCall(FactoryPrinter.callUniversalCreate(node), node.properties
|
|
9387
9819
|
.map(it => it.name)
|
|
9388
9820
|
.map(mangleIfKeyword)
|
|
9389
9821
|
.map(it => this.writer.makeString(it))))));
|
|
9390
9822
|
}
|
|
9823
|
+
makeParameters(properties) {
|
|
9824
|
+
// We may need to ensure optional parameters are at the end
|
|
9825
|
+
return properties
|
|
9826
|
+
.map(it => createParameter(it.name, flattenType(it.type), it.isOptional));
|
|
9827
|
+
}
|
|
9391
9828
|
printUpdate(node) {
|
|
9392
9829
|
this.writer.writeMethodImplementation(makeMethod(PeersConstructions.universalUpdate(node.name), [{
|
|
9393
9830
|
name: FactoryConstructions.original,
|
|
9394
|
-
type: id(createReferenceType(node.name))
|
|
9831
|
+
type: id(flattenType(createReferenceType(node.name))),
|
|
9832
|
+
isOptional: false
|
|
9395
9833
|
}]
|
|
9396
|
-
.concat(node.properties), createReferenceType(node.name)), () => {
|
|
9834
|
+
.concat(this.makeParameters(node.properties)), flattenType(createReferenceType(node.name))), () => {
|
|
9397
9835
|
this.printUnchangedBranch(node);
|
|
9398
9836
|
this.printChangedBranch(node);
|
|
9399
9837
|
});
|
|
@@ -9420,7 +9858,7 @@ class FactoryPrinter extends SingleFilePrinter {
|
|
|
9420
9858
|
return PeersConstructions.callPeerMethod(node.name, PeersConstructions.createOrUpdate(node.name, (_b = (_a = FactoryPrinter.getUniversalCreate(node)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : throwException(`unexpected node with no universal create`)));
|
|
9421
9859
|
}
|
|
9422
9860
|
static getUniversalCreate(node) {
|
|
9423
|
-
const creates = node.methods.filter(it =>
|
|
9861
|
+
const creates = node.methods.filter(it => isCreate(it.name));
|
|
9424
9862
|
if (creates.length !== 1) {
|
|
9425
9863
|
return undefined;
|
|
9426
9864
|
}
|
|
@@ -9445,24 +9883,66 @@ class FactoryPrinter extends SingleFilePrinter {
|
|
|
9445
9883
|
* See the License for the specific language governing permissions and
|
|
9446
9884
|
* limitations under the License.
|
|
9447
9885
|
*/
|
|
9448
|
-
class
|
|
9449
|
-
constructor(file) {
|
|
9886
|
+
class Transformer {
|
|
9887
|
+
constructor(file, removeNamespaces = false) {
|
|
9450
9888
|
this.file = file;
|
|
9451
|
-
this.
|
|
9889
|
+
this.removeNamespaces = removeNamespaces;
|
|
9890
|
+
}
|
|
9891
|
+
transformFile(input) {
|
|
9892
|
+
let entries = this.removeNamespaces ?
|
|
9893
|
+
linearizeNamespaceMembers(input.entries).filter(it => !isNamespace(it)) : input.entries;
|
|
9894
|
+
let file = createFile(entries
|
|
9895
|
+
.map(it => this.transformDeep(it))
|
|
9896
|
+
.filter(isDefined), input.fileName);
|
|
9897
|
+
linkParentBack(file);
|
|
9898
|
+
return file;
|
|
9899
|
+
}
|
|
9900
|
+
transformDeep(entry) {
|
|
9901
|
+
if (isNamespace(entry)) {
|
|
9902
|
+
return createNamespace(entry.name, entry.members
|
|
9903
|
+
.map(it => this.transformDeep(it))
|
|
9904
|
+
.filter(isDefined));
|
|
9905
|
+
}
|
|
9906
|
+
return this.transform(entry);
|
|
9907
|
+
}
|
|
9908
|
+
transform(entry) {
|
|
9909
|
+
if (isInterface$1(entry))
|
|
9910
|
+
return this.transformInterface(entry);
|
|
9911
|
+
else
|
|
9912
|
+
return entry;
|
|
9452
9913
|
}
|
|
9453
9914
|
transformed() {
|
|
9454
|
-
return
|
|
9455
|
-
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9915
|
+
return this.transformFile(this.file);
|
|
9916
|
+
}
|
|
9917
|
+
}
|
|
9918
|
+
|
|
9919
|
+
/*
|
|
9920
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
9921
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9922
|
+
* you may not use this file except in compliance with the License.
|
|
9923
|
+
* You may obtain a copy of the License at
|
|
9924
|
+
*
|
|
9925
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9926
|
+
*
|
|
9927
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
9928
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
9929
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9930
|
+
* See the License for the specific language governing permissions and
|
|
9931
|
+
* limitations under the License.
|
|
9932
|
+
*/
|
|
9933
|
+
class BaseInterfaceFilterTransformer extends Transformer {
|
|
9934
|
+
constructor(file, removeNamespaces = false) {
|
|
9935
|
+
super(file, removeNamespaces);
|
|
9936
|
+
this.typechecker = new Typechecker(this.file.entries);
|
|
9937
|
+
}
|
|
9938
|
+
transformInterface(entry) {
|
|
9939
|
+
if (this.shouldFilterOutInterface(entry.name)) {
|
|
9940
|
+
return undefined;
|
|
9941
|
+
}
|
|
9942
|
+
return createUpdatedInterface(entry, entry.methods
|
|
9943
|
+
.filter(it => !this.shouldFilterOutMethod(entry.name, it.name))
|
|
9944
|
+
.filter(it => !this.isReferringForbiddenOrMissing(it, (name) => this.shouldFilterOutInterface(name))), entry.name, entry.inheritance, entry.extendedAttributes, entry.properties
|
|
9945
|
+
.filter(it => !this.shouldFilterOutProperty(entry.name, it.name)));
|
|
9466
9946
|
}
|
|
9467
9947
|
isReferringForbiddenOrMissing(node, predicate) {
|
|
9468
9948
|
return node.parameters
|
|
@@ -9479,8 +9959,7 @@ class BaseInterfaceFilterTransformer {
|
|
|
9479
9959
|
}
|
|
9480
9960
|
}
|
|
9481
9961
|
return false;
|
|
9482
|
-
})
|
|
9483
|
-
.length !== 0;
|
|
9962
|
+
}).length !== 0;
|
|
9484
9963
|
}
|
|
9485
9964
|
}
|
|
9486
9965
|
|
|
@@ -9504,10 +9983,13 @@ class OptionsFilterTransformer extends BaseInterfaceFilterTransformer {
|
|
|
9504
9983
|
this.config = config;
|
|
9505
9984
|
}
|
|
9506
9985
|
shouldFilterOutInterface(name) {
|
|
9507
|
-
return
|
|
9986
|
+
return this.config.ignore.isIgnoredInterface(name);
|
|
9508
9987
|
}
|
|
9509
9988
|
shouldFilterOutMethod(node, name) {
|
|
9510
|
-
return
|
|
9989
|
+
return this.config.ignore.isIgnoredMethod(node, name);
|
|
9990
|
+
}
|
|
9991
|
+
shouldFilterOutProperty(node, name) {
|
|
9992
|
+
return this.config.ignore.isIgnoredProperty(node, name);
|
|
9511
9993
|
}
|
|
9512
9994
|
}
|
|
9513
9995
|
|
|
@@ -9525,18 +10007,23 @@ class OptionsFilterTransformer extends BaseInterfaceFilterTransformer {
|
|
|
9525
10007
|
* See the License for the specific language governing permissions and
|
|
9526
10008
|
* limitations under the License.
|
|
9527
10009
|
*/
|
|
9528
|
-
class AddContextDeclarationTransformer {
|
|
10010
|
+
class AddContextDeclarationTransformer extends Transformer {
|
|
9529
10011
|
constructor(file) {
|
|
9530
|
-
|
|
10012
|
+
super(file);
|
|
10013
|
+
}
|
|
10014
|
+
transformInterface(entry) {
|
|
10015
|
+
return entry;
|
|
9531
10016
|
}
|
|
9532
10017
|
transformed() {
|
|
9533
|
-
|
|
10018
|
+
let file = createFile(this.file.entries
|
|
9534
10019
|
.concat(createInterface(Config.context, IDLInterfaceSubkind.Class, undefined, undefined, undefined, undefined, undefined, undefined, undefined, {
|
|
9535
10020
|
extendedAttributes: [{
|
|
9536
10021
|
name: Config.nodeNamespaceAttribute,
|
|
9537
10022
|
value: Config.irNamespace
|
|
9538
10023
|
}]
|
|
9539
10024
|
})));
|
|
10025
|
+
linkParentBack(file);
|
|
10026
|
+
return file;
|
|
9540
10027
|
}
|
|
9541
10028
|
}
|
|
9542
10029
|
|
|
@@ -9554,30 +10041,27 @@ class AddContextDeclarationTransformer {
|
|
|
9554
10041
|
* See the License for the specific language governing permissions and
|
|
9555
10042
|
* limitations under the License.
|
|
9556
10043
|
*/
|
|
9557
|
-
class MultipleDeclarationFilterTransformer {
|
|
10044
|
+
class MultipleDeclarationFilterTransformer extends Transformer {
|
|
9558
10045
|
constructor(file) {
|
|
9559
|
-
|
|
9560
|
-
|
|
9561
|
-
|
|
9562
|
-
|
|
9563
|
-
this.file.entries.forEach(it => {
|
|
10046
|
+
super(file);
|
|
10047
|
+
this.seen = new Map();
|
|
10048
|
+
// TODO: namespaces
|
|
10049
|
+
linearizeNamespaceMembers(this.file.entries).forEach(it => {
|
|
9564
10050
|
var _a;
|
|
9565
|
-
|
|
9566
|
-
seen.
|
|
10051
|
+
let name = baseNameString(it.name);
|
|
10052
|
+
const oldValue = (_a = this.seen.get(name)) !== null && _a !== void 0 ? _a : 0;
|
|
10053
|
+
this.seen.set(name, oldValue + 1);
|
|
9567
10054
|
});
|
|
9568
|
-
|
|
9569
|
-
|
|
9570
|
-
|
|
9571
|
-
|
|
9572
|
-
|
|
9573
|
-
|
|
9574
|
-
|
|
9575
|
-
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
return undefined;
|
|
9579
|
-
return it;
|
|
9580
|
-
}), this.file.fileName);
|
|
10055
|
+
}
|
|
10056
|
+
transformInterface(entry) {
|
|
10057
|
+
var _a;
|
|
10058
|
+
const occurence = (_a = this.seen.get(baseNameString(entry.name))) !== null && _a !== void 0 ? _a : 0;
|
|
10059
|
+
if (occurence > 1 && !isIrNamespace(entry)) {
|
|
10060
|
+
console.log(`FILTERED (MULTIPLE) ${entry.name}`);
|
|
10061
|
+
this.seen.set(baseNameString(entry.name), occurence - 1);
|
|
10062
|
+
return undefined;
|
|
10063
|
+
}
|
|
10064
|
+
return entry;
|
|
9581
10065
|
}
|
|
9582
10066
|
}
|
|
9583
10067
|
|
|
@@ -9595,18 +10079,9 @@ class MultipleDeclarationFilterTransformer {
|
|
|
9595
10079
|
* See the License for the specific language governing permissions and
|
|
9596
10080
|
* limitations under the License.
|
|
9597
10081
|
*/
|
|
9598
|
-
class ParameterTransformer {
|
|
10082
|
+
class ParameterTransformer extends Transformer {
|
|
9599
10083
|
constructor(file) {
|
|
9600
|
-
|
|
9601
|
-
}
|
|
9602
|
-
transformed() {
|
|
9603
|
-
return createFile(this.file.entries
|
|
9604
|
-
.map(it => {
|
|
9605
|
-
if (isInterface$1(it)) {
|
|
9606
|
-
return this.transformInterface(it);
|
|
9607
|
-
}
|
|
9608
|
-
return it;
|
|
9609
|
-
}));
|
|
10084
|
+
super(file);
|
|
9610
10085
|
}
|
|
9611
10086
|
transformInterface(node) {
|
|
9612
10087
|
return createUpdatedInterface(node, node.methods.map(it => this.transformMethod(it, node)));
|
|
@@ -9645,15 +10120,15 @@ class ParameterTransformer {
|
|
|
9645
10120
|
* See the License for the specific language governing permissions and
|
|
9646
10121
|
* limitations under the License.
|
|
9647
10122
|
*/
|
|
9648
|
-
class TwinMergeTransformer {
|
|
10123
|
+
class TwinMergeTransformer extends Transformer {
|
|
9649
10124
|
constructor(file) {
|
|
9650
|
-
|
|
9651
|
-
const all = file.entries.filter(isInterface$1);
|
|
10125
|
+
super(file);
|
|
10126
|
+
const all = linearizeNamespaceMembers(file.entries).filter(isInterface$1);
|
|
9652
10127
|
this.twins = new Set();
|
|
9653
10128
|
all
|
|
9654
10129
|
.filter(it => this.hasPrefix(it.name))
|
|
9655
10130
|
.forEach(it => {
|
|
9656
|
-
const twin = all.find(candidate => this.withPrefix(candidate.name) === it.name);
|
|
10131
|
+
const twin = all.find(candidate => this.withPrefix(baseNameString(candidate.name)) === it.name);
|
|
9657
10132
|
if (twin === undefined)
|
|
9658
10133
|
return;
|
|
9659
10134
|
if (!isIrNamespace(twin))
|
|
@@ -9662,26 +10137,20 @@ class TwinMergeTransformer {
|
|
|
9662
10137
|
});
|
|
9663
10138
|
}
|
|
9664
10139
|
hasTwin(name) {
|
|
10140
|
+
name = baseNameString(name);
|
|
9665
10141
|
if (this.hasPrefix(name)) {
|
|
9666
10142
|
return this.twins.has(this.withoutPrefix(name));
|
|
9667
10143
|
}
|
|
9668
10144
|
return this.twins.has(name);
|
|
9669
10145
|
}
|
|
9670
|
-
transformed() {
|
|
9671
|
-
return createFile(this.file.entries
|
|
9672
|
-
.map(it => {
|
|
9673
|
-
if (isInterface$1(it)) {
|
|
9674
|
-
return this.transformInterface(it);
|
|
9675
|
-
}
|
|
9676
|
-
return it;
|
|
9677
|
-
})
|
|
9678
|
-
.filter(isDefined));
|
|
9679
|
-
}
|
|
9680
10146
|
transformInterface(node) {
|
|
10147
|
+
if (node.name === Config.astNodeCommonAncestor) { // TODO: is handwritten
|
|
10148
|
+
return createUpdatedInterface(node, node.methods.map(it => this.transformMethod(it)));
|
|
10149
|
+
}
|
|
9681
10150
|
if (this.hasTwin(node.name) && this.hasPrefix(node.name)) {
|
|
9682
10151
|
return undefined;
|
|
9683
10152
|
}
|
|
9684
|
-
if (this.hasTwin(node.name)
|
|
10153
|
+
if (this.hasTwin(node.name) || this.hasPrefix(node.name)) {
|
|
9685
10154
|
return createUpdatedInterface(node, node.methods.map(it => this.transformMethod(it)), this.withoutPrefix(node.name), [createReferenceType(Config.defaultAncestor)]);
|
|
9686
10155
|
}
|
|
9687
10156
|
return createUpdatedInterface(node, node.methods.map(it => this.transformMethod(it)));
|
|
@@ -9732,16 +10201,23 @@ class TwinMergeTransformer {
|
|
|
9732
10201
|
* limitations under the License.
|
|
9733
10202
|
*/
|
|
9734
10203
|
class AstNodeFilterTransformer extends BaseInterfaceFilterTransformer {
|
|
10204
|
+
constructor(idl) {
|
|
10205
|
+
super(idl, true);
|
|
10206
|
+
}
|
|
9735
10207
|
shouldFilterOutInterface(name) {
|
|
9736
10208
|
if (this.typechecker.isHeir(name, Config.astNodeCommonAncestor))
|
|
9737
10209
|
return false;
|
|
9738
10210
|
if (this.typechecker.isHeir(name, Config.defaultAncestor))
|
|
9739
10211
|
return false;
|
|
10212
|
+
console.log(`FILTERED (AST) ${name}`);
|
|
9740
10213
|
return true;
|
|
9741
10214
|
}
|
|
9742
10215
|
shouldFilterOutMethod(node, name) {
|
|
9743
10216
|
return false;
|
|
9744
10217
|
}
|
|
10218
|
+
shouldFilterOutProperty(node, name) {
|
|
10219
|
+
return false;
|
|
10220
|
+
}
|
|
9745
10221
|
}
|
|
9746
10222
|
|
|
9747
10223
|
/*
|
|
@@ -9758,21 +10234,12 @@ class AstNodeFilterTransformer extends BaseInterfaceFilterTransformer {
|
|
|
9758
10234
|
* See the License for the specific language governing permissions and
|
|
9759
10235
|
* limitations under the License.
|
|
9760
10236
|
*/
|
|
9761
|
-
class NullabilityTransformer {
|
|
10237
|
+
class NullabilityTransformer extends Transformer {
|
|
9762
10238
|
constructor(file, config) {
|
|
9763
|
-
|
|
10239
|
+
super(file);
|
|
9764
10240
|
this.config = config;
|
|
9765
10241
|
this.typechecker = new Typechecker(this.file.entries);
|
|
9766
10242
|
}
|
|
9767
|
-
transformed() {
|
|
9768
|
-
return createFile(this.file.entries
|
|
9769
|
-
.map(it => {
|
|
9770
|
-
if (isInterface$1(it)) {
|
|
9771
|
-
return this.transformInterface(it);
|
|
9772
|
-
}
|
|
9773
|
-
return it;
|
|
9774
|
-
}));
|
|
9775
|
-
}
|
|
9776
10243
|
transformInterface(node) {
|
|
9777
10244
|
return createUpdatedInterface(node, node.methods
|
|
9778
10245
|
.map(it => createUpdatedMethod(it, undefined, this.transformedParameters(it, node), this.transformedReturnType(it, node))));
|
|
@@ -9783,7 +10250,7 @@ class NullabilityTransformer {
|
|
|
9783
10250
|
: this.transformType(it.type)));
|
|
9784
10251
|
}
|
|
9785
10252
|
transformedReturnType(node, parent) {
|
|
9786
|
-
if (
|
|
10253
|
+
if (isCreateOrUpdate(node.name)) {
|
|
9787
10254
|
return node.returnType;
|
|
9788
10255
|
}
|
|
9789
10256
|
if (this.config.nonNullable.isNonNullableReturnType(parent.name, node.name)) {
|
|
@@ -9835,9 +10302,9 @@ function remove(array, value) {
|
|
|
9835
10302
|
* See the License for the specific language governing permissions and
|
|
9836
10303
|
* limitations under the License.
|
|
9837
10304
|
*/
|
|
9838
|
-
class AttributeTransformer {
|
|
10305
|
+
class AttributeTransformer extends Transformer {
|
|
9839
10306
|
constructor(file) {
|
|
9840
|
-
|
|
10307
|
+
super(file);
|
|
9841
10308
|
this.convertor = new LibraryTypeConvertor(new Typechecker(this.file.entries));
|
|
9842
10309
|
}
|
|
9843
10310
|
convertToKey(type) {
|
|
@@ -9846,18 +10313,9 @@ class AttributeTransformer {
|
|
|
9846
10313
|
}
|
|
9847
10314
|
return this.convertor.convertType(type);
|
|
9848
10315
|
}
|
|
9849
|
-
transformed() {
|
|
9850
|
-
return createFile(this.file.entries
|
|
9851
|
-
.map(it => {
|
|
9852
|
-
if (isInterface$1(it)) {
|
|
9853
|
-
return this.transformInterface(it);
|
|
9854
|
-
}
|
|
9855
|
-
return it;
|
|
9856
|
-
}));
|
|
9857
|
-
}
|
|
9858
10316
|
transformInterface(node) {
|
|
9859
10317
|
var _a;
|
|
9860
|
-
const creates = node.methods.filter(it =>
|
|
10318
|
+
const creates = node.methods.filter(it => isCreate(it.name));
|
|
9861
10319
|
if (creates.length !== 1) {
|
|
9862
10320
|
return node;
|
|
9863
10321
|
}
|
|
@@ -9913,22 +10371,13 @@ class AttributeTransformer {
|
|
|
9913
10371
|
* See the License for the specific language governing permissions and
|
|
9914
10372
|
* limitations under the License.
|
|
9915
10373
|
*/
|
|
9916
|
-
class InteropTransformer {
|
|
9917
|
-
constructor(file) {
|
|
9918
|
-
|
|
9919
|
-
|
|
9920
|
-
transformed() {
|
|
9921
|
-
return createFile(this.file.entries
|
|
9922
|
-
.map(it => {
|
|
9923
|
-
if (isInterface$1(it)) {
|
|
9924
|
-
return this.transformInterface(it);
|
|
9925
|
-
}
|
|
9926
|
-
return it;
|
|
9927
|
-
}), this.file.fileName);
|
|
10374
|
+
class InteropTransformer extends Transformer {
|
|
10375
|
+
constructor(config, file) {
|
|
10376
|
+
super(file);
|
|
10377
|
+
this.config = config;
|
|
9928
10378
|
}
|
|
9929
10379
|
transformInterface(node) {
|
|
9930
|
-
|
|
9931
|
-
return node;
|
|
10380
|
+
return this.withTransformedMethods(node);
|
|
9932
10381
|
}
|
|
9933
10382
|
withTransformedMethods(node) {
|
|
9934
10383
|
return createUpdatedInterface(node, node.methods.map(it => this.transformMethod(it, node)));
|
|
@@ -9948,7 +10397,7 @@ class InteropTransformer {
|
|
|
9948
10397
|
]);
|
|
9949
10398
|
}
|
|
9950
10399
|
withInsertedReceiver(node, parent) {
|
|
9951
|
-
if (
|
|
10400
|
+
if (isCreateOrUpdate(node.name)) {
|
|
9952
10401
|
return node;
|
|
9953
10402
|
}
|
|
9954
10403
|
return createUpdatedMethod(node, node.name, [
|
|
@@ -9990,25 +10439,17 @@ class InteropTransformer {
|
|
|
9990
10439
|
* See the License for the specific language governing permissions and
|
|
9991
10440
|
* limitations under the License.
|
|
9992
10441
|
*/
|
|
9993
|
-
class ConstMergeTransformer {
|
|
10442
|
+
class ConstMergeTransformer extends Transformer {
|
|
9994
10443
|
constructor(file) {
|
|
9995
|
-
|
|
9996
|
-
}
|
|
9997
|
-
transformed() {
|
|
9998
|
-
return createFile(this.file.entries
|
|
9999
|
-
.map(it => {
|
|
10000
|
-
if (isInterface$1(it)) {
|
|
10001
|
-
return this.transformInterface(it);
|
|
10002
|
-
}
|
|
10003
|
-
return it;
|
|
10004
|
-
}));
|
|
10444
|
+
super(file);
|
|
10005
10445
|
}
|
|
10006
10446
|
transformInterface(node) {
|
|
10007
10447
|
return createUpdatedInterface(node, node.methods
|
|
10008
10448
|
.filter(it => {
|
|
10009
|
-
|
|
10010
|
-
|
|
10011
|
-
|
|
10449
|
+
if (!it.name.endsWith(Config.constPostfix))
|
|
10450
|
+
return true;
|
|
10451
|
+
const nonConstVersion = it.name.substring(0, it.name.length - Config.constPostfix.length);
|
|
10452
|
+
return !node.methods.some(it => it.name === nonConstVersion);
|
|
10012
10453
|
}));
|
|
10013
10454
|
}
|
|
10014
10455
|
}
|
|
@@ -10027,30 +10468,21 @@ class ConstMergeTransformer {
|
|
|
10027
10468
|
* See the License for the specific language governing permissions and
|
|
10028
10469
|
* limitations under the License.
|
|
10029
10470
|
*/
|
|
10030
|
-
class UniversalCreateTransformer {
|
|
10471
|
+
class UniversalCreateTransformer extends Transformer {
|
|
10031
10472
|
constructor(file) {
|
|
10032
|
-
|
|
10033
|
-
}
|
|
10034
|
-
transformed() {
|
|
10035
|
-
return createFile(this.file.entries
|
|
10036
|
-
.map(it => {
|
|
10037
|
-
if (isInterface$1(it)) {
|
|
10038
|
-
return UniversalCreateTransformer.transformInterface(it);
|
|
10039
|
-
}
|
|
10040
|
-
return it;
|
|
10041
|
-
}));
|
|
10473
|
+
super(file);
|
|
10042
10474
|
}
|
|
10043
|
-
|
|
10475
|
+
transformInterface(node) {
|
|
10044
10476
|
const universal = UniversalCreateTransformer.universalCreate(node);
|
|
10045
10477
|
if (universal === undefined) {
|
|
10046
10478
|
return node;
|
|
10047
10479
|
}
|
|
10048
10480
|
return createUpdatedInterface(node, [universal].concat(node.methods
|
|
10049
|
-
.filter(it => !
|
|
10481
|
+
.filter(it => !isCreate(it.name))));
|
|
10050
10482
|
}
|
|
10051
10483
|
static universalCreate(node) {
|
|
10052
10484
|
const creates = node.methods
|
|
10053
|
-
.filter(it =>
|
|
10485
|
+
.filter(it => isCreate(it.name))
|
|
10054
10486
|
.filter(it => !UniversalCreateTransformer.isCopyConstructor(it));
|
|
10055
10487
|
return creates.find(candidate => creates.every(it => UniversalCreateTransformer.isCovered(it, candidate)));
|
|
10056
10488
|
}
|
|
@@ -10103,11 +10535,11 @@ class DynamicEmitter {
|
|
|
10103
10535
|
this.shouldLog = shouldLog;
|
|
10104
10536
|
this.logDir = `./out/log-idl`;
|
|
10105
10537
|
this.logCount = 0;
|
|
10106
|
-
this.bridgesPrinter = new SingleFileEmitter((idl) => new BridgesPrinter(idl).print(), `libarkts/native/src/generated/bridges.cc`, `bridges.cc`, true);
|
|
10538
|
+
this.bridgesPrinter = new SingleFileEmitter((idl) => new BridgesPrinter(this.config, idl).print(), `libarkts/native/src/generated/bridges.cc`, `bridges.cc`, true);
|
|
10107
10539
|
this.bindingsPrinter = new SingleFileEmitter((idl) => new BindingsPrinter(idl).print(), `libarkts/src/generated/Es2pandaNativeModule.ts`, `Es2pandaNativeModule.ts`, true);
|
|
10108
|
-
this.enumsPrinter = new SingleFileEmitter((idl) => new EnumsPrinter(idl).print(), `libarkts/src/Es2pandaEnums.ts`, `Es2pandaEnums.ts`,
|
|
10540
|
+
this.enumsPrinter = new SingleFileEmitter((idl) => new EnumsPrinter(idl).print(), `libarkts/src/generated/Es2pandaEnums.ts`, `Es2pandaEnums.ts`, true);
|
|
10109
10541
|
this.indexPrinter = new SingleFileEmitter((idl) => new IndexPrinter(idl).print(), `libarkts/src/generated/index.ts`, `index.ts`, true);
|
|
10110
|
-
this.peersPrinter = new MultiFileEmitter((idl) => new AllPeersPrinter(idl).print(), `libarkts/src/generated/peers`, `peer.ts`, true);
|
|
10542
|
+
this.peersPrinter = new MultiFileEmitter((idl) => new AllPeersPrinter(this.config, idl).print(), `libarkts/src/generated/peers`, `peer.ts`, true);
|
|
10111
10543
|
this.factoryPrinter = new SingleFileEmitter((idl) => new FactoryPrinter(idl).print(), `libarkts/src/generated/factory.ts`, `factory.ts`, true);
|
|
10112
10544
|
}
|
|
10113
10545
|
emit() {
|
|
@@ -10136,7 +10568,7 @@ class DynamicEmitter {
|
|
|
10136
10568
|
this.printFile(this.factoryPrinter, idl);
|
|
10137
10569
|
}
|
|
10138
10570
|
printInterop(idl) {
|
|
10139
|
-
idl = this.withLog(new InteropTransformer(idl));
|
|
10571
|
+
idl = this.withLog(new InteropTransformer(this.config, idl));
|
|
10140
10572
|
this.printFile(this.bindingsPrinter, idl);
|
|
10141
10573
|
this.printFile(this.bridgesPrinter, idl);
|
|
10142
10574
|
}
|
|
@@ -11622,77 +12054,41 @@ var lib = JSON5;
|
|
|
11622
12054
|
*/
|
|
11623
12055
|
class IgnoreOptions {
|
|
11624
12056
|
constructor(filePath) {
|
|
11625
|
-
var _a, _b
|
|
12057
|
+
var _a, _b;
|
|
12058
|
+
this.full = [];
|
|
12059
|
+
this.partial = [];
|
|
11626
12060
|
if (filePath === undefined) {
|
|
11627
|
-
this.generateByDefault = true;
|
|
11628
|
-
this.interfaces = [];
|
|
11629
12061
|
return;
|
|
11630
12062
|
}
|
|
11631
|
-
const
|
|
11632
|
-
|
|
11633
|
-
|
|
11634
|
-
}
|
|
11635
|
-
else if ((json === null || json === void 0 ? void 0 : json.generate) !== undefined) {
|
|
11636
|
-
this.generateByDefault = false;
|
|
11637
|
-
}
|
|
11638
|
-
else {
|
|
11639
|
-
throwException(`missing options.json section generate or ignore`);
|
|
11640
|
-
}
|
|
11641
|
-
const interfaces = (_d = (_b = (_a = json.ignore) === null || _a === void 0 ? void 0 : _a.interfaces) !== null && _b !== void 0 ? _b : (_c = json.generate) === null || _c === void 0 ? void 0 : _c.interfaces) !== null && _d !== void 0 ? _d : throwException(`missing options.json section generate.interfaces or ignore.interfaces`);
|
|
11642
|
-
this.interfaces = [
|
|
11643
|
-
...Object.entries(interfaces).map(([name, methods]) => {
|
|
11644
|
-
if (Interface.isWhole(methods)) {
|
|
11645
|
-
return this.generateByDefault
|
|
11646
|
-
? new Ignored(name)
|
|
11647
|
-
: new Full(name);
|
|
11648
|
-
}
|
|
11649
|
-
return new Partial(name, new Map(Object.values(methods)
|
|
11650
|
-
.map((name) => [name, !this.generateByDefault])));
|
|
11651
|
-
})
|
|
11652
|
-
];
|
|
12063
|
+
const ignore = lib.parse(fs__namespace$1.readFileSync(filePath).toString()).ignore;
|
|
12064
|
+
this.full = (_a = ignore === null || ignore === void 0 ? void 0 : ignore.full) !== null && _a !== void 0 ? _a : [];
|
|
12065
|
+
this.partial = (_b = ignore === null || ignore === void 0 ? void 0 : ignore.partial) !== null && _b !== void 0 ? _b : [];
|
|
11653
12066
|
}
|
|
11654
|
-
|
|
12067
|
+
isIgnoredMethod(iface, method) {
|
|
11655
12068
|
var _a;
|
|
11656
|
-
|
|
11657
|
-
if (known === undefined) {
|
|
11658
|
-
return this.generateByDefault;
|
|
11659
|
-
}
|
|
11660
|
-
if (known instanceof Ignored) {
|
|
11661
|
-
return false;
|
|
11662
|
-
}
|
|
11663
|
-
if (known instanceof Full) {
|
|
11664
|
-
return true;
|
|
11665
|
-
}
|
|
11666
|
-
if (known instanceof Partial) {
|
|
11667
|
-
return (_a = known.methods.get(method)) !== null && _a !== void 0 ? _a : this.generateByDefault;
|
|
11668
|
-
}
|
|
11669
|
-
throwException(`unexpected kind of interface: ${known}`);
|
|
11670
|
-
}
|
|
11671
|
-
shouldEmitInterface(name) {
|
|
11672
|
-
const known = this.interfaces.find(it => it.name === name);
|
|
11673
|
-
if (known === undefined) {
|
|
11674
|
-
return this.generateByDefault;
|
|
11675
|
-
}
|
|
11676
|
-
return !(known instanceof Ignored);
|
|
12069
|
+
return (_a = this.partial) === null || _a === void 0 ? void 0 : _a.some(it => { var _a; return it.interface === iface && ((_a = it.methods) === null || _a === void 0 ? void 0 : _a.includes(method)); });
|
|
11677
12070
|
}
|
|
11678
|
-
|
|
11679
|
-
|
|
11680
|
-
|
|
11681
|
-
this.name = name;
|
|
12071
|
+
isIgnoredProperty(iface, name) {
|
|
12072
|
+
var _a;
|
|
12073
|
+
return (_a = this.partial) === null || _a === void 0 ? void 0 : _a.some(it => { var _a; return it.interface === iface && ((_a = it.properties) === null || _a === void 0 ? void 0 : _a.includes(name)); });
|
|
11682
12074
|
}
|
|
11683
|
-
|
|
11684
|
-
return
|
|
12075
|
+
isIgnoredInterface(name) {
|
|
12076
|
+
return this.full.includes(name);
|
|
11685
12077
|
}
|
|
11686
12078
|
}
|
|
11687
|
-
|
|
11688
|
-
|
|
11689
|
-
|
|
11690
|
-
|
|
11691
|
-
|
|
11692
|
-
|
|
11693
|
-
|
|
11694
|
-
|
|
11695
|
-
|
|
12079
|
+
// TODO: remove when interfaces fixed!
|
|
12080
|
+
class IrHackOptions {
|
|
12081
|
+
constructor(filePath) {
|
|
12082
|
+
var _a;
|
|
12083
|
+
this.irHack = [];
|
|
12084
|
+
if (filePath === undefined) {
|
|
12085
|
+
return;
|
|
12086
|
+
}
|
|
12087
|
+
const json = lib.parse(fs__namespace$1.readFileSync(filePath).toString());
|
|
12088
|
+
this.irHack = (_a = json === null || json === void 0 ? void 0 : json.irHack) !== null && _a !== void 0 ? _a : [];
|
|
12089
|
+
}
|
|
12090
|
+
isIrHackInterface(name) {
|
|
12091
|
+
return this.irHack.includes(name);
|
|
11696
12092
|
}
|
|
11697
12093
|
}
|
|
11698
12094
|
|
|
@@ -11789,7 +12185,7 @@ function cliOptions() {
|
|
|
11789
12185
|
return {
|
|
11790
12186
|
pandaSdkPath: (_a = cliOptions.pandaSdkPath) !== null && _a !== void 0 ? _a : throwException(`panda-sdk-path is mandatory parameter`),
|
|
11791
12187
|
outputDir: (_b = cliOptions.outputDir) !== null && _b !== void 0 ? _b : throwException(`output-dir is mandatory parameter`),
|
|
11792
|
-
optionsFile: (_c = cliOptions.optionsFile) !== null && _c !== void 0 ? _c :
|
|
12188
|
+
optionsFile: (_c = cliOptions.optionsFile) !== null && _c !== void 0 ? _c : path$1.join(__dirname, `../build/libarkts-copy/generator/options.json5`),
|
|
11793
12189
|
debug: (_d = cliOptions.debug) !== null && _d !== void 0 ? _d : false,
|
|
11794
12190
|
initialize: (_e = cliOptions.initialize) !== null && _e !== void 0 ? _e : false
|
|
11795
12191
|
};
|
|
@@ -11852,7 +12248,7 @@ function main() {
|
|
|
11852
12248
|
if (options.initialize) {
|
|
11853
12249
|
new StaticEmitter(options.outputDir, options.pandaSdkPath).emit();
|
|
11854
12250
|
}
|
|
11855
|
-
new DynamicEmitter(options.outputDir, toIDLFile(path__namespace$1.join(options.pandaSdkPath, pandaSdkIdlFilePath)), new Config(new IgnoreOptions(options.optionsFile), new NonNullableOptions(options.optionsFile)), options.debug).emit();
|
|
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();
|
|
11856
12252
|
}
|
|
11857
12253
|
main();
|
|
11858
12254
|
//# sourceMappingURL=index.js.map
|