Commit a6356ac6 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[turbolizer] Enable more tslint checks

 - Ban T[] array syntax
 - Format arrow function arguments consistently

Bug: v8:7327
Notry: true
Change-Id: I072a352ec9009948392a6bb5dd4381d4993af7be
Reviewed-on: https://chromium-review.googlesource.com/c/1405317
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58759}
parent 843535b8
This diff is collapsed.
......@@ -6,9 +6,9 @@
"build": "rollup -c",
"watch": "rollup -c -w",
"deploy": "./deploy.sh",
"format": "tsfmt -r",
"test": "ts-mocha -p tsconfig.test.json test/**/*-test.ts",
"dev-server": "ws"
"dev-server": "ws",
"presubmit": "tslint --project ./tslint.json --fix"
},
"author": "The V8 team",
"license": "MIT",
......@@ -17,8 +17,7 @@
"d3": "^5.7.0",
"rollup": "^0.68.2",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-typescript2": "^0.18.1",
"tslint": "^5.12.0"
"rollup-plugin-typescript2": "^0.18.1"
},
"repository": {
"type": "git",
......@@ -30,6 +29,6 @@
"mocha": "^5.2.0",
"ts-mocha": "^2.0.0",
"typescript": "^3.2.2",
"typescript-formatter": "^7.2.2"
"tslint": "^5.12.0"
}
}
......@@ -18,10 +18,10 @@ const toolboxHTML = `<div id="disassembly-toolbox">
export class DisassemblyView extends TextView {
SOURCE_POSITION_HEADER_REGEX: any;
addr_event_counts: any;
total_event_counts: any;
max_event_counts: any;
pos_lines: Array<any>;
addrEventCounts: any;
totalEventCounts: any;
maxEventCounts: any;
posLines: Array<any>;
instructionSelectionHandler: InstructionSelectionHandler;
offsetSelection: MySelection;
showInstructionAddressHandler: () => void;
......@@ -77,7 +77,7 @@ export class DisassemblyView extends TextView {
let OPCODE_ARGS = {
associateData: function (text, fragment) {
fragment.innerHTML = text;
const replacer = (match, hexOffset, stringOffset, string) => {
const replacer = (match, hexOffset) => {
const offset = Number.parseInt(hexOffset, 16);
const keyOffset = view.sourceResolver.getKeyPcOffset(offset)
return `<span class="tag linkable-text" data-pc-offset="${keyOffset}">${match}</span>`
......@@ -154,7 +154,7 @@ export class DisassemblyView extends TextView {
}
view.divNode.addEventListener('click', linkHandler);
const linkHandlerBlock = (e) => {
const linkHandlerBlock = e => {
const blockId = e.target.dataset.blockId;
if (typeof blockId != "undefined" && !Number.isNaN(blockId)) {
e.stopPropagation();
......@@ -239,21 +239,21 @@ export class DisassemblyView extends TextView {
initializeCode(sourceText, sourcePosition: number = 0) {
let view = this;
view.addr_event_counts = null;
view.total_event_counts = null;
view.max_event_counts = null;
view.pos_lines = new Array();
view.addrEventCounts = null;
view.totalEventCounts = null;
view.maxEventCounts = null;
view.posLines = new Array();
// Comment lines for line 0 include sourcePosition already, only need to
// add sourcePosition for lines > 0.
view.pos_lines[0] = sourcePosition;
view.posLines[0] = sourcePosition;
if (sourceText && sourceText != "") {
let base = sourcePosition;
let current = 0;
let source_lines = sourceText.split("\n");
for (let i = 1; i < source_lines.length; i++) {
let sourceLines = sourceText.split("\n");
for (let i = 1; i < sourceLines.length; i++) {
// Add 1 for newline character that is split off.
current += source_lines[i - 1].length + 1;
view.pos_lines[i] = base + current;
current += sourceLines[i - 1].length + 1;
view.posLines[i] = base + current;
}
}
}
......@@ -261,20 +261,22 @@ export class DisassemblyView extends TextView {
initializePerfProfile(eventCounts) {
let view = this;
if (eventCounts !== undefined) {
view.addr_event_counts = eventCounts;
view.addrEventCounts = eventCounts;
view.total_event_counts = {};
view.max_event_counts = {};
for (let ev_name in view.addr_event_counts) {
let keys = Object.keys(view.addr_event_counts[ev_name]);
let values = keys.map(key => view.addr_event_counts[ev_name][key]);
view.total_event_counts[ev_name] = values.reduce((a, b) => a + b);
view.max_event_counts[ev_name] = values.reduce((a, b) => Math.max(a, b));
view.totalEventCounts = {};
view.maxEventCounts = {};
for (let evName in view.addrEventCounts) {
if (view.addrEventCounts.hasOwnProperty(evName)) {
let keys = Object.keys(view.addrEventCounts[evName]);
let values = keys.map(key => view.addrEventCounts[evName][key]);
view.totalEventCounts[evName] = values.reduce((a, b) => a + b);
view.maxEventCounts[evName] = values.reduce((a, b) => Math.max(a, b));
}
}
} else {
view.addr_event_counts = null;
view.total_event_counts = null;
view.max_event_counts = null;
view.addrEventCounts = null;
view.totalEventCounts = null;
view.maxEventCounts = null;
}
}
......@@ -296,16 +298,17 @@ export class DisassemblyView extends TextView {
let fragments = super.processLine(line);
// Add profiling data per instruction if available.
if (view.total_event_counts) {
if (view.totalEventCounts) {
let matches = /^(0x[0-9a-fA-F]+)\s+\d+\s+[0-9a-fA-F]+/.exec(line);
if (matches) {
let newFragments = [];
for (let event in view.addr_event_counts) {
let count = view.addr_event_counts[event][matches[1]];
for (let event in view.addrEventCounts) {
if (!view.addrEventCounts.hasOwnProperty(event)) continue;
let count = view.addrEventCounts[event][matches[1]];
let str = " ";
let css_cls = "prof";
let cssCls = "prof";
if (count !== undefined) {
let perc = count / view.total_event_counts[event] * 100;
let perc = count / view.totalEventCounts[event] * 100;
let col = { r: 255, g: 255, b: 255 };
for (let i = 0; i < PROF_COLS.length; i++) {
......@@ -328,13 +331,13 @@ export class DisassemblyView extends TextView {
str = UNICODE_BLOCK;
let fragment = view.createFragment(str, css_cls);
let fragment = view.createFragment(str, cssCls);
fragment.title = event + ": " + view.humanize(perc) + " (" + count + ")";
fragment.style.color = "rgb(" + col.r + ", " + col.g + ", " + col.b + ")";
newFragments.push(fragment);
} else {
newFragments.push(view.createFragment(str, css_cls));
newFragments.push(view.createFragment(str, cssCls));
}
}
fragments = newFragments.concat(fragments);
......
......@@ -39,11 +39,11 @@ export class Edge {
var source = this.source;
var target = this.target;
var index = this.index;
var input_x = target.x + target.getInputX(index);
var inputX = target.x + target.getInputX(index);
var inputApproach = target.getInputApproach(this.index);
var outputApproach = source.getOutputApproach(showTypes);
if (inputApproach > outputApproach) {
return input_x;
return inputX;
} else {
var inputOffset = MINIMUM_EDGE_SEPARATION * (index + 1);
return (target.x < source.x)
......@@ -55,20 +55,20 @@ export class Edge {
generatePath(graph: Graph, showTypes: boolean) {
var target = this.target;
var source = this.source;
var input_x = target.x + target.getInputX(this.index);
var inputX = target.x + target.getInputX(this.index);
var arrowheadHeight = 7;
var input_y = target.y - 2 * DEFAULT_NODE_BUBBLE_RADIUS - arrowheadHeight;
var output_x = source.x + source.getOutputX();
var output_y = source.y + source.getNodeHeight(showTypes) + DEFAULT_NODE_BUBBLE_RADIUS;
var inputY = target.y - 2 * DEFAULT_NODE_BUBBLE_RADIUS - arrowheadHeight;
var outputX = source.x + source.getOutputX();
var outputY = source.y + source.getNodeHeight(showTypes) + DEFAULT_NODE_BUBBLE_RADIUS;
var inputApproach = target.getInputApproach(this.index);
var outputApproach = source.getOutputApproach(showTypes);
var horizontalPos = this.getInputHorizontalPosition(graph, showTypes);
var result = "M" + output_x + "," + output_y +
"L" + output_x + "," + outputApproach +
var result = "M" + outputX + "," + outputY +
"L" + outputX + "," + outputApproach +
"L" + horizontalPos + "," + outputApproach;
if (horizontalPos != input_x) {
if (horizontalPos != inputX) {
result += "L" + horizontalPos + "," + inputApproach;
} else {
if (inputApproach < outputApproach) {
......@@ -76,8 +76,8 @@ export class Edge {
}
}
result += "L" + input_x + "," + inputApproach +
"L" + input_x + "," + input_y;
result += "L" + inputX + "," + inputApproach +
"L" + inputX + "," + inputY;
return result;
}
......
......@@ -15,7 +15,7 @@ import { NodeSelectionHandler, ClearableHandler } from "./selection-handler";
import { Graph } from "./graph";
import { SelectionBroker } from "./selection-broker";
function nodeToStringKey(n) {
function nodeToStringKey(n: GNode) {
return "" + n.id;
}
......@@ -67,8 +67,8 @@ export class GraphView extends View implements PhaseView {
// to be important even if it does nothing.
svg
.attr("focusable", false)
.on("focus", (e) => { })
.on("keydown", (e) => { view.svgKeyDown(); })
.on("focus", e => {})
.on("keydown", e => { view.svgKeyDown(); })
view.svg = svg;
......@@ -103,7 +103,7 @@ export class GraphView extends View implements PhaseView {
},
brokeredNodeSelect: function (locations, selected: boolean) {
if (!view.graph) return;
let selection = view.graph.nodes((n) => {
let selection = view.graph.nodes(n => {
return locations.has(nodeToStringKey(n))
&& (!view.state.hideDead || n.isLive());
});
......@@ -112,10 +112,10 @@ export class GraphView extends View implements PhaseView {
for (const n of view.graph.nodes()) {
if (view.state.selection.isSelected(n)) {
n.visible = true;
n.inputs.forEach((e) => {
n.inputs.forEach(e => {
e.visible = e.visible || view.state.selection.isSelected(e.source);
});
n.outputs.forEach((e) => {
n.outputs.forEach(e => {
e.visible = e.visible || view.state.selection.isSelected(e.target);
});
}
......@@ -330,7 +330,7 @@ export class GraphView extends View implements PhaseView {
attachSelection(s) {
if (!(s instanceof Set)) return;
this.selectionHandler.clear();
const selected = [...this.graph.nodes((n) =>
const selected = [...this.graph.nodes(n =>
s.has(this.state.selection.stringKey(n)) && (!this.state.hideDead || n.isLive()))];
this.selectionHandler.select(selected, true);
}
......@@ -343,7 +343,7 @@ export class GraphView extends View implements PhaseView {
if (!d3.event.shiftKey) {
this.state.selection.clear();
}
const allVisibleNodes = [...this.graph.nodes((n) => n.visible)];
const allVisibleNodes = [...this.graph.nodes(n => n.visible)];
this.state.selection.select(allVisibleNodes, true);
this.updateGraphVisibility();
}
......@@ -423,7 +423,7 @@ export class GraphView extends View implements PhaseView {
reg.exec(n.nodeLabel.opcode) != null);
};
const selection = [...this.graph.nodes((n) => {
const selection = [...this.graph.nodes(n => {
if ((e.ctrlKey || n.visible) && filterFunction(n)) {
if (e.ctrlKey) n.visible = true;
return true;
......@@ -614,7 +614,7 @@ export class GraphView extends View implements PhaseView {
const newAndOldEdges = newEdges.merge(selEdges);
newAndOldEdges.classed('hidden', (e) => !e.isVisible());
newAndOldEdges.classed('hidden', e => !e.isVisible());
// select existing nodes
const filteredNodes = [...graph.nodes(n => n.visible)];
......@@ -658,7 +658,7 @@ export class GraphView extends View implements PhaseView {
visibleNodes.data(adjNodes, nodeToStr).attr('relToHover', "none");
view.updateGraphVisibility();
})
.on("click", (d) => {
.on("click", d => {
if (!d3.event.shiftKey) view.selectionHandler.clear();
view.selectionHandler.select([d], undefined);
d3.event.stopPropagation();
......@@ -821,7 +821,10 @@ export class GraphView extends View implements PhaseView {
viewSelection() {
const view = this;
var minX, maxX, minY, maxY;
var minX;
var maxX;
var minY;
var maxY;
let hasSelection = false;
view.visibleNodes.selectAll<SVGGElement, GNode>("g").each(function (n) {
if (view.state.selection.isSelected(n)) {
......@@ -836,12 +839,11 @@ export class GraphView extends View implements PhaseView {
});
if (hasSelection) {
view.viewGraphRegion(minX - NODE_INPUT_WIDTH, minY - 60,
maxX + NODE_INPUT_WIDTH, maxY + 60,
true);
maxX + NODE_INPUT_WIDTH, maxY + 60);
}
}
viewGraphRegion(minX, minY, maxX, maxY, transition) {
viewGraphRegion(minX, minY, maxX, maxY) {
const [width, height] = this.getSvgViewDimensions();
const dx = maxX - minX;
const dy = maxY - minY;
......
......@@ -22,8 +22,8 @@ export class Graph {
this.width = 1;
this.height = 1;
data.nodes.forEach((json_node: any) => {
this.nodeMap[json_node.id] = new GNode(json_node.nodeLabel);
data.nodes.forEach((jsonNode: any) => {
this.nodeMap[jsonNode.id] = new GNode(jsonNode.nodeLabel);
});
data.edges.forEach((e: any) => {
......
......@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { GraphView } from "../src/graph-view"
import { ScheduleView } from "../src/schedule-view"
import { SequenceView } from "../src/sequence-view"
import { SourceResolver } from "../src/source-resolver"
import { SelectionBroker } from "../src/selection-broker"
import { View, PhaseView } from "../src/view"
import { GraphView } from "../src/graph-view";
import { ScheduleView } from "../src/schedule-view";
import { SequenceView } from "../src/sequence-view";
import { SourceResolver } from "../src/source-resolver";
import { SelectionBroker } from "../src/selection-broker";
import { View, PhaseView } from "../src/view";
const multiviewID = "multiview";
......@@ -29,7 +29,7 @@ const toolboxHTML = `
<select id="display-selector">
<option disabled selected>(please open a file)</option>
</select>
</div>`
</div>`;
export class GraphMultiView extends View {
sourceResolver: SourceResolver;
......@@ -41,8 +41,8 @@ export class GraphMultiView extends View {
currentPhaseView: View & PhaseView;
createViewElement() {
const pane = document.createElement('div');
pane.setAttribute('id', multiviewID);
const pane = document.createElement("div");
pane.setAttribute("id", multiviewID);
pane.className = "viewpane";
return pane;
}
......@@ -59,7 +59,7 @@ export class GraphMultiView extends View {
const searchInput = toolbox.querySelector("#search-input") as HTMLInputElement;
searchInput.addEventListener("keyup", e => {
if (!view.currentPhaseView) return;
view.currentPhaseView.searchInputAction(searchInput, e)
view.currentPhaseView.searchInputAction(searchInput, e);
});
view.divNode.addEventListener("keyup", (e: KeyboardEvent) => {
if (e.keyCode == 191) { // keyCode == '/'
......@@ -67,17 +67,16 @@ export class GraphMultiView extends View {
}
});
searchInput.setAttribute("value", window.sessionStorage.getItem("lastSearch") || "");
this.graph = new GraphView(this.divNode, selectionBroker,
(phaseName) => view.displayPhaseByName(phaseName));
this.graph = new GraphView(this.divNode, selectionBroker, phaseName => view.displayPhaseByName(phaseName));
this.schedule = new ScheduleView(this.divNode, selectionBroker);
this.sequence = new SequenceView(this.divNode, selectionBroker);
this.selectMenu = toolbox.querySelector('#display-selector') as HTMLSelectElement;
this.selectMenu = toolbox.querySelector("#display-selector") as HTMLSelectElement;
}
initializeSelect() {
const view = this;
view.selectMenu.innerHTML = '';
view.sourceResolver.forEachPhase((phase) => {
view.selectMenu.innerHTML = "";
view.sourceResolver.forEachPhase(phase => {
const optionElement = document.createElement("option");
let maxNodeId = "";
if (phase.type == "graph" && phase.highestNodeId != 0) {
......@@ -104,11 +103,11 @@ export class GraphMultiView extends View {
initializeContent() { }
displayPhase(phase) {
if (phase.type == 'graph') {
if (phase.type == "graph") {
this.displayPhaseView(this.graph, phase.data);
} else if (phase.type == 'schedule') {
} else if (phase.type == "schedule") {
this.displayPhaseView(this.schedule, phase);
} else if (phase.type == 'sequence') {
} else if (phase.type == "sequence") {
this.displayPhaseView(this.sequence, phase);
}
}
......
......@@ -98,12 +98,12 @@ export class GNode {
return this.nodeLabel.type;
}
getDisplayType() {
var type_string = this.nodeLabel.type;
if (type_string == undefined) return "";
if (type_string.length > 24) {
type_string = type_string.substr(0, 25) + "...";
var typeString = this.nodeLabel.type;
if (typeString == undefined) return "";
if (typeString.length > 24) {
typeString = typeString.substr(0, 25) + "...";
}
return type_string;
return typeString;
}
deepestInputRank() {
var deepestRank = 0;
......
......@@ -34,9 +34,9 @@ class Snapper {
this.setDisassemblyExpanded(this.getLastExpandedState("disassembly", false));
}
getLastExpandedState(type: string, default_state: boolean): boolean {
getLastExpandedState(type: string, defaultState: boolean): boolean {
var state = window.sessionStorage.getItem("expandedState-" + type);
if (state === null) return default_state;
if (state === null) return defaultState;
return state === 'true';
}
......@@ -51,11 +51,11 @@ class Snapper {
const resizer = this.resizer;
this.sourceExpandUpdate(newState);
if (newState) {
resizer.sep_left = resizer.sep_left_snap;
resizer.sep_left_snap = 0;
resizer.sepLeft = resizer.sepLeftSnap;
resizer.sepLeftSnap = 0;
} else {
resizer.sep_left_snap = resizer.sep_left;
resizer.sep_left = 0;
resizer.sepLeftSnap = resizer.sepLeft;
resizer.sepLeft = 0;
}
}
......@@ -70,94 +70,94 @@ class Snapper {
const resizer = this.resizer;
this.disassemblyExpandUpdate(newState);
if (newState) {
resizer.sep_right = resizer.sep_right_snap;
resizer.sep_right_snap = resizer.client_width;
resizer.sepRight = resizer.sepRightSnap;
resizer.sepRightSnap = resizer.clientWidth;
} else {
resizer.sep_right_snap = resizer.sep_right;
resizer.sep_right = resizer.client_width;
resizer.sepRightSnap = resizer.sepRight;
resizer.sepRight = resizer.clientWidth;
}
}
panesUpdated(): void {
this.sourceExpandUpdate(this.resizer.sep_left > this.resizer.dead_width);
this.disassemblyExpandUpdate(this.resizer.sep_right <
(this.resizer.client_width - this.resizer.dead_width));
this.sourceExpandUpdate(this.resizer.sepLeft > this.resizer.deadWidth);
this.disassemblyExpandUpdate(this.resizer.sepRight <
(this.resizer.clientWidth - this.resizer.deadWidth));
}
}
export class Resizer {
snapper: Snapper;
dead_width: number;
client_width: number;
deadWidth: number;
clientWidth: number;
left: HTMLElement;
right: HTMLElement;
middle: HTMLElement;
sep_left: number;
sep_right: number;
sep_left_snap: number;
sep_right_snap: number;
sep_width_offset: number;
panes_updated_callback: () => void;
resizer_right: d3.Selection<HTMLDivElement, any, any, any>;
resizer_left: d3.Selection<HTMLDivElement, any, any, any>;
constructor(panes_updated_callback: () => void, dead_width: number) {
sepLeft: number;
sepRight: number;
sepLeftSnap: number;
sepRightSnap: number;
sepWidthOffset: number;
panesUpdatedCallback: () => void;
resizerRight: d3.Selection<HTMLDivElement, any, any, any>;
resizerLeft: d3.Selection<HTMLDivElement, any, any, any>;
constructor(panesUpdatedCallback: () => void, deadWidth: number) {
let resizer = this;
resizer.panes_updated_callback = panes_updated_callback;
resizer.dead_width = dead_width
resizer.panesUpdatedCallback = panesUpdatedCallback;
resizer.deadWidth = deadWidth
resizer.left = document.getElementById(C.SOURCE_PANE_ID);
resizer.middle = document.getElementById(C.INTERMEDIATE_PANE_ID);
resizer.right = document.getElementById(C.GENERATED_PANE_ID);
resizer.resizer_left = d3.select('#resizer-left');
resizer.resizer_right = d3.select('#resizer-right');
resizer.sep_left_snap = 0;
resizer.sep_right_snap = 0;
resizer.resizerLeft = d3.select('#resizer-left');
resizer.resizerRight = d3.select('#resizer-right');
resizer.sepLeftSnap = 0;
resizer.sepRightSnap = 0;
// Offset to prevent resizers from sliding slightly over one another.
resizer.sep_width_offset = 7;
resizer.sepWidthOffset = 7;
this.updateWidths();
let dragResizeLeft = d3.drag()
.on('drag', function () {
let x = d3.mouse(this.parentElement)[0];
resizer.sep_left = Math.min(Math.max(0, x), resizer.sep_right - resizer.sep_width_offset);
resizer.sepLeft = Math.min(Math.max(0, x), resizer.sepRight - resizer.sepWidthOffset);
resizer.updatePanes();
})
.on('start', function () {
resizer.resizer_left.classed("dragged", true);
resizer.resizerLeft.classed("dragged", true);
let x = d3.mouse(this.parentElement)[0];
if (x > dead_width) {
resizer.sep_left_snap = resizer.sep_left;
if (x > deadWidth) {
resizer.sepLeftSnap = resizer.sepLeft;
}
})
.on('end', function () {
if (!resizer.isRightSnapped()) {
window.sessionStorage.setItem("source-pane-width", `${resizer.sep_left / resizer.client_width}`);
window.sessionStorage.setItem("source-pane-width", `${resizer.sepLeft / resizer.clientWidth}`);
}
resizer.resizer_left.classed("dragged", false);
resizer.resizerLeft.classed("dragged", false);
});
resizer.resizer_left.call(dragResizeLeft);
resizer.resizerLeft.call(dragResizeLeft);
let dragResizeRight = d3.drag()
.on('drag', function () {
let x = d3.mouse(this.parentElement)[0];
resizer.sep_right = Math.max(resizer.sep_left + resizer.sep_width_offset, Math.min(x, resizer.client_width));
resizer.sepRight = Math.max(resizer.sepLeft + resizer.sepWidthOffset, Math.min(x, resizer.clientWidth));
resizer.updatePanes();
})
.on('start', function () {
resizer.resizer_right.classed("dragged", true);
resizer.resizerRight.classed("dragged", true);
let x = d3.mouse(this.parentElement)[0];
if (x < (resizer.client_width - dead_width)) {
resizer.sep_right_snap = resizer.sep_right;
if (x < (resizer.clientWidth - deadWidth)) {
resizer.sepRightSnap = resizer.sepRight;
}
})
.on('end', function () {
if (!resizer.isRightSnapped()) {
console.log(`disassembly-pane-width ${resizer.sep_right}`)
window.sessionStorage.setItem("disassembly-pane-width", `${resizer.sep_right / resizer.client_width}`);
console.log(`disassembly-pane-width ${resizer.sepRight}`)
window.sessionStorage.setItem("disassembly-pane-width", `${resizer.sepRight / resizer.clientWidth}`);
}
resizer.resizer_right.classed("dragged", false);
resizer.resizerRight.classed("dragged", false);
});
resizer.resizer_right.call(dragResizeRight);
resizer.resizerRight.call(dragResizeRight);
window.onresize = function () {
resizer.updateWidths();
resizer.updatePanes();
......@@ -167,33 +167,33 @@ export class Resizer {
}
isLeftSnapped() {
return this.sep_left === 0;
return this.sepLeft === 0;
}
isRightSnapped() {
return this.sep_right >= this.client_width - 1;
return this.sepRight >= this.clientWidth - 1;
}
updatePanes() {
let left_snapped = this.isLeftSnapped();
let right_snapped = this.isRightSnapped();
this.resizer_left.classed("snapped", left_snapped);
this.resizer_right.classed("snapped", right_snapped);
this.left.style.width = this.sep_left + 'px';
this.middle.style.width = (this.sep_right - this.sep_left) + 'px';
this.right.style.width = (this.client_width - this.sep_right) + 'px';
this.resizer_left.style('left', this.sep_left + 'px');
this.resizer_right.style('right', (this.client_width - this.sep_right - 1) + 'px');
let leftSnapped = this.isLeftSnapped();
let rightSnapped = this.isRightSnapped();
this.resizerLeft.classed("snapped", leftSnapped);
this.resizerRight.classed("snapped", rightSnapped);
this.left.style.width = this.sepLeft + 'px';
this.middle.style.width = (this.sepRight - this.sepLeft) + 'px';
this.right.style.width = (this.clientWidth - this.sepRight) + 'px';
this.resizerLeft.style('left', this.sepLeft + 'px');
this.resizerRight.style('right', (this.clientWidth - this.sepRight - 1) + 'px');
this.snapper.panesUpdated();
this.panes_updated_callback();
this.panesUpdatedCallback();
}
updateWidths() {
this.client_width = document.body.getBoundingClientRect().width;
const sep_left = window.sessionStorage.getItem("source-pane-width");
this.sep_left = this.client_width * (sep_left ? Number.parseFloat(sep_left) : (1 / 3));
const sep_right = window.sessionStorage.getItem("disassembly-pane-width");
this.sep_right = this.client_width * (sep_right ? Number.parseFloat(sep_right) : (2 / 3));
this.clientWidth = document.body.getBoundingClientRect().width;
const sepLeft = window.sessionStorage.getItem("source-pane-width");
this.sepLeft = this.clientWidth * (sepLeft ? Number.parseFloat(sepLeft) : (1 / 3));
const sepRight = window.sessionStorage.getItem("disassembly-pane-width");
this.sepRight = this.clientWidth * (sepRight ? Number.parseFloat(sepRight) : (2 / 3));
}
}
......@@ -92,21 +92,21 @@ export class ScheduleView extends TextView implements PhaseView {
instrMarker.onclick = mkNodeLinkHandler(node.id);
nodeEl.appendChild(instrMarker);
const node_id = createElement("div", "node-id tag clickable", node.id);
node_id.onclick = mkNodeLinkHandler(node.id);
view.addHtmlElementForNodeId(node.id, node_id);
nodeEl.appendChild(node_id);
const node_label = createElement("div", "node-label", node.label);
nodeEl.appendChild(node_label);
const nodeId = createElement("div", "node-id tag clickable", node.id);
nodeId.onclick = mkNodeLinkHandler(node.id);
view.addHtmlElementForNodeId(node.id, nodeId);
nodeEl.appendChild(nodeId);
const nodeLabel = createElement("div", "node-label", node.label);
nodeEl.appendChild(nodeLabel);
if (node.inputs.length > 0) {
const node_parameters = createElement("div", "parameter-list comma-sep-list");
const nodeParameters = createElement("div", "parameter-list comma-sep-list");
for (const param of node.inputs) {
const paramEl = createElement("div", "parameter tag clickable", param);
node_parameters.appendChild(paramEl);
nodeParameters.appendChild(paramEl);
paramEl.onclick = mkNodeLinkHandler(param);
view.addHtmlElementForNodeId(param, paramEl);
}
nodeEl.appendChild(node_parameters);
nodeEl.appendChild(nodeParameters);
}
return nodeEl;
......@@ -122,38 +122,38 @@ export class ScheduleView extends TextView implements PhaseView {
};
}
const schedule_block = createElement("div", "schedule-block");
const scheduleBlock = createElement("div", "schedule-block");
const [start, end] = view.sourceResolver.getInstructionRangeForBlock(block.id);
const instrMarker = createElement("div", "instr-marker com", "&#8857;");
instrMarker.setAttribute("title", `Instructions range for this block is [${start}, ${end})`)
instrMarker.onclick = mkBlockLinkHandler(block.id);
schedule_block.appendChild(instrMarker);
scheduleBlock.appendChild(instrMarker);
const block_id = createElement("div", "block-id com clickable", block.id);
block_id.onclick = mkBlockLinkHandler(block.id);
schedule_block.appendChild(block_id);
const block_pred = createElement("div", "predecessor-list block-list comma-sep-list");
const blockId = createElement("div", "block-id com clickable", block.id);
blockId.onclick = mkBlockLinkHandler(block.id);
scheduleBlock.appendChild(blockId);
const blockPred = createElement("div", "predecessor-list block-list comma-sep-list");
for (const pred of block.pred) {
const predEl = createElement("div", "block-id com clickable", pred);
predEl.onclick = mkBlockLinkHandler(pred);
block_pred.appendChild(predEl);
blockPred.appendChild(predEl);
}
if (block.pred.length) schedule_block.appendChild(block_pred);
if (block.pred.length) scheduleBlock.appendChild(blockPred);
const nodes = createElement("div", "nodes");
for (const node of block.nodes) {
nodes.appendChild(createElementForNode(node));
}
schedule_block.appendChild(nodes);
const block_succ = createElement("div", "successor-list block-list comma-sep-list");
scheduleBlock.appendChild(nodes);
const blockSucc = createElement("div", "successor-list block-list comma-sep-list");
for (const succ of block.succ) {
const succEl = createElement("div", "block-id com clickable", succ);
succEl.onclick = mkBlockLinkHandler(succ);
block_succ.appendChild(succEl);
blockSucc.appendChild(succEl);
}
if (block.succ.length) schedule_block.appendChild(block_succ);
this.addHtmlElementForBlockId(block.id, schedule_block);
return schedule_block;
if (block.succ.length) scheduleBlock.appendChild(blockSucc);
this.addHtmlElementForBlockId(block.id, scheduleBlock);
return scheduleBlock;
}
addBlocks(blocks) {
......
......@@ -49,7 +49,7 @@ export class SelectionBroker {
}
broadcastSourcePositionSelect(from, sourcePositions, selected) {
sourcePositions = sourcePositions.filter((l) => {
sourcePositions = sourcePositions.filter(l => {
if (!sourcePositionValid(l)) {
console.log("Warning: invalid source position");
return false;
......
......@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {Sequence} from "../src/source-resolver"
import {isIterable} from "../src/util"
import {PhaseView} from "../src/view"
import {TextView} from "../src/text-view"
import { Sequence } from "../src/source-resolver"
import { isIterable } from "../src/util"
import { PhaseView } from "../src/view"
import { TextView } from "../src/text-view"
export class SequenceView extends TextView implements PhaseView {
sequence: Sequence;
search_info: Array<any>;
searchInfo: Array<any>;
createViewElement() {
const pane = document.createElement('div');
......@@ -39,7 +39,7 @@ export class SequenceView extends TextView implements PhaseView {
initializeContent(data, rememberedSelection) {
this.divNode.innerHTML = '';
this.sequence = data.sequence;
this.search_info = [];
this.searchInfo = [];
this.divNode.addEventListener('click', (e: MouseEvent) => {
if (!(e.target instanceof HTMLElement)) return;
const instructionId = Number.parseInt(e.target.dataset.instructionId, 10);
......@@ -82,25 +82,25 @@ export class SequenceView extends TextView implements PhaseView {
return mkLinkHandler(text, view.selectionHandler);
}
function elementForOperand(operand, search_info) {
function elementForOperand(operand, searchInfo) {
var text = operand.text;
const operandEl = createElement("div", ["parameter", "tag", "clickable", operand.type], text);
if (operand.tooltip) {
operandEl.setAttribute("title", operand.tooltip);
}
operandEl.onclick = mkOperandLinkHandler(text);
search_info.push(text);
searchInfo.push(text);
view.addHtmlElementForNodeId(text, operandEl);
return operandEl;
}
function elementForInstruction(instruction, search_info) {
function elementForInstruction(instruction, searchInfo) {
const instNodeEl = createElement("div", "instruction-node");
const inst_id = createElement("div", "instruction-id", instruction.id);
inst_id.classList.add("clickable");
inst_id.dataset.instructionId = instruction.id;
instNodeEl.appendChild(inst_id);
const instId = createElement("div", "instruction-id", instruction.id);
instId.classList.add("clickable");
instId.dataset.instructionId = instruction.id;
instNodeEl.appendChild(instId);
const instContentsEl = createElement("div", "instruction-contents");
instNodeEl.appendChild(instContentsEl);
......@@ -112,11 +112,11 @@ export class SequenceView extends TextView implements PhaseView {
const moves = createElement("div", ["comma-sep-list", "gap-move"]);
for (const move of gap) {
const moveEl = createElement("div", "move");
const destinationEl = elementForOperand(move[0], search_info);
const destinationEl = elementForOperand(move[0], searchInfo);
moveEl.appendChild(destinationEl);
const assignEl = createElement("div", "assign", "=");
moveEl.appendChild(assignEl);
const sourceEl = elementForOperand(move[1], search_info);
const sourceEl = elementForOperand(move[1], searchInfo);
moveEl.appendChild(sourceEl);
moves.appendChild(moveEl);
}
......@@ -129,7 +129,7 @@ export class SequenceView extends TextView implements PhaseView {
if (instruction.outputs.length > 0) {
const outputs = createElement("div", ["comma-sep-list", "input-output-list"]);
for (const output of instruction.outputs) {
const outputEl = elementForOperand(output, search_info);
const outputEl = elementForOperand(output, searchInfo);
outputs.appendChild(outputEl);
}
instEl.appendChild(outputs);
......@@ -138,15 +138,15 @@ export class SequenceView extends TextView implements PhaseView {
}
var text = instruction.opcode + instruction.flags;
const inst_label = createElement("div", "node-label", text);
search_info.push(text);
view.addHtmlElementForNodeId(text, inst_label);
instEl.appendChild(inst_label);
const instLabel = createElement("div", "node-label", text);
searchInfo.push(text);
view.addHtmlElementForNodeId(text, instLabel);
instEl.appendChild(instLabel);
if (instruction.inputs.length > 0) {
const inputs = createElement("div", ["comma-sep-list", "input-output-list"]);
for (const input of instruction.inputs) {
const inputEl = elementForOperand(input, search_info);
const inputEl = elementForOperand(input, searchInfo);
inputs.appendChild(inputEl);
}
instEl.appendChild(inputs);
......@@ -155,7 +155,7 @@ export class SequenceView extends TextView implements PhaseView {
if (instruction.temps.length > 0) {
const temps = createElement("div", ["comma-sep-list", "input-output-list", "temps"]);
for (const temp of instruction.temps) {
const tempEl = elementForOperand(temp, search_info);
const tempEl = elementForOperand(temp, searchInfo);
temps.appendChild(tempEl);
}
instEl.appendChild(temps);
......@@ -164,20 +164,20 @@ export class SequenceView extends TextView implements PhaseView {
return instNodeEl;
}
const sequence_block = createElement("div", "schedule-block");
const sequenceBlock = createElement("div", "schedule-block");
const block_id = createElement("div", ["block-id", "com", "clickable"], block.id);
block_id.onclick = mkBlockLinkHandler(block.id);
sequence_block.appendChild(block_id);
const block_pred = createElement("div", ["predecessor-list", "block-list", "comma-sep-list"]);
const blockId = createElement("div", ["block-id", "com", "clickable"], block.id);
blockId.onclick = mkBlockLinkHandler(block.id);
sequenceBlock.appendChild(blockId);
const blockPred = createElement("div", ["predecessor-list", "block-list", "comma-sep-list"]);
for (const pred of block.predecessors) {
const predEl = createElement("div", ["block-id", "com", "clickable"], pred);
predEl.onclick = mkBlockLinkHandler(pred);
block_pred.appendChild(predEl);
blockPred.appendChild(predEl);
}
if (block.predecessors.length > 0) sequence_block.appendChild(block_pred);
if (block.predecessors.length > 0) sequenceBlock.appendChild(blockPred);
const phis = createElement("div", "phis");
sequence_block.appendChild(phis);
sequenceBlock.appendChild(phis);
const phiLabel = createElement("div", "phi-label", "phi:");
phis.appendChild(phiLabel);
......@@ -189,7 +189,7 @@ export class SequenceView extends TextView implements PhaseView {
const phiEl = createElement("div", "phi");
phiContents.appendChild(phiEl);
const outputEl = elementForOperand(phi.output, this.search_info);
const outputEl = elementForOperand(phi.output, this.searchInfo);
phiEl.appendChild(outputEl);
const assignEl = createElement("div", "assign", "=");
......@@ -203,18 +203,18 @@ export class SequenceView extends TextView implements PhaseView {
const instructions = createElement("div", "instructions");
for (const instruction of block.instructions) {
instructions.appendChild(elementForInstruction(instruction, this.search_info));
instructions.appendChild(elementForInstruction(instruction, this.searchInfo));
}
sequence_block.appendChild(instructions);
const block_succ = createElement("div", ["successor-list", "block-list", "comma-sep-list"]);
sequenceBlock.appendChild(instructions);
const blockSucc = createElement("div", ["successor-list", "block-list", "comma-sep-list"]);
for (const succ of block.successors) {
const succEl = createElement("div", ["block-id", "com", "clickable"], succ);
succEl.onclick = mkBlockLinkHandler(succ);
block_succ.appendChild(succEl);
blockSucc.appendChild(succEl);
}
if (block.successors.length > 0) sequence_block.appendChild(block_succ);
this.addHtmlElementForBlockId(block.id, sequence_block);
return sequence_block;
if (block.successors.length > 0) sequenceBlock.appendChild(blockSucc);
this.addHtmlElementForBlockId(block.id, sequenceBlock);
return sequenceBlock;
}
addBlocks(blocks) {
......@@ -232,7 +232,7 @@ export class SequenceView extends TextView implements PhaseView {
const select = [];
window.sessionStorage.setItem("lastSearch", query);
const reg = new RegExp(query);
for (const item of this.search_info) {
for (const item of this.searchInfo) {
if (reg.exec(item) != null) {
select.push(item);
}
......
......@@ -235,7 +235,7 @@ export class SourceResolver {
return sourcePositionArray;
}
forEachSource(f: (value: Source, index: number, array: Source[]) => void) {
forEachSource(f: (value: Source, index: number, array: Array<Source>) => void) {
this.sources.forEach(f);
}
......@@ -294,8 +294,7 @@ export class SourceResolver {
if (!this.sources[sourceId]) return [];
const res = [];
const list = this.sources[sourceId].sourcePositions;
for (let i = 0; i < list.length; i++) {
const sourcePosition = list[i]
for (const sourcePosition of list) {
if (start <= sourcePosition.scriptOffset && sourcePosition.scriptOffset < end) {
res.push(sourcePosition);
}
......@@ -507,7 +506,7 @@ export class SourceResolver {
return this.phaseNames.get(phaseName);
}
forEachPhase(f: (value: Phase, index: number, array: Phase[]) => void) {
forEachPhase(f: (value: Phase, index: number, array: Array<Phase>) => void) {
this.phases.forEach(f);
}
......@@ -534,12 +533,12 @@ export class SourceResolver {
}
parseSchedule(phase) {
function createNode(state, match) {
function createNode(state: any, match) {
let inputs = [];
if (match.groups.args) {
const nodeIdsString = match.groups.args.replace(/\s/g, '');
const nodeIdStrings = nodeIdsString.split(',');
inputs = nodeIdStrings.map((n) => Number.parseInt(n, 10));
inputs = nodeIdStrings.map(n => Number.parseInt(n, 10));
}
const node = {
id: Number.parseInt(match.groups.id, 10),
......@@ -549,7 +548,7 @@ export class SourceResolver {
if (match.groups.blocks) {
const nodeIdsString = match.groups.blocks.replace(/\s/g, '').replace(/B/g, '');
const nodeIdStrings = nodeIdsString.split(',');
const successors = nodeIdStrings.map((n) => Number.parseInt(n, 10));
const successors = nodeIdStrings.map(n => Number.parseInt(n, 10));
state.currentBlock.succ = successors;
}
state.nodes[node.id] = node;
......@@ -560,7 +559,7 @@ export class SourceResolver {
if (match.groups.in) {
const blockIdsString = match.groups.in.replace(/\s/g, '').replace(/B/g, '');
const blockIdStrings = blockIdsString.split(',');
predecessors = blockIdStrings.map((n) => Number.parseInt(n, 10));
predecessors = blockIdStrings.map(n => Number.parseInt(n, 10));
}
const block = {
id: Number.parseInt(match.groups.id, 10),
......
......@@ -59,7 +59,7 @@ export abstract class TextView extends View {
};
this.selectionHandler = selectionHandler;
broker.addNodeHandler(selectionHandler);
view.divNode.addEventListener('click', (e) => {
view.divNode.addEventListener('click', e => {
if (!e.shiftKey) {
view.selectionHandler.clear();
}
......
......@@ -31,7 +31,7 @@ window.onload = function () {
txtRes += '{"name":"disassembly","type":"disassembly","data":""}]}';
}
try {
sourceViews.forEach((sv) => sv.hide());
sourceViews.forEach(sv => sv.hide());
if (multiview) multiview.hide();
multiview = null;
if (disassemblyView) disassemblyView.hide();
......@@ -72,7 +72,7 @@ window.onload = function () {
sourceView.show(null, null);
sourceViews.push(sourceView);
sourceResolver.forEachSource((source) => {
sourceResolver.forEachSource(source => {
let sourceView = new CodeView(sourceContainer, selectionBroker, sourceResolver, source, CodeMode.INLINED_SOURCE);
sourceView.show(null, null);
sourceViews.push(sourceView);
......
......@@ -60,8 +60,8 @@ export function sortUnique<T>(arr: Array<T>, f: (a: T, b: T) => number, equal: (
}
// Partial application without binding the receiver
export function partial(f: any, ...arguments1: any[]) {
return function (this: any, ...arguments2: any[]) {
export function partial(f: any, ...arguments1: Array<any>) {
return function (this: any, ...arguments2: Array<any>) {
f.apply(this, [...arguments1, ...arguments2]);
}
}
......
......@@ -19,7 +19,7 @@ export abstract class View {
return false;
}
show(data, rememberedSelection): void {
show(data: any, rememberedSelection: Selection): void {
this.initializeContent(data, rememberedSelection);
this.container.appendChild(this.divNode);
}
......
......@@ -12,7 +12,7 @@
"limit": 80
}],
"ordered-imports": false,
"array-type": [false, "generic"],
"array-type": [true, "generic"],
"semicolon": false,
"member-access": false,
"object-literal-shorthand": false,
......@@ -27,7 +27,7 @@
"trailing-comma": false,
"member-ordering": false,
"no-string-literal": false,
"arrow-parens": false,
"arrow-parens": [true, "ban-single-arg-parens"],
"no-console": false,
"interface-name": false,
"no-bitwise": false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment