From f145afceef27923b96fb0f89604587467f21d117 Mon Sep 17 00:00:00 2001 From: DenisDudarenko Date: Thu, 14 Mar 2024 15:45:03 +0300 Subject: [PATCH] Fix warnings --- .../Transformations/set_implicit_none.cpp | 108 ++++++++++-------- 1 file changed, 60 insertions(+), 48 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 1cb3ce4..cb719e4 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/set_implicit_none.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/set_implicit_none.cpp @@ -1,19 +1,8 @@ -#include -#include -#include -#include - #include "Utils/SgUtils.h" #include "set_implicit_none.h" -#include using std::vector; using std::map; -using std::multimap; -using std::set; -using std::make_pair; -using std::string; -using std::to_string; map types; vector allVars; @@ -24,9 +13,11 @@ void InitTypes(); void FillCommonTypes(); void FunctionImplicitCheck(SgStatement* function); -void ImplicitCheck(SgFile* file) { +void ImplicitCheck(SgFile* file) +{ - for (int funcNum = 0; funcNum < file->numberOfFunctions(); funcNum++) { + for (int funcNum = 0; funcNum < file->numberOfFunctions(); funcNum++) + { SgStatement* function = file->functions(funcNum); FunctionImplicitCheck(function); } @@ -34,22 +25,27 @@ void ImplicitCheck(SgFile* file) { return; } -void FunctionImplicitCheck(SgStatement* function) { +void FunctionImplicitCheck(SgStatement* function) +{ auto implicitNoneDeclaration = new SgStatement(IMPL_DECL); auto hasImplicitNone = false; InitTypes(); FillCommonTypes(); - for (SgStatement* i = function->lexNext(); i = i->lexNext(); i != NULL) { - - if (i->variant() == IMPL_DECL) { - SgImplicitStmt* implicitSt = isSgImplicitStmt(i); - if (implicitSt) { + for (SgStatement* statement = function->lexNext(); statement = statement->lexNext(); statement != NULL) + { + if (statement->variant() == IMPL_DECL) + { + SgImplicitStmt* implicitSt = isSgImplicitStmt(statement); + if (implicitSt) + { int numberOfTypes = implicitSt->numberOfImplicitTypes(); - if (numberOfTypes > 0) { - for (int j = 0; j < numberOfTypes; j++) { + if (numberOfTypes > 0) + { + for (int j = 0; j < numberOfTypes; j++) + { SgType* type = implicitSt->implicitType(j); SgExpression* letters = implicitSt->implicitRangeList(j); @@ -57,15 +53,22 @@ void FunctionImplicitCheck(SgStatement* function) { types['o'] = type; } } - else { + else + { hasImplicitNone = true; } } } + else if (statement->variant() == CONTAINS_STMT || isSgExecutableStatement(statement) != NULL) + { + break; + } } - for (SgSymbol* symbol = function->symbol(); symbol != NULL; symbol = symbol->next()) { - if (symbol != NULL && symbol->declaredInStmt() != NULL) { + for (SgSymbol* symbol = function->symbol(); symbol != NULL; symbol = symbol->next()) + { + if (symbol != NULL && symbol->declaredInStmt() != NULL) + { allVars.push_back(symbol); } } @@ -74,36 +77,38 @@ void FunctionImplicitCheck(SgStatement* function) { { vector _; SgStatement* declaredIn = declaratedInStmt(var, &_, false); - if (declaredIn == NULL) { + if (declaredIn == NULL) + { + char c = var->identifier()[0]; + + if (types.find(c) != types.end()) + { + var->setType(types[c]); + } + varsWithoutDecl.push_back(var); } } - for (auto var : varsWithoutDecl) { - vector test = { var }; - char c = var->identifier()[0]; + makeDeclaration(varsWithoutDecl, function, NULL); - if (types.find(c) != types.end()) { - test[0]->setType(types[c]); - } - - makeDeclaration(function, test); - } - - if (!hasImplicitNone) { - for (SgStatement* i = function->lexNext(); i != NULL;) { - if (i->variant() == IMPL_DECL) { + if (!hasImplicitNone) + { + for (SgStatement* i = function->lexNext(); i != NULL;) + { + if (i->variant() == IMPL_DECL) + { auto tmp = i; i = i->lexNext(); tmp->deleteStmt(); } - else { + else + { i = i->lexNext(); } } - auto firstRealStatementOfFile = function->lexNext(); - firstRealStatementOfFile->insertStmtBefore(*implicitNoneDeclaration, *(firstRealStatementOfFile->controlParent())); + function->insertStmtBefore(*implicitNoneDeclaration, *function); } printf("%s", function->unparse()); @@ -111,21 +116,28 @@ void FunctionImplicitCheck(SgStatement* function) { return; } -void InitTypes() { - for (char i = 'a'; i <= 'z'; i++) { +void InitTypes() +{ + for (char i = 'a'; i <= 'z'; i++) + { types[i] = NULL; } } -void FillCommonTypes() { - for (char i: commonIntLetters) { - if (types[i] == NULL) { +void FillCommonTypes() +{ + for (char i: commonIntLetters) + { + if (types[i] == NULL) + { types[i] = new SgType(T_INT); } } - for (auto i : types) { - if (i.second == NULL) { + for (auto i : types) + { + if (i.second == NULL) + { types[i.first] = new SgType(T_FLOAT); } }