Commit 963a97a2 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[turbolizer] Add source formatter

Bug: v8:7327
Change-Id: Id354b039977a82af8b2c6bba416cf5a1f804ca71
Reviewed-on: https://chromium-review.googlesource.com/1095257
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53637}
parent 3f8607bf
This diff is collapsed.
......@@ -6,7 +6,8 @@
"scripts": {
"build": "tsc",
"watch": "tsc --watch",
"deploy": "./deploy.sh"
"deploy": "./deploy.sh",
"format": "tsfmt -r"
},
"author": "The V8 team",
"license": "MIT",
......@@ -19,6 +20,7 @@
"url": "https://github.com/v8/v8.git"
},
"devDependencies": {
"typescript": "^2.9.1"
"typescript": "^2.9.1",
"typescript-formatter": "^7.2.2"
}
}
......@@ -86,7 +86,7 @@ class CodeView extends View {
return this.sourcePositionToHtmlElement.get(key);
}
updateSelection(scrollIntoView: boolean = false) : void {
updateSelection(scrollIntoView: boolean = false): void {
const mkVisible = new ViewElements(this.divNode.parentNode as HTMLElement);
for (const [sp, el] of this.sourcePositionToHtmlElement.entries()) {
const isSelected = this.selection.isKeySelected(sp);
......@@ -112,12 +112,12 @@ class CodeView extends View {
return ordereList.childNodes as NodeListOf<HTMLElement>;
}
onSelectLine(lineNumber:number, doClear:boolean) {
onSelectLine(lineNumber: number, doClear: boolean) {
const key = anyToString(lineNumber);
if (doClear) {
this.selectionHandler.clear();
}
const positions = this.sourceResolver.linetoSourcePositions(lineNumber - 1);
const positions = this.sourceResolver.linetoSourcePositions(lineNumber - 1);
if (positions !== undefined) {
this.selectionHandler.select(positions, undefined);
}
......@@ -182,7 +182,7 @@ class CodeView extends View {
view.selectionHandler.clear();
}
const base:number = source.startPosition;
const base: number = source.startPosition;
let current = 0;
const lineListDiv = this.getHtmlCodeLines();
let newlineAdjust = 0;
......
......@@ -21,9 +21,9 @@ const COLLAPSE_PANE_BUTTON_VISIBLE = 'button-input';
const COLLAPSE_PANE_BUTTON_INVISIBLE = 'button-input-invisible';
const UNICODE_BLOCK = '&#9611;';
const PROF_COLS = [
{ perc: 0, col: { r: 255, g: 255, b: 255 } },
{ perc: 0, col: { r: 255, g: 255, b: 255 } },
{ perc: 0.5, col: { r: 255, g: 255, b: 128 } },
{ perc: 5, col: { r: 255, g: 128, b: 0 } },
{ perc: 15, col: { r: 255, g: 0, b: 0 } },
{ perc: 100, col: { r: 0, g: 0, b: 0 } }
{ perc: 5, col: { r: 255, g: 128, b: 0 } },
{ perc: 15, col: { r: 255, g: 0, b: 0 } },
{ perc: 100, col: { r: 0, g: 0, b: 0 } }
];
......@@ -89,4 +89,4 @@ class Edge {
}
const edgeToStr = (e:Edge) => e.stringID();
const edgeToStr = (e: Edge) => e.stringID();
......@@ -6,7 +6,7 @@ var DEFAULT_NODE_ROW_SEPARATION = 130
var traceLayout = false;
function newGraphOccupation(graph){
function newGraphOccupation(graph) {
var isSlotFilled = [];
var maxSlot = 0;
var minSlot = 0;
......@@ -42,7 +42,7 @@ function newGraphOccupation(graph){
function findSpace(pos, width, direction) {
var widthSlots = Math.floor((width + NODE_INPUT_WIDTH - 1) /
NODE_INPUT_WIDTH);
NODE_INPUT_WIDTH);
var currentSlot = positionToSlot(pos + width / 2);
var currentScanSlot = currentSlot;
var widthSlotsRemainingLeft = widthSlots;
......@@ -53,14 +53,14 @@ function newGraphOccupation(graph){
currentScanSlot = currentSlot + (mod ? -1 : 1) * (slotsChecked >> 1);
if (!isSlotFilled[slotToIndex(currentScanSlot)]) {
if (mod) {
if (direction <= 0) --widthSlotsRemainingLeft
if (direction <= 0)--widthSlotsRemainingLeft
} else {
if (direction >= 0) --widthSlotsRemainingRight
if (direction >= 0)--widthSlotsRemainingRight
}
if (widthSlotsRemainingLeft == 0 ||
widthSlotsRemainingRight == 0 ||
(widthSlotsRemainingLeft + widthSlotsRemainingRight) == widthSlots &&
(widthSlots == slotsChecked)) {
widthSlotsRemainingRight == 0 ||
(widthSlotsRemainingLeft + widthSlotsRemainingRight) == widthSlots &&
(widthSlots == slotsChecked)) {
if (mod) {
return [currentScanSlot, widthSlots];
} else {
......@@ -79,7 +79,7 @@ function newGraphOccupation(graph){
function setIndexRange(from, to, value) {
if (to < from) {
throw("illegal slot range");
throw ("illegal slot range");
}
while (from <= to) {
if (from > maxSlot) {
......@@ -127,7 +127,7 @@ function newGraphOccupation(graph){
}
var occupation = {
occupyNodeInputs: function(node) {
occupyNodeInputs: function (node) {
for (var i = 0; i < node.inputs.length; ++i) {
if (node.inputs[i].isVisible()) {
var edge = node.inputs[i];
......@@ -138,14 +138,14 @@ function newGraphOccupation(graph){
console.log("Occupying input " + i + " of " + node.id + " at " + horizontalPos);
}
occupyPositionRangeWithMargin(horizontalPos,
horizontalPos,
NODE_INPUT_WIDTH / 2);
horizontalPos,
NODE_INPUT_WIDTH / 2);
}
}
}
},
occupyNode: function(node) {
var getPlacementHint = function(n) {
occupyNode: function (node) {
var getPlacementHint = function (n) {
var pos = 0;
var direction = -1;
var outputEdges = 0;
......@@ -201,28 +201,28 @@ function newGraphOccupation(graph){
return slotToLeftPosition(firstSlot + slotWidth / 2) - (width / 2);
}
},
clearOccupiedNodes: function() {
nodeOccupation.forEach(function(o) {
clearOccupiedNodes: function () {
nodeOccupation.forEach(function (o) {
clearSlotRange(o[0], o[1]);
});
nodeOccupation = [];
},
clearNodeOutputs: function(source) {
source.outputs.forEach(function(edge) {
clearNodeOutputs: function (source) {
source.outputs.forEach(function (edge) {
if (edge.isVisible()) {
var target = edge.target;
for (var i = 0; i < target.inputs.length; ++i) {
if (target.inputs[i].source === source) {
var horizontalPos = edge.getInputHorizontalPosition(graph);
clearPositionRangeWithMargin(horizontalPos,
horizontalPos,
NODE_INPUT_WIDTH / 2);
horizontalPos,
NODE_INPUT_WIDTH / 2);
}
}
}
});
},
print: function() {
print: function () {
var s = "";
for (var currentSlot = -40; currentSlot < 40; ++currentSlot) {
if (currentSlot != 0) {
......@@ -251,11 +251,11 @@ function layoutNodeGraph(graph) {
// basis for bottom-up DFS to determine rank and node placement.
var endNodesHasNoOutputs = [];
var startNodesHasNoInputs = [];
graph.nodes.forEach(function(n, i){
graph.nodes.forEach(function (n, i) {
endNodesHasNoOutputs[n.id] = true;
startNodesHasNoInputs[n.id] = true;
});
graph.edges.forEach(function(e, i){
graph.edges.forEach(function (e, i) {
endNodesHasNoOutputs[e.source.id] = false;
startNodesHasNoInputs[e.target.id] = false;
});
......@@ -265,7 +265,7 @@ function layoutNodeGraph(graph) {
var startNodes = [];
var visited = [];
var rank = [];
graph.nodes.forEach(function(n, i){
graph.nodes.forEach(function (n, i) {
if (endNodesHasNoOutputs[n.id]) {
endNodes.push(n);
}
......@@ -323,7 +323,7 @@ function layoutNodeGraph(graph) {
}
}
visited = [];
visited = [];
function dfsFindRankLate(n) {
if (visited[n.id]) return;
visited[n.id] = true;
......@@ -335,7 +335,7 @@ function layoutNodeGraph(graph) {
dfsFindRankLate(output);
var outputRank = output.rank;
if (output.visible && (firstInput || outputRank <= newRank) &&
(outputRank > originalRank)) {
(outputRank > originalRank)) {
newRank = outputRank - 1;
}
firstInput = false;
......@@ -364,15 +364,15 @@ function layoutNodeGraph(graph) {
}
startNodes.forEach(dfsRankOrder);
endNodes.forEach(function(n) {
endNodes.forEach(function (n) {
n.rank = maxRank + 1;
});
var rankSets = [];
// Collect sets for each rank.
graph.nodes.forEach(function(n, i){
graph.nodes.forEach(function (n, i) {
n.y = n.rank * (DEFAULT_NODE_ROW_SEPARATION + graph.getNodeHeight(n) +
2 * DEFAULT_NODE_BUBBLE_RADIUS);
2 * DEFAULT_NODE_BUBBLE_RADIUS);
if (n.visible) {
if (rankSets[n.rank] === undefined) {
rankSets[n.rank] = [n];
......@@ -388,7 +388,7 @@ function layoutNodeGraph(graph) {
var occupation = newGraphOccupation(graph);
var rankCount = 0;
rankSets.reverse().forEach(function(rankSet) {
rankSets.reverse().forEach(function (rankSet) {
for (var i = 0; i < rankSet.length; ++i) {
occupation.clearNodeOutputs(rankSet[i]);
......@@ -400,7 +400,7 @@ function layoutNodeGraph(graph) {
}
var placedCount = 0;
rankSet = rankSet.sort(function(a,b) {
rankSet = rankSet.sort(function (a, b) {
return a.visitOrderWithinRank < b.visitOrderWithinRank;
});
for (var i = 0; i < rankSet.length; ++i) {
......@@ -495,8 +495,8 @@ function redetermineGraphBoundingBox(graph) {
graph.height = height;
const extent = [
[graph.minGraphX-width/2, graph.minGraphY-height/2],
[graph.maxGraphX+width/2, graph.maxGraphY+height/2]
[graph.minGraphX - width / 2, graph.minGraphY - height / 2],
[graph.maxGraphX + width / 2, graph.maxGraphY + height / 2]
];
graph.panZoom.translateExtent(extent);
graph.minScale();
......
......@@ -92,7 +92,7 @@ class GraphView extends View implements PhaseView {
locations.push(node.sourcePosition);
}
if (node.origin && node.origin.bytecodePosition) {
locations.push({bytecodePosition: node.origin.bytecodePosition});
locations.push({ bytecodePosition: node.origin.bytecodePosition });
}
}
graph.state.selection.select(nodes, selected);
......
......@@ -43,7 +43,7 @@ class GraphMultiView extends View {
optionElement.text = phase.name;
view.selectMenu.add(optionElement);
});
this.selectMenu.onchange = function (this:HTMLSelectElement) {
this.selectMenu.onchange = function (this: HTMLSelectElement) {
window.sessionStorage.setItem("lastSelectedPhase", this.selectedIndex.toString());
view.displayPhase(view.sourceResolver.getPhase(this.selectedIndex));
}
......@@ -58,7 +58,7 @@ class GraphMultiView extends View {
this.displayPhase(this.sourceResolver.getPhase(initialPhaseIndex));
}
initializeContent() {}
initializeContent() { }
displayPhase(phase) {
if (phase.type == 'graph') {
......
......@@ -3,12 +3,12 @@
// found in the LICENSE file.
PR.registerLangHandler(
PR.createSimpleLexer(
[
[PR.PR_STRING, /^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$))/, null, '\''],
[PR.PR_PLAIN, /^\s+/, null, ' \r\n\t\xA0']
],
[ // fallthroughStylePatterns
[PR.PR_COMMENT, /;; debug: position \d+/, null],
]),
['disassembly']);
PR.createSimpleLexer(
[
[PR.PR_STRING, /^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$))/, null, '\''],
[PR.PR_PLAIN, /^\s+/, null, ' \r\n\t\xA0']
],
[ // fallthroughStylePatterns
[PR.PR_COMMENT, /;; debug: position \d+/, null],
]),
['disassembly']);
......@@ -41,7 +41,7 @@ class GNode {
visible: boolean;
rank: number;
opinfo: string;
labelbbox: {width: number, height: number};
labelbbox: { width: number, height: number };
isControl() {
return this.control;
......@@ -177,4 +177,4 @@ class GNode {
}
};
const nodeToStr = (n:GNode) => "N" + n.id;
const nodeToStr = (n: GNode) => "N" + n.id;
......@@ -11,7 +11,7 @@ class ScheduleView extends TextView implements PhaseView {
const pane = document.createElement('div');
pane.setAttribute('id', "schedule");
pane.innerHTML =
`<pre id='schedule-text-pre' class='prettyprint prettyprinted'>
`<pre id='schedule-text-pre' class='prettyprint prettyprinted'>
<ul id='schedule-list' class='nolinenums noindent'>
</ul>
</pre>`;
......@@ -42,7 +42,7 @@ class ScheduleView extends TextView implements PhaseView {
elementForBlock(block) {
const view = this;
function createElement(tag:string, cls: string|Array<string>, content?:string) {
function createElement(tag: string, cls: string | Array<string>, content?: string) {
const el = document.createElement(tag);
if (isIterable(cls)) {
for (const c of cls) el.classList.add(c);
......@@ -162,5 +162,5 @@ class ScheduleView extends TextView implements PhaseView {
this.selectionHandler.select(select, true);
}
onresize() {}
onresize() { }
}
......@@ -3,22 +3,22 @@
// found in the LICENSE file.
interface SelectionHandler {
clear() : void;
select(nodeIds:any, selected:any) : void;
brokeredClear(): void;
brokeredSourcePositionSelect(sourcePositions:any, selected:any): void;
clear(): void;
select(nodeIds: any, selected: any): void;
brokeredClear(): void;
brokeredSourcePositionSelect(sourcePositions: any, selected: any): void;
};
interface NodeSelectionHandler {
clear() : void;
select(nodeIds:any, selected:any) : void;
brokeredClear(): void;
brokeredNodeSelect(nodeIds:any, selected:any): void;
clear(): void;
select(nodeIds: any, selected: any): void;
brokeredClear(): void;
brokeredNodeSelect(nodeIds: any, selected: any): void;
};
interface BlockSelectionHandler {
clear() : void;
select(nodeIds:any, selected:any) : void;
brokeredClear(): void;
brokeredBlockSelect(blockIds:any, selected:any): void;
clear(): void;
select(nodeIds: any, selected: any): void;
brokeredClear(): void;
brokeredBlockSelect(blockIds: any, selected: any): void;
};
......@@ -4,18 +4,18 @@
class MySelection {
selection: any;
stringKey: (o:any) => string;
stringKey: (o: any) => string;
constructor(stringKeyFnc) {
this.selection = new Map();
this.stringKey = stringKeyFnc;
}
isEmpty() : boolean {
isEmpty(): boolean {
return this.selection.size == 0;
}
clear() : void {
clear(): void {
this.selection = new Map();
}
......@@ -38,7 +38,7 @@ class MySelection {
return this.selection.has(this.stringKey(i));
}
isKeySelected(key:string): boolean {
isKeySelected(key: string): boolean {
return this.selection.has(key);
}
......
......@@ -25,7 +25,7 @@ function sourcePositionToStringKey(sourcePosition): string {
function sourcePositionValid(l) {
return (typeof l.scriptOffset !== undefined
&& typeof l.inliningId !== undefined) || typeof l.bytecodePosition != undefined;
&& typeof l.inliningId !== undefined) || typeof l.bytecodePosition != undefined;
}
interface SourcePosition {
......@@ -285,8 +285,8 @@ class SourceResolver {
if (phase.type != "graph") return;
for (const node of phase.data.nodes) {
if (node.origin != undefined &&
node.origin.bytecodePosition != undefined) {
const position = {bytecodePosition: node.origin.bytecodePosition};
node.origin.bytecodePosition != undefined) {
const position = { bytecodePosition: node.origin.bytecodePosition };
this.nodePositionMap[node.id] = position;
let key = sourcePositionToStringKey(position);
if (!this.positionToNodes.has(key)) {
......@@ -329,7 +329,7 @@ class SourceResolver {
this.phases.forEach(f);
}
addAnyPositionToLine(lineNumber:number|String, sourcePosition:AnyPosition) {
addAnyPositionToLine(lineNumber: number | String, sourcePosition: AnyPosition) {
const lineNumberString = anyToString(lineNumber);
if (!this.lineToSourcePositions.has(lineNumberString)) {
this.lineToSourcePositions.set(lineNumberString, []);
......@@ -338,14 +338,14 @@ class SourceResolver {
if (!A.includes(sourcePosition)) A.push(sourcePosition);
}
setSourceLineToBytecodePosition(sourceLineToBytecodePosition:Array<number>|undefined) {
setSourceLineToBytecodePosition(sourceLineToBytecodePosition: Array<number> | undefined) {
if (!sourceLineToBytecodePosition) return;
sourceLineToBytecodePosition.forEach((pos, i) => {
this.addAnyPositionToLine(i, {bytecodePosition: pos});
this.addAnyPositionToLine(i, { bytecodePosition: pos });
});
}
linetoSourcePositions(lineNumber:number|String) {
linetoSourcePositions(lineNumber: number | String) {
const positions = this.lineToSourcePositions.get(anyToString(lineNumber));
if (positions === undefined) return [];
return positions;
......@@ -359,11 +359,13 @@ class SourceResolver {
const nodeIdStrings = nodeIdsString.split(',');
inputs = nodeIdStrings.map((n) => Number.parseInt(n, 10));
}
const node = {id: Number.parseInt(match.groups.id, 10),
label: match.groups.label,
inputs: inputs};
const node = {
id: Number.parseInt(match.groups.id, 10),
label: match.groups.label,
inputs: inputs
};
if (match.groups.blocks) {
const nodeIdsString = match.groups.blocks.replace(/\s/g, '').replace(/B/g,'');
const nodeIdsString = match.groups.blocks.replace(/\s/g, '').replace(/B/g, '');
const nodeIdStrings = nodeIdsString.split(',');
const successors = nodeIdStrings.map((n) => Number.parseInt(n, 10));
state.currentBlock.succ = successors;
......@@ -378,11 +380,13 @@ class SourceResolver {
const blockIdStrings = blockIdsString.split(',');
predecessors = blockIdStrings.map((n) => Number.parseInt(n, 10));
}
const block = {id: Number.parseInt(match.groups.id, 10),
isDeferred: match.groups.deferred != undefined,
pred: predecessors.sort(),
succ: [],
nodes: []};
const block = {
id: Number.parseInt(match.groups.id, 10),
isDeferred: match.groups.deferred != undefined,
pred: predecessors.sort(),
succ: [],
nodes: []
};
state.blocks[block.id] = block;
state.currentBlock = block;
}
......@@ -392,7 +396,7 @@ class SourceResolver {
const rules = [
{
lineRegexps:
[ /^\s*(?<id>\d+):\ (?<label>.*)\((?<args>.*)\)$/,
[/^\s*(?<id>\d+):\ (?<label>.*)\((?<args>.*)\)$/,
/^\s*(?<id>\d+):\ (?<label>.*)\((?<args>.*)\)\ ->\ (?<blocks>.*)$/,
/^\s*(?<id>\d+):\ (?<label>.*)$/
],
......
......@@ -4,7 +4,7 @@
"use strict";
function anyToString(x:any): string {
function anyToString(x: any): string {
return "" + x;
}
......@@ -118,7 +118,7 @@ abstract class TextView extends View {
broker.addSourcePositionHandler(sourcePositionSelectionHandler);
}
addHtmlElementForNodeId(anyNodeId:any, htmlElement: HTMLElement) {
addHtmlElementForNodeId(anyNodeId: any, htmlElement: HTMLElement) {
const nodeId = anyToString(anyNodeId);
if (!this.nodeIdToHtmlElementsMap.has(nodeId)) {
this.nodeIdToHtmlElementsMap.set(nodeId, []);
......@@ -247,7 +247,7 @@ abstract class TextView extends View {
this.addNodeIdToBlockId(fragment.nodeId, fragment.blockId);
}
if (typeof style.linkHandler == 'function') {
if (typeof style.linkHandler == 'function') {
const handler = style.linkHandler(text, fragment)
if (handler !== undefined) {
fragment.classList.add('linkable-text');
......
......@@ -104,7 +104,7 @@ function partial(f, ...arguments1) {
}
}
function isIterable(obj:any): obj is Iterable<any> {
function isIterable(obj: any): obj is Iterable<any> {
return obj != null && obj != undefined
&& typeof obj != 'string' && typeof obj[Symbol.iterator] === 'function';
}
......@@ -34,5 +34,5 @@ abstract class View {
interface PhaseView {
onresize();
searchInputAction(searchInput: HTMLInputElement, e:Event);
searchInputAction(searchInput: HTMLInputElement, e: Event);
}
{
"tabSize": 2,
"indentSize": 2,
"convertTabsToSpaces": true,
"insertSpaceAfterCommaDelimiter": true,
"insertSpaceAfterSemicolonInForStatements": true,
"insertSpaceBeforeAndAfterBinaryOperators": true,
"insertSpaceAfterKeywordsInControlFlowStatements": true,
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": true,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
"insertSpaceBeforeFunctionParenthesis": false,
"placeOpenBraceOnNewLineForFunctions": false,
"placeOpenBraceOnNewLineForControlBlocks": false
}
\ No newline at end of file
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