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,7 +112,7 @@ 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();
......@@ -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;
......
......@@ -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;
......@@ -53,9 +53,9 @@ 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 ||
......@@ -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];
......@@ -144,8 +144,8 @@ function newGraphOccupation(graph){
}
}
},
occupyNode: function(node) {
var getPlacementHint = function(n) {
occupyNode: function (node) {
var getPlacementHint = function (n) {
var pos = 0;
var direction = -1;
var outputEdges = 0;
......@@ -201,14 +201,14 @@ 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) {
......@@ -222,7 +222,7 @@ function newGraphOccupation(graph){
}
});
},
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);
}
......@@ -364,13 +364,13 @@ 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);
if (n.visible) {
......@@ -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') {
......
......@@ -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;
......@@ -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;
clear(): void;
select(nodeIds: any, selected: any): void;
brokeredClear(): void;
brokeredSourcePositionSelect(sourcePositions:any, selected:any): void;
brokeredSourcePositionSelect(sourcePositions: any, selected: any): void;
};
interface NodeSelectionHandler {
clear() : void;
select(nodeIds:any, selected:any) : void;
clear(): void;
select(nodeIds: any, selected: any): void;
brokeredClear(): void;
brokeredNodeSelect(nodeIds:any, selected:any): void;
brokeredNodeSelect(nodeIds: any, selected: any): void;
};
interface BlockSelectionHandler {
clear() : void;
select(nodeIds:any, selected:any) : void;
clear(): void;
select(nodeIds: any, selected: any): void;
brokeredClear(): void;
brokeredBlockSelect(blockIds:any, selected:any): 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);
}
......
......@@ -286,7 +286,7 @@ class SourceResolver {
for (const node of phase.data.nodes) {
if (node.origin != undefined &&
node.origin.bytecodePosition != undefined) {
const position = {bytecodePosition: node.origin.bytecodePosition};
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),
const node = {
id: Number.parseInt(match.groups.id, 10),
label: match.groups.label,
inputs: inputs};
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),
const block = {
id: Number.parseInt(match.groups.id, 10),
isDeferred: match.groups.deferred != undefined,
pred: predecessors.sort(),
succ: [],
nodes: []};
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, []);
......
......@@ -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