diff --git a/src/abi/AbiFunction.ts b/src/abi/AbiFunction.ts index e700b41cc..d043df202 100644 --- a/src/abi/AbiFunction.ts +++ b/src/abi/AbiFunction.ts @@ -1,4 +1,4 @@ -import { ASTExpression, SrcInfo } from "../grammar/ast"; +import { AstExpression, SrcInfo } from "../grammar/ast"; import { CompilerContext } from "../context"; import { WriterContext } from "../generator/Writer"; import { TypeRef } from "../types/types"; @@ -9,7 +9,7 @@ export type AbiFunction = { generate: ( ctx: WriterContext, args: TypeRef[], - resolved: ASTExpression[], + resolved: AstExpression[], loc: SrcInfo, ) => string; }; diff --git a/src/constEval.ts b/src/constEval.ts index d0f815bf8..9cc5cf877 100644 --- a/src/constEval.ts +++ b/src/constEval.ts @@ -2,12 +2,12 @@ import { Address, Cell, toNano } from "@ton/core"; import { enabledMasterchain } from "./config/features"; import { CompilerContext } from "./context"; import { - ASTBinaryOperation, - ASTExpression, + AstBinaryOperation, + AstExpression, AstId, - ASTNewParameter, + AstStructFieldInitializer, SrcInfo, - ASTUnaryOperation, + AstUnaryOperation, isSelfId, eqNames, idText, @@ -75,7 +75,7 @@ function ensureString(val: Value, source: SrcInfo): string { return val; } -function ensureFunArity(arity: number, args: ASTExpression[], source: SrcInfo) { +function ensureFunArity(arity: number, args: AstExpression[], source: SrcInfo) { if (args.length !== arity) { throwErrorConstEval( `function expects ${arity} argument(s), but got ${args.length}`, @@ -86,7 +86,7 @@ function ensureFunArity(arity: number, args: ASTExpression[], source: SrcInfo) { function ensureMethodArity( arity: number, - args: ASTExpression[], + args: AstExpression[], source: SrcInfo, ) { if (args.length !== arity) { @@ -98,8 +98,8 @@ function ensureMethodArity( } function evalUnaryOp( - op: ASTUnaryOperation, - operand: ASTExpression, + op: AstUnaryOperation, + operand: AstExpression, source: SrcInfo, ctx: CompilerContext, ): Value { @@ -149,9 +149,9 @@ function modFloor(a: bigint, b: bigint): bigint { } function evalBinaryOp( - op: ASTBinaryOperation, - left: ASTExpression, - right: ASTExpression, + op: AstBinaryOperation, + left: AstExpression, + right: AstExpression, source: SrcInfo, ctx: CompilerContext, ): Value { @@ -303,9 +303,9 @@ function evalBinaryOp( } function evalConditional( - condition: ASTExpression, - thenBranch: ASTExpression, - elseBranch: ASTExpression, + condition: AstExpression, + thenBranch: AstExpression, + elseBranch: AstExpression, ctx: CompilerContext, ): Value { // here we rely on the typechecker that both branches have the same type @@ -322,13 +322,13 @@ function evalConditional( function evalStructInstance( structTypeId: AstId, - structFields: ASTNewParameter[], + structFields: AstStructFieldInitializer[], ctx: CompilerContext, ): StructValue { return structFields.reduce( (resObj, fieldWithInit) => { - resObj[fieldWithInit.name.text] = evalConstantExpression( - fieldWithInit.exp, + resObj[fieldWithInit.field.text] = evalConstantExpression( + fieldWithInit.initializer, ctx, ); return resObj; @@ -338,7 +338,7 @@ function evalStructInstance( } function evalFieldAccess( - structExpr: ASTExpression, + structExpr: AstExpression, fieldId: AstId, source: SrcInfo, ctx: CompilerContext, @@ -392,8 +392,8 @@ function evalFieldAccess( function evalMethod( methodName: AstId, - object: ASTExpression, - args: ASTExpression[], + object: AstExpression, + args: AstExpression[], source: SrcInfo, ctx: CompilerContext, ): Value { @@ -416,7 +416,7 @@ function evalMethod( function evalBuiltins( builtinName: AstId, - args: ASTExpression[], + args: AstExpression[], source: SrcInfo, ctx: CompilerContext, ): Value { @@ -638,7 +638,7 @@ function interpretEscapeSequences(stringLiteral: string) { } export function evalConstantExpression( - ast: ASTExpression, + ast: AstExpression, ctx: CompilerContext, ): Value { switch (ast.kind) { @@ -656,8 +656,8 @@ export function evalConstantExpression( } throwNonFatalErrorConstEval("cannot evaluate a variable", ast.loc); break; - case "op_call": - return evalMethod(ast.name, ast.src, ast.args, ast.loc, ctx); + case "method_call": + return evalMethod(ast.method, ast.self, ast.args, ast.loc, ctx); case "init_of": throwNonFatalErrorConstEval( "initOf is not supported at this moment", @@ -673,7 +673,7 @@ export function evalConstantExpression( case "string": return ensureString(interpretEscapeSequences(ast.value), ast.loc); case "op_unary": - return evalUnaryOp(ast.op, ast.right, ast.loc, ctx); + return evalUnaryOp(ast.op, ast.operand, ast.loc, ctx); case "op_binary": return evalBinaryOp(ast.op, ast.left, ast.right, ast.loc, ctx); case "conditional": @@ -683,11 +683,11 @@ export function evalConstantExpression( ast.elseBranch, ctx, ); - case "op_new": + case "struct_instance": return evalStructInstance(ast.type, ast.args, ctx); - case "op_field": - return evalFieldAccess(ast.src, ast.name, ast.loc, ctx); - case "op_static_call": - return evalBuiltins(ast.name, ast.args, ast.loc, ctx); + case "field_access": + return evalFieldAccess(ast.aggregate, ast.field, ast.loc, ctx); + case "static_call": + return evalBuiltins(ast.function, ast.args, ast.loc, ctx); } } diff --git a/src/errors.ts b/src/errors.ts index cfb0bf01a..0fe11a720 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -1,7 +1,7 @@ import { MatchResult } from "ohm-js"; import path from "path"; import { cwd } from "process"; -import { AstId, SrcInfo } from "./grammar/ast"; +import { AstFuncId, AstId, AstTypeId, SrcInfo } from "./grammar/ast"; import { ItemOrigin } from "./grammar/grammar"; export class TactError extends Error { @@ -98,7 +98,11 @@ export function throwConstEvalError( export function idTextErr(ident: string): string; export function idTextErr(ident: AstId): string; -export function idTextErr(ident: AstId | string): string { +export function idTextErr(ident: AstFuncId): string; +export function idTextErr(ident: AstTypeId): string; +export function idTextErr( + ident: AstId | AstFuncId | AstTypeId | string, +): string { if (typeof ident === "string") { return `"${ident}"`; } diff --git a/src/generator/writers/writeExpression.ts b/src/generator/writers/writeExpression.ts index 5083c0772..6e5cf7cb2 100644 --- a/src/generator/writers/writeExpression.ts +++ b/src/generator/writers/writeExpression.ts @@ -1,11 +1,15 @@ import { - ASTExpression, + AstExpression, AstId, eqNames, idText, tryExtractPath, } from "../../grammar/ast"; -import { TactConstEvalError, throwCompilationError } from "../../errors"; +import { + idTextErr, + TactConstEvalError, + throwCompilationError, +} from "../../errors"; import { getExpType } from "../../types/resolveExpression"; import { getStaticConstant, @@ -38,7 +42,7 @@ import { ops } from "./ops"; import { writeCastedExpression } from "./writeFunction"; import { evalConstantExpression } from "../../constEval"; -function isNull(f: ASTExpression): boolean { +function isNull(f: AstExpression): boolean { return f.kind === "null"; } @@ -152,7 +156,7 @@ export function writePathExpression(path: AstId[]): string { ); } -export function writeExpression(f: ASTExpression, wCtx: WriterContext): string { +export function writeExpression(f: AstExpression, wCtx: WriterContext): string { // literals and constant expressions are covered here try { const value = evalConstantExpression(f, wCtx.ctx); @@ -407,33 +411,33 @@ export function writeExpression(f: ASTExpression, wCtx: WriterContext): string { if (f.kind === "op_unary") { // NOTE: Logical not is written as a bitwise not if (f.op === "!") { - return "(~ " + writeExpression(f.right, wCtx) + ")"; + return "(~ " + writeExpression(f.operand, wCtx) + ")"; } if (f.op === "~") { - return "(~ " + writeExpression(f.right, wCtx) + ")"; + return "(~ " + writeExpression(f.operand, wCtx) + ")"; } if (f.op === "-") { - return "(- " + writeExpression(f.right, wCtx) + ")"; + return "(- " + writeExpression(f.operand, wCtx) + ")"; } if (f.op === "+") { - return "(+ " + writeExpression(f.right, wCtx) + ")"; + return "(+ " + writeExpression(f.operand, wCtx) + ")"; } // NOTE: Assert function that ensures that the value is not null if (f.op === "!!") { - const t = getExpType(wCtx.ctx, f.right); + const t = getExpType(wCtx.ctx, f.operand); if (t.kind === "ref") { const tt = getType(wCtx.ctx, t.name); if (tt.kind === "struct") { - return `${ops.typeNotNull(tt.name, wCtx)}(${writeExpression(f.right, wCtx)})`; + return `${ops.typeNotNull(tt.name, wCtx)}(${writeExpression(f.operand, wCtx)})`; } } wCtx.used("__tact_not_null"); - return `${wCtx.used("__tact_not_null")}(${writeExpression(f.right, wCtx)})`; + return `${wCtx.used("__tact_not_null")}(${writeExpression(f.operand, wCtx)})`; } throwCompilationError(`Unknown unary operator: ${f.op}`, f.loc); @@ -444,9 +448,9 @@ export function writeExpression(f: ASTExpression, wCtx: WriterContext): string { // NOTE: this branch resolves "a.b", where "a" is an expression and "b" is a field name // - if (f.kind === "op_field") { + if (f.kind === "field_access") { // Resolve the type of the expression - const src = getExpType(wCtx.ctx, f.src); + const src = getExpType(wCtx.ctx, f.aggregate); if ( src === null || ((src.kind !== "ref" || src.optional) && src.kind !== "ref_bounced") @@ -466,12 +470,12 @@ export function writeExpression(f: ASTExpression, wCtx: WriterContext): string { fields = fields.slice(0, srcT.partialFieldCount); } - const field = fields.find((v) => v.name === f.name.text)!; - const cst = srcT.constants.find((v) => v.name === f.name.text)!; + const field = fields.find((v) => eqNames(v.name, f.field))!; + const cst = srcT.constants.find((v) => eqNames(v.name, f.field))!; if (!field && !cst) { throwCompilationError( - `Cannot find field "${f.name.text}" in struct "${srcT.name}"`, - f.name.loc, + `Cannot find field ${idTextErr(f.field)} in struct ${idTextErr(srcT.name)}`, + f.field.loc, ); } @@ -494,7 +498,7 @@ export function writeExpression(f: ASTExpression, wCtx: WriterContext): string { } // Getter instead of direct field access - return `${ops.typeField(srcT.name, field.name, wCtx)}(${writeExpression(f.src, wCtx)})`; + return `${ops.typeField(srcT.name, field.name, wCtx)}(${writeExpression(f.aggregate, wCtx)})`; } else { return writeValue(cst.value!, wCtx); } @@ -504,10 +508,10 @@ export function writeExpression(f: ASTExpression, wCtx: WriterContext): string { // Static Function Call // - if (f.kind === "op_static_call") { + if (f.kind === "static_call") { // Check global functions - if (GlobalFunctions.has(idText(f.name))) { - return GlobalFunctions.get(idText(f.name))!.generate( + if (GlobalFunctions.has(idText(f.function))) { + return GlobalFunctions.get(idText(f.function))!.generate( wCtx, f.args.map((v) => getExpType(wCtx.ctx, v)), f.args, @@ -515,8 +519,8 @@ export function writeExpression(f: ASTExpression, wCtx: WriterContext): string { ); } - const sf = getStaticFunction(wCtx.ctx, idText(f.name)); - let n = ops.global(idText(f.name)); + const sf = getStaticFunction(wCtx.ctx, idText(f.function)); + let n = ops.global(idText(f.function)); if (sf.ast.kind === "native_function_decl") { n = idText(sf.ast.nativeName); if (n.startsWith("__tact")) { @@ -541,13 +545,13 @@ export function writeExpression(f: ASTExpression, wCtx: WriterContext): string { // Struct Constructor // - if (f.kind === "op_new") { + if (f.kind === "struct_instance") { const src = getType(wCtx.ctx, f.type); // Write a constructor const id = writeStructConstructor( src, - f.args.map((v) => idText(v.name)), + f.args.map((v) => idText(v.field)), wCtx, ); wCtx.used(id); @@ -556,8 +560,8 @@ export function writeExpression(f: ASTExpression, wCtx: WriterContext): string { const expressions = f.args.map( (v) => writeCastedExpression( - v.exp, - src.fields.find((v2) => eqNames(v2.name, v.name))!.type, + v.initializer, + src.fields.find((v2) => eqNames(v2.name, v.field))!.type, wCtx, ), wCtx, @@ -569,9 +573,9 @@ export function writeExpression(f: ASTExpression, wCtx: WriterContext): string { // Object-based function call // - if (f.kind === "op_call") { + if (f.kind === "method_call") { // Resolve source type - const src = getExpType(wCtx.ctx, f.src); + const src = getExpType(wCtx.ctx, f.self); if (src === null) { throwCompilationError( `Cannot call function of non - direct type: "${printTypeRef(src)}"`, @@ -593,20 +597,20 @@ export function writeExpression(f: ASTExpression, wCtx: WriterContext): string { // Check struct ABI if (t.kind === "struct") { - if (StructFunctions.has(idText(f.name))) { - const abi = StructFunctions.get(idText(f.name))!; + if (StructFunctions.has(idText(f.method))) { + const abi = StructFunctions.get(idText(f.method))!; return abi.generate( wCtx, [src, ...f.args.map((v) => getExpType(wCtx.ctx, v))], - [f.src, ...f.args], + [f.self, ...f.args], f.loc, ); } } // Resolve function - const ff = t.functions.get(idText(f.name))!; - let name = ops.extension(src.name, idText(f.name)); + const ff = t.functions.get(idText(f.method))!; + let name = ops.extension(src.name, idText(f.method)); if ( ff.ast.kind === "function_def" || ff.ast.kind === "function_decl" @@ -645,9 +649,9 @@ export function writeExpression(f: ASTExpression, wCtx: WriterContext): string { } // Render - const s = writeExpression(f.src, wCtx); + const s = writeExpression(f.self, wCtx); if (ff.isMutating) { - if (f.src.kind === "id" || f.src.kind === "op_field") { + if (f.self.kind === "id" || f.self.kind === "field_access") { return `${s}~${name}(${renderedArguments.join(", ")})`; } else { return `${wCtx.used(ops.nonModifying(name))}(${[s, ...renderedArguments].join(", ")})`; @@ -659,17 +663,17 @@ export function writeExpression(f: ASTExpression, wCtx: WriterContext): string { // Map types if (src.kind === "map") { - if (!MapFunctions.has(idText(f.name))) { + if (!MapFunctions.has(idText(f.method))) { throwCompilationError( - `Map function "${idText(f.name)}" not found`, + `Map function "${idText(f.method)}" not found`, f.loc, ); } - const abf = MapFunctions.get(idText(f.name))!; + const abf = MapFunctions.get(idText(f.method))!; return abf.generate( wCtx, [src, ...f.args.map((v) => getExpType(wCtx.ctx, v))], - [f.src, ...f.args], + [f.self, ...f.args], f.loc, ); } @@ -689,8 +693,8 @@ export function writeExpression(f: ASTExpression, wCtx: WriterContext): string { // if (f.kind === "init_of") { - const type = getType(wCtx.ctx, f.name); - return `${ops.contractInitChild(idText(f.name), wCtx)}(${["__tact_context_sys", ...f.args.map((a, i) => writeCastedExpression(a, type.init!.params[i].type, wCtx))].join(", ")})`; + const type = getType(wCtx.ctx, f.contract); + return `${ops.contractInitChild(idText(f.contract), wCtx)}(${["__tact_context_sys", ...f.args.map((a, i) => writeCastedExpression(a, type.init!.params[i].type, wCtx))].join(", ")})`; } // diff --git a/src/generator/writers/writeFunction.ts b/src/generator/writers/writeFunction.ts index 84b60ba7e..5a9013f31 100644 --- a/src/generator/writers/writeFunction.ts +++ b/src/generator/writers/writeFunction.ts @@ -1,9 +1,9 @@ import { enabledInline } from "../../config/features"; import { - ASTCondition, - ASTExpression, + AstCondition, + AstExpression, AstNativeFunctionDecl, - ASTStatement, + AstStatement, idText, isWildcard, tryExtractPath, @@ -25,7 +25,7 @@ import { freshIdentifier } from "./freshIdentifier"; import { idTextErr, throwInternalCompilerError } from "../../errors"; export function writeCastedExpression( - expression: ASTExpression, + expression: AstExpression, to: TypeRef, ctx: WriterContext, ) { @@ -69,7 +69,7 @@ export function unwrapExternal( } export function writeStatement( - f: ASTStatement, + f: AstStatement, self: string | null, returns: TypeRef | null, ctx: WriterContext, @@ -443,14 +443,14 @@ export function writeStatement( } function writeCondition( - f: ASTCondition, + f: AstCondition, self: string | null, elseif: boolean, returns: TypeRef | null, ctx: WriterContext, ) { ctx.append( - `${elseif ? "} else" : ""}if (${writeExpression(f.expression, ctx)}) {`, + `${elseif ? "} else" : ""}if (${writeExpression(f.condition, ctx)}) {`, ); ctx.inIndent(() => { for (const s of f.trueStatements) { diff --git a/src/grammar/__snapshots__/grammar.spec.ts.snap b/src/grammar/__snapshots__/grammar.spec.ts.snap index dff43bf15..502cb787b 100644 --- a/src/grammar/__snapshots__/grammar.spec.ts.snap +++ b/src/grammar/__snapshots__/grammar.spec.ts.snap @@ -376,7 +376,7 @@ Line 1, col 8: exports[`grammar should parse abstract-const 1`] = ` { - "id": 7, + "id": 6, "imports": [], "items": [ { @@ -389,7 +389,7 @@ exports[`grammar should parse abstract-const 1`] = ` "type": "abstract", }, ], - "id": 5, + "id": 4, "kind": "constant_decl", "loc": abstract const c: Int;, "name": { @@ -399,20 +399,14 @@ exports[`grammar should parse abstract-const 1`] = ` "text": "c", }, "type": { - "id": 4, - "kind": "type_ref_simple", + "id": 3, + "kind": "type_id", "loc": Int, - "name": { - "id": 3, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 6, + "id": 5, "kind": "trait", "loc": trait t { abstract const c: Int; @@ -432,7 +426,7 @@ exports[`grammar should parse abstract-const 1`] = ` exports[`grammar should parse contract-with-const-override 1`] = ` { - "id": 8, + "id": 7, "imports": [], "items": [ { @@ -445,9 +439,9 @@ exports[`grammar should parse contract-with-const-override 1`] = ` "type": "overrides", }, ], - "id": 6, + "id": 5, "initializer": { - "id": 5, + "id": 4, "kind": "number", "loc": 0, "value": 0n, @@ -461,20 +455,14 @@ exports[`grammar should parse contract-with-const-override 1`] = ` "text": "Test", }, "type": { - "id": 4, - "kind": "type_ref_simple", + "id": 3, + "kind": "type_id", "loc": Int, - "name": { - "id": 3, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 7, + "id": 6, "kind": "contract", "loc": contract Contract { override const Test: Int = 0; @@ -537,7 +525,7 @@ exports[`grammar should parse contract-with-imports 1`] = ` exports[`grammar should parse contract-with-init 1`] = ` { - "id": 30, + "id": 26, "imports": [], "items": [ { @@ -545,9 +533,9 @@ exports[`grammar should parse contract-with-init 1`] = ` "declarations": [ { "as": null, - "id": 5, - "init": null, - "kind": "def_field", + "id": 4, + "initializer": null, + "kind": "field_decl", "loc": a: Int, "name": { "id": 2, @@ -556,159 +544,135 @@ exports[`grammar should parse contract-with-init 1`] = ` "text": "a", }, "type": { - "id": 4, - "kind": "type_ref_simple", + "id": 3, + "kind": "type_id", "loc": Int, - "name": { - "id": 3, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 9, - "init": null, - "kind": "def_field", + "id": 7, + "initializer": null, + "kind": "field_decl", "loc": b: Int, "name": { - "id": 6, + "id": 5, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 8, - "kind": "type_ref_simple", + "id": 6, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { - "id": 28, - "kind": "def_init_function", + "id": 24, + "kind": "contract_init", "loc": init(a: Int, b: Int) { self.a = a; self.b = b; }, "params": [ { - "id": 13, + "id": 10, "kind": "typed_parameter", "loc": a: Int, "name": { - "id": 10, + "id": 8, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 12, - "kind": "type_ref_simple", + "id": 9, + "kind": "type_id", "loc": Int, - "name": { - "id": 11, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { - "id": 17, + "id": 13, "kind": "typed_parameter", "loc": b: Int, "name": { - "id": 14, + "id": 11, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 16, - "kind": "type_ref_simple", + "id": 12, + "kind": "type_id", "loc": Int, - "name": { - "id": 15, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], "statements": [ { "expression": { - "id": 21, + "id": 17, "kind": "id", "loc": a, "text": "a", }, - "id": 22, + "id": 18, "kind": "statement_assign", "loc": self.a = a;, "path": { - "id": 20, - "kind": "op_field", - "loc": self.a, - "name": { - "id": 19, - "kind": "id", - "loc": a, - "text": "a", - }, - "src": { - "id": 18, + "aggregate": { + "id": 14, "kind": "id", "loc": self, "text": "self", }, + "field": { + "id": 15, + "kind": "id", + "loc": a, + "text": "a", + }, + "id": 16, + "kind": "field_access", + "loc": self.a, }, }, { "expression": { - "id": 26, + "id": 22, "kind": "id", "loc": b, "text": "b", }, - "id": 27, + "id": 23, "kind": "statement_assign", "loc": self.b = b;, "path": { - "id": 25, - "kind": "op_field", - "loc": self.b, - "name": { - "id": 24, - "kind": "id", - "loc": b, - "text": "b", - }, - "src": { - "id": 23, + "aggregate": { + "id": 19, "kind": "id", "loc": self, "text": "self", }, + "field": { + "id": 20, + "kind": "id", + "loc": b, + "text": "b", + }, + "id": 21, + "kind": "field_access", + "loc": self.b, }, }, ], }, ], - "id": 29, + "id": 25, "kind": "contract", "loc": contract Sample { a: Int; @@ -734,7 +698,7 @@ exports[`grammar should parse contract-with-init 1`] = ` exports[`grammar should parse contract-with-trait 1`] = ` { - "id": 28, + "id": 24, "imports": [], "items": [ { @@ -743,7 +707,7 @@ exports[`grammar should parse contract-with-trait 1`] = ` "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -753,9 +717,9 @@ exports[`grammar should parse contract-with-trait 1`] = ` "declarations": [ { "as": null, - "id": 7, - "init": null, - "kind": "def_field", + "id": 6, + "initializer": null, + "kind": "field_decl", "loc": a: Int, "name": { "id": 4, @@ -764,16 +728,10 @@ exports[`grammar should parse contract-with-trait 1`] = ` "text": "a", }, "type": { - "id": 6, - "kind": "type_ref_simple", + "id": 5, + "kind": "type_id", "loc": Int, - "name": { - "id": 5, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { @@ -783,46 +741,40 @@ exports[`grammar should parse contract-with-trait 1`] = ` "type": "virtual", }, ], - "id": 13, + "id": 11, "kind": "function_def", "loc": virtual fun a(): Int { return a; }, "name": { - "id": 8, + "id": 7, "kind": "id", "loc": a, "text": "a", }, "params": [], "return": { - "id": 10, - "kind": "type_ref_simple", + "id": 8, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 11, + "id": 9, "kind": "id", "loc": a, "text": "a", }, - "id": 12, + "id": 10, "kind": "statement_return", "loc": return a;, }, ], }, ], - "id": 14, + "id": 12, "kind": "trait", "loc": trait SomeTrait { a: Int; @@ -844,27 +796,21 @@ exports[`grammar should parse contract-with-trait 1`] = ` "declarations": [ { "as": null, - "id": 19, - "init": null, - "kind": "def_field", + "id": 16, + "initializer": null, + "kind": "field_decl", "loc": b: Int, "name": { - "id": 16, + "id": 14, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 18, - "kind": "type_ref_simple", + "id": 15, + "kind": "type_id", "loc": Int, - "name": { - "id": 17, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { @@ -874,46 +820,40 @@ exports[`grammar should parse contract-with-trait 1`] = ` "type": "overrides", }, ], - "id": 25, + "id": 21, "kind": "function_def", "loc": override fun a(): Int { return b; }, "name": { - "id": 20, + "id": 17, "kind": "id", "loc": a, "text": "a", }, "params": [], "return": { - "id": 22, - "kind": "type_ref_simple", + "id": 18, + "kind": "type_id", "loc": Int, - "name": { - "id": 21, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 23, + "id": 19, "kind": "id", "loc": b, "text": "b", }, - "id": 24, + "id": 20, "kind": "statement_return", "loc": return b;, }, ], }, ], - "id": 27, + "id": 23, "kind": "contract", "loc": contract Main with SomeTrait { b: Int; @@ -923,14 +863,14 @@ exports[`grammar should parse contract-with-trait 1`] = ` } }, "name": { - "id": 15, + "id": 13, "kind": "id", "loc": Main, "text": "Main", }, "traits": [ { - "id": 26, + "id": 22, "kind": "id", "loc": SomeTrait, "text": "SomeTrait", @@ -944,7 +884,7 @@ exports[`grammar should parse contract-with-trait 1`] = ` exports[`grammar should parse contract-with-trait-string-literal 1`] = ` { - "id": 28, + "id": 24, "imports": [], "items": [ { @@ -953,7 +893,7 @@ exports[`grammar should parse contract-with-trait-string-literal 1`] = ` "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -963,9 +903,9 @@ exports[`grammar should parse contract-with-trait-string-literal 1`] = ` "declarations": [ { "as": null, - "id": 7, - "init": null, - "kind": "def_field", + "id": 6, + "initializer": null, + "kind": "field_decl", "loc": a: Int, "name": { "id": 4, @@ -974,16 +914,10 @@ exports[`grammar should parse contract-with-trait-string-literal 1`] = ` "text": "a", }, "type": { - "id": 6, - "kind": "type_ref_simple", + "id": 5, + "kind": "type_id", "loc": Int, - "name": { - "id": 5, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { @@ -993,46 +927,40 @@ exports[`grammar should parse contract-with-trait-string-literal 1`] = ` "type": "virtual", }, ], - "id": 13, + "id": 11, "kind": "function_def", "loc": virtual fun a(): Int { return a; }, "name": { - "id": 8, + "id": 7, "kind": "id", "loc": a, "text": "a", }, "params": [], "return": { - "id": 10, - "kind": "type_ref_simple", + "id": 8, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 11, + "id": 9, "kind": "id", "loc": a, "text": "a", }, - "id": 12, + "id": 10, "kind": "statement_return", "loc": return a;, }, ], }, ], - "id": 14, + "id": 12, "kind": "trait", "loc": trait SomeTrait { a: Int; @@ -1054,27 +982,21 @@ exports[`grammar should parse contract-with-trait-string-literal 1`] = ` "declarations": [ { "as": null, - "id": 19, - "init": null, - "kind": "def_field", + "id": 16, + "initializer": null, + "kind": "field_decl", "loc": b: Int, "name": { - "id": 16, + "id": 14, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 18, - "kind": "type_ref_simple", + "id": 15, + "kind": "type_id", "loc": Int, - "name": { - "id": 17, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { @@ -1084,46 +1006,40 @@ exports[`grammar should parse contract-with-trait-string-literal 1`] = ` "type": "overrides", }, ], - "id": 25, + "id": 21, "kind": "function_def", "loc": override fun a(): Int { return "hello world!"; }, "name": { - "id": 20, + "id": 17, "kind": "id", "loc": a, "text": "a", }, "params": [], "return": { - "id": 22, - "kind": "type_ref_simple", + "id": 18, + "kind": "type_id", "loc": Int, - "name": { - "id": 21, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 23, + "id": 19, "kind": "string", "loc": "hello world!", "value": "hello world!", }, - "id": 24, + "id": 20, "kind": "statement_return", "loc": return "hello world!";, }, ], }, ], - "id": 27, + "id": 23, "kind": "contract", "loc": contract Main with SomeTrait { b: Int; @@ -1133,14 +1049,14 @@ exports[`grammar should parse contract-with-trait-string-literal 1`] = ` } }, "name": { - "id": 15, + "id": 13, "kind": "id", "loc": Main, "text": "Main", }, "traits": [ { - "id": 26, + "id": 22, "kind": "id", "loc": SomeTrait, "text": "SomeTrait", @@ -1154,12 +1070,12 @@ exports[`grammar should parse contract-with-trait-string-literal 1`] = ` exports[`grammar should parse expr-arith 1`] = ` { - "id": 13, + "id": 12, "imports": [], "items": [ { "attributes": [], - "id": 12, + "id": 11, "kind": "function_def", "loc": fun testFunc(): Int { return (0 + 1) * 10 / 20; @@ -1172,30 +1088,24 @@ exports[`grammar should parse expr-arith 1`] = ` }, "params": [], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 10, + "id": 9, "kind": "op_binary", "left": { - "id": 8, + "id": 7, "kind": "op_binary", "left": { - "id": 6, + "id": 5, "kind": "op_binary", "left": { - "id": 4, + "id": 3, "kind": "number", "loc": 0, "value": 0n, @@ -1203,7 +1113,7 @@ exports[`grammar should parse expr-arith 1`] = ` "loc": 0 + 1, "op": "+", "right": { - "id": 5, + "id": 4, "kind": "number", "loc": 1, "value": 1n, @@ -1212,7 +1122,7 @@ exports[`grammar should parse expr-arith 1`] = ` "loc": (0 + 1) * 10, "op": "*", "right": { - "id": 7, + "id": 6, "kind": "number", "loc": 10, "value": 10n, @@ -1221,13 +1131,13 @@ exports[`grammar should parse expr-arith 1`] = ` "loc": (0 + 1) * 10 / 20, "op": "/", "right": { - "id": 9, + "id": 8, "kind": "number", "loc": 20, "value": 20n, }, }, - "id": 11, + "id": 10, "kind": "statement_return", "loc": return (0 + 1) * 10 / 20;, }, @@ -1240,12 +1150,12 @@ exports[`grammar should parse expr-arith 1`] = ` exports[`grammar should parse expr-arith-and-cmp 1`] = ` { - "id": 15, + "id": 14, "imports": [], "items": [ { "attributes": [], - "id": 14, + "id": 13, "kind": "function_def", "loc": fun testFunc(): Int { return (0 + 1) * 10 / 20 != 10; @@ -1258,33 +1168,27 @@ exports[`grammar should parse expr-arith-and-cmp 1`] = ` }, "params": [], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 12, + "id": 11, "kind": "op_binary", "left": { - "id": 10, + "id": 9, "kind": "op_binary", "left": { - "id": 8, + "id": 7, "kind": "op_binary", "left": { - "id": 6, + "id": 5, "kind": "op_binary", "left": { - "id": 4, + "id": 3, "kind": "number", "loc": 0, "value": 0n, @@ -1292,7 +1196,7 @@ exports[`grammar should parse expr-arith-and-cmp 1`] = ` "loc": 0 + 1, "op": "+", "right": { - "id": 5, + "id": 4, "kind": "number", "loc": 1, "value": 1n, @@ -1301,7 +1205,7 @@ exports[`grammar should parse expr-arith-and-cmp 1`] = ` "loc": (0 + 1) * 10, "op": "*", "right": { - "id": 7, + "id": 6, "kind": "number", "loc": 10, "value": 10n, @@ -1310,7 +1214,7 @@ exports[`grammar should parse expr-arith-and-cmp 1`] = ` "loc": (0 + 1) * 10 / 20, "op": "/", "right": { - "id": 9, + "id": 8, "kind": "number", "loc": 20, "value": 20n, @@ -1319,13 +1223,13 @@ exports[`grammar should parse expr-arith-and-cmp 1`] = ` "loc": (0 + 1) * 10 / 20 != 10, "op": "!=", "right": { - "id": 11, + "id": 10, "kind": "number", "loc": 10, "value": 10n, }, }, - "id": 13, + "id": 12, "kind": "statement_return", "loc": return (0 + 1) * 10 / 20 != 10;, }, @@ -1338,12 +1242,12 @@ exports[`grammar should parse expr-arith-and-cmp 1`] = ` exports[`grammar should parse expr-arith-bool-cmp-method-call 1`] = ` { - "id": 28, + "id": 27, "imports": [], "items": [ { "attributes": [], - "id": 27, + "id": 26, "kind": "function_def", "loc": fun testFunc(): Int { return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 123.add(10); @@ -1356,36 +1260,30 @@ exports[`grammar should parse expr-arith-bool-cmp-method-call 1`] = ` }, "params": [], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 25, + "id": 24, "kind": "op_binary", "left": { - "id": 14, + "id": 13, "kind": "op_binary", "left": { - "id": 10, + "id": 9, "kind": "op_binary", "left": { - "id": 8, + "id": 7, "kind": "op_binary", "left": { - "id": 6, + "id": 5, "kind": "op_binary", "left": { - "id": 4, + "id": 3, "kind": "number", "loc": 0, "value": 0n, @@ -1393,7 +1291,7 @@ exports[`grammar should parse expr-arith-bool-cmp-method-call 1`] = ` "loc": 0 + 1, "op": "+", "right": { - "id": 5, + "id": 4, "kind": "number", "loc": 1, "value": 1n, @@ -1402,7 +1300,7 @@ exports[`grammar should parse expr-arith-bool-cmp-method-call 1`] = ` "loc": (0 + 1) * 10, "op": "*", "right": { - "id": 7, + "id": 6, "kind": "number", "loc": 10, "value": 10n, @@ -1411,7 +1309,7 @@ exports[`grammar should parse expr-arith-bool-cmp-method-call 1`] = ` "loc": (0 + 1) * 10 / 20, "op": "/", "right": { - "id": 9, + "id": 8, "kind": "number", "loc": 20, "value": 20n, @@ -1420,10 +1318,10 @@ exports[`grammar should parse expr-arith-bool-cmp-method-call 1`] = ` "loc": (0 + 1) * 10 / 20 != 10 * someId, "op": "!=", "right": { - "id": 13, + "id": 12, "kind": "op_binary", "left": { - "id": 11, + "id": 10, "kind": "number", "loc": 10, "value": 10n, @@ -1431,7 +1329,7 @@ exports[`grammar should parse expr-arith-bool-cmp-method-call 1`] = ` "loc": 10 * someId, "op": "*", "right": { - "id": 12, + "id": 11, "kind": "id", "loc": someId, "text": "someId", @@ -1441,13 +1339,13 @@ exports[`grammar should parse expr-arith-bool-cmp-method-call 1`] = ` "loc": (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 123.add(10), "op": "||", "right": { - "id": 24, + "id": 23, "kind": "op_binary", "left": { - "id": 17, + "id": 16, "kind": "op_binary", "left": { - "id": 15, + "id": 14, "kind": "id", "loc": some2, "text": "some2", @@ -1455,7 +1353,7 @@ exports[`grammar should parse expr-arith-bool-cmp-method-call 1`] = ` "loc": some2 > 10, "op": ">", "right": { - "id": 16, + "id": 15, "kind": "number", "loc": 10, "value": 10n, @@ -1464,10 +1362,10 @@ exports[`grammar should parse expr-arith-bool-cmp-method-call 1`] = ` "loc": some2 > 10 && some3 < 123.add(10), "op": "&&", "right": { - "id": 23, + "id": 22, "kind": "op_binary", "left": { - "id": 18, + "id": 17, "kind": "id", "loc": some3, "text": "some3", @@ -1477,23 +1375,23 @@ exports[`grammar should parse expr-arith-bool-cmp-method-call 1`] = ` "right": { "args": [ { - "id": 21, + "id": 20, "kind": "number", "loc": 10, "value": 10n, }, ], - "id": 22, - "kind": "op_call", + "id": 21, + "kind": "method_call", "loc": 123.add(10), - "name": { - "id": 20, + "method": { + "id": 19, "kind": "id", "loc": add, "text": "add", }, - "src": { - "id": 19, + "self": { + "id": 18, "kind": "number", "loc": 123, "value": 123n, @@ -1502,7 +1400,7 @@ exports[`grammar should parse expr-arith-bool-cmp-method-call 1`] = ` }, }, }, - "id": 26, + "id": 25, "kind": "statement_return", "loc": return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 123.add(10);, }, @@ -1515,12 +1413,12 @@ exports[`grammar should parse expr-arith-bool-cmp-method-call 1`] = ` exports[`grammar should parse expr-arith-bool-var 1`] = ` { - "id": 25, + "id": 24, "imports": [], "items": [ { "attributes": [], - "id": 24, + "id": 23, "kind": "function_def", "loc": fun testFunc(): Int { return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 10; @@ -1533,36 +1431,30 @@ exports[`grammar should parse expr-arith-bool-var 1`] = ` }, "params": [], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 22, + "id": 21, "kind": "op_binary", "left": { - "id": 14, + "id": 13, "kind": "op_binary", "left": { - "id": 10, + "id": 9, "kind": "op_binary", "left": { - "id": 8, + "id": 7, "kind": "op_binary", "left": { - "id": 6, + "id": 5, "kind": "op_binary", "left": { - "id": 4, + "id": 3, "kind": "number", "loc": 0, "value": 0n, @@ -1570,7 +1462,7 @@ exports[`grammar should parse expr-arith-bool-var 1`] = ` "loc": 0 + 1, "op": "+", "right": { - "id": 5, + "id": 4, "kind": "number", "loc": 1, "value": 1n, @@ -1579,7 +1471,7 @@ exports[`grammar should parse expr-arith-bool-var 1`] = ` "loc": (0 + 1) * 10, "op": "*", "right": { - "id": 7, + "id": 6, "kind": "number", "loc": 10, "value": 10n, @@ -1588,7 +1480,7 @@ exports[`grammar should parse expr-arith-bool-var 1`] = ` "loc": (0 + 1) * 10 / 20, "op": "/", "right": { - "id": 9, + "id": 8, "kind": "number", "loc": 20, "value": 20n, @@ -1597,10 +1489,10 @@ exports[`grammar should parse expr-arith-bool-var 1`] = ` "loc": (0 + 1) * 10 / 20 != 10 * someId, "op": "!=", "right": { - "id": 13, + "id": 12, "kind": "op_binary", "left": { - "id": 11, + "id": 10, "kind": "number", "loc": 10, "value": 10n, @@ -1608,7 +1500,7 @@ exports[`grammar should parse expr-arith-bool-var 1`] = ` "loc": 10 * someId, "op": "*", "right": { - "id": 12, + "id": 11, "kind": "id", "loc": someId, "text": "someId", @@ -1618,13 +1510,13 @@ exports[`grammar should parse expr-arith-bool-var 1`] = ` "loc": (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 10, "op": "||", "right": { - "id": 21, + "id": 20, "kind": "op_binary", "left": { - "id": 17, + "id": 16, "kind": "op_binary", "left": { - "id": 15, + "id": 14, "kind": "id", "loc": some2, "text": "some2", @@ -1632,7 +1524,7 @@ exports[`grammar should parse expr-arith-bool-var 1`] = ` "loc": some2 > 10, "op": ">", "right": { - "id": 16, + "id": 15, "kind": "number", "loc": 10, "value": 10n, @@ -1641,10 +1533,10 @@ exports[`grammar should parse expr-arith-bool-var 1`] = ` "loc": some2 > 10 && some3 < 10, "op": "&&", "right": { - "id": 20, + "id": 19, "kind": "op_binary", "left": { - "id": 18, + "id": 17, "kind": "id", "loc": some3, "text": "some3", @@ -1652,7 +1544,7 @@ exports[`grammar should parse expr-arith-bool-var 1`] = ` "loc": some3 < 10, "op": "<", "right": { - "id": 19, + "id": 18, "kind": "number", "loc": 10, "value": 10n, @@ -1660,7 +1552,7 @@ exports[`grammar should parse expr-arith-bool-var 1`] = ` }, }, }, - "id": 23, + "id": 22, "kind": "statement_return", "loc": return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 10;, }, @@ -1673,12 +1565,12 @@ exports[`grammar should parse expr-arith-bool-var 1`] = ` exports[`grammar should parse expr-chaining-unbox 1`] = ` { - "id": 17, + "id": 16, "imports": [], "items": [ { "attributes": [], - "id": 16, + "id": 15, "kind": "function_def", "loc": fun testFunc(m: map): Int { return m.asCell()!!.hash(); @@ -1691,79 +1583,73 @@ exports[`grammar should parse expr-chaining-unbox 1`] = ` }, "params": [ { - "id": 8, + "id": 7, "kind": "typed_parameter", "loc": m: map, "name": { - "id": 4, + "id": 3, "kind": "id", "loc": m, "text": "m", }, "type": { - "id": 7, - "key": { - "id": 5, - "kind": "id", + "id": 6, + "keyStorageType": null, + "keyType": { + "id": 4, + "kind": "type_id", "loc": Int, "text": "Int", }, - "keyAs": null, - "kind": "type_ref_map", + "kind": "map_type", "loc": map, - "value": { - "id": 6, - "kind": "id", + "valueStorageType": null, + "valueType": { + "id": 5, + "kind": "type_id", "loc": Int, "text": "Int", }, - "valueAs": null, }, }, ], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { "args": [], - "id": 14, - "kind": "op_call", + "id": 13, + "kind": "method_call", "loc": m.asCell()!!.hash(), - "name": { - "id": 13, + "method": { + "id": 12, "kind": "id", "loc": hash, "text": "hash", }, - "src": { - "id": 12, + "self": { + "id": 11, "kind": "op_unary", "loc": m.asCell()!!, "op": "!!", - "right": { + "operand": { "args": [], - "id": 11, - "kind": "op_call", + "id": 10, + "kind": "method_call", "loc": m.asCell(), - "name": { - "id": 10, + "method": { + "id": 9, "kind": "id", "loc": asCell, "text": "asCell", }, - "src": { - "id": 9, + "self": { + "id": 8, "kind": "id", "loc": m, "text": "m", @@ -1771,7 +1657,7 @@ exports[`grammar should parse expr-chaining-unbox 1`] = ` }, }, }, - "id": 15, + "id": 14, "kind": "statement_return", "loc": return m.asCell()!!.hash();, }, @@ -1784,12 +1670,12 @@ exports[`grammar should parse expr-chaining-unbox 1`] = ` exports[`grammar should parse expr-condition-with-or 1`] = ` { - "id": 24, + "id": 22, "imports": [], "items": [ { "attributes": [], - "id": 23, + "id": 21, "kind": "function_def", "loc": fun testFunc(a: Int): Int { return a == 123 || a == 456 ? a + 1 : a + 2; @@ -1802,52 +1688,40 @@ exports[`grammar should parse expr-condition-with-or 1`] = ` }, "params": [ { - "id": 7, + "id": 5, "kind": "typed_parameter", "loc": a: Int, "name": { - "id": 4, + "id": 3, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 6, - "kind": "type_ref_simple", + "id": 4, + "kind": "type_id", "loc": Int, - "name": { - "id": 5, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { "condition": { - "id": 14, + "id": 12, "kind": "op_binary", "left": { - "id": 10, + "id": 8, "kind": "op_binary", "left": { - "id": 8, + "id": 6, "kind": "id", "loc": a, "text": "a", @@ -1855,7 +1729,7 @@ exports[`grammar should parse expr-condition-with-or 1`] = ` "loc": a == 123, "op": "==", "right": { - "id": 9, + "id": 7, "kind": "number", "loc": 123, "value": 123n, @@ -1864,10 +1738,10 @@ exports[`grammar should parse expr-condition-with-or 1`] = ` "loc": a == 123 || a == 456, "op": "||", "right": { - "id": 13, + "id": 11, "kind": "op_binary", "left": { - "id": 11, + "id": 9, "kind": "id", "loc": a, "text": "a", @@ -1875,7 +1749,7 @@ exports[`grammar should parse expr-condition-with-or 1`] = ` "loc": a == 456, "op": "==", "right": { - "id": 12, + "id": 10, "kind": "number", "loc": 456, "value": 456n, @@ -1883,10 +1757,10 @@ exports[`grammar should parse expr-condition-with-or 1`] = ` }, }, "elseBranch": { - "id": 20, + "id": 18, "kind": "op_binary", "left": { - "id": 18, + "id": 16, "kind": "id", "loc": a, "text": "a", @@ -1894,20 +1768,20 @@ exports[`grammar should parse expr-condition-with-or 1`] = ` "loc": a + 2, "op": "+", "right": { - "id": 19, + "id": 17, "kind": "number", "loc": 2, "value": 2n, }, }, - "id": 21, + "id": 19, "kind": "conditional", "loc": a == 123 || a == 456 ? a + 1 : a + 2, "thenBranch": { - "id": 17, + "id": 15, "kind": "op_binary", "left": { - "id": 15, + "id": 13, "kind": "id", "loc": a, "text": "a", @@ -1915,14 +1789,14 @@ exports[`grammar should parse expr-condition-with-or 1`] = ` "loc": a + 1, "op": "+", "right": { - "id": 16, + "id": 14, "kind": "number", "loc": 1, "value": 1n, }, }, }, - "id": 22, + "id": 20, "kind": "statement_return", "loc": return a == 123 || a == 456 ? a + 1 : a + 2;, }, @@ -1935,12 +1809,12 @@ exports[`grammar should parse expr-condition-with-or 1`] = ` exports[`grammar should parse expr-conditional 1`] = ` { - "id": 16, + "id": 14, "imports": [], "items": [ { "attributes": [], - "id": 15, + "id": 13, "kind": "function_def", "loc": fun testFunc(a: Int): Int { return a == 123 ? 1 : 2; @@ -1953,49 +1827,37 @@ exports[`grammar should parse expr-conditional 1`] = ` }, "params": [ { - "id": 7, + "id": 5, "kind": "typed_parameter", "loc": a: Int, "name": { - "id": 4, + "id": 3, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 6, - "kind": "type_ref_simple", + "id": 4, + "kind": "type_id", "loc": Int, - "name": { - "id": 5, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { "condition": { - "id": 10, + "id": 8, "kind": "op_binary", "left": { - "id": 8, + "id": 6, "kind": "id", "loc": a, "text": "a", @@ -2003,29 +1865,29 @@ exports[`grammar should parse expr-conditional 1`] = ` "loc": a == 123, "op": "==", "right": { - "id": 9, + "id": 7, "kind": "number", "loc": 123, "value": 123n, }, }, "elseBranch": { - "id": 12, + "id": 10, "kind": "number", "loc": 2, "value": 2n, }, - "id": 13, + "id": 11, "kind": "conditional", "loc": a == 123 ? 1 : 2, "thenBranch": { - "id": 11, + "id": 9, "kind": "number", "loc": 1, "value": 1n, }, }, - "id": 14, + "id": 12, "kind": "statement_return", "loc": return a == 123 ? 1 : 2;, }, @@ -2038,12 +1900,12 @@ exports[`grammar should parse expr-conditional 1`] = ` exports[`grammar should parse expr-conditional-with-let 1`] = ` { - "id": 21, + "id": 18, "imports": [], "items": [ { "attributes": [], - "id": 20, + "id": 17, "kind": "function_def", "loc": fun testFunc(a: Int): Int { let b: Int = a == 123 ? 1 : 2; @@ -2057,49 +1919,37 @@ exports[`grammar should parse expr-conditional-with-let 1`] = ` }, "params": [ { - "id": 7, + "id": 5, "kind": "typed_parameter", "loc": a: Int, "name": { - "id": 4, + "id": 3, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 6, - "kind": "type_ref_simple", + "id": 4, + "kind": "type_id", "loc": Int, - "name": { - "id": 5, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { "condition": { - "id": 13, + "id": 10, "kind": "op_binary", "left": { - "id": 11, + "id": 8, "kind": "id", "loc": a, "text": "a", @@ -2107,58 +1957,52 @@ exports[`grammar should parse expr-conditional-with-let 1`] = ` "loc": a == 123, "op": "==", "right": { - "id": 12, + "id": 9, "kind": "number", "loc": 123, "value": 123n, }, }, "elseBranch": { - "id": 15, + "id": 12, "kind": "number", "loc": 2, "value": 2n, }, - "id": 16, + "id": 13, "kind": "conditional", "loc": a == 123 ? 1 : 2, "thenBranch": { - "id": 14, + "id": 11, "kind": "number", "loc": 1, "value": 1n, }, }, - "id": 17, + "id": 14, "kind": "statement_let", "loc": let b: Int = a == 123 ? 1 : 2;, "name": { - "id": 8, + "id": 6, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 10, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 18, + "id": 15, "kind": "id", "loc": b, "text": "b", }, - "id": 19, + "id": 16, "kind": "statement_return", "loc": return b;, }, @@ -2171,12 +2015,12 @@ exports[`grammar should parse expr-conditional-with-let 1`] = ` exports[`grammar should parse expr-fun-call 1`] = ` { - "id": 30, + "id": 29, "imports": [], "items": [ { "attributes": [], - "id": 29, + "id": 28, "kind": "function_def", "loc": fun testFunc(): Int { return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < abs(123.add(10)); @@ -2189,36 +2033,30 @@ exports[`grammar should parse expr-fun-call 1`] = ` }, "params": [], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 27, + "id": 26, "kind": "op_binary", "left": { - "id": 14, + "id": 13, "kind": "op_binary", "left": { - "id": 10, + "id": 9, "kind": "op_binary", "left": { - "id": 8, + "id": 7, "kind": "op_binary", "left": { - "id": 6, + "id": 5, "kind": "op_binary", "left": { - "id": 4, + "id": 3, "kind": "number", "loc": 0, "value": 0n, @@ -2226,7 +2064,7 @@ exports[`grammar should parse expr-fun-call 1`] = ` "loc": 0 + 1, "op": "+", "right": { - "id": 5, + "id": 4, "kind": "number", "loc": 1, "value": 1n, @@ -2235,7 +2073,7 @@ exports[`grammar should parse expr-fun-call 1`] = ` "loc": (0 + 1) * 10, "op": "*", "right": { - "id": 7, + "id": 6, "kind": "number", "loc": 10, "value": 10n, @@ -2244,7 +2082,7 @@ exports[`grammar should parse expr-fun-call 1`] = ` "loc": (0 + 1) * 10 / 20, "op": "/", "right": { - "id": 9, + "id": 8, "kind": "number", "loc": 20, "value": 20n, @@ -2253,10 +2091,10 @@ exports[`grammar should parse expr-fun-call 1`] = ` "loc": (0 + 1) * 10 / 20 != 10 * someId, "op": "!=", "right": { - "id": 13, + "id": 12, "kind": "op_binary", "left": { - "id": 11, + "id": 10, "kind": "number", "loc": 10, "value": 10n, @@ -2264,7 +2102,7 @@ exports[`grammar should parse expr-fun-call 1`] = ` "loc": 10 * someId, "op": "*", "right": { - "id": 12, + "id": 11, "kind": "id", "loc": someId, "text": "someId", @@ -2274,13 +2112,13 @@ exports[`grammar should parse expr-fun-call 1`] = ` "loc": (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < abs(123.add(10)), "op": "||", "right": { - "id": 26, + "id": 25, "kind": "op_binary", "left": { - "id": 17, + "id": 16, "kind": "op_binary", "left": { - "id": 15, + "id": 14, "kind": "id", "loc": some2, "text": "some2", @@ -2288,7 +2126,7 @@ exports[`grammar should parse expr-fun-call 1`] = ` "loc": some2 > 10, "op": ">", "right": { - "id": 16, + "id": 15, "kind": "number", "loc": 10, "value": 10n, @@ -2297,10 +2135,10 @@ exports[`grammar should parse expr-fun-call 1`] = ` "loc": some2 > 10 && some3 < abs(123.add(10)), "op": "&&", "right": { - "id": 25, + "id": 24, "kind": "op_binary", "left": { - "id": 18, + "id": 17, "kind": "id", "loc": some3, "text": "some3", @@ -2312,43 +2150,43 @@ exports[`grammar should parse expr-fun-call 1`] = ` { "args": [ { - "id": 22, + "id": 21, "kind": "number", "loc": 10, "value": 10n, }, ], - "id": 23, - "kind": "op_call", + "id": 22, + "kind": "method_call", "loc": 123.add(10), - "name": { - "id": 21, + "method": { + "id": 20, "kind": "id", "loc": add, "text": "add", }, - "src": { - "id": 20, + "self": { + "id": 19, "kind": "number", "loc": 123, "value": 123n, }, }, ], - "id": 24, - "kind": "op_static_call", - "loc": abs(123.add(10)), - "name": { - "id": 19, + "function": { + "id": 18, "kind": "id", "loc": abs, "text": "abs", }, + "id": 23, + "kind": "static_call", + "loc": abs(123.add(10)), }, }, }, }, - "id": 28, + "id": 27, "kind": "statement_return", "loc": return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < abs(123.add(10));, }, @@ -2361,12 +2199,12 @@ exports[`grammar should parse expr-fun-call 1`] = ` exports[`grammar should parse expr-int-literal 1`] = ` { - "id": 7, + "id": 6, "imports": [], "items": [ { "attributes": [], - "id": 6, + "id": 5, "kind": "function_def", "loc": fun testFunc(): Int { return 0; @@ -2379,26 +2217,20 @@ exports[`grammar should parse expr-int-literal 1`] = ` }, "params": [], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 4, + "id": 3, "kind": "number", "loc": 0, "value": 0n, }, - "id": 5, + "id": 4, "kind": "statement_return", "loc": return 0;, }, @@ -2411,12 +2243,12 @@ exports[`grammar should parse expr-int-literal 1`] = ` exports[`grammar should parse expr-nested-conditional 1`] = ` { - "id": 29, + "id": 27, "imports": [], "items": [ { "attributes": [], - "id": 28, + "id": 26, "kind": "function_def", "loc": fun testFunc(a: Int): Int { return a == 123 || a == 456 ? (a == 10 ? a : a * 2) : a + 2; @@ -2429,52 +2261,40 @@ exports[`grammar should parse expr-nested-conditional 1`] = ` }, "params": [ { - "id": 7, + "id": 5, "kind": "typed_parameter", "loc": a: Int, "name": { - "id": 4, + "id": 3, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 6, - "kind": "type_ref_simple", + "id": 4, + "kind": "type_id", "loc": Int, - "name": { - "id": 5, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { "condition": { - "id": 14, + "id": 12, "kind": "op_binary", "left": { - "id": 10, + "id": 8, "kind": "op_binary", "left": { - "id": 8, + "id": 6, "kind": "id", "loc": a, "text": "a", @@ -2482,7 +2302,7 @@ exports[`grammar should parse expr-nested-conditional 1`] = ` "loc": a == 123, "op": "==", "right": { - "id": 9, + "id": 7, "kind": "number", "loc": 123, "value": 123n, @@ -2491,10 +2311,10 @@ exports[`grammar should parse expr-nested-conditional 1`] = ` "loc": a == 123 || a == 456, "op": "||", "right": { - "id": 13, + "id": 11, "kind": "op_binary", "left": { - "id": 11, + "id": 9, "kind": "id", "loc": a, "text": "a", @@ -2502,7 +2322,7 @@ exports[`grammar should parse expr-nested-conditional 1`] = ` "loc": a == 456, "op": "==", "right": { - "id": 12, + "id": 10, "kind": "number", "loc": 456, "value": 456n, @@ -2510,10 +2330,10 @@ exports[`grammar should parse expr-nested-conditional 1`] = ` }, }, "elseBranch": { - "id": 25, + "id": 23, "kind": "op_binary", "left": { - "id": 23, + "id": 21, "kind": "id", "loc": a, "text": "a", @@ -2521,21 +2341,21 @@ exports[`grammar should parse expr-nested-conditional 1`] = ` "loc": a + 2, "op": "+", "right": { - "id": 24, + "id": 22, "kind": "number", "loc": 2, "value": 2n, }, }, - "id": 26, + "id": 24, "kind": "conditional", "loc": a == 123 || a == 456 ? (a == 10 ? a : a * 2) : a + 2, "thenBranch": { "condition": { - "id": 17, + "id": 15, "kind": "op_binary", "left": { - "id": 15, + "id": 13, "kind": "id", "loc": a, "text": "a", @@ -2543,17 +2363,17 @@ exports[`grammar should parse expr-nested-conditional 1`] = ` "loc": a == 10, "op": "==", "right": { - "id": 16, + "id": 14, "kind": "number", "loc": 10, "value": 10n, }, }, "elseBranch": { - "id": 21, + "id": 19, "kind": "op_binary", "left": { - "id": 19, + "id": 17, "kind": "id", "loc": a, "text": "a", @@ -2561,24 +2381,24 @@ exports[`grammar should parse expr-nested-conditional 1`] = ` "loc": a * 2, "op": "*", "right": { - "id": 20, + "id": 18, "kind": "number", "loc": 2, "value": 2n, }, }, - "id": 22, + "id": 20, "kind": "conditional", "loc": a == 10 ? a : a * 2, "thenBranch": { - "id": 18, + "id": 16, "kind": "id", "loc": a, "text": "a", }, }, }, - "id": 27, + "id": 25, "kind": "statement_return", "loc": return a == 123 || a == 456 ? (a == 10 ? a : a * 2) : a + 2;, }, @@ -2591,12 +2411,12 @@ exports[`grammar should parse expr-nested-conditional 1`] = ` exports[`grammar should parse expr-parens 1`] = ` { - "id": 16, + "id": 15, "imports": [], "items": [ { "attributes": [], - "id": 15, + "id": 14, "kind": "function_def", "loc": fun testFunc(): Int { return 1 + 2 + (123 + 3)!! > 123; @@ -2609,30 +2429,24 @@ exports[`grammar should parse expr-parens 1`] = ` }, "params": [], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 13, + "id": 12, "kind": "op_binary", "left": { - "id": 11, + "id": 10, "kind": "op_binary", "left": { - "id": 6, + "id": 5, "kind": "op_binary", "left": { - "id": 4, + "id": 3, "kind": "number", "loc": 1, "value": 1n, @@ -2640,7 +2454,7 @@ exports[`grammar should parse expr-parens 1`] = ` "loc": 1 + 2, "op": "+", "right": { - "id": 5, + "id": 4, "kind": "number", "loc": 2, "value": 2n, @@ -2649,15 +2463,15 @@ exports[`grammar should parse expr-parens 1`] = ` "loc": 1 + 2 + (123 + 3)!!, "op": "+", "right": { - "id": 10, + "id": 9, "kind": "op_unary", "loc": (123 + 3)!!, "op": "!!", - "right": { - "id": 9, + "operand": { + "id": 8, "kind": "op_binary", "left": { - "id": 7, + "id": 6, "kind": "number", "loc": 123, "value": 123n, @@ -2665,7 +2479,7 @@ exports[`grammar should parse expr-parens 1`] = ` "loc": 123 + 3, "op": "+", "right": { - "id": 8, + "id": 7, "kind": "number", "loc": 3, "value": 3n, @@ -2676,13 +2490,13 @@ exports[`grammar should parse expr-parens 1`] = ` "loc": 1 + 2 + (123 + 3)!! > 123, "op": ">", "right": { - "id": 12, + "id": 11, "kind": "number", "loc": 123, "value": 123n, }, }, - "id": 14, + "id": 13, "kind": "statement_return", "loc": return 1 + 2 + (123 + 3)!! > 123;, }, @@ -2695,12 +2509,12 @@ exports[`grammar should parse expr-parens 1`] = ` exports[`grammar should parse expr-with-unbox 1`] = ` { - "id": 14, + "id": 13, "imports": [], "items": [ { "attributes": [], - "id": 13, + "id": 12, "kind": "function_def", "loc": fun testFunc(): Int { return 1 + 2 + 3!! > 123; @@ -2713,30 +2527,24 @@ exports[`grammar should parse expr-with-unbox 1`] = ` }, "params": [], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 11, + "id": 10, "kind": "op_binary", "left": { - "id": 9, + "id": 8, "kind": "op_binary", "left": { - "id": 6, + "id": 5, "kind": "op_binary", "left": { - "id": 4, + "id": 3, "kind": "number", "loc": 1, "value": 1n, @@ -2744,7 +2552,7 @@ exports[`grammar should parse expr-with-unbox 1`] = ` "loc": 1 + 2, "op": "+", "right": { - "id": 5, + "id": 4, "kind": "number", "loc": 2, "value": 2n, @@ -2753,12 +2561,12 @@ exports[`grammar should parse expr-with-unbox 1`] = ` "loc": 1 + 2 + 3!!, "op": "+", "right": { - "id": 8, + "id": 7, "kind": "op_unary", "loc": 3!!, "op": "!!", - "right": { - "id": 7, + "operand": { + "id": 6, "kind": "number", "loc": 3, "value": 3n, @@ -2768,13 +2576,13 @@ exports[`grammar should parse expr-with-unbox 1`] = ` "loc": 1 + 2 + 3!! > 123, "op": ">", "right": { - "id": 10, + "id": 9, "kind": "number", "loc": 123, "value": 123n, }, }, - "id": 12, + "id": 11, "kind": "statement_return", "loc": return 1 + 2 + 3!! > 123;, }, @@ -2787,12 +2595,12 @@ exports[`grammar should parse expr-with-unbox 1`] = ` exports[`grammar should parse expr-with-var 1`] = ` { - "id": 17, + "id": 16, "imports": [], "items": [ { "attributes": [], - "id": 16, + "id": 15, "kind": "function_def", "loc": fun testFunc(): Int { return (0 + 1) * 10 / 20 != 10 * someId; @@ -2805,33 +2613,27 @@ exports[`grammar should parse expr-with-var 1`] = ` }, "params": [], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 14, + "id": 13, "kind": "op_binary", "left": { - "id": 10, + "id": 9, "kind": "op_binary", "left": { - "id": 8, + "id": 7, "kind": "op_binary", "left": { - "id": 6, + "id": 5, "kind": "op_binary", "left": { - "id": 4, + "id": 3, "kind": "number", "loc": 0, "value": 0n, @@ -2839,7 +2641,7 @@ exports[`grammar should parse expr-with-var 1`] = ` "loc": 0 + 1, "op": "+", "right": { - "id": 5, + "id": 4, "kind": "number", "loc": 1, "value": 1n, @@ -2848,7 +2650,7 @@ exports[`grammar should parse expr-with-var 1`] = ` "loc": (0 + 1) * 10, "op": "*", "right": { - "id": 7, + "id": 6, "kind": "number", "loc": 10, "value": 10n, @@ -2857,7 +2659,7 @@ exports[`grammar should parse expr-with-var 1`] = ` "loc": (0 + 1) * 10 / 20, "op": "/", "right": { - "id": 9, + "id": 8, "kind": "number", "loc": 20, "value": 20n, @@ -2866,10 +2668,10 @@ exports[`grammar should parse expr-with-var 1`] = ` "loc": (0 + 1) * 10 / 20 != 10 * someId, "op": "!=", "right": { - "id": 13, + "id": 12, "kind": "op_binary", "left": { - "id": 11, + "id": 10, "kind": "number", "loc": 10, "value": 10n, @@ -2877,14 +2679,14 @@ exports[`grammar should parse expr-with-var 1`] = ` "loc": 10 * someId, "op": "*", "right": { - "id": 12, + "id": 11, "kind": "id", "loc": someId, "text": "someId", }, }, }, - "id": 15, + "id": 14, "kind": "statement_return", "loc": return (0 + 1) * 10 / 20 != 10 * someId;, }, @@ -2897,12 +2699,12 @@ exports[`grammar should parse expr-with-var 1`] = ` exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] = ` { - "id": 130, + "id": 111, "imports": [], "items": [ { "attributes": [], - "id": 22, + "id": 19, "kind": "function_def", "loc": fun function(a: Int, b: Int): Int { return (a >> b) || (a << (32 - b)); @@ -2915,74 +2717,56 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] }, "params": [ { - "id": 7, + "id": 5, "kind": "typed_parameter", "loc": a: Int, "name": { - "id": 4, + "id": 3, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 6, - "kind": "type_ref_simple", + "id": 4, + "kind": "type_id", "loc": Int, - "name": { - "id": 5, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { - "id": 11, + "id": 8, "kind": "typed_parameter", "loc": b: Int, "name": { - "id": 8, + "id": 6, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 10, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 20, + "id": 17, "kind": "op_binary", "left": { - "id": 14, + "id": 11, "kind": "op_binary", "left": { - "id": 12, + "id": 9, "kind": "id", "loc": a, "text": "a", @@ -2990,7 +2774,7 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] "loc": a >> b, "op": ">>", "right": { - "id": 13, + "id": 10, "kind": "id", "loc": b, "text": "b", @@ -2999,10 +2783,10 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] "loc": (a >> b) || (a << (32 - b)), "op": "||", "right": { - "id": 19, + "id": 16, "kind": "op_binary", "left": { - "id": 15, + "id": 12, "kind": "id", "loc": a, "text": "a", @@ -3010,10 +2794,10 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] "loc": a << (32 - b), "op": "<<", "right": { - "id": 18, + "id": 15, "kind": "op_binary", "left": { - "id": 16, + "id": 13, "kind": "number", "loc": 32, "value": 32n, @@ -3021,7 +2805,7 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] "loc": 32 - b, "op": "-", "right": { - "id": 17, + "id": 14, "kind": "id", "loc": b, "text": "b", @@ -3029,7 +2813,7 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] }, }, }, - "id": 21, + "id": 18, "kind": "statement_return", "loc": return (a >> b) || (a << (32 - b));, }, @@ -3037,7 +2821,7 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] }, { "attributes": [], - "id": 44, + "id": 38, "kind": "function_def", "loc": fun anotherFunction( a: Int, @@ -3046,81 +2830,63 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] return (a >> b) || (a << (32 - b)); }, "name": { - "id": 23, + "id": 20, "kind": "id", "loc": anotherFunction, "text": "anotherFunction", }, "params": [ { - "id": 29, + "id": 24, "kind": "typed_parameter", "loc": a: Int, "name": { - "id": 26, + "id": 22, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 28, - "kind": "type_ref_simple", + "id": 23, + "kind": "type_id", "loc": Int, - "name": { - "id": 27, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { - "id": 33, + "id": 27, "kind": "typed_parameter", "loc": b: Int, "name": { - "id": 30, + "id": 25, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 32, - "kind": "type_ref_simple", + "id": 26, + "kind": "type_id", "loc": Int, - "name": { - "id": 31, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], "return": { - "id": 25, - "kind": "type_ref_simple", + "id": 21, + "kind": "type_id", "loc": Int, - "name": { - "id": 24, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 42, + "id": 36, "kind": "op_binary", "left": { - "id": 36, + "id": 30, "kind": "op_binary", "left": { - "id": 34, + "id": 28, "kind": "id", "loc": a, "text": "a", @@ -3128,7 +2894,7 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] "loc": a >> b, "op": ">>", "right": { - "id": 35, + "id": 29, "kind": "id", "loc": b, "text": "b", @@ -3137,10 +2903,10 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] "loc": (a >> b) || (a << (32 - b)), "op": "||", "right": { - "id": 41, + "id": 35, "kind": "op_binary", "left": { - "id": 37, + "id": 31, "kind": "id", "loc": a, "text": "a", @@ -3148,10 +2914,10 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] "loc": a << (32 - b), "op": "<<", "right": { - "id": 40, + "id": 34, "kind": "op_binary", "left": { - "id": 38, + "id": 32, "kind": "number", "loc": 32, "value": 32n, @@ -3159,7 +2925,7 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] "loc": 32 - b, "op": "-", "right": { - "id": 39, + "id": 33, "kind": "id", "loc": b, "text": "b", @@ -3167,7 +2933,7 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] }, }, }, - "id": 43, + "id": 37, "kind": "statement_return", "loc": return (a >> b) || (a << (32 - b));, }, @@ -3180,85 +2946,67 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] "type": "extends", }, ], - "id": 64, + "id": 55, "kind": "function_def", "loc": extends fun extension(self: Int, c: Int, d: Int) { return self + c + d; }, "name": { - "id": 45, + "id": 39, "kind": "id", "loc": extension, "text": "extension", }, "params": [ { - "id": 49, + "id": 42, "kind": "typed_parameter", "loc": self: Int, "name": { - "id": 46, + "id": 40, "kind": "id", "loc": self, "text": "self", }, "type": { - "id": 48, - "kind": "type_ref_simple", + "id": 41, + "kind": "type_id", "loc": Int, - "name": { - "id": 47, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { - "id": 53, + "id": 45, "kind": "typed_parameter", "loc": c: Int, "name": { - "id": 50, + "id": 43, "kind": "id", "loc": c, "text": "c", }, "type": { - "id": 52, - "kind": "type_ref_simple", + "id": 44, + "kind": "type_id", "loc": Int, - "name": { - "id": 51, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { - "id": 57, + "id": 48, "kind": "typed_parameter", "loc": d: Int, "name": { - "id": 54, + "id": 46, "kind": "id", "loc": d, "text": "d", }, "type": { - "id": 56, - "kind": "type_ref_simple", + "id": 47, + "kind": "type_id", "loc": Int, - "name": { - "id": 55, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], @@ -3266,13 +3014,13 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] "statements": [ { "expression": { - "id": 62, + "id": 53, "kind": "op_binary", "left": { - "id": 60, + "id": 51, "kind": "op_binary", "left": { - "id": 58, + "id": 49, "kind": "id", "loc": self, "text": "self", @@ -3280,7 +3028,7 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] "loc": self + c, "op": "+", "right": { - "id": 59, + "id": 50, "kind": "id", "loc": c, "text": "c", @@ -3289,13 +3037,13 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] "loc": self + c + d, "op": "+", "right": { - "id": 61, + "id": 52, "kind": "id", "loc": d, "text": "d", }, }, - "id": 63, + "id": 54, "kind": "statement_return", "loc": return self + c + d;, }, @@ -3303,7 +3051,7 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] }, { "attributes": [], - "id": 91, + "id": 78, "kind": "function_def", "loc": fun coverage(a: Int, b: Int) { let k: Int = a.extension( @@ -3317,56 +3065,44 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] ); }, "name": { - "id": 65, + "id": 56, "kind": "id", "loc": coverage, "text": "coverage", }, "params": [ { - "id": 69, + "id": 59, "kind": "typed_parameter", "loc": a: Int, "name": { - "id": 66, + "id": 57, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 68, - "kind": "type_ref_simple", + "id": 58, + "kind": "type_id", "loc": Int, - "name": { - "id": 67, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { - "id": 73, + "id": 62, "kind": "typed_parameter", "loc": b: Int, "name": { - "id": 70, + "id": 60, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 72, - "kind": "type_ref_simple", + "id": 61, + "kind": "type_id", "loc": Int, - "name": { - "id": 71, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], @@ -3376,121 +3112,109 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] "expression": { "args": [ { - "id": 79, + "id": 67, "kind": "id", "loc": b, "text": "b", }, { - "id": 80, + "id": 68, "kind": "number", "loc": 4, "value": 4n, }, ], - "id": 81, - "kind": "op_call", + "id": 69, + "kind": "method_call", "loc": a.extension( b, 4, ), - "name": { - "id": 78, + "method": { + "id": 66, "kind": "id", "loc": extension, "text": "extension", }, - "src": { - "id": 77, + "self": { + "id": 65, "kind": "id", "loc": a, "text": "a", }, }, - "id": 82, + "id": 70, "kind": "statement_let", "loc": let k: Int = a.extension( b, 4, );, "name": { - "id": 74, + "id": 63, "kind": "id", "loc": k, "text": "k", }, "type": { - "id": 76, - "kind": "type_ref_simple", + "id": 64, + "kind": "type_id", "loc": Int, - "name": { - "id": 75, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { "args": [ { - "id": 87, + "id": 74, "kind": "id", "loc": a, "text": "a", }, { - "id": 88, + "id": 75, "kind": "id", "loc": b, "text": "b", }, ], - "id": 89, - "kind": "op_static_call", - "loc": anotherFunction( - a, - b, - ), - "name": { - "id": 86, + "function": { + "id": 73, "kind": "id", "loc": anotherFunction, "text": "anotherFunction", }, + "id": 76, + "kind": "static_call", + "loc": anotherFunction( + a, + b, + ), }, - "id": 90, + "id": 77, "kind": "statement_let", "loc": let c: Int = anotherFunction( a, b, );, "name": { - "id": 83, + "id": 71, "kind": "id", "loc": c, "text": "c", }, "type": { - "id": 85, - "kind": "type_ref_simple", + "id": 72, + "kind": "type_id", "loc": Int, - "name": { - "id": 84, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], }, { "attributes": [], - "id": 108, + "id": 92, "kind": "function_def", "loc": fun oneMoreFunction( a: Int, @@ -3502,102 +3226,84 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] ); }, "name": { - "id": 92, + "id": 79, "kind": "id", "loc": oneMoreFunction, "text": "oneMoreFunction", }, "params": [ { - "id": 98, + "id": 83, "kind": "typed_parameter", "loc": a: Int, "name": { - "id": 95, + "id": 81, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 97, - "kind": "type_ref_simple", + "id": 82, + "kind": "type_id", "loc": Int, - "name": { - "id": 96, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { - "id": 102, + "id": 86, "kind": "typed_parameter", "loc": b: Int, "name": { - "id": 99, + "id": 84, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 101, - "kind": "type_ref_simple", + "id": 85, + "kind": "type_id", "loc": Int, - "name": { - "id": 100, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], "return": { - "id": 94, - "kind": "type_ref_simple", + "id": 80, + "kind": "type_id", "loc": Int, - "name": { - "id": 93, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { "args": [ { - "id": 104, + "id": 88, "kind": "id", "loc": a, "text": "a", }, { - "id": 105, + "id": 89, "kind": "id", "loc": b, "text": "b", }, ], - "id": 106, - "kind": "op_static_call", - "loc": anotherFunction( - a, - b, - ), - "name": { - "id": 103, + "function": { + "id": 87, "kind": "id", "loc": anotherFunction, "text": "anotherFunction", }, + "id": 90, + "kind": "static_call", + "loc": anotherFunction( + a, + b, + ), }, - "id": 107, + "id": 91, "kind": "statement_return", "loc": return anotherFunction( a, @@ -3610,64 +3316,52 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] "attributes": [], "declarations": [ { - "id": 118, - "kind": "def_init_function", + "id": 100, + "kind": "contract_init", "loc": init( arg1: Int, arg2: Int, ) {}, "params": [ { - "id": 113, + "id": 96, "kind": "typed_parameter", "loc": arg1: Int, "name": { - "id": 110, + "id": 94, "kind": "id", "loc": arg1, "text": "arg1", }, "type": { - "id": 112, - "kind": "type_ref_simple", + "id": 95, + "kind": "type_id", "loc": Int, - "name": { - "id": 111, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { - "id": 117, + "id": 99, "kind": "typed_parameter", "loc": arg2: Int, "name": { - "id": 114, + "id": 97, "kind": "id", "loc": arg2, "text": "arg2", }, "type": { - "id": 116, - "kind": "type_ref_simple", + "id": 98, + "kind": "type_id", "loc": Int, - "name": { - "id": 115, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], "statements": [], }, ], - "id": 119, + "id": 101, "kind": "contract", "loc": contract TestContract { init( @@ -3676,7 +3370,7 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] ) {} }, "name": { - "id": 109, + "id": 93, "kind": "id", "loc": TestContract, "text": "TestContract", @@ -3685,7 +3379,7 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] }, { "attributes": [], - "id": 129, + "id": 110, "kind": "function_def", "loc": fun test() { let k: StateInit = initOf TestContract( @@ -3694,7 +3388,7 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] ); }, "name": { - "id": 120, + "id": 102, "kind": "id", "loc": test, "text": "test", @@ -3706,54 +3400,48 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] "expression": { "args": [ { - "id": 125, + "id": 106, "kind": "number", "loc": 2, "value": 2n, }, { - "id": 126, + "id": 107, "kind": "number", "loc": 3, "value": 3n, }, ], - "id": 127, + "contract": { + "id": 105, + "kind": "id", + "loc": TestContract, + "text": "TestContract", + }, + "id": 108, "kind": "init_of", "loc": initOf TestContract( 2, 3, ), - "name": { - "id": 124, - "kind": "id", - "loc": TestContract, - "text": "TestContract", - }, }, - "id": 128, + "id": 109, "kind": "statement_let", "loc": let k: StateInit = initOf TestContract( 2, 3, );, "name": { - "id": 121, + "id": 103, "kind": "id", "loc": k, "text": "k", }, "type": { - "id": 123, - "kind": "type_ref_simple", + "id": 104, + "kind": "type_id", "loc": StateInit, - "name": { - "id": 122, - "kind": "id", - "loc": StateInit, - "text": "StateInit", - }, - "optional": false, + "text": "StateInit", }, }, ], @@ -3765,7 +3453,7 @@ exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] exports[`grammar should parse items-multi-funs 1`] = ` { - "id": 17, + "id": 15, "imports": [], "items": [ { @@ -3799,7 +3487,7 @@ exports[`grammar should parse items-multi-funs 1`] = ` }, { "attributes": [], - "id": 10, + "id": 9, "kind": "function_def", "loc": fun testFunc(): Int { return 0; @@ -3812,26 +3500,20 @@ exports[`grammar should parse items-multi-funs 1`] = ` }, "params": [], "return": { - "id": 7, - "kind": "type_ref_simple", + "id": 6, + "kind": "type_id", "loc": Int, - "name": { - "id": 6, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 8, + "id": 7, "kind": "number", "loc": 0, "value": 0n, }, - "id": 9, + "id": 8, "kind": "statement_return", "loc": return 0;, }, @@ -3839,39 +3521,33 @@ exports[`grammar should parse items-multi-funs 1`] = ` }, { "attributes": [], - "id": 16, + "id": 14, "kind": "function_def", "loc": fun testFunc(): Bool { return 0; }, "name": { - "id": 11, + "id": 10, "kind": "id", "loc": testFunc, "text": "testFunc", }, "params": [], "return": { - "id": 13, - "kind": "type_ref_simple", + "id": 11, + "kind": "type_id", "loc": Bool, - "name": { - "id": 12, - "kind": "id", - "loc": Bool, - "text": "Bool", - }, - "optional": false, + "text": "Bool", }, "statements": [ { "expression": { - "id": 14, + "id": 12, "kind": "number", "loc": 0, "value": 0n, }, - "id": 15, + "id": 13, "kind": "statement_return", "loc": return 0;, }, @@ -3884,7 +3560,7 @@ exports[`grammar should parse items-multi-funs 1`] = ` exports[`grammar should parse items-native-fun-decls 1`] = ` { - "id": 14, + "id": 12, "imports": [], "items": [ { @@ -3910,7 +3586,7 @@ native testFunc();, }, { "attributes": [], - "id": 8, + "id": 7, "kind": "native_function_decl", "loc": @name(native_name_2) native testFunc(): Int;, @@ -3928,48 +3604,36 @@ native testFunc(): Int;, }, "params": [], "return": { - "id": 7, - "kind": "type_ref_simple", + "id": 6, + "kind": "type_id", "loc": Int, - "name": { - "id": 6, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "attributes": [], - "id": 13, + "id": 11, "kind": "native_function_decl", "loc": @name(native_name_3) native testFunc(): Bool;, "name": { - "id": 9, + "id": 8, "kind": "id", "loc": testFunc, "text": "testFunc", }, "nativeName": { - "id": 10, + "id": 9, "kind": "func_id", "loc": native_name_3, "text": "native_name_3", }, "params": [], "return": { - "id": 12, - "kind": "type_ref_simple", + "id": 10, + "kind": "type_id", "loc": Bool, - "name": { - "id": 11, - "kind": "id", - "loc": Bool, - "text": "Bool", - }, - "optional": false, + "text": "Bool", }, }, ], @@ -3979,16 +3643,16 @@ native testFunc(): Bool;, exports[`grammar should parse items-struct-msg-fun-const 1`] = ` { - "id": 68, + "id": 60, "imports": [], "items": [ { "fields": [ { "as": null, - "id": 5, - "init": null, - "kind": "def_field", + "id": 4, + "initializer": null, + "kind": "field_decl", "loc": x: Int, "name": { "id": 2, @@ -3997,45 +3661,33 @@ exports[`grammar should parse items-struct-msg-fun-const 1`] = ` "text": "x", }, "type": { - "id": 4, - "kind": "type_ref_simple", + "id": 3, + "kind": "type_id", "loc": Int, - "name": { - "id": 3, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 9, - "init": null, - "kind": "def_field", + "id": 7, + "initializer": null, + "kind": "field_decl", "loc": y: Int, "name": { - "id": 6, + "id": 5, "kind": "id", "loc": y, "text": "y", }, "type": { - "id": 8, - "kind": "type_ref_simple", + "id": 6, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 10, + "id": 8, "kind": "struct_decl", "loc": struct A { x: Int; @@ -4043,40 +3695,40 @@ exports[`grammar should parse items-struct-msg-fun-const 1`] = ` }, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": A, "text": "A", }, }, { "attributes": [], - "id": 19, + "id": 16, "initializer": { "args": [ { - "exp": { - "id": 16, + "field": { + "id": 12, + "kind": "id", + "loc": x, + "text": "x", + }, + "id": 14, + "initializer": { + "id": 13, "kind": "number", "loc": 1, "value": 1n, }, - "id": 17, - "kind": "new_parameter", + "kind": "struct_field_initializer", "loc": x: 1, - "name": { - "id": 15, - "kind": "id", - "loc": x, - "text": "x", - }, }, ], - "id": 18, - "kind": "op_new", + "id": 15, + "kind": "struct_instance", "loc": A { x: 1 }, "type": { - "id": 14, - "kind": "id", + "id": 11, + "kind": "type_id", "loc": A, "text": "A", }, @@ -4084,27 +3736,21 @@ exports[`grammar should parse items-struct-msg-fun-const 1`] = ` "kind": "constant_def", "loc": const a: A = A { x: 1 };, "name": { - "id": 11, + "id": 9, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 13, - "kind": "type_ref_simple", + "id": 10, + "kind": "type_id", "loc": A, - "name": { - "id": 12, - "kind": "id", - "loc": A, - "text": "A", - }, - "optional": false, + "text": "A", }, }, { "attributes": [], - "id": 32, + "id": 28, "kind": "function_def", "loc": fun getA(): A { return A { @@ -4113,77 +3759,71 @@ exports[`grammar should parse items-struct-msg-fun-const 1`] = ` }; }, "name": { - "id": 20, + "id": 17, "kind": "id", "loc": getA, "text": "getA", }, "params": [], "return": { - "id": 22, - "kind": "type_ref_simple", + "id": 18, + "kind": "type_id", "loc": A, - "name": { - "id": 21, - "kind": "id", - "loc": A, - "text": "A", - }, - "optional": false, + "text": "A", }, "statements": [ { "expression": { "args": [ { - "exp": { - "id": 25, + "field": { + "id": 20, + "kind": "id", + "loc": x, + "text": "x", + }, + "id": 22, + "initializer": { + "id": 21, "kind": "number", "loc": 1, "value": 1n, }, - "id": 26, - "kind": "new_parameter", + "kind": "struct_field_initializer", "loc": x: 1, - "name": { - "id": 24, - "kind": "id", - "loc": x, - "text": "x", - }, }, { - "exp": { - "id": 28, + "field": { + "id": 23, + "kind": "id", + "loc": y, + "text": "y", + }, + "id": 25, + "initializer": { + "id": 24, "kind": "number", "loc": 2, "value": 2n, }, - "id": 29, - "kind": "new_parameter", + "kind": "struct_field_initializer", "loc": y: 2, - "name": { - "id": 27, - "kind": "id", - "loc": y, - "text": "y", - }, }, ], - "id": 30, - "kind": "op_new", + "id": 26, + "kind": "struct_instance", "loc": A { x: 1, y: 2, }, "type": { - "id": 23, - "kind": "id", + "id": 19, + "kind": "type_id", "loc": A, "text": "A", }, }, - "id": 31, + "id": 27, "kind": "statement_return", "loc": return A { x: 1, @@ -4196,64 +3836,52 @@ exports[`grammar should parse items-struct-msg-fun-const 1`] = ` "fields": [ { "as": null, - "id": 37, - "init": null, - "kind": "def_field", + "id": 32, + "initializer": null, + "kind": "field_decl", "loc": x: Int, "name": { - "id": 34, + "id": 30, "kind": "id", "loc": x, "text": "x", }, "type": { - "id": 36, - "kind": "type_ref_simple", + "id": 31, + "kind": "type_id", "loc": Int, - "name": { - "id": 35, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 41, - "init": null, - "kind": "def_field", + "id": 35, + "initializer": null, + "kind": "field_decl", "loc": y: Int, "name": { - "id": 38, + "id": 33, "kind": "id", "loc": y, "text": "y", }, "type": { - "id": 40, - "kind": "type_ref_simple", + "id": 34, + "kind": "type_id", "loc": Int, - "name": { - "id": 39, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 42, + "id": 36, "kind": "message_decl", "loc": message B { x: Int; y: Int; }, "name": { - "id": 33, - "kind": "id", + "id": 29, + "kind": "type_id", "loc": B, "text": "B", }, @@ -4261,53 +3889,53 @@ exports[`grammar should parse items-struct-msg-fun-const 1`] = ` }, { "attributes": [], - "id": 54, + "id": 47, "initializer": { "args": [ { - "exp": { - "id": 48, + "field": { + "id": 40, + "kind": "id", + "loc": x, + "text": "x", + }, + "id": 42, + "initializer": { + "id": 41, "kind": "number", "loc": 2, "value": 2n, }, - "id": 49, - "kind": "new_parameter", + "kind": "struct_field_initializer", "loc": x: 2, - "name": { - "id": 47, - "kind": "id", - "loc": x, - "text": "x", - }, }, { - "exp": { - "id": 51, + "field": { + "id": 43, + "kind": "id", + "loc": y, + "text": "y", + }, + "id": 45, + "initializer": { + "id": 44, "kind": "number", "loc": 3, "value": 3n, }, - "id": 52, - "kind": "new_parameter", + "kind": "struct_field_initializer", "loc": y: 3, - "name": { - "id": 50, - "kind": "id", - "loc": y, - "text": "y", - }, }, ], - "id": 53, - "kind": "op_new", + "id": 46, + "kind": "struct_instance", "loc": B { x: 2, y: 3, }, "type": { - "id": 46, - "kind": "id", + "id": 39, + "kind": "type_id", "loc": B, "text": "B", }, @@ -4318,100 +3946,88 @@ exports[`grammar should parse items-struct-msg-fun-const 1`] = ` y: 3, };, "name": { - "id": 43, + "id": 37, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 45, - "kind": "type_ref_simple", + "id": 38, + "kind": "type_id", "loc": B, - "name": { - "id": 44, - "kind": "id", - "loc": B, - "text": "B", - }, - "optional": false, + "text": "B", }, }, { "attributes": [], - "id": 67, + "id": 59, "kind": "function_def", "loc": fun getB(): B { return B { x: 1, y: 5, }; }, "name": { - "id": 55, + "id": 48, "kind": "id", "loc": getB, "text": "getB", }, "params": [], "return": { - "id": 57, - "kind": "type_ref_simple", + "id": 49, + "kind": "type_id", "loc": B, - "name": { - "id": 56, - "kind": "id", - "loc": B, - "text": "B", - }, - "optional": false, + "text": "B", }, "statements": [ { "expression": { "args": [ { - "exp": { - "id": 60, + "field": { + "id": 51, + "kind": "id", + "loc": x, + "text": "x", + }, + "id": 53, + "initializer": { + "id": 52, "kind": "number", "loc": 1, "value": 1n, }, - "id": 61, - "kind": "new_parameter", + "kind": "struct_field_initializer", "loc": x: 1, - "name": { - "id": 59, - "kind": "id", - "loc": x, - "text": "x", - }, }, { - "exp": { - "id": 63, + "field": { + "id": 54, + "kind": "id", + "loc": y, + "text": "y", + }, + "id": 56, + "initializer": { + "id": 55, "kind": "number", "loc": 5, "value": 5n, }, - "id": 64, - "kind": "new_parameter", + "kind": "struct_field_initializer", "loc": y: 5, - "name": { - "id": 62, - "kind": "id", - "loc": y, - "text": "y", - }, }, ], - "id": 65, - "kind": "op_new", + "id": 57, + "kind": "struct_instance", "loc": B { x: 1, y: 5, }, "type": { - "id": 58, - "kind": "id", + "id": 50, + "kind": "type_id", "loc": B, "text": "B", }, }, - "id": 66, + "id": 58, "kind": "statement_return", "loc": return B { x: 1, y: 5, };, }, @@ -4424,12 +4040,12 @@ exports[`grammar should parse items-struct-msg-fun-const 1`] = ` exports[`grammar should parse literals-int-underscores-bin-dec-hex-oct 1`] = ` { - "id": 93, + "id": 80, "imports": [], "items": [ { "attributes": [], - "id": 92, + "id": 79, "kind": "function_def", "loc": fun test_fun(): Int { let a: Int = 123; @@ -4454,426 +4070,348 @@ exports[`grammar should parse literals-int-underscores-bin-dec-hex-oct 1`] = ` }, "params": [], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 7, + "id": 5, "kind": "number", "loc": 123, "value": 123n, }, - "id": 8, + "id": 6, "kind": "statement_let", "loc": let a: Int = 123;, "name": { - "id": 4, + "id": 3, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 6, - "kind": "type_ref_simple", + "id": 4, + "kind": "type_id", "loc": Int, - "name": { - "id": 5, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 13, + "id": 10, "kind": "op_unary", "loc": -123, "op": "-", - "right": { - "id": 12, + "operand": { + "id": 9, "kind": "number", "loc": 123, "value": 123n, }, }, - "id": 14, + "id": 11, "kind": "statement_let", "loc": let b: Int = -123;, "name": { - "id": 9, + "id": 7, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 11, - "kind": "type_ref_simple", + "id": 8, + "kind": "type_id", "loc": Int, - "name": { - "id": 10, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 18, + "id": 14, "kind": "number", "loc": 1_0123_00_000, "value": 1012300000n, }, - "id": 19, + "id": 15, "kind": "statement_let", "loc": let c: Int = 1_0123_00_000;, "name": { - "id": 15, + "id": 12, "kind": "id", "loc": c, "text": "c", }, "type": { - "id": 17, - "kind": "type_ref_simple", + "id": 13, + "kind": "type_id", "loc": Int, - "name": { - "id": 16, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 23, + "id": 18, "kind": "number", "loc": 0x123, "value": 291n, }, - "id": 24, + "id": 19, "kind": "statement_let", "loc": let d: Int = 0x123;, "name": { - "id": 20, + "id": 16, "kind": "id", "loc": d, "text": "d", }, "type": { - "id": 22, - "kind": "type_ref_simple", + "id": 17, + "kind": "type_id", "loc": Int, - "name": { - "id": 21, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 29, + "id": 23, "kind": "op_unary", "loc": -0x123, "op": "-", - "right": { - "id": 28, + "operand": { + "id": 22, "kind": "number", "loc": 0x123, "value": 291n, }, }, - "id": 30, + "id": 24, "kind": "statement_let", "loc": let e: Int = -0x123;, "name": { - "id": 25, + "id": 20, "kind": "id", "loc": e, "text": "e", }, "type": { - "id": 27, - "kind": "type_ref_simple", + "id": 21, + "kind": "type_id", "loc": Int, - "name": { - "id": 26, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 34, + "id": 27, "kind": "number", "loc": 0x1_0123_00_000, "value": 69024612352n, }, - "id": 35, + "id": 28, "kind": "statement_let", "loc": let f: Int = 0x1_0123_00_000;, "name": { - "id": 31, + "id": 25, "kind": "id", "loc": f, "text": "f", }, "type": { - "id": 33, - "kind": "type_ref_simple", + "id": 26, + "kind": "type_id", "loc": Int, - "name": { - "id": 32, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 39, + "id": 31, "kind": "number", "loc": 0b101010, "value": 42n, }, - "id": 40, + "id": 32, "kind": "statement_let", "loc": let g: Int = 0b101010;, "name": { - "id": 36, + "id": 29, "kind": "id", "loc": g, "text": "g", }, "type": { - "id": 38, - "kind": "type_ref_simple", + "id": 30, + "kind": "type_id", "loc": Int, - "name": { - "id": 37, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 45, + "id": 36, "kind": "op_unary", "loc": -0b101010, "op": "-", - "right": { - "id": 44, + "operand": { + "id": 35, "kind": "number", "loc": 0b101010, "value": 42n, }, }, - "id": 46, + "id": 37, "kind": "statement_let", "loc": let h: Int = -0b101010;, "name": { - "id": 41, + "id": 33, "kind": "id", "loc": h, "text": "h", }, "type": { - "id": 43, - "kind": "type_ref_simple", + "id": 34, + "kind": "type_id", "loc": Int, - "name": { - "id": 42, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 50, + "id": 40, "kind": "number", "loc": 0b1_0101_00_000, "value": 672n, }, - "id": 51, + "id": 41, "kind": "statement_let", "loc": let i: Int = 0b1_0101_00_000;, "name": { - "id": 47, + "id": 38, "kind": "id", "loc": i, "text": "i", }, "type": { - "id": 49, - "kind": "type_ref_simple", + "id": 39, + "kind": "type_id", "loc": Int, - "name": { - "id": 48, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 55, + "id": 44, "kind": "number", "loc": 0o123, "value": 83n, }, - "id": 56, + "id": 45, "kind": "statement_let", "loc": let j: Int = 0o123;, "name": { - "id": 52, + "id": 42, "kind": "id", "loc": j, "text": "j", }, "type": { - "id": 54, - "kind": "type_ref_simple", + "id": 43, + "kind": "type_id", "loc": Int, - "name": { - "id": 53, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 61, + "id": 49, "kind": "op_unary", "loc": -0o123, "op": "-", - "right": { - "id": 60, + "operand": { + "id": 48, "kind": "number", "loc": 0o123, "value": 83n, }, }, - "id": 62, + "id": 50, "kind": "statement_let", "loc": let k: Int = -0o123;, "name": { - "id": 57, + "id": 46, "kind": "id", "loc": k, "text": "k", }, "type": { - "id": 59, - "kind": "type_ref_simple", + "id": 47, + "kind": "type_id", "loc": Int, - "name": { - "id": 58, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 66, + "id": 53, "kind": "number", "loc": 0o1_0123_00_000, "value": 136937472n, }, - "id": 67, + "id": 54, "kind": "statement_let", "loc": let l: Int = 0o1_0123_00_000;, "name": { - "id": 63, + "id": 51, "kind": "id", "loc": l, "text": "l", }, "type": { - "id": 65, - "kind": "type_ref_simple", + "id": 52, + "kind": "type_id", "loc": Int, - "name": { - "id": 64, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 90, + "id": 77, "kind": "op_binary", "left": { - "id": 88, + "id": 75, "kind": "op_binary", "left": { - "id": 86, + "id": 73, "kind": "op_binary", "left": { - "id": 84, + "id": 71, "kind": "op_binary", "left": { - "id": 82, + "id": 69, "kind": "op_binary", "left": { - "id": 80, + "id": 67, "kind": "op_binary", "left": { - "id": 78, + "id": 65, "kind": "op_binary", "left": { - "id": 76, + "id": 63, "kind": "op_binary", "left": { - "id": 74, + "id": 61, "kind": "op_binary", "left": { - "id": 72, + "id": 59, "kind": "op_binary", "left": { - "id": 70, + "id": 57, "kind": "op_binary", "left": { - "id": 68, + "id": 55, "kind": "id", "loc": a, "text": "a", @@ -4881,7 +4419,7 @@ exports[`grammar should parse literals-int-underscores-bin-dec-hex-oct 1`] = ` "loc": a + b, "op": "+", "right": { - "id": 69, + "id": 56, "kind": "id", "loc": b, "text": "b", @@ -4890,7 +4428,7 @@ exports[`grammar should parse literals-int-underscores-bin-dec-hex-oct 1`] = ` "loc": a + b + c, "op": "+", "right": { - "id": 71, + "id": 58, "kind": "id", "loc": c, "text": "c", @@ -4899,7 +4437,7 @@ exports[`grammar should parse literals-int-underscores-bin-dec-hex-oct 1`] = ` "loc": a + b + c + d, "op": "+", "right": { - "id": 73, + "id": 60, "kind": "id", "loc": d, "text": "d", @@ -4908,7 +4446,7 @@ exports[`grammar should parse literals-int-underscores-bin-dec-hex-oct 1`] = ` "loc": a + b + c + d + e, "op": "+", "right": { - "id": 75, + "id": 62, "kind": "id", "loc": e, "text": "e", @@ -4917,7 +4455,7 @@ exports[`grammar should parse literals-int-underscores-bin-dec-hex-oct 1`] = ` "loc": a + b + c + d + e + f, "op": "+", "right": { - "id": 77, + "id": 64, "kind": "id", "loc": f, "text": "f", @@ -4926,7 +4464,7 @@ exports[`grammar should parse literals-int-underscores-bin-dec-hex-oct 1`] = ` "loc": a + b + c + d + e + f + g, "op": "+", "right": { - "id": 79, + "id": 66, "kind": "id", "loc": g, "text": "g", @@ -4935,7 +4473,7 @@ exports[`grammar should parse literals-int-underscores-bin-dec-hex-oct 1`] = ` "loc": a + b + c + d + e + f + g + h, "op": "+", "right": { - "id": 81, + "id": 68, "kind": "id", "loc": h, "text": "h", @@ -4944,7 +4482,7 @@ exports[`grammar should parse literals-int-underscores-bin-dec-hex-oct 1`] = ` "loc": a + b + c + d + e + f + g + h + i, "op": "+", "right": { - "id": 83, + "id": 70, "kind": "id", "loc": i, "text": "i", @@ -4953,7 +4491,7 @@ exports[`grammar should parse literals-int-underscores-bin-dec-hex-oct 1`] = ` "loc": a + b + c + d + e + f + g + h + i + j, "op": "+", "right": { - "id": 85, + "id": 72, "kind": "id", "loc": j, "text": "j", @@ -4962,7 +4500,7 @@ exports[`grammar should parse literals-int-underscores-bin-dec-hex-oct 1`] = ` "loc": a + b + c + d + e + f + g + h + i + j + k, "op": "+", "right": { - "id": 87, + "id": 74, "kind": "id", "loc": k, "text": "k", @@ -4971,13 +4509,13 @@ exports[`grammar should parse literals-int-underscores-bin-dec-hex-oct 1`] = ` "loc": a + b + c + d + e + f + g + h + i + j + k + l, "op": "+", "right": { - "id": 89, + "id": 76, "kind": "id", "loc": l, "text": "l", }, }, - "id": 91, + "id": 78, "kind": "statement_return", "loc": return a + b + c + d + e + f + g + h + i + j + k + l;, }, @@ -4990,12 +4528,12 @@ exports[`grammar should parse literals-int-underscores-bin-dec-hex-oct 1`] = ` exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` { - "id": 75, + "id": 72, "imports": [], "items": [ { "attributes": [], - "id": 74, + "id": 71, "kind": "function_def", "loc": fun testFunc(): Int { let a: Int = 1; @@ -5026,89 +4564,71 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, "params": [], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 7, + "id": 5, "kind": "number", "loc": 1, "value": 1n, }, - "id": 8, + "id": 6, "kind": "statement_let", "loc": let a: Int = 1;, "name": { - "id": 4, + "id": 3, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 6, - "kind": "type_ref_simple", + "id": 4, + "kind": "type_id", "loc": Int, - "name": { - "id": 5, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 12, + "id": 9, "kind": "number", "loc": 2, "value": 2n, }, - "id": 13, + "id": 10, "kind": "statement_let", "loc": let b: Int = 2;, "name": { - "id": 9, + "id": 7, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 11, - "kind": "type_ref_simple", + "id": 8, + "kind": "type_id", "loc": Int, - "name": { - "id": 10, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 15, + "id": 12, "kind": "id", "loc": b, "text": "b", }, - "id": 16, + "id": 13, "kind": "statement_augmentedassign", "loc": a += b;, "op": "+", "path": { - "id": 14, + "id": 11, "kind": "id", "loc": a, "text": "a", @@ -5116,17 +4636,17 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 18, + "id": 15, "kind": "id", "loc": a, "text": "a", }, - "id": 19, + "id": 16, "kind": "statement_augmentedassign", "loc": b += a;, "op": "+", "path": { - "id": 17, + "id": 14, "kind": "id", "loc": b, "text": "b", @@ -5134,17 +4654,17 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 21, + "id": 18, "kind": "number", "loc": 3, "value": 3n, }, - "id": 22, + "id": 19, "kind": "statement_augmentedassign", "loc": a += 3;, "op": "+", "path": { - "id": 20, + "id": 17, "kind": "id", "loc": a, "text": "a", @@ -5152,10 +4672,10 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 26, + "id": 23, "kind": "op_binary", "left": { - "id": 24, + "id": 21, "kind": "id", "loc": b, "text": "b", @@ -5163,18 +4683,18 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` "loc": b + 4, "op": "+", "right": { - "id": 25, + "id": 22, "kind": "number", "loc": 4, "value": 4n, }, }, - "id": 27, + "id": 24, "kind": "statement_augmentedassign", "loc": a += b + 4;, "op": "+", "path": { - "id": 23, + "id": 20, "kind": "id", "loc": a, "text": "a", @@ -5182,17 +4702,17 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 29, + "id": 26, "kind": "number", "loc": 1, "value": 1n, }, - "id": 30, + "id": 27, "kind": "statement_augmentedassign", "loc": b -= 1;, "op": "-", "path": { - "id": 28, + "id": 25, "kind": "id", "loc": b, "text": "b", @@ -5200,17 +4720,17 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 32, + "id": 29, "kind": "id", "loc": b, "text": "b", }, - "id": 33, + "id": 30, "kind": "statement_augmentedassign", "loc": a -= b;, "op": "-", "path": { - "id": 31, + "id": 28, "kind": "id", "loc": a, "text": "a", @@ -5218,10 +4738,10 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 37, + "id": 34, "kind": "op_binary", "left": { - "id": 35, + "id": 32, "kind": "id", "loc": b, "text": "b", @@ -5229,18 +4749,18 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` "loc": b - 1, "op": "-", "right": { - "id": 36, + "id": 33, "kind": "number", "loc": 1, "value": 1n, }, }, - "id": 38, + "id": 35, "kind": "statement_augmentedassign", "loc": a -= b - 1;, "op": "-", "path": { - "id": 34, + "id": 31, "kind": "id", "loc": a, "text": "a", @@ -5248,17 +4768,17 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 40, + "id": 37, "kind": "number", "loc": 2, "value": 2n, }, - "id": 41, + "id": 38, "kind": "statement_augmentedassign", "loc": b *= 2;, "op": "*", "path": { - "id": 39, + "id": 36, "kind": "id", "loc": b, "text": "b", @@ -5266,17 +4786,17 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 43, + "id": 40, "kind": "id", "loc": b, "text": "b", }, - "id": 44, + "id": 41, "kind": "statement_augmentedassign", "loc": a *= b;, "op": "*", "path": { - "id": 42, + "id": 39, "kind": "id", "loc": a, "text": "a", @@ -5284,10 +4804,10 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 48, + "id": 45, "kind": "op_binary", "left": { - "id": 46, + "id": 43, "kind": "id", "loc": b, "text": "b", @@ -5295,18 +4815,18 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` "loc": b * 2, "op": "*", "right": { - "id": 47, + "id": 44, "kind": "number", "loc": 2, "value": 2n, }, }, - "id": 49, + "id": 46, "kind": "statement_augmentedassign", "loc": a *= b * 2;, "op": "*", "path": { - "id": 45, + "id": 42, "kind": "id", "loc": a, "text": "a", @@ -5314,17 +4834,17 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 51, + "id": 48, "kind": "number", "loc": 2, "value": 2n, }, - "id": 52, + "id": 49, "kind": "statement_augmentedassign", "loc": b /= 2;, "op": "/", "path": { - "id": 50, + "id": 47, "kind": "id", "loc": b, "text": "b", @@ -5332,17 +4852,17 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 54, + "id": 51, "kind": "id", "loc": b, "text": "b", }, - "id": 55, + "id": 52, "kind": "statement_augmentedassign", "loc": a /= b;, "op": "/", "path": { - "id": 53, + "id": 50, "kind": "id", "loc": a, "text": "a", @@ -5350,10 +4870,10 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 59, + "id": 56, "kind": "op_binary", "left": { - "id": 57, + "id": 54, "kind": "id", "loc": b, "text": "b", @@ -5361,18 +4881,18 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` "loc": b / 2, "op": "/", "right": { - "id": 58, + "id": 55, "kind": "number", "loc": 2, "value": 2n, }, }, - "id": 60, + "id": 57, "kind": "statement_augmentedassign", "loc": a /= b / 2;, "op": "/", "path": { - "id": 56, + "id": 53, "kind": "id", "loc": a, "text": "a", @@ -5380,17 +4900,17 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 62, + "id": 59, "kind": "number", "loc": 2, "value": 2n, }, - "id": 63, + "id": 60, "kind": "statement_augmentedassign", "loc": a %= 2;, "op": "%", "path": { - "id": 61, + "id": 58, "kind": "id", "loc": a, "text": "a", @@ -5398,17 +4918,17 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 65, + "id": 62, "kind": "id", "loc": b, "text": "b", }, - "id": 66, + "id": 63, "kind": "statement_augmentedassign", "loc": a %= b;, "op": "%", "path": { - "id": 64, + "id": 61, "kind": "id", "loc": a, "text": "a", @@ -5416,10 +4936,10 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 70, + "id": 67, "kind": "op_binary", "left": { - "id": 68, + "id": 65, "kind": "id", "loc": b, "text": "b", @@ -5427,18 +4947,18 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` "loc": b % 2, "op": "%", "right": { - "id": 69, + "id": 66, "kind": "number", "loc": 2, "value": 2n, }, }, - "id": 71, + "id": 68, "kind": "statement_augmentedassign", "loc": a %= b % 2;, "op": "%", "path": { - "id": 67, + "id": 64, "kind": "id", "loc": a, "text": "a", @@ -5446,12 +4966,12 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` }, { "expression": { - "id": 72, + "id": 69, "kind": "id", "loc": a, "text": "a", }, - "id": 73, + "id": 70, "kind": "statement_return", "loc": return a;, }, @@ -5464,12 +4984,12 @@ exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` { - "id": 59, + "id": 56, "imports": [], "items": [ { "attributes": [], - "id": 58, + "id": 55, "kind": "function_def", "loc": fun testFunc(): Int { let a: Int = 1; @@ -5496,89 +5016,71 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` }, "params": [], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 7, + "id": 5, "kind": "number", "loc": 1, "value": 1n, }, - "id": 8, + "id": 6, "kind": "statement_let", "loc": let a: Int = 1;, "name": { - "id": 4, + "id": 3, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 6, - "kind": "type_ref_simple", + "id": 4, + "kind": "type_id", "loc": Int, - "name": { - "id": 5, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 12, + "id": 9, "kind": "number", "loc": 2, "value": 2n, }, - "id": 13, + "id": 10, "kind": "statement_let", "loc": let b: Int = 2;, "name": { - "id": 9, + "id": 7, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 11, - "kind": "type_ref_simple", + "id": 8, + "kind": "type_id", "loc": Int, - "name": { - "id": 10, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "expression": { - "id": 15, + "id": 12, "kind": "id", "loc": b, "text": "b", }, - "id": 16, + "id": 13, "kind": "statement_augmentedassign", "loc": a |= b;, "op": "|", "path": { - "id": 14, + "id": 11, "kind": "id", "loc": a, "text": "a", @@ -5586,17 +5088,17 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` }, { "expression": { - "id": 18, + "id": 15, "kind": "id", "loc": a, "text": "a", }, - "id": 19, + "id": 16, "kind": "statement_augmentedassign", "loc": b |= a;, "op": "|", "path": { - "id": 17, + "id": 14, "kind": "id", "loc": b, "text": "b", @@ -5604,17 +5106,17 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` }, { "expression": { - "id": 21, + "id": 18, "kind": "number", "loc": 3, "value": 3n, }, - "id": 22, + "id": 19, "kind": "statement_augmentedassign", "loc": a |= 3;, "op": "|", "path": { - "id": 20, + "id": 17, "kind": "id", "loc": a, "text": "a", @@ -5622,10 +5124,10 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` }, { "expression": { - "id": 26, + "id": 23, "kind": "op_binary", "left": { - "id": 24, + "id": 21, "kind": "id", "loc": b, "text": "b", @@ -5633,18 +5135,18 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` "loc": b | 4, "op": "|", "right": { - "id": 25, + "id": 22, "kind": "number", "loc": 4, "value": 4n, }, }, - "id": 27, + "id": 24, "kind": "statement_augmentedassign", "loc": a |= b | 4;, "op": "|", "path": { - "id": 23, + "id": 20, "kind": "id", "loc": a, "text": "a", @@ -5652,17 +5154,17 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` }, { "expression": { - "id": 29, + "id": 26, "kind": "number", "loc": 1, "value": 1n, }, - "id": 30, + "id": 27, "kind": "statement_augmentedassign", "loc": b &= 1;, "op": "&", "path": { - "id": 28, + "id": 25, "kind": "id", "loc": b, "text": "b", @@ -5670,17 +5172,17 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` }, { "expression": { - "id": 32, + "id": 29, "kind": "id", "loc": b, "text": "b", }, - "id": 33, + "id": 30, "kind": "statement_augmentedassign", "loc": a &= b;, "op": "&", "path": { - "id": 31, + "id": 28, "kind": "id", "loc": a, "text": "a", @@ -5688,17 +5190,17 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` }, { "expression": { - "id": 35, + "id": 32, "kind": "id", "loc": a, "text": "a", }, - "id": 36, + "id": 33, "kind": "statement_augmentedassign", "loc": b &= a;, "op": "&", "path": { - "id": 34, + "id": 31, "kind": "id", "loc": b, "text": "b", @@ -5706,10 +5208,10 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` }, { "expression": { - "id": 40, + "id": 37, "kind": "op_binary", "left": { - "id": 38, + "id": 35, "kind": "id", "loc": b, "text": "b", @@ -5717,18 +5219,18 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` "loc": b & 1, "op": "&", "right": { - "id": 39, + "id": 36, "kind": "number", "loc": 1, "value": 1n, }, }, - "id": 41, + "id": 38, "kind": "statement_augmentedassign", "loc": a &= b & 1;, "op": "&", "path": { - "id": 37, + "id": 34, "kind": "id", "loc": a, "text": "a", @@ -5736,17 +5238,17 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` }, { "expression": { - "id": 43, + "id": 40, "kind": "number", "loc": 2, "value": 2n, }, - "id": 44, + "id": 41, "kind": "statement_augmentedassign", "loc": b ^= 2;, "op": "^", "path": { - "id": 42, + "id": 39, "kind": "id", "loc": b, "text": "b", @@ -5754,17 +5256,17 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` }, { "expression": { - "id": 46, + "id": 43, "kind": "id", "loc": b, "text": "b", }, - "id": 47, + "id": 44, "kind": "statement_augmentedassign", "loc": a ^= b;, "op": "^", "path": { - "id": 45, + "id": 42, "kind": "id", "loc": a, "text": "a", @@ -5772,17 +5274,17 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` }, { "expression": { - "id": 49, + "id": 46, "kind": "id", "loc": a, "text": "a", }, - "id": 50, + "id": 47, "kind": "statement_augmentedassign", "loc": b ^= a;, "op": "^", "path": { - "id": 48, + "id": 45, "kind": "id", "loc": b, "text": "b", @@ -5790,10 +5292,10 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` }, { "expression": { - "id": 54, + "id": 51, "kind": "op_binary", "left": { - "id": 52, + "id": 49, "kind": "id", "loc": b, "text": "b", @@ -5801,18 +5303,18 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` "loc": b ^ 2, "op": "^", "right": { - "id": 53, + "id": 50, "kind": "number", "loc": 2, "value": 2n, }, }, - "id": 55, + "id": 52, "kind": "statement_augmentedassign", "loc": a ^= b ^ 2;, "op": "^", "path": { - "id": 51, + "id": 48, "kind": "id", "loc": a, "text": "a", @@ -5820,12 +5322,12 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` }, { "expression": { - "id": 56, + "id": 53, "kind": "id", "loc": a, "text": "a", }, - "id": 57, + "id": 54, "kind": "statement_return", "loc": return a;, }, @@ -5838,12 +5340,12 @@ exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` exports[`grammar should parse stmt-if 1`] = ` { - "id": 17, + "id": 16, "imports": [], "items": [ { "attributes": [], - "id": 16, + "id": 15, "kind": "function_def", "loc": fun testFunc(src: Int?): Int { if (src != null) { @@ -5859,49 +5361,41 @@ exports[`grammar should parse stmt-if 1`] = ` }, "params": [ { - "id": 7, + "id": 6, "kind": "typed_parameter", "loc": src: Int?, "name": { - "id": 4, + "id": 3, "kind": "id", "loc": src, "text": "src", }, "type": { - "id": 6, - "kind": "type_ref_simple", + "id": 5, + "kind": "optional_type", "loc": Int?, - "name": { - "id": 5, - "kind": "id", + "typeArg": { + "id": 4, + "kind": "type_id", "loc": Int, "text": "Int", }, - "optional": true, }, }, ], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { - "elseif": null, - "expression": { - "id": 10, + "condition": { + "id": 9, "kind": "op_binary", "left": { - "id": 8, + "id": 7, "kind": "id", "loc": src, "text": "src", @@ -5909,13 +5403,14 @@ exports[`grammar should parse stmt-if 1`] = ` "loc": src != null, "op": "!=", "right": { - "id": 9, + "id": 8, "kind": "null", "loc": null, }, }, + "elseif": null, "falseStatements": null, - "id": 13, + "id": 12, "kind": "statement_condition", "loc": if (src != null) { return src; @@ -5923,12 +5418,12 @@ exports[`grammar should parse stmt-if 1`] = ` "trueStatements": [ { "expression": { - "id": 11, + "id": 10, "kind": "id", "loc": src, "text": "src", }, - "id": 12, + "id": 11, "kind": "statement_return", "loc": return src;, }, @@ -5936,12 +5431,12 @@ exports[`grammar should parse stmt-if 1`] = ` }, { "expression": { - "id": 14, + "id": 13, "kind": "number", "loc": 0, "value": 0n, }, - "id": 15, + "id": 14, "kind": "statement_return", "loc": return 0;, }, @@ -5954,12 +5449,12 @@ exports[`grammar should parse stmt-if 1`] = ` exports[`grammar should parse stmt-if-else 1`] = ` { - "id": 17, + "id": 16, "imports": [], "items": [ { "attributes": [], - "id": 16, + "id": 15, "kind": "function_def", "loc": fun testFunc(src: Int?): Int { if (src != null) { @@ -5976,49 +5471,41 @@ exports[`grammar should parse stmt-if-else 1`] = ` }, "params": [ { - "id": 7, + "id": 6, "kind": "typed_parameter", "loc": src: Int?, "name": { - "id": 4, + "id": 3, "kind": "id", "loc": src, "text": "src", }, "type": { - "id": 6, - "kind": "type_ref_simple", + "id": 5, + "kind": "optional_type", "loc": Int?, - "name": { - "id": 5, - "kind": "id", + "typeArg": { + "id": 4, + "kind": "type_id", "loc": Int, "text": "Int", }, - "optional": true, }, }, ], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { - "elseif": null, - "expression": { - "id": 10, + "condition": { + "id": 9, "kind": "op_binary", "left": { - "id": 8, + "id": 7, "kind": "id", "loc": src, "text": "src", @@ -6026,25 +5513,26 @@ exports[`grammar should parse stmt-if-else 1`] = ` "loc": src != null, "op": "!=", "right": { - "id": 9, + "id": 8, "kind": "null", "loc": null, }, }, + "elseif": null, "falseStatements": [ { "expression": { - "id": 13, + "id": 12, "kind": "number", "loc": 10, "value": 10n, }, - "id": 14, + "id": 13, "kind": "statement_return", "loc": return 10;, }, ], - "id": 15, + "id": 14, "kind": "statement_condition", "loc": if (src != null) { return src; @@ -6054,12 +5542,12 @@ exports[`grammar should parse stmt-if-else 1`] = ` "trueStatements": [ { "expression": { - "id": 11, + "id": 10, "kind": "id", "loc": src, "text": "src", }, - "id": 12, + "id": 11, "kind": "statement_return", "loc": return src;, }, @@ -6074,12 +5562,12 @@ exports[`grammar should parse stmt-if-else 1`] = ` exports[`grammar should parse stmt-optional-semicolon-for-last-statement 1`] = ` { - "id": 43, + "id": 40, "imports": [], "items": [ { "attributes": [], - "id": 21, + "id": 20, "kind": "function_def", "loc": fun test1() { let i: Int = 1; @@ -6097,12 +5585,12 @@ exports[`grammar should parse stmt-optional-semicolon-for-last-statement 1`] = ` "statements": [ { "expression": { - "id": 5, + "id": 4, "kind": "number", "loc": 1, "value": 1n, }, - "id": 6, + "id": 5, "kind": "statement_let", "loc": let i: Int = 1;, "name": { @@ -6112,27 +5600,21 @@ exports[`grammar should parse stmt-optional-semicolon-for-last-statement 1`] = ` "text": "i", }, "type": { - "id": 4, - "kind": "type_ref_simple", + "id": 3, + "kind": "type_id", "loc": Int, - "name": { - "id": 3, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "condition": { - "id": 13, + "id": 12, "kind": "op_binary", "left": { - "id": 9, + "id": 8, "kind": "op_binary", "left": { - "id": 7, + "id": 6, "kind": "id", "loc": i, "text": "i", @@ -6140,7 +5622,7 @@ exports[`grammar should parse stmt-optional-semicolon-for-last-statement 1`] = ` "loc": i >= 10, "op": ">=", "right": { - "id": 8, + "id": 7, "kind": "number", "loc": 10, "value": 10n, @@ -6149,10 +5631,10 @@ exports[`grammar should parse stmt-optional-semicolon-for-last-statement 1`] = ` "loc": i >= 10 || i <= 100, "op": "||", "right": { - "id": 12, + "id": 11, "kind": "op_binary", "left": { - "id": 10, + "id": 9, "kind": "id", "loc": i, "text": "i", @@ -6160,30 +5642,30 @@ exports[`grammar should parse stmt-optional-semicolon-for-last-statement 1`] = ` "loc": i <= 100, "op": "<=", "right": { - "id": 11, + "id": 10, "kind": "number", "loc": 100, "value": 100n, }, }, }, - "id": 17, + "id": 16, "kind": "statement_while", "loc": while(i >= 10 || i <= 100) { i += 1 }, "statements": [ { "expression": { - "id": 15, + "id": 14, "kind": "number", "loc": 1, "value": 1n, }, - "id": 16, + "id": 15, "kind": "statement_augmentedassign", "loc": i += 1, "op": "+", "path": { - "id": 14, + "id": 13, "kind": "id", "loc": i, "text": "i", @@ -6193,16 +5675,16 @@ exports[`grammar should parse stmt-optional-semicolon-for-last-statement 1`] = ` }, { "expression": { - "id": 19, + "id": 18, "kind": "number", "loc": 42, "value": 42n, }, - "id": 20, + "id": 19, "kind": "statement_let", "loc": let i = 42, "name": { - "id": 18, + "id": 17, "kind": "id", "loc": i, "text": "i", @@ -6213,11 +5695,11 @@ exports[`grammar should parse stmt-optional-semicolon-for-last-statement 1`] = ` }, { "attributes": [], - "id": 24, + "id": 23, "kind": "function_def", "loc": fun test2() { return }, "name": { - "id": 22, + "id": 21, "kind": "id", "loc": test2, "text": "test2", @@ -6227,7 +5709,7 @@ exports[`grammar should parse stmt-optional-semicolon-for-last-statement 1`] = ` "statements": [ { "expression": null, - "id": 23, + "id": 22, "kind": "statement_return", "loc": return, }, @@ -6235,37 +5717,31 @@ exports[`grammar should parse stmt-optional-semicolon-for-last-statement 1`] = ` }, { "attributes": [], - "id": 30, + "id": 28, "kind": "function_def", "loc": fun test3(): Int { return 42 }, "name": { - "id": 25, + "id": 24, "kind": "id", "loc": test3, "text": "test3", }, "params": [], "return": { - "id": 27, - "kind": "type_ref_simple", + "id": 25, + "kind": "type_id", "loc": Int, - "name": { - "id": 26, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 28, + "id": 26, "kind": "number", "loc": 42, "value": 42n, }, - "id": 29, + "id": 27, "kind": "statement_return", "loc": return 42, }, @@ -6273,37 +5749,31 @@ exports[`grammar should parse stmt-optional-semicolon-for-last-statement 1`] = ` }, { "attributes": [], - "id": 42, + "id": 39, "kind": "function_def", "loc": fun test4(): Int { do { 21 + 21 } until (true && true) }, "name": { - "id": 31, + "id": 29, "kind": "id", "loc": test4, "text": "test4", }, "params": [], "return": { - "id": 33, - "kind": "type_ref_simple", + "id": 30, + "kind": "type_id", "loc": Int, - "name": { - "id": 32, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "condition": { - "id": 36, + "id": 33, "kind": "op_binary", "left": { - "id": 34, + "id": 31, "kind": "boolean", "loc": true, "value": true, @@ -6311,22 +5781,22 @@ exports[`grammar should parse stmt-optional-semicolon-for-last-statement 1`] = ` "loc": true && true, "op": "&&", "right": { - "id": 35, + "id": 32, "kind": "boolean", "loc": true, "value": true, }, }, - "id": 41, + "id": 38, "kind": "statement_until", "loc": do { 21 + 21 } until (true && true), "statements": [ { "expression": { - "id": 39, + "id": 36, "kind": "op_binary", "left": { - "id": 37, + "id": 34, "kind": "number", "loc": 21, "value": 21n, @@ -6334,13 +5804,13 @@ exports[`grammar should parse stmt-optional-semicolon-for-last-statement 1`] = ` "loc": 21 + 21, "op": "+", "right": { - "id": 38, + "id": 35, "kind": "number", "loc": 21, "value": 21n, }, }, - "id": 40, + "id": 37, "kind": "statement_expression", "loc": 21 + 21, }, @@ -6355,12 +5825,12 @@ exports[`grammar should parse stmt-optional-semicolon-for-last-statement 1`] = ` exports[`grammar should parse stmt-while-loop 1`] = ` { - "id": 21, + "id": 20, "imports": [], "items": [ { "attributes": [], - "id": 20, + "id": 19, "kind": "function_def", "loc": fun main() { let i: Int = 1; @@ -6379,12 +5849,12 @@ exports[`grammar should parse stmt-while-loop 1`] = ` "statements": [ { "expression": { - "id": 5, + "id": 4, "kind": "number", "loc": 1, "value": 1n, }, - "id": 6, + "id": 5, "kind": "statement_let", "loc": let i: Int = 1;, "name": { @@ -6394,27 +5864,21 @@ exports[`grammar should parse stmt-while-loop 1`] = ` "text": "i", }, "type": { - "id": 4, - "kind": "type_ref_simple", + "id": 3, + "kind": "type_id", "loc": Int, - "name": { - "id": 3, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "condition": { - "id": 13, + "id": 12, "kind": "op_binary", "left": { - "id": 9, + "id": 8, "kind": "op_binary", "left": { - "id": 7, + "id": 6, "kind": "id", "loc": i, "text": "i", @@ -6422,7 +5886,7 @@ exports[`grammar should parse stmt-while-loop 1`] = ` "loc": i >= 10, "op": ">=", "right": { - "id": 8, + "id": 7, "kind": "number", "loc": 10, "value": 10n, @@ -6431,10 +5895,10 @@ exports[`grammar should parse stmt-while-loop 1`] = ` "loc": i >= 10 || i <= 100, "op": "||", "right": { - "id": 12, + "id": 11, "kind": "op_binary", "left": { - "id": 10, + "id": 9, "kind": "id", "loc": i, "text": "i", @@ -6442,14 +5906,14 @@ exports[`grammar should parse stmt-while-loop 1`] = ` "loc": i <= 100, "op": "<=", "right": { - "id": 11, + "id": 10, "kind": "number", "loc": 100, "value": 100n, }, }, }, - "id": 19, + "id": 18, "kind": "statement_while", "loc": while(i >= 10 || i <= 100) { i = i + 1; @@ -6457,10 +5921,10 @@ exports[`grammar should parse stmt-while-loop 1`] = ` "statements": [ { "expression": { - "id": 17, + "id": 16, "kind": "op_binary", "left": { - "id": 15, + "id": 14, "kind": "id", "loc": i, "text": "i", @@ -6468,17 +5932,17 @@ exports[`grammar should parse stmt-while-loop 1`] = ` "loc": i + 1, "op": "+", "right": { - "id": 16, + "id": 15, "kind": "number", "loc": 1, "value": 1n, }, }, - "id": 18, + "id": 17, "kind": "statement_assign", "loc": i = i + 1;, "path": { - "id": 14, + "id": 13, "kind": "id", "loc": i, "text": "i", @@ -6495,12 +5959,12 @@ exports[`grammar should parse stmt-while-loop 1`] = ` exports[`grammar should parse stmt-while-repeat-do-loops 1`] = ` { - "id": 29, + "id": 28, "imports": [], "items": [ { "attributes": [], - "id": 28, + "id": 27, "kind": "function_def", "loc": fun main() { let i: Int = 1; @@ -6525,12 +5989,12 @@ exports[`grammar should parse stmt-while-repeat-do-loops 1`] = ` "statements": [ { "expression": { - "id": 5, + "id": 4, "kind": "number", "loc": 1, "value": 1n, }, - "id": 6, + "id": 5, "kind": "statement_let", "loc": let i: Int = 1;, "name": { @@ -6540,26 +6004,20 @@ exports[`grammar should parse stmt-while-repeat-do-loops 1`] = ` "text": "i", }, "type": { - "id": 4, - "kind": "type_ref_simple", + "id": 3, + "kind": "type_id", "loc": Int, - "name": { - "id": 3, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "condition": { - "id": 7, + "id": 6, "kind": "boolean", "loc": true, "value": true, }, - "id": 13, + "id": 12, "kind": "statement_while", "loc": while(true) { i = i + 1; @@ -6567,10 +6025,10 @@ exports[`grammar should parse stmt-while-repeat-do-loops 1`] = ` "statements": [ { "expression": { - "id": 11, + "id": 10, "kind": "op_binary", "left": { - "id": 9, + "id": 8, "kind": "id", "loc": i, "text": "i", @@ -6578,17 +6036,17 @@ exports[`grammar should parse stmt-while-repeat-do-loops 1`] = ` "loc": i + 1, "op": "+", "right": { - "id": 10, + "id": 9, "kind": "number", "loc": 1, "value": 1n, }, }, - "id": 12, + "id": 11, "kind": "statement_assign", "loc": i = i + 1;, "path": { - "id": 8, + "id": 7, "kind": "id", "loc": i, "text": "i", @@ -6597,9 +6055,9 @@ exports[`grammar should parse stmt-while-repeat-do-loops 1`] = ` ], }, { - "id": 20, + "id": 19, "iterations": { - "id": 14, + "id": 13, "kind": "number", "loc": 10, "value": 10n, @@ -6611,10 +6069,10 @@ exports[`grammar should parse stmt-while-repeat-do-loops 1`] = ` "statements": [ { "expression": { - "id": 18, + "id": 17, "kind": "op_binary", "left": { - "id": 16, + "id": 15, "kind": "id", "loc": i, "text": "i", @@ -6622,17 +6080,17 @@ exports[`grammar should parse stmt-while-repeat-do-loops 1`] = ` "loc": i * 10, "op": "*", "right": { - "id": 17, + "id": 16, "kind": "number", "loc": 10, "value": 10n, }, }, - "id": 19, + "id": 18, "kind": "statement_assign", "loc": i = i * 10;, "path": { - "id": 15, + "id": 14, "kind": "id", "loc": i, "text": "i", @@ -6642,12 +6100,12 @@ exports[`grammar should parse stmt-while-repeat-do-loops 1`] = ` }, { "condition": { - "id": 21, + "id": 20, "kind": "boolean", "loc": false, "value": false, }, - "id": 27, + "id": 26, "kind": "statement_until", "loc": do { i = i - 1; @@ -6655,10 +6113,10 @@ exports[`grammar should parse stmt-while-repeat-do-loops 1`] = ` "statements": [ { "expression": { - "id": 25, + "id": 24, "kind": "op_binary", "left": { - "id": 23, + "id": 22, "kind": "id", "loc": i, "text": "i", @@ -6666,17 +6124,17 @@ exports[`grammar should parse stmt-while-repeat-do-loops 1`] = ` "loc": i - 1, "op": "-", "right": { - "id": 24, + "id": 23, "kind": "number", "loc": 1, "value": 1n, }, }, - "id": 26, + "id": 25, "kind": "statement_assign", "loc": i = i - 1;, "path": { - "id": 22, + "id": 21, "kind": "id", "loc": i, "text": "i", @@ -6693,16 +6151,16 @@ exports[`grammar should parse stmt-while-repeat-do-loops 1`] = ` exports[`grammar should parse struct-field-punning 1`] = ` { - "id": 33, + "id": 28, "imports": [], "items": [ { "fields": [ { "as": null, - "id": 5, - "init": null, - "kind": "def_field", + "id": 4, + "initializer": null, + "kind": "field_decl", "loc": x: Int, "name": { "id": 2, @@ -6711,45 +6169,33 @@ exports[`grammar should parse struct-field-punning 1`] = ` "text": "x", }, "type": { - "id": 4, - "kind": "type_ref_simple", + "id": 3, + "kind": "type_id", "loc": Int, - "name": { - "id": 3, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 9, - "init": null, - "kind": "def_field", + "id": 7, + "initializer": null, + "kind": "field_decl", "loc": y: Int, "name": { - "id": 6, + "id": 5, "kind": "id", "loc": y, "text": "y", }, "type": { - "id": 8, - "kind": "type_ref_simple", + "id": 6, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 10, + "id": 8, "kind": "struct_decl", "loc": struct A { x: Int; @@ -6757,16 +6203,16 @@ exports[`grammar should parse struct-field-punning 1`] = ` }, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": A, "text": "A", }, }, { "attributes": [], - "id": 15, + "id": 12, "initializer": { - "id": 14, + "id": 11, "kind": "number", "loc": 5, "value": 5n, @@ -6774,29 +6220,23 @@ exports[`grammar should parse struct-field-punning 1`] = ` "kind": "constant_def", "loc": const x: Int = 5;, "name": { - "id": 11, + "id": 9, "kind": "id", "loc": x, "text": "x", }, "type": { - "id": 13, - "kind": "type_ref_simple", + "id": 10, + "kind": "type_id", "loc": Int, - "name": { - "id": 12, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "attributes": [], - "id": 20, + "id": 16, "initializer": { - "id": 19, + "id": 15, "kind": "number", "loc": 6, "value": 6n, @@ -6804,70 +6244,64 @@ exports[`grammar should parse struct-field-punning 1`] = ` "kind": "constant_def", "loc": const y: Int = 6;, "name": { - "id": 16, + "id": 13, "kind": "id", "loc": y, "text": "y", }, "type": { - "id": 18, - "kind": "type_ref_simple", + "id": 14, + "kind": "type_id", "loc": Int, - "name": { - "id": 17, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "attributes": [], - "id": 32, + "id": 27, "initializer": { "args": [ { - "exp": { - "id": 26, + "field": { + "id": 20, "kind": "id", "loc": x, "text": "x", }, - "id": 27, - "kind": "new_parameter", - "loc": x, - "name": { - "id": 25, + "id": 22, + "initializer": { + "id": 21, "kind": "id", "loc": x, "text": "x", }, + "kind": "struct_field_initializer", + "loc": x, }, { - "exp": { - "id": 29, + "field": { + "id": 23, "kind": "id", "loc": y, "text": "y", }, - "id": 30, - "kind": "new_parameter", - "loc": y, - "name": { - "id": 28, + "id": 25, + "initializer": { + "id": 24, "kind": "id", "loc": y, "text": "y", }, + "kind": "struct_field_initializer", + "loc": y, }, ], - "id": 31, - "kind": "op_new", + "id": 26, + "kind": "struct_instance", "loc": A { x, y }, "type": { - "id": 24, - "kind": "id", + "id": 19, + "kind": "type_id", "loc": A, "text": "A", }, @@ -6875,22 +6309,16 @@ exports[`grammar should parse struct-field-punning 1`] = ` "kind": "constant_def", "loc": const D: A = A { x, y };, "name": { - "id": 21, + "id": 17, "kind": "id", "loc": D, "text": "D", }, "type": { - "id": 23, - "kind": "type_ref_simple", + "id": 18, + "kind": "type_id", "loc": A, - "name": { - "id": 22, - "kind": "id", - "loc": A, - "text": "A", - }, - "optional": false, + "text": "A", }, }, ], @@ -6900,16 +6328,16 @@ exports[`grammar should parse struct-field-punning 1`] = ` exports[`grammar should parse struct-msg-as 1`] = ` { - "id": 14, + "id": 12, "imports": [], "items": [ { "fields": [ { "as": null, - "id": 5, - "init": null, - "kind": "def_field", + "id": 4, + "initializer": null, + "kind": "field_decl", "loc": x: Int, "name": { "id": 2, @@ -6918,27 +6346,21 @@ exports[`grammar should parse struct-msg-as 1`] = ` "text": "x", }, "type": { - "id": 4, - "kind": "type_ref_simple", + "id": 3, + "kind": "type_id", "loc": Int, - "name": { - "id": 3, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 6, + "id": 5, "kind": "struct_decl", "loc": struct A { x: Int; }, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": A, "text": "A", }, @@ -6947,43 +6369,37 @@ exports[`grammar should parse struct-msg-as 1`] = ` "fields": [ { "as": { - "id": 11, + "id": 9, "kind": "id", "loc": coin, "text": "coin", }, - "id": 12, - "init": null, - "kind": "def_field", + "id": 10, + "initializer": null, + "kind": "field_decl", "loc": x: Int as coin, "name": { - "id": 8, + "id": 7, "kind": "id", "loc": x, "text": "x", }, "type": { - "id": 10, - "kind": "type_ref_simple", + "id": 8, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 13, + "id": 11, "kind": "message_decl", "loc": message B { x: Int as coin; }, "name": { - "id": 7, - "kind": "id", + "id": 6, + "kind": "type_id", "loc": B, "text": "B", }, @@ -6996,21 +6412,21 @@ exports[`grammar should parse struct-msg-as 1`] = ` exports[`grammar should parse struct-msg-initializers 1`] = ` { - "id": 21, + "id": 18, "imports": [], "items": [ { "fields": [ { "as": null, - "id": 6, - "init": { - "id": 5, + "id": 5, + "initializer": { + "id": 4, "kind": "number", "loc": 1000, "value": 1000n, }, - "kind": "def_field", + "kind": "field_decl", "loc": x: Int = 1000, "name": { "id": 2, @@ -7019,27 +6435,21 @@ exports[`grammar should parse struct-msg-initializers 1`] = ` "text": "x", }, "type": { - "id": 4, - "kind": "type_ref_simple", + "id": 3, + "kind": "type_id", "loc": Int, - "name": { - "id": 3, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 7, + "id": 6, "kind": "struct_decl", "loc": struct A { x: Int = 1000; }, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": A, "text": "A", }, @@ -7048,79 +6458,67 @@ exports[`grammar should parse struct-msg-initializers 1`] = ` "fields": [ { "as": { - "id": 12, + "id": 10, "kind": "id", "loc": coins, "text": "coins", }, - "id": 14, - "init": { - "id": 13, + "id": 12, + "initializer": { + "id": 11, "kind": "number", "loc": 1000, "value": 1000n, }, - "kind": "def_field", + "kind": "field_decl", "loc": x: Int as coins = 1000, "name": { - "id": 9, + "id": 8, "kind": "id", "loc": x, "text": "x", }, "type": { - "id": 11, - "kind": "type_ref_simple", + "id": 9, + "kind": "type_id", "loc": Int, - "name": { - "id": 10, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 19, - "init": { - "id": 18, + "id": 16, + "initializer": { + "id": 15, "kind": "boolean", "loc": true, "value": true, }, - "kind": "def_field", + "kind": "field_decl", "loc": y: Bool = true, "name": { - "id": 15, + "id": 13, "kind": "id", "loc": y, "text": "y", }, "type": { - "id": 17, - "kind": "type_ref_simple", + "id": 14, + "kind": "type_id", "loc": Bool, - "name": { - "id": 16, - "kind": "id", - "loc": Bool, - "text": "Bool", - }, - "optional": false, + "text": "Bool", }, }, ], - "id": 20, + "id": 17, "kind": "message_decl", "loc": message B { x: Int as coins = 1000; y: Bool = true; }, "name": { - "id": 8, - "kind": "id", + "id": 7, + "kind": "type_id", "loc": B, "text": "B", }, @@ -7133,16 +6531,16 @@ exports[`grammar should parse struct-msg-initializers 1`] = ` exports[`grammar should parse struct-msg-trailing-semicolon 1`] = ` { - "id": 77, + "id": 63, "imports": [], "items": [ { "fields": [ { "as": null, - "id": 5, - "init": null, - "kind": "def_field", + "id": 4, + "initializer": null, + "kind": "field_decl", "loc": x: Int, "name": { "id": 2, @@ -7150,26 +6548,20 @@ exports[`grammar should parse struct-msg-trailing-semicolon 1`] = ` "loc": x, "text": "x", }, - "type": { - "id": 4, - "kind": "type_ref_simple", - "loc": Int, - "name": { - "id": 3, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "type": { + "id": 3, + "kind": "type_id", + "loc": Int, + "text": "Int", }, }, ], - "id": 6, + "id": 5, "kind": "struct_decl", "loc": struct A { x: Int }, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": A, "text": "A", }, @@ -7178,61 +6570,49 @@ exports[`grammar should parse struct-msg-trailing-semicolon 1`] = ` "fields": [ { "as": null, - "id": 11, - "init": null, - "kind": "def_field", + "id": 9, + "initializer": null, + "kind": "field_decl", "loc": x: Int, "name": { - "id": 8, + "id": 7, "kind": "id", "loc": x, "text": "x", }, "type": { - "id": 10, - "kind": "type_ref_simple", + "id": 8, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 15, - "init": null, - "kind": "def_field", + "id": 12, + "initializer": null, + "kind": "field_decl", "loc": y: Int, "name": { - "id": 12, + "id": 10, "kind": "id", "loc": y, "text": "y", }, "type": { - "id": 14, - "kind": "type_ref_simple", + "id": 11, + "kind": "type_id", "loc": Int, - "name": { - "id": 13, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 16, + "id": 13, "kind": "struct_decl", "loc": struct B { x: Int; y: Int }, "name": { - "id": 7, - "kind": "id", + "id": 6, + "kind": "type_id", "loc": B, "text": "B", }, @@ -7241,66 +6621,54 @@ exports[`grammar should parse struct-msg-trailing-semicolon 1`] = ` "fields": [ { "as": null, - "id": 21, - "init": null, - "kind": "def_field", + "id": 17, + "initializer": null, + "kind": "field_decl", "loc": x: Int, "name": { - "id": 18, + "id": 15, "kind": "id", "loc": x, "text": "x", }, "type": { - "id": 20, - "kind": "type_ref_simple", + "id": 16, + "kind": "type_id", "loc": Int, - "name": { - "id": 19, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 26, - "init": { - "id": 25, + "id": 21, + "initializer": { + "id": 20, "kind": "number", "loc": 42, "value": 42n, }, - "kind": "def_field", + "kind": "field_decl", "loc": y: Int = 42, "name": { - "id": 22, + "id": 18, "kind": "id", "loc": y, "text": "y", }, "type": { - "id": 24, - "kind": "type_ref_simple", + "id": 19, + "kind": "type_id", "loc": Int, - "name": { - "id": 23, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 27, + "id": 22, "kind": "struct_decl", "loc": struct C { x: Int; y: Int = 42 }, "name": { - "id": 17, - "kind": "id", + "id": 14, + "kind": "type_id", "loc": C, "text": "C", }, @@ -7309,66 +6677,54 @@ exports[`grammar should parse struct-msg-trailing-semicolon 1`] = ` "fields": [ { "as": null, - "id": 33, - "init": { - "id": 32, + "id": 27, + "initializer": { + "id": 26, "kind": "number", "loc": 42, "value": 42n, }, - "kind": "def_field", + "kind": "field_decl", "loc": x: Int = 42, "name": { - "id": 29, + "id": 24, "kind": "id", "loc": x, "text": "x", }, "type": { - "id": 31, - "kind": "type_ref_simple", + "id": 25, + "kind": "type_id", "loc": Int, - "name": { - "id": 30, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 37, - "init": null, - "kind": "def_field", + "id": 30, + "initializer": null, + "kind": "field_decl", "loc": y: Int, "name": { - "id": 34, + "id": 28, "kind": "id", "loc": y, "text": "y", }, "type": { - "id": 36, - "kind": "type_ref_simple", + "id": 29, + "kind": "type_id", "loc": Int, - "name": { - "id": 35, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 38, + "id": 31, "kind": "struct_decl", "loc": struct D { x: Int = 42; y: Int }, "name": { - "id": 28, - "kind": "id", + "id": 23, + "kind": "type_id", "loc": D, "text": "D", }, @@ -7377,36 +6733,30 @@ exports[`grammar should parse struct-msg-trailing-semicolon 1`] = ` "fields": [ { "as": null, - "id": 43, - "init": null, - "kind": "def_field", + "id": 35, + "initializer": null, + "kind": "field_decl", "loc": x: Int, "name": { - "id": 40, + "id": 33, "kind": "id", "loc": x, "text": "x", }, "type": { - "id": 42, - "kind": "type_ref_simple", + "id": 34, + "kind": "type_id", "loc": Int, - "name": { - "id": 41, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 44, + "id": 36, "kind": "message_decl", "loc": message E { x: Int }, "name": { - "id": 39, - "kind": "id", + "id": 32, + "kind": "type_id", "loc": E, "text": "E", }, @@ -7416,61 +6766,49 @@ exports[`grammar should parse struct-msg-trailing-semicolon 1`] = ` "fields": [ { "as": null, - "id": 49, - "init": null, - "kind": "def_field", + "id": 40, + "initializer": null, + "kind": "field_decl", "loc": x: Int, "name": { - "id": 46, + "id": 38, "kind": "id", "loc": x, "text": "x", }, "type": { - "id": 48, - "kind": "type_ref_simple", + "id": 39, + "kind": "type_id", "loc": Int, - "name": { - "id": 47, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 53, - "init": null, - "kind": "def_field", + "id": 43, + "initializer": null, + "kind": "field_decl", "loc": y: Int, "name": { - "id": 50, + "id": 41, "kind": "id", "loc": y, "text": "y", }, "type": { - "id": 52, - "kind": "type_ref_simple", + "id": 42, + "kind": "type_id", "loc": Int, - "name": { - "id": 51, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 54, + "id": 44, "kind": "message_decl", "loc": message F { x: Int; y: Int }, "name": { - "id": 45, - "kind": "id", + "id": 37, + "kind": "type_id", "loc": F, "text": "F", }, @@ -7480,66 +6818,54 @@ exports[`grammar should parse struct-msg-trailing-semicolon 1`] = ` "fields": [ { "as": null, - "id": 59, - "init": null, - "kind": "def_field", + "id": 48, + "initializer": null, + "kind": "field_decl", "loc": x: Int, "name": { - "id": 56, + "id": 46, "kind": "id", "loc": x, "text": "x", }, "type": { - "id": 58, - "kind": "type_ref_simple", + "id": 47, + "kind": "type_id", "loc": Int, - "name": { - "id": 57, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 64, - "init": { - "id": 63, + "id": 52, + "initializer": { + "id": 51, "kind": "number", "loc": 42, "value": 42n, }, - "kind": "def_field", + "kind": "field_decl", "loc": y: Int = 42, "name": { - "id": 60, + "id": 49, "kind": "id", "loc": y, "text": "y", }, "type": { - "id": 62, - "kind": "type_ref_simple", + "id": 50, + "kind": "type_id", "loc": Int, - "name": { - "id": 61, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 65, + "id": 53, "kind": "message_decl", "loc": message G { x: Int; y: Int = 42 }, "name": { - "id": 55, - "kind": "id", + "id": 45, + "kind": "type_id", "loc": G, "text": "G", }, @@ -7549,66 +6875,54 @@ exports[`grammar should parse struct-msg-trailing-semicolon 1`] = ` "fields": [ { "as": null, - "id": 71, - "init": { - "id": 70, + "id": 58, + "initializer": { + "id": 57, "kind": "number", "loc": 42, "value": 42n, }, - "kind": "def_field", + "kind": "field_decl", "loc": x: Int = 42, "name": { - "id": 67, + "id": 55, "kind": "id", "loc": x, "text": "x", }, "type": { - "id": 69, - "kind": "type_ref_simple", + "id": 56, + "kind": "type_id", "loc": Int, - "name": { - "id": 68, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 75, - "init": null, - "kind": "def_field", + "id": 61, + "initializer": null, + "kind": "field_decl", "loc": y: Int, "name": { - "id": 72, + "id": 59, "kind": "id", "loc": y, "text": "y", }, "type": { - "id": 74, - "kind": "type_ref_simple", + "id": 60, + "kind": "type_id", "loc": Int, - "name": { - "id": 73, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 76, + "id": 62, "kind": "message_decl", "loc": message G { x: Int = 42; y: Int }, "name": { - "id": 66, - "kind": "id", + "id": 54, + "kind": "type_id", "loc": G, "text": "G", }, @@ -7621,7 +6935,7 @@ exports[`grammar should parse struct-msg-trailing-semicolon 1`] = ` exports[`grammar should parse traits-inheritance-trailing-comma 1`] = ` { - "id": 23, + "id": 20, "imports": [], "items": [ { @@ -7630,7 +6944,7 @@ exports[`grammar should parse traits-inheritance-trailing-comma 1`] = ` "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -7640,9 +6954,9 @@ exports[`grammar should parse traits-inheritance-trailing-comma 1`] = ` "declarations": [ { "as": null, - "id": 7, - "init": null, - "kind": "def_field", + "id": 6, + "initializer": null, + "kind": "field_decl", "loc": c: Int, "name": { "id": 4, @@ -7651,20 +6965,14 @@ exports[`grammar should parse traits-inheritance-trailing-comma 1`] = ` "text": "c", }, "type": { - "id": 6, - "kind": "type_ref_simple", + "id": 5, + "kind": "type_id", "loc": Int, - "name": { - "id": 5, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 8, + "id": 7, "kind": "trait", "loc": trait OtherTrait { c: Int; @@ -7682,44 +6990,38 @@ exports[`grammar should parse traits-inheritance-trailing-comma 1`] = ` "declarations": [ { "as": null, - "id": 13, - "init": null, - "kind": "def_field", + "id": 11, + "initializer": null, + "kind": "field_decl", "loc": a: Int, "name": { - "id": 10, + "id": 9, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 12, - "kind": "type_ref_simple", + "id": 10, + "kind": "type_id", "loc": Int, - "name": { - "id": 11, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 15, + "id": 13, "kind": "trait", "loc": trait SomeTrait with OtherTrait, { a: Int; }, "name": { - "id": 9, + "id": 8, "kind": "id", "loc": SomeTrait, "text": "SomeTrait", }, "traits": [ { - "id": 14, + "id": 12, "kind": "id", "loc": OtherTrait, "text": "OtherTrait", @@ -7731,44 +7033,38 @@ exports[`grammar should parse traits-inheritance-trailing-comma 1`] = ` "declarations": [ { "as": null, - "id": 20, - "init": null, - "kind": "def_field", + "id": 17, + "initializer": null, + "kind": "field_decl", "loc": b: Int, "name": { - "id": 17, + "id": 15, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 19, - "kind": "type_ref_simple", + "id": 16, + "kind": "type_id", "loc": Int, - "name": { - "id": 18, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 22, + "id": 19, "kind": "contract", "loc": contract Main with SomeTrait, { b: Int; }, "name": { - "id": 16, + "id": 14, "kind": "id", "loc": Main, "text": "Main", }, "traits": [ { - "id": 21, + "id": 18, "kind": "id", "loc": SomeTrait, "text": "SomeTrait", @@ -7790,8 +7086,8 @@ exports[`grammar should parse type-struct-with-map 1`] = ` { "as": null, "id": 6, - "init": null, - "kind": "def_field", + "initializer": null, + "kind": "field_decl", "loc": y: map, "name": { "id": 2, @@ -7801,22 +7097,22 @@ exports[`grammar should parse type-struct-with-map 1`] = ` }, "type": { "id": 5, - "key": { + "keyStorageType": null, + "keyType": { "id": 3, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, - "keyAs": null, - "kind": "type_ref_map", + "kind": "map_type", "loc": map, - "value": { + "valueStorageType": null, + "valueType": { "id": 4, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, - "valueAs": null, }, }, ], @@ -7827,7 +7123,7 @@ exports[`grammar should parse type-struct-with-map 1`] = ` }, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": A, "text": "A", }, @@ -7837,8 +7133,8 @@ exports[`grammar should parse type-struct-with-map 1`] = ` { "as": null, "id": 13, - "init": null, - "kind": "def_field", + "initializer": null, + "kind": "field_decl", "loc": x: map, "name": { "id": 9, @@ -7848,22 +7144,22 @@ exports[`grammar should parse type-struct-with-map 1`] = ` }, "type": { "id": 12, - "key": { + "keyStorageType": null, + "keyType": { "id": 10, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, - "keyAs": null, - "kind": "type_ref_map", + "kind": "map_type", "loc": map, - "value": { + "valueStorageType": null, + "valueType": { "id": 11, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, - "valueAs": null, }, }, ], @@ -7874,7 +7170,7 @@ exports[`grammar should parse type-struct-with-map 1`] = ` }, "name": { "id": 8, - "kind": "id", + "kind": "type_id", "loc": B, "text": "B", }, @@ -7887,12 +7183,12 @@ exports[`grammar should parse type-struct-with-map 1`] = ` exports[`grammar should parse types-optional 1`] = ` { - "id": 20, + "id": 19, "imports": [], "items": [ { "attributes": [], - "id": 19, + "id": 18, "kind": "function_def", "loc": fun testFunc(src: Int?): Int { return 1 + 2 + (123 + 3)!! > 123; @@ -7905,54 +7201,47 @@ exports[`grammar should parse types-optional 1`] = ` }, "params": [ { - "id": 7, + "id": 6, "kind": "typed_parameter", "loc": src: Int?, "name": { - "id": 4, + "id": 3, "kind": "id", "loc": src, "text": "src", }, "type": { - "id": 6, - "kind": "type_ref_simple", + "id": 5, + "kind": "optional_type", "loc": Int?, - "name": { - "id": 5, - "kind": "id", + "typeArg": { + "id": 4, + "kind": "type_id", "loc": Int, "text": "Int", }, - "optional": true, }, }, ], "return": { - "id": 3, - "kind": "type_ref_simple", + "id": 2, + "kind": "type_id", "loc": Int, - "name": { - "id": 2, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 17, + "id": 16, "kind": "op_binary", "left": { - "id": 15, + "id": 14, "kind": "op_binary", "left": { - "id": 10, + "id": 9, "kind": "op_binary", "left": { - "id": 8, + "id": 7, "kind": "number", "loc": 1, "value": 1n, @@ -7960,7 +7249,7 @@ exports[`grammar should parse types-optional 1`] = ` "loc": 1 + 2, "op": "+", "right": { - "id": 9, + "id": 8, "kind": "number", "loc": 2, "value": 2n, @@ -7969,15 +7258,15 @@ exports[`grammar should parse types-optional 1`] = ` "loc": 1 + 2 + (123 + 3)!!, "op": "+", "right": { - "id": 14, + "id": 13, "kind": "op_unary", "loc": (123 + 3)!!, "op": "!!", - "right": { - "id": 13, + "operand": { + "id": 12, "kind": "op_binary", "left": { - "id": 11, + "id": 10, "kind": "number", "loc": 123, "value": 123n, @@ -7985,7 +7274,7 @@ exports[`grammar should parse types-optional 1`] = ` "loc": 123 + 3, "op": "+", "right": { - "id": 12, + "id": 11, "kind": "number", "loc": 3, "value": 3n, @@ -7996,13 +7285,13 @@ exports[`grammar should parse types-optional 1`] = ` "loc": 1 + 2 + (123 + 3)!! > 123, "op": ">", "right": { - "id": 16, + "id": 15, "kind": "number", "loc": 123, "value": 123n, }, }, - "id": 18, + "id": 17, "kind": "statement_return", "loc": return 1 + 2 + (123 + 3)!! > 123;, }, diff --git a/src/grammar/ast.ts b/src/grammar/ast.ts index a8eb5ea8d..d961304a2 100644 --- a/src/grammar/ast.ts +++ b/src/grammar/ast.ts @@ -9,7 +9,7 @@ export type AstModule = { export type AstImport = { kind: "import"; - path: ASTString; + path: AstString; id: number; loc: SrcInfo; }; @@ -24,6 +24,13 @@ export type AstModuleItem = | AstContract | AstTrait; +export type AstTypeDecl = + | AstPrimitiveTypeDecl + | AstStructDecl + | AstMessageDecl + | AstContract + | AstTrait; + export type AstPrimitiveTypeDecl = { kind: "primitive_type_decl"; name: AstId; @@ -33,20 +40,20 @@ export type AstPrimitiveTypeDecl = { export type AstFunctionDef = { kind: "function_def"; - attributes: ASTFunctionAttribute[]; + attributes: AstFunctionAttribute[]; name: AstId; - return: ASTTypeRef | null; + return: AstType | null; params: AstTypedParameter[]; - statements: ASTStatement[]; + statements: AstStatement[]; id: number; loc: SrcInfo; }; export type AstFunctionDecl = { kind: "function_decl"; - attributes: ASTFunctionAttribute[]; + attributes: AstFunctionAttribute[]; name: AstId; - return: ASTTypeRef | null; + return: AstType | null; params: AstTypedParameter[]; id: number; loc: SrcInfo; @@ -54,30 +61,30 @@ export type AstFunctionDecl = { export type AstNativeFunctionDecl = { kind: "native_function_decl"; - attributes: ASTFunctionAttribute[]; + attributes: AstFunctionAttribute[]; name: AstId; nativeName: AstFuncId; params: AstTypedParameter[]; - return: ASTTypeRef | null; + return: AstType | null; id: number; loc: SrcInfo; }; export type AstConstantDef = { kind: "constant_def"; - attributes: ASTConstantAttribute[]; + attributes: AstConstantAttribute[]; name: AstId; - type: ASTTypeRef; - initializer: ASTExpression; + type: AstType; + initializer: AstExpression; id: number; loc: SrcInfo; }; export type AstConstantDecl = { kind: "constant_decl"; - attributes: ASTConstantAttribute[]; + attributes: AstConstantAttribute[]; name: AstId; - type: ASTTypeRef; + type: AstType; id: number; loc: SrcInfo; }; @@ -85,7 +92,7 @@ export type AstConstantDecl = { export type AstStructDecl = { kind: "struct_decl"; name: AstId; - fields: ASTField[]; + fields: AstFieldDecl[]; id: number; loc: SrcInfo; }; @@ -94,7 +101,7 @@ export type AstMessageDecl = { kind: "message_decl"; name: AstId; opcode: number | null; - fields: ASTField[]; + fields: AstFieldDecl[]; id: number; loc: SrcInfo; }; @@ -103,8 +110,8 @@ export type AstContract = { kind: "contract"; name: AstId; traits: AstId[]; - attributes: ASTContractAttribute[]; - declarations: ASTContractDeclaration[]; + attributes: AstContractAttribute[]; + declarations: AstContractDeclaration[]; id: number; loc: SrcInfo; }; @@ -113,124 +120,177 @@ export type AstTrait = { kind: "trait"; name: AstId; traits: AstId[]; - attributes: ASTContractAttribute[]; - declarations: ASTTraitDeclaration[]; + attributes: AstContractAttribute[]; + declarations: AstTraitDeclaration[]; id: number; loc: SrcInfo; }; -export type AstId = { - kind: "id"; - text: string; +export type AstContractDeclaration = + | AstFieldDecl + | AstFunctionDef + | AstContractInit + | AstReceiver + | AstConstantDef; + +export type AstTraitDeclaration = + | AstFieldDecl + | AstFunctionDef + | AstFunctionDecl + | AstReceiver + | AstConstantDef + | AstConstantDecl; + +export type AstFieldDecl = { + kind: "field_decl"; + name: AstId; + type: AstType; + initializer: AstExpression | null; + as: AstId | null; id: number; loc: SrcInfo; }; -export type AstFuncId = { - kind: "func_id"; - text: string; +export type AstReceiver = { + kind: "receiver"; + selector: AstReceiverKind; + statements: AstStatement[]; id: number; loc: SrcInfo; }; -export function idText(ident: AstFuncId): string; -export function idText(ident: AstId): string; -export function idText(ident: AstId | AstFuncId): string { - return ident.text; -} - -export function isInt(ident: AstId): boolean { - return ident.text === "Int"; -} - -export function isBool(ident: AstId): boolean { - return ident.text === "Bool"; -} - -export function isCell(ident: AstId): boolean { - return ident.text === "Cell"; -} +export type AstContractInit = { + kind: "contract_init"; + params: AstTypedParameter[]; + statements: AstStatement[]; + id: number; + loc: SrcInfo; +}; -export function isSlice(ident: AstId): boolean { - return ident.text === "Slice"; -} +// +// Statements +// -export function isBuilder(ident: AstId): boolean { - return ident.text === "Builder"; -} +export type AstStatement = + | AstStatementLet + | AstStatementReturn + | AstStatementExpression + | AstStatementAssign + | AstStatementAugmentedAssign + | AstCondition + | AstStatementWhile + | AstStatementUntil + | AstStatementRepeat + | AstStatementTry + | AstStatementTryCatch + | AstStatementForEach; + +export type AstStatementLet = { + kind: "statement_let"; + name: AstId; + type: AstType | null; + expression: AstExpression; + id: number; + loc: SrcInfo; +}; -export function isAddress(ident: AstId): boolean { - return ident.text === "Address"; -} +export type AstStatementReturn = { + kind: "statement_return"; + expression: AstExpression | null; + id: number; + loc: SrcInfo; +}; -export function isString(ident: AstId): boolean { - return ident.text === "String"; -} +export type AstStatementExpression = { + kind: "statement_expression"; + expression: AstExpression; + id: number; + loc: SrcInfo; +}; -export function isStringBuilder(ident: AstId): boolean { - return ident.text === "StringBuilder"; -} +export type AstStatementAssign = { + kind: "statement_assign"; + path: AstExpression; // left-hand side of `=` + expression: AstExpression; + id: number; + loc: SrcInfo; +}; -export function isSelfId(ident: AstId): boolean { - return ident.text === "self"; -} +export type AstAugmentedAssignOperation = + | "+" + | "-" + | "*" + | "/" + | "%" + | "|" + | "&" + | "^"; -export function isWildcard(ident: AstId): boolean { - return ident.text === "_"; -} +export type AstStatementAugmentedAssign = { + kind: "statement_augmentedassign"; + op: AstAugmentedAssignOperation; + path: AstExpression; + expression: AstExpression; + id: number; + loc: SrcInfo; +}; -export function isRequire(ident: AstId): boolean { - return ident.text === "require"; -} +export type AstCondition = { + kind: "statement_condition"; + condition: AstExpression; + trueStatements: AstStatement[]; + falseStatements: AstStatement[] | null; + elseif: AstCondition | null; + id: number; + loc: SrcInfo; +}; -export function eqNames(left: string, right: string): boolean; -export function eqNames(left: string, right: AstId): boolean; -export function eqNames(left: AstId, right: string): boolean; -export function eqNames(left: AstId, right: AstId): boolean; -export function eqNames(left: AstId | string, right: AstId | string): boolean { - if (typeof left === "string") { - if (typeof right === "string") { - return left === right; - } - return left === right.text; - } else { - if (typeof right === "string") { - return left.text === right; - } - return left.text === right.text; - } -} +export type AstStatementWhile = { + kind: "statement_while"; + condition: AstExpression; + statements: AstStatement[]; + id: number; + loc: SrcInfo; +}; -export const selfId: AstId = { - kind: "id", - text: "self", - id: 0, - loc: dummySrcInfo, +export type AstStatementUntil = { + kind: "statement_until"; + condition: AstExpression; + statements: AstStatement[]; + id: number; + loc: SrcInfo; }; -export type ASTNumber = { - kind: "number"; +export type AstStatementRepeat = { + kind: "statement_repeat"; + iterations: AstExpression; + statements: AstStatement[]; id: number; - value: bigint; loc: SrcInfo; }; -export type ASTBoolean = { - kind: "boolean"; +export type AstStatementTry = { + kind: "statement_try"; + statements: AstStatement[]; id: number; - value: boolean; loc: SrcInfo; }; -export type ASTString = { - kind: "string"; +export type AstStatementTryCatch = { + kind: "statement_try_catch"; + statements: AstStatement[]; + catchName: AstId; + catchStatements: AstStatement[]; id: number; - value: string; loc: SrcInfo; }; -export type ASTNull = { - kind: "null"; +export type AstStatementForEach = { + kind: "statement_foreach"; + keyName: AstId; + valueName: AstId; + map: AstExpression; + statements: AstStatement[]; id: number; loc: SrcInfo; }; @@ -239,38 +299,63 @@ export type ASTNull = { // Types // -export type ASTTypeRefSimple = { - kind: "type_ref_simple"; +export type AstType = + | AstTypeId + | AstOptionalType + | AstMapType + | AstBouncedMessageType; + +export type AstTypeId = { + kind: "type_id"; + text: string; id: number; - name: AstId; - optional: boolean; loc: SrcInfo; }; -export type ASTTypeRefMap = { - kind: "type_ref_map"; +export type AstOptionalType = { + kind: "optional_type"; + typeArg: AstType; id: number; - key: AstId; - keyAs: AstId | null; - value: AstId; - valueAs: AstId | null; loc: SrcInfo; }; -export type ASTTypeRefBounced = { - kind: "type_ref_bounced"; +export type AstMapType = { + kind: "map_type"; + keyType: AstTypeId; + keyStorageType: AstId | null; + valueType: AstTypeId; + valueStorageType: AstId | null; id: number; - name: AstId; loc: SrcInfo; }; -export type ASTTypeRef = ASTTypeRefSimple | ASTTypeRefMap | ASTTypeRefBounced; +export type AstBouncedMessageType = { + kind: "bounced_message_type"; + messageType: AstTypeId; + id: number; + loc: SrcInfo; +}; // // Expressions // -export type ASTBinaryOperation = +export type AstExpression = + | AstOpBinary + | AstOpUnary + | AstFieldAccess + | AstNumber + | AstId + | AstBoolean + | AstMethodCall + | AstStaticCall + | AstStructInstance + | AstNull + | AstInitOf + | AstString + | AstConditional; + +export type AstBinaryOperation = | "+" | "-" | "*" @@ -290,128 +375,220 @@ export type ASTBinaryOperation = | "|" | "^"; -export type ASTOpBinary = { +export type AstOpBinary = { kind: "op_binary"; + op: AstBinaryOperation; + left: AstExpression; + right: AstExpression; id: number; - op: ASTBinaryOperation; - left: ASTExpression; - right: ASTExpression; loc: SrcInfo; }; -export type ASTUnaryOperation = "+" | "-" | "!" | "!!" | "~"; +export type AstUnaryOperation = "+" | "-" | "!" | "!!" | "~"; -export type ASTOpUnary = { +export type AstOpUnary = { kind: "op_unary"; + op: AstUnaryOperation; + operand: AstExpression; id: number; - op: ASTUnaryOperation; - right: ASTExpression; loc: SrcInfo; }; -export type ASTOpField = { - kind: "op_field"; +export type AstFieldAccess = { + kind: "field_access"; + aggregate: AstExpression; // contract, trait, struct, message + field: AstId; id: number; - src: ASTExpression; - name: AstId; loc: SrcInfo; }; -export type ASTOpCall = { - kind: "op_call"; +export type AstMethodCall = { + kind: "method_call"; + self: AstExpression; // anything with a method + method: AstId; + args: AstExpression[]; id: number; - src: ASTExpression; - name: AstId; - args: ASTExpression[]; loc: SrcInfo; }; -export type ASTOpCallStatic = { - kind: "op_static_call"; +// builtins or top-level (module) functions +export type AstStaticCall = { + kind: "static_call"; + function: AstId; + args: AstExpression[]; id: number; - name: AstId; - args: ASTExpression[]; loc: SrcInfo; }; -export type ASTOpNew = { - kind: "op_new"; - id: number; +export type AstStructInstance = { + kind: "struct_instance"; type: AstId; - args: ASTNewParameter[]; + args: AstStructFieldInitializer[]; + id: number; loc: SrcInfo; }; -export type ASTNewParameter = { - kind: "new_parameter"; +export type AstStructFieldInitializer = { + kind: "struct_field_initializer"; + field: AstId; + initializer: AstExpression; id: number; - name: AstId; - exp: ASTExpression; loc: SrcInfo; }; -export type ASTInitOf = { +export type AstInitOf = { kind: "init_of"; + contract: AstId; + args: AstExpression[]; id: number; - name: AstId; - args: ASTExpression[]; loc: SrcInfo; }; -export type ASTConditional = { +export type AstConditional = { kind: "conditional"; + condition: AstExpression; + thenBranch: AstExpression; + elseBranch: AstExpression; id: number; - condition: ASTExpression; - thenBranch: ASTExpression; - elseBranch: ASTExpression; loc: SrcInfo; }; -export type ASTTraitDeclaration = - | ASTField - | AstFunctionDef - | AstFunctionDecl - | ASTReceive - | AstConstantDef - | AstConstantDecl; +export type AstId = { + kind: "id"; + text: string; + id: number; + loc: SrcInfo; +}; -export type ASTField = { - kind: "def_field"; +export type AstFuncId = { + kind: "func_id"; + text: string; id: number; - name: AstId; - type: ASTTypeRef; - init: ASTExpression | null; - as: AstId | null; loc: SrcInfo; }; -export type ASTConstantAttribute = - | { type: "virtual"; loc: SrcInfo } - | { type: "overrides"; loc: SrcInfo } - | { type: "abstract"; loc: SrcInfo }; +export function idText(ident: AstId): string; +export function idText(ident: AstFuncId): string; +export function idText(ident: AstTypeId): string; +export function idText(ident: AstId | AstFuncId | AstTypeId): string { + return ident.text; +} -export type ASTContractAttribute = { - type: "interface"; - name: ASTString; +export function isInt(ident: AstTypeId): boolean { + return ident.text === "Int"; +} + +export function isBool(ident: AstTypeId): boolean { + return ident.text === "Bool"; +} + +export function isCell(ident: AstTypeId): boolean { + return ident.text === "Cell"; +} + +export function isSlice(ident: AstTypeId): boolean { + return ident.text === "Slice"; +} + +export function isBuilder(ident: AstTypeId): boolean { + return ident.text === "Builder"; +} + +export function isAddress(ident: AstTypeId): boolean { + return ident.text === "Address"; +} + +export function isString(ident: AstTypeId): boolean { + return ident.text === "String"; +} + +export function isStringBuilder(ident: AstTypeId): boolean { + return ident.text === "StringBuilder"; +} + +export function isSelfId(ident: AstId): boolean { + return ident.text === "self"; +} + +export function isWildcard(ident: AstId): boolean { + return ident.text === "_"; +} + +export function isRequire(ident: AstId): boolean { + return ident.text === "require"; +} + +export function eqNames(left: string, right: string): boolean; +export function eqNames(left: string, right: AstId): boolean; +export function eqNames(left: AstId, right: string): boolean; +export function eqNames(left: AstId, right: AstId): boolean; +export function eqNames(left: AstId, right: AstId): boolean; +export function eqNames( + left: AstId | AstTypeId | string, + right: AstId | AstTypeId | string, +): boolean { + if (typeof left === "string") { + if (typeof right === "string") { + return left === right; + } + return left === right.text; + } else { + if (typeof right === "string") { + return left.text === right; + } + return left.text === right.text; + } +} + +export const selfId: AstId = { + kind: "id", + text: "self", + id: 0, + loc: dummySrcInfo, +}; + +export type AstNumber = { + kind: "number"; + value: bigint; + id: number; loc: SrcInfo; }; -export type ASTContractDeclaration = - | ASTField - | AstFunctionDef - | ASTInitFunction - | ASTReceive - | AstConstantDef; +export type AstBoolean = { + kind: "boolean"; + value: boolean; + id: number; + loc: SrcInfo; +}; -export type AstTypedParameter = { - kind: "typed_parameter"; +export type AstString = { + kind: "string"; + value: string; id: number; - name: AstId; - type: ASTTypeRef; loc: SrcInfo; }; -export type ASTFunctionAttribute = +// `null` value is an inhabitant of several types: +// it can represent missing values in optional types, +// or empty map of any key and value types +export type AstNull = { + kind: "null"; + id: number; + loc: SrcInfo; +}; + +export type AstConstantAttribute = + | { type: "virtual"; loc: SrcInfo } + | { type: "overrides"; loc: SrcInfo } + | { type: "abstract"; loc: SrcInfo }; + +export type AstContractAttribute = { + type: "interface"; + name: AstString; + loc: SrcInfo; +}; + +export type AstFunctionAttribute = | { type: "get"; loc: SrcInfo } | { type: "mutates"; loc: SrcInfo } | { type: "extends"; loc: SrcInfo } @@ -420,7 +597,15 @@ export type ASTFunctionAttribute = | { type: "overrides"; loc: SrcInfo } | { type: "inline"; loc: SrcInfo }; -export type ASTReceiveType = +export type AstTypedParameter = { + kind: "typed_parameter"; + name: AstId; + type: AstType; + id: number; + loc: SrcInfo; +}; + +export type AstReceiverKind = | { kind: "internal-simple"; param: AstTypedParameter; @@ -430,7 +615,7 @@ export type ASTReceiveType = } | { kind: "internal-comment"; - comment: ASTString; + comment: AstString; } | { kind: "bounce"; @@ -445,200 +630,27 @@ export type ASTReceiveType = } | { kind: "external-comment"; - comment: ASTString; + comment: AstString; }; -export type ASTReceive = { - kind: "def_receive"; - id: number; - selector: ASTReceiveType; - statements: ASTStatement[]; - loc: SrcInfo; -}; - -export type ASTInitFunction = { - kind: "def_init_function"; - id: number; - params: AstTypedParameter[]; - statements: ASTStatement[]; - loc: SrcInfo; -}; - -// -// Statements -// - -export type ASTStatementLet = { - kind: "statement_let"; - id: number; - name: AstId; - type: ASTTypeRef | null; - expression: ASTExpression; - loc: SrcInfo; -}; - -export type ASTStatementReturn = { - kind: "statement_return"; - id: number; - expression: ASTExpression | null; - loc: SrcInfo; -}; - -export type ASTStatementExpression = { - kind: "statement_expression"; - id: number; - expression: ASTExpression; - loc: SrcInfo; -}; - -export type ASTStatementAssign = { - kind: "statement_assign"; - id: number; - path: ASTExpression; - expression: ASTExpression; - loc: SrcInfo; -}; - -export type ASTAugmentedAssignOperation = - | "+" - | "-" - | "*" - | "/" - | "%" - | "|" - | "&" - | "^"; - -export type ASTStatementAugmentedAssign = { - kind: "statement_augmentedassign"; - id: number; - op: ASTAugmentedAssignOperation; - path: ASTExpression; - expression: ASTExpression; - loc: SrcInfo; -}; - -export type ASTCondition = { - kind: "statement_condition"; - id: number; - expression: ASTExpression; - trueStatements: ASTStatement[]; - falseStatements: ASTStatement[] | null; - elseif: ASTCondition | null; - loc: SrcInfo; -}; - -export type ASTStatementWhile = { - kind: "statement_while"; - id: number; - condition: ASTExpression; - statements: ASTStatement[]; - loc: SrcInfo; -}; - -export type ASTStatementUntil = { - kind: "statement_until"; - id: number; - condition: ASTExpression; - statements: ASTStatement[]; - loc: SrcInfo; -}; - -export type ASTStatementRepeat = { - kind: "statement_repeat"; - id: number; - iterations: ASTExpression; - statements: ASTStatement[]; - loc: SrcInfo; -}; - -export type ASTStatementTry = { - kind: "statement_try"; - id: number; - statements: ASTStatement[]; - loc: SrcInfo; -}; - -export type ASTStatementTryCatch = { - kind: "statement_try_catch"; - id: number; - statements: ASTStatement[]; - catchName: AstId; - catchStatements: ASTStatement[]; - loc: SrcInfo; -}; - -export type ASTStatementForEach = { - kind: "statement_foreach"; - id: number; - keyName: AstId; - valueName: AstId; - map: ASTExpression; - statements: ASTStatement[]; - loc: SrcInfo; -}; - -// -// Unions -// - -export type ASTStatement = - | ASTStatementLet - | ASTStatementReturn - | ASTStatementExpression - | ASTStatementAssign - | ASTStatementAugmentedAssign - | ASTCondition - | ASTStatementWhile - | ASTStatementUntil - | ASTStatementRepeat - | ASTStatementTry - | ASTStatementTryCatch - | ASTStatementForEach; -export type ASTNode = +export type AstNode = | AstFuncId - | ASTExpression - | ASTStatement - | AstStructDecl - | AstMessageDecl - | ASTField - | AstContract + | AstExpression + | AstStatement + | AstTypeDecl + | AstFieldDecl | AstTypedParameter | AstFunctionDef | AstFunctionDecl - | ASTOpCall | AstModule - | AstPrimitiveTypeDecl - | ASTOpCallStatic | AstNativeFunctionDecl - | ASTNewParameter - | ASTTypeRef - | ASTInitFunction - | ASTReceive - | AstTrait + | AstStructFieldInitializer + | AstType + | AstContractInit + | AstReceiver | AstImport | AstConstantDef | AstConstantDecl; -export type ASTExpression = - | ASTOpBinary - | ASTOpUnary - | ASTOpField - | ASTNumber - | AstId - | ASTBoolean - | ASTOpCall - | ASTOpCallStatic - | ASTOpNew - | ASTNull - | ASTInitOf - | ASTString - | ASTConditional; -export type ASTType = - | AstPrimitiveTypeDecl - | AstStructDecl - | AstMessageDecl - | AstContract - | AstTrait; /** * Check if input expression is a 'path expression', @@ -646,13 +658,13 @@ export type ASTType = * @param path A path expression to check. * @returns An array of identifiers or null if the input expression is not a path expression. */ -export function tryExtractPath(path: ASTExpression): AstId[] | null { +export function tryExtractPath(path: AstExpression): AstId[] | null { switch (path.kind) { case "id": return [path]; - case "op_field": { - const p = tryExtractPath(path.src); - return p ? [...p, path.name] : null; + case "field_access": { + const p = tryExtractPath(path.aggregate); + return p ? [...p, path.field] : null; } default: return null; @@ -664,10 +676,10 @@ type DistributiveOmit = T extends any ? Omit : never; let nextId = 1; -export function createNode(src: DistributiveOmit): ASTNode { +export function createAstNode(src: DistributiveOmit): AstNode { return Object.freeze(Object.assign({ id: nextId++ }, src)); } -export function cloneASTNode(src: T): T { +export function cloneAstNode(src: T): T { return { ...src, id: nextId++ }; } @@ -675,7 +687,7 @@ export function __DANGER_resetNodeId() { nextId = 1; } -export function traverse(node: ASTNode, callback: (node: ASTNode) => void) { +export function traverse(node: AstNode, callback: (node: AstNode) => void) { callback(node); if (node.kind === "module") { @@ -721,7 +733,7 @@ export function traverse(node: ASTNode, callback: (node: ASTNode) => void) { traverse(e, callback); } } - if (node.kind === "def_init_function") { + if (node.kind === "contract_init") { for (const e of node.params) { traverse(e, callback); } @@ -729,7 +741,7 @@ export function traverse(node: ASTNode, callback: (node: ASTNode) => void) { traverse(e, callback); } } - if (node.kind === "def_receive") { + if (node.kind === "receiver") { for (const e of node.statements) { traverse(e, callback); } @@ -739,9 +751,9 @@ export function traverse(node: ASTNode, callback: (node: ASTNode) => void) { traverse(e, callback); } } - if (node.kind === "def_field") { - if (node.init) { - traverse(node.init, callback); + if (node.kind === "field_decl") { + if (node.initializer) { + traverse(node.initializer, callback); } } if (node.kind === "constant_def") { @@ -772,7 +784,7 @@ export function traverse(node: ASTNode, callback: (node: ASTNode) => void) { traverse(node.expression, callback); } if (node.kind === "statement_condition") { - traverse(node.expression, callback); + traverse(node.condition, callback); for (const e of node.trueStatements) { traverse(e, callback); } @@ -826,29 +838,29 @@ export function traverse(node: ASTNode, callback: (node: ASTNode) => void) { traverse(node.right, callback); } if (node.kind === "op_unary") { - traverse(node.right, callback); + traverse(node.operand, callback); } - if (node.kind === "op_field") { - traverse(node.src, callback); + if (node.kind === "field_access") { + traverse(node.aggregate, callback); } - if (node.kind === "op_call") { - traverse(node.src, callback); + if (node.kind === "method_call") { + traverse(node.self, callback); for (const e of node.args) { traverse(e, callback); } } - if (node.kind === "op_static_call") { + if (node.kind === "static_call") { for (const e of node.args) { traverse(e, callback); } } - if (node.kind === "op_new") { + if (node.kind === "struct_instance") { for (const e of node.args) { traverse(e, callback); } } - if (node.kind === "new_parameter") { - traverse(node.exp, callback); + if (node.kind === "struct_field_initializer") { + traverse(node.initializer, callback); } if (node.kind === "conditional") { traverse(node.condition, callback); diff --git a/src/grammar/checkConstAttributes.ts b/src/grammar/checkConstAttributes.ts index 1cd8177bb..e4d26ec81 100644 --- a/src/grammar/checkConstAttributes.ts +++ b/src/grammar/checkConstAttributes.ts @@ -1,9 +1,9 @@ -import { ASTConstantAttribute, SrcInfo } from "./ast"; +import { AstConstantAttribute, SrcInfo } from "./ast"; import { throwCompilationError } from "../errors"; export function checkConstAttributes( isAbstract: boolean, - attributes: ASTConstantAttribute[], + attributes: AstConstantAttribute[], loc: SrcInfo, ) { const k = new Set(); diff --git a/src/grammar/checkFunctionAttributes.ts b/src/grammar/checkFunctionAttributes.ts index 6b19cae1f..1c99157e6 100644 --- a/src/grammar/checkFunctionAttributes.ts +++ b/src/grammar/checkFunctionAttributes.ts @@ -1,9 +1,9 @@ -import { ASTFunctionAttribute, SrcInfo } from "./ast"; +import { AstFunctionAttribute, SrcInfo } from "./ast"; import { throwCompilationError } from "../errors"; export function checkFunctionAttributes( isAbstract: boolean, - attrs: ASTFunctionAttribute[], + attrs: AstFunctionAttribute[], loc: SrcInfo, ) { const k = new Set(); diff --git a/src/grammar/clone.ts b/src/grammar/clone.ts index 6ec81e528..bfaff2c2e 100644 --- a/src/grammar/clone.ts +++ b/src/grammar/clone.ts @@ -1,176 +1,176 @@ -import { ASTNode, cloneASTNode } from "./ast"; +import { AstNode, cloneAstNode } from "./ast"; -export function cloneNode(src: T): T { +export function cloneNode(src: T): T { if (src.kind === "boolean") { - return cloneASTNode(src); + return cloneAstNode(src); } else if (src.kind === "id") { - return cloneASTNode(src); + return cloneAstNode(src); } else if (src.kind === "null") { - return cloneASTNode(src); + return cloneAstNode(src); } else if (src.kind === "number") { - return cloneASTNode(src); + return cloneAstNode(src); } else if (src.kind === "string") { - return cloneASTNode(src); + return cloneAstNode(src); } else if (src.kind === "statement_assign") { - return cloneASTNode({ + return cloneAstNode({ ...src, path: cloneNode(src.path), expression: cloneNode(src.expression), }); } else if (src.kind === "statement_augmentedassign") { - return cloneASTNode({ + return cloneAstNode({ ...src, path: cloneNode(src.path), expression: cloneNode(src.expression), }); } else if (src.kind === "statement_let") { - return cloneASTNode({ + return cloneAstNode({ ...src, - type: src.type ? cloneASTNode(src.type) : null, + type: src.type ? cloneAstNode(src.type) : null, expression: cloneNode(src.expression), }); } else if (src.kind === "statement_condition") { - return cloneASTNode({ + return cloneAstNode({ ...src, - expression: cloneNode(src.expression), + condition: cloneNode(src.condition), trueStatements: src.trueStatements.map(cloneNode), falseStatements: src.falseStatements ? src.falseStatements.map(cloneNode) : null, elseif: src.elseif ? cloneNode(src.elseif) : null, }); - } else if (src.kind === "new_parameter") { - return cloneASTNode({ + } else if (src.kind === "struct_field_initializer") { + return cloneAstNode({ ...src, - exp: cloneNode(src.exp), + initializer: cloneNode(src.initializer), }); } else if (src.kind === "statement_expression") { - return cloneASTNode({ + return cloneAstNode({ ...src, expression: cloneNode(src.expression), }); } else if (src.kind === "op_binary") { - return cloneASTNode({ + return cloneAstNode({ ...src, left: cloneNode(src.left), right: cloneNode(src.right), }); } else if (src.kind === "op_unary") { - return cloneASTNode({ + return cloneAstNode({ ...src, - right: cloneNode(src.right), + operand: cloneNode(src.operand), }); - } else if (src.kind === "op_new") { - return cloneASTNode({ + } else if (src.kind === "struct_instance") { + return cloneAstNode({ ...src, args: src.args.map(cloneNode), }); - } else if (src.kind === "op_call") { - return cloneASTNode({ + } else if (src.kind === "method_call") { + return cloneAstNode({ ...src, - src: cloneNode(src.src), + self: cloneNode(src.self), args: src.args.map(cloneNode), }); - } else if (src.kind === "op_field") { - return cloneASTNode({ + } else if (src.kind === "field_access") { + return cloneAstNode({ ...src, - src: cloneNode(src.src), + aggregate: cloneNode(src.aggregate), }); - } else if (src.kind === "op_static_call") { - return cloneASTNode({ + } else if (src.kind === "static_call") { + return cloneAstNode({ ...src, args: src.args.map(cloneNode), }); } else if (src.kind === "conditional") { - return cloneASTNode({ + return cloneAstNode({ ...src, condition: cloneNode(src.condition), thenBranch: cloneNode(src.thenBranch), elseBranch: cloneNode(src.elseBranch), }); } else if (src.kind === "statement_return") { - return cloneASTNode({ + return cloneAstNode({ ...src, expression: src.expression ? cloneNode(src.expression) : null, }); } else if (src.kind === "statement_repeat") { - return cloneASTNode({ + return cloneAstNode({ ...src, iterations: cloneNode(src.iterations), statements: src.statements.map(cloneNode), }); } else if (src.kind === "statement_until") { - return cloneASTNode({ + return cloneAstNode({ ...src, condition: cloneNode(src.condition), statements: src.statements.map(cloneNode), }); } else if (src.kind === "statement_while") { - return cloneASTNode({ + return cloneAstNode({ ...src, condition: cloneNode(src.condition), statements: src.statements.map(cloneNode), }); } else if (src.kind === "statement_try") { - return cloneASTNode({ + return cloneAstNode({ ...src, statements: src.statements.map(cloneNode), }); } else if (src.kind === "statement_try_catch") { - return cloneASTNode({ + return cloneAstNode({ ...src, statements: src.statements.map(cloneNode), catchStatements: src.catchStatements.map(cloneNode), }); } else if (src.kind === "statement_foreach") { - return cloneASTNode({ + return cloneAstNode({ ...src, statements: src.statements.map(cloneNode), }); } else if (src.kind === "function_def") { - return cloneASTNode({ + return cloneAstNode({ ...src, - return: src.return ? cloneASTNode(src.return) : null, + return: src.return ? cloneAstNode(src.return) : null, statements: src.statements.map(cloneNode), params: src.params.map(cloneNode), }); } else if (src.kind === "function_decl") { - return cloneASTNode({ + return cloneAstNode({ ...src, - return: src.return ? cloneASTNode(src.return) : null, + return: src.return ? cloneAstNode(src.return) : null, params: src.params.map(cloneNode), }); } else if (src.kind === "native_function_decl") { - return cloneASTNode({ + return cloneAstNode({ ...src, - return: src.return ? cloneASTNode(src.return) : null, + return: src.return ? cloneAstNode(src.return) : null, params: src.params.map(cloneNode), }); - } else if (src.kind === "def_receive") { - return cloneASTNode({ + } else if (src.kind === "receiver") { + return cloneAstNode({ ...src, statements: src.statements.map(cloneNode), }); } else if (src.kind === "typed_parameter") { - return cloneASTNode({ + return cloneAstNode({ ...src, - type: cloneASTNode(src.type), + type: cloneAstNode(src.type), }); } else if (src.kind === "init_of") { - return cloneASTNode({ + return cloneAstNode({ ...src, args: src.args.map(cloneNode), }); } else if (src.kind === "constant_def") { - return cloneASTNode({ + return cloneAstNode({ ...src, - type: cloneASTNode(src.type), + type: cloneAstNode(src.type), initializer: cloneNode(src.initializer), }); } else if (src.kind === "constant_decl") { - return cloneASTNode({ + return cloneAstNode({ ...src, - type: cloneASTNode(src.type), + type: cloneAstNode(src.type), }); } diff --git a/src/grammar/grammar.ts b/src/grammar/grammar.ts index 15f988aaa..dd4b25361 100644 --- a/src/grammar/grammar.ts +++ b/src/grammar/grammar.ts @@ -8,17 +8,17 @@ import { } from "ohm-js"; import tactGrammar from "./grammar.ohm-bundle"; import { - ASTAugmentedAssignOperation, - ASTConstantAttribute, - ASTContractAttribute, - ASTExpression, - ASTFunctionAttribute, - ASTNode, + AstAugmentedAssignOperation, + AstConstantAttribute, + AstContractAttribute, + AstExpression, + AstFunctionAttribute, + AstNode, AstModule, - ASTReceiveType, - ASTString, - ASTTypeRef, - createNode, + AstReceiverKind, + AstString, + AstType, + createAstNode, AstImport, } from "./ast"; import { throwParseError, throwCompilationError } from "../errors"; @@ -95,9 +95,9 @@ function unwrapOptNode( const semantics = tactGrammar.createSemantics(); -semantics.addOperation("astOfModule", { +semantics.addOperation("astOfModule", { Module(imports, items) { - return createNode({ + return createAstNode({ kind: "module", imports: imports.children.map((item) => item.astOfImport()), items: items.children.map((item) => item.astOfModuleItem()), @@ -105,16 +105,16 @@ semantics.addOperation("astOfModule", { }, }); -semantics.addOperation("astOfImport", { +semantics.addOperation("astOfImport", { Import(_importKwd, path, _semicolon) { - const pathAST = path.astOfExpression() as ASTString; + const pathAST = path.astOfExpression() as AstString; if (pathAST.value.indexOf("\\") >= 0) { throwCompilationError( 'Import path can\'t contain "\\"', createRef(path), ); } - return createNode({ + return createAstNode({ kind: "import", path: pathAST, loc: createRef(this), @@ -128,10 +128,10 @@ semantics.addOperation("astOfJustImports", { }, }); -semantics.addOperation("astOfModuleItem", { +semantics.addOperation("astOfModuleItem", { PrimitiveTypeDecl(_primitive_kwd, typeId, _semicolon) { checkVariableName(typeId.sourceString, createRef(typeId)); - return createNode({ + return createAstNode({ kind: "primitive_type_decl", name: typeId.astOfType(), loc: createRef(this), @@ -151,7 +151,7 @@ semantics.addOperation("astOfModuleItem", { _semicolon, ) { checkVariableName(tactId.sourceString, createRef(tactId)); - return createNode({ + return createAstNode({ kind: "native_function_decl", attributes: funAttributes.children.map((a) => a.astOfFunctionAttributes(), @@ -165,7 +165,7 @@ semantics.addOperation("astOfModuleItem", { }, StructDecl_regular(_structKwd, typeId, _lbrace, fields, _rbrace) { checkVariableName(typeId.sourceString, createRef(typeId)); - return createNode({ + return createAstNode({ kind: "struct_decl", name: typeId.astOfType(), fields: fields.astsOfList(), @@ -183,7 +183,7 @@ semantics.addOperation("astOfModuleItem", { _rbrace, ) { checkVariableName(typeId.sourceString, createRef(typeId)); - return createNode({ + return createAstNode({ kind: "message_decl", name: typeId.astOfType(), fields: fields.astsOfList(), @@ -204,7 +204,7 @@ semantics.addOperation("astOfModuleItem", { _rbrace, ) { checkVariableName(contractId.sourceString, createRef(contractId)); - return createNode({ + return createAstNode({ kind: "contract", name: contractId.astOfExpression(), attributes: attributes.children.map((ca) => @@ -228,7 +228,7 @@ semantics.addOperation("astOfModuleItem", { _rbrace, ) { checkVariableName(traitId.sourceString, createRef(traitId)); - return createNode({ + return createAstNode({ kind: "trait", name: traitId.astOfExpression(), attributes: attributes.children.map((ca) => @@ -250,7 +250,7 @@ semantics.addOperation("astOfModuleItem", { // top-level (module-level), contract or trait items: // constant declarations/definitions, functions, receivers, // getters, etc. -semantics.addOperation("astOfItem", { +semantics.addOperation("astOfItem", { ConstantDefinition( constAttributes, _constKwd, @@ -263,9 +263,9 @@ semantics.addOperation("astOfItem", { ) { const attributes = constAttributes.children.map((a) => a.astOfConstAttribute(), - ) as ASTConstantAttribute[]; + ) as AstConstantAttribute[]; checkConstAttributes(false, attributes, createRef(this)); - return createNode({ + return createAstNode({ kind: "constant_def", name: constId.astOfExpression(), type: constType.astOfType(), @@ -284,9 +284,9 @@ semantics.addOperation("astOfItem", { ) { const attributes = constAttributes.children.map((a) => a.astOfConstAttribute(), - ) as ASTConstantAttribute[]; + ) as AstConstantAttribute[]; checkConstAttributes(true, attributes, createRef(this)); - return createNode({ + return createAstNode({ kind: "constant_decl", name: constId.astOfExpression(), type: constType.astOfType(), @@ -310,10 +310,10 @@ semantics.addOperation("astOfItem", { ) { const attributes = funAttributes.children.map((a) => a.astOfFunctionAttributes(), - ) as ASTFunctionAttribute[]; + ) as AstFunctionAttribute[]; checkVariableName(funId.sourceString, createRef(funId)); checkFunctionAttributes(false, attributes, createRef(this)); - return createNode({ + return createAstNode({ kind: "function_def", attributes, name: funId.astOfExpression(), @@ -334,10 +334,10 @@ semantics.addOperation("astOfItem", { ) { const attributes = funAttributes.children.map((a) => a.astOfFunctionAttributes(), - ) as ASTFunctionAttribute[]; + ) as AstFunctionAttribute[]; checkVariableName(funId.sourceString, createRef(funId)); checkFunctionAttributes(true, attributes, createRef(this)); - return createNode({ + return createAstNode({ kind: "function_decl", attributes, name: funId.astOfExpression(), @@ -347,8 +347,8 @@ semantics.addOperation("astOfItem", { }); }, ContractInit(_initKwd, initParameters, _lbrace, initBody, _rbrace) { - return createNode({ - kind: "def_init_function", + return createAstNode({ + kind: "contract_init", params: initParameters.astsOfList(), statements: initBody.children.map((s) => s.astOfStatement()), loc: createRef(this), @@ -364,14 +364,14 @@ semantics.addOperation("astOfItem", { _rbrace, ) { const optParam = optParameter.children[0]; - const selector: ASTReceiveType = optParam + const selector: AstReceiverKind = optParam ? { kind: "internal-simple", param: optParam.astOfDeclaration(), } : { kind: "internal-fallback" }; - return createNode({ - kind: "def_receive", + return createAstNode({ + kind: "receiver", selector, statements: receiverBody.children.map((s) => s.astOfStatement()), loc: createRef(this), @@ -386,8 +386,8 @@ semantics.addOperation("astOfItem", { receiverBody, _rbrace, ) { - return createNode({ - kind: "def_receive", + return createAstNode({ + kind: "receiver", selector: { kind: "internal-comment", comment: comment.astOfExpression(), @@ -405,8 +405,8 @@ semantics.addOperation("astOfItem", { receiverBody, _rbrace, ) { - return createNode({ - kind: "def_receive", + return createAstNode({ + kind: "receiver", selector: { kind: "bounce", param: parameter.astOfDeclaration() }, statements: receiverBody.children.map((s) => s.astOfStatement()), loc: createRef(this), @@ -422,14 +422,14 @@ semantics.addOperation("astOfItem", { _rbrace, ) { const optParam = optParameter.children[0]; - const selector: ASTReceiveType = optParam + const selector: AstReceiverKind = optParam ? { kind: "external-simple", param: optParam.astOfDeclaration(), } : { kind: "external-fallback" }; - return createNode({ - kind: "def_receive", + return createAstNode({ + kind: "receiver", selector, statements: receiverBody.children.map((s) => s.astOfStatement()), loc: createRef(this), @@ -444,8 +444,8 @@ semantics.addOperation("astOfItem", { receiverBody, _rbrace, ) { - return createNode({ - kind: "def_receive", + return createAstNode({ + kind: "receiver", selector: { kind: "external-comment", comment: comment.astOfExpression(), @@ -456,7 +456,7 @@ semantics.addOperation("astOfItem", { }, }); -semantics.addOperation("astOfFunctionAttributes", { +semantics.addOperation("astOfFunctionAttributes", { FunctionAttribute_getter(_) { return { type: "get", loc: createRef(this) }; }, @@ -480,7 +480,7 @@ semantics.addOperation("astOfFunctionAttributes", { }, }); -semantics.addOperation("astOfConstAttribute", { +semantics.addOperation("astOfConstAttribute", { ConstantAttribute_override(_) { return { type: "overrides", loc: createRef(this) }; }, @@ -492,7 +492,7 @@ semantics.addOperation("astOfConstAttribute", { }, }); -semantics.addOperation("astsOfList", { +semantics.addOperation("astsOfList", { InheritedTraits(traits, _optTrailingComma) { return traits .asIteration() @@ -529,7 +529,7 @@ semantics.addOperation("astsOfList", { }, }); -semantics.addOperation("astOfContractAttributes", { +semantics.addOperation("astOfContractAttributes", { ContractAttribute_interface(_interface, _lparen, interfaceName, _rparen) { return { type: "interface", @@ -539,7 +539,7 @@ semantics.addOperation("astOfContractAttributes", { }, }); -semantics.addOperation("astOfDeclaration", { +semantics.addOperation("astOfDeclaration", { FieldDecl( id, _colon, @@ -549,18 +549,20 @@ semantics.addOperation("astOfDeclaration", { _optEq, optInitializer, ) { - return createNode({ - kind: "def_field", + return createAstNode({ + kind: "field_decl", name: id.astOfExpression(), - type: type.astOfType() as ASTTypeRef, + type: type.astOfType() as AstType, as: unwrapOptNode(optStorageType, (t) => t.astOfExpression()), - init: unwrapOptNode(optInitializer, (e) => e.astOfExpression()), + initializer: unwrapOptNode(optInitializer, (e) => + e.astOfExpression(), + ), loc: createRef(this), }); }, Parameter(id, _colon, type) { checkVariableName(id.sourceString, createRef(id)); - return createNode({ + return createAstNode({ kind: "typed_parameter", name: id.astOfExpression(), type: type.astOfType(), @@ -568,25 +570,25 @@ semantics.addOperation("astOfDeclaration", { }); }, StructFieldInitializer_full(fieldId, _colon, initializer) { - return createNode({ - kind: "new_parameter", - name: fieldId.astOfExpression(), - exp: initializer.astOfExpression(), + return createAstNode({ + kind: "struct_field_initializer", + field: fieldId.astOfExpression(), + initializer: initializer.astOfExpression(), loc: createRef(this), }); }, StructFieldInitializer_punned(fieldId) { - return createNode({ - kind: "new_parameter", - name: fieldId.astOfExpression(), - exp: fieldId.astOfExpression(), + return createAstNode({ + kind: "struct_field_initializer", + field: fieldId.astOfExpression(), + initializer: fieldId.astOfExpression(), loc: createRef(this), }); }, }); // Statements -semantics.addOperation("astOfStatement", { +semantics.addOperation("astOfStatement", { // TODO: process StatementBlock StatementLet( @@ -600,7 +602,7 @@ semantics.addOperation("astOfStatement", { ) { checkVariableName(id.sourceString, createRef(id)); - return createNode({ + return createAstNode({ kind: "statement_let", name: id.astOfExpression(), type: unwrapOptNode(optType, (t) => t.astOfType()), @@ -609,7 +611,7 @@ semantics.addOperation("astOfStatement", { }); }, StatementReturn(_returnKwd, optExpression, _optSemicolonIfLastStmtInBlock) { - return createNode({ + return createAstNode({ kind: "statement_return", expression: unwrapOptNode(optExpression, (e) => e.astOfExpression(), @@ -618,7 +620,7 @@ semantics.addOperation("astOfStatement", { }); }, StatementExpression(expression, _optSemicolonIfLastStmtInBlock) { - return createNode({ + return createAstNode({ kind: "statement_expression", expression: expression.astOfExpression(), loc: createRef(this), @@ -631,14 +633,14 @@ semantics.addOperation("astOfStatement", { _optSemicolonIfLastStmtInBlock, ) { if (operator.sourceString === "=") { - return createNode({ + return createAstNode({ kind: "statement_assign", path: lvalue.astOfExpression(), expression: expression.astOfExpression(), loc: createRef(this), }); } else { - let op: ASTAugmentedAssignOperation; + let op: AstAugmentedAssignOperation; switch (operator.sourceString) { case "+=": op = "+"; @@ -667,7 +669,7 @@ semantics.addOperation("astOfStatement", { default: throw "Internal compiler error: unreachable augmented assignment operator. Please report at https://github.com/tact-lang/tact/issues"; } - return createNode({ + return createAstNode({ kind: "statement_augmentedassign", path: lvalue.astOfExpression(), op, @@ -677,9 +679,9 @@ semantics.addOperation("astOfStatement", { } }, StatementCondition_noElse(_ifKwd, condition, _lbrace, thenBlock, _rbrace) { - return createNode({ + return createAstNode({ kind: "statement_condition", - expression: condition.astOfExpression(), + condition: condition.astOfExpression(), trueStatements: thenBlock.children.map((s) => s.astOfStatement()), falseStatements: null, elseif: null, @@ -697,9 +699,9 @@ semantics.addOperation("astOfStatement", { elseBlock, _rbraceElse, ) { - return createNode({ + return createAstNode({ kind: "statement_condition", - expression: condition.astOfExpression(), + condition: condition.astOfExpression(), trueStatements: thenBlock.children.map((s) => s.astOfStatement()), falseStatements: elseBlock.children.map((s) => s.astOfStatement()), elseif: null, @@ -715,9 +717,9 @@ semantics.addOperation("astOfStatement", { _elseKwd, elseifClause, ) { - return createNode({ + return createAstNode({ kind: "statement_condition", - expression: condition.astOfExpression(), + condition: condition.astOfExpression(), trueStatements: thenBlock.children.map((s) => s.astOfStatement()), falseStatements: null, elseif: elseifClause.astOfStatement(), @@ -733,7 +735,7 @@ semantics.addOperation("astOfStatement", { loopBody, _rbrace, ) { - return createNode({ + return createAstNode({ kind: "statement_while", condition: condition.astOfExpression(), statements: loopBody.children.map((s) => s.astOfStatement()), @@ -749,7 +751,7 @@ semantics.addOperation("astOfStatement", { loopBody, _rbrace, ) { - return createNode({ + return createAstNode({ kind: "statement_repeat", iterations: iterations.astOfExpression(), statements: loopBody.children.map((s) => s.astOfStatement()), @@ -767,7 +769,7 @@ semantics.addOperation("astOfStatement", { _rparen, _optSemicolonIfLastStmtInBlock, ) { - return createNode({ + return createAstNode({ kind: "statement_until", condition: condition.astOfExpression(), statements: loopBody.children.map((s) => s.astOfStatement()), @@ -775,7 +777,7 @@ semantics.addOperation("astOfStatement", { }); }, StatementTry_noCatch(_tryKwd, _lbraceTry, tryBlock, _rbraceTry) { - return createNode({ + return createAstNode({ kind: "statement_try", statements: tryBlock.children.map((s) => s.astOfStatement()), loc: createRef(this), @@ -794,7 +796,7 @@ semantics.addOperation("astOfStatement", { catchBlock, _rbraceCatch, ) { - return createNode({ + return createAstNode({ kind: "statement_try_catch", statements: tryBlock.children.map((s) => s.astOfStatement()), catchName: exitCodeId.astOfExpression(), @@ -817,7 +819,7 @@ semantics.addOperation("astOfStatement", { ) { checkVariableName(keyId.sourceString, createRef(keyId)); checkVariableName(valueId.sourceString, createRef(valueId)); - return createNode({ + return createAstNode({ kind: "statement_foreach", keyName: keyId.astOfExpression(), valueName: valueId.astOfExpression(), @@ -828,10 +830,10 @@ semantics.addOperation("astOfStatement", { }, }); -semantics.addOperation("astOfType", { +semantics.addOperation("astOfType", { typeId(firstTactTypeIdCharacter, restOfTactTypeId) { - return createNode({ - kind: "id", + return createAstNode({ + kind: "type_id", text: firstTactTypeIdCharacter.sourceString + restOfTactTypeId.sourceString, @@ -839,20 +841,14 @@ semantics.addOperation("astOfType", { }); }, Type_optional(typeId, _questionMark) { - return createNode({ - kind: "type_ref_simple", - name: typeId.astOfType(), - optional: true, + return createAstNode({ + kind: "optional_type", + typeArg: typeId.astOfType(), loc: createRef(this), }); }, Type_regular(typeId) { - return createNode({ - kind: "type_ref_simple", - name: typeId.astOfType(), - optional: false, - loc: createRef(this), - }); + return typeId.astOfType(); }, Type_map( _mapKwd, @@ -866,21 +862,23 @@ semantics.addOperation("astOfType", { optValueStorageType, _rangle, ) { - return createNode({ - kind: "type_ref_map", - key: keyTypeId.astOfType(), - keyAs: unwrapOptNode(optKeyStorageType, (t) => t.astOfExpression()), - value: valueTypeId.astOfType(), - valueAs: unwrapOptNode(optValueStorageType, (t) => + return createAstNode({ + kind: "map_type", + keyType: keyTypeId.astOfType(), + keyStorageType: unwrapOptNode(optKeyStorageType, (t) => + t.astOfExpression(), + ), + valueType: valueTypeId.astOfType(), + valueStorageType: unwrapOptNode(optValueStorageType, (t) => t.astOfExpression(), ), loc: createRef(this), }); }, Type_bounced(_bouncedKwd, _langle, typeId, _rangle) { - return createNode({ - kind: "type_ref_bounced", - name: typeId.astOfType(), + return createAstNode({ + kind: "bounced_message_type", + messageType: typeId.astOfType(), loc: createRef(this), }); }, @@ -892,48 +890,48 @@ function bigintOfIntLiteral(litString: NonterminalNode): bigint { } // Expressions -semantics.addOperation("astOfExpression", { +semantics.addOperation("astOfExpression", { // Literals integerLiteral(number) { - return createNode({ + return createAstNode({ kind: "number", value: bigintOfIntLiteral(number), loc: createRef(this), }); // Parses dec, hex, and bin numbers }, boolLiteral(boolValue) { - return createNode({ + return createAstNode({ kind: "boolean", value: boolValue.sourceString === "true", loc: createRef(this), }); }, id(firstTactIdCharacter, restOfTactId) { - return createNode({ + return createAstNode({ kind: "id", text: firstTactIdCharacter.sourceString + restOfTactId.sourceString, loc: createRef(this), }); }, funcId(firstFuncIdCharacter, restOfFuncId) { - return createNode({ + return createAstNode({ kind: "func_id", text: firstFuncIdCharacter.sourceString + restOfFuncId.sourceString, loc: createRef(this), }); }, null(_nullKwd) { - return createNode({ kind: "null", loc: createRef(this) }); + return createAstNode({ kind: "null", loc: createRef(this) }); }, stringLiteral(_startQuotationMark, string, _endQuotationMark) { - return createNode({ + return createAstNode({ kind: "string", value: string.sourceString, loc: createRef(this), }); }, ExpressionAdd_add(left, _plus, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: "+", left: left.astOfExpression(), @@ -942,7 +940,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionAdd_sub(left, _minus, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: "-", left: left.astOfExpression(), @@ -951,7 +949,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionMul_div(left, _slash, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: "/", left: left.astOfExpression(), @@ -960,7 +958,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionMul_mul(left, _star, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: "*", left: left.astOfExpression(), @@ -969,7 +967,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionMul_rem(left, _percent, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: "%", left: left.astOfExpression(), @@ -978,7 +976,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionEquality_eq(left, _equalsEquals, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: "==", left: left.astOfExpression(), @@ -987,7 +985,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionEquality_not(left, _bangEquals, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: "!=", left: left.astOfExpression(), @@ -996,7 +994,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionCompare_gt(left, _rangle, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: ">", left: left.astOfExpression(), @@ -1005,7 +1003,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionCompare_gte(left, _rangleEquals, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: ">=", left: left.astOfExpression(), @@ -1014,7 +1012,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionCompare_lt(left, _langle, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: "<", left: left.astOfExpression(), @@ -1023,7 +1021,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionCompare_lte(left, _langleEquals, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: "<=", left: left.astOfExpression(), @@ -1032,7 +1030,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionOr_or(left, _pipePipe, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: "||", left: left.astOfExpression(), @@ -1041,7 +1039,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionAnd_and(left, _ampersandAmpersand, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: "&&", left: left.astOfExpression(), @@ -1050,7 +1048,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionBitwiseShift_shr(left, _rangleRangle, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: ">>", left: left.astOfExpression(), @@ -1059,7 +1057,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionBitwiseShift_shl(left, _langleLangle, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: "<<", left: left.astOfExpression(), @@ -1068,7 +1066,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionBitwiseAnd_bitwiseAnd(left, _ampersand, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: "&", left: left.astOfExpression(), @@ -1077,7 +1075,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionBitwiseOr_bitwiseOr(left, _pipe, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: "|", left: left.astOfExpression(), @@ -1086,7 +1084,7 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionBitwiseXor_bitwiseXor(left, _caret, right) { - return createNode({ + return createAstNode({ kind: "op_binary", op: "^", left: left.astOfExpression(), @@ -1097,34 +1095,34 @@ semantics.addOperation("astOfExpression", { // Unary ExpressionUnary_plus(_plus, operand) { - return createNode({ + return createAstNode({ kind: "op_unary", op: "+", - right: operand.astOfExpression(), + operand: operand.astOfExpression(), loc: createRef(this), }); }, ExpressionUnary_minus(_minus, operand) { - return createNode({ + return createAstNode({ kind: "op_unary", op: "-", - right: operand.astOfExpression(), + operand: operand.astOfExpression(), loc: createRef(this), }); }, ExpressionUnary_not(_bang, operand) { - return createNode({ + return createAstNode({ kind: "op_unary", op: "!", - right: operand.astOfExpression(), + operand: operand.astOfExpression(), loc: createRef(this), }); }, ExpressionUnary_bitwiseNot(_tilde, operand) { - return createNode({ + return createAstNode({ kind: "op_unary", op: "~", - right: operand.astOfExpression(), + operand: operand.astOfExpression(), loc: createRef(this), }); }, @@ -1132,35 +1130,35 @@ semantics.addOperation("astOfExpression", { return expression.astOfExpression(); }, ExpressionUnboxNotNull(operand, _bangBang) { - return createNode({ + return createAstNode({ kind: "op_unary", op: "!!", - right: operand.astOfExpression(), + operand: operand.astOfExpression(), loc: createRef(this), }); }, ExpressionFieldAccess(source, _dot, fieldId) { - return createNode({ - kind: "op_field", - src: source.astOfExpression(), - name: fieldId.astOfExpression(), + return createAstNode({ + kind: "field_access", + aggregate: source.astOfExpression(), + field: fieldId.astOfExpression(), loc: createRef(this), }); }, ExpressionMethodCall(source, _dot, methodId, methodArguments) { - return createNode({ - kind: "op_call", - src: source.astOfExpression(), - name: methodId.astOfExpression(), + return createAstNode({ + kind: "method_call", + self: source.astOfExpression(), + method: methodId.astOfExpression(), args: methodArguments.astsOfList(), loc: createRef(this), }); }, ExpressionStaticCall(functionId, functionArguments) { - return createNode({ - kind: "op_static_call", - name: functionId.astOfExpression(), + return createAstNode({ + kind: "static_call", + function: functionId.astOfExpression(), args: functionArguments.astsOfList(), loc: createRef(this), }); @@ -1182,8 +1180,8 @@ semantics.addOperation("astOfExpression", { ); } - return createNode({ - kind: "op_new", + return createAstNode({ + kind: "struct_instance", type: typeId.astOfType(), args: structFields .asIteration() @@ -1192,9 +1190,9 @@ semantics.addOperation("astOfExpression", { }); }, ExpressionInitOf(_initOfKwd, contractId, initArguments) { - return createNode({ + return createAstNode({ kind: "init_of", - name: contractId.astOfExpression(), + contract: contractId.astOfExpression(), args: initArguments.astsOfList(), loc: createRef(this), }); @@ -1208,7 +1206,7 @@ semantics.addOperation("astOfExpression", { _colon, elseExpression, ) { - return createNode({ + return createAstNode({ kind: "conditional", condition: condition.astOfExpression(), thenBranch: thenExpression.astOfExpression(), @@ -1237,7 +1235,7 @@ export function parse( }); } -export function parseExpression(sourceCode: string): ASTExpression { +export function parseExpression(sourceCode: string): AstExpression { const matchResult = tactGrammar.match(sourceCode, "Expression"); if (matchResult.failed()) { throwParseError(matchResult, "", "user"); diff --git a/src/grammar/iterators.ts b/src/grammar/iterators.ts index b8714c313..5f1c5f363 100644 --- a/src/grammar/iterators.ts +++ b/src/grammar/iterators.ts @@ -1,4 +1,4 @@ -import { ASTNode, ASTStatement, ASTExpression } from "./ast"; +import { AstNode, AstStatement, AstExpression } from "./ast"; /** * Recursively iterates over each expression in an ASTNode and applies a callback to each expression. @@ -6,10 +6,10 @@ import { ASTNode, ASTStatement, ASTExpression } from "./ast"; * @param callback The callback function to apply to each expression. */ export function forEachExpression( - node: ASTNode, - callback: (expr: ASTExpression) => void, + node: AstNode, + callback: (expr: AstExpression) => void, ): void { - function traverseExpression(expr: ASTExpression): void { + function traverseExpression(expr: AstExpression): void { callback(expr); switch (expr.kind) { @@ -18,20 +18,22 @@ export function forEachExpression( traverseExpression(expr.right); break; case "op_unary": - traverseExpression(expr.right); + traverseExpression(expr.operand); break; - case "op_field": - traverseExpression(expr.src); + case "field_access": + traverseExpression(expr.aggregate); break; - case "op_call": - traverseExpression(expr.src); + case "method_call": + traverseExpression(expr.self); expr.args.forEach(traverseExpression); break; - case "op_static_call": + case "static_call": expr.args.forEach(traverseExpression); break; - case "op_new": - expr.args.forEach((param) => traverseExpression(param.exp)); + case "struct_instance": + expr.args.forEach((param) => + traverseExpression(param.initializer), + ); break; case "init_of": expr.args.forEach(traverseExpression); @@ -53,7 +55,7 @@ export function forEachExpression( } } - function traverseStatement(stmt: ASTStatement): void { + function traverseStatement(stmt: AstStatement): void { switch (stmt.kind) { case "statement_let": case "statement_assign": @@ -65,7 +67,7 @@ export function forEachExpression( if (stmt.expression) traverseExpression(stmt.expression); break; case "statement_condition": - traverseExpression(stmt.expression); + traverseExpression(stmt.condition); stmt.trueStatements.forEach(traverseStatement); if (stmt.falseStatements) stmt.falseStatements.forEach(traverseStatement); @@ -93,7 +95,7 @@ export function forEachExpression( } } - function traverseNode(node: ASTNode): void { + function traverseNode(node: AstNode): void { switch (node.kind) { case "module": node.items.forEach(traverseNode); @@ -105,8 +107,8 @@ export function forEachExpression( // These node types do not require further traversal of expressions or sub-nodes break; case "function_def": - case "def_init_function": - case "def_receive": + case "contract_init": + case "receiver": if (node.statements) { node.statements.forEach(traverseStatement); } @@ -115,9 +117,9 @@ export function forEachExpression( case "trait": node.declarations.forEach(traverseNode); break; - case "def_field": - if (node.init) { - traverseExpression(node.init); + case "field_decl": + if (node.initializer) { + traverseExpression(node.initializer); } break; case "constant_def": @@ -142,10 +144,10 @@ export function forEachExpression( break; case "op_binary": case "op_unary": - case "op_field": - case "op_call": - case "op_static_call": - case "op_new": + case "field_access": + case "method_call": + case "static_call": + case "struct_instance": case "init_of": case "conditional": case "string": @@ -155,13 +157,13 @@ export function forEachExpression( case "null": traverseExpression(node); break; - case "new_parameter": - traverseExpression(node.exp); + case "struct_field_initializer": + traverseExpression(node.initializer); break; case "typed_parameter": - case "type_ref_simple": - case "type_ref_map": - case "type_ref_bounced": + case "type_id": + case "map_type": + case "bounced_message_type": // Do nothing break; default: @@ -180,11 +182,11 @@ export function forEachExpression( * @returns The final value of the accumulator after processing all expressions. */ export function foldExpressions( - node: ASTNode, + node: AstNode, acc: T, - callback: (acc: T, expr: ASTExpression) => T, + callback: (acc: T, expr: AstExpression) => T, ): T { - function traverseExpression(acc: T, expr: ASTExpression): T { + function traverseExpression(acc: T, expr: AstExpression): T { acc = callback(acc, expr); switch (expr.kind) { @@ -193,25 +195,25 @@ export function foldExpressions( acc = traverseExpression(acc, expr.right); break; case "op_unary": - acc = traverseExpression(acc, expr.right); + acc = traverseExpression(acc, expr.operand); break; - case "op_field": - acc = traverseExpression(acc, expr.src); + case "field_access": + acc = traverseExpression(acc, expr.aggregate); break; - case "op_call": - acc = traverseExpression(acc, expr.src); + case "method_call": + acc = traverseExpression(acc, expr.self); expr.args.forEach((arg) => { acc = traverseExpression(acc, arg); }); break; - case "op_static_call": + case "static_call": expr.args.forEach((arg) => { acc = traverseExpression(acc, arg); }); break; - case "op_new": + case "struct_instance": expr.args.forEach((param) => { - acc = traverseExpression(acc, param.exp); + acc = traverseExpression(acc, param.initializer); }); break; case "init_of": @@ -237,7 +239,7 @@ export function foldExpressions( return acc; } - function traverseStatement(acc: T, stmt: ASTStatement): T { + function traverseStatement(acc: T, stmt: AstStatement): T { switch (stmt.kind) { case "statement_let": case "statement_expression": @@ -253,7 +255,7 @@ export function foldExpressions( acc = traverseExpression(acc, stmt.expression); break; case "statement_condition": - acc = traverseExpression(acc, stmt.expression); + acc = traverseExpression(acc, stmt.condition); stmt.trueStatements.forEach((st) => { acc = traverseStatement(acc, st); }); @@ -301,7 +303,7 @@ export function foldExpressions( return acc; } - function traverseNode(acc: T, node: ASTNode): T { + function traverseNode(acc: T, node: AstNode): T { switch (node.kind) { case "module": node.items.forEach((entry) => { @@ -315,8 +317,8 @@ export function foldExpressions( // These node types do not require further traversal of expressions or sub-nodes break; case "function_def": - case "def_init_function": - case "def_receive": + case "contract_init": + case "receiver": if (node.statements) { node.statements.forEach((stmt) => { acc = traverseStatement(acc, stmt); @@ -329,9 +331,9 @@ export function foldExpressions( acc = traverseNode(acc, decl); }); break; - case "def_field": - if (node.init) { - acc = traverseExpression(acc, node.init); + case "field_decl": + if (node.initializer) { + acc = traverseExpression(acc, node.initializer); } break; case "constant_def": @@ -356,10 +358,10 @@ export function foldExpressions( break; case "op_binary": case "op_unary": - case "op_field": - case "op_call": - case "op_static_call": - case "op_new": + case "field_access": + case "method_call": + case "static_call": + case "struct_instance": case "init_of": case "conditional": case "string": @@ -369,13 +371,13 @@ export function foldExpressions( case "null": acc = traverseExpression(acc, node); break; - case "new_parameter": - acc = traverseExpression(acc, node.exp); + case "struct_field_initializer": + acc = traverseExpression(acc, node.initializer); break; case "typed_parameter": - case "type_ref_simple": - case "type_ref_map": - case "type_ref_bounced": + case "type_id": + case "map_type": + case "bounced_message_type": // Do nothing break; default: @@ -393,10 +395,10 @@ export function foldExpressions( * @param callback The callback function to apply to each statement. */ export function forEachStatement( - node: ASTNode, - callback: (stmt: ASTStatement) => void, + node: AstNode, + callback: (stmt: AstStatement) => void, ): void { - function traverseStatement(stmt: ASTStatement): void { + function traverseStatement(stmt: AstStatement): void { callback(stmt); switch (stmt.kind) { @@ -429,14 +431,14 @@ export function forEachStatement( } } - function traverseNode(node: ASTNode): void { + function traverseNode(node: AstNode): void { switch (node.kind) { case "module": node.items.forEach(traverseNode); break; case "function_def": - case "def_init_function": - case "def_receive": + case "contract_init": + case "receiver": if (node.statements) node.statements.forEach(traverseStatement); break; case "contract": @@ -459,10 +461,10 @@ export function forEachStatement( break; case "op_binary": case "op_unary": - case "op_field": - case "op_call": - case "op_static_call": - case "op_new": + case "field_access": + case "method_call": + case "static_call": + case "struct_instance": case "init_of": case "conditional": case "string": @@ -470,17 +472,17 @@ export function forEachStatement( case "boolean": case "id": case "null": - case "new_parameter": + case "struct_field_initializer": case "typed_parameter": - case "type_ref_simple": - case "type_ref_map": - case "type_ref_bounced": + case "type_id": + case "map_type": + case "bounced_message_type": case "native_function_decl": case "struct_decl": case "message_decl": case "constant_def": case "constant_decl": - case "def_field": + case "field_decl": case "import": case "primitive_type_decl": // Do nothing @@ -501,11 +503,11 @@ export function forEachStatement( * @returns The final value of the accumulator after processing all statements. */ export function foldStatements( - node: ASTNode, + node: AstNode, acc: T, - callback: (acc: T, stmt: ASTStatement) => T, + callback: (acc: T, stmt: AstStatement) => T, ): T { - function traverseStatement(acc: T, stmt: ASTStatement): T { + function traverseStatement(acc: T, stmt: AstStatement): T { acc = callback(acc, stmt); switch (stmt.kind) { @@ -549,7 +551,7 @@ export function foldStatements( return acc; } - function traverseNode(acc: T, node: ASTNode): T { + function traverseNode(acc: T, node: AstNode): T { switch (node.kind) { case "module": node.items.forEach((entry) => { @@ -557,8 +559,8 @@ export function foldStatements( }); break; case "function_def": - case "def_init_function": - case "def_receive": + case "contract_init": + case "receiver": if (node.statements) { node.statements.forEach((stmt) => { acc = traverseStatement(acc, stmt); @@ -587,10 +589,10 @@ export function foldStatements( break; case "op_binary": case "op_unary": - case "op_field": - case "op_call": - case "op_static_call": - case "op_new": + case "field_access": + case "method_call": + case "static_call": + case "struct_instance": case "init_of": case "conditional": case "string": @@ -598,18 +600,18 @@ export function foldStatements( case "boolean": case "id": case "null": - case "new_parameter": + case "struct_field_initializer": case "typed_parameter": - case "type_ref_simple": - case "type_ref_map": - case "type_ref_bounced": + case "type_id": + case "map_type": + case "bounced_message_type": case "native_function_decl": case "function_decl": case "struct_decl": case "message_decl": case "constant_def": case "constant_decl": - case "def_field": + case "field_decl": case "import": case "primitive_type_decl": // Do nothing diff --git a/src/grammar/store.ts b/src/grammar/store.ts index b3d7ac977..1f5faf1bb 100644 --- a/src/grammar/store.ts +++ b/src/grammar/store.ts @@ -3,7 +3,7 @@ import { AstConstantDef, AstFunctionDef, AstNativeFunctionDecl, - ASTType, + AstTypeDecl, } from "./ast"; import { CompilerContext, createContextStore } from "../context"; import { ItemOrigin, parse } from "./grammar"; @@ -21,7 +21,7 @@ export type ASTStore = { funcSources: { code: string; path: string }[]; functions: (AstFunctionDef | AstNativeFunctionDecl)[]; constants: AstConstantDef[]; - types: ASTType[]; + types: AstTypeDecl[]; }; const store = createContextStore(); @@ -62,7 +62,7 @@ export function openContext( parsedPrograms?: AstModule[], ): CompilerContext { const programs = parsedPrograms ? parsedPrograms : parseModules(sources); - const types: ASTType[] = []; + const types: AstTypeDecl[] = []; const functions: (AstNativeFunctionDecl | AstFunctionDef)[] = []; const constants: AstConstantDef[] = []; for (const program of programs) { diff --git a/src/storage/__snapshots__/resolveAllocation.spec.ts.snap b/src/storage/__snapshots__/resolveAllocation.spec.ts.snap index 2d55253fd..8234d108c 100644 --- a/src/storage/__snapshots__/resolveAllocation.spec.ts.snap +++ b/src/storage/__snapshots__/resolveAllocation.spec.ts.snap @@ -82,61 +82,49 @@ exports[`resolveAllocation should write program 1`] = ` "fields": [ { "as": null, - "id": 34, - "init": null, - "kind": "def_field", + "id": 31, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 31, + "id": 29, "kind": "id", "loc": SrcInfo {}, "text": "x", }, "type": { - "id": 33, - "kind": "type_ref_simple", + "id": 30, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 32, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 38, - "init": null, - "kind": "def_field", + "id": 34, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 35, + "id": 32, "kind": "id", "loc": SrcInfo {}, "text": "y", }, "type": { - "id": 37, - "kind": "type_ref_simple", + "id": 33, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 36, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 39, + "id": 35, "kind": "struct_decl", "loc": SrcInfo {}, "name": { - "id": 30, - "kind": "id", + "id": 28, + "kind": "type_id", "loc": SrcInfo {}, "text": "Point", }, @@ -157,27 +145,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 34, - "init": null, - "kind": "def_field", + "id": 31, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 31, + "id": 29, "kind": "id", "loc": SrcInfo {}, "text": "x", }, "type": { - "id": 33, - "kind": "type_ref_simple", + "id": 30, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 32, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -203,27 +185,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 38, - "init": null, - "kind": "def_field", + "id": 34, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 35, + "id": 32, "kind": "id", "loc": SrcInfo {}, "text": "y", }, "type": { - "id": 37, - "kind": "type_ref_simple", + "id": 33, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 36, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -312,36 +288,30 @@ exports[`resolveAllocation should write program 1`] = ` "fields": [ { "as": null, - "id": 44, - "init": null, - "kind": "def_field", + "id": 39, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 41, + "id": 37, "kind": "id", "loc": SrcInfo {}, "text": "z", }, "type": { - "id": 43, - "kind": "type_ref_simple", + "id": 38, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 42, - "kind": "id", - "loc": SrcInfo {}, - "text": "Point", - }, - "optional": false, + "text": "Point", }, }, ], - "id": 45, + "id": 40, "kind": "struct_decl", "loc": SrcInfo {}, "name": { - "id": 40, - "kind": "id", + "id": 36, + "kind": "type_id", "loc": SrcInfo {}, "text": "Point2", }, @@ -361,27 +331,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 44, - "init": null, - "kind": "def_field", + "id": 39, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 41, + "id": 37, "kind": "id", "loc": SrcInfo {}, "text": "z", }, "type": { - "id": 43, - "kind": "type_ref_simple", + "id": 38, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 42, - "kind": "id", - "loc": SrcInfo {}, - "text": "Point", - }, - "optional": false, + "text": "Point", }, }, "default": undefined, @@ -514,9 +478,9 @@ exports[`resolveAllocation should write program 1`] = ` "fields": [ { "as": null, - "id": 24, - "init": null, - "kind": "def_field", + "id": 23, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { "id": 21, @@ -525,50 +489,38 @@ exports[`resolveAllocation should write program 1`] = ` "text": "a", }, "type": { - "id": 23, - "kind": "type_ref_simple", + "id": 22, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 22, - "kind": "id", - "loc": SrcInfo {}, - "text": "Point", - }, - "optional": false, + "text": "Point", }, }, { "as": null, - "id": 28, - "init": null, - "kind": "def_field", + "id": 26, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 25, + "id": 24, "kind": "id", "loc": SrcInfo {}, "text": "b", }, "type": { - "id": 27, - "kind": "type_ref_simple", + "id": 25, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 26, - "kind": "id", - "loc": SrcInfo {}, - "text": "Point2", - }, - "optional": false, + "text": "Point2", }, }, ], - "id": 29, + "id": 27, "kind": "struct_decl", "loc": SrcInfo {}, "name": { "id": 20, - "kind": "id", + "kind": "type_id", "loc": SrcInfo {}, "text": "Point3", }, @@ -588,9 +540,9 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 24, - "init": null, - "kind": "def_field", + "id": 23, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { "id": 21, @@ -599,16 +551,10 @@ exports[`resolveAllocation should write program 1`] = ` "text": "a", }, "type": { - "id": 23, - "kind": "type_ref_simple", + "id": 22, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 22, - "kind": "id", - "loc": SrcInfo {}, - "text": "Point", - }, - "optional": false, + "text": "Point", }, }, "default": undefined, @@ -633,27 +579,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 28, - "init": null, - "kind": "def_field", + "id": 26, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 25, + "id": 24, "kind": "id", "loc": SrcInfo {}, "text": "b", }, "type": { - "id": 27, - "kind": "type_ref_simple", + "id": 25, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 26, - "kind": "id", - "loc": SrcInfo {}, - "text": "Point2", - }, - "optional": false, + "text": "Point2", }, }, "default": undefined, @@ -1038,286 +978,220 @@ exports[`resolveAllocation should write program 1`] = ` "fields": [ { "as": null, - "id": 50, - "init": null, - "kind": "def_field", + "id": 44, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 47, + "id": 42, "kind": "id", "loc": SrcInfo {}, "text": "a", }, "type": { - "id": 49, - "kind": "type_ref_simple", + "id": 43, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 48, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 54, - "init": null, - "kind": "def_field", + "id": 47, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 51, + "id": 45, "kind": "id", "loc": SrcInfo {}, "text": "b", }, "type": { - "id": 53, - "kind": "type_ref_simple", + "id": 46, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 52, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 58, - "init": null, - "kind": "def_field", + "id": 50, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 55, + "id": 48, "kind": "id", "loc": SrcInfo {}, "text": "c", }, "type": { - "id": 57, - "kind": "type_ref_simple", + "id": 49, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 56, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 62, - "init": null, - "kind": "def_field", + "id": 53, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 59, + "id": 51, "kind": "id", "loc": SrcInfo {}, "text": "d", }, "type": { - "id": 61, - "kind": "type_ref_simple", + "id": 52, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 60, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 66, - "init": null, - "kind": "def_field", + "id": 56, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 63, + "id": 54, "kind": "id", "loc": SrcInfo {}, "text": "e", }, "type": { - "id": 65, - "kind": "type_ref_simple", + "id": 55, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 64, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 70, - "init": null, - "kind": "def_field", + "id": 59, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 67, + "id": 57, "kind": "id", "loc": SrcInfo {}, "text": "f", }, "type": { - "id": 69, - "kind": "type_ref_simple", + "id": 58, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 68, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 74, - "init": null, - "kind": "def_field", + "id": 62, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 71, + "id": 60, "kind": "id", "loc": SrcInfo {}, "text": "g", }, "type": { - "id": 73, - "kind": "type_ref_simple", + "id": 61, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 72, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 78, - "init": null, - "kind": "def_field", + "id": 65, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 75, + "id": 63, "kind": "id", "loc": SrcInfo {}, "text": "h", }, "type": { - "id": 77, - "kind": "type_ref_simple", + "id": 64, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 76, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 82, - "init": null, - "kind": "def_field", + "id": 68, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 79, + "id": 66, "kind": "id", "loc": SrcInfo {}, "text": "i", }, "type": { - "id": 81, - "kind": "type_ref_simple", + "id": 67, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 80, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 86, - "init": null, - "kind": "def_field", + "id": 71, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 83, + "id": 69, "kind": "id", "loc": SrcInfo {}, "text": "j", }, "type": { - "id": 85, - "kind": "type_ref_simple", + "id": 70, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 84, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 90, - "init": null, - "kind": "def_field", + "id": 74, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 87, + "id": 72, "kind": "id", "loc": SrcInfo {}, "text": "k", }, "type": { - "id": 89, - "kind": "type_ref_simple", + "id": 73, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 88, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 91, + "id": 75, "kind": "struct_decl", "loc": SrcInfo {}, "name": { - "id": 46, - "kind": "id", + "id": 41, + "kind": "type_id", "loc": SrcInfo {}, "text": "Deep", }, @@ -1338,27 +1212,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 50, - "init": null, - "kind": "def_field", + "id": 44, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 47, + "id": 42, "kind": "id", "loc": SrcInfo {}, "text": "a", }, "type": { - "id": 49, - "kind": "type_ref_simple", + "id": 43, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 48, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -1384,27 +1252,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 54, - "init": null, - "kind": "def_field", + "id": 47, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 51, + "id": 45, "kind": "id", "loc": SrcInfo {}, "text": "b", }, "type": { - "id": 53, - "kind": "type_ref_simple", + "id": 46, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 52, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -1430,27 +1292,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 58, - "init": null, - "kind": "def_field", + "id": 50, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 55, + "id": 48, "kind": "id", "loc": SrcInfo {}, "text": "c", }, "type": { - "id": 57, - "kind": "type_ref_simple", + "id": 49, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 56, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -1476,27 +1332,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 62, - "init": null, - "kind": "def_field", + "id": 53, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 59, + "id": 51, "kind": "id", "loc": SrcInfo {}, "text": "d", }, "type": { - "id": 61, - "kind": "type_ref_simple", + "id": 52, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 60, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -1522,27 +1372,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 66, - "init": null, - "kind": "def_field", + "id": 56, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 63, + "id": 54, "kind": "id", "loc": SrcInfo {}, "text": "e", }, "type": { - "id": 65, - "kind": "type_ref_simple", + "id": 55, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 64, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -1568,27 +1412,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 70, - "init": null, - "kind": "def_field", + "id": 59, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 67, + "id": 57, "kind": "id", "loc": SrcInfo {}, "text": "f", }, "type": { - "id": 69, - "kind": "type_ref_simple", + "id": 58, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 68, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -1614,27 +1452,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 74, - "init": null, - "kind": "def_field", + "id": 62, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 71, + "id": 60, "kind": "id", "loc": SrcInfo {}, "text": "g", }, "type": { - "id": 73, - "kind": "type_ref_simple", + "id": 61, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 72, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -1660,27 +1492,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 78, - "init": null, - "kind": "def_field", + "id": 65, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 75, + "id": 63, "kind": "id", "loc": SrcInfo {}, "text": "h", }, "type": { - "id": 77, - "kind": "type_ref_simple", + "id": 64, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 76, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -1706,27 +1532,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 82, - "init": null, - "kind": "def_field", + "id": 68, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 79, + "id": 66, "kind": "id", "loc": SrcInfo {}, "text": "i", }, "type": { - "id": 81, - "kind": "type_ref_simple", + "id": 67, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 80, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -1752,27 +1572,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 86, - "init": null, - "kind": "def_field", + "id": 71, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 83, + "id": 69, "kind": "id", "loc": SrcInfo {}, "text": "j", }, "type": { - "id": 85, - "kind": "type_ref_simple", + "id": 70, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 84, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -1798,27 +1612,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 90, - "init": null, - "kind": "def_field", + "id": 74, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 87, + "id": 72, "kind": "id", "loc": SrcInfo {}, "text": "k", }, "type": { - "id": 89, - "kind": "type_ref_simple", + "id": 73, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 88, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -1995,86 +1803,68 @@ exports[`resolveAllocation should write program 1`] = ` "fields": [ { "as": null, - "id": 96, - "init": null, - "kind": "def_field", + "id": 79, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 93, + "id": 77, "kind": "id", "loc": SrcInfo {}, "text": "a", }, "type": { - "id": 95, - "kind": "type_ref_simple", + "id": 78, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 94, - "kind": "id", - "loc": SrcInfo {}, - "text": "Deep", - }, - "optional": false, + "text": "Deep", }, }, { "as": null, - "id": 100, - "init": null, - "kind": "def_field", + "id": 82, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 97, + "id": 80, "kind": "id", "loc": SrcInfo {}, "text": "b", }, "type": { - "id": 99, - "kind": "type_ref_simple", + "id": 81, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 98, - "kind": "id", - "loc": SrcInfo {}, - "text": "Deep", - }, - "optional": false, + "text": "Deep", }, }, { "as": null, - "id": 104, - "init": null, - "kind": "def_field", + "id": 85, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 101, + "id": 83, "kind": "id", "loc": SrcInfo {}, "text": "c", }, "type": { - "id": 103, - "kind": "type_ref_simple", + "id": 84, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 102, - "kind": "id", - "loc": SrcInfo {}, - "text": "Deep", - }, - "optional": false, + "text": "Deep", }, }, ], - "id": 105, + "id": 86, "kind": "struct_decl", "loc": SrcInfo {}, "name": { - "id": 92, - "kind": "id", + "id": 76, + "kind": "type_id", "loc": SrcInfo {}, "text": "Deep2", }, @@ -2094,27 +1884,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 96, - "init": null, - "kind": "def_field", + "id": 79, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 93, + "id": 77, "kind": "id", "loc": SrcInfo {}, "text": "a", }, "type": { - "id": 95, - "kind": "type_ref_simple", + "id": 78, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 94, - "kind": "id", - "loc": SrcInfo {}, - "text": "Deep", - }, - "optional": false, + "text": "Deep", }, }, "default": undefined, @@ -2139,27 +1923,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 100, - "init": null, - "kind": "def_field", + "id": 82, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 97, + "id": 80, "kind": "id", "loc": SrcInfo {}, "text": "b", }, "type": { - "id": 99, - "kind": "type_ref_simple", + "id": 81, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 98, - "kind": "id", - "loc": SrcInfo {}, - "text": "Deep", - }, - "optional": false, + "text": "Deep", }, }, "default": undefined, @@ -2184,27 +1962,21 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 104, - "init": null, - "kind": "def_field", + "id": 85, + "initializer": null, + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 101, + "id": 83, "kind": "id", "loc": SrcInfo {}, "text": "c", }, "type": { - "id": 103, - "kind": "type_ref_simple", + "id": 84, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 102, - "kind": "id", - "loc": SrcInfo {}, - "text": "Deep", - }, - "optional": false, + "text": "Deep", }, }, "default": undefined, @@ -2286,97 +2058,79 @@ exports[`resolveAllocation should write program 1`] = ` "declarations": [ { "as": null, - "id": 111, - "init": { - "id": 110, + "id": 91, + "initializer": { + "id": 90, "kind": "number", "loc": SrcInfo {}, "value": 0n, }, - "kind": "def_field", + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 107, + "id": 88, "kind": "id", "loc": SrcInfo {}, "text": "v", }, "type": { - "id": 109, - "kind": "type_ref_simple", + "id": 89, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 108, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { - "id": 112, - "kind": "def_init_function", + "id": 92, + "kind": "contract_init", "loc": SrcInfo {}, "params": [], "statements": [], }, { "attributes": [], - "id": 122, + "id": 100, "kind": "function_def", "loc": SrcInfo {}, "name": { - "id": 113, + "id": 93, "kind": "id", "loc": SrcInfo {}, "text": "main", }, "params": [ { - "id": 117, + "id": 96, "kind": "typed_parameter", "loc": SrcInfo {}, "name": { - "id": 114, + "id": 94, "kind": "id", "loc": SrcInfo {}, "text": "a", }, "type": { - "id": 116, - "kind": "type_ref_simple", + "id": 95, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 115, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { - "id": 121, + "id": 99, "kind": "typed_parameter", "loc": SrcInfo {}, "name": { - "id": 118, + "id": 97, "kind": "id", "loc": SrcInfo {}, "text": "b", }, "type": { - "id": 120, - "kind": "type_ref_simple", + "id": 98, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 119, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], @@ -2384,11 +2138,11 @@ exports[`resolveAllocation should write program 1`] = ` "statements": [], }, ], - "id": 123, + "id": 101, "kind": "contract", "loc": SrcInfo {}, "name": { - "id": 106, + "id": 87, "kind": "id", "loc": SrcInfo {}, "text": "Sample", @@ -2411,32 +2165,26 @@ exports[`resolveAllocation should write program 1`] = ` "as": null, "ast": { "as": null, - "id": 111, - "init": { - "id": 110, + "id": 91, + "initializer": { + "id": 90, "kind": "number", "loc": SrcInfo {}, "value": 0n, }, - "kind": "def_field", + "kind": "field_decl", "loc": SrcInfo {}, "name": { - "id": 107, + "id": 88, "kind": "id", "loc": SrcInfo {}, "text": "v", }, "type": { - "id": 109, - "kind": "type_ref_simple", + "id": 89, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 108, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": 0n, @@ -2454,60 +2202,48 @@ exports[`resolveAllocation should write program 1`] = ` "main" => { "ast": { "attributes": [], - "id": 122, + "id": 100, "kind": "function_def", "loc": SrcInfo {}, "name": { - "id": 113, + "id": 93, "kind": "id", "loc": SrcInfo {}, "text": "main", }, "params": [ { - "id": 117, + "id": 96, "kind": "typed_parameter", "loc": SrcInfo {}, "name": { - "id": 114, + "id": 94, "kind": "id", "loc": SrcInfo {}, "text": "a", }, "type": { - "id": 116, - "kind": "type_ref_simple", + "id": 95, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 115, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { - "id": 121, + "id": 99, "kind": "typed_parameter", "loc": SrcInfo {}, "name": { - "id": 118, + "id": 97, "kind": "id", "loc": SrcInfo {}, "text": "b", }, "type": { - "id": 120, - "kind": "type_ref_simple", + "id": 98, + "kind": "type_id", "loc": SrcInfo {}, - "name": { - "id": 119, - "kind": "id", - "loc": SrcInfo {}, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], @@ -2526,7 +2262,7 @@ exports[`resolveAllocation should write program 1`] = ` { "loc": SrcInfo {}, "name": { - "id": 114, + "id": 94, "kind": "id", "loc": SrcInfo {}, "text": "a", @@ -2540,7 +2276,7 @@ exports[`resolveAllocation should write program 1`] = ` { "loc": SrcInfo {}, "name": { - "id": 118, + "id": 97, "kind": "id", "loc": SrcInfo {}, "text": "b", @@ -2561,8 +2297,8 @@ exports[`resolveAllocation should write program 1`] = ` "header": null, "init": { "ast": { - "id": 112, - "kind": "def_init_function", + "id": 92, + "kind": "contract_init", "loc": SrcInfo {}, "params": [], "statements": [], diff --git a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap index d6ee84583..e9c172f91 100644 --- a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap +++ b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap @@ -181,7 +181,7 @@ Line 13, col 3: `; exports[`resolveDescriptors should fail descriptors for contract-receiver-optional-msg 1`] = ` -":13:3: Receive function cannot have optional parameter +":13:3: Receive function can only accept non-optional message types Line 13, col 3: 12 | contract Pair { > 13 | receive(src: B?) { @@ -392,14 +392,14 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-slic "fields": [ { "as": { - "id": 11, + "id": 10, "kind": "id", "loc": uint32, "text": "uint32", }, - "id": 12, - "init": null, - "kind": "def_field", + "id": 11, + "initializer": null, + "kind": "field_decl", "loc": a: Int as uint32, "name": { "id": 8, @@ -408,27 +408,21 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-slic "text": "a", }, "type": { - "id": 10, - "kind": "type_ref_simple", + "id": 9, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 13, + "id": 12, "kind": "message_decl", "loc": message A { a: Int as uint32; }, "name": { "id": 7, - "kind": "id", + "kind": "type_id", "loc": A, "text": "A", }, @@ -450,14 +444,14 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-slic "as": "uint32", "ast": { "as": { - "id": 11, + "id": 10, "kind": "id", "loc": uint32, "text": "uint32", }, - "id": 12, - "init": null, - "kind": "def_field", + "id": 11, + "initializer": null, + "kind": "field_decl", "loc": a: Int as uint32, "name": { "id": 8, @@ -466,16 +460,10 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-slic "text": "a", }, "type": { - "id": 10, - "kind": "type_ref_simple", + "id": 9, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -544,7 +532,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-slic "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -573,7 +561,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-slic "loc": primitive Slice;, "name": { "id": 3, - "kind": "id", + "kind": "type_id", "loc": Slice, "text": "Slice", }, @@ -600,82 +588,70 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-slic "attributes": [], "declarations": [ { - "id": 15, - "kind": "def_init_function", + "id": 14, + "kind": "contract_init", "loc": init() {}, "params": [], "statements": [], }, { - "id": 20, - "kind": "def_receive", + "id": 18, + "kind": "receiver", "loc": receive(src: A) { }, "selector": { "kind": "internal-simple", "param": { - "id": 19, + "id": 17, "kind": "typed_parameter", "loc": src: A, "name": { - "id": 16, + "id": 15, "kind": "id", "loc": src, "text": "src", }, "type": { - "id": 18, - "kind": "type_ref_simple", + "id": 16, + "kind": "type_id", "loc": A, - "name": { - "id": 17, - "kind": "id", - "loc": A, - "text": "A", - }, - "optional": false, + "text": "A", }, }, }, "statements": [], }, { - "id": 25, - "kind": "def_receive", + "id": 22, + "kind": "receiver", "loc": bounced(src: Slice) { }, "selector": { "kind": "bounce", "param": { - "id": 24, + "id": 21, "kind": "typed_parameter", "loc": src: Slice, "name": { - "id": 21, + "id": 19, "kind": "id", "loc": src, "text": "src", }, "type": { - "id": 23, - "kind": "type_ref_simple", + "id": 20, + "kind": "type_id", "loc": Slice, - "name": { - "id": 22, - "kind": "id", - "loc": Slice, - "text": "Slice", - }, - "optional": false, + "text": "Slice", }, }, }, "statements": [], }, ], - "id": 26, + "id": 23, "kind": "contract", "loc": contract Test { init() {} @@ -688,7 +664,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-slic } }, "name": { - "id": 14, + "id": 13, "kind": "id", "loc": Test, "text": "Test", @@ -702,8 +678,8 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-slic "header": null, "init": { "ast": { - "id": 15, - "kind": "def_init_function", + "id": 14, + "kind": "contract_init", "loc": init() {}, "params": [], "statements": [], @@ -718,34 +694,28 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-slic "receivers": [ { "ast": { - "id": 20, - "kind": "def_receive", + "id": 18, + "kind": "receiver", "loc": receive(src: A) { }, "selector": { "kind": "internal-simple", "param": { - "id": 19, + "id": 17, "kind": "typed_parameter", "loc": src: A, "name": { - "id": 16, + "id": 15, "kind": "id", "loc": src, "text": "src", }, "type": { - "id": 18, - "kind": "type_ref_simple", + "id": 16, + "kind": "type_id", "loc": A, - "name": { - "id": 17, - "kind": "id", - "loc": A, - "text": "A", - }, - "optional": false, + "text": "A", }, }, }, @@ -754,7 +724,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-slic "selector": { "kind": "internal-binary", "name": { - "id": 16, + "id": 15, "kind": "id", "loc": src, "text": "src", @@ -764,34 +734,28 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-slic }, { "ast": { - "id": 25, - "kind": "def_receive", + "id": 22, + "kind": "receiver", "loc": bounced(src: Slice) { }, "selector": { "kind": "bounce", "param": { - "id": 24, + "id": 21, "kind": "typed_parameter", "loc": src: Slice, "name": { - "id": 21, + "id": 19, "kind": "id", "loc": src, "text": "src", }, "type": { - "id": 23, - "kind": "type_ref_simple", + "id": 20, + "kind": "type_id", "loc": Slice, - "name": { - "id": 22, - "kind": "id", - "loc": Slice, - "text": "Slice", - }, - "optional": false, + "text": "Slice", }, }, }, @@ -800,7 +764,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-slic "selector": { "kind": "bounce-fallback", "name": { - "id": 21, + "id": 19, "kind": "id", "loc": src, "text": "src", @@ -860,14 +824,14 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- "fields": [ { "as": { - "id": 11, + "id": 10, "kind": "id", "loc": uint32, "text": "uint32", }, - "id": 12, - "init": null, - "kind": "def_field", + "id": 11, + "initializer": null, + "kind": "field_decl", "loc": a: Int as uint32, "name": { "id": 8, @@ -876,75 +840,57 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- "text": "a", }, "type": { - "id": 10, - "kind": "type_ref_simple", + "id": 9, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 16, - "init": null, - "kind": "def_field", + "id": 14, + "initializer": null, + "kind": "field_decl", "loc": b: Bool, "name": { - "id": 13, + "id": 12, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 15, - "kind": "type_ref_simple", + "id": 13, + "kind": "type_id", "loc": Bool, - "name": { - "id": 14, - "kind": "id", - "loc": Bool, - "text": "Bool", - }, - "optional": false, + "text": "Bool", }, }, { "as": { - "id": 20, + "id": 17, "kind": "id", "loc": uint256, "text": "uint256", }, - "id": 21, - "init": null, - "kind": "def_field", + "id": 18, + "initializer": null, + "kind": "field_decl", "loc": c: Int as uint256, "name": { - "id": 17, + "id": 15, "kind": "id", "loc": c, "text": "c", }, "type": { - "id": 19, - "kind": "type_ref_simple", + "id": 16, + "kind": "type_id", "loc": Int, - "name": { - "id": 18, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 22, + "id": 19, "kind": "message_decl", "loc": message A { a: Int as uint32; @@ -953,7 +899,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- }, "name": { "id": 7, - "kind": "id", + "kind": "type_id", "loc": A, "text": "A", }, @@ -975,14 +921,14 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- "as": "uint32", "ast": { "as": { - "id": 11, + "id": 10, "kind": "id", "loc": uint32, "text": "uint32", }, - "id": 12, - "init": null, - "kind": "def_field", + "id": 11, + "initializer": null, + "kind": "field_decl", "loc": a: Int as uint32, "name": { "id": 8, @@ -991,16 +937,10 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- "text": "a", }, "type": { - "id": 10, - "kind": "type_ref_simple", + "id": 9, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -1025,27 +965,21 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- "as": null, "ast": { "as": null, - "id": 16, - "init": null, - "kind": "def_field", + "id": 14, + "initializer": null, + "kind": "field_decl", "loc": b: Bool, "name": { - "id": 13, + "id": 12, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 15, - "kind": "type_ref_simple", + "id": 13, + "kind": "type_id", "loc": Bool, - "name": { - "id": 14, - "kind": "id", - "loc": Bool, - "text": "Bool", - }, - "optional": false, + "text": "Bool", }, }, "default": undefined, @@ -1071,32 +1005,26 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- "as": "uint256", "ast": { "as": { - "id": 20, + "id": 17, "kind": "id", "loc": uint256, "text": "uint256", }, - "id": 21, - "init": null, - "kind": "def_field", + "id": 18, + "initializer": null, + "kind": "field_decl", "loc": c: Int as uint256, "name": { - "id": 17, + "id": 15, "kind": "id", "loc": c, "text": "c", }, "type": { - "id": 19, - "kind": "type_ref_simple", + "id": 16, + "kind": "type_id", "loc": Int, - "name": { - "id": 18, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -1165,7 +1093,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- "loc": primitive Bool;, "name": { "id": 3, - "kind": "id", + "kind": "type_id", "loc": Bool, "text": "Bool", }, @@ -1194,7 +1122,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -1221,71 +1149,65 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- "attributes": [], "declarations": [ { - "id": 24, - "kind": "def_init_function", + "id": 21, + "kind": "contract_init", "loc": init() {}, "params": [], "statements": [], }, { - "id": 29, - "kind": "def_receive", + "id": 25, + "kind": "receiver", "loc": receive(src: A) { }, "selector": { "kind": "internal-simple", "param": { - "id": 28, + "id": 24, "kind": "typed_parameter", "loc": src: A, "name": { - "id": 25, + "id": 22, "kind": "id", "loc": src, "text": "src", }, "type": { - "id": 27, - "kind": "type_ref_simple", + "id": 23, + "kind": "type_id", "loc": A, - "name": { - "id": 26, - "kind": "id", - "loc": A, - "text": "A", - }, - "optional": false, + "text": "A", }, }, }, "statements": [], }, { - "id": 41, - "kind": "def_receive", + "id": 36, + "kind": "receiver", "loc": bounced(src: bounced) { let x: Int = src.c; }, "selector": { "kind": "bounce", "param": { - "id": 33, + "id": 29, "kind": "typed_parameter", "loc": src: bounced, "name": { - "id": 30, + "id": 26, "kind": "id", "loc": src, "text": "src", }, "type": { - "id": 32, - "kind": "type_ref_bounced", + "id": 28, + "kind": "bounced_message_type", "loc": bounced, - "name": { - "id": 31, - "kind": "id", + "messageType": { + "id": 27, + "kind": "type_id", "loc": A, "text": "A", }, @@ -1295,48 +1217,42 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- "statements": [ { "expression": { - "id": 39, - "kind": "op_field", - "loc": src.c, - "name": { - "id": 38, - "kind": "id", - "loc": c, - "text": "c", - }, - "src": { - "id": 37, + "aggregate": { + "id": 32, "kind": "id", "loc": src, "text": "src", }, + "field": { + "id": 33, + "kind": "id", + "loc": c, + "text": "c", + }, + "id": 34, + "kind": "field_access", + "loc": src.c, }, - "id": 40, + "id": 35, "kind": "statement_let", "loc": let x: Int = src.c;, "name": { - "id": 34, + "id": 30, "kind": "id", "loc": x, "text": "x", }, "type": { - "id": 36, - "kind": "type_ref_simple", + "id": 31, + "kind": "type_id", "loc": Int, - "name": { - "id": 35, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], }, ], - "id": 42, + "id": 37, "kind": "contract", "loc": contract Test { init() {} @@ -1349,7 +1265,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- } }, "name": { - "id": 23, + "id": 20, "kind": "id", "loc": Test, "text": "Test", @@ -1363,8 +1279,8 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- "header": null, "init": { "ast": { - "id": 24, - "kind": "def_init_function", + "id": 21, + "kind": "contract_init", "loc": init() {}, "params": [], "statements": [], @@ -1379,34 +1295,28 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- "receivers": [ { "ast": { - "id": 29, - "kind": "def_receive", + "id": 25, + "kind": "receiver", "loc": receive(src: A) { }, "selector": { "kind": "internal-simple", "param": { - "id": 28, + "id": 24, "kind": "typed_parameter", "loc": src: A, "name": { - "id": 25, + "id": 22, "kind": "id", "loc": src, "text": "src", }, "type": { - "id": 27, - "kind": "type_ref_simple", + "id": 23, + "kind": "type_id", "loc": A, - "name": { - "id": 26, - "kind": "id", - "loc": A, - "text": "A", - }, - "optional": false, + "text": "A", }, }, }, @@ -1415,7 +1325,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- "selector": { "kind": "internal-binary", "name": { - "id": 25, + "id": 22, "kind": "id", "loc": src, "text": "src", @@ -1425,30 +1335,30 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- }, { "ast": { - "id": 41, - "kind": "def_receive", + "id": 36, + "kind": "receiver", "loc": bounced(src: bounced) { let x: Int = src.c; }, "selector": { "kind": "bounce", "param": { - "id": 33, + "id": 29, "kind": "typed_parameter", "loc": src: bounced, "name": { - "id": 30, + "id": 26, "kind": "id", "loc": src, "text": "src", }, "type": { - "id": 32, - "kind": "type_ref_bounced", + "id": 28, + "kind": "bounced_message_type", "loc": bounced, - "name": { - "id": 31, - "kind": "id", + "messageType": { + "id": 27, + "kind": "type_id", "loc": A, "text": "A", }, @@ -1458,42 +1368,36 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- "statements": [ { "expression": { - "id": 39, - "kind": "op_field", - "loc": src.c, - "name": { - "id": 38, - "kind": "id", - "loc": c, - "text": "c", - }, - "src": { - "id": 37, + "aggregate": { + "id": 32, "kind": "id", "loc": src, "text": "src", }, + "field": { + "id": 33, + "kind": "id", + "loc": c, + "text": "c", + }, + "id": 34, + "kind": "field_access", + "loc": src.c, }, - "id": 40, + "id": 35, "kind": "statement_let", "loc": let x: Int = src.c;, "name": { - "id": 34, + "id": 30, "kind": "id", "loc": x, "text": "x", }, "type": { - "id": 36, - "kind": "type_ref_simple", + "id": 31, + "kind": "type_id", "loc": Int, - "name": { - "id": 35, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], @@ -1502,7 +1406,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-bounced-too- "bounced": true, "kind": "bounce-binary", "name": { - "id": 30, + "id": 26, "kind": "id", "loc": src, "text": "src", @@ -1597,7 +1501,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -1630,7 +1534,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "type": "abstract", }, ], - "id": 9, + "id": 8, "kind": "constant_decl", "loc": abstract const Foo: Int;, "name": { @@ -1640,20 +1544,14 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "text": "Foo", }, "type": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 10, + "id": 9, "kind": "trait", "loc": trait T { abstract const Foo: Int; @@ -1675,7 +1573,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "type": "abstract", }, ], - "id": 9, + "id": 8, "kind": "constant_decl", "loc": abstract const Foo: Int;, "name": { @@ -1685,16 +1583,10 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "text": "Foo", }, "type": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "loc": abstract const Foo: Int;, @@ -1767,9 +1659,9 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "type": "overrides", }, ], - "id": 16, + "id": 14, "initializer": { - "id": 15, + "id": 13, "kind": "number", "loc": 42, "value": 42n, @@ -1777,39 +1669,33 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "kind": "constant_def", "loc": override const Foo: Int = 42;, "name": { - "id": 12, + "id": 11, "kind": "id", "loc": Foo, "text": "Foo", }, "type": { - "id": 14, - "kind": "type_ref_simple", + "id": 12, + "kind": "type_id", "loc": Int, - "name": { - "id": 13, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 18, + "id": 16, "kind": "contract", "loc": contract TestContract with T { override const Foo: Int = 42; }, "name": { - "id": 11, + "id": 10, "kind": "id", "loc": TestContract, "text": "TestContract", }, "traits": [ { - "id": 17, + "id": 15, "kind": "id", "loc": T, "text": "T", @@ -1825,9 +1711,9 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "type": "overrides", }, ], - "id": 16, + "id": 14, "initializer": { - "id": 15, + "id": 13, "kind": "number", "loc": 42, "value": 42n, @@ -1835,22 +1721,16 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "kind": "constant_def", "loc": override const Foo: Int = 42;, "name": { - "id": 12, + "id": 11, "kind": "id", "loc": Foo, "text": "Foo", }, "type": { - "id": 14, - "kind": "type_ref_simple", + "id": 12, + "kind": "type_id", "loc": Int, - "name": { - "id": 13, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "loc": override const Foo: Int = 42;, @@ -1869,8 +1749,8 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "header": null, "init": { "ast": { - "id": 20, - "kind": "def_init_function", + "id": 18, + "kind": "contract_init", "loc": contract TestContract with T { override const Foo: Int = 42; }, @@ -1931,7 +1811,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "type": "abstract", }, ], - "id": 9, + "id": 8, "kind": "constant_decl", "loc": abstract const Foo: Int;, "name": { @@ -1941,20 +1821,14 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "text": "Foo", }, "type": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 10, + "id": 9, "kind": "trait", "loc": trait T { abstract const Foo: Int; @@ -1976,7 +1850,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "type": "abstract", }, ], - "id": 9, + "id": 8, "kind": "constant_decl", "loc": abstract const Foo: Int;, "name": { @@ -1986,16 +1860,10 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "text": "Foo", }, "type": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "loc": abstract const Foo: Int;, @@ -2106,7 +1974,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -2139,9 +2007,9 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "type": "virtual", }, ], - "id": 10, + "id": 9, "initializer": { - "id": 9, + "id": 8, "kind": "number", "loc": 41, "value": 41n, @@ -2155,20 +2023,14 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "text": "Foo", }, "type": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 11, + "id": 10, "kind": "trait", "loc": trait T { virtual const Foo: Int = 41; @@ -2190,9 +2052,9 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "type": "virtual", }, ], - "id": 10, + "id": 9, "initializer": { - "id": 9, + "id": 8, "kind": "number", "loc": 41, "value": 41n, @@ -2206,16 +2068,10 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "text": "Foo", }, "type": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "loc": virtual const Foo: Int = 41;, @@ -2288,9 +2144,9 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "type": "overrides", }, ], - "id": 17, + "id": 15, "initializer": { - "id": 16, + "id": 14, "kind": "number", "loc": 42, "value": 42n, @@ -2298,39 +2154,33 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "kind": "constant_def", "loc": override const Foo: Int = 42;, "name": { - "id": 13, + "id": 12, "kind": "id", "loc": Foo, "text": "Foo", }, "type": { - "id": 15, - "kind": "type_ref_simple", + "id": 13, + "kind": "type_id", "loc": Int, - "name": { - "id": 14, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 19, + "id": 17, "kind": "contract", "loc": contract TestContract with T { override const Foo: Int = 42; }, "name": { - "id": 12, + "id": 11, "kind": "id", "loc": TestContract, "text": "TestContract", }, "traits": [ { - "id": 18, + "id": 16, "kind": "id", "loc": T, "text": "T", @@ -2346,9 +2196,9 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "type": "overrides", }, ], - "id": 17, + "id": 15, "initializer": { - "id": 16, + "id": 14, "kind": "number", "loc": 42, "value": 42n, @@ -2356,22 +2206,16 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "kind": "constant_def", "loc": override const Foo: Int = 42;, "name": { - "id": 13, + "id": 12, "kind": "id", "loc": Foo, "text": "Foo", }, "type": { - "id": 15, - "kind": "type_ref_simple", + "id": 13, + "kind": "type_id", "loc": Int, - "name": { - "id": 14, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "loc": override const Foo: Int = 42;, @@ -2390,8 +2234,8 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "header": null, "init": { "ast": { - "id": 21, - "kind": "def_init_function", + "id": 19, + "kind": "contract_init", "loc": contract TestContract with T { override const Foo: Int = 42; }, @@ -2452,9 +2296,9 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "type": "virtual", }, ], - "id": 10, + "id": 9, "initializer": { - "id": 9, + "id": 8, "kind": "number", "loc": 41, "value": 41n, @@ -2468,20 +2312,14 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "text": "Foo", }, "type": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 11, + "id": 10, "kind": "trait", "loc": trait T { virtual const Foo: Int = 41; @@ -2503,9 +2341,9 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "type": "virtual", }, ], - "id": 10, + "id": 9, "initializer": { - "id": 9, + "id": 8, "kind": "number", "loc": 41, "value": 41n, @@ -2519,16 +2357,10 @@ exports[`resolveDescriptors should resolve descriptors for contract-const-overri "text": "Foo", }, "type": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "loc": virtual const Foo: Int = 41;, @@ -2605,14 +2437,14 @@ exports[`resolveDescriptors should resolve descriptors for contract-external-fal "fields": [ { "as": { - "id": 9, + "id": 8, "kind": "id", "loc": uint32, "text": "uint32", }, - "id": 10, - "init": null, - "kind": "def_field", + "id": 9, + "initializer": null, + "kind": "field_decl", "loc": a: Int as uint32, "name": { "id": 6, @@ -2621,27 +2453,21 @@ exports[`resolveDescriptors should resolve descriptors for contract-external-fal "text": "a", }, "type": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 11, + "id": 10, "kind": "message_decl", "loc": message A { a: Int as uint32; }, "name": { "id": 5, - "kind": "id", + "kind": "type_id", "loc": A, "text": "A", }, @@ -2663,14 +2489,14 @@ exports[`resolveDescriptors should resolve descriptors for contract-external-fal "as": "uint32", "ast": { "as": { - "id": 9, + "id": 8, "kind": "id", "loc": uint32, "text": "uint32", }, - "id": 10, - "init": null, - "kind": "def_field", + "id": 9, + "initializer": null, + "kind": "field_decl", "loc": a: Int as uint32, "name": { "id": 6, @@ -2679,16 +2505,10 @@ exports[`resolveDescriptors should resolve descriptors for contract-external-fal "text": "a", }, "type": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -2757,7 +2577,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-external-fal "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -2784,54 +2604,48 @@ exports[`resolveDescriptors should resolve descriptors for contract-external-fal "attributes": [], "declarations": [ { - "id": 19, - "kind": "def_receive", + "id": 17, + "kind": "receiver", "loc": external(msg: A) { 42; }, "selector": { "kind": "external-simple", "param": { - "id": 16, + "id": 14, "kind": "typed_parameter", "loc": msg: A, "name": { - "id": 13, + "id": 12, "kind": "id", "loc": msg, "text": "msg", }, "type": { - "id": 15, - "kind": "type_ref_simple", + "id": 13, + "kind": "type_id", "loc": A, - "name": { - "id": 14, - "kind": "id", - "loc": A, - "text": "A", - }, - "optional": false, + "text": "A", }, }, }, "statements": [ { "expression": { - "id": 17, + "id": 15, "kind": "number", "loc": 42, "value": 42n, }, - "id": 18, + "id": 16, "kind": "statement_expression", "loc": 42;, }, ], }, { - "id": 22, - "kind": "def_receive", + "id": 20, + "kind": "receiver", "loc": external() { 42; }, @@ -2841,19 +2655,19 @@ exports[`resolveDescriptors should resolve descriptors for contract-external-fal "statements": [ { "expression": { - "id": 20, + "id": 18, "kind": "number", "loc": 42, "value": 42n, }, - "id": 21, + "id": 19, "kind": "statement_expression", "loc": 42;, }, ], }, ], - "id": 23, + "id": 21, "kind": "contract", "loc": contract Test { external(msg: A) { @@ -2865,7 +2679,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-external-fal } }, "name": { - "id": 12, + "id": 11, "kind": "id", "loc": Test, "text": "Test", @@ -2879,8 +2693,8 @@ exports[`resolveDescriptors should resolve descriptors for contract-external-fal "header": null, "init": { "ast": { - "id": 25, - "kind": "def_init_function", + "id": 23, + "kind": "contract_init", "loc": contract Test { external(msg: A) { 42; @@ -2903,46 +2717,40 @@ exports[`resolveDescriptors should resolve descriptors for contract-external-fal "receivers": [ { "ast": { - "id": 19, - "kind": "def_receive", + "id": 17, + "kind": "receiver", "loc": external(msg: A) { 42; }, "selector": { "kind": "external-simple", "param": { - "id": 16, + "id": 14, "kind": "typed_parameter", "loc": msg: A, "name": { - "id": 13, + "id": 12, "kind": "id", "loc": msg, "text": "msg", }, "type": { - "id": 15, - "kind": "type_ref_simple", + "id": 13, + "kind": "type_id", "loc": A, - "name": { - "id": 14, - "kind": "id", - "loc": A, - "text": "A", - }, - "optional": false, + "text": "A", }, }, }, "statements": [ { "expression": { - "id": 17, + "id": 15, "kind": "number", "loc": 42, "value": 42n, }, - "id": 18, + "id": 16, "kind": "statement_expression", "loc": 42;, }, @@ -2951,7 +2759,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-external-fal "selector": { "kind": "external-binary", "name": { - "id": 13, + "id": 12, "kind": "id", "loc": msg, "text": "msg", @@ -2961,8 +2769,8 @@ exports[`resolveDescriptors should resolve descriptors for contract-external-fal }, { "ast": { - "id": 22, - "kind": "def_receive", + "id": 20, + "kind": "receiver", "loc": external() { 42; }, @@ -2972,12 +2780,12 @@ exports[`resolveDescriptors should resolve descriptors for contract-external-fal "statements": [ { "expression": { - "id": 20, + "id": 18, "kind": "number", "loc": 42, "value": 42n, }, - "id": 21, + "id": 19, "kind": "statement_expression", "loc": 42;, }, @@ -3074,7 +2882,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -3111,7 +2919,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "type": "get", }, ], - "id": 9, + "id": 8, "kind": "function_decl", "loc": abstract get fun getter(): Int;, "name": { @@ -3122,20 +2930,14 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr }, "params": [], "return": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 10, + "id": 9, "kind": "trait", "loc": trait T { abstract get fun getter(): Int; @@ -3164,7 +2966,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "type": "get", }, ], - "id": 9, + "id": 8, "kind": "function_decl", "loc": abstract get fun getter(): Int;, "name": { @@ -3175,16 +2977,10 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr }, "params": [], "return": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "isAbstract": true, @@ -3265,57 +3061,51 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "type": "get", }, ], - "id": 17, + "id": 15, "kind": "function_def", "loc": override get fun getter(): Int { return 0 }, "name": { - "id": 12, + "id": 11, "kind": "id", "loc": getter, "text": "getter", }, "params": [], "return": { - "id": 14, - "kind": "type_ref_simple", + "id": 12, + "kind": "type_id", "loc": Int, - "name": { - "id": 13, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 15, + "id": 13, "kind": "number", "loc": 0, "value": 0n, }, - "id": 16, + "id": 14, "kind": "statement_return", "loc": return 0, }, ], }, ], - "id": 19, + "id": 17, "kind": "contract", "loc": contract TestContract with T { override get fun getter(): Int { return 0 } }, "name": { - "id": 11, + "id": 10, "kind": "id", "loc": TestContract, "text": "TestContract", }, "traits": [ { - "id": 18, + "id": 16, "kind": "id", "loc": T, "text": "T", @@ -3338,37 +3128,31 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "type": "get", }, ], - "id": 17, + "id": 15, "kind": "function_def", "loc": override get fun getter(): Int { return 0 }, "name": { - "id": 12, + "id": 11, "kind": "id", "loc": getter, "text": "getter", }, "params": [], "return": { - "id": 14, - "kind": "type_ref_simple", + "id": 12, + "kind": "type_id", "loc": Int, - "name": { - "id": 13, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 15, + "id": 13, "kind": "number", "loc": 0, "value": 0n, }, - "id": 16, + "id": 14, "kind": "statement_return", "loc": return 0, }, @@ -3394,8 +3178,8 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "header": null, "init": { "ast": { - "id": 21, - "kind": "def_init_function", + "id": 19, + "kind": "contract_init", "loc": contract TestContract with T { override get fun getter(): Int { return 0 } }, @@ -3460,7 +3244,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "type": "get", }, ], - "id": 9, + "id": 8, "kind": "function_decl", "loc": abstract get fun getter(): Int;, "name": { @@ -3471,20 +3255,14 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr }, "params": [], "return": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 10, + "id": 9, "kind": "trait", "loc": trait T { abstract get fun getter(): Int; @@ -3513,7 +3291,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "type": "get", }, ], - "id": 9, + "id": 8, "kind": "function_decl", "loc": abstract get fun getter(): Int;, "name": { @@ -3524,16 +3302,10 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr }, "params": [], "return": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "isAbstract": true, @@ -3648,7 +3420,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -3685,7 +3457,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "type": "get", }, ], - "id": 11, + "id": 10, "kind": "function_def", "loc": virtual get fun getter(): Int { return 42 }, "name": { @@ -3696,33 +3468,27 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr }, "params": [], "return": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 9, + "id": 8, "kind": "number", "loc": 42, "value": 42n, }, - "id": 10, + "id": 9, "kind": "statement_return", "loc": return 42, }, ], }, ], - "id": 12, + "id": 11, "kind": "trait", "loc": trait T { virtual get fun getter(): Int { return 42 } @@ -3751,7 +3517,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "type": "get", }, ], - "id": 11, + "id": 10, "kind": "function_def", "loc": virtual get fun getter(): Int { return 42 }, "name": { @@ -3762,26 +3528,20 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr }, "params": [], "return": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 9, + "id": 8, "kind": "number", "loc": 42, "value": 42n, }, - "id": 10, + "id": 9, "kind": "statement_return", "loc": return 42, }, @@ -3865,57 +3625,51 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "type": "get", }, ], - "id": 19, + "id": 17, "kind": "function_def", "loc": override get fun getter(): Int { return 43 }, "name": { - "id": 14, + "id": 13, "kind": "id", "loc": getter, "text": "getter", }, "params": [], "return": { - "id": 16, - "kind": "type_ref_simple", + "id": 14, + "kind": "type_id", "loc": Int, - "name": { - "id": 15, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 17, + "id": 15, "kind": "number", "loc": 43, "value": 43n, }, - "id": 18, + "id": 16, "kind": "statement_return", "loc": return 43, }, ], }, ], - "id": 21, + "id": 19, "kind": "contract", "loc": contract TestContract with T { override get fun getter(): Int { return 43 } }, "name": { - "id": 13, + "id": 12, "kind": "id", "loc": TestContract, "text": "TestContract", }, "traits": [ { - "id": 20, + "id": 18, "kind": "id", "loc": T, "text": "T", @@ -3938,37 +3692,31 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "type": "get", }, ], - "id": 19, + "id": 17, "kind": "function_def", "loc": override get fun getter(): Int { return 43 }, "name": { - "id": 14, + "id": 13, "kind": "id", "loc": getter, "text": "getter", }, "params": [], "return": { - "id": 16, - "kind": "type_ref_simple", + "id": 14, + "kind": "type_id", "loc": Int, - "name": { - "id": 15, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 17, + "id": 15, "kind": "number", "loc": 43, "value": 43n, }, - "id": 18, + "id": 16, "kind": "statement_return", "loc": return 43, }, @@ -3994,8 +3742,8 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "header": null, "init": { "ast": { - "id": 23, - "kind": "def_init_function", + "id": 21, + "kind": "contract_init", "loc": contract TestContract with T { override get fun getter(): Int { return 43 } }, @@ -4060,7 +3808,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "type": "get", }, ], - "id": 11, + "id": 10, "kind": "function_def", "loc": virtual get fun getter(): Int { return 42 }, "name": { @@ -4071,33 +3819,27 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr }, "params": [], "return": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 9, + "id": 8, "kind": "number", "loc": 42, "value": 42n, }, - "id": 10, + "id": 9, "kind": "statement_return", "loc": return 42, }, ], }, ], - "id": 12, + "id": 11, "kind": "trait", "loc": trait T { virtual get fun getter(): Int { return 42 } @@ -4126,7 +3868,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr "type": "get", }, ], - "id": 11, + "id": 10, "kind": "function_def", "loc": virtual get fun getter(): Int { return 42 }, "name": { @@ -4137,26 +3879,20 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr }, "params": [], "return": { - "id": 8, - "kind": "type_ref_simple", + "id": 7, + "kind": "type_id", "loc": Int, - "name": { - "id": 7, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 9, + "id": 8, "kind": "number", "loc": 42, "value": 42n, }, - "id": 10, + "id": 9, "kind": "statement_return", "loc": return 42, }, @@ -4276,7 +4012,7 @@ exports[`resolveDescriptors should resolve descriptors for init-vars-analysis-un "loc": primitive Bool;, "name": { "id": 3, - "kind": "id", + "kind": "type_id", "loc": Bool, "text": "Bool", }, @@ -4304,9 +4040,9 @@ exports[`resolveDescriptors should resolve descriptors for init-vars-analysis-un "declarations": [ { "as": null, - "id": 11, - "init": null, - "kind": "def_field", + "id": 10, + "initializer": null, + "kind": "field_decl", "loc": a: Int, "name": { "id": 8, @@ -4315,46 +4051,34 @@ exports[`resolveDescriptors should resolve descriptors for init-vars-analysis-un "text": "a", }, "type": { - "id": 10, - "kind": "type_ref_simple", + "id": 9, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 15, - "init": null, - "kind": "def_field", + "id": 13, + "initializer": null, + "kind": "field_decl", "loc": b: Bool, "name": { - "id": 12, + "id": 11, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 14, - "kind": "type_ref_simple", + "id": 12, + "kind": "type_id", "loc": Bool, - "name": { - "id": 13, - "kind": "id", - "loc": Bool, - "text": "Bool", - }, - "optional": false, + "text": "Bool", }, }, { - "id": 16, - "kind": "def_init_function", + "id": 14, + "kind": "contract_init", "loc": init() { }, @@ -4363,13 +4087,13 @@ exports[`resolveDescriptors should resolve descriptors for init-vars-analysis-un }, { "attributes": [], - "id": 18, + "id": 16, "kind": "function_def", "loc": fun hello() { }, "name": { - "id": 17, + "id": 15, "kind": "id", "loc": hello, "text": "hello", @@ -4380,13 +4104,13 @@ exports[`resolveDescriptors should resolve descriptors for init-vars-analysis-un }, { "attributes": [], - "id": 20, + "id": 18, "kind": "function_def", "loc": fun hello2() { }, "name": { - "id": 19, + "id": 17, "kind": "id", "loc": hello2, "text": "hello2", @@ -4396,7 +4120,7 @@ exports[`resolveDescriptors should resolve descriptors for init-vars-analysis-un "statements": [], }, ], - "id": 21, + "id": 19, "kind": "contract", "loc": contract HelloWorld { a: Int; @@ -4438,9 +4162,9 @@ exports[`resolveDescriptors should resolve descriptors for init-vars-analysis-un "as": null, "ast": { "as": null, - "id": 11, - "init": null, - "kind": "def_field", + "id": 10, + "initializer": null, + "kind": "field_decl", "loc": a: Int, "name": { "id": 8, @@ -4449,16 +4173,10 @@ exports[`resolveDescriptors should resolve descriptors for init-vars-analysis-un "text": "a", }, "type": { - "id": 10, - "kind": "type_ref_simple", + "id": 9, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -4483,27 +4201,21 @@ exports[`resolveDescriptors should resolve descriptors for init-vars-analysis-un "as": null, "ast": { "as": null, - "id": 15, - "init": null, - "kind": "def_field", + "id": 13, + "initializer": null, + "kind": "field_decl", "loc": b: Bool, "name": { - "id": 12, + "id": 11, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 14, - "kind": "type_ref_simple", + "id": 12, + "kind": "type_id", "loc": Bool, - "name": { - "id": 13, - "kind": "id", - "loc": Bool, - "text": "Bool", - }, - "optional": false, + "text": "Bool", }, }, "default": undefined, @@ -4521,13 +4233,13 @@ exports[`resolveDescriptors should resolve descriptors for init-vars-analysis-un "hello" => { "ast": { "attributes": [], - "id": 18, + "id": 16, "kind": "function_def", "loc": fun hello() { }, "name": { - "id": 17, + "id": 15, "kind": "id", "loc": hello, "text": "hello", @@ -4553,13 +4265,13 @@ exports[`resolveDescriptors should resolve descriptors for init-vars-analysis-un "hello2" => { "ast": { "attributes": [], - "id": 20, + "id": 18, "kind": "function_def", "loc": fun hello2() { }, "name": { - "id": 19, + "id": 17, "kind": "id", "loc": hello2, "text": "hello2", @@ -4586,8 +4298,8 @@ exports[`resolveDescriptors should resolve descriptors for init-vars-analysis-un "header": null, "init": { "ast": { - "id": 16, - "kind": "def_init_function", + "id": 14, + "kind": "contract_init", "loc": init() { }, @@ -4649,7 +4361,7 @@ exports[`resolveDescriptors should resolve descriptors for init-vars-analysis-un "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -4719,7 +4431,7 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "loc": primitive Bool;, "name": { "id": 3, - "kind": "id", + "kind": "type_id", "loc": Bool, "text": "Bool", }, @@ -4748,7 +4460,7 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -4778,7 +4490,7 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "testFunc": { "ast": { "attributes": [], - "id": 12, + "id": 11, "kind": "function_def", "loc": fun testFunc(): Int { return 0; @@ -4791,26 +4503,20 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors }, "params": [], "return": { - "id": 9, - "kind": "type_ref_simple", + "id": 8, + "kind": "type_id", "loc": Int, - "name": { - "id": 8, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 10, + "id": 9, "kind": "number", "loc": 0, "value": 0n, }, - "id": 11, + "id": 10, "kind": "statement_return", "loc": return 0;, }, @@ -4835,13 +4541,13 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "testFunc2": { "ast": { "attributes": [], - "id": 16, + "id": 15, "kind": "function_def", "loc": fun testFunc2() { return 0; }, "name": { - "id": 13, + "id": 12, "kind": "id", "loc": testFunc2, "text": "testFunc2", @@ -4851,12 +4557,12 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "statements": [ { "expression": { - "id": 14, + "id": 13, "kind": "number", "loc": 0, "value": 0n, }, - "id": 15, + "id": 14, "kind": "statement_return", "loc": return 0;, }, @@ -4879,62 +4585,50 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "testFunc3": { "ast": { "attributes": [], - "id": 28, + "id": 25, "kind": "function_def", "loc": fun testFunc3(a: Int, b: Bool) { return 0; }, "name": { - "id": 17, + "id": 16, "kind": "id", "loc": testFunc3, "text": "testFunc3", }, "params": [ { - "id": 21, + "id": 19, "kind": "typed_parameter", "loc": a: Int, "name": { - "id": 18, + "id": 17, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 20, - "kind": "type_ref_simple", + "id": 18, + "kind": "type_id", "loc": Int, - "name": { - "id": 19, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { - "id": 25, + "id": 22, "kind": "typed_parameter", "loc": b: Bool, "name": { - "id": 22, + "id": 20, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 24, - "kind": "type_ref_simple", + "id": 21, + "kind": "type_id", "loc": Bool, - "name": { - "id": 23, - "kind": "id", - "loc": Bool, - "text": "Bool", - }, - "optional": false, + "text": "Bool", }, }, ], @@ -4942,12 +4636,12 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "statements": [ { "expression": { - "id": 26, + "id": 23, "kind": "number", "loc": 0, "value": 0n, }, - "id": 27, + "id": 24, "kind": "statement_return", "loc": return 0;, }, @@ -4965,7 +4659,7 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors { "loc": a: Int, "name": { - "id": 18, + "id": 17, "kind": "id", "loc": a, "text": "a", @@ -4979,7 +4673,7 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors { "loc": b: Bool, "name": { - "id": 22, + "id": 20, "kind": "id", "loc": b, "text": "b", @@ -5042,7 +4736,7 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "loc": primitive Bool;, "name": { "id": 3, - "kind": "id", + "kind": "type_id", "loc": Bool, "text": "Bool", }, @@ -5071,7 +4765,7 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -5099,87 +4793,75 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "declarations": [ { "as": null, - "id": 17, - "init": null, - "kind": "def_field", + "id": 15, + "initializer": null, + "kind": "field_decl", "loc": a: Int, "name": { - "id": 14, + "id": 13, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 16, - "kind": "type_ref_simple", + "id": 14, + "kind": "type_id", "loc": Int, - "name": { - "id": 15, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { - "id": 27, - "kind": "def_init_function", + "id": 24, + "kind": "contract_init", "loc": init(a: Int) { self.a = a; }, "params": [ { - "id": 21, + "id": 18, "kind": "typed_parameter", "loc": a: Int, "name": { - "id": 18, + "id": 16, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 20, - "kind": "type_ref_simple", + "id": 17, + "kind": "type_id", "loc": Int, - "name": { - "id": 19, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], "statements": [ { "expression": { - "id": 25, + "id": 22, "kind": "id", "loc": a, "text": "a", }, - "id": 26, + "id": 23, "kind": "statement_assign", "loc": self.a = a;, "path": { - "id": 24, - "kind": "op_field", - "loc": self.a, - "name": { - "id": 23, - "kind": "id", - "loc": a, - "text": "a", - }, - "src": { - "id": 22, + "aggregate": { + "id": 19, "kind": "id", "loc": self, "text": "self", }, + "field": { + "id": 20, + "kind": "id", + "loc": a, + "text": "a", + }, + "id": 21, + "kind": "field_access", + "loc": self.a, }, }, ], @@ -5191,39 +4873,33 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "type": "get", }, ], - "id": 33, + "id": 29, "kind": "function_def", "loc": get fun hello(): Int { return 0; }, "name": { - "id": 28, + "id": 25, "kind": "id", "loc": hello, "text": "hello", }, "params": [], "return": { - "id": 30, - "kind": "type_ref_simple", - "loc": Int, - "name": { - "id": 29, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "id": 26, + "kind": "type_id", + "loc": Int, + "text": "Int", }, "statements": [ { "expression": { - "id": 31, + "id": 27, "kind": "number", "loc": 0, "value": 0n, }, - "id": 32, + "id": 28, "kind": "statement_return", "loc": return 0;, }, @@ -5236,46 +4912,40 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "type": "get", }, ], - "id": 39, + "id": 34, "kind": "function_def", "loc": get fun hello2(): Point { return 0; }, "name": { - "id": 34, + "id": 30, "kind": "id", "loc": hello2, "text": "hello2", }, "params": [], "return": { - "id": 36, - "kind": "type_ref_simple", + "id": 31, + "kind": "type_id", "loc": Point, - "name": { - "id": 35, - "kind": "id", - "loc": Point, - "text": "Point", - }, - "optional": false, + "text": "Point", }, "statements": [ { "expression": { - "id": 37, + "id": 32, "kind": "number", "loc": 0, "value": 0n, }, - "id": 38, + "id": 33, "kind": "statement_return", "loc": return 0;, }, ], }, ], - "id": 40, + "id": 35, "kind": "contract", "loc": contract Main { a: Int; @@ -5291,7 +4961,7 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors } }, "name": { - "id": 13, + "id": 12, "kind": "id", "loc": Main, "text": "Main", @@ -5314,27 +4984,21 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "as": null, "ast": { "as": null, - "id": 17, - "init": null, - "kind": "def_field", + "id": 15, + "initializer": null, + "kind": "field_decl", "loc": a: Int, "name": { - "id": 14, + "id": 13, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 16, - "kind": "type_ref_simple", + "id": 14, + "kind": "type_id", "loc": Int, - "name": { - "id": 15, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -5357,39 +5021,33 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "type": "get", }, ], - "id": 33, + "id": 29, "kind": "function_def", "loc": get fun hello(): Int { return 0; }, "name": { - "id": 28, + "id": 25, "kind": "id", "loc": hello, "text": "hello", }, "params": [], "return": { - "id": 30, - "kind": "type_ref_simple", + "id": 26, + "kind": "type_id", "loc": Int, - "name": { - "id": 29, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 31, + "id": 27, "kind": "number", "loc": 0, "value": 0n, }, - "id": 32, + "id": 28, "kind": "statement_return", "loc": return 0;, }, @@ -5419,39 +5077,33 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "type": "get", }, ], - "id": 39, + "id": 34, "kind": "function_def", "loc": get fun hello2(): Point { return 0; }, "name": { - "id": 34, + "id": 30, "kind": "id", "loc": hello2, "text": "hello2", }, "params": [], "return": { - "id": 36, - "kind": "type_ref_simple", + "id": 31, + "kind": "type_id", "loc": Point, - "name": { - "id": 35, - "kind": "id", - "loc": Point, - "text": "Point", - }, - "optional": false, + "text": "Point", }, "statements": [ { "expression": { - "id": 37, + "id": 32, "kind": "number", "loc": 0, "value": 0n, }, - "id": 38, + "id": 33, "kind": "statement_return", "loc": return 0;, }, @@ -5477,63 +5129,57 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "header": null, "init": { "ast": { - "id": 27, - "kind": "def_init_function", + "id": 24, + "kind": "contract_init", "loc": init(a: Int) { self.a = a; }, "params": [ { - "id": 21, + "id": 18, "kind": "typed_parameter", "loc": a: Int, "name": { - "id": 18, + "id": 16, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 20, - "kind": "type_ref_simple", + "id": 17, + "kind": "type_id", "loc": Int, - "name": { - "id": 19, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], "statements": [ { "expression": { - "id": 25, + "id": 22, "kind": "id", "loc": a, "text": "a", }, - "id": 26, + "id": 23, "kind": "statement_assign", "loc": self.a = a;, "path": { - "id": 24, - "kind": "op_field", - "loc": self.a, - "name": { - "id": 23, - "kind": "id", - "loc": a, - "text": "a", - }, - "src": { - "id": 22, + "aggregate": { + "id": 19, "kind": "id", "loc": self, "text": "self", }, + "field": { + "id": 20, + "kind": "id", + "loc": a, + "text": "a", + }, + "id": 21, + "kind": "field_access", + "loc": self.a, }, }, ], @@ -5543,7 +5189,7 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "as": null, "loc": a: Int, "name": { - "id": 18, + "id": 16, "kind": "id", "loc": a, "text": "a", @@ -5607,9 +5253,9 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "fields": [ { "as": null, - "id": 11, - "init": null, - "kind": "def_field", + "id": 10, + "initializer": null, + "kind": "field_decl", "loc": p: Int, "name": { "id": 8, @@ -5618,27 +5264,21 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "text": "p", }, "type": { - "id": 10, - "kind": "type_ref_simple", + "id": 9, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], - "id": 12, + "id": 11, "kind": "struct_decl", "loc": struct Point { p: Int; }, "name": { "id": 7, - "kind": "id", + "kind": "type_id", "loc": Point, "text": "Point", }, @@ -5659,9 +5299,9 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "as": null, "ast": { "as": null, - "id": 11, - "init": null, - "kind": "def_field", + "id": 10, + "initializer": null, + "kind": "field_decl", "loc": p: Int, "name": { "id": 8, @@ -5670,16 +5310,10 @@ exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors "text": "p", }, "type": { - "id": 10, - "kind": "type_ref_simple", + "id": 9, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -5755,7 +5389,7 @@ exports[`resolveDescriptors should resolve descriptors for item-method 1`] = ` "loc": primitive Bool;, "name": { "id": 3, - "kind": "id", + "kind": "type_id", "loc": Bool, "text": "Bool", }, @@ -5784,7 +5418,7 @@ exports[`resolveDescriptors should resolve descriptors for item-method 1`] = ` "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -5801,7 +5435,7 @@ exports[`resolveDescriptors should resolve descriptors for item-method 1`] = ` "type": "extends", }, ], - "id": 18, + "id": 16, "kind": "function_def", "loc": extends fun inc(self: Int): Int { return self + 1; @@ -5814,48 +5448,36 @@ exports[`resolveDescriptors should resolve descriptors for item-method 1`] = ` }, "params": [ { - "id": 13, + "id": 11, "kind": "typed_parameter", "loc": self: Int, "name": { - "id": 10, + "id": 9, "kind": "id", "loc": self, "text": "self", }, "type": { - "id": 12, - "kind": "type_ref_simple", + "id": 10, + "kind": "type_id", "loc": Int, - "name": { - "id": 11, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], "return": { - "id": 9, - "kind": "type_ref_simple", + "id": 8, + "kind": "type_id", "loc": Int, - "name": { - "id": 8, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { - "id": 16, + "id": 14, "kind": "op_binary", "left": { - "id": 14, + "id": 12, "kind": "id", "loc": self, "text": "self", @@ -5863,13 +5485,13 @@ exports[`resolveDescriptors should resolve descriptors for item-method 1`] = ` "loc": self + 1, "op": "+", "right": { - "id": 15, + "id": 13, "kind": "number", "loc": 1, "value": 1n, }, }, - "id": 17, + "id": 15, "kind": "statement_return", "loc": return self + 1;, }, @@ -5953,7 +5575,7 @@ exports[`resolveDescriptors should resolve descriptors for item-native-decl 1`] "loc": primitive Bool;, "name": { "id": 3, - "kind": "id", + "kind": "type_id", "loc": Bool, "text": "Bool", }, @@ -5982,7 +5604,7 @@ exports[`resolveDescriptors should resolve descriptors for item-native-decl 1`] "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -6012,7 +5634,7 @@ exports[`resolveDescriptors should resolve descriptors for item-native-decl 2`] "sample": { "ast": { "attributes": [], - "id": 15, + "id": 13, "kind": "native_function_decl", "loc": @name(hello_world) native sample(a: Int): Int;, @@ -6030,40 +5652,28 @@ native sample(a: Int): Int;, }, "params": [ { - "id": 14, + "id": 12, "kind": "typed_parameter", "loc": a: Int, "name": { - "id": 11, + "id": 10, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 13, - "kind": "type_ref_simple", + "id": 11, + "kind": "type_id", "loc": Int, - "name": { - "id": 12, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], "return": { - "id": 10, - "kind": "type_ref_simple", + "id": 9, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "isAbstract": false, @@ -6078,7 +5688,7 @@ native sample(a: Int): Int;, { "loc": a: Int, "name": { - "id": 11, + "id": 10, "kind": "id", "loc": a, "text": "a", @@ -6143,7 +5753,7 @@ exports[`resolveDescriptors should resolve descriptors for item-native-mutating- "loc": primitive Bool;, "name": { "id": 3, - "kind": "id", + "kind": "type_id", "loc": Bool, "text": "Bool", }, @@ -6172,7 +5782,7 @@ exports[`resolveDescriptors should resolve descriptors for item-native-mutating- "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -6193,7 +5803,7 @@ exports[`resolveDescriptors should resolve descriptors for item-native-mutating- "type": "extends", }, ], - "id": 15, + "id": 13, "kind": "native_function_decl", "loc": @name(inc) mutates extends native inc(self: Int): Int;, @@ -6211,40 +5821,28 @@ mutates extends native inc(self: Int): Int;, }, "params": [ { - "id": 14, + "id": 12, "kind": "typed_parameter", "loc": self: Int, "name": { - "id": 11, + "id": 10, "kind": "id", "loc": self, "text": "self", }, "type": { - "id": 13, - "kind": "type_ref_simple", + "id": 11, + "kind": "type_id", "loc": Int, - "name": { - "id": 12, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], "return": { - "id": 10, - "kind": "type_ref_simple", + "id": 9, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "isAbstract": false, @@ -6325,7 +5923,7 @@ exports[`resolveDescriptors should resolve descriptors for map-value-as-coins 1` "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -6354,8 +5952,8 @@ exports[`resolveDescriptors should resolve descriptors for map-value-as-coins 1` { "as": null, "id": 11, - "init": null, - "kind": "def_field", + "initializer": null, + "kind": "field_decl", "loc": m: map, "name": { "id": 6, @@ -6365,27 +5963,27 @@ exports[`resolveDescriptors should resolve descriptors for map-value-as-coins 1` }, "type": { "id": 10, - "key": { + "keyStorageType": null, + "keyType": { "id": 7, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, - "keyAs": null, - "kind": "type_ref_map", + "kind": "map_type", "loc": map, - "value": { - "id": 8, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "valueAs": { + "valueStorageType": { "id": 9, "kind": "id", "loc": coins, "text": "coins", }, + "valueType": { + "id": 8, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, }, }, { @@ -6395,7 +5993,7 @@ exports[`resolveDescriptors should resolve descriptors for map-value-as-coins 1` "type": "get", }, ], - "id": 49, + "id": 48, "kind": "function_def", "loc": get fun test(): Int { let m: map = emptyMap(); @@ -6411,98 +6009,92 @@ exports[`resolveDescriptors should resolve descriptors for map-value-as-coins 1` }, "params": [], "return": { - "id": 14, - "kind": "type_ref_simple", + "id": 13, + "kind": "type_id", "loc": Int, - "name": { - "id": 13, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { "args": [], - "id": 21, - "kind": "op_static_call", - "loc": emptyMap(), - "name": { - "id": 20, + "function": { + "id": 19, "kind": "id", "loc": emptyMap, "text": "emptyMap", }, + "id": 20, + "kind": "static_call", + "loc": emptyMap(), }, - "id": 22, + "id": 21, "kind": "statement_let", "loc": let m: map = emptyMap();, "name": { - "id": 15, + "id": 14, "kind": "id", "loc": m, "text": "m", }, "type": { - "id": 19, - "key": { - "id": 16, - "kind": "id", + "id": 18, + "keyStorageType": null, + "keyType": { + "id": 15, + "kind": "type_id", "loc": Int, "text": "Int", }, - "keyAs": null, - "kind": "type_ref_map", + "kind": "map_type", "loc": map, - "value": { + "valueStorageType": { "id": 17, "kind": "id", - "loc": Int, - "text": "Int", - }, - "valueAs": { - "id": 18, - "kind": "id", "loc": coins, "text": "coins", }, + "valueType": { + "id": 16, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, }, }, { "expression": { "args": [ { - "id": 25, + "id": 24, "kind": "number", "loc": 1, "value": 1n, }, { - "id": 26, + "id": 25, "kind": "number", "loc": 2, "value": 2n, }, ], - "id": 27, - "kind": "op_call", + "id": 26, + "kind": "method_call", "loc": m.set(1, 2), - "name": { - "id": 24, + "method": { + "id": 23, "kind": "id", "loc": set, "text": "set", }, - "src": { - "id": 23, + "self": { + "id": 22, "kind": "id", "loc": m, "text": "m", }, }, - "id": 28, + "id": 27, "kind": "statement_expression", "loc": m.set(1, 2);, }, @@ -6510,73 +6102,73 @@ exports[`resolveDescriptors should resolve descriptors for map-value-as-coins 1` "expression": { "args": [ { - "id": 33, + "id": 32, "kind": "number", "loc": 1, "value": 1n, }, { - "id": 34, + "id": 33, "kind": "number", "loc": 2, "value": 2n, }, ], - "id": 35, - "kind": "op_call", + "id": 34, + "kind": "method_call", "loc": self.m.set(1, 2), - "name": { - "id": 32, + "method": { + "id": 31, "kind": "id", "loc": set, "text": "set", }, - "src": { - "id": 31, - "kind": "op_field", - "loc": self.m, - "name": { - "id": 30, + "self": { + "aggregate": { + "id": 28, "kind": "id", - "loc": m, - "text": "m", + "loc": self, + "text": "self", }, - "src": { + "field": { "id": 29, "kind": "id", - "loc": self, - "text": "self", + "loc": m, + "text": "m", }, + "id": 30, + "kind": "field_access", + "loc": self.m, }, }, - "id": 36, + "id": 35, "kind": "statement_expression", "loc": self.m.set(1, 2);, }, { "expression": { - "id": 47, + "id": 46, "kind": "op_binary", "left": { "args": [ { - "id": 39, + "id": 38, "kind": "number", "loc": 1, "value": 1n, }, ], - "id": 40, - "kind": "op_call", + "id": 39, + "kind": "method_call", "loc": m.get(1), - "name": { - "id": 38, + "method": { + "id": 37, "kind": "id", "loc": get, "text": "get", }, - "src": { - "id": 37, + "self": { + "id": 36, "kind": "id", "loc": m, "text": "m", @@ -6587,48 +6179,48 @@ exports[`resolveDescriptors should resolve descriptors for map-value-as-coins 1` "right": { "args": [ { - "id": 45, + "id": 44, "kind": "number", "loc": 1, "value": 1n, }, ], - "id": 46, - "kind": "op_call", + "id": 45, + "kind": "method_call", "loc": self.m.get(1), - "name": { - "id": 44, + "method": { + "id": 43, "kind": "id", "loc": get, "text": "get", }, - "src": { - "id": 43, - "kind": "op_field", - "loc": self.m, - "name": { - "id": 42, + "self": { + "aggregate": { + "id": 40, "kind": "id", - "loc": m, - "text": "m", + "loc": self, + "text": "self", }, - "src": { + "field": { "id": 41, "kind": "id", - "loc": self, - "text": "self", + "loc": m, + "text": "m", }, + "id": 42, + "kind": "field_access", + "loc": self.m, }, }, }, - "id": 48, + "id": 47, "kind": "statement_return", "loc": return m.get(1) + self.m.get(1);, }, ], }, ], - "id": 50, + "id": 49, "kind": "contract", "loc": contract Main { m: map; @@ -6666,8 +6258,8 @@ exports[`resolveDescriptors should resolve descriptors for map-value-as-coins 1` "ast": { "as": null, "id": 11, - "init": null, - "kind": "def_field", + "initializer": null, + "kind": "field_decl", "loc": m: map, "name": { "id": 6, @@ -6677,27 +6269,27 @@ exports[`resolveDescriptors should resolve descriptors for map-value-as-coins 1` }, "type": { "id": 10, - "key": { + "keyStorageType": null, + "keyType": { "id": 7, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, - "keyAs": null, - "kind": "type_ref_map", + "kind": "map_type", "loc": map, - "value": { - "id": 8, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "valueAs": { + "valueStorageType": { "id": 9, "kind": "id", "loc": coins, "text": "coins", }, + "valueType": { + "id": 8, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, }, }, "default": undefined, @@ -6722,7 +6314,7 @@ exports[`resolveDescriptors should resolve descriptors for map-value-as-coins 1` "type": "get", }, ], - "id": 49, + "id": 48, "kind": "function_def", "loc": get fun test(): Int { let m: map = emptyMap(); @@ -6738,98 +6330,92 @@ exports[`resolveDescriptors should resolve descriptors for map-value-as-coins 1` }, "params": [], "return": { - "id": 14, - "kind": "type_ref_simple", + "id": 13, + "kind": "type_id", "loc": Int, - "name": { - "id": 13, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, "statements": [ { "expression": { "args": [], - "id": 21, - "kind": "op_static_call", - "loc": emptyMap(), - "name": { - "id": 20, + "function": { + "id": 19, "kind": "id", "loc": emptyMap, "text": "emptyMap", }, + "id": 20, + "kind": "static_call", + "loc": emptyMap(), }, - "id": 22, + "id": 21, "kind": "statement_let", "loc": let m: map = emptyMap();, "name": { - "id": 15, + "id": 14, "kind": "id", "loc": m, "text": "m", }, "type": { - "id": 19, - "key": { - "id": 16, - "kind": "id", + "id": 18, + "keyStorageType": null, + "keyType": { + "id": 15, + "kind": "type_id", "loc": Int, "text": "Int", }, - "keyAs": null, - "kind": "type_ref_map", + "kind": "map_type", "loc": map, - "value": { + "valueStorageType": { "id": 17, "kind": "id", - "loc": Int, - "text": "Int", - }, - "valueAs": { - "id": 18, - "kind": "id", "loc": coins, "text": "coins", }, + "valueType": { + "id": 16, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, }, }, { "expression": { "args": [ { - "id": 25, + "id": 24, "kind": "number", "loc": 1, "value": 1n, }, { - "id": 26, + "id": 25, "kind": "number", "loc": 2, "value": 2n, }, ], - "id": 27, - "kind": "op_call", + "id": 26, + "kind": "method_call", "loc": m.set(1, 2), - "name": { - "id": 24, + "method": { + "id": 23, "kind": "id", "loc": set, "text": "set", }, - "src": { - "id": 23, + "self": { + "id": 22, "kind": "id", "loc": m, "text": "m", }, }, - "id": 28, + "id": 27, "kind": "statement_expression", "loc": m.set(1, 2);, }, @@ -6837,73 +6423,73 @@ exports[`resolveDescriptors should resolve descriptors for map-value-as-coins 1` "expression": { "args": [ { - "id": 33, + "id": 32, "kind": "number", "loc": 1, "value": 1n, }, { - "id": 34, + "id": 33, "kind": "number", "loc": 2, "value": 2n, }, ], - "id": 35, - "kind": "op_call", + "id": 34, + "kind": "method_call", "loc": self.m.set(1, 2), - "name": { - "id": 32, + "method": { + "id": 31, "kind": "id", "loc": set, "text": "set", }, - "src": { - "id": 31, - "kind": "op_field", - "loc": self.m, - "name": { - "id": 30, + "self": { + "aggregate": { + "id": 28, "kind": "id", - "loc": m, - "text": "m", + "loc": self, + "text": "self", }, - "src": { + "field": { "id": 29, "kind": "id", - "loc": self, - "text": "self", + "loc": m, + "text": "m", }, + "id": 30, + "kind": "field_access", + "loc": self.m, }, }, - "id": 36, + "id": 35, "kind": "statement_expression", "loc": self.m.set(1, 2);, }, { "expression": { - "id": 47, + "id": 46, "kind": "op_binary", "left": { "args": [ { - "id": 39, + "id": 38, "kind": "number", "loc": 1, "value": 1n, }, ], - "id": 40, - "kind": "op_call", + "id": 39, + "kind": "method_call", "loc": m.get(1), - "name": { - "id": 38, + "method": { + "id": 37, "kind": "id", "loc": get, "text": "get", }, - "src": { - "id": 37, + "self": { + "id": 36, "kind": "id", "loc": m, "text": "m", @@ -6914,41 +6500,41 @@ exports[`resolveDescriptors should resolve descriptors for map-value-as-coins 1` "right": { "args": [ { - "id": 45, + "id": 44, "kind": "number", "loc": 1, "value": 1n, }, ], - "id": 46, - "kind": "op_call", + "id": 45, + "kind": "method_call", "loc": self.m.get(1), - "name": { - "id": 44, + "method": { + "id": 43, "kind": "id", "loc": get, "text": "get", }, - "src": { - "id": 43, - "kind": "op_field", - "loc": self.m, - "name": { - "id": 42, + "self": { + "aggregate": { + "id": 40, "kind": "id", - "loc": m, - "text": "m", + "loc": self, + "text": "self", }, - "src": { + "field": { "id": 41, "kind": "id", - "loc": self, - "text": "self", + "loc": m, + "text": "m", }, + "id": 42, + "kind": "field_access", + "loc": self.m, }, }, }, - "id": 48, + "id": 47, "kind": "statement_return", "loc": return m.get(1) + self.m.get(1);, }, @@ -6974,8 +6560,8 @@ exports[`resolveDescriptors should resolve descriptors for map-value-as-coins 1` "header": null, "init": { "ast": { - "id": 52, - "kind": "def_init_function", + "id": 51, + "kind": "contract_init", "loc": contract Main { m: map; @@ -7049,7 +6635,7 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` "scopeIf": { "ast": { "attributes": [], - "id": 56, + "id": 48, "kind": "function_def", "loc": fun scopeIf() { if (true) { @@ -7058,7 +6644,7 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` let a: String = "abc"; }, "name": { - "id": 43, + "id": 37, "kind": "id", "loc": scopeIf, "text": "scopeIf", @@ -7067,15 +6653,15 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` "return": null, "statements": [ { - "elseif": null, - "expression": { - "id": 44, + "condition": { + "id": 38, "kind": "boolean", "loc": true, "value": true, }, + "elseif": null, "falseStatements": null, - "id": 50, + "id": 43, "kind": "statement_condition", "loc": if (true) { let a: Int = 0; @@ -7083,62 +6669,50 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` "trueStatements": [ { "expression": { - "id": 48, + "id": 41, "kind": "number", "loc": 0, "value": 0n, }, - "id": 49, + "id": 42, "kind": "statement_let", "loc": let a: Int = 0;, "name": { - "id": 45, + "id": 39, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 47, - "kind": "type_ref_simple", + "id": 40, + "kind": "type_id", "loc": Int, - "name": { - "id": 46, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], }, { "expression": { - "id": 54, + "id": 46, "kind": "string", "loc": "abc", "value": "abc", }, - "id": 55, + "id": 47, "kind": "statement_let", "loc": let a: String = "abc";, "name": { - "id": 51, + "id": 44, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 53, - "kind": "type_ref_simple", + "id": 45, + "kind": "type_id", "loc": String, - "name": { - "id": 52, - "kind": "id", - "loc": String, - "text": "String", - }, - "optional": false, + "text": "String", }, }, ], @@ -7160,7 +6734,7 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` "scopeRepeat": { "ast": { "attributes": [], - "id": 28, + "id": 24, "kind": "function_def", "loc": fun scopeRepeat() { repeat (1) { @@ -7169,7 +6743,7 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` let a: String = "abc"; }, "name": { - "id": 15, + "id": 13, "kind": "id", "loc": scopeRepeat, "text": "scopeRepeat", @@ -7178,9 +6752,9 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` "return": null, "statements": [ { - "id": 22, + "id": 19, "iterations": { - "id": 16, + "id": 14, "kind": "number", "loc": 1, "value": 1n, @@ -7192,62 +6766,50 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` "statements": [ { "expression": { - "id": 20, + "id": 17, "kind": "number", "loc": 0, "value": 0n, }, - "id": 21, + "id": 18, "kind": "statement_let", "loc": let a: Int = 0;, "name": { - "id": 17, + "id": 15, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 19, - "kind": "type_ref_simple", + "id": 16, + "kind": "type_id", "loc": Int, - "name": { - "id": 18, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], }, { "expression": { - "id": 26, + "id": 22, "kind": "string", "loc": "abc", "value": "abc", }, - "id": 27, + "id": 23, "kind": "statement_let", "loc": let a: String = "abc";, "name": { - "id": 23, + "id": 20, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 25, - "kind": "type_ref_simple", + "id": 21, + "kind": "type_id", "loc": String, - "name": { - "id": 24, - "kind": "id", - "loc": String, - "text": "String", - }, - "optional": false, + "text": "String", }, }, ], @@ -7269,7 +6831,7 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` "scopeUntil": { "ast": { "attributes": [], - "id": 14, + "id": 12, "kind": "function_def", "loc": fun scopeUntil() { do { @@ -7293,7 +6855,7 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` "loc": true, "value": true, }, - "id": 8, + "id": 7, "kind": "statement_until", "loc": do { let a: Int = 0; @@ -7301,12 +6863,12 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` "statements": [ { "expression": { - "id": 6, + "id": 5, "kind": "number", "loc": 0, "value": 0n, }, - "id": 7, + "id": 6, "kind": "statement_let", "loc": let a: Int = 0;, "name": { @@ -7316,47 +6878,35 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` "text": "a", }, "type": { - "id": 5, - "kind": "type_ref_simple", + "id": 4, + "kind": "type_id", "loc": Int, - "name": { - "id": 4, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], }, { "expression": { - "id": 12, + "id": 10, "kind": "string", "loc": "abc", "value": "abc", }, - "id": 13, + "id": 11, "kind": "statement_let", "loc": let a: String = "abc";, "name": { - "id": 9, + "id": 8, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 11, - "kind": "type_ref_simple", + "id": 9, + "kind": "type_id", "loc": String, - "name": { - "id": 10, - "kind": "id", - "loc": String, - "text": "String", - }, - "optional": false, + "text": "String", }, }, ], @@ -7378,7 +6928,7 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` "scopeWhile": { "ast": { "attributes": [], - "id": 42, + "id": 36, "kind": "function_def", "loc": fun scopeWhile() { while (true) { @@ -7387,7 +6937,7 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` let a: String = "abc"; }, "name": { - "id": 29, + "id": 25, "kind": "id", "loc": scopeWhile, "text": "scopeWhile", @@ -7397,12 +6947,12 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` "statements": [ { "condition": { - "id": 30, + "id": 26, "kind": "boolean", "loc": true, "value": true, }, - "id": 36, + "id": 31, "kind": "statement_while", "loc": while (true) { let a: Int = 0; @@ -7410,62 +6960,50 @@ exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` "statements": [ { "expression": { - "id": 34, + "id": 29, "kind": "number", "loc": 0, "value": 0n, }, - "id": 35, + "id": 30, "kind": "statement_let", "loc": let a: Int = 0;, "name": { - "id": 31, + "id": 27, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 33, - "kind": "type_ref_simple", + "id": 28, + "kind": "type_id", "loc": Int, - "name": { - "id": 32, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, ], }, { "expression": { - "id": 40, + "id": 34, "kind": "string", "loc": "abc", "value": "abc", }, - "id": 41, + "id": 35, "kind": "statement_let", "loc": let a: String = "abc";, "name": { - "id": 37, + "id": 32, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 39, - "kind": "type_ref_simple", + "id": 33, + "kind": "type_id", "loc": String, - "name": { - "id": 38, - "kind": "id", - "loc": String, - "text": "String", - }, - "optional": false, + "text": "String", }, }, ], @@ -7530,7 +7068,7 @@ exports[`resolveDescriptors should resolve descriptors for struct-nested 1`] = ` "loc": primitive Bool;, "name": { "id": 3, - "kind": "id", + "kind": "type_id", "loc": Bool, "text": "Bool", }, @@ -7559,7 +7097,7 @@ exports[`resolveDescriptors should resolve descriptors for struct-nested 1`] = ` "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, @@ -7586,9 +7124,9 @@ exports[`resolveDescriptors should resolve descriptors for struct-nested 1`] = ` "fields": [ { "as": null, - "id": 11, - "init": null, - "kind": "def_field", + "id": 10, + "initializer": null, + "kind": "field_decl", "loc": a: Int, "name": { "id": 8, @@ -7597,45 +7135,33 @@ exports[`resolveDescriptors should resolve descriptors for struct-nested 1`] = ` "text": "a", }, "type": { - "id": 10, - "kind": "type_ref_simple", + "id": 9, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, { "as": null, - "id": 15, - "init": null, - "kind": "def_field", + "id": 13, + "initializer": null, + "kind": "field_decl", "loc": b: Bool, "name": { - "id": 12, + "id": 11, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 14, - "kind": "type_ref_simple", + "id": 12, + "kind": "type_id", "loc": Bool, - "name": { - "id": 13, - "kind": "id", - "loc": Bool, - "text": "Bool", - }, - "optional": false, + "text": "Bool", }, }, ], - "id": 16, + "id": 14, "kind": "struct_decl", "loc": struct Struct1 { a: Int; @@ -7643,7 +7169,7 @@ exports[`resolveDescriptors should resolve descriptors for struct-nested 1`] = ` }, "name": { "id": 7, - "kind": "id", + "kind": "type_id", "loc": Struct1, "text": "Struct1", }, @@ -7664,9 +7190,9 @@ exports[`resolveDescriptors should resolve descriptors for struct-nested 1`] = ` "as": null, "ast": { "as": null, - "id": 11, - "init": null, - "kind": "def_field", + "id": 10, + "initializer": null, + "kind": "field_decl", "loc": a: Int, "name": { "id": 8, @@ -7675,16 +7201,10 @@ exports[`resolveDescriptors should resolve descriptors for struct-nested 1`] = ` "text": "a", }, "type": { - "id": 10, - "kind": "type_ref_simple", + "id": 9, + "kind": "type_id", "loc": Int, - "name": { - "id": 9, - "kind": "id", - "loc": Int, - "text": "Int", - }, - "optional": false, + "text": "Int", }, }, "default": undefined, @@ -7709,27 +7229,21 @@ exports[`resolveDescriptors should resolve descriptors for struct-nested 1`] = ` "as": null, "ast": { "as": null, - "id": 15, - "init": null, - "kind": "def_field", + "id": 13, + "initializer": null, + "kind": "field_decl", "loc": b: Bool, "name": { - "id": 12, + "id": 11, "kind": "id", "loc": b, "text": "b", }, "type": { - "id": 14, - "kind": "type_ref_simple", + "id": 12, + "kind": "type_id", "loc": Bool, - "name": { - "id": 13, - "kind": "id", - "loc": Bool, - "text": "Bool", - }, - "optional": false, + "text": "Bool", }, }, "default": undefined, @@ -7762,38 +7276,32 @@ exports[`resolveDescriptors should resolve descriptors for struct-nested 1`] = ` "fields": [ { "as": null, - "id": 21, - "init": null, - "kind": "def_field", + "id": 18, + "initializer": null, + "kind": "field_decl", "loc": a: Struct1, "name": { - "id": 18, + "id": 16, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 20, - "kind": "type_ref_simple", + "id": 17, + "kind": "type_id", "loc": Struct1, - "name": { - "id": 19, - "kind": "id", - "loc": Struct1, - "text": "Struct1", - }, - "optional": false, + "text": "Struct1", }, }, ], - "id": 22, + "id": 19, "kind": "struct_decl", "loc": struct Struct2 { a: Struct1; }, "name": { - "id": 17, - "kind": "id", + "id": 15, + "kind": "type_id", "loc": Struct2, "text": "Struct2", }, @@ -7813,27 +7321,21 @@ exports[`resolveDescriptors should resolve descriptors for struct-nested 1`] = ` "as": null, "ast": { "as": null, - "id": 21, - "init": null, - "kind": "def_field", + "id": 18, + "initializer": null, + "kind": "field_decl", "loc": a: Struct1, "name": { - "id": 18, + "id": 16, "kind": "id", "loc": a, "text": "a", }, "type": { - "id": 20, - "kind": "type_ref_simple", + "id": 17, + "kind": "type_id", "loc": Struct1, - "name": { - "id": 19, - "kind": "id", - "loc": Struct1, - "text": "Struct1", - }, - "optional": false, + "text": "Struct1", }, }, "default": undefined, @@ -7909,7 +7411,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-base 1`] = ` "loc": primitive Bool;, "name": { "id": 3, - "kind": "id", + "kind": "type_id", "loc": Bool, "text": "Bool", }, @@ -7938,7 +7440,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-base 1`] = ` "loc": primitive Int;, "name": { "id": 1, - "kind": "id", + "kind": "type_id", "loc": Int, "text": "Int", }, diff --git a/src/types/__snapshots__/resolveStatements.spec.ts.snap b/src/types/__snapshots__/resolveStatements.spec.ts.snap index 02092e129..1009636e9 100644 --- a/src/types/__snapshots__/resolveStatements.spec.ts.snap +++ b/src/types/__snapshots__/resolveStatements.spec.ts.snap @@ -270,6 +270,26 @@ Line 10, col 5: " `; +exports[`resolveStatements should fail statements for init-vars-analysis-used-uninit-storage-augmented-assign1 1`] = ` +":8:27: Field "value" is not initialized +Line 8, col 27: + 7 | init() { +> 8 | self.value = self.value + 1; + ^~~~~ + 9 | } +" +`; + +exports[`resolveStatements should fail statements for init-vars-analysis-used-uninit-storage-augmented-assign2 1`] = ` +":7:5: Field "value" is not set +Line 7, col 5: + 6 | value: Int; +> 7 | init() { + ^~~~~~~~ + 8 | self.value += 1; +" +`; + exports[`resolveStatements should fail statements for init-vars-analysis-used-uninit-storage-override-fun-call 1`] = ` ":15:9: Cannot access self before init Line 15, col 9: diff --git a/src/types/resolveABITypeRef.ts b/src/types/resolveABITypeRef.ts index dda00a07d..1d6124baf 100644 --- a/src/types/resolveABITypeRef.ts +++ b/src/types/resolveABITypeRef.ts @@ -1,6 +1,7 @@ import { ABITypeRef } from "@ton/core"; import { - ASTField, + AstFieldDecl, + AstTypeId, eqNames, idText, isAddress, @@ -13,7 +14,11 @@ import { isStringBuilder, SrcInfo, } from "../grammar/ast"; -import { idTextErr, throwCompilationError } from "../errors"; +import { + idTextErr, + throwCompilationError, + throwInternalCompilerError, +} from "../errors"; import { TypeRef } from "./types"; type FormatDef = { [key: string]: { type: string; format: string | number } }; @@ -70,13 +75,28 @@ const builderFormats: FormatDef = { remaining: { type: "builder", format: "remainder" }, }; -export function resolveABIType(src: ASTField): ABITypeRef { - if (src.type.kind === "type_ref_simple") { +export function resolveABIType(src: AstFieldDecl): ABITypeRef { + if ( + src.type.kind === "type_id" || + (src.type.kind === "optional_type" && + src.type.typeArg.kind == "type_id") + ) { // // Primitive types // - if (isInt(src.type.name)) { + const typeId: AstTypeId = + src.type.kind === "type_id" + ? src.type + : src.type.kind === "optional_type" && + src.type.typeArg.kind == "type_id" + ? src.type.typeArg + : throwInternalCompilerError( + "Only optional type identifiers are supported now", + src.type.typeArg.loc, + ); + + if (isInt(typeId)) { if (src.as) { const fmt = intFormats[idText(src.as)]; if (!fmt) { @@ -88,18 +108,18 @@ export function resolveABIType(src: ASTField): ABITypeRef { return { kind: "simple", type: fmt.type, - optional: src.type.optional, + optional: src.type.kind === "optional_type", format: fmt.format, }; } return { kind: "simple", type: "int", - optional: src.type.optional, + optional: src.type.kind === "optional_type", format: 257, }; // Default is maximum size int } - if (isBool(src.type.name)) { + if (isBool(typeId)) { if (src.as) { throwCompilationError( `Unsupported format ${idTextErr(src.as)}`, @@ -109,10 +129,10 @@ export function resolveABIType(src: ASTField): ABITypeRef { return { kind: "simple", type: "bool", - optional: src.type.optional, + optional: src.type.kind === "optional_type", }; } - if (isCell(src.type.name)) { + if (isCell(typeId)) { if (src.as) { const fmt = cellFormats[idText(src.as)]; if (!fmt) { @@ -124,17 +144,17 @@ export function resolveABIType(src: ASTField): ABITypeRef { return { kind: "simple", type: fmt.type, - optional: src.type.optional, + optional: src.type.kind === "optional_type", format: fmt.format, }; } return { kind: "simple", type: "cell", - optional: src.type.optional, + optional: src.type.kind === "optional_type", }; } - if (isSlice(src.type.name)) { + if (isSlice(typeId)) { if (src.as) { if (src.as) { const fmt = sliceFormats[idText(src.as)]; @@ -147,7 +167,7 @@ export function resolveABIType(src: ASTField): ABITypeRef { return { kind: "simple", type: fmt.type, - optional: src.type.optional, + optional: src.type.kind === "optional_type", format: fmt.format, }; } @@ -155,10 +175,10 @@ export function resolveABIType(src: ASTField): ABITypeRef { return { kind: "simple", type: "slice", - optional: src.type.optional, + optional: src.type.kind === "optional_type", }; } - if (isBuilder(src.type.name)) { + if (isBuilder(typeId)) { if (src.as) { if (src.as) { const fmt = builderFormats[idText(src.as)]; @@ -171,7 +191,7 @@ export function resolveABIType(src: ASTField): ABITypeRef { return { kind: "simple", type: fmt.type, - optional: src.type.optional, + optional: src.type.kind === "optional_type", format: fmt.format, }; } @@ -179,10 +199,10 @@ export function resolveABIType(src: ASTField): ABITypeRef { return { kind: "simple", type: "builder", - optional: src.type.optional, + optional: src.type.kind === "optional_type", }; } - if (isAddress(src.type.name)) { + if (isAddress(typeId)) { if (src.as) { throwCompilationError( `Unsupported format ${idTextErr(src.as)}`, @@ -192,10 +212,10 @@ export function resolveABIType(src: ASTField): ABITypeRef { return { kind: "simple", type: "address", - optional: src.type.optional, + optional: src.type.kind === "optional_type", }; } - if (isString(src.type.name)) { + if (isString(typeId)) { if (src.as) { throwCompilationError( `Unsupported format ${idTextErr(src.as)}`, @@ -205,14 +225,11 @@ export function resolveABIType(src: ASTField): ABITypeRef { return { kind: "simple", type: "string", - optional: src.type.optional, + optional: src.type.kind === "optional_type", }; } - if (isStringBuilder(src.type.name)) { - throwCompilationError( - `Unsupported type ${idTextErr(src.type.name)}`, - src.loc, - ); + if (isStringBuilder(typeId)) { + throwCompilationError(`Unsupported type StringBuilder`, src.loc); } // @@ -223,8 +240,8 @@ export function resolveABIType(src: ASTField): ABITypeRef { if (eqNames(src.as, "reference")) { return { kind: "simple", - type: idText(src.type.name), - optional: src.type.optional, + type: idText(typeId), + optional: src.type.kind === "optional_type", format: "ref", }; } else { @@ -236,8 +253,8 @@ export function resolveABIType(src: ASTField): ABITypeRef { } return { kind: "simple", - type: idText(src.type.name), - optional: src.type.optional, + type: idText(typeId), + optional: src.type.kind === "optional_type", }; } @@ -245,104 +262,110 @@ export function resolveABIType(src: ASTField): ABITypeRef { // Map // - if (src.type.kind === "type_ref_map") { + if (src.type.kind === "map_type") { let key: string; let keyFormat: string | number | undefined = undefined; let value: string; let valueFormat: string | number | undefined = undefined; // Resolve key type - if (isInt(src.type.key)) { + if (isInt(src.type.keyType)) { key = "int"; - if (src.type.keyAs) { - const format = intMapFormats[idText(src.type.keyAs)]; + if (src.type.keyStorageType) { + const format = intMapFormats[idText(src.type.keyStorageType)]; if (!format) { throwCompilationError( - `Unsupported format ${idTextErr(src.type.keyAs)} for map key`, + `Unsupported format ${idTextErr(src.type.keyStorageType)} for map key`, src.loc, ); } key = format.type; keyFormat = format.format; } - } else if (isAddress(src.type.key)) { + } else if (isAddress(src.type.keyType)) { key = "address"; - if (src.type.keyAs) { + if (src.type.keyStorageType) { throwCompilationError( - `Unsupported format ${idTextErr(src.type.keyAs)} for map key`, + `Unsupported format ${idTextErr(src.type.keyStorageType)} for map key`, src.loc, ); } } else { throwCompilationError( - `Unsupported map key type ${idTextErr(src.type.key)}`, + `Unsupported map key type ${idTextErr(src.type.keyType)}`, src.loc, ); } // Resolve value type - if (isInt(src.type.value)) { + if (isInt(src.type.valueType)) { value = "int"; - if (src.type.valueAs) { - const format = intMapFormats[idText(src.type.valueAs)]; + if (src.type.valueStorageType) { + const format = intMapFormats[idText(src.type.valueStorageType)]; if (!format) { throwCompilationError( - `Unsupported format ${idText(src.type.valueAs)} for map value`, + `Unsupported format ${idText(src.type.valueStorageType)} for map value`, src.loc, ); } value = format.type; valueFormat = format.format; } - } else if (isBool(src.type.value)) { + } else if (isBool(src.type.valueType)) { value = "bool"; - if (src.type.valueAs) { + if (src.type.valueStorageType) { throwCompilationError( - `Unsupported format ${idTextErr(src.type.valueAs)} for map value`, + `Unsupported format ${idTextErr(src.type.valueStorageType)} for map value`, src.loc, ); } - } else if (isCell(src.type.value)) { + } else if (isCell(src.type.valueType)) { value = "cell"; valueFormat = "ref"; - if (src.type.valueAs && eqNames(src.type.valueAs, "reference")) { + if ( + src.type.valueStorageType && + eqNames(src.type.valueStorageType, "reference") + ) { throwCompilationError( - `Unsupported format ${idTextErr(src.type.valueAs)} for map value`, + `Unsupported format ${idTextErr(src.type.valueStorageType)} for map value`, src.loc, ); } - } else if (isSlice(src.type.value)) { + } else if (isSlice(src.type.valueType)) { throwCompilationError( - `Unsupported map value type ${idTextErr(src.type.value)}`, + `Unsupported map value type ${idTextErr(src.type.valueType)}`, src.loc, ); - } else if (isAddress(src.type.value)) { + } else if (isAddress(src.type.valueType)) { value = "address"; - if (src.type.valueAs) { + if (src.type.valueStorageType) { throwCompilationError( - `Unsupported format ${idTextErr(src.type.valueAs)} for map value`, + `Unsupported format ${idTextErr(src.type.valueStorageType)} for map value`, src.loc, ); } - } else if (isString(src.type.value)) { + } else if (isString(src.type.valueType)) { throwCompilationError( - `Unsupported map value type ${idTextErr(src.type.value)}`, + `Unsupported map value type ${idTextErr(src.type.valueType)}`, src.loc, ); } else if ( - isStringBuilder(src.type.value) || - isBuilder(src.type.value) + isStringBuilder(src.type.valueType) || + isBuilder(src.type.valueType) ) { throwCompilationError( - `Unsupported map value type ${idTextErr(src.type.value)}`, + `Unsupported map value type ${idTextErr(src.type.valueType)}`, src.loc, ); } else { - value = idText(src.type.value); + value = idText(src.type.valueType); valueFormat = "ref"; - if (src.type.valueAs && eqNames(src.type.valueAs, "reference")) { + if ( + src.type.valueStorageType && + eqNames(src.type.valueStorageType, "reference") + ) { throwCompilationError( - `Unsupported format ${idTextErr(src.type.valueAs)} for map value`, + `Unsupported format ${idTextErr(src.type.valueStorageType)} for map value`, src.loc, ); } diff --git a/src/types/resolveDescriptors.ts b/src/types/resolveDescriptors.ts index 1f77f8731..de8c2ba9c 100644 --- a/src/types/resolveDescriptors.ts +++ b/src/types/resolveDescriptors.ts @@ -1,12 +1,12 @@ import { AstConstantDef, - ASTField, - ASTInitFunction, + AstFieldDecl, + AstContractInit, AstNativeFunctionDecl, - ASTNode, + AstNode, SrcInfo, - ASTTypeRef, - createNode, + AstType, + createAstNode, traverse, idText, AstId, @@ -17,7 +17,11 @@ import { AstFunctionDecl, AstConstantDecl, } from "../grammar/ast"; -import { idTextErr, throwCompilationError } from "../errors"; +import { + idTextErr, + throwCompilationError, + throwInternalCompilerError, +} from "../errors"; import { CompilerContext, createContextStore } from "../context"; import { ConstantDescription, @@ -116,29 +120,47 @@ function verifyMapType( export const toBounced = (type: string) => `${type}%%BOUNCED%%`; -export function resolveTypeRef(ctx: CompilerContext, src: ASTTypeRef): TypeRef { - if (src.kind === "type_ref_simple") { - const t = getType(ctx, src.name); +export function resolveTypeRef(ctx: CompilerContext, src: AstType): TypeRef { + if (src.kind === "type_id") { + const t = getType(ctx, idText(src)); + return { + kind: "ref", + name: t.name, + optional: false, + }; + } + if (src.kind === "optional_type") { + if (src.typeArg.kind !== "type_id") { + throwInternalCompilerError( + "Only optional type identifiers are supported now", + src.typeArg.loc, + ); + } + const t = getType(ctx, idText(src.typeArg)); return { kind: "ref", name: t.name, - optional: src.optional, + optional: true, }; } - if (src.kind === "type_ref_map") { - const k = getType(ctx, src.key).name; - const v = getType(ctx, src.value).name; - verifyMapType(k, src.keyAs, v, src.valueAs, src.loc); + if (src.kind === "map_type") { + const k = getType(ctx, idText(src.keyType)).name; + const v = getType(ctx, idText(src.valueType)).name; + verifyMapType(k, src.keyStorageType, v, src.valueStorageType, src.loc); return { kind: "map", key: k, - keyAs: src.keyAs !== null ? idText(src.keyAs) : null, + keyAs: + src.keyStorageType !== null ? idText(src.keyStorageType) : null, value: v, - valueAs: src.valueAs !== null ? idText(src.valueAs) : null, + valueAs: + src.valueStorageType !== null + ? idText(src.valueStorageType) + : null, }; } - if (src.kind === "type_ref_bounced") { - const t = getType(ctx, src.name); + if (src.kind === "bounced_message_type") { + const t = getType(ctx, idText(src.messageType)); return { kind: "ref_bounced", name: t.name, @@ -148,47 +170,67 @@ export function resolveTypeRef(ctx: CompilerContext, src: ASTTypeRef): TypeRef { } function buildTypeRef( - src: ASTTypeRef, + src: AstType, types: Map, ): TypeRef { - if (src.kind === "type_ref_simple") { - if (!types.has(idText(src.name))) { + if (src.kind === "type_id") { + if (!types.has(idText(src))) { + throwCompilationError(`Type ${idTextErr(src)} not found`, src.loc); + } + return { + kind: "ref", + name: idText(src), + optional: false, + }; + } + if (src.kind === "optional_type") { + if (src.typeArg.kind !== "type_id") { + throwInternalCompilerError( + "Only optional type identifiers are supported now", + src.typeArg.loc, + ); + } + if (!types.has(idText(src.typeArg))) { throwCompilationError( - `Type ${idTextErr(src.name)} not found`, + `Type ${idTextErr(src.typeArg)} not found`, src.loc, ); } return { kind: "ref", - name: idText(src.name), - optional: src.optional, + name: idText(src.typeArg), + optional: true, }; } - if (src.kind === "type_ref_map") { - if (!types.has(idText(src.key))) { + if (src.kind === "map_type") { + if (!types.has(idText(src.keyType))) { throwCompilationError( - `Type ${idTextErr(src.key)} not found`, + `Type ${idTextErr(src.keyType)} not found`, src.loc, ); } - if (!types.has(idText(src.value))) { + if (!types.has(idText(src.valueType))) { throwCompilationError( - `Type ${idTextErr(src.value)} not found`, + `Type ${idTextErr(src.valueType)} not found`, src.loc, ); } return { kind: "map", - key: idText(src.key), - keyAs: src.keyAs !== null ? idText(src.keyAs) : null, - value: idText(src.value), - valueAs: src.valueAs !== null ? idText(src.valueAs) : null, + key: idText(src.keyType), + keyAs: + src.keyStorageType !== null ? idText(src.keyStorageType) : null, + value: idText(src.valueType), + valueAs: + src.valueStorageType !== null + ? idText(src.valueStorageType) + : null, }; } - if (src.kind === "type_ref_bounced") { + if (src.kind === "bounced_message_type") { return { kind: "ref_bounced", - name: idText(src.name), + name: idText(src.messageType), }; } @@ -316,7 +358,7 @@ export function resolveDescriptors(ctx: CompilerContext) { // function buildFieldDescription( - src: ASTField, + src: AstFieldDecl, index: number, ): FieldDescription { const tr = buildTypeRef(src.type, types); @@ -330,7 +372,9 @@ export function resolveDescriptors(ctx: CompilerContext) { ); } - const d = src.init ? evalConstantExpression(src.init, ctx) : undefined; + const d = src.initializer + ? evalConstantExpression(src.initializer, ctx) + : undefined; // Resolve abi type const type = resolveABIType(src); @@ -368,7 +412,7 @@ export function resolveDescriptors(ctx: CompilerContext) { // Contract if (a.kind === "contract") { for (const f of a.declarations) { - if (f.kind === "def_field") { + if (f.kind === "field_decl") { if ( types .get(idText(a.name))! @@ -464,7 +508,7 @@ export function resolveDescriptors(ctx: CompilerContext) { // Trait if (a.kind === "trait") { for (const f of a.declarations) { - if (f.kind === "def_field") { + if (f.kind === "field_decl") { if ( types .get(idText(a.name))! @@ -809,7 +853,7 @@ export function resolveDescriptors(ctx: CompilerContext) { }; } - function resolveInitFunction(ast: ASTInitFunction): InitDescription { + function resolveInitFunction(ast: AstContractInit): InitDescription { const params: InitParameter[] = []; for (const r of ast.params) { params.push({ @@ -854,7 +898,7 @@ export function resolveDescriptors(ctx: CompilerContext) { } s.functions.set(f.name, f); } - if (d.kind === "def_init_function") { + if (d.kind === "contract_init") { if (s.init) { throwCompilationError( "Init function already exists", @@ -863,7 +907,7 @@ export function resolveDescriptors(ctx: CompilerContext) { } s.init = resolveInitFunction(d); } - if (d.kind === "def_receive") { + if (d.kind === "receiver") { // Check if externals are enabled if ( d.selector.kind.startsWith("external-") && @@ -882,23 +926,16 @@ export function resolveDescriptors(ctx: CompilerContext) { const param = d.selector.param; const internal = d.selector.kind === "internal-simple"; - if (param.type.kind !== "type_ref_simple") { - throwCompilationError( - "Receive function can only accept message", - d.loc, - ); - } - if (param.type.optional) { + if (param.type.kind !== "type_id") { throwCompilationError( - "Receive function cannot have optional parameter", + "Receive function can only accept non-optional message types", d.loc, ); } - - const t = types.get(idText(param.type.name)); + const t = types.get(idText(param.type)); if (!t) { throwCompilationError( - `Type ${idTextErr(param.type.name)} not found`, + `Type ${idTextErr(param.type)} not found`, d.loc, ); } @@ -981,7 +1018,7 @@ export function resolveDescriptors(ctx: CompilerContext) { } // Check for duplicate - const n = param.type.name; + const n = idText(param.type); if ( s.receivers.find( (v) => @@ -993,7 +1030,7 @@ export function resolveDescriptors(ctx: CompilerContext) { ) ) { throwCompilationError( - `Receive function for ${idTextErr(param.type.name)} already exists`, + `Receive function for ${idTextErr(param.type)} already exists`, param.loc, ); } @@ -1005,7 +1042,7 @@ export function resolveDescriptors(ctx: CompilerContext) { ? "internal-binary" : "external-binary", name: param.name, - type: idText(param.type.name), + type: idText(param.type), }, ast: d, }); @@ -1078,15 +1115,8 @@ export function resolveDescriptors(ctx: CompilerContext) { } else if (d.selector.kind === "bounce") { const param = d.selector.param; - if (param.type.kind === "type_ref_simple") { - if (param.type.optional) { - throwCompilationError( - "Bounce receive function cannot have optional parameter", - d.loc, - ); - } - - if (isSlice(param.type.name)) { + if (param.type.kind === "type_id") { + if (isSlice(param.type)) { if ( s.receivers.find( (v) => @@ -1108,9 +1138,7 @@ export function resolveDescriptors(ctx: CompilerContext) { ast: d, }); } else { - const type = types.get( - idText(param.type.name), - )!; + const type = types.get(idText(param.type))!; if (type.ast.kind !== "message_decl") { throwCompilationError( "Bounce receive function can only accept bounced message, message or Slice", @@ -1122,7 +1150,7 @@ export function resolveDescriptors(ctx: CompilerContext) { type.partialFieldCount ) { throwCompilationError( - `This message is too big for bounce receiver, you need to wrap it to a bounced<${idTextErr(param.type.name)}>.`, + `This message is too big for bounce receiver, you need to wrap it to a bounced<${idTextErr(param.type)}>.`, d.loc, ); } @@ -1135,7 +1163,7 @@ export function resolveDescriptors(ctx: CompilerContext) { ) ) { throwCompilationError( - `Bounce receive function for ${idTextErr(param.type.name)} already exists`, + `Bounce receive function for ${idTextErr(param.type)} already exists`, param.loc, ); } @@ -1143,14 +1171,21 @@ export function resolveDescriptors(ctx: CompilerContext) { selector: { kind: "bounce-binary", name: param.name, - type: idText(param.type.name), + type: idText(param.type), bounced: false, }, ast: d, }); } - } else if (param.type.kind === "type_ref_bounced") { - const t = types.get(idText(param.type.name))!; + } else if (param.type.kind === "optional_type") { + throwCompilationError( + "Bounce receive function cannot have optional parameter", + d.loc, + ); + } else if (param.type.kind === "bounced_message_type") { + const t = types.get( + idText(param.type.messageType), + )!; if (t.kind !== "struct") { throwCompilationError( "Bounce receive function can only accept bounced struct types", @@ -1185,7 +1220,7 @@ export function resolveDescriptors(ctx: CompilerContext) { selector: { kind: "bounce-binary", name: param.name, - type: idText(param.type.name), + type: idText(param.type.messageType), bounced: true, }, ast: d, @@ -1216,12 +1251,12 @@ export function resolveDescriptors(ctx: CompilerContext) { if (!t.init) { t.init = { params: [], - ast: createNode({ - kind: "def_init_function", + ast: createAstNode({ + kind: "contract_init", params: [], statements: [], loc: t.ast.loc, - }) as ASTInitFunction, + }) as AstContractInit, }; } } @@ -1613,15 +1648,15 @@ export function resolveDescriptors(ctx: CompilerContext) { for (const [k, t] of types) { const dependsOn = new Set(); - const handler = (src: ASTNode) => { + const handler = (src: AstNode) => { if (src.kind === "init_of") { - if (!types.has(idText(src.name))) { + if (!types.has(idText(src.contract))) { throwCompilationError( - `Type ${idTextErr(src.name)} not found`, + `Type ${idTextErr(src.contract)} not found`, src.loc, ); } - dependsOn.add(idText(src.name)); + dependsOn.add(idText(src.contract)); } }; diff --git a/src/types/resolveErrors.ts b/src/types/resolveErrors.ts index 7abd5084d..38de9d823 100644 --- a/src/types/resolveErrors.ts +++ b/src/types/resolveErrors.ts @@ -1,6 +1,6 @@ import { sha256_sync } from "@ton/crypto"; import { CompilerContext, createContextStore } from "../context"; -import { ASTNode, isRequire, traverse } from "../grammar/ast"; +import { AstNode, isRequire, traverse } from "../grammar/ast"; import { evalConstantExpression } from "../constEval"; import { getAllStaticConstants, @@ -18,9 +18,9 @@ function exceptionId(src: string): number { return (stringId(src) % 63000) + 1000; } -function resolveStringsInAST(ast: ASTNode, ctx: CompilerContext) { +function resolveStringsInAST(ast: AstNode, ctx: CompilerContext) { traverse(ast, (node) => { - if (node.kind === "op_static_call" && isRequire(node.name)) { + if (node.kind === "static_call" && isRequire(node.function)) { if (node.args.length !== 2) { return; } diff --git a/src/types/resolveExpression.ts b/src/types/resolveExpression.ts index 6b7fddff3..5f055f483 100644 --- a/src/types/resolveExpression.ts +++ b/src/types/resolveExpression.ts @@ -1,17 +1,17 @@ import { - ASTBoolean, - ASTExpression, - ASTInitOf, - ASTNull, - ASTNumber, - ASTOpBinary, - ASTOpCall, - ASTOpCallStatic, - ASTOpField, - ASTOpNew, - ASTOpUnary, - ASTString, - ASTConditional, + AstBoolean, + AstExpression, + AstInitOf, + AstNull, + AstNumber, + AstOpBinary, + AstMethodCall, + AstStaticCall, + AstFieldAccess, + AstStructInstance, + AstOpUnary, + AstString, + AstConditional, eqNames, idText, isWildcard, @@ -38,11 +38,11 @@ import { isAssignable, moreGeneralType } from "./subtyping"; import { StructFunctions } from "../abi/struct"; const store = createContextStore<{ - ast: ASTExpression; + ast: AstExpression; description: TypeRef; }>(); -export function getExpType(ctx: CompilerContext, exp: ASTExpression) { +export function getExpType(ctx: CompilerContext, exp: AstExpression) { const t = store.get(ctx, exp.id); if (!t) { throw Error("Expression " + exp.id + " not found"); @@ -52,7 +52,7 @@ export function getExpType(ctx: CompilerContext, exp: ASTExpression) { function registerExpType( ctx: CompilerContext, - exp: ASTExpression, + exp: AstExpression, description: TypeRef, ): CompilerContext { const ex = store.get(ctx, exp.id); @@ -66,7 +66,7 @@ function registerExpType( } function resolveBooleanLiteral( - exp: ASTBoolean, + exp: AstBoolean, sctx: StatementContext, ctx: CompilerContext, ): CompilerContext { @@ -78,7 +78,7 @@ function resolveBooleanLiteral( } function resolveIntLiteral( - exp: ASTNumber, + exp: AstNumber, sctx: StatementContext, ctx: CompilerContext, ): CompilerContext { @@ -90,7 +90,7 @@ function resolveIntLiteral( } function resolveNullLiteral( - exp: ASTNull, + exp: AstNull, sctx: StatementContext, ctx: CompilerContext, ): CompilerContext { @@ -98,7 +98,7 @@ function resolveNullLiteral( } function resolveStringLiteral( - exp: ASTString, + exp: AstString, sctx: StatementContext, ctx: CompilerContext, ): CompilerContext { @@ -110,7 +110,7 @@ function resolveStringLiteral( } function resolveStructNew( - exp: ASTOpNew, + exp: AstStructInstance, sctx: StatementContext, ctx: CompilerContext, ): CompilerContext { @@ -128,31 +128,31 @@ function resolveStructNew( const processed = new Set(); for (const e of exp.args) { // Check duplicates - if (processed.has(idText(e.name))) { + if (processed.has(idText(e.field))) { throwCompilationError( - `Duplicate fields ${idTextErr(e.name)}`, + `Duplicate fields ${idTextErr(e.field)}`, e.loc, ); } - processed.add(idText(e.name)); + processed.add(idText(e.field)); // Check existing - const f = tp.fields.find((v) => eqNames(v.name, e.name)); + const f = tp.fields.find((v) => eqNames(v.name, e.field)); if (!f) { throwCompilationError( - `Unknown fields ${idTextErr(e.name)} in type ${idTextErr(tp.name)}`, + `Unknown fields ${idTextErr(e.field)} in type ${idTextErr(tp.name)}`, e.loc, ); } // Resolve expression - ctx = resolveExpression(e.exp, sctx, ctx); + ctx = resolveExpression(e.initializer, sctx, ctx); // Check expression type - const expressionType = getExpType(ctx, e.exp); + const expressionType = getExpType(ctx, e.initializer); if (!isAssignable(expressionType, f.type)) { throwCompilationError( - `Invalid type "${printTypeRef(expressionType)}" for fields ${idTextErr(e.name)} with type "${printTypeRef(f.type)}" in type "${tp.name}"`, + `Invalid type "${printTypeRef(expressionType)}" for fields ${idTextErr(e.field)} with type "${printTypeRef(f.type)}" in type "${tp.name}"`, e.loc, ); } @@ -177,7 +177,7 @@ function resolveStructNew( } function resolveBinaryOp( - exp: ASTOpBinary, + exp: AstOpBinary, sctx: StatementContext, ctx: CompilerContext, ): CompilerContext { @@ -316,15 +316,15 @@ function resolveBinaryOp( } function resolveUnaryOp( - exp: ASTOpUnary, + exp: AstOpUnary, sctx: StatementContext, ctx: CompilerContext, ): CompilerContext { // Resolve right side - ctx = resolveExpression(exp.right, sctx, ctx); + ctx = resolveExpression(exp.operand, sctx, ctx); // Check right type dependent on operator - let resolvedType = getExpType(ctx, exp.right); + let resolvedType = getExpType(ctx, exp.operand); if (exp.op === "-" || exp.op === "+" || exp.op === "~") { if ( resolvedType.kind !== "ref" || @@ -368,15 +368,15 @@ function resolveUnaryOp( } function resolveFieldAccess( - exp: ASTOpField, + exp: AstFieldAccess, sctx: StatementContext, ctx: CompilerContext, ): CompilerContext { // Resolve expression - ctx = resolveExpression(exp.src, sctx, ctx); + ctx = resolveExpression(exp.aggregate, sctx, ctx); // Find target type and check for type - const src = getExpType(ctx, exp.src); + const src = getExpType(ctx, exp.aggregate); if ( src === null || @@ -391,13 +391,13 @@ function resolveFieldAccess( // Check if field initialized if ( sctx.requiredFields.length > 0 && - exp.src.kind === "id" && - exp.src.text === "self" + exp.aggregate.kind === "id" && + exp.aggregate.text === "self" ) { - if (sctx.requiredFields.find((v) => v === exp.name.text)) { + if (sctx.requiredFields.find((v) => eqNames(v, exp.field))) { throwCompilationError( - `Field "${exp.name.text}" is not initialized`, - exp.name.loc, + `Field ${idTextErr(exp.field)} is not initialized`, + exp.field.loc, ); } } @@ -412,17 +412,17 @@ function resolveFieldAccess( fields = fields.slice(0, srcT.partialFieldCount); } - const field = fields.find((v) => v.name === exp.name.text); - const cst = srcT.constants.find((v) => v.name === exp.name.text); + const field = fields.find((v) => eqNames(v.name, exp.field)); + const cst = srcT.constants.find((v) => eqNames(v.name, exp.field)); if (!field && !cst) { if (src.kind === "ref_bounced") { throwCompilationError( - `Type bounced<"${src.name}"> does not have a field named "${exp.name.text}"`, - exp.name.loc, + `Type bounced<${idTextErr(src.name)}> does not have a field named ${idTextErr(exp.field)}`, + exp.field.loc, ); } else { throwCompilationError( - `Type ${idTextErr(src.name)} does not have a field named ${idTextErr(exp.name)}`, + `Type ${idTextErr(src.name)} does not have a field named ${idTextErr(exp.field)}`, exp.loc, ); } @@ -437,13 +437,13 @@ function resolveFieldAccess( } function resolveStaticCall( - exp: ASTOpCallStatic, + exp: AstStaticCall, sctx: StatementContext, ctx: CompilerContext, ): CompilerContext { // Check if abi global function - if (GlobalFunctions.has(idText(exp.name))) { - const f = GlobalFunctions.get(idText(exp.name))!; + if (GlobalFunctions.has(idText(exp.function))) { + const f = GlobalFunctions.get(idText(exp.function))!; // Resolve arguments for (const e of exp.args) { @@ -462,15 +462,15 @@ function resolveStaticCall( } // Check if function exists - if (!hasStaticFunction(ctx, idText(exp.name))) { + if (!hasStaticFunction(ctx, idText(exp.function))) { throwCompilationError( - `Static function ${idTextErr(exp.name)} does not exist`, + `Static function ${idTextErr(exp.function)} does not exist`, exp.loc, ); } // Get static function - const f = getStaticFunction(ctx, idText(exp.name)); + const f = getStaticFunction(ctx, idText(exp.function)); // Resolve call arguments for (const e of exp.args) { @@ -480,7 +480,7 @@ function resolveStaticCall( // Check arguments if (f.params.length !== exp.args.length) { throwCompilationError( - `Function ${idTextErr(exp.name)} expects ${f.params.length} arguments, got ${exp.args.length}`, + `Function ${idTextErr(exp.function)} expects ${f.params.length} arguments, got ${exp.args.length}`, exp.loc, ); } @@ -501,17 +501,17 @@ function resolveStaticCall( } function resolveCall( - exp: ASTOpCall, + exp: AstMethodCall, sctx: StatementContext, ctx: CompilerContext, ): CompilerContext { // Resolve expression - ctx = resolveExpression(exp.src, sctx, ctx); + ctx = resolveExpression(exp.self, sctx, ctx); // Check if self is initialized if ( - exp.src.kind === "id" && - exp.src.text === "self" && + exp.self.kind === "id" && + exp.self.text === "self" && sctx.requiredFields.length > 0 ) { throwCompilationError("Cannot access self before init", exp.loc); @@ -523,7 +523,7 @@ function resolveCall( } // Resolve return value - const src = getExpType(ctx, exp.src); + const src = getExpType(ctx, exp.self); if (src === null) { throwCompilationError( `Invalid type "${printTypeRef(src)}" for function call`, @@ -545,8 +545,8 @@ function resolveCall( // Check struct ABI if (srcT.kind === "struct") { - if (StructFunctions.has(idText(exp.name))) { - const abi = StructFunctions.get(idText(exp.name))!; + if (StructFunctions.has(idText(exp.method))) { + const abi = StructFunctions.get(idText(exp.method))!; const resolved = abi.resolve( ctx, [src, ...exp.args.map((v) => getExpType(ctx, v))], @@ -556,10 +556,10 @@ function resolveCall( } } - const f = srcT.functions.get(idText(exp.name))!; + const f = srcT.functions.get(idText(exp.method))!; if (!f) { throwCompilationError( - `Type "${src.name}" does not have a function named ${idTextErr(exp.name)}`, + `Type "${src.name}" does not have a function named ${idTextErr(exp.method)}`, exp.loc, ); } @@ -567,7 +567,7 @@ function resolveCall( // Check arguments if (f.params.length !== exp.args.length) { throwCompilationError( - `Function ${idTextErr(exp.name)} expects ${f.params.length} arguments, got ${exp.args.length}`, + `Function ${idTextErr(exp.method)} expects ${f.params.length} arguments, got ${exp.args.length}`, exp.loc, ); } @@ -588,13 +588,13 @@ function resolveCall( // Handle map if (src.kind === "map") { - if (!MapFunctions.has(idText(exp.name))) { + if (!MapFunctions.has(idText(exp.method))) { throwCompilationError( - `Map function ${idTextErr(exp.name)} not found`, + `Map function ${idTextErr(exp.method)} not found`, exp.loc, ); } - const abf = MapFunctions.get(idText(exp.name))!; + const abf = MapFunctions.get(idText(exp.method))!; const resolved = abf.resolve( ctx, [src, ...exp.args.map((v) => getExpType(ctx, v))], @@ -614,21 +614,21 @@ function resolveCall( } export function resolveInitOf( - ast: ASTInitOf, + ast: AstInitOf, sctx: StatementContext, ctx: CompilerContext, ): CompilerContext { // Resolve type - const type = getType(ctx, ast.name); + const type = getType(ctx, ast.contract); if (type.kind !== "contract") { throwCompilationError( - `Type ${idTextErr(ast.name)} is not a contract`, + `Type ${idTextErr(ast.contract)} is not a contract`, ast.loc, ); } if (!type.init) { throwCompilationError( - `Contract ${idTextErr(ast.name)} does not have an init function`, + `Contract ${idTextErr(ast.contract)} does not have an init function`, ast.loc, ); } @@ -666,7 +666,7 @@ export function resolveInitOf( } export function resolveConditional( - ast: ASTConditional, + ast: AstConditional, sctx: StatementContext, ctx: CompilerContext, ): CompilerContext { @@ -706,7 +706,7 @@ export function resolveConditional( } export function resolveExpression( - exp: ASTExpression, + exp: AstExpression, sctx: StatementContext, ctx: CompilerContext, ) { @@ -731,7 +731,7 @@ export function resolveExpression( // Constructors // - if (exp.kind === "op_new") { + if (exp.kind === "struct_instance") { return resolveStructNew(exp, sctx, ctx); } @@ -789,7 +789,7 @@ export function resolveExpression( return registerExpType(ctx, exp, v); } - if (exp.kind === "op_field") { + if (exp.kind === "field_access") { return resolveFieldAccess(exp, sctx, ctx); } @@ -797,11 +797,11 @@ export function resolveExpression( // Function calls // - if (exp.kind === "op_static_call") { + if (exp.kind === "static_call") { return resolveStaticCall(exp, sctx, ctx); } - if (exp.kind === "op_call") { + if (exp.kind === "method_call") { return resolveCall(exp, sctx, ctx); } diff --git a/src/types/resolveSignatures.ts b/src/types/resolveSignatures.ts index 885a45fac..b93d52db0 100644 --- a/src/types/resolveSignatures.ts +++ b/src/types/resolveSignatures.ts @@ -10,7 +10,7 @@ import { ReceiverDescription, } from "./types"; import { throwCompilationError } from "../errors"; -import { ASTReceive } from "../grammar/ast"; +import { AstReceiver } from "../grammar/ast"; import { commentPseudoOpcode } from "../generator/writers/writeRouter"; export function resolveSignatures(ctx: CompilerContext) { @@ -189,7 +189,7 @@ type binOpcode = number; function checkBinaryMessageReceiver( rcv: BinaryReceiverSelector, - rcvAst: ASTReceive, + rcvAst: AstReceiver, usedOpcodes: Map, ctx: CompilerContext, ) { @@ -210,7 +210,7 @@ type commentOpcode = string; // "opcode" clashes are highly unlikely in this case, of course function checkCommentMessageReceiver( rcv: CommentReceiverSelector, - rcvAst: ASTReceive, + rcvAst: AstReceiver, usedOpcodes: Map, ) { const opcode = commentPseudoOpcode(rcv.comment); diff --git a/src/types/resolveStatements.ts b/src/types/resolveStatements.ts index 89f9ee6bd..6db679cdf 100644 --- a/src/types/resolveStatements.ts +++ b/src/types/resolveStatements.ts @@ -1,8 +1,8 @@ import { CompilerContext } from "../context"; import { - ASTCondition, + AstCondition, SrcInfo, - ASTStatement, + AstStatement, tryExtractPath, AstId, idText, @@ -87,7 +87,7 @@ function addVariable( } function processCondition( - condition: ASTCondition, + condition: AstCondition, sctx: StatementContext, ctx: CompilerContext, ): { @@ -96,7 +96,7 @@ function processCondition( returnAlwaysReachable: boolean; } { // Process expression - ctx = resolveExpression(condition.expression, sctx, ctx); + ctx = resolveExpression(condition.condition, sctx, ctx); let initialCtx = sctx; // Simple if @@ -164,7 +164,7 @@ function processCondition( } function processStatements( - statements: ASTStatement[], + statements: AstStatement[], sctx: StatementContext, ctx: CompilerContext, ): { @@ -279,22 +279,14 @@ function processStatements( s.loc, ); } - - // Mark as assigned - if (path.length === 2 && path[0].text === "self") { - const field = path[1].text; - if (sctx.requiredFields.findIndex((v) => v === field) >= 0) { - sctx = removeRequiredVariable(field, sctx); - } - } } else if (s.kind === "statement_expression") { // Process expression ctx = resolveExpression(s.expression, sctx, ctx); // take `throw` and `throwNative` into account when doing // return-reachability analysis if ( - s.expression.kind === "op_static_call" && - ["throw", "nativeThrow"].includes(idText(s.expression.name)) + s.expression.kind === "static_call" && + ["throw", "nativeThrow"].includes(idText(s.expression.function)) ) { returnAlwaysReachable = true; } @@ -306,7 +298,7 @@ function processStatements( returnAlwaysReachable ||= r.returnAlwaysReachable; // Check type - const expressionType = getExpType(ctx, s.expression); + const expressionType = getExpType(ctx, s.condition); if ( expressionType.kind !== "ref" || expressionType.name !== "Bool" || @@ -543,7 +535,7 @@ function processStatements( } function processFunctionBody( - statements: ASTStatement[], + statements: AstStatement[], sctx: StatementContext, ctx: CompilerContext, ): CompilerContext { diff --git a/src/types/stmts-failed/init-vars-analysis-used-uninit-storage-augmented-assign1.tact b/src/types/stmts-failed/init-vars-analysis-used-uninit-storage-augmented-assign1.tact new file mode 100644 index 000000000..75ed36646 --- /dev/null +++ b/src/types/stmts-failed/init-vars-analysis-used-uninit-storage-augmented-assign1.tact @@ -0,0 +1,10 @@ +primitive Int; + +trait BaseTrait { } + +contract Contract { + value: Int; + init() { + self.value = self.value + 1; + } +} \ No newline at end of file diff --git a/src/types/stmts-failed/init-vars-analysis-used-uninit-storage-augmented-assign2.tact b/src/types/stmts-failed/init-vars-analysis-used-uninit-storage-augmented-assign2.tact new file mode 100644 index 000000000..e4fd71035 --- /dev/null +++ b/src/types/stmts-failed/init-vars-analysis-used-uninit-storage-augmented-assign2.tact @@ -0,0 +1,10 @@ +primitive Int; + +trait BaseTrait { } + +contract Contract { + value: Int; + init() { + self.value += 1; + } +} \ No newline at end of file diff --git a/src/types/types.ts b/src/types/types.ts index 340b2ebed..9d3061d5f 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -2,13 +2,13 @@ import { ABIField, Address, Cell } from "@ton/core"; import { AstConstantDef, AstFunctionDef, - ASTInitFunction, + AstContractInit, AstNativeFunctionDecl, - ASTNode, - ASTReceive, + AstNode, + AstReceiver, SrcInfo, - ASTStatement, - ASTType, + AstStatement, + AstTypeDecl, AstId, AstFunctionDecl, AstConstantDecl, @@ -32,7 +32,7 @@ export type TypeDescription = { functions: Map; receivers: ReceiverDescription[]; init: InitDescription | null; - ast: ASTType; + ast: AstTypeDecl; dependsOn: TypeDescription[]; interfaces: string[]; constants: ConstantDescription[]; @@ -87,7 +87,7 @@ export type FieldDescription = { as: string | null; default: Value | undefined; loc: SrcInfo; - ast: ASTNode; + ast: AstNode; abi: ABIField; }; @@ -130,7 +130,7 @@ export type FunctionDescription = { export type StatementDescription = | { kind: "native"; - src: ASTStatement; + src: AstStatement; } | { kind: "intrinsic"; @@ -225,12 +225,12 @@ export function receiverSelectorName(selector: ReceiverSelector): string { export type ReceiverDescription = { selector: ReceiverSelector; - ast: ASTReceive; + ast: AstReceiver; }; export type InitDescription = { params: InitParameter[]; - ast: ASTInitFunction; + ast: AstContractInit; }; export function printTypeRef(src: TypeRef): string {