@idlizer/arktscgen 2.1.2 → 2.1.7

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.
Files changed (269) hide show
  1. package/build/libarkts-copy/README.md +36 -0
  2. package/build/libarkts-copy/generator/options.json5 +113 -44
  3. package/build/libarkts-copy/native/meson.build +13 -0
  4. package/build/libarkts-copy/native/meson_options.txt +13 -0
  5. package/build/libarkts-copy/native/src/bridges.cc +78 -10
  6. package/build/libarkts-copy/native/src/common.cc +56 -8
  7. package/build/libarkts-copy/native/src/common.h +48 -0
  8. package/build/libarkts-copy/native/src/generated/bridges.cc +825 -325
  9. package/build/libarkts-copy/package.json +67 -49
  10. package/build/libarkts-copy/src/Es2pandaNativeModule.ts +42 -4
  11. package/build/libarkts-copy/src/InteropNativeModule.ts +5 -2
  12. package/build/libarkts-copy/src/arkts-api/AbstractVisitor.ts +50 -0
  13. package/build/libarkts-copy/src/arkts-api/CheckedBackFilter.ts +53 -0
  14. package/build/libarkts-copy/src/arkts-api/SetBaseOverloads.ts +51 -0
  15. package/build/libarkts-copy/src/arkts-api/class-by-peer.ts +8 -6
  16. package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +95 -117
  17. package/build/libarkts-copy/src/arkts-api/index.ts +6 -1
  18. package/build/libarkts-copy/src/arkts-api/node-cache.ts +35 -0
  19. package/build/libarkts-copy/src/arkts-api/node-utilities/ArrayExpression.ts +42 -0
  20. package/build/libarkts-copy/src/arkts-api/node-utilities/ArrowFunctionExpression.ts +49 -0
  21. package/build/libarkts-copy/src/arkts-api/node-utilities/AssignmentExpression.ts +50 -0
  22. package/build/libarkts-copy/src/arkts-api/node-utilities/{createCallExpression.ts → CallExpression.ts} +27 -4
  23. package/build/libarkts-copy/src/arkts-api/node-utilities/ClassDefinition.ts +73 -0
  24. package/build/libarkts-copy/src/arkts-api/node-utilities/ClassProperty.ts +64 -0
  25. package/build/libarkts-copy/src/arkts-api/node-utilities/ETSFunctionType.ts +65 -0
  26. package/build/libarkts-copy/src/arkts-api/node-utilities/ETSImportDeclaration.ts +69 -0
  27. package/build/libarkts-copy/src/arkts-api/node-utilities/ETSParameterExpression.ts +60 -0
  28. package/build/libarkts-copy/src/arkts-api/node-utilities/ETSStructDeclaration.ts +31 -0
  29. package/build/libarkts-copy/src/arkts-api/node-utilities/ETSTuple.ts +31 -0
  30. package/build/libarkts-copy/src/arkts-api/node-utilities/MemberExpression.ts +41 -0
  31. package/build/libarkts-copy/src/arkts-api/node-utilities/MethodDefinition.ts +75 -0
  32. package/build/libarkts-copy/src/arkts-api/node-utilities/{createNumberLiteral.ts → NumberLiteral.ts} +15 -0
  33. package/build/libarkts-copy/src/arkts-api/node-utilities/ObjectExpression.ts +34 -0
  34. package/build/libarkts-copy/src/arkts-api/node-utilities/ScriptFunction.ts +99 -0
  35. package/build/libarkts-copy/src/arkts-api/node-utilities/TSInterfaceDeclaration.ts +81 -0
  36. package/build/libarkts-copy/src/arkts-api/node-utilities/TSTypeAliasDeclaration.ts +68 -0
  37. package/build/libarkts-copy/src/arkts-api/node-utilities/TSTypeParameter.ts +39 -0
  38. package/build/libarkts-copy/src/arkts-api/node-utilities/TSTypeReferencePart.ts +36 -0
  39. package/build/libarkts-copy/src/arkts-api/node-utilities/TryStatement.ts +44 -0
  40. package/build/libarkts-copy/src/arkts-api/node-utilities/VariableDeclaration.ts +54 -0
  41. package/build/libarkts-copy/src/arkts-api/node-utilities/VariableDeclarator.ts +37 -0
  42. package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +16 -15
  43. package/build/libarkts-copy/src/arkts-api/peers/Context.ts +1 -2
  44. package/build/libarkts-copy/src/arkts-api/peers/ImportPathManager.ts +30 -0
  45. package/build/libarkts-copy/src/arkts-api/peers/Program.ts +7 -5
  46. package/build/libarkts-copy/src/arkts-api/peers/SourcePosition.ts +38 -0
  47. package/build/libarkts-copy/src/arkts-api/plugins.ts +48 -0
  48. package/build/libarkts-copy/src/arkts-api/static/global.ts +8 -2
  49. package/build/libarkts-copy/src/arkts-api/static/profiler.ts +40 -0
  50. package/build/libarkts-copy/src/arkts-api/utilities/private.ts +18 -14
  51. package/build/libarkts-copy/src/arkts-api/utilities/public.ts +76 -12
  52. package/build/libarkts-copy/src/arkts-api/visitor.ts +324 -42
  53. package/build/libarkts-copy/src/generated/Es2pandaEnums.ts +504 -458
  54. package/build/libarkts-copy/src/generated/Es2pandaNativeModule.ts +225 -75
  55. package/build/libarkts-copy/src/generated/factory.ts +21 -43
  56. package/build/libarkts-copy/src/generated/index.ts +24 -3
  57. package/build/libarkts-copy/src/generated/peers/AnnotatedAstNode.ts +1 -2
  58. package/build/libarkts-copy/src/generated/peers/AnnotatedExpression.ts +1 -2
  59. package/build/libarkts-copy/src/generated/peers/AnnotatedStatement.ts +1 -2
  60. package/build/libarkts-copy/src/generated/peers/AnnotationDeclaration.ts +7 -7
  61. package/build/libarkts-copy/src/generated/peers/AnnotationUsage.ts +12 -12
  62. package/build/libarkts-copy/src/generated/peers/ArrayExpression.ts +10 -5
  63. package/build/libarkts-copy/src/generated/peers/ArrowFunctionExpression.ts +7 -7
  64. package/build/libarkts-copy/src/generated/peers/AssertStatement.ts +5 -5
  65. package/build/libarkts-copy/src/generated/peers/AssignmentExpression.ts +13 -7
  66. package/build/libarkts-copy/src/generated/peers/AstDumper.ts +1 -2
  67. package/build/libarkts-copy/src/generated/peers/AstVerifier.ts +35 -0
  68. package/build/libarkts-copy/src/generated/peers/AstVisitor.ts +35 -0
  69. package/build/libarkts-copy/src/generated/peers/AwaitExpression.ts +4 -4
  70. package/build/libarkts-copy/src/generated/peers/BigIntLiteral.ts +4 -4
  71. package/build/libarkts-copy/src/generated/peers/BinaryExpression.ts +14 -7
  72. package/build/libarkts-copy/src/generated/peers/BindingProps.ts +35 -0
  73. package/build/libarkts-copy/src/generated/peers/BlockExpression.ts +5 -5
  74. package/build/libarkts-copy/src/generated/peers/BlockStatement.ts +15 -5
  75. package/build/libarkts-copy/src/generated/peers/BooleanLiteral.ts +4 -4
  76. package/build/libarkts-copy/src/generated/peers/BreakStatement.ts +8 -5
  77. package/build/libarkts-copy/src/generated/peers/CallExpression.ts +8 -8
  78. package/build/libarkts-copy/src/generated/peers/CatchClause.ts +6 -6
  79. package/build/libarkts-copy/src/generated/peers/ChainExpression.ts +12 -5
  80. package/build/libarkts-copy/src/generated/peers/CharLiteral.ts +4 -4
  81. package/build/libarkts-copy/src/generated/peers/ClassDeclaration.ts +5 -5
  82. package/build/libarkts-copy/src/generated/peers/ClassDefinition.ts +30 -15
  83. package/build/libarkts-copy/src/generated/peers/ClassElement.ts +7 -8
  84. package/build/libarkts-copy/src/generated/peers/ClassExpression.ts +4 -4
  85. package/build/libarkts-copy/src/generated/peers/ClassProperty.ts +21 -5
  86. package/build/libarkts-copy/src/generated/peers/ClassStaticBlock.ts +5 -5
  87. package/build/libarkts-copy/src/generated/peers/CodeGen.ts +35 -0
  88. package/build/libarkts-copy/src/generated/peers/ConditionalExpression.ts +7 -7
  89. package/build/libarkts-copy/src/generated/peers/ContinueStatement.ts +8 -5
  90. package/build/libarkts-copy/src/generated/peers/DebuggerStatement.ts +4 -4
  91. package/build/libarkts-copy/src/generated/peers/Declaration.ts +35 -0
  92. package/build/libarkts-copy/src/generated/peers/Decorator.ts +4 -4
  93. package/build/libarkts-copy/src/generated/peers/DirectEvalExpression.ts +4 -4
  94. package/build/libarkts-copy/src/generated/peers/DoWhileStatement.ts +6 -6
  95. package/build/libarkts-copy/src/generated/peers/DynamicImportData.ts +35 -0
  96. package/build/libarkts-copy/src/generated/peers/ETSClassLiteral.ts +4 -4
  97. package/build/libarkts-copy/src/generated/peers/ETSDynamicFunctionType.ts +1 -2
  98. package/build/libarkts-copy/src/generated/peers/ETSFunctionType.ts +15 -15
  99. package/build/libarkts-copy/src/generated/peers/ETSImportDeclaration.ts +26 -17
  100. package/build/libarkts-copy/src/generated/peers/ETSKeyofType.ts +53 -0
  101. package/build/libarkts-copy/src/generated/peers/ETSModule.ts +6 -6
  102. package/build/libarkts-copy/src/generated/peers/ETSNewArrayInstanceExpression.ts +11 -6
  103. package/build/libarkts-copy/src/generated/peers/ETSNewClassInstanceExpression.ts +5 -5
  104. package/build/libarkts-copy/src/generated/peers/ETSNewMultiDimArrayInstanceExpression.ts +11 -6
  105. package/build/libarkts-copy/src/generated/peers/ETSNullType.ts +6 -6
  106. package/build/libarkts-copy/src/generated/peers/ETSPackageDeclaration.ts +4 -4
  107. package/build/libarkts-copy/src/generated/peers/ETSParameterExpression.ts +10 -10
  108. package/build/libarkts-copy/src/generated/peers/ETSPrimitiveType.ts +4 -4
  109. package/build/libarkts-copy/src/generated/peers/ETSReExportDeclaration.ts +5 -5
  110. package/build/libarkts-copy/src/generated/peers/ETSStringLiteralType.ts +50 -0
  111. package/build/libarkts-copy/src/generated/peers/ETSStructDeclaration.ts +4 -4
  112. package/build/libarkts-copy/src/generated/peers/ETSTuple.ts +5 -5
  113. package/build/libarkts-copy/src/generated/peers/ETSTypeReference.ts +5 -5
  114. package/build/libarkts-copy/src/generated/peers/ETSTypeReferencePart.ts +8 -8
  115. package/build/libarkts-copy/src/generated/peers/ETSUndefinedType.ts +6 -6
  116. package/build/libarkts-copy/src/generated/peers/ETSUnionType.ts +7 -7
  117. package/build/libarkts-copy/src/generated/peers/ETSWildcardType.ts +5 -5
  118. package/build/libarkts-copy/src/generated/peers/EmptyStatement.ts +4 -4
  119. package/build/libarkts-copy/src/generated/peers/ErrorLogger.ts +35 -0
  120. package/build/libarkts-copy/src/generated/peers/ExportAllDeclaration.ts +4 -4
  121. package/build/libarkts-copy/src/generated/peers/ExportDefaultDeclaration.ts +5 -5
  122. package/build/libarkts-copy/src/generated/peers/ExportNamedDeclaration.ts +4 -4
  123. package/build/libarkts-copy/src/generated/peers/ExportSpecifier.ts +4 -4
  124. package/build/libarkts-copy/src/generated/peers/Expression.ts +4 -5
  125. package/build/libarkts-copy/src/generated/peers/ExpressionStatement.ts +6 -6
  126. package/build/libarkts-copy/src/generated/peers/ForInStatement.ts +7 -7
  127. package/build/libarkts-copy/src/generated/peers/ForOfStatement.ts +7 -7
  128. package/build/libarkts-copy/src/generated/peers/ForUpdateStatement.ts +7 -7
  129. package/build/libarkts-copy/src/generated/peers/FunctionDecl.ts +1 -2
  130. package/build/libarkts-copy/src/generated/peers/FunctionDeclaration.ts +8 -8
  131. package/build/libarkts-copy/src/generated/peers/FunctionExpression.ts +5 -5
  132. package/build/libarkts-copy/src/generated/peers/FunctionSignature.ts +6 -7
  133. package/build/libarkts-copy/src/generated/peers/IRNode.ts +35 -0
  134. package/build/libarkts-copy/src/generated/peers/Identifier.ts +5 -5
  135. package/build/libarkts-copy/src/generated/peers/IfStatement.ts +9 -9
  136. package/build/libarkts-copy/src/generated/peers/ImportDeclaration.ts +10 -10
  137. package/build/libarkts-copy/src/generated/peers/ImportDefaultSpecifier.ts +5 -5
  138. package/build/libarkts-copy/src/generated/peers/ImportExpression.ts +5 -5
  139. package/build/libarkts-copy/src/generated/peers/ImportNamespaceSpecifier.ts +5 -5
  140. package/build/libarkts-copy/src/generated/peers/ImportSource.ts +1 -15
  141. package/build/libarkts-copy/src/generated/peers/ImportSpecifier.ts +14 -6
  142. package/build/libarkts-copy/src/generated/peers/IndexInfo.ts +35 -0
  143. package/build/libarkts-copy/src/generated/peers/InterfaceDecl.ts +1 -2
  144. package/build/libarkts-copy/src/generated/peers/LabelPair.ts +35 -0
  145. package/build/libarkts-copy/src/generated/peers/LabelledStatement.ts +6 -6
  146. package/build/libarkts-copy/src/generated/peers/Literal.ts +1 -2
  147. package/build/libarkts-copy/src/generated/peers/LoopStatement.ts +1 -2
  148. package/build/libarkts-copy/src/generated/peers/MaybeOptionalExpression.ts +1 -2
  149. package/build/libarkts-copy/src/generated/peers/MemberExpression.ts +24 -8
  150. package/build/libarkts-copy/src/generated/peers/MetaProperty.ts +4 -4
  151. package/build/libarkts-copy/src/generated/peers/MethodDefinition.ts +25 -8
  152. package/build/libarkts-copy/src/generated/peers/NamedType.ts +4 -4
  153. package/build/libarkts-copy/src/generated/peers/NewExpression.ts +4 -4
  154. package/build/libarkts-copy/src/generated/peers/NullLiteral.ts +4 -4
  155. package/build/libarkts-copy/src/generated/peers/NumberLiteral.ts +19 -4
  156. package/build/libarkts-copy/src/generated/peers/ObjectDescriptor.ts +35 -0
  157. package/build/libarkts-copy/src/generated/peers/ObjectExpression.ts +4 -4
  158. package/build/libarkts-copy/src/generated/peers/OmittedExpression.ts +4 -4
  159. package/build/libarkts-copy/src/generated/peers/OpaqueTypeNode.ts +4 -4
  160. package/build/libarkts-copy/src/generated/peers/OverloadInfo.ts +35 -0
  161. package/build/libarkts-copy/src/generated/peers/PrefixAssertionExpression.ts +4 -4
  162. package/build/libarkts-copy/src/generated/peers/Property.ts +6 -6
  163. package/build/libarkts-copy/src/generated/peers/RegExpLiteral.ts +4 -4
  164. package/build/libarkts-copy/src/generated/peers/ReturnStatement.ts +8 -5
  165. package/build/libarkts-copy/src/generated/peers/ScopeFindResult.ts +35 -0
  166. package/build/libarkts-copy/src/generated/peers/ScriptFunction.ts +16 -11
  167. package/build/libarkts-copy/src/generated/peers/ScriptFunctionData.ts +35 -0
  168. package/build/libarkts-copy/src/generated/peers/SequenceExpression.ts +5 -5
  169. package/build/libarkts-copy/src/generated/peers/SignatureInfo.ts +35 -0
  170. package/build/libarkts-copy/src/generated/peers/SourcePosition.ts +35 -0
  171. package/build/libarkts-copy/src/generated/peers/SourceRange.ts +35 -0
  172. package/build/libarkts-copy/src/generated/peers/SpreadElement.ts +5 -5
  173. package/build/libarkts-copy/src/generated/peers/SrcDumper.ts +1 -2
  174. package/build/libarkts-copy/src/generated/peers/Statement.ts +1 -2
  175. package/build/libarkts-copy/src/generated/peers/StringLiteral.ts +4 -4
  176. package/build/libarkts-copy/src/generated/peers/SuperExpression.ts +4 -4
  177. package/build/libarkts-copy/src/generated/peers/SwitchCaseStatement.ts +5 -5
  178. package/build/libarkts-copy/src/generated/peers/SwitchStatement.ts +6 -6
  179. package/build/libarkts-copy/src/generated/peers/TSAnyKeyword.ts +4 -4
  180. package/build/libarkts-copy/src/generated/peers/TSArrayType.ts +4 -4
  181. package/build/libarkts-copy/src/generated/peers/TSAsExpression.ts +5 -5
  182. package/build/libarkts-copy/src/generated/peers/TSBigintKeyword.ts +4 -4
  183. package/build/libarkts-copy/src/generated/peers/TSBooleanKeyword.ts +4 -4
  184. package/build/libarkts-copy/src/generated/peers/TSClassImplements.ts +5 -5
  185. package/build/libarkts-copy/src/generated/peers/TSConditionalType.ts +4 -4
  186. package/build/libarkts-copy/src/generated/peers/TSConstructorType.ts +6 -6
  187. package/build/libarkts-copy/src/generated/peers/TSEnumDeclaration.ts +5 -5
  188. package/build/libarkts-copy/src/generated/peers/TSEnumMember.ts +6 -6
  189. package/build/libarkts-copy/src/generated/peers/TSExternalModuleReference.ts +4 -4
  190. package/build/libarkts-copy/src/generated/peers/TSFunctionType.ts +6 -6
  191. package/build/libarkts-copy/src/generated/peers/TSImportEqualsDeclaration.ts +4 -4
  192. package/build/libarkts-copy/src/generated/peers/TSImportType.ts +4 -4
  193. package/build/libarkts-copy/src/generated/peers/TSIndexSignature.ts +4 -4
  194. package/build/libarkts-copy/src/generated/peers/TSIndexedAccessType.ts +4 -4
  195. package/build/libarkts-copy/src/generated/peers/TSInferType.ts +4 -4
  196. package/build/libarkts-copy/src/generated/peers/TSInterfaceBody.ts +5 -5
  197. package/build/libarkts-copy/src/generated/peers/TSInterfaceDeclaration.ts +10 -10
  198. package/build/libarkts-copy/src/generated/peers/TSInterfaceHeritage.ts +5 -5
  199. package/build/libarkts-copy/src/generated/peers/TSIntersectionType.ts +4 -4
  200. package/build/libarkts-copy/src/generated/peers/TSLiteralType.ts +4 -4
  201. package/build/libarkts-copy/src/generated/peers/TSMappedType.ts +4 -4
  202. package/build/libarkts-copy/src/generated/peers/TSMethodSignature.ts +7 -7
  203. package/build/libarkts-copy/src/generated/peers/TSModuleBlock.ts +4 -4
  204. package/build/libarkts-copy/src/generated/peers/TSModuleDeclaration.ts +4 -4
  205. package/build/libarkts-copy/src/generated/peers/TSNamedTupleMember.ts +5 -5
  206. package/build/libarkts-copy/src/generated/peers/TSNeverKeyword.ts +4 -4
  207. package/build/libarkts-copy/src/generated/peers/TSNonNullExpression.ts +5 -5
  208. package/build/libarkts-copy/src/generated/peers/TSNullKeyword.ts +4 -4
  209. package/build/libarkts-copy/src/generated/peers/TSNumberKeyword.ts +4 -4
  210. package/build/libarkts-copy/src/generated/peers/TSObjectKeyword.ts +4 -4
  211. package/build/libarkts-copy/src/generated/peers/TSParameterProperty.ts +4 -4
  212. package/build/libarkts-copy/src/generated/peers/TSParenthesizedType.ts +4 -4
  213. package/build/libarkts-copy/src/generated/peers/TSPropertySignature.ts +5 -5
  214. package/build/libarkts-copy/src/generated/peers/TSQualifiedName.ts +7 -7
  215. package/build/libarkts-copy/src/generated/peers/TSSignatureDeclaration.ts +6 -6
  216. package/build/libarkts-copy/src/generated/peers/TSStringKeyword.ts +4 -4
  217. package/build/libarkts-copy/src/generated/peers/TSThisType.ts +4 -4
  218. package/build/libarkts-copy/src/generated/peers/TSTupleType.ts +4 -4
  219. package/build/libarkts-copy/src/generated/peers/TSTypeAliasDeclaration.ts +8 -8
  220. package/build/libarkts-copy/src/generated/peers/TSTypeAssertion.ts +4 -4
  221. package/build/libarkts-copy/src/generated/peers/TSTypeLiteral.ts +4 -4
  222. package/build/libarkts-copy/src/generated/peers/TSTypeOperator.ts +4 -4
  223. package/build/libarkts-copy/src/generated/peers/TSTypeParameter.ts +7 -7
  224. package/build/libarkts-copy/src/generated/peers/TSTypeParameterDeclaration.ts +4 -4
  225. package/build/libarkts-copy/src/generated/peers/TSTypeParameterInstantiation.ts +4 -4
  226. package/build/libarkts-copy/src/generated/peers/TSTypePredicate.ts +4 -4
  227. package/build/libarkts-copy/src/generated/peers/TSTypeQuery.ts +4 -4
  228. package/build/libarkts-copy/src/generated/peers/TSTypeReference.ts +4 -4
  229. package/build/libarkts-copy/src/generated/peers/TSUndefinedKeyword.ts +4 -4
  230. package/build/libarkts-copy/src/generated/peers/TSUnionType.ts +4 -4
  231. package/build/libarkts-copy/src/generated/peers/TSUnknownKeyword.ts +4 -4
  232. package/build/libarkts-copy/src/generated/peers/TSVoidKeyword.ts +4 -4
  233. package/build/libarkts-copy/src/generated/peers/TaggedTemplateExpression.ts +4 -4
  234. package/build/libarkts-copy/src/generated/peers/TemplateElement.ts +4 -4
  235. package/build/libarkts-copy/src/generated/peers/TemplateLiteral.ts +4 -4
  236. package/build/libarkts-copy/src/generated/peers/ThisExpression.ts +4 -4
  237. package/build/libarkts-copy/src/generated/peers/ThrowStatement.ts +4 -4
  238. package/build/libarkts-copy/src/generated/peers/TryStatement.ts +10 -6
  239. package/build/libarkts-copy/src/generated/peers/TypeNode.ts +2 -3
  240. package/build/libarkts-copy/src/generated/peers/TypedAstNode.ts +1 -2
  241. package/build/libarkts-copy/src/generated/peers/TypedStatement.ts +1 -2
  242. package/build/libarkts-copy/src/generated/peers/TypeofExpression.ts +4 -4
  243. package/build/libarkts-copy/src/generated/peers/UnaryExpression.ts +5 -5
  244. package/build/libarkts-copy/src/generated/peers/UndefinedLiteral.ts +4 -4
  245. package/build/libarkts-copy/src/generated/peers/UpdateExpression.ts +5 -5
  246. package/build/libarkts-copy/src/generated/peers/VReg.ts +35 -0
  247. package/build/libarkts-copy/src/generated/peers/ValidationInfo.ts +4 -4
  248. package/build/libarkts-copy/src/generated/peers/VariableDeclaration.ts +5 -5
  249. package/build/libarkts-copy/src/generated/peers/VariableDeclarator.ts +7 -7
  250. package/build/libarkts-copy/src/generated/peers/VerificationContext.ts +35 -0
  251. package/build/libarkts-copy/src/generated/peers/VerifierMessage.ts +35 -0
  252. package/build/libarkts-copy/src/generated/peers/WhileStatement.ts +6 -6
  253. package/build/libarkts-copy/src/generated/peers/YieldExpression.ts +4 -4
  254. package/build/libarkts-copy/src/index.ts +35 -0
  255. package/build/libarkts-copy/src/reexport-for-generated.ts +1 -1
  256. package/build/libarkts-copy/src/ts-api/factory/nodeFactory.ts +15 -0
  257. package/build/libarkts-copy/src/ts-api/factory/nodeTests.ts +15 -0
  258. package/build/libarkts-copy/src/ts-api/types.ts +15 -0
  259. package/build/libarkts-copy/src/utils.ts +301 -9
  260. package/build/libarkts-copy/tsconfig.json +5 -4
  261. package/lib/index.js +2861 -1209
  262. package/package.json +6 -6
  263. package/templates/factory.ts +0 -1
  264. package/templates/peer.ts +0 -1
  265. package/build/libarkts-copy/src/Es2pandaEnums.ts +0 -183
  266. package/build/libarkts-copy/src/arkts-api/node-utilities/createScriptFunction.ts +0 -55
  267. package/build/libarkts-copy/src/es2panda.ts +0 -277
  268. package/build/libarkts-copy/src/generated/node-map.ts +0 -182
  269. package/build/libarkts-copy/src/generated/peers/ETSLaunchExpression.ts +0 -57
@@ -0,0 +1,36 @@
1
+ ## libarkts
2
+
3
+ Wrapper library which provides tsc-like __ArkTS__ compiler API
4
+
5
+ Implemented with koala interop technology
6
+
7
+ ### Prerequisites
8
+
9
+ node >= 18
10
+ meson >= 0.62
11
+
12
+ Having following .npmrc: https://gitee.com/openharmony-sig/arkcompiler_ets_frontend/wikis/npmrc
13
+
14
+ ```
15
+ cd ~/arkcompiler_ets_frontend
16
+ npm i
17
+ cd ./ui2abc/libarkts/
18
+ npm i
19
+ npm run compile
20
+ ```
21
+
22
+ ### Structure
23
+
24
+ - ```compatible``` - __ArkTS__ / __typescript__ plugins
25
+ - ```input``` - code samples to be compiled with __ArkTS__ / __typescript__
26
+ - ```native``` - node module wrapper for __es2panda.so__
27
+ - ```src``` - plugin API sources
28
+ - ```test``` - plugin API tests
29
+
30
+ ### How to run
31
+ ```
32
+ npm run run
33
+ node build/api/es2panda.js --help
34
+ ```
35
+
36
+ Runs __ArkTS__ compiler for __./input/main.sts__ invoking plugins specified in __arktsconfig.json__
@@ -1,47 +1,98 @@
1
1
  {
2
+ "irHack": [
3
+ "AnnotationUsage",
4
+ "ETSFunctionType",
5
+ "ETSUnionType",
6
+ "ETSNullType",
7
+ "ETSUndefinedType",
8
+ ],
2
9
  "ignore": {
3
- "interfaces": {
4
- "es2panda_Impl": [
5
- "*"
6
- ],
7
- "es2panda_SourcePosition": [ // until idl is fixed
8
- "*"
9
- ],
10
- "es2panda_LabelPair": [
11
- "*"
12
- ],
13
- "AnnotationDeclaration": [
14
- "PropertiesPtrConst" // interferes create-to-param matching
15
- ],
16
- "AnnotationUsage": [
17
- "PropertiesPtrConst" // interferes create-to-param matching
18
- ],
19
- "TSInterfaceBody": [
20
- "BodyPtr" // interferes create-to-param matching
21
- ],
22
- "Signature": [
23
- "ProtectionFlagConst", // u8
24
- ],
25
- "ETSReExportDeclaration": [
26
- "Create", // sequence<String>
27
- "Update", // sequence<String>
28
- "GetUserPathsConst" // sequence<String>
29
- ],
30
- "CharLiteral": [
31
- "Create1", // KShort,
32
- "Update1", // KShort
33
- "CharConst", // KShort
34
- ],
35
- "ForUpdateStatement": [ // forbidden naming
36
- "Update"
37
- ],
38
- "CallExpression": [
39
- "Update" // differs from handwritten
40
- ],
41
- "TryStatement": [
42
- "AddFinalizerInsertion" // idl missing const
43
- ],
44
- }
10
+ "full": [
11
+ "es2panda_Impl",
12
+ "es2panda_Config",
13
+ "es2panda_ExternalSource",
14
+ ],
15
+ "partial": [
16
+ {
17
+ interface: "MethodDefinition",
18
+ methods: [
19
+ "GetOverloadInfo", // return type is wrong
20
+ ]
21
+ },
22
+ {
23
+ interface: "AnnotationDeclaration",
24
+ methods: [
25
+ "PropertiesPtrConst" // interfaces create-to-param matching
26
+ ]
27
+ },
28
+ {
29
+ interface: "NumberLiteral",
30
+ methods: [
31
+ "SetInt",
32
+ "SetLong",
33
+ "SetDouble",
34
+ "SetFloat"
35
+ ]
36
+ },
37
+ {
38
+ interface: "AnnotationUsage",
39
+ methods: [
40
+ "PropertiesPtrConst" // interfaces create-to-param matching
41
+ ]
42
+ },
43
+ {
44
+ interface: "TSInterfaceBody",
45
+ methods: [
46
+ "BodyPtr" // interfaces create-to-param matching
47
+ ]
48
+ },
49
+ {
50
+ interface: "Signature",
51
+ methods: [
52
+ "ProtectionFlagConst" // u8
53
+ ]
54
+ },
55
+ {
56
+ interface: "ETSReExportDeclaration",
57
+ methods: [
58
+ "Create", // sequence<String>
59
+ "Update", // sequence<String>
60
+ "GetUserPathsConst" // sequence<String>
61
+ ]
62
+ },
63
+ {
64
+ interface: "CharLiteral",
65
+ methods: [
66
+ "Create1", // KShort,
67
+ "Update1", // KShort
68
+ "CharConst", // KShort
69
+ ]
70
+ },
71
+ {
72
+ interface: "ForUpdateStatement",
73
+ methods: [
74
+ "Update" // forbidden naming
75
+ ]
76
+ },
77
+ {
78
+ interface: "CallExpression",
79
+ methods: [
80
+ "Update" // differs from handwritten
81
+ ]
82
+ },
83
+ {
84
+ interface: "TryStatement",
85
+ methods: [
86
+ "AddFinalizerInsertion" // idl missing const
87
+ ]
88
+ },
89
+ {
90
+ interface: "MemberExpression",
91
+ methods: [
92
+ "SetExtensionAccessorType" // ETSFunction type ambiguity
93
+ ]
94
+ },
95
+ ]
45
96
  },
46
97
  nonNullable: [
47
98
  {
@@ -148,8 +199,26 @@
148
199
  {
149
200
  name: "FunctionConst",
150
201
  types: ["returnType"]
202
+ },
203
+ ]
204
+ },
205
+ {
206
+ name: "ETSFunctionType",
207
+ methods: [
208
+ {
209
+ name: "ReturnTypeConst",
210
+ types: ["returnType"]
211
+ }
212
+ ]
213
+ },
214
+ {
215
+ name: "TSTypeAliasDeclaration",
216
+ methods: [
217
+ {
218
+ name: "TypeAnnotationConst",
219
+ types: ["returnType"]
151
220
  }
152
221
  ]
153
222
  },
154
- ]
155
- }
223
+ ],
224
+ }
@@ -1,3 +1,16 @@
1
+ # Copyright (c) 2025 Huawei Device Co., Ltd.
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+
1
14
  project(
2
15
  'es2panda_interop',
3
16
  'cpp',
@@ -1,3 +1,16 @@
1
+ # Copyright (c) 2025 Huawei Device Co., Ltd.
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+
1
14
  option(
2
15
  'node_modules_dir',
3
16
  type : 'string',
@@ -39,7 +39,7 @@ KNativePointer impl_AnnotationAllowedAnnotations(KNativePointer contextPtr, KNat
39
39
  auto node = reinterpret_cast<es2panda_AstNode*>(nodePtr);
40
40
  std::size_t params_len = 0;
41
41
  auto annotations = GetImpl()->AnnotationAllowedAnnotations(context, node, &params_len);
42
- return new std::vector<void*>(annotations, annotations + params_len);
42
+ return StageArena::cloneVector(annotations, params_len);
43
43
  }
44
44
  KOALA_INTEROP_3(AnnotationAllowedAnnotations, KNativePointer, KNativePointer, KNativePointer, KNativePointer)
45
45
 
@@ -49,10 +49,11 @@ KNativePointer impl_AnnotationAllowedAnnotationsConst(KNativePointer contextPtr,
49
49
  auto node = reinterpret_cast<es2panda_AstNode*>(nodePtr);
50
50
  std::size_t params_len = 0;
51
51
  auto annotations = GetImpl()->AnnotationAllowedAnnotationsConst(context, node, &params_len);
52
- return new std::vector<void*>(annotations, annotations + params_len);
52
+ return StageArena::cloneVector(annotations, params_len);
53
53
  }
54
54
  KOALA_INTEROP_3(AnnotationAllowedAnnotationsConst, KNativePointer, KNativePointer, KNativePointer, KNativePointer)
55
55
 
56
+ /*
56
57
  KNativePointer impl_AstNodeVariableConst(KNativePointer contextPtr, KNativePointer nodePtr)
57
58
  {
58
59
  auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
@@ -61,6 +62,7 @@ KNativePointer impl_AstNodeVariableConst(KNativePointer contextPtr, KNativePoint
61
62
  return GetImpl()->AstNodeVariableConst(context, node);
62
63
  }
63
64
  KOALA_INTEROP_2(AstNodeVariableConst, KNativePointer, KNativePointer, KNativePointer)
65
+ */
64
66
 
65
67
  KNativePointer impl_VariableDeclaration(KNativePointer contextPtr, KNativePointer variablePtr)
66
68
  {
@@ -80,6 +82,7 @@ KNativePointer impl_DeclNode(KNativePointer contextPtr, KNativePointer declPtr)
80
82
  }
81
83
  KOALA_INTEROP_2(DeclNode, KNativePointer, KNativePointer, KNativePointer)
82
84
 
85
+ /*
83
86
  KNativePointer impl_AstNodeScopeConst(KNativePointer contextPtr, KNativePointer nodePtr)
84
87
  {
85
88
  auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
@@ -87,7 +90,7 @@ KNativePointer impl_AstNodeScopeConst(KNativePointer contextPtr, KNativePointer
87
90
  return GetImpl()->AstNodeScopeConst(context, node);
88
91
  }
89
92
  KOALA_INTEROP_2(AstNodeScopeConst, KNativePointer, KNativePointer, KNativePointer)
90
-
93
+ */
91
94
  KNativePointer impl_ScopeSetParent(KNativePointer contextPtr, KNativePointer nodePtr, KNativePointer parentPtr)
92
95
  {
93
96
  auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
@@ -98,6 +101,7 @@ KNativePointer impl_ScopeSetParent(KNativePointer contextPtr, KNativePointer nod
98
101
  }
99
102
  KOALA_INTEROP_3(ScopeSetParent, KNativePointer, KNativePointer, KNativePointer, KNativePointer)
100
103
 
104
+ /*
101
105
  KNativePointer impl_CreateNumberLiteral(KNativePointer contextPtr, KDouble value)
102
106
  {
103
107
  auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
@@ -105,6 +109,7 @@ KNativePointer impl_CreateNumberLiteral(KNativePointer contextPtr, KDouble value
105
109
  return GetImpl()->CreateNumberLiteral(context, value);
106
110
  }
107
111
  KOALA_INTEROP_2(CreateNumberLiteral, KNativePointer, KNativePointer, KDouble)
112
+ */
108
113
 
109
114
  KNativePointer impl_ETSParserCreateExpression(KNativePointer contextPtr, KStringPtr& sourceCodePtr, KInt flagsT)
110
115
  {
@@ -146,7 +151,7 @@ KOALA_INTEROP_1(ContextProgram, KNativePointer, KNativePointer)
146
151
 
147
152
  KNativePointer impl_ProgramAst(KNativePointer contextPtr, KNativePointer programPtr)
148
153
  {
149
- auto context = reinterpret_cast<es2panda_Context*>(programPtr);
154
+ auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
150
155
  auto program = reinterpret_cast<es2panda_Program*>(programPtr);
151
156
  return GetImpl()->ProgramAst(context, program);
152
157
  }
@@ -185,10 +190,11 @@ KNativePointer impl_ContextErrorMessage(KNativePointer contextPtr)
185
190
  {
186
191
  auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
187
192
 
188
- return new string(GetImpl()->ContextErrorMessage(context));
193
+ return StageArena::strdup(GetImpl()->ContextErrorMessage(context));
189
194
  }
190
195
  KOALA_INTEROP_1(ContextErrorMessage, KNativePointer, KNativePointer)
191
196
 
197
+ /*
192
198
  KNativePointer impl_CallExpressionSignature(KNativePointer context, KNativePointer classInstance)
193
199
  {
194
200
  const auto _context = reinterpret_cast<es2panda_Context*>(context);
@@ -197,7 +203,7 @@ KNativePointer impl_CallExpressionSignature(KNativePointer context, KNativePoint
197
203
  return result;
198
204
  }
199
205
  KOALA_INTEROP_2(CallExpressionSignature, KNativePointer, KNativePointer, KNativePointer)
200
-
206
+ */
201
207
  KNativePointer impl_SignatureFunction(KNativePointer context, KNativePointer classInstance)
202
208
  {
203
209
  const auto _context = reinterpret_cast<es2panda_Context*>(context);
@@ -222,15 +228,15 @@ static KNativePointer impl_ProgramExternalSources(KNativePointer contextPtr, KNa
222
228
  auto&& instance = reinterpret_cast<es2panda_Program *>(instancePtr);
223
229
  std::size_t source_len = 0;
224
230
  auto external_sources = GetImpl()->ProgramExternalSources(context, instance, &source_len);
225
- return new std::vector<void*>(external_sources, external_sources + source_len);
231
+ return StageArena::cloneVector(external_sources, source_len);
226
232
  }
227
233
  KOALA_INTEROP_2(ProgramExternalSources, KNativePointer, KNativePointer, KNativePointer);
228
234
 
229
235
  static KNativePointer impl_ExternalSourceName(KNativePointer instance)
230
236
  {
231
237
  auto&& _instance_ = reinterpret_cast<es2panda_ExternalSource *>(instance);
232
- auto&& _result_ = GetImpl()->ExternalSourceName(_instance_);
233
- return new std::string(_result_);
238
+ auto&& result = GetImpl()->ExternalSourceName(_instance_);
239
+ return StageArena::strdup(result);
234
240
  }
235
241
  KOALA_INTEROP_1(ExternalSourceName, KNativePointer, KNativePointer);
236
242
 
@@ -239,7 +245,7 @@ static KNativePointer impl_ExternalSourcePrograms(KNativePointer instance)
239
245
  auto&& _instance_ = reinterpret_cast<es2panda_ExternalSource *>(instance);
240
246
  std::size_t program_len = 0;
241
247
  auto programs = GetImpl()->ExternalSourcePrograms(_instance_, &program_len);
242
- return new std::vector<void*>(programs, programs + program_len);
248
+ return StageArena::cloneVector(programs, program_len);
243
249
  }
244
250
  KOALA_INTEROP_1(ExternalSourcePrograms, KNativePointer, KNativePointer);
245
251
 
@@ -263,3 +269,65 @@ KBoolean impl_IsETSFunctionType(KNativePointer nodePtr)
263
269
  return GetImpl()->IsETSFunctionType(node);
264
270
  }
265
271
  KOALA_INTEROP_1(IsETSFunctionType, KBoolean, KNativePointer)
272
+
273
+ KNativePointer impl_ETSParserBuildImportDeclaration(KNativePointer context, KInt importKinds, KNativePointerArray specifiers, KUInt specifiersSequenceLength, KNativePointer source, KNativePointer program, KInt importFlag)
274
+ {
275
+ const auto _context = reinterpret_cast<es2panda_Context*>(context);
276
+ const auto _kinds = static_cast<Es2pandaImportKinds>(importKinds);
277
+ const auto _specifiers = reinterpret_cast<es2panda_AstNode**>(specifiers);
278
+ const auto _specifiersSequenceLength = static_cast<size_t>(specifiersSequenceLength);
279
+ const auto _source = reinterpret_cast<es2panda_AstNode*>(source);
280
+ const auto _program = reinterpret_cast<es2panda_Program*>(program);
281
+ const auto _importFlag = static_cast<Es2pandaImportFlags>(importFlag);
282
+
283
+ return GetImpl()->ETSParserBuildImportDeclaration(_context, _kinds, _specifiers, _specifiersSequenceLength, _source, _program, _importFlag);
284
+ }
285
+ KOALA_INTEROP_7(ETSParserBuildImportDeclaration, KNativePointer, KNativePointer, KInt, KNativePointerArray, KUInt, KNativePointer, KNativePointer, KInt)
286
+
287
+ void impl_InsertETSImportDeclarationAndParse(KNativePointer context, KNativePointer program, KNativePointer importDeclaration)
288
+ {
289
+ const auto _context = reinterpret_cast<es2panda_Context*>(context);
290
+ const auto _program = reinterpret_cast<es2panda_Program*>(program);
291
+ const auto _import = reinterpret_cast<es2panda_AstNode*>(importDeclaration);
292
+ GetImpl()->InsertETSImportDeclarationAndParse(_context, _program, _import);
293
+ }
294
+ KOALA_INTEROP_V3(InsertETSImportDeclarationAndParse, KNativePointer, KNativePointer, KNativePointer)
295
+
296
+ KNativePointer impl_ETSParserGetImportPathManager(KNativePointer contextPtr)
297
+ {
298
+ auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
299
+ return GetImpl()->ETSParserGetImportPathManager(context);
300
+ }
301
+ KOALA_INTEROP_1(ETSParserGetImportPathManager, KNativePointer, KNativePointer);
302
+
303
+ KNativePointer impl_CreateSourcePosition(KNativePointer context, KInt index, KInt line)
304
+ {
305
+ auto&& _context_ = reinterpret_cast<es2panda_Context *>(context);
306
+ return GetImpl()->CreateSourcePosition(_context_, index, line);
307
+ }
308
+ KOALA_INTEROP_3(CreateSourcePosition, KNativePointer, KNativePointer, KInt, KInt);
309
+
310
+ KInt impl_SourcePositionIndex(KNativePointer context, KNativePointer instance)
311
+ {
312
+ auto&& _context_ = reinterpret_cast<es2panda_Context *>(context);
313
+ auto&& _instance_ = reinterpret_cast<es2panda_SourcePosition *>(instance);
314
+ return GetImpl()->SourcePositionIndex(_context_, _instance_);
315
+ }
316
+ KOALA_INTEROP_2(SourcePositionIndex, KInt, KNativePointer, KNativePointer);
317
+
318
+ KInt impl_SourcePositionLine(KNativePointer context, KNativePointer instance)
319
+ {
320
+ auto&& _context_ = reinterpret_cast<es2panda_Context *>(context);
321
+ auto&& _instance_ = reinterpret_cast<es2panda_SourcePosition *>(instance);
322
+ return GetImpl()->SourcePositionLine(_context_, _instance_);
323
+ }
324
+ KOALA_INTEROP_2(SourcePositionLine, KInt, KNativePointer, KNativePointer);
325
+
326
+ KNativePointer impl_CreateSourceRange(KNativePointer context, KNativePointer start, KNativePointer end)
327
+ {
328
+ auto&& _context_ = reinterpret_cast<es2panda_Context *>(context);
329
+ auto&& _start_ = reinterpret_cast<es2panda_SourcePosition *>(start);
330
+ auto&& _end_ = reinterpret_cast<es2panda_SourcePosition *>(end);
331
+ return GetImpl()->CreateSourceRange(_context_, _start_, _end_);
332
+ }
333
+ KOALA_INTEROP_3(CreateSourceRange, KNativePointer, KNativePointer, KNativePointer, KNativePointer);
@@ -14,11 +14,56 @@
14
14
  */
15
15
 
16
16
  #include <common.h>
17
+ #include <utility>
17
18
 
18
19
  using std::string, std::cout, std::endl, std::vector;
19
20
 
20
21
  static es2panda_Impl *impl = nullptr;
21
22
 
23
+ static thread_local StageArena currentArena;
24
+
25
+ StageArena* StageArena::instance() {
26
+ return &currentArena;
27
+ }
28
+
29
+ void StageArena::add(void* pointer) {
30
+ if (pointer)
31
+ allocated.push_back(pointer);
32
+ }
33
+
34
+ void StageArena::cleanup() {
35
+ if (totalSize > 0 && false)
36
+ printf("cleanup %d objects %d bytes\n", (int)allocated.size(), (int)totalSize);
37
+ for (auto it : allocated) {
38
+ free(it);
39
+ }
40
+ totalSize = 0;
41
+ allocated.clear();
42
+ }
43
+
44
+ StageArena::StageArena() {
45
+ totalSize = 0;
46
+ }
47
+
48
+ StageArena::~StageArena() {
49
+ cleanup();
50
+ }
51
+
52
+ char* StageArena::strdup(const char* string) {
53
+ auto* arena = StageArena::instance();
54
+ auto size = strlen(string) + 1;
55
+ char* memory = (char*)arena->alloc(size);
56
+ memcpy(memory, string, size);
57
+ return memory;
58
+ }
59
+
60
+ void* StageArena::alloc(size_t size) {
61
+ void* result = malloc(size);
62
+ totalSize += size;
63
+ add(result);
64
+ return result;
65
+ }
66
+
22
67
  #ifdef KOALA_WINDOWS
23
68
  #include <windows.h>
24
69
  #define PLUGIN_DIR "windows_host_tools"
@@ -58,11 +103,13 @@ es2panda_Impl *GetImpl() {
58
103
  }
59
104
  auto library = FindLibrary();
60
105
  if (!library) {
61
- throw std::runtime_error("No library (es2panda_lib.cc)");
106
+ printf("No library (es2panda_lib.cc)"); // TODO: dont use throw for ohos build
107
+ abort();
62
108
  }
63
109
  auto symbol = findSymbol(library, "es2panda_GetImpl");
64
110
  if (!symbol) {
65
- throw std::runtime_error("No entry point");
111
+ printf("no entry point");
112
+ abort();
66
113
  }
67
114
  impl = reinterpret_cast<es2panda_Impl *(*)(int)>(symbol)(ES2PANDA_LIB_VERSION);
68
115
  return impl;
@@ -78,7 +125,7 @@ string getString(KStringPtr ptr) {
78
125
  }
79
126
 
80
127
  char* getStringCopy(KStringPtr& ptr) {
81
- return strdup(ptr.c_str());
128
+ return StageArena::strdup(ptr.c_str() ? ptr.c_str() : "");
82
129
  }
83
130
 
84
131
  inline KUInt unpackUInt(const KByte* bytes) {
@@ -91,7 +138,7 @@ inline KUInt unpackUInt(const KByte* bytes) {
91
138
  const KUInt BYTE_2_SHIFT = 16;
92
139
  const KUInt BYTE_3_SHIFT = 24;
93
140
  return (
94
- bytes[BYTE_0]
141
+ bytes[BYTE_0]
95
142
  | (bytes[BYTE_1] << BYTE_1_SHIFT)
96
143
  | (bytes[BYTE_2] << BYTE_2_SHIFT)
97
144
  | (bytes[BYTE_3] << BYTE_3_SHIFT)
@@ -101,13 +148,13 @@ inline KUInt unpackUInt(const KByte* bytes) {
101
148
  KNativePointer impl_CreateConfig(KInt argc, KStringArray argvPtr) {
102
149
  const std::size_t headerLen = 4;
103
150
 
104
- const char** argv = new const char*[argc];
151
+ const char** argv = StageArena::allocArray<const char*>(argc);
105
152
  std::size_t position = headerLen;
106
153
  std::size_t strLen;
107
154
  for (std::size_t i = 0; i < static_cast<std::size_t>(argc); ++i) {
108
155
  strLen = unpackUInt(argvPtr + position);
109
156
  position += headerLen;
110
- argv[i] = strdup(std::string(reinterpret_cast<const char*>(argvPtr + position), strLen).c_str());
157
+ argv[i] = StageArena::strdup(std::string(reinterpret_cast<const char*>(argvPtr + position), strLen).c_str());
111
158
  position += strLen;
112
159
  }
113
160
  return GetImpl()->CreateConfig(argc, argv);
@@ -124,6 +171,7 @@ KOALA_INTEROP_1(DestroyConfig, KNativePointer, KNativePointer)
124
171
  KNativePointer impl_DestroyContext(KNativePointer contextPtr) {
125
172
  auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
126
173
  GetImpl()->DestroyContext(context);
174
+ StageArena::instance()->cleanup();
127
175
  return nullptr;
128
176
  }
129
177
  KOALA_INTEROP_1(DestroyContext, KNativePointer, KNativePointer)
@@ -148,7 +196,7 @@ KNativePointer impl_UpdateCallExpression(
148
196
 
149
197
  auto nn = GetImpl()->CreateCallExpression(
150
198
  context, callee, arguments, argumentsLen, typeParams, optional, trailingComma
151
- );
199
+ );
152
200
  GetImpl()->AstNodeSetOriginalNode(context, nn, node);
153
201
  return nn;
154
202
  }
@@ -222,7 +270,7 @@ KNativePointer impl_AstNodeChildren(
222
270
  cachedChildren.clear();
223
271
 
224
272
  GetImpl()->AstNodeIterateConst(context, node, visitChild);
225
- return new std::vector(cachedChildren);
273
+ return StageArena::clone(cachedChildren);
226
274
  }
227
275
  KOALA_INTEROP_2(AstNodeChildren, KNativePointer, KNativePointer, KNativePointer)
228
276
 
@@ -36,4 +36,52 @@ inline KUInt unpackUInt(const KByte* bytes);
36
36
 
37
37
  es2panda_ContextState intToState(KInt state);
38
38
 
39
+ class StageArena {
40
+ std::vector<void*> allocated;
41
+ size_t totalSize;
42
+ public:
43
+ StageArena();
44
+ ~StageArena();
45
+ static StageArena* instance();
46
+ template <typename T>
47
+ static T* alloc() {
48
+ auto* arena = StageArena::instance();
49
+ void* memory = arena->alloc(sizeof(T));
50
+ return new (memory) T();
51
+ }
52
+ template <class T, class T1>
53
+ static T* alloc(T1 arg1) {
54
+ auto* arena = StageArena::instance();
55
+ void* memory = arena->alloc(sizeof(T));
56
+ return new (memory) T(std::forward(arg1));
57
+ }
58
+ template <class T, class T1, class T2>
59
+ static T* alloc(T1 arg1, T2 arg2) {
60
+ auto* arena = StageArena::instance();
61
+ void* memory = arena->alloc(sizeof(T));
62
+ return new (memory) T(arg1, arg2);
63
+ }
64
+ template <typename T>
65
+ static T* allocArray(size_t count) {
66
+ auto* arena = StageArena::instance();
67
+ // align?
68
+ void* memory = arena->alloc(sizeof(T) * count);
69
+ return new (memory) T();
70
+ }
71
+ template <class T>
72
+ static T* clone(const T& arg) {
73
+ auto* arena = StageArena::instance();
74
+ void* memory = arena->alloc(sizeof(T));
75
+ return new (memory) T(arg);
76
+ }
77
+ template <class T>
78
+ static std::vector<const void*>* cloneVector(const T* arg, size_t count) {
79
+ return alloc<std::vector<const void*>, const T*, const T*>(arg, arg + count);
80
+ }
81
+ void* alloc(size_t size);
82
+ static char* strdup(const char* original);
83
+ void add(void* pointer);
84
+ void cleanup();
85
+ };
86
+
39
87
  #endif // COMMON_H