Skip to content

Commit

Permalink
Adapt to change in naming
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad committed Oct 24, 2023
1 parent 7442786 commit bfd45a7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
28 changes: 14 additions & 14 deletions src/renderer/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ import { deepCopy, intersectRect, showErrorModal } from '../utils/utils';
import { CanvasManager } from './canvas_manager';
import {
AccessNode, Connector,
Edge, EntryNode, InterstateEdge, LoopScopeBlock, Memlet, NestedSDFG,
Edge, EntryNode, InterstateEdge, LoopRegion, Memlet, NestedSDFG,
SDFG,
SDFGElement,
SDFGElementType,
SDFGElements,
SDFGNode,
ScopeBlock,
ControlFlowRegion,
State,
Tasklet,
drawSDFG,
Expand Down Expand Up @@ -2651,7 +2651,7 @@ export class SDFGRenderer extends EventEmitter {
let sdfg_elem = null;
if (foreground_elem instanceof State)
sdfg_elem = foreground_elem.data.state;
else if (foreground_elem instanceof ScopeBlock)
else if (foreground_elem instanceof ControlFlowRegion)
sdfg_elem = foreground_elem.data.block;
else if (foreground_elem instanceof SDFGNode) {
sdfg_elem = foreground_elem.data.node;
Expand Down Expand Up @@ -3337,9 +3337,9 @@ function relayoutStateMachine(
let blockGraph = null;
if (block.attributes.is_collapsed) {
blockInfo.height = SDFV.LINEHEIGHT;
if (blockElem instanceof LoopScopeBlock) {
if (blockElem instanceof LoopRegion) {
const oldFont = ctx.font;
ctx.font = LoopScopeBlock.LOOP_STATEMENT_FONT;
ctx.font = LoopRegion.LOOP_STATEMENT_FONT;
const labelWidths = [
ctx.measureText(
(block.attributes.scope_condition?.string_data ?? '') +
Expand All @@ -3358,7 +3358,7 @@ function relayoutStateMachine(
ctx.font = oldFont;
blockInfo.width = Math.max(
maxLabelWidth, ctx.measureText(block.label).width
) + 3 * LoopScopeBlock.META_LABEL_MARGIN;
) + 3 * LoopRegion.META_LABEL_MARGIN;
} else if (blockElem instanceof State) {
blockInfo.width = ctx.measureText(blockInfo.label).width;
}
Expand All @@ -3373,16 +3373,16 @@ function relayoutStateMachine(
blockInfo.width += 2 * BLOCK_MARGIN;
blockInfo.height += 2 * BLOCK_MARGIN;

if (blockElem instanceof LoopScopeBlock) {
if (blockElem instanceof LoopRegion) {
// Add spacing for the condition if the loop is not inverted.
if (!block.attributes.inverted)
blockInfo.height += LoopScopeBlock.CONDITION_SPACING;
blockInfo.height += LoopRegion.CONDITION_SPACING;
// If there's an init statement, add space for it.
if (block.attributes.init_statement)
blockInfo.height += LoopScopeBlock.INIT_SPACING;
blockInfo.height += LoopRegion.INIT_SPACING;
// If there's an update statement, also add space for it.
if (block.attributes.update_statement)
blockInfo.height += LoopScopeBlock.UPDATE_SPACING;
blockInfo.height += LoopRegion.UPDATE_SPACING;
}

blockElem.data.layout = blockInfo;
Expand Down Expand Up @@ -3454,13 +3454,13 @@ function relayoutStateMachine(
// Base spacing for the inside.
let topSpacing = BLOCK_MARGIN;

if (gBlock instanceof LoopScopeBlock) {
if (gBlock instanceof LoopRegion) {
// Add spacing for the condition if the loop isn't inverted.
if (!block.attributes.inverted)
topSpacing += LoopScopeBlock.CONDITION_SPACING;
topSpacing += LoopRegion.CONDITION_SPACING;
// If there's an init statement, add space for it.
if (block.attributes.init_statement)
topSpacing += LoopScopeBlock.INIT_SPACING;
topSpacing += LoopRegion.INIT_SPACING;
}
offset_sdfg(block as any, gBlock.data.graph, {
x: topleft.x + BLOCK_MARGIN,
Expand Down Expand Up @@ -3861,7 +3861,7 @@ function relayoutSDFGBlock(
omitAccessNodes: boolean, parent: SDFGElement
): DagreSDFG | null {
switch (block.type) {
case SDFGElementType.LoopScopeBlock:
case SDFGElementType.LoopRegion:
return relayoutStateMachine(
ctx, block as StateMachineType, sdfg, sdfgList, stateParentList,
omitAccessNodes, parent
Expand Down
56 changes: 28 additions & 28 deletions src/renderer/renderer_elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export enum SDFGElementType {
Reduce = 'Reduce',
BasicBlock = 'BasicBlock',
ControlFlowBlock = 'ControlFlowBlock',
ScopeBlock = 'ScopeBlock',
LoopScopeBlock = 'LoopScopeBlock',
ControlFlowRegion = 'ControlFlowRegion',
LoopRegion = 'LoopRegion',
}

export class SDFGElement {
Expand Down Expand Up @@ -232,7 +232,7 @@ export class ControlFlowBlock extends SDFGElement {
export class BasicBlock extends SDFGElement {
}

export class ScopeBlock extends ControlFlowBlock {
export class ControlFlowRegion extends ControlFlowBlock {
}

export class State extends BasicBlock {
Expand Down Expand Up @@ -385,7 +385,7 @@ export class State extends BasicBlock {

}

export class LoopScopeBlock extends ScopeBlock {
export class LoopRegion extends ControlFlowRegion {

public static readonly META_LABEL_MARGIN: number = 5;

Expand Down Expand Up @@ -458,22 +458,22 @@ export class LoopScopeBlock extends ScopeBlock {
);

const oldFont = ctx.font;
let topSpacing = LoopScopeBlock.META_LABEL_MARGIN;
let topSpacing = LoopRegion.META_LABEL_MARGIN;
let remainingHeight = this.height;

// Draw the init statement if there is one.
if (this.attributes().init_statement) {
topSpacing += LoopScopeBlock.INIT_SPACING;
const initBottomLineY = topleft.y + LoopScopeBlock.INIT_SPACING;
topSpacing += LoopRegion.INIT_SPACING;
const initBottomLineY = topleft.y + LoopRegion.INIT_SPACING;
ctx.beginPath();
ctx.moveTo(topleft.x, initBottomLineY);
ctx.lineTo(topleft.x + this.width, initBottomLineY);
ctx.stroke();

ctx.font = LoopScopeBlock.LOOP_STATEMENT_FONT;
ctx.font = LoopRegion.LOOP_STATEMENT_FONT;
const initStatement = this.attributes().init_statement.string_data;
const initTextY = (
(topleft.y + (LoopScopeBlock.INIT_SPACING / 2)) +
(topleft.y + (LoopRegion.INIT_SPACING / 2)) +
(SDFV.LINEHEIGHT / 2)
);
const initTextMetrics = ctx.measureText(initStatement);
Expand All @@ -482,7 +482,7 @@ export class LoopScopeBlock extends ScopeBlock {

ctx.font = oldFont;
ctx.fillText(
'init', topleft.x + LoopScopeBlock.META_LABEL_MARGIN, initTextY
'init', topleft.x + LoopRegion.META_LABEL_MARGIN, initTextY
);
}

Expand All @@ -491,58 +491,58 @@ export class LoopScopeBlock extends ScopeBlock {
// (do-while-style) loop). If the condition is drawn on top, make sure
// the init statement spacing is respected if there is one.
let condTopY = topleft.y;
let condLineY = condTopY + LoopScopeBlock.CONDITION_SPACING;
let condLineY = condTopY + LoopRegion.CONDITION_SPACING;
if (this.attributes().inverted) {
condTopY = topleft.y +
(this.height - LoopScopeBlock.CONDITION_SPACING);
condLineY = condTopY - LoopScopeBlock.CONDITION_SPACING;
(this.height - LoopRegion.CONDITION_SPACING);
condLineY = condTopY - LoopRegion.CONDITION_SPACING;
} else if (this.attributes().init_statement) {
condTopY += LoopScopeBlock.INIT_SPACING;
condLineY = condTopY + LoopScopeBlock.CONDITION_SPACING;
condTopY += LoopRegion.INIT_SPACING;
condLineY = condTopY + LoopRegion.CONDITION_SPACING;
}
topSpacing += LoopScopeBlock.CONDITION_SPACING;
topSpacing += LoopRegion.CONDITION_SPACING;
ctx.beginPath();
ctx.moveTo(topleft.x, condLineY);
ctx.lineTo(topleft.x + this.width, condLineY);
ctx.stroke();
ctx.font = LoopScopeBlock.LOOP_STATEMENT_FONT;
const condStatement = this.attributes().scope_condition.string_data;
ctx.font = LoopRegion.LOOP_STATEMENT_FONT;
const condStatement = this.attributes().loop_condition.string_data;
const condTextY = (
(condTopY + (LoopScopeBlock.CONDITION_SPACING / 2)) +
(condTopY + (LoopRegion.CONDITION_SPACING / 2)) +
(SDFV.LINEHEIGHT / 2)
);
const condTextMetrics = ctx.measureText(condStatement);
const condTextX = this.x - (condTextMetrics.width / 2);
ctx.fillText(condStatement, condTextX, condTextY);
ctx.font = oldFont;
ctx.fillText(
'while', topleft.x + LoopScopeBlock.META_LABEL_MARGIN, condTextY
'while', topleft.x + LoopRegion.META_LABEL_MARGIN, condTextY
);

// Draw the update statement if there is one.
if (this.attributes().update_statement) {
remainingHeight -= LoopScopeBlock.UPDATE_SPACING;
remainingHeight -= LoopRegion.UPDATE_SPACING;
const updateTopY = topleft.y + (
this.height - LoopScopeBlock.UPDATE_SPACING
this.height - LoopRegion.UPDATE_SPACING
);
ctx.beginPath();
ctx.moveTo(topleft.x, updateTopY);
ctx.lineTo(topleft.x + this.width, updateTopY);
ctx.stroke();

ctx.font = LoopScopeBlock.LOOP_STATEMENT_FONT;
ctx.font = LoopRegion.LOOP_STATEMENT_FONT;
const updateStatement =
this.attributes().update_statement.string_data;
const updateTextY = (
(updateTopY + (LoopScopeBlock.UPDATE_SPACING / 2)) +
(updateTopY + (LoopRegion.UPDATE_SPACING / 2)) +
(SDFV.LINEHEIGHT / 2)
);
const updateTextMetrics = ctx.measureText(updateStatement);
const updateTextX = this.x - (updateTextMetrics.width / 2);
ctx.fillText(updateStatement, updateTextX, updateTextY);
ctx.font = oldFont;
ctx.fillText(
'update', topleft.x + LoopScopeBlock.META_LABEL_MARGIN,
'update', topleft.x + LoopRegion.META_LABEL_MARGIN,
updateTextY
);
}
Expand All @@ -554,7 +554,7 @@ export class LoopScopeBlock extends ScopeBlock {
visibleRect.y <= topleft.y + SDFV.LINEHEIGHT &&
SDFVSettings.showStateNames)
ctx.fillText(
this.label(), topleft.x + LoopScopeBlock.META_LABEL_MARGIN,
this.label(), topleft.x + LoopRegion.META_LABEL_MARGIN,
topleft.y + topSpacing + SDFV.LINEHEIGHT
);

Expand Down Expand Up @@ -2661,6 +2661,6 @@ export const SDFGElements: { [name: string]: typeof SDFGElement } = {
ControlFlowBlock,
BasicBlock,
State,
ScopeBlock,
LoopScopeBlock,
ControlFlowRegion: ControlFlowRegion,
LoopRegion: LoopRegion,
};

0 comments on commit bfd45a7

Please sign in to comment.