From e7f7a40f67ecb095577a71f7d1b20e28aa5bfd96 Mon Sep 17 00:00:00 2001 From: Process-ing Date: Mon, 29 Jul 2024 01:17:49 +0100 Subject: [PATCH] Some minor fixes --- Clava-JS/src-api/visualization/ClavaAstConverter.ts | 10 +++++++--- .../clava/visualization/ClavaAstConverter.js | 12 ++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Clava-JS/src-api/visualization/ClavaAstConverter.ts b/Clava-JS/src-api/visualization/ClavaAstConverter.ts index 9ed059785..3012fb1bc 100644 --- a/Clava-JS/src-api/visualization/ClavaAstConverter.ts +++ b/Clava-JS/src-api/visualization/ClavaAstConverter.ts @@ -268,8 +268,8 @@ export default class ClavaAstConverter implements GenericAstConverter { } if (node.jp.astName === 'LambdaExpr' && node.children.length >= 1) { - const body = node.children[0]; - if (body.jp instanceof Body && !node.code?.includes(body.code!)) { + const body = node.children.find(child => child.jp instanceof Body); + if (body && body.jp instanceof Body && !node.code?.includes(body.code!)) { body.code = body.code!.replaceAll(/\n */g, ' '); // Remove newlines and indentation from lambda body } } @@ -338,7 +338,7 @@ export default class ClavaAstConverter implements GenericAstConverter { const [openingTag, closingTag] = getSyntaxHighlightTags('type'); const escapedName = node.jp.name?.replace(/\[[^\]]*]$/, "") // Remove array suffix from variable name - const regex = new RegExp(`\\s*[&*]*\\s*` + (escapedName ? `\\b${escapedName}\\b` : "$")); // Match the declaration name (if one exists) with the '&' and '*' prefixes + const regex = new RegExp(`\\s*(&|\\*)*\\s*` + (escapedName ? `\\b${escapedName}\\b` : "$")); // Match the declaration name (if one exists) with the '&' and '*' prefixes const namePos = code.search(regex); return namePos <= 0 ? code : openingTag + code.slice(0, namePos) + closingTag + code.slice(namePos); } @@ -431,6 +431,10 @@ export default class ClavaAstConverter implements GenericAstConverter { newCodeIndex = outerCode.indexOf('(', innerCodeStart) + 1; newCode += outerCode.slice(innerCodeStart, newCodeIndex); } // Ignore function return type and name in declaration + if (root.jp instanceof ReturnStmt) { + newCodeIndex = outerCode.indexOf(' ', innerCodeStart) + 1; + newCode += outerCode.slice(innerCodeStart, newCodeIndex); + } // Ignore keyword in return statement for (const child of root.children) { const [childCodeStart, childCodeEnd, childCode] = this.linkCodeToAstNodes(child, outerCode, newCodeIndex, innerCodeEnd); diff --git a/ClavaLaraApi/src-lara/clava/visualization/ClavaAstConverter.js b/ClavaLaraApi/src-lara/clava/visualization/ClavaAstConverter.js index 0ffec6873..a69b1c697 100644 --- a/ClavaLaraApi/src-lara/clava/visualization/ClavaAstConverter.js +++ b/ClavaLaraApi/src-lara/clava/visualization/ClavaAstConverter.js @@ -218,9 +218,9 @@ export default class ClavaAstConverter { } } if (node.jp.astName === 'LambdaExpr' && node.children.length >= 1) { - const body = node.children[0]; - if (body.jp instanceof Body && !node.code?.includes(body.code)) { - body.code = body.code.replaceAll(/\n */g, ' '); + const body = node.children.find(child => child.jp instanceof Body); + if (body && body.jp instanceof Body && !node.code?.includes(body.code)) { + body.code = body.code.replaceAll(/\n */g, ' '); // Remove newlines and indentation from lambda body } } if (node.children.length >= 1 && node.children[0].jp.astName === 'TagDeclVars') { @@ -278,7 +278,7 @@ export default class ClavaAstConverter { if (node.jp instanceof Declarator || node.jp instanceof EnumeratorDecl) { const [openingTag, closingTag] = getSyntaxHighlightTags('type'); const escapedName = node.jp.name?.replace(/\[[^\]]*]$/, ""); // Remove array suffix from variable name - const regex = new RegExp(`\\s*[&*]*\\s*` + (escapedName ? `\\b${escapedName}\\b` : "$")); // Match the declaration name (if one exists) with the '&' and '*' prefixes + const regex = new RegExp(`\\s*(&|\\*)*\\s*` + (escapedName ? `\\b${escapedName}\\b` : "$")); // Match the declaration name (if one exists) with the '&' and '*' prefixes const namePos = code.search(regex); return namePos <= 0 ? code : openingTag + code.slice(0, namePos) + closingTag + code.slice(namePos); } @@ -357,6 +357,10 @@ export default class ClavaAstConverter { newCodeIndex = outerCode.indexOf('(', innerCodeStart) + 1; newCode += outerCode.slice(innerCodeStart, newCodeIndex); } // Ignore function return type and name in declaration + if (root.jp instanceof ReturnStmt) { + newCodeIndex = outerCode.indexOf(' ', innerCodeStart) + 1; + newCode += outerCode.slice(innerCodeStart, newCodeIndex); + } // Ignore keyword in return statement for (const child of root.children) { const [childCodeStart, childCodeEnd, childCode] = this.linkCodeToAstNodes(child, outerCode, newCodeIndex, innerCodeEnd); newCode += outerCode.slice(newCodeIndex, childCodeStart) + childCode; // Add portion behind children that is not matched and the linked child code