fixed BUILD_INCLUDE_DEPENDENCIES pass

This commit is contained in:
ALEXks
2025-05-18 15:38:26 +03:00
parent 5f98eaf872
commit a719dea05f
4 changed files with 29 additions and 23 deletions

View File

@@ -331,7 +331,8 @@ static string unparseProjectIfNeed(SgFile* file, const int curr_regime, const bo
unparseToBuf = removeIncludeStatsAndUnparse(file, file_name, fout_name.c_str(), allIncludeFiles, out_free_form == 1, moduleUsesByFile, unparseToBuf = removeIncludeStatsAndUnparse(file, file_name, fout_name.c_str(), allIncludeFiles, out_free_form == 1, moduleUsesByFile,
moduleDecls, getObjectForFileFromMap(file_name, exctactedModuleStats), toString, false, true); moduleDecls, getObjectForFileFromMap(file_name, exctactedModuleStats), toString, false, true);
auto itI = filesToInclude.find(file_name); auto itI = filesToInclude.find(file_name);
for (auto& [_, incl] : itI->second) for (auto& [_, incls] : itI->second)
for (auto& incl : incls)
if (allIncludeFiles.find(incl) != allIncludeFiles.end()) if (allIncludeFiles.find(incl) != allIncludeFiles.end())
allIncludeFiles.erase(incl); allIncludeFiles.erase(incl);
} }
@@ -827,7 +828,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
{ {
auto fileIt = includeDependencies.find(file_name); auto fileIt = includeDependencies.find(file_name);
if (fileIt == includeDependencies.end()) if (fileIt == includeDependencies.end())
fileIt = includeDependencies.insert(fileIt, make_pair(file_name, vector<pair<int, string>>())); fileIt = includeDependencies.insert(fileIt, make_pair(file_name, map<int, set<string>>()));
set<string> modFiles; set<string> modFiles;
for (auto& elem : moduleDecls) for (auto& elem : moduleDecls)
@@ -844,7 +845,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
{ {
if (lastFromFile == NULL) if (lastFromFile == NULL)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
fileIt->second.push_back(make_pair(lastFromFile->lineNumber(), st->fileName())); fileIt->second[lastFromFile->lineNumber()].insert(st->fileName());
} }
else else
lastFromFile = st; lastFromFile = st;
@@ -1603,14 +1604,17 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
set<string> includedToThisFile; set<string> includedToThisFile;
if (itDep != includeDependencies.end()) if (itDep != includeDependencies.end())
{ {
for (auto& [_, incl] : itDep->second) for (auto& [_, incls] : itDep->second)
{
for (auto& incl : incls)
{ {
auto comm = commentsToInclude.find(incl); auto comm = commentsToInclude.find(incl);
if (comm != commentsToInclude.end()) if (comm != commentsToInclude.end())
for (auto &allComm : comm->second) for (auto& allComm : comm->second)
includedToThisFile.insert(allComm.second.begin(), allComm.second.end()); includedToThisFile.insert(allComm.second.begin(), allComm.second.end());
} }
} }
}
for (int z = 0; z < parallelRegions.size(); ++z) for (int z = 0; z < parallelRegions.size(); ++z)
{ {

View File

@@ -85,7 +85,7 @@ std::map<std::string, std::map<int, std::set<std::string>>> commentsToInclude;
// //
//for INSERT_INCLUDES //for INSERT_INCLUDES
std::map<std::string, std::vector<std::pair<int, std::string>>> filesToInclude; // file -> includes [nearest line, include] std::map<std::string, std::map<int, std::set<std::string>>> filesToInclude; // file -> includes [nearest line, include]
// //
//for PASSES DEPENDENSIES //for PASSES DEPENDENSIES
@@ -96,7 +96,7 @@ std::set<passes> passesIgnoreStateDone;
//for files info //for files info
std::map<std::string, int> lineInfo; // file -> lines count std::map<std::string, int> lineInfo; // file -> lines count
std::map<std::string, std::pair<std::set<int>, std::set<int>>> dirsInfo; // file -> dirs <lines SPF, lines DVM> count std::map<std::string, std::pair<std::set<int>, std::set<int>>> dirsInfo; // file -> dirs <lines SPF, lines DVM> count
std::map<std::string, std::vector<std::pair<int, std::string>>> includeDependencies; // file -> includes [nearest line, include] std::map<std::string, std::map<int, std::set<std::string>>> includeDependencies; // file -> includes [nearest line, include]
std::vector<std::string> filesCompilationOrder; // order of files for unite to one file std::vector<std::string> filesCompilationOrder; // order of files for unite to one file
std::map<std::string, std::map<SgStatement*, std::vector<SgStatement*>>> exctactedModuleStats; // file -> hided excluded modules std::map<std::string, std::map<SgStatement*, std::vector<SgStatement*>>> exctactedModuleStats; // file -> hided excluded modules
// //

View File

@@ -1,3 +1,3 @@
#pragma once #pragma once
#define VERSION_SPF "2417" #define VERSION_SPF "2418"

View File

@@ -1308,7 +1308,7 @@ int SPF_GetIntrinsics(void*& context, short *&result)
return (int)resVal.size() + 1; return (int)resVal.size() + 1;
} }
extern map<string, vector<pair<int, string>>> includeDependencies; extern map<string, map<int, set<string>>> includeDependencies;
int SPF_GetIncludeDependencies(void*& context, int winHandler, short *options, short *projName, short *&result, short*& output, int*& outputSize, int SPF_GetIncludeDependencies(void*& context, int winHandler, short *options, short *projName, short *&result, short*& output, int*& outputSize,
short*& outputMessage, int*& outputMessageSize) short*& outputMessage, int*& outputMessageSize)
{ {
@@ -1328,13 +1328,16 @@ int SPF_GetIncludeDependencies(void*& context, int winHandler, short *options, s
includes["file"] = deps.first; includes["file"] = deps.first;
json array = json::array(); json array = json::array();
for (const auto& [line, incl] : deps.second) for (const auto& [line, incls] : deps.second)
{
for (auto& incl : incls)
{ {
json elem; json elem;
elem["line"] = line; elem["line"] = line;
elem["dependencyFileName"] = incl; elem["dependencyFileName"] = incl;
array.push_back(elem); array.push_back(elem);
} }
}
includes["includes"] = array; includes["includes"] = array;
inc_array.push_back(includes); inc_array.push_back(includes);
} }
@@ -2189,7 +2192,7 @@ int SPF_InlineProcedures(void*& context, int winHandler, short* options, short*
} }
extern map<string, vector<pair<int, string>>> filesToInclude; extern map<string, map<int, set<string>>> filesToInclude;
int SPF_InsertIncludesPass(void*& context, int winHandler, short *options, short *projName, short *folderName, char *visFilesToInclude, int SPF_InsertIncludesPass(void*& context, int winHandler, short *options, short *projName, short *folderName, char *visFilesToInclude,
short *&output, int *&outputSize, short *&outputMessage, int *&outputMessageSize) short *&output, int *&outputSize, short *&outputMessage, int *&outputMessageSize)
{ {
@@ -2222,9 +2225,8 @@ int SPF_InsertIncludesPass(void*& context, int winHandler, short *options, short
if (sscanf(splited[k].c_str(), "%d", &line) == -1) if (sscanf(splited[k].c_str(), "%d", &line) == -1)
return -5; return -5;
auto pair = make_pair(line, splited[k + 1]); filesToInclude[file][line].insert(splited[k + 1]);
filesToInclude[file].push_back(pair); __spf_print(1, " include = [%d %s]\n", line, splited[k + 1].c_str());
__spf_print(1, " include = [%d %s]\n", pair.first, pair.second.c_str());
} }
i += 2 * num; i += 2 * num;
} }