Skip to content

Commit a122850

Browse files
committed
Expose flatSwitch and Simplify
Simplify and FlatSwitch can now be controlled both in the demo and the extension
1 parent c36d107 commit a122850

File tree

6 files changed

+63
-100
lines changed

6 files changed

+63
-100
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
"type": "boolean",
7373
"default": "true",
7474
"description": "Simplify the graph by collapsing trivial paths."
75+
},
76+
"functionGraphOverview.flatSwitch": {
77+
"type": "boolean",
78+
"default": "false",
79+
"description": "Flatten switches, so that all cases are direct descendants of the root."
7580
}
7681
}
7782
},

src/frontend/src/lib/Demo.svelte

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<script lang="ts">
22
import CodeMirror from "svelte-codemirror-editor";
33
import { go } from "@codemirror/lang-go";
4-
import SimpleGraph from "./SimpleGraph.svelte";
4+
import Graph from "./Graph.svelte";
55
66
export let code = "func Example() {\n\tif x {\n\t\treturn\n\t}\n}";
7+
8+
let simplify = true;
9+
let flatSwitch = false;
710
</script>
811

912
<main>
@@ -28,7 +31,14 @@
2831
</div>
2932
</div>
3033
<div class="graph">
31-
<SimpleGraph {code} />
34+
<div class="controls">
35+
<input type="checkbox" id="simplify" bind:checked={simplify} />
36+
<label for="simplify">Simplify</label>
37+
38+
<input type="checkbox" id="flatSwitch" bind:checked={flatSwitch} />
39+
<label for="flatSwitch">Flat Switch</label>
40+
</div>
41+
<Graph {code} {simplify} {flatSwitch} />
3242
</div>
3343
</main>
3444

@@ -51,6 +61,11 @@
5161
background-color: white;
5262
position: relative;
5363
}
64+
.controls {
65+
font-family: Arial, Helvetica, sans-serif;
66+
margin-top: 1rem;
67+
margin-left: 1rem;
68+
}
5469
.graph,
5570
.editor {
5671
background-color: white;

src/frontend/src/lib/Graph.svelte

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
export let simplify: boolean = true;
1717
export let trim: boolean = true;
1818
export let flatSwitch: boolean = false;
19+
export let showDot: boolean = false;
20+
export let showAST: boolean = false;
1921
2022
async function initialize() {
2123
parser = await initializeParser();
@@ -70,20 +72,33 @@
7072
}
7173
</script>
7274

73-
<div class="graph">
75+
<div class="results">
7476
{#await initialize() then}
75-
{@html renderWrapper(code, { simplify, verbose, trim, flatSwitch })}
77+
<div class="graph">
78+
{@html renderWrapper(code, { simplify, verbose, trim, flatSwitch })}
79+
</div>
7680
{/await}
77-
<br />
78-
<details>
79-
<summary>AST</summary>
80-
{@html ast}
81-
</details>
82-
<details>
83-
<summary>DOT</summary>
84-
<pre>{dot}</pre>
85-
</details>
81+
{#if showAST}
82+
<br />
83+
<details>
84+
<summary>AST</summary>
85+
{@html ast}
86+
</details>
87+
{/if}
88+
{#if showDot}
89+
<br />
90+
<details>
91+
<summary>DOT</summary>
92+
<pre>{dot}</pre>
93+
</details>
94+
{/if}
8695
</div>
8796

8897
<style>
98+
.graph {
99+
display: flex;
100+
align-items: center;
101+
justify-content: center;
102+
padding: 1em;
103+
}
89104
</style>

src/frontend/src/lib/SampleViewer.svelte

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@
2929
<div class="container">
3030
{#each Object.entries(goSamples) as [name, code] (name)}
3131
<div class="code"><pre>{code}</pre></div>
32-
<Graph {code} {simplify} {verbose} {trim} {flatSwitch} />
32+
<Graph
33+
{code}
34+
{simplify}
35+
{verbose}
36+
{trim}
37+
{flatSwitch}
38+
showAST={true}
39+
showDot={true}
40+
/>
3341
{/each}
3442
</div>
3543

src/frontend/src/lib/SimpleGraph.svelte

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/vscode/extension.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ export async function activate(context: vscode.ExtensionContext) {
116116
);
117117
console.log("Currently in", name);
118118
}
119-
120-
const builder = new CFGBuilder();
119+
const flatSwitch = Boolean(
120+
vscode.workspace
121+
.getConfiguration("functionGraphOverview")
122+
.get("flatSwitch"),
123+
);
124+
const builder = new CFGBuilder({ flatSwitch });
121125
let cfg = builder.buildCFG(node);
122126
cfg = trimFor(cfg);
123127
if (

0 commit comments

Comments
 (0)