Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 3 additions & 7 deletions src/slang-nodes/AdditiveExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,15 @@ export class AdditiveExpression extends SlangNode {

rightOperand: Expression['variant'];

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

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

this.updateMetadata(this.leftOperand, this.rightOperand);
Expand Down
10 changes: 3 additions & 7 deletions src/slang-nodes/AndExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,15 @@ export class AndExpression extends SlangNode {

rightOperand: Expression['variant'];

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

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

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

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

const createNonterminalVariant = createNonterminalVariantSimpleCreator<
ast.ArgumentsDeclaration,
Expand All @@ -22,14 +20,10 @@ export class ArgumentsDeclaration extends SlangNode {

variant: PositionalArgumentsDeclaration | NamedArgumentsDeclaration;

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

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

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

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

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

items: ArrayValues;

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

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

this.updateMetadata(this.items);
}
Expand Down
17 changes: 4 additions & 13 deletions src/slang-nodes/ArrayTypeName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import { TypeName } from './TypeName.js';
import { Expression } from './Expression.js';

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

export class ArrayTypeName extends SlangNode {
readonly kind = NonterminalKind.ArrayTypeName;
Expand All @@ -16,20 +15,12 @@ export class ArrayTypeName extends SlangNode {

index?: Expression['variant'];

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

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

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

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

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

items: Expression['variant'][];

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

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

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

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

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

items: StringLiteral[];

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

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

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

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

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

flags: AssemblyFlags;

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

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

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

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

export class AssemblyStatement extends SlangNode {
readonly kind = NonterminalKind.AssemblyStatement;
Expand All @@ -19,20 +18,16 @@ export class AssemblyStatement extends SlangNode {

body: YulBlock;

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

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

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

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

export class AssignmentExpression extends SlangNode {
readonly kind = NonterminalKind.AssignmentExpression;
Expand All @@ -18,19 +17,15 @@ export class AssignmentExpression extends SlangNode {

rightOperand: Expression['variant'];

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

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

this.updateMetadata(this.leftOperand, this.rightOperand);
Expand Down
10 changes: 3 additions & 7 deletions src/slang-nodes/BitwiseAndExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,15 @@ export class BitwiseAndExpression extends SlangNode {

rightOperand: Expression['variant'];

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

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

this.updateMetadata(this.leftOperand, this.rightOperand);
Expand Down
10 changes: 3 additions & 7 deletions src/slang-nodes/BitwiseOrExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,15 @@ export class BitwiseOrExpression extends SlangNode {

rightOperand: Expression['variant'];

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

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

this.updateMetadata(this.leftOperand, this.rightOperand);
Expand Down
10 changes: 3 additions & 7 deletions src/slang-nodes/BitwiseXorExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,15 @@ export class BitwiseXorExpression extends SlangNode {

rightOperand: Expression['variant'];

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

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

this.updateMetadata(this.leftOperand, this.rightOperand);
Expand Down
11 changes: 3 additions & 8 deletions src/slang-nodes/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@ import { SlangNode } from './SlangNode.js';
import { Statements } from './Statements.js';

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

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

statements: Statements;

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

this.statements = new Statements(ast.statements, collected, options);
this.statements = new Statements(ast.statements, collected);

this.updateMetadata(this.statements);
}
Expand Down
Loading