Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cd1m0 committed Mar 9, 2024
1 parent a6c3c7b commit 0499e67
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/lib/souffle/ast/declarations/adt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export class AlgebraicDataType extends Declaration {
}

pp(indent: string = ""): string {
return `${indent}.type ${this.name} = [${this.branches
return `${indent}.type ${this.name} = ${this.branches
.map((b) => `${b[0]} {${b[1].map((f) => `${f[0]}: ${f[1].pp()}`).join(", ")}}`)
.join(" | ")}]`;
.join(" | ")}`;
}

children(): Iterable<Node> {
Expand Down
8 changes: 5 additions & 3 deletions src/lib/souffle/ast/declarations/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ export class Component extends Declaration {
}

pp(indent: string = ""): string {
const innerIndent = indent + " ";

return `${indent}.comp ${Component.ppCompInv([this.name, this.typeParams])}${
this.bases.length ? 0 : this.bases.map(Component.ppCompInv).join(", ")
this.bases.length == 0 ? "" : ":" + this.bases.map(Component.ppCompInv).join(", ")
} {
${this.body.map((x) => x.pp(indent + " ")).join("\n")}
${this.body.map((x) => x.pp(innerIndent)).join("\n")}
}`;
}

Expand All @@ -30,6 +32,6 @@ export class Component extends Declaration {
}

getStructId(): any {
return [this.name, ...this.typeParams, ...this.bases, ...this.body];
return [this.name, this.typeParams, this.bases, this.body];
}
}
10 changes: 6 additions & 4 deletions src/lib/souffle/ast/declarations/directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ export class Directive extends Declaration {
}

pp(indent: string = ""): string {
return `${indent}${this.type} ${this.name}(${this.parameters
.map(([name, val]) => `${name} = ${val}`)
.join(", ")})`;
const paramStr = this.parameters
.map(([name, val]) => `${name} = ${typeof val === "string" ? `"${val}"` : val}`)
.join(", ");

return `${indent}${this.type} ${this.name}${paramStr.length > 0 ? `(${paramStr})` : ""}`;
}

children(): Iterable<Node> {
return [];
}

getStructId(): any {
return [this.type, this.name, ...this.parameters];
return [this.type, this.name, this.parameters];
}
}
2 changes: 1 addition & 1 deletion src/lib/souffle/ast/declarations/functor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export class Functor extends Declaration {
}

getStructId(): any {
return [this.name, ...this.args, this.returnType, this.stateful];
return [this.name, this.args, this.returnType, this.stateful];
}
}
2 changes: 1 addition & 1 deletion src/lib/souffle/ast/declarations/record_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export class RecordType extends Declaration {
}

getStructId(): any {
return [this.name, ...this.fields];
return [this.name, this.fields];
}
}
6 changes: 4 additions & 2 deletions src/lib/souffle/ast/declarations/relation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Relation extends Declaration {

return `${indent}.decl ${this.name}(${this.args
.map((a) => `${a[0]}: ${a[1].pp()}`)
.join(", ")}) ${[...this.tags].join(" ")}${
.join(", ")}) ${[...this.tags].join(" ") + " "}${
choiceStrs.length > 0 ? `choice-domain ${choiceStrs.join(", ")}` : ""
}`;
}
Expand All @@ -50,6 +50,8 @@ export class Relation extends Declaration {
}

getStructId(): any {
return [this.name, ...this.args, [...this.tags], this.choiceDomains];
const tags = [...this.tags];
tags.sort();
return [this.name, this.args, tags, this.choiceDomains];
}
}
2 changes: 1 addition & 1 deletion src/lib/souffle/ast/declarations/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Rule extends Declaration {
let queryPlanStr = "";

if (this.queryPlan.length > 0) {
queryPlanStr += ".plan";
queryPlanStr += " .plan";
queryPlanStr += this.queryPlan
.map(([num, nums]) => `${num}: (${nums.map((x) => `${x}`).join(", ")})`)
.join(", ");
Expand Down
17 changes: 16 additions & 1 deletion src/lib/souffle/ast/expressions/binary.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import { Node, Src } from "../node";
import { Expression } from "./expression";

export type BinaryOp = "+";
export type BinaryOp =
| "+"
| "-"
| "*"
| "/"
| "%"
| "^"
| "land"
| "lor"
| "lxor"
| "band"
| "bor"
| "bxor"
| "bshl"
| "bshr"
| "bshru";

export class BinaryOperator extends Expression {
constructor(
Expand Down
4 changes: 2 additions & 2 deletions src/lib/souffle/ast/expressions/unary.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Node, Src } from "../node";
import { Expression } from "./expression";

export type UnaryOp = "-" | "~" | "!";
export type UnaryOp = "-" | "bnot" | "lnot";

export class UnaryOperator extends Expression {
constructor(
Expand All @@ -13,7 +13,7 @@ export class UnaryOperator extends Expression {
}

pp(): string {
return `${this.op}(${this.subExpr.pp()})`;
return `(${this.op}${this.subExpr.pp()})`;
}

children(): Iterable<Node> {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/souffle/ast/rules/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export class Atom extends Node {
}

getStructId(): any {
return [this.name, ...this.args];
return [this.name, this.args];
}
}
2 changes: 1 addition & 1 deletion src/lib/souffle/ast/rules/constraints/comparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Comparison extends Constraint {
}

pp(): string {
return `${this.lhs.pp()} ${this.op} ${this.rhs.pp()}`;
return `(${this.lhs.pp()} ${this.op} ${this.rhs.pp()})`;
}

children(): Iterable<Node> {
Expand Down
2 changes: 2 additions & 0 deletions test/samples/analyses/fcall.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
[52, 15, [52, [15, null]]],
[52, 22, [52, [8, [22, null]]]],
[52, 29, [52, [15, [29, null]]]],
[52, 29, [52, [8, [22, [29, null]]]]],
[52, 40, [52, [15, [29, [40, null]]]]],
[52, 40, [52, [8, [22, [29, [40, null]]]]]],
[59, 59, [59, [59, null]]]
]
}
4 changes: 2 additions & 2 deletions test/succ.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ describe("Test succ relation for all samples", () => {
describe(sample, () => {
let units: sol.SourceUnit[];
let infer: sol.InferType;
let contents: string;
let contents: Buffer;
let succ: Fact[];
let succFirst: NdGraph;
let g: NdGraph;

before(async () => {
contents = fse.readFileSync(sample, { encoding: "utf-8" });
contents = fse.readFileSync(sample);
const result = await sol.compileSol(sample, "auto");

const data = result.data;
Expand Down

0 comments on commit 0499e67

Please sign in to comment.