From d0fa88eea27971aca13f4628510f8127db275a87 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Sat, 30 Mar 2024 19:29:13 +0300 Subject: [PATCH] fixed privates resizing --- .../private_arrays_resizing.cpp | 46 +++++++++++-------- .../experts/Sapfor_2017/_src/Utils/utils.cpp | 1 + .../experts/Sapfor_2017/_src/Utils/version.h | 2 +- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/private_arrays_resizing.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/private_arrays_resizing.cpp index f0df286..25d2766 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/private_arrays_resizing.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/private_arrays_resizing.cpp @@ -276,11 +276,10 @@ static SgExpression* constructExtendedArrayRefTail(SgExpression* oldTail, const return newTail; } -static SgExpression* extendArrayRef(const vector& indexes, SgExpression* expressionToExtend, - SgSymbol* newSymbol, const vector& lowBounds) +static void extendArrayRef(const vector& indexes, SgExpression*& expressionToExtend, + SgSymbol* newSymbol, const vector& lowBounds) { SgExpression* newTail = constructExtendedArrayRefTail(expressionToExtend->lhs(), indexes); - SgExpression* oldTail = expressionToExtend->lhs(); if (oldTail == NULL) { @@ -305,8 +304,6 @@ static SgExpression* extendArrayRef(const vector& indexes, SgExpressi expressionToExtend->setLhs(newTail); expressionToExtend->setSymbol(newSymbol); } - - return expressionToExtend; } static bool isAllocatable(SgSymbol* symbol) @@ -348,14 +345,21 @@ static void setAllocatable(SgStatement *newDecl, SgSymbol *origSymbol) } static SgExpression* checkArrayDecl(SgExpression* array, SgSymbol* arraySymbol, SgStatement* checkedDecl) -{ +{ if (array->lhs() == NULL) { vector allDecls; auto mainDecl = declaratedInStmt(arraySymbol, &allDecls); - if (allDecls.size() < 2) + if (allDecls.size() == 0) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + if (allDecls.size() == 1) + { + array = findSymbol(arraySymbol, mainDecl->expr(0)); + checkNull(array, convertFileName(__FILE__).c_str(), __LINE__); + return array; + } + for (auto& decl : allDecls) { if (decl == mainDecl) @@ -418,7 +422,7 @@ static SgSymbol* alterShrinkArrayDeclaration(SgStatement *declarationStatement, return newArraySymbol; } -static void extendArrayRefsInExpr(const vector& indexes, SgExpression* expr, +static void extendArrayRefsInExpr(const vector& indexes, SgExpression*& expr, SgSymbol* arraySymbol, SgSymbol* newArraySymbol, const vector& lowBounds, int line) { @@ -438,19 +442,20 @@ static void extendArrayRefsInExpr(const vector& indexes, SgExpression } } - extendArrayRefsInExpr(indexes, expr->lhs(), arraySymbol, newArraySymbol, lowBounds, line); - extendArrayRefsInExpr(indexes, expr->rhs(), arraySymbol, newArraySymbol, lowBounds, line); + SgExpression* left = expr->lhs(); + extendArrayRefsInExpr(indexes, left, arraySymbol, newArraySymbol, lowBounds, line); + if (left != expr->lhs()) + expr->setLhs(left); + + SgExpression* right = expr->rhs(); + extendArrayRefsInExpr(indexes, right, arraySymbol, newArraySymbol, lowBounds, line); + if (right != expr->rhs()) + expr->setRhs(right); if (isArrayRef(expr) && isEqSymbols(arraySymbol, expr->symbol())) extendArrayRef(indexes, expr, newArraySymbol, lowBounds); else if (expr->variant() == VAR_REF && isEqSymbols(arraySymbol, expr->symbol())) - { - SgExpression* extended = extendArrayRef(indexes, expr, newArraySymbol, lowBounds); - - expr->setSymbol(extended->symbol()); - expr->setLhs(extended->lhs()); - expr->setRhs(extended->rhs()); - } + extendArrayRef(indexes, expr, newArraySymbol, lowBounds); } } @@ -474,7 +479,12 @@ static void extendArrayRefs(const vector &indexes, SgStatement *st, S } if (st->expr(i)) - extendArrayRefsInExpr(indexes, st->expr(i), arraySymbol, newArraySymbol, lowBounds, st->lineNumber()); + { + SgExpression* ex = st->expr(i); + extendArrayRefsInExpr(indexes, ex, arraySymbol, newArraySymbol, lowBounds, st->lineNumber()); + if (ex != st->expr(i)) + st->setExpression(i, ex); + } } } diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/utils.cpp b/sapfor/experts/Sapfor_2017/_src/Utils/utils.cpp index c6d98a5..b5a3eab 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/utils.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Utils/utils.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "utils.h" #include "errors.h" diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index 8a3f0fb..071b745 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/version.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/version.h @@ -1,3 +1,3 @@ #pragma once -#define VERSION_SPF "2298" +#define VERSION_SPF "2298"