fixed implicit pass

This commit is contained in:
ALEXks
2024-04-18 21:36:40 +03:00
parent 387707cd82
commit 0f79933131
7 changed files with 118 additions and 65 deletions

View File

@@ -438,6 +438,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
auto rw_analyzer = ReadWriteAnalyzer(allFuncInfo); // doesn't analyze anything until first query
int global_err = 0;
map<string, int> same_decls;
for (int i = n - 1; i >= 0; --i)
{
createNeededException();
@@ -1033,6 +1035,24 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
}
else if (curr_regime == TEST_PASS)
{
/*int funcNum = file->numberOfFunctions();
for (int z = 0; z < funcNum; ++z)
{
SgStatement* f = file->functions(z);
for (auto st = f->lexNext(); st != f->lastNodeOfStmt(); st = st->lexNext())
{
if (st->variant() == CONTAINS_STMT)
break;
if (isSgExecutableStatement(st))
break;
string key = st->unparse();
if (same_decls.find(key) == same_decls.end())
same_decls[key] = 1;
else
same_decls[key]++;
}
}*/
//test pass
}

View File

@@ -30,16 +30,19 @@ static void FillCommonTypes(map<char, SgType*>& types)
types[letter.first] = new SgType(T_FLOAT);
}
static void FindAllVars(SgExpression* expr, set<SgSymbol*>& allVars)
static void FindAllVars(SgExpression* expr, set<SgSymbol*>& allVars, set<SgSymbol*>& allVarsConst)
{
if (expr == NULL)
return;
if (expr->variant() == VAR_REF || expr->variant() == ARRAY_REF)
const int var = expr->variant();
if (var == VAR_REF || var == ARRAY_REF)
allVars.insert(expr->symbol());
if (var == CONST_REF)
allVarsConst.insert(expr->symbol());
FindAllVars(expr->lhs(), allVars);
FindAllVars(expr->rhs(), allVars);
FindAllVars(expr->lhs(), allVars, allVarsConst);
FindAllVars(expr->rhs(), allVars, allVarsConst);
}
static char getValue(SgExpression* ex)
@@ -82,11 +85,63 @@ static void AddLettersToMap(SgExpression* expr, SgType* type, map<char, SgType*>
}
}
static vector<SgSymbol*> getVars(const char* funcSymbol, set<SgSymbol*>& toRename,
const set<SgSymbol*>& allVars, const map<char, SgType*>& types)
{
vector<SgSymbol*> varsWithoutDecl;
map<string, SgSymbol*> vars;
for (auto& var : allVars)
{
if (vars.find(var->identifier()) != vars.end())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
vars[var->identifier()] = var;
}
for (auto& var : allVars)
{
if (string(var->identifier()) == funcSymbol)
continue;
vector<SgStatement*> allDecls;
declaratedInStmt(var, &allDecls, false);
bool hasTypeDecls = false;
for (auto& decl : allDecls)
{
const int var = decl->variant();
if (var == VAR_DECL || var == VAR_DECL_90 || var == STRUCT_DECL)
hasTypeDecls = true;
}
if (!hasTypeDecls)
{
const char c = var->identifier()[0];
auto it = types.find(c);
if (it != types.end())
{
var->setType(it->second);
auto s = it->second->symbol();
if (s)
{
auto itS = vars.find(s->identifier());
if (itS != vars.end())
toRename.insert(itS->second);
}
}
varsWithoutDecl.push_back(var);
}
}
return varsWithoutDecl;
}
static map<char, SgType*> FunctionImplicitCheck(SgStatement* function, const map<SgStatement*, map<char, SgType*>>& typesByFunctions)
{
set<SgSymbol*> allVars;
set<SgSymbol*> allVars, allVarsConst;
map<char, SgType*> types;
vector<SgSymbol*> varsWithoutDecl;
vector<SgSymbol*> varsWithoutDecl, varsWithoutDeclConst;
set<SgSymbol*> toRename;
InitTypes(types);
FillCommonTypes(types);
@@ -128,28 +183,11 @@ static map<char, SgType*> FunctionImplicitCheck(SgStatement* function, const map
for (auto st = function; st != endOfFunc && st->variant() != CONTAINS_STMT; st = st->lexNext())
for (int i = 0; i < 3; ++i)
FindAllVars(st->expr(i), allVars);
for (auto& var : allVars)
{
if (string(var->identifier()) == function->symbol()->identifier())
continue;
vector<SgStatement*> _;
SgStatement* declaredInStatement = declaratedInStmt(var, &_, false);
if (declaredInStatement == NULL)
{
const char c = var->identifier()[0];
if (types.find(c) != types.end())
var->setType(types[c]);
varsWithoutDecl.push_back(var);
}
}
makeDeclaration(varsWithoutDecl, function, NULL);
FindAllVars(st->expr(i), allVars, allVarsConst);
varsWithoutDecl = getVars(function->symbol()->identifier(), toRename, allVars, types);
varsWithoutDeclConst = getVars(function->symbol()->identifier(), toRename, allVarsConst, types);
if (!hasImplicitNone)
{
for (auto st = function->lexNext();
@@ -170,11 +208,22 @@ static map<char, SgType*> FunctionImplicitCheck(SgStatement* function, const map
implNone->setlineNumber(function->lineNumber());
implNone->setFileName(function->fileName());
function->insertStmtAfter(*implNone, *function);
SgStatement* insertPlace = function;
while (insertPlace->lexNext()->variant() == USE_STMT)
insertPlace = insertPlace->lexNext();
insertPlace->insertStmtAfter(*implNone, *function);
insertPlace = insertPlace->lexNext();
makeDeclaration(varsWithoutDecl, function);
auto declList = makeDeclaration(varsWithoutDeclConst, NULL);
for (auto& decl : declList)
insertPlace->insertStmtAfter(*decl, *function);
}
allVars.clear();
varsWithoutDecl.clear();
for (auto& s : toRename)
s->changeName(TestAndCorrectName((string(s->identifier()) + "_").c_str()));
return types;
}

View File

@@ -1,3 +1,3 @@
#pragma once
#define VERSION_SPF "2322"
#define VERSION_SPF "2324"