fixed privates resizing

This commit is contained in:
ALEXks
2024-03-30 19:29:13 +03:00
parent d589a372a0
commit d0fa88eea2
3 changed files with 30 additions and 19 deletions

View File

@@ -276,11 +276,10 @@ static SgExpression* constructExtendedArrayRefTail(SgExpression* oldTail, const
return newTail; return newTail;
} }
static SgExpression* extendArrayRef(const vector<SgSymbol*>& indexes, SgExpression* expressionToExtend, static void extendArrayRef(const vector<SgSymbol*>& indexes, SgExpression*& expressionToExtend,
SgSymbol* newSymbol, const vector<SgExpression*>& lowBounds) SgSymbol* newSymbol, const vector<SgExpression*>& lowBounds)
{ {
SgExpression* newTail = constructExtendedArrayRefTail(expressionToExtend->lhs(), indexes); SgExpression* newTail = constructExtendedArrayRefTail(expressionToExtend->lhs(), indexes);
SgExpression* oldTail = expressionToExtend->lhs(); SgExpression* oldTail = expressionToExtend->lhs();
if (oldTail == NULL) if (oldTail == NULL)
{ {
@@ -305,8 +304,6 @@ static SgExpression* extendArrayRef(const vector<SgSymbol*>& indexes, SgExpressi
expressionToExtend->setLhs(newTail); expressionToExtend->setLhs(newTail);
expressionToExtend->setSymbol(newSymbol); expressionToExtend->setSymbol(newSymbol);
} }
return expressionToExtend;
} }
static bool isAllocatable(SgSymbol* symbol) static bool isAllocatable(SgSymbol* symbol)
@@ -353,9 +350,16 @@ static SgExpression* checkArrayDecl(SgExpression* array, SgSymbol* arraySymbol,
{ {
vector<SgStatement*> allDecls; vector<SgStatement*> allDecls;
auto mainDecl = declaratedInStmt(arraySymbol, &allDecls); auto mainDecl = declaratedInStmt(arraySymbol, &allDecls);
if (allDecls.size() < 2) if (allDecls.size() == 0)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); 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) for (auto& decl : allDecls)
{ {
if (decl == mainDecl) if (decl == mainDecl)
@@ -418,7 +422,7 @@ static SgSymbol* alterShrinkArrayDeclaration(SgStatement *declarationStatement,
return newArraySymbol; return newArraySymbol;
} }
static void extendArrayRefsInExpr(const vector<SgSymbol*>& indexes, SgExpression* expr, static void extendArrayRefsInExpr(const vector<SgSymbol*>& indexes, SgExpression*& expr,
SgSymbol* arraySymbol, SgSymbol* newArraySymbol, SgSymbol* arraySymbol, SgSymbol* newArraySymbol,
const vector<SgExpression*>& lowBounds, int line) const vector<SgExpression*>& lowBounds, int line)
{ {
@@ -438,19 +442,20 @@ static void extendArrayRefsInExpr(const vector<SgSymbol*>& indexes, SgExpression
} }
} }
extendArrayRefsInExpr(indexes, expr->lhs(), arraySymbol, newArraySymbol, lowBounds, line); SgExpression* left = expr->lhs();
extendArrayRefsInExpr(indexes, expr->rhs(), arraySymbol, newArraySymbol, lowBounds, line); 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())) if (isArrayRef(expr) && isEqSymbols(arraySymbol, expr->symbol()))
extendArrayRef(indexes, expr, newArraySymbol, lowBounds); extendArrayRef(indexes, expr, newArraySymbol, lowBounds);
else if (expr->variant() == VAR_REF && isEqSymbols(arraySymbol, expr->symbol())) else if (expr->variant() == VAR_REF && isEqSymbols(arraySymbol, expr->symbol()))
{ extendArrayRef(indexes, expr, newArraySymbol, lowBounds);
SgExpression* extended = extendArrayRef(indexes, expr, newArraySymbol, lowBounds);
expr->setSymbol(extended->symbol());
expr->setLhs(extended->lhs());
expr->setRhs(extended->rhs());
}
} }
} }
@@ -474,7 +479,12 @@ static void extendArrayRefs(const vector<SgSymbol*> &indexes, SgStatement *st, S
} }
if (st->expr(i)) 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);
}
} }
} }

View File

@@ -19,6 +19,7 @@
#include <locale> #include <locale>
#include <algorithm> #include <algorithm>
#include <thread> #include <thread>
#include <cstdint>
#include "utils.h" #include "utils.h"
#include "errors.h" #include "errors.h"