Skip to content

Commit

Permalink
Add support for direct struct member accesses on access nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad committed Oct 30, 2024
1 parent 1566f86 commit c23e92b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
35 changes: 31 additions & 4 deletions src/renderer/renderer_elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2099,6 +2099,35 @@ export class Connector extends SDFGElement {

export class AccessNode extends SDFGNode {

public getDesc(): any {
const name = this.data.node.attributes.data;
const nameParts = name.split('.');
if (nameParts.length > 1) {
let desc = this.sdfg.attributes._arrays[nameParts[0]];
let i = 1;
while (i < nameParts.length) {
if (!desc.attributes?.members)
return undefined;
const nextName = nameParts[i];
let foundDesc = undefined;
for (const mbr of desc.attributes.members) {
if (mbr[0] == nextName) {
foundDesc = mbr[1];
break;
}
}
if (foundDesc)
desc = foundDesc;
else
return undefined;
i++;
}
return desc;
} else {
return this.sdfg.attributes._arrays[nameParts[0]];
}
}

public draw(
renderer: SDFGRenderer, ctx: CanvasRenderingContext2D,
_mousepos?: Point2D
Expand All @@ -2110,7 +2139,7 @@ export class AccessNode extends SDFGNode {
ctx.strokeStyle = this.strokeStyle(renderer);

const name = this.data.node.attributes.data;
const nodedesc = this.sdfg.attributes._arrays[name];
const nodedesc = this.getDesc();
// Streams have dashed edges
if (nodedesc && nodedesc.type === 'Stream')
ctx.setLineDash([5, 3]);
Expand Down Expand Up @@ -2217,9 +2246,7 @@ export class AccessNode extends SDFGNode {

public tooltip(container: HTMLElement): void {
super.tooltip(container);
const nodedesc = this.sdfg.attributes._arrays[
this.data.node.attributes.data
];
const nodedesc = this.getDesc();
if (nodedesc)
return;
container.classList.add('sdfvtooltip--error');
Expand Down
4 changes: 1 addition & 3 deletions src/sdfv_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ export class SDFVWebUI implements ISDFVUserInterface {

// If access node, add array information too
if (elem instanceof AccessNode) {
const sdfg_array = elem.sdfg.attributes._arrays[
elem.attributes().data
];
const sdfg_array = elem.getDesc();
contents.append($('<br>'));
contents.append($('<h4>', {
text: sdfg_array.type + ' properties:',
Expand Down

0 comments on commit c23e92b

Please sign in to comment.