From 87a4413472c0c117df3359bec7419bded1055426 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Tue, 14 May 2024 12:53:31 +0300 Subject: [PATCH 1/2] fixed implicit pass --- .gitignore | 2 + sapfor/experts/Sapfor_2017/_src/Sapfor.cpp | 2 +- .../Transformations/function_purifying.cpp | 2 +- .../Transformations/set_implicit_none.cpp | 45 ++++++++++++++++++- .../Sapfor_2017/_src/Utils/SgUtils.cpp | 12 ++--- .../experts/Sapfor_2017/_src/Utils/version.h | 2 +- 6 files changed, 55 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 26bbf69..ab041ca 100644 --- a/.gitignore +++ b/.gitignore @@ -74,3 +74,5 @@ sapfor/experts/Sapfor_2017/Sapc++/Sapc++/x64/ sapfor/experts/Sapfor_2017/Sapc++/x64/ /build + +sapfor/experts/Sapfor_2017/out/ diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp index efa3410..7759c53 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -2432,7 +2432,7 @@ int main(int argc, char **argv) int numVar = 0; out_free_form = 0; // F90 style out - out_upper_case = 1; + out_upper_case = 0; out_line_unlimit = 0; bool printText = false; diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp index 03316f2..c85d2e9 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp @@ -1010,7 +1010,7 @@ void commonTransfer(const map>& allFuncInfo, const map } } -static string changeData(const string data, const map& constSymVars, const map& locVars) +static string changeData(const string& data, const map& constSymVars, const map& locVars) { int curChar = 0; string ident = ""; diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/set_implicit_none.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/set_implicit_none.cpp index b4c537c..c2b8551 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/set_implicit_none.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/set_implicit_none.cpp @@ -39,7 +39,12 @@ static void FindAllVars(SgExpression* expr, set& allVars, setsymbol(); - if ((s->attributes() & EXTERNAL_BIT) == 0) + if ((s->attributes() & EXTERNAL_BIT)) + { + if (var == FUNC_CALL) + allVars.insert(s); + } + else allVars.insert(s); } else if (var == CONST_REF) @@ -187,18 +192,34 @@ static map FunctionImplicitCheck(SgStatement* function, const map set skip = { EXTERN_STAT }; + set allDataSymbols; + for (auto s = function->symbol()->next(); s; s = s->next()) + if (s->attributes() & DATA_BIT) + allDataSymbols.insert(s); + for (auto st = function->lexNext(); st != endOfFunc && st->variant() != CONTAINS_STMT; st = st->lexNext()) { if (skip.count(st->variant())) continue; + if (st->variant() == DATA_DECL) + { + const string str = st->expr(0)->thellnd->entry.string_val; + + for (auto& data : allDataSymbols) + { + if (str.find(data->identifier()) != string::npos) + allVars.insert(data); + } + } + for (int i = 0; i < 3; ++i) FindAllVars(st->expr(i), allVars, allVarsConst); if (st->variant() == FOR_NODE) allVars.insert(isSgForStmt(st)->doName()); } - + //add parameters auto prog = isSgProgHedrStmt(function); if (prog) @@ -216,6 +237,8 @@ static map FunctionImplicitCheck(SgStatement* function, const map if (!hasImplicitNone) { + vector macro; + for (auto st = function->lexNext(); st != endOfFunc && st->variant() != CONTAINS_STMT && isSgExecutableStatement(st) == NULL; ) @@ -226,6 +249,12 @@ static map FunctionImplicitCheck(SgStatement* function, const map st = st->lexNext(); tmpStatement->deleteStmt(); } + else if (st->variant() == STMTFN_STAT) + { + auto stat = st; + st = st->lexNext(); + macro.push_back(stat->extractStmt()); + } else st = st->lexNext(); } @@ -253,6 +282,18 @@ static map FunctionImplicitCheck(SgStatement* function, const map auto declList = makeDeclaration(varsWithoutDeclConst, NULL); for (auto& decl : declList) insertPlace->insertStmtAfter(*decl, *function); + + if (macro.size()) + { + while (!isSgExecutableStatement(insertPlace) && insertPlace != NULL) + insertPlace = insertPlace->lexNext(); + + if (insertPlace == NULL) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + + for (auto& elem : macro) + insertPlace->insertStmtBefore(*elem, *function); + } } for (auto& s : toRename) diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp index 2b41882..ae78c98 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp @@ -1002,12 +1002,14 @@ static bool findSymbol(SgExpression *declLst, const string &toFind) if (ex->symbol()->identifier() == toFind) return true; } + else + { + if (ex->lhs()) + exs.push(ex->lhs()); - if (ex->lhs()) - exs.push(ex->lhs()); - - if (ex->rhs()) - exs.push(ex->rhs()); + if (ex->rhs()) + exs.push(ex->rhs()); + } } return false; } diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index f45280d..ee7049e 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 "2336" +#define VERSION_SPF "2337" From 2fa0eb3e428509a5eba4be35dac977e9c345f498 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Wed, 15 May 2024 17:54:18 +0300 Subject: [PATCH 2/2] fixed implicit pass --- .../Transformations/set_implicit_none.cpp | 66 ++++++++++++++----- .../Sapfor_2017/_src/Utils/PassManager.h | 2 + .../Sapfor_2017/_src/Utils/SgUtils.cpp | 2 +- .../experts/Sapfor_2017/_src/Utils/version.h | 2 +- .../VerificationCode/StructureChecker.cpp | 9 +-- 5 files changed, 57 insertions(+), 24 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/set_implicit_none.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/set_implicit_none.cpp index c2b8551..c45db9a 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/set_implicit_none.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/set_implicit_none.cpp @@ -30,7 +30,7 @@ static void FillCommonTypes(map& types) types[letter.first] = new SgType(T_FLOAT); } -static void FindAllVars(SgExpression* expr, set& allVars, set& allVarsConst) +static void FindAllVars(SgExpression* expr, set& allVars, set& allVarsConst, SgStatement* scope) { if (expr == NULL) return; @@ -41,17 +41,22 @@ static void FindAllVars(SgExpression* expr, set& allVars, setsymbol(); if ((s->attributes() & EXTERNAL_BIT)) { - if (var == FUNC_CALL) + if (var == FUNC_CALL && !IS_BY_USE(s) && s->scope() == scope) allVars.insert(s); } else - allVars.insert(s); + { + if (!IS_BY_USE(s) && s->scope() == scope) + { + allVars.insert(s); + } + } } else if (var == CONST_REF) allVarsConst.insert(expr->symbol()); - FindAllVars(expr->lhs(), allVars, allVarsConst); - FindAllVars(expr->rhs(), allVars, allVarsConst); + FindAllVars(expr->lhs(), allVars, allVarsConst, scope); + FindAllVars(expr->rhs(), allVars, allVarsConst, scope); } static char getValue(SgExpression* ex) @@ -94,7 +99,7 @@ static void AddLettersToMap(SgExpression* expr, SgType* type, map } } -static vector getVars(const char* funcSymbol, set& toRename, +static vector getVars(const set& functionSymbs, set& toRename, const set& allVars, const map& types) { vector varsWithoutDecl; @@ -108,7 +113,7 @@ static vector getVars(const char* funcSymbol, set& toRenam for (auto& var : allVars) { - if (string(var->identifier()) == funcSymbol) + if (functionSymbs.count(var->identifier())) continue; vector allDecls; @@ -194,14 +199,31 @@ static map FunctionImplicitCheck(SgStatement* function, const map set allDataSymbols; for (auto s = function->symbol()->next(); s; s = s->next()) - if (s->attributes() & DATA_BIT) + if ((s->attributes() & DATA_BIT) && s->scope() == function) allDataSymbols.insert(s); + set functionSymbs = { function->symbol()->identifier() }; + if (isSgFuncHedrStmt(function)) + { + SgFuncHedrStmt* hedr = isSgFuncHedrStmt(function); + if (hedr->resultName()) + functionSymbs.insert(hedr->resultName()->identifier()); + } + for (auto st = function->lexNext(); st != endOfFunc && st->variant() != CONTAINS_STMT; st = st->lexNext()) { if (skip.count(st->variant())) continue; + if (isDVM_stat(st) || isSPF_stat(st)) + continue; + + if (st->variant() == INTERFACE_STMT) + { + st = st->lastNodeOfStmt(); + continue; + } + if (st->variant() == DATA_DECL) { const string str = st->expr(0)->thellnd->entry.string_val; @@ -214,10 +236,14 @@ static map FunctionImplicitCheck(SgStatement* function, const map } for (int i = 0; i < 3; ++i) - FindAllVars(st->expr(i), allVars, allVarsConst); + FindAllVars(st->expr(i), allVars, allVarsConst, function); if (st->variant() == FOR_NODE) - allVars.insert(isSgForStmt(st)->doName()); + { + auto s = isSgForStmt(st)->doName(); + if (!IS_BY_USE(s) && s->scope() == function) + allVars.insert(s); + } } //add parameters @@ -232,8 +258,8 @@ static map FunctionImplicitCheck(SgStatement* function, const map } } - varsWithoutDecl = getVars(function->symbol()->identifier(), toRename, allVars, types); - varsWithoutDeclConst = getVars(function->symbol()->identifier(), toRename, allVarsConst, types); + varsWithoutDecl = getVars(functionSymbs, toRename, allVars, types); + varsWithoutDeclConst = getVars(functionSymbs, toRename, allVarsConst, types); if (!hasImplicitNone) { @@ -272,9 +298,16 @@ static map FunctionImplicitCheck(SgStatement* function, const map if (function->variant() == FUNC_HEDR) { + SgFuncHedrStmt* hedr = isSgFuncHedrStmt(function); + auto type_op = function->expr(1); if (type_op == NULL) - varsWithoutDecl.push_back(function->symbol()); + { + if (hedr->resultName()) + varsWithoutDecl.push_back(hedr->resultName()); + else + varsWithoutDecl.push_back(function->symbol()); + } } makeDeclaration(varsWithoutDecl, function); @@ -306,9 +339,12 @@ void implicitCheck(SgFile* file) { map> typesByFunctions; - for (int func = 0; func < file->numberOfFunctions(); ++func) + vector modulesAndFunctions; + getModulesAndFunctions(file, modulesAndFunctions); + + for (int func = 0; func < modulesAndFunctions.size(); ++func) { - SgStatement* function = file->functions(func); + SgStatement* function = modulesAndFunctions[func]; typesByFunctions[function] = FunctionImplicitCheck(function, typesByFunctions); } diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h b/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h index a5068c3..50f571b 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h @@ -310,6 +310,8 @@ void InitPassesDependencies(map> &passDepsIn, set list({ CALL_GRAPH2, REVERT_SUBST_EXPR_RD }) <= Pass(REMOVE_DEAD_CODE); list({ REMOVE_DEAD_CODE, CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN }) <= Pass(REMOVE_DEAD_CODE_AND_UNPARSE); + Pass(CORRECT_VAR_DECL) <= Pass(SET_IMPLICIT_NONE); + passesIgnoreStateDone.insert({ CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS, INSERT_SHADOW_DIRS, EXTRACT_PARALLEL_DIRS, EXTRACT_SHADOW_DIRS, CREATE_REMOTES, UNPARSE_FILE, REMOVE_AND_CALC_SHADOW, REVERSE_CREATED_NESTED_LOOPS, PREDICT_SCHEME, CALCULATE_STATS_SCHEME, REVERT_SPF_DIRS, CLEAR_SPF_DIRS, TRANSFORM_SHADOW_IF_FULL, diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp index ae78c98..02c2c11 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp @@ -997,7 +997,7 @@ static bool findSymbol(SgExpression *declLst, const string &toFind) SgExpression* ex = exs.top(); exs.pop(); - if (ex->variant() == ARRAY_REF || ex->variant() == VAR_REF) + if (ex->variant() == ARRAY_REF || ex->variant() == VAR_REF || ex->variant() == CONST_REF) { if (ex->symbol()->identifier() == toFind) return true; diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index ee7049e..f4f69b9 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 "2337" +#define VERSION_SPF "2339" diff --git a/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp b/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp index 99c38d6..0c6d0e9 100644 --- a/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp +++ b/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp @@ -590,7 +590,6 @@ bool checkAndMoveFormatOperators(SgFile* file, vector& currMessages, b SgStatement* lastNode = st->lastNodeOfStmt(); vector toMove; - SgStatement* firstExec = NULL; while (st != lastNode) { if (st == NULL) @@ -602,11 +601,8 @@ bool checkAndMoveFormatOperators(SgFile* file, vector& currMessages, b if (st->variant() == CONTAINS_STMT) break; - if (isSgExecutableStatement(st) && !isDVM_stat(st) && !isSPF_stat(st)) - { - firstExec = st; + if (isSgExecutableStatement(st) && !isDVM_stat(st) && !isSPF_stat(st)) break; - } if (st->variant() == FORMAT_STAT) { @@ -630,9 +626,8 @@ bool checkAndMoveFormatOperators(SgFile* file, vector& currMessages, b { if (!withError) { - checkNull(firstExec, convertFileName(__FILE__).c_str(), __LINE__); for (auto& format : toMove) - firstExec->insertStmtBefore(*format, *firstExec->controlParent()); + lastNode->insertStmtBefore(*format, *lastNode->controlParent()); } else {