Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/slang-nodes/AbicoderPragma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { AbicoderVersion } from './AbicoderVersion.js';

import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc } from 'prettier';
import type { PrintFunction } from '../types.d.ts';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';

export class AbicoderPragma extends SlangNode {
readonly kind = NonterminalKind.AbicoderPragma;

version: AbicoderVersion;

constructor(ast: ast.AbicoderPragma) {
super(ast);
constructor(ast: ast.AbicoderPragma, collected: CollectedMetadata) {
super(ast, collected);

this.version = new AbicoderVersion(ast.version);
this.version = new AbicoderVersion(ast.version, collected);
}

print(path: AstPath<AbicoderPragma>, print: PrintFunction): Doc {
Expand Down
5 changes: 3 additions & 2 deletions src/slang-nodes/AbicoderVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { SlangNode } from './SlangNode.js';

import type * as ast from '@nomicfoundation/slang/ast';
import type { Doc } from 'prettier';
import type { CollectedMetadata } from '../types.d.ts';

export class AbicoderVersion extends SlangNode {
readonly kind = NonterminalKind.AbicoderVersion;

variant: string;

constructor(ast: ast.AbicoderVersion) {
super(ast);
constructor(ast: ast.AbicoderVersion, collected: CollectedMetadata) {
super(ast, collected);

this.variant = ast.variant.unparse();
}
Expand Down
16 changes: 11 additions & 5 deletions src/slang-nodes/AdditiveExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Expression } from './Expression.js';

import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { PrintFunction } from '../types.d.ts';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
import type { AstNode } from './types.d.ts';

const tryToHug = createHugFunction(['%']);
Expand All @@ -35,13 +35,19 @@ export class AdditiveExpression extends SlangNode {

rightOperand: Expression['variant'];

constructor(ast: ast.AdditiveExpression, options: ParserOptions<AstNode>) {
super(ast);
constructor(
ast: ast.AdditiveExpression,
collected: CollectedMetadata,
options: ParserOptions<AstNode>
) {
super(ast, collected);

this.leftOperand = extractVariant(new Expression(ast.leftOperand, options));
this.leftOperand = extractVariant(
new Expression(ast.leftOperand, collected, options)
);
this.operator = ast.operator.unparse();
this.rightOperand = extractVariant(
new Expression(ast.rightOperand, options)
new Expression(ast.rightOperand, collected, options)
);

this.updateMetadata(this.leftOperand, this.rightOperand);
Expand Down
5 changes: 3 additions & 2 deletions src/slang-nodes/AddressType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { SlangNode } from './SlangNode.js';

import type * as ast from '@nomicfoundation/slang/ast';
import type { Doc } from 'prettier';
import type { CollectedMetadata } from '../types.d.ts';

export class AddressType extends SlangNode {
readonly kind = NonterminalKind.AddressType;

payableKeyword?: string;

constructor(ast: ast.AddressType) {
super(ast);
constructor(ast: ast.AddressType, collected: CollectedMetadata) {
super(ast, collected);

this.payableKeyword = ast.payableKeyword?.unparse();
}
Expand Down
16 changes: 11 additions & 5 deletions src/slang-nodes/AndExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Expression } from './Expression.js';

import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { PrintFunction } from '../types.d.ts';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
import type { AstNode } from './types.d.ts';

export class AndExpression extends SlangNode {
Expand All @@ -18,13 +18,19 @@ export class AndExpression extends SlangNode {

rightOperand: Expression['variant'];

constructor(ast: ast.AndExpression, options: ParserOptions<AstNode>) {
super(ast);
constructor(
ast: ast.AndExpression,
collected: CollectedMetadata,
options: ParserOptions<AstNode>
) {
super(ast, collected);

this.leftOperand = extractVariant(new Expression(ast.leftOperand, options));
this.leftOperand = extractVariant(
new Expression(ast.leftOperand, collected, options)
);
this.operator = ast.operator.unparse();
this.rightOperand = extractVariant(
new Expression(ast.rightOperand, options)
new Expression(ast.rightOperand, collected, options)
);

this.updateMetadata(this.leftOperand, this.rightOperand);
Expand Down
16 changes: 11 additions & 5 deletions src/slang-nodes/ArgumentsDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import { PositionalArgumentsDeclaration } from './PositionalArgumentsDeclaration
import { NamedArgumentsDeclaration } from './NamedArgumentsDeclaration.js';

import type { ParserOptions } from 'prettier';
import type { CollectedMetadata } from '../types.d.ts';
import type { AstNode } from './types.d.ts';

function createNonterminalVariant(
variant: ast.ArgumentsDeclaration['variant'],
collected: CollectedMetadata,
options: ParserOptions<AstNode>
): ArgumentsDeclaration['variant'] {
if (variant instanceof ast.PositionalArgumentsDeclaration) {
return new PositionalArgumentsDeclaration(variant, options);
return new PositionalArgumentsDeclaration(variant, collected, options);
}
if (variant instanceof ast.NamedArgumentsDeclaration) {
return new NamedArgumentsDeclaration(variant, options);
return new NamedArgumentsDeclaration(variant, collected, options);
}
const exhaustiveCheck: never = variant;
throw new Error(`Unexpected variant: ${JSON.stringify(exhaustiveCheck)}`);
Expand All @@ -26,10 +28,14 @@ export class ArgumentsDeclaration extends SlangNode {

variant: PositionalArgumentsDeclaration | NamedArgumentsDeclaration;

constructor(ast: ast.ArgumentsDeclaration, options: ParserOptions<AstNode>) {
super(ast);
constructor(
ast: ast.ArgumentsDeclaration,
collected: CollectedMetadata,
options: ParserOptions<AstNode>
) {
super(ast, collected);

this.variant = createNonterminalVariant(ast.variant, options);
this.variant = createNonterminalVariant(ast.variant, collected, options);

this.updateMetadata(this.variant);
}
Expand Down
12 changes: 8 additions & 4 deletions src/slang-nodes/ArrayExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import { ArrayValues } from './ArrayValues.js';

import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { PrintFunction } from '../types.d.ts';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
import type { AstNode } from './types.d.ts';

export class ArrayExpression extends SlangNode {
readonly kind = NonterminalKind.ArrayExpression;

items: ArrayValues;

constructor(ast: ast.ArrayExpression, options: ParserOptions<AstNode>) {
super(ast);
constructor(
ast: ast.ArrayExpression,
collected: CollectedMetadata,
options: ParserOptions<AstNode>
) {
super(ast, collected);

this.items = new ArrayValues(ast.items, options);
this.items = new ArrayValues(ast.items, collected, options);
}

print(path: AstPath<ArrayExpression>, print: PrintFunction): Doc {
Expand Down
18 changes: 13 additions & 5 deletions src/slang-nodes/ArrayTypeName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Expression } from './Expression.js';

import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { PrintFunction } from '../types.d.ts';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
import type { AstNode } from './types.d.ts';

export class ArrayTypeName extends SlangNode {
Expand All @@ -16,12 +16,20 @@ export class ArrayTypeName extends SlangNode {

index?: Expression['variant'];

constructor(ast: ast.ArrayTypeName, options: ParserOptions<AstNode>) {
super(ast);
constructor(
ast: ast.ArrayTypeName,
collected: CollectedMetadata,
options: ParserOptions<AstNode>
) {
super(ast, collected);

this.operand = extractVariant(new TypeName(ast.operand, options));
this.operand = extractVariant(
new TypeName(ast.operand, collected, options)
);
if (ast.index) {
this.index = extractVariant(new Expression(ast.index, options));
this.index = extractVariant(
new Expression(ast.index, collected, options)
);
}

this.updateMetadata(this.operand, this.index);
Expand Down
12 changes: 8 additions & 4 deletions src/slang-nodes/ArrayValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ import { Expression } from './Expression.js';

import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { PrintFunction } from '../types.d.ts';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
import type { AstNode } from './types.d.ts';

export class ArrayValues extends SlangNode {
readonly kind = NonterminalKind.ArrayValues;

items: Expression['variant'][];

constructor(ast: ast.ArrayValues, options: ParserOptions<AstNode>) {
super(ast, true);
constructor(
ast: ast.ArrayValues,
collected: CollectedMetadata,
options: ParserOptions<AstNode>
) {
super(ast, collected, true);

this.items = ast.items.map((item) =>
extractVariant(new Expression(item, options))
extractVariant(new Expression(item, collected, options))
);
}

Expand Down
14 changes: 10 additions & 4 deletions src/slang-nodes/AssemblyFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ import { StringLiteral } from './StringLiteral.js';

import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { PrintFunction } from '../types.d.ts';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
import type { AstNode } from './types.d.ts';

export class AssemblyFlags extends SlangNode {
readonly kind = NonterminalKind.AssemblyFlags;

items: StringLiteral[];

constructor(ast: ast.AssemblyFlags, options: ParserOptions<AstNode>) {
super(ast, true);
constructor(
ast: ast.AssemblyFlags,
collected: CollectedMetadata,
options: ParserOptions<AstNode>
) {
super(ast, collected, true);

this.items = ast.items.map((item) => new StringLiteral(item, options));
this.items = ast.items.map(
(item) => new StringLiteral(item, collected, options)
);
}

print(path: AstPath<AssemblyFlags>, print: PrintFunction): Doc {
Expand Down
7 changes: 4 additions & 3 deletions src/slang-nodes/AssemblyFlagsDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AssemblyFlags } from './AssemblyFlags.js';

import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { PrintFunction } from '../types.d.ts';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
import type { AstNode } from './types.d.ts';

export class AssemblyFlagsDeclaration extends SlangNode {
Expand All @@ -14,11 +14,12 @@ export class AssemblyFlagsDeclaration extends SlangNode {

constructor(
ast: ast.AssemblyFlagsDeclaration,
collected: CollectedMetadata,
options: ParserOptions<AstNode>
) {
super(ast);
super(ast, collected);

this.flags = new AssemblyFlags(ast.flags, options);
this.flags = new AssemblyFlags(ast.flags, collected, options);

this.updateMetadata(this.flags);
}
Expand Down
16 changes: 10 additions & 6 deletions src/slang-nodes/AssemblyStatement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { YulBlock } from './YulBlock.js';

import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { PrintFunction } from '../types.d.ts';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
import type { AstNode } from './types.d.ts';

export class AssemblyStatement extends SlangNode {
Expand All @@ -19,16 +19,20 @@ export class AssemblyStatement extends SlangNode {

body: YulBlock;

constructor(ast: ast.AssemblyStatement, options: ParserOptions<AstNode>) {
super(ast);
constructor(
ast: ast.AssemblyStatement,
collected: CollectedMetadata,
options: ParserOptions<AstNode>
) {
super(ast, collected);

if (ast.label) {
this.label = new StringLiteral(ast.label, options);
this.label = new StringLiteral(ast.label, collected, options);
}
if (ast.flags) {
this.flags = new AssemblyFlagsDeclaration(ast.flags, options);
this.flags = new AssemblyFlagsDeclaration(ast.flags, collected, options);
}
this.body = new YulBlock(ast.body, options);
this.body = new YulBlock(ast.body, collected, options);

this.updateMetadata(this.label, this.flags, this.body);
}
Expand Down
16 changes: 11 additions & 5 deletions src/slang-nodes/AssignmentExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TerminalNode } from './TerminalNode.js';

import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { PrintFunction } from '../types.d.ts';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
import type { AstNode } from './types.d.ts';

export class AssignmentExpression extends SlangNode {
Expand All @@ -20,13 +20,19 @@ export class AssignmentExpression extends SlangNode {

rightOperand: Expression['variant'];

constructor(ast: ast.AssignmentExpression, options: ParserOptions<AstNode>) {
super(ast);
constructor(
ast: ast.AssignmentExpression,
collected: CollectedMetadata,
options: ParserOptions<AstNode>
) {
super(ast, collected);

this.leftOperand = extractVariant(new Expression(ast.leftOperand, options));
this.leftOperand = extractVariant(
new Expression(ast.leftOperand, collected, options)
);
this.operator = ast.operator.unparse();
this.rightOperand = extractVariant(
new Expression(ast.rightOperand, options)
new Expression(ast.rightOperand, collected, options)
);

this.updateMetadata(this.leftOperand, this.rightOperand);
Expand Down
Loading