From d51c691dd4fd3d8f3b44670fc21e35e474694f03 Mon Sep 17 00:00:00 2001 From: ekkoruse Date: Mon, 9 Jun 2025 17:33:17 +0800 Subject: [PATCH] api --- koala-wrapper/native/src/bridges.cc | 17 +++++++++++++++++ koala-wrapper/src/Es2pandaNativeModule.ts | 4 ++++ koala-wrapper/src/arkts-api/peers/Context.ts | 16 ++++++++++++++-- koala-wrapper/src/arkts-api/utilities/public.ts | 12 +++++++++++- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/koala-wrapper/native/src/bridges.cc b/koala-wrapper/native/src/bridges.cc index 5333ea8b5..31f47ec4b 100644 --- a/koala-wrapper/native/src/bridges.cc +++ b/koala-wrapper/native/src/bridges.cc @@ -316,6 +316,23 @@ static KNativePointer impl_ExternalSourcePrograms(KNativePointer instance) } KOALA_INTEROP_1(ExternalSourcePrograms, KNativePointer, KNativePointer); +KNativePointer impl_CreateContextGenerateAbcForExternalSourceFiles(KNativePointer configPtr, KInt fileNamesCount, KStringArray fileNames) +{ + auto config = reinterpret_cast(configPtr); + const std::size_t HEADER_LEN = 4; + const char **argv = new const char *[static_cast(fileNamesCount)]; + std::size_t position = HEADER_LEN; + std::size_t strLen; + for (std::size_t i = 0; i < static_cast(fileNamesCount); ++i) { + strLen = unpackUInt(fileNames + position); + position += HEADER_LEN; + argv[i] = strdup(std::string(reinterpret_cast(fileNames + position), strLen).c_str()); + position += strLen; + } + return GetImpl()->CreateContextGenerateAbcForExternalSourceFiles(config, fileNamesCount, argv); +} +KOALA_INTEROP_3(CreateContextGenerateAbcForExternalSourceFiles, KNativePointer, KNativePointer, KInt, KStringArray) + KBoolean impl_IsClassProperty(KNativePointer nodePtr) { auto node = reinterpret_cast(nodePtr); diff --git a/koala-wrapper/src/Es2pandaNativeModule.ts b/koala-wrapper/src/Es2pandaNativeModule.ts index 6c5b48e7d..e75524ba7 100644 --- a/koala-wrapper/src/Es2pandaNativeModule.ts +++ b/koala-wrapper/src/Es2pandaNativeModule.ts @@ -105,6 +105,10 @@ export class Es2pandaNativeModule { _CreateContextFromString(config: KPtr, source: String, filename: String): KPtr { throw new Error('Not implemented'); } + _CreateContextGenerateAbcForExternalSourceFiles(config: KPtr, fileCount: KInt, filenames: + string[]): KPtr { + throw new Error('Not implemented'); + } _CreateContextFromFile(config: KPtr, filename: String): KPtr { throw new Error('Not implemented'); } diff --git a/koala-wrapper/src/arkts-api/peers/Context.ts b/koala-wrapper/src/arkts-api/peers/Context.ts index b4bf7a203..d587d1f9a 100644 --- a/koala-wrapper/src/arkts-api/peers/Context.ts +++ b/koala-wrapper/src/arkts-api/peers/Context.ts @@ -16,8 +16,8 @@ import { ArktsObject } from './ArktsObject'; import { global } from '../static/global'; import { throwError, filterSource } from '../../utils'; -import { passString } from '../utilities/private'; -import { KBoolean, KNativePointer } from '@koalaui/interop'; +import { passString, passStringArray } from '../utilities/private'; +import { KBoolean, KInt, KNativePointer } from '@koalaui/interop'; import { AstNode } from './AstNode'; import { Program } from './Program'; export class Context extends ArktsObject { @@ -45,6 +45,18 @@ export class Context extends ArktsObject { ); } + static createContextGenerateAbcForExternalSourceFiles( + fileCount: KInt, + filenames: string[]): Context { + if (!global.configIsInitialized()) { + throwError(`Config not initialized`); + } + return new Context( + global.es2panda._CreateContextGenerateAbcForExternalSourceFiles(global.config, fileCount, passStringArray(filenames)) + ); + } + + static destroyAndRecreate(ast: AstNode): Context { console.log('[TS WRAPPER] DESTROY AND RECREATE'); const source = filterSource(ast.dumpSrc()); diff --git a/koala-wrapper/src/arkts-api/utilities/public.ts b/koala-wrapper/src/arkts-api/utilities/public.ts index d7e2dfc33..450451109 100644 --- a/koala-wrapper/src/arkts-api/utilities/public.ts +++ b/koala-wrapper/src/arkts-api/utilities/public.ts @@ -15,7 +15,7 @@ import { global } from '../static/global'; import { isNumber, throwError, getEnumName } from '../../utils'; -import { KNativePointer, KInt, nullptr, withStringResult } from '@koalaui/interop'; +import { KNativePointer, KInt, nullptr, withStringResult, KStringArrayPtr } from '@koalaui/int import { passNode, passString, passStringArray, unpackNodeArray, unpackNonNullableNode } from './private'; import { isFunctionDeclaration, isMemberExpression, isMethodDefinition, isNumberLiteral } from '../factory/nodeTests'; import { @@ -42,6 +42,7 @@ import { Program } from '../peers/Program'; import { clearNodeCache } from '../class-by-peer'; import { SourcePosition } from '../peers/SourcePosition'; import { MemberExpression } from '../to-be-generated/MemberExpression'; +import { KNativePointerArray } from 'src/generated/Es2pandaNativeModule'; export function proceedToState(state: Es2pandaContextState, context: KNativePointer, forceDtsEmit = false): void { console.log('[TS WRAPPER] PROCEED TO STATE: ', getEnumName(Es2pandaContextState, state)); @@ -317,3 +318,12 @@ export function insertGlobalStructInfo(structName: string): void { export function hasGlobalStructInfo(structName: string): boolean { return global.es2panda._HasGlobalStructInfo(global.context, passString(structName)); } + +export function createContextGenerateAbcForExternalSourceFiles( + fileCount: KInt, + filenames: string[] +): KNativePointer { + console.log("1232131") + console.log("filenames", filenames); + return global.es2panda._CreateContextGenerateAbcForExternalSourceFiles(global.config, fileCount, passStringArray(filenames)); +} -- Gitee