Skip to content

Commit

Permalink
feat(astUtil): Restore AST iterators + add tests for traits
Browse files Browse the repository at this point in the history
The iterators in the Tact API seems broken after refactoring.

Addresses #30

Closes #29 as 'wonfix'
  • Loading branch information
byakuren-hijiri committed Jul 27, 2024
1 parent 3b29a8e commit 256b4e0
Show file tree
Hide file tree
Showing 22 changed files with 773 additions and 210 deletions.
10 changes: 5 additions & 5 deletions src/detectors/builtin/divideBeforeMultiply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ import {
MistiTactError,
Severity,
} from "../../internals/errors";
import {
forEachExpression,
forEachStatement,
foldExpressions,
} from "../../internals/tactASTUtil";
import {
AstStatement,
AstNode,
AstExpression,
AstOpBinary,
SrcInfo,
} from "@tact-lang/compiler/dist/grammar/ast";
import { forEachExpression } from "../../internals/tactASTUtil";
import {
forEachStatement,
foldExpressions,
} from "@tact-lang/compiler/dist/grammar/iterators";

/**
* A detector that identifies and corrects instances of division before multiplication to
Expand Down
7 changes: 5 additions & 2 deletions src/detectors/builtin/unboundLoops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ import {
Severity,
makeDocURL,
} from "../../internals/errors";
import { extractPath, forEachExpression } from "../../internals/tactASTUtil";
import {
extractPath,
forEachExpression,
forEachStatement,
} from "../../internals/tactASTUtil";
import { AstStatement, SrcInfo } from "@tact-lang/compiler/dist/grammar/ast";
import { forEachStatement } from "@tact-lang/compiler/dist/grammar/iterators";

/**
* A detector that analyzes loop conditions and control flow to ensure loops have proper termination criteria.
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/builtin/zeroAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
MistiTactError,
Severity,
} from "../../internals/errors";
import { foldExpressions } from "../../internals/tactASTUtil";
import { AstExpression } from "@tact-lang/compiler/dist/grammar/ast";
import { foldExpressions } from "@tact-lang/compiler/dist/grammar/iterators";

function findZeroAddress(
ctx: MistiContext,
Expand Down
7 changes: 5 additions & 2 deletions src/internals/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import JSONbig from "json-bigint";

const REPORT_TEXT =
"Please report this output and the input sources to https://github.com/nowarp/misti/issues/new";
const SEPARATOR =
"============================================================";

export class TactException {
private constructor() {}
Expand All @@ -11,9 +13,10 @@ export class TactException {
return new Error(
[
"Internal Tact Compiler Error:",
SEPARATOR,
error.message,
error.stack,
"",
SEPARATOR,
REPORT_TEXT,
].join("\n"),
);
Expand Down Expand Up @@ -44,7 +47,7 @@ export class InternalException {
msg,
...(node === undefined
? []
: [`AST node:\n${JSONbig.stringify(node, null, 2)}`]),
: [`${SEPARATOR}\nAST node:\n${JSONbig.stringify(node, null, 2)}`]),
REPORT_TEXT,
].join("\n"),
);
Expand Down
Loading

0 comments on commit 256b4e0

Please sign in to comment.