Skip to content

Commit

Permalink
Merge branch 'flat-switch-option'
Browse files Browse the repository at this point in the history
  • Loading branch information
tmr232 committed Sep 7, 2024
2 parents c36d107 + 134bb9f commit cc1e1eb
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 100 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
- Learned Go's `fallthrough` keyword
- Learned an option to draw flat-switches (where all cases are direct descendants of the switch head)
- Added utilities for basic reachability testing
- Expose `simplify` and `flat switch` settings in demo
- Expose `flat switch` setting in extension

## [0.0.2] - 2024-09-06

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
"type": "boolean",
"default": "true",
"description": "Simplify the graph by collapsing trivial paths."
},
"functionGraphOverview.flatSwitch": {
"type": "boolean",
"default": "false",
"description": "Flatten switches, so that all cases are direct descendants of the root."
}
}
},
Expand Down
19 changes: 17 additions & 2 deletions src/frontend/src/lib/Demo.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<script lang="ts">
import CodeMirror from "svelte-codemirror-editor";
import { go } from "@codemirror/lang-go";
import SimpleGraph from "./SimpleGraph.svelte";
import Graph from "./Graph.svelte";
export let code = "func Example() {\n\tif x {\n\t\treturn\n\t}\n}";
let simplify = true;
let flatSwitch = false;
</script>

<main>
Expand All @@ -28,7 +31,14 @@
</div>
</div>
<div class="graph">
<SimpleGraph {code} />
<div class="controls">
<input type="checkbox" id="simplify" bind:checked={simplify} />
<label for="simplify">Simplify</label>

<input type="checkbox" id="flatSwitch" bind:checked={flatSwitch} />
<label for="flatSwitch">Flat Switch</label>
</div>
<Graph {code} {simplify} {flatSwitch} />
</div>
</main>

Expand All @@ -51,6 +61,11 @@
background-color: white;
position: relative;
}
.controls {
font-family: Arial, Helvetica, sans-serif;
margin-top: 1rem;
margin-left: 1rem;
}
.graph,
.editor {
background-color: white;
Expand Down
37 changes: 26 additions & 11 deletions src/frontend/src/lib/Graph.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
export let simplify: boolean = true;
export let trim: boolean = true;
export let flatSwitch: boolean = false;
export let showDot: boolean = false;
export let showAST: boolean = false;
async function initialize() {
parser = await initializeParser();
Expand Down Expand Up @@ -70,20 +72,33 @@
}
</script>

<div class="graph">
<div class="results">
{#await initialize() then}
{@html renderWrapper(code, { simplify, verbose, trim, flatSwitch })}
<div class="graph">
{@html renderWrapper(code, { simplify, verbose, trim, flatSwitch })}
</div>
{/await}
<br />
<details>
<summary>AST</summary>
{@html ast}
</details>
<details>
<summary>DOT</summary>
<pre>{dot}</pre>
</details>
{#if showAST}
<br />
<details>
<summary>AST</summary>
{@html ast}
</details>
{/if}
{#if showDot}
<br />
<details>
<summary>DOT</summary>
<pre>{dot}</pre>
</details>
{/if}
</div>

<style>
.graph {
display: flex;
align-items: center;
justify-content: center;
padding: 1em;
}
</style>
10 changes: 9 additions & 1 deletion src/frontend/src/lib/SampleViewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@
<div class="container">
{#each Object.entries(goSamples) as [name, code] (name)}
<div class="code"><pre>{code}</pre></div>
<Graph {code} {simplify} {verbose} {trim} {flatSwitch} />
<Graph
{code}
{simplify}
{verbose}
{trim}
{flatSwitch}
showAST={true}
showDot={true}
/>
{/each}
</div>

Expand Down
84 changes: 0 additions & 84 deletions src/frontend/src/lib/SimpleGraph.svelte

This file was deleted.

8 changes: 6 additions & 2 deletions src/vscode/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,12 @@ export async function activate(context: vscode.ExtensionContext) {
);
console.log("Currently in", name);
}

const builder = new CFGBuilder();
const flatSwitch = Boolean(
vscode.workspace
.getConfiguration("functionGraphOverview")
.get("flatSwitch"),
);
const builder = new CFGBuilder({ flatSwitch });
let cfg = builder.buildCFG(node);
cfg = trimFor(cfg);
if (
Expand Down

0 comments on commit cc1e1eb

Please sign in to comment.