diff --git a/libarkts/generator/options.json5 b/libarkts/generator/options.json5 index 50c1e97ba7c518bd064362cd3f9a6fccdd7d0794..5c87fe5951856128ad8f7940e5eabe27b9715fab 100644 --- a/libarkts/generator/options.json5 +++ b/libarkts/generator/options.json5 @@ -171,29 +171,25 @@ { interface: "ClassDefinition", methods: [ - "SetBody", // handwritten, no such method in idl. - // probably, an optimized version. + "SetBody", // TODO: implement in compiler some time ] }, ] }, - globalAliases: - { - classes: [ - "parser.Program", - "es2panda.ArkTsConfig", - ], - functions: [ - "compiler.generateTsDeclarationsFromContext", - "compiler.createDiagnosticInfo", - "compiler.createSuggestionInfo", - "compiler.logDiagnostic", - "compiler.logDiagnosticWithSuggestion", - "compiler.memInitialize", - "compiler.memFinalize", - "compiler.freeCompilerPartMemory", - ] - }, + globalAliases: { + classes: [ + "parser.Program", + "es2panda.ArkTsConfig", + ], + functions: [ + "compiler.*", + "compiler.ProceedToState!", + "compiler.Is*!", + "compiler.LogDiagnostic!", // different order or arguments in handwritten and idl + "compiler.CreateSuggestionInfo!", // different order or arguments in handwritten and idl, spread args + "compiler.CreateDiagnosticInfo!", // different order or arguments in handwritten and idl, spread args + ] + }, nonNullable: [ { name: "es2panda_Impl", @@ -234,6 +230,14 @@ name: "CreateSuggestionInfo", types: ["returnType"], }, + { + name: "CreateSourceRange", + types: ["returnType"], + }, + { + name: "CreateSourcePosition", + types: ["returnType"], + }, ], }, { diff --git a/libarkts/package.json b/libarkts/package.json index f2ff19b71a9878f28d9daa31f01962e5d4de1089..8b38c31305c157f07d7c12bde571d158460f1832 100644 --- a/libarkts/package.json +++ b/libarkts/package.json @@ -38,7 +38,7 @@ "tsconfig-paths": "^4.2.0", "rimraf": "^6.0.1", "@koalaui/fast-arktsc": "1.7.14+devel", - "@idlizer/arktscgen": "2.1.10-arktscgen-9", + "@idlizer/arktscgen": "2.1.10-arktscgen-10", "mocha": "^9.2.2", "@koalaui/harness": "1.7.14+devel", "@koalaui/ets-tsc": "4.9.5-r6", diff --git a/libarkts/src/arkts-api/utilities/public.ts b/libarkts/src/arkts-api/utilities/public.ts index 09ef2b9962d7fb447ad1218c1b12a087faa11615..931bc36f1461cbb959221456f19d5fe16137a254 100644 --- a/libarkts/src/arkts-api/utilities/public.ts +++ b/libarkts/src/arkts-api/utilities/public.ts @@ -20,7 +20,6 @@ import { passNode, unpackNodeArray, unpackNonNullableNode, - passString, unpackString, unpackNode, } from './private'; @@ -78,15 +77,8 @@ import { traceGlobal } from '../../tracer'; * @deprecated */ export function createETSModuleFromContext(): ETSModule { - let program = global.generatedEs2panda._ContextProgram(global.context); - if (program == nullptr) { - throw new Error(`Program is null for context ${global.context.toString(16)}`); - } - const ast = global.generatedEs2panda._ProgramAst(global.context, program); - if (ast == nullptr) { - throw new Error(`AST is null for program ${program.toString(16)}`); - } - return new ETSModule(ast, Es2pandaAstNodeType.AST_NODE_TYPE_ETS_MODULE); + const program = compiler.contextProgram(); + return program.getAstCasted(); } /** @@ -104,13 +96,8 @@ export function createETSModuleFromSource( } global.compilerContext = Context.createFromString(source); proceedToState(state); - let program = global.generatedEs2panda._ContextProgram(global.compilerContext.peer); - if (program === nullptr) - throw new Error(`Program is null for ${source} 0x${global.compilerContext.peer.toString(16)}`); - return new ETSModule( - global.generatedEs2panda._ProgramAst(global.context, program), - Es2pandaAstNodeType.AST_NODE_TYPE_ETS_MODULE - ); + const program = compiler.contextProgram(); + return program.getAstCasted(); } export function metaDatabase(fileName: string): string { @@ -119,14 +106,14 @@ export function metaDatabase(fileName: string): string { } export function checkErrors(proceedTo?: string) { - if (global.es2panda._ContextState(global.context) === Es2pandaContextState.ES2PANDA_STATE_ERROR) { + if (compiler.contextState() === Es2pandaContextState.ES2PANDA_STATE_ERROR) { traceGlobal(() => `Terminated due to compilation errors occured`); - const errorMessage = unpackString(global.generatedEs2panda._ContextErrorMessage(global.context)); + const errorMessage = compiler.contextErrorMessage(); if (errorMessage === undefined) { throwError(`Could not get ContextErrorMessage`); } - const allErrorMessages = unpackString(global.generatedEs2panda._GetAllErrorMessages(global.context)); + const allErrorMessages = compiler.getAllErrorMessages(); if (allErrorMessages === undefined) { throwError(`Could not get AllErrorMessages`); } @@ -136,13 +123,13 @@ export function checkErrors(proceedTo?: string) { } export function proceedToState(state: Es2pandaContextState, _contextPtr?: KNativePointer, ignoreErrors = false): void { - if (global.es2panda._ContextState(global.context) === Es2pandaContextState.ES2PANDA_STATE_ERROR) { + if (compiler.contextState() === Es2pandaContextState.ES2PANDA_STATE_ERROR) { NodeCache.clear(); if (!ignoreErrors) { checkErrors(Es2pandaContextState[state]); } } - if (state <= global.es2panda._ContextState(global.context)) { + if (state <= compiler.contextState()) { return; } NodeCache.clear(); @@ -161,7 +148,7 @@ export function proceedToState(state: Es2pandaContextState, _contextPtr?: KNativ export function rebindSubtree(node: AstNode): void { NodeCache.clear(); traceGlobal(() => `Rebind: start`); - global.es2panda._AstNodeRebind(global.context, node.peer); + compiler.astNodeRebind(node); traceGlobal(() => `Rebind: done`); checkErrors(); } @@ -170,17 +157,14 @@ export function rebindSubtree(node: AstNode): void { export function recheckSubtree(node: AstNode): void { NodeCache.clear(); traceGlobal(() => `Recheck: start`); - global.generatedEs2panda._AstNodeRecheck(global.context, node.peer); + compiler.astNodeRecheck(node); traceGlobal(() => `Recheck: done`); } export function rebindContext(context: KNativePointer = global.context): void { NodeCache.clear(); traceGlobal(() => `Rebind: start`); - global.es2panda._AstNodeRebind( - context, - global.generatedEs2panda._ProgramAst(context, global.generatedEs2panda._ContextProgram(context)) - ); + compiler.astNodeRebind(compiler.contextProgram().getAstCasted()); traceGlobal(() => `Rebind: done`); checkErrors(); } @@ -188,10 +172,7 @@ export function rebindContext(context: KNativePointer = global.context): void { export function recheckContext(context: KNativePointer = global.context): void { NodeCache.clear(); traceGlobal(() => `Recheck: start`); - global.generatedEs2panda._AstNodeRecheck( - context, - global.generatedEs2panda._ProgramAst(context, global.generatedEs2panda._ContextProgram(context)) - ); + compiler.astNodeRecheck(compiler.contextProgram().getAstCasted()); traceGlobal(() => `Recheck: done`); checkErrors(); } @@ -260,10 +241,6 @@ export function getPeerDecl(peer: KNativePointer): AstNode | undefined { return unpackNonNullableNode(decl); } -export function declarationFromIdentifier(node: Identifier): AstNode | undefined { - return unpackNode(global.generatedEs2panda._DeclarationFromIdentifier(global.context, node.peer)); -} - export function resolveGensymVariableDeclaratorForDefaultParam(node: VariableDeclarator): Identifier | undefined { const init = node.init; if ( @@ -349,7 +326,7 @@ export function getJsDoc(node: AstNode): string | undefined { // Use this function if you need // the language level modifiers: public, declare, export, etc. export function classDefinitionFlags(node: ClassDefinition): Es2pandaModifierFlags { - return global.generatedEs2panda._AstNodeModifiers(global.context, node.peer); + return node.modifierFlags } // Improve: ClassProperty's optional flag is set by AstNode's modifiers flags. @@ -405,24 +382,6 @@ export function findStdlib(): string { return `${sdk}/ets/stdlib`; } -export function generateTsDeclarationsFromContext( - outputDeclEts: string, - outputEts: string, - exportAll: boolean, - isolated: boolean, - recordFile: string, - genAnnotations: boolean -): KInt { - return compiler.generateTsDeclarationsFromContext( - passString(outputDeclEts), - passString(outputEts), - exportAll, - isolated, - recordFile, - genAnnotations - ); -} - export function setAllParents(ast: AstNode): void { global.es2panda._AstNodeUpdateAll(global.context, ast.peer); } @@ -432,7 +391,7 @@ export function getProgramFromAstNode(node: AstNode): Program { } export function importDeclarationInsert(node: ETSImportDeclaration, program: Program): void { - global.generatedEs2panda._InsertETSImportDeclarationAndParse(global.context, program.peer, node.peer); + compiler.insertETSImportDeclarationAndParse(program, node); } export function signatureReturnType(signature: KNativePointer): KNativePointer { @@ -465,10 +424,6 @@ export function originalSourcePositionString(node: AstNode | undefined) { return `[${program.absoluteName}${sourcePosition.toString()}]`; } -export function generateStaticDeclarationsFromContext(outputPath: string): KInt { - return global.generatedEs2panda._GenerateStaticDeclarationsFromContext(global.context, passString(outputPath)); -} - export function createTypeNodeFromTsType(node: AstNode): AstNode | undefined { const typeAnnotation = global.es2panda._CreateTypeNodeFromTsType(global.context, node.peer); if (typeAnnotation === nullptr) { @@ -477,14 +432,6 @@ export function createTypeNodeFromTsType(node: AstNode): AstNode | undefined { return unpackNonNullableNode(typeAnnotation); } -export function createSourcePosition(index: KUInt, line: KUInt): SourcePosition { - return new SourcePosition(global.generatedEs2panda._CreateSourcePosition(global.context, index, line)); -} - -export function createSourceRange(start: SourcePosition, end: SourcePosition): SourceRange { - return new SourceRange(global.generatedEs2panda._CreateSourceRange(global.context, start.peer, end.peer)); -} - export function createDiagnosticInfo( kind: DiagnosticKind, position: SourcePosition, @@ -521,10 +468,6 @@ export function logDiagnostic(kind: DiagnosticKind, pos: SourcePosition, ...args compiler.logDiagnostic(kind, args, pos); } -export function logDiagnosticWithSuggestion(diagnosticInfo: DiagnosticInfo, suggestionInfo: SuggestionInfo): void { - compiler.logDiagnosticWithSuggestion(diagnosticInfo, suggestionInfo); -} - export function filterNodes(node: AstNode, filter: string, deeperAfterMatch: boolean): AstNode[] { return unpackNodeArray(global.es2panda._FilterNodes(global.context, passNode(node), filter, deeperAfterMatch)); } @@ -541,18 +484,6 @@ export function filterNodesByTypes(node: AstNode, types: Es2pandaAstNodeType[]): return unpackNodeArray(global.es2panda._FilterNodes3(global.context, passNode(node), typesArray, types.length)); } -export function memInitialize() { - compiler.memInitialize() -} - -export function memFinalize() { - compiler.memFinalize() -} - -export function freeCompilerPartMemory() { - compiler.freeCompilerPartMemory() -} - export function jumpFromETSTypeReferenceToTSTypeAliasDeclarationTypeAnnotation(node: AstNode): AstNode | undefined { return unpackNode( global.es2panda._JumpFromETSTypeReferenceToTSTypeAliasDeclarationTypeAnnotation(global.context, passNode(node))