From aa449a07d69308cf683e216963af4fc1d02f30a4 Mon Sep 17 00:00:00 2001 From: polyprogrammist Date: Fri, 29 Dec 2023 21:39:15 -0500 Subject: [PATCH] tmp --- src/codegen/generators/generator.ts | 3 ++- src/codegen/generators/typescript/generator.ts | 4 ++-- src/codegen/generators/typescript/handle_field.ts | 8 -------- src/codegen/main.ts | 4 ++-- 4 files changed, 6 insertions(+), 13 deletions(-) delete mode 100644 src/codegen/generators/typescript/handle_field.ts diff --git a/src/codegen/generators/generator.ts b/src/codegen/generators/generator.ts index 05ab205..c9e29af 100644 --- a/src/codegen/generators/generator.ts +++ b/src/codegen/generators/generator.ts @@ -6,10 +6,11 @@ export interface CodeGenerator { jsCodeDeclarations: CommonGenDeclaration[] jsCodeConstructorDeclarations: CommonGenDeclaration[] jsCodeFunctionsDeclarations: CommonGenDeclaration[] + tlbCode: TLBCode addTonCoreClassUsage(name: string): void addBitLenFunction(): void - addTlbType(tlbType: TLBType, tlbCode: TLBCode): void + addTlbType(tlbType: TLBType): void toCode(node: TheNode, code: CodeBuilder): CodeBuilder } diff --git a/src/codegen/generators/typescript/generator.ts b/src/codegen/generators/typescript/generator.ts index b6480af..616047e 100644 --- a/src/codegen/generators/typescript/generator.ts +++ b/src/codegen/generators/typescript/generator.ts @@ -6,6 +6,7 @@ import { BinaryExpression, FunctionDeclaration, GenDeclaration, ObjectProperty, import { addLoadProperty, convertToAST, getCondition, getParamVarExpr, getTypeParametersExpression, sliceLoad } from "./utils"; import { handleType } from "./handle_type"; + export class TypescriptGenerator implements CodeGenerator { jsCodeDeclarations: GenDeclaration[] = [] jsCodeConstructorDeclarations: GenDeclaration[] = [] @@ -24,7 +25,7 @@ export class TypescriptGenerator implements CodeGenerator { tExpressionStatement(tIdentifier('return n.toString(2).length;')) ])) } - addTlbType(tlbType: TLBType, tlbCode: TLBCode): void { + addTlbType(tlbType: TLBType): void { let variableCombinatorName = goodVariableName(firstLower(tlbType.name), '0') let subStructsUnion: TypeExpression[] = [] let subStructDeclarations: StructDeclaration[] = [] @@ -37,7 +38,6 @@ export class TypescriptGenerator implements CodeGenerator { tlbType.constructors.forEach(constructor => { let constructorLoadStatements: Statement[] = [] let subStructName: string = getSubStructName(tlbType, constructor); - let variableSubStructName = goodVariableName(firstLower(subStructName), '_' + constructor.name) let subStructProperties: TypedIdentifier[] = [tTypedIdentifier(tIdentifier('kind'), tStringLiteral(subStructName))] diff --git a/src/codegen/generators/typescript/handle_field.ts b/src/codegen/generators/typescript/handle_field.ts deleted file mode 100644 index 4970f28..0000000 --- a/src/codegen/generators/typescript/handle_field.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { tIdentifier, tArrowFunctionExpression, tArrowFunctionType, tBinaryExpression, tBinaryNumericLiteral, tDeclareVariable, tExpressionStatement, tFunctionCall, tFunctionDeclaration, tIfStatement, tImportDeclaration, tMemberExpression, tNumericLiteral, tObjectExpression, tObjectProperty, tReturnStatement, tStringLiteral, tStructDeclaration, tTypeParametersExpression, tTypeWithParameters, tTypedIdentifier, GenDeclaration, tUnionTypeDeclaration, toCode, TypeWithParameters, ArrowFunctionExpression, FunctionDeclaration } from './tsgen' -import { TLBMathExpr, TLBVarExpr, TLBNumberExpr, TLBBinaryOp, TLBCode, TLBType, TLBConstructor, TLBParameter, TLBVariable, TLBField, TLBFieldType } from '../../ast' -import { Expression, Statement, Identifier, BinaryExpression, ASTNode, TypeExpression, TypeParametersExpression, ObjectProperty, TypedIdentifier } from './tsgen' -import { fillConstructors, firstLower, getCurrentSlice, bitLen, convertToMathExpr, splitForTypeValue, deriveMathExpression } from '../../utils' -import { handleType } from './handle_type' -import { addLoadProperty, getNegationDerivationFunctionBody, getParamVarExpr, sliceLoad } from './utils' -import { goodVariableName } from '../../utils' -import { getType } from "../../astbuilder/handle_type" diff --git a/src/codegen/main.ts b/src/codegen/main.ts index c77a63e..4cb6ae6 100644 --- a/src/codegen/main.ts +++ b/src/codegen/main.ts @@ -11,7 +11,7 @@ export function generate(tree: Program, input: string) { let splittedInput = input.split('\n') fillConstructors(tree.declarations, tlbCode, splittedInput); - + let codeGenerator: CodeGenerator = new TypescriptGenerator(tlbCode); codeGenerator.addTonCoreClassUsage('Builder') @@ -28,7 +28,7 @@ export function generate(tree: Program, input: string) { jsCodeDeclarations.push(declaration) }) - tlbCode.types.forEach((tlbType: TLBType) => { codeGenerator.addTlbType(tlbType, tlbCode) }); + tlbCode.types.forEach((tlbType: TLBType) => { codeGenerator.addTlbType(tlbType) }); let generatedCode = ''