moved messages from Parser to SPF_message

This commit is contained in:
ALEXks
2025-05-26 21:06:51 +03:00
parent 78e9b63331
commit 7ee9d839a1
4 changed files with 57 additions and 5 deletions

View File

@@ -387,7 +387,50 @@ static string shiftLines(const string &in, const map<string, const FileInfo*> &m
return newStr;
}
static int dumpErrors(const vector<FileInfo>& listOfProject, const vector<string>& errors)
static void addMessage(const string& in, const map<string, const FileInfo*>& mapOfFiles,
const FileInfo* currF, map<string, vector<Messages>>& messages, typeMessage type)
{
int byNum = 0;
auto it = in.find("on line ");
if (it != string::npos)
it += strlen("on line ");
int line = 0;
sscanf(in.c_str() + it, "%d", &line);
auto it1 = in.find("of", it + 1);
if (it1 == string::npos)
return;
it1 += 3;
string fileN = in.substr(it1, in.find(':', it1) - it1);
auto itF = mapOfFiles.find(fileN);
if (itF != mapOfFiles.end() && itF->second != currF)
{
byNum = itF->second->includesAdded;
if (byNum != 0)
{
if (line - byNum <= 0)
{
//return in;
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
else
line -= byNum;
}
}
const string newStr = in.substr(0, it) + std::to_string(line) + in.substr(in.find(' ', it + 1));
wstring messageE, messageR;
__spf_printToLongBuf(messageE, L"%s", to_wstring(newStr).c_str());
__spf_printToLongBuf(messageR, L"%s", to_wstring(newStr).c_str());
messages[fileN].push_back(Messages(type, line, messageR, messageE, 6000));
}
static int dumpErrors(const vector<FileInfo>& listOfProject, const vector<string>& errors, map<string, vector<Messages>>& messages)
{
int errorsCount = 0;
map<string, const FileInfo*> mapOfFiles;
@@ -420,9 +463,13 @@ static int dumpErrors(const vector<FileInfo>& listOfProject, const vector<string
for (auto& elem : splited)
{
if (elem.find("Warning 308") != string::npos)
{
addMessage(elem, mapOfFiles, &file, messages, WARR);
outS += shiftLines(elem, mapOfFiles, &file) + "\n";
}
else if (elem.find("Error") != string::npos)
{
addMessage(elem, mapOfFiles, &file, messages, ERROR);
errS += shiftLines(elem, mapOfFiles, &file) + "\n";
errorsCount++;
}
@@ -652,7 +699,7 @@ static int parseFiles(vector<string>& errors, vector<FileInfo>& listOfProject, v
return rethrow;
}
int parseFiles(const char* proj, vector<string>& filesCompilationOrder, int parseForInlining)
int parseFiles(const char* proj, vector<string>& filesCompilationOrder, int parseForInlining, map<string, vector<Messages>>& messages)
{
FILE* list = fopen(proj, "r");
if (!list)
@@ -723,7 +770,7 @@ int parseFiles(const char* proj, vector<string>& filesCompilationOrder, int pars
vector<string> errors;
int rethrow = parseFiles(errors, listOfProject, filesCompilationOrder, parseForInlining);
int errCount = dumpErrors(listOfProject, errors);
int errCount = dumpErrors(listOfProject, errors, messages);
if (rethrow != 0)
throw rethrow;
@@ -732,6 +779,8 @@ int parseFiles(const char* proj, vector<string>& filesCompilationOrder, int pars
void parseFiles(int argc, char** argv)
{
map<string, vector<Messages>> messages;
bool isInline = false;
auto result = splitCommandLineForParse(argv, argc, isInline);
if (result.second.size() == 0)

View File

@@ -3,5 +3,5 @@
#include <vector>
#include <string>
int parseFiles(const char* proj, std::vector<std::string>& filesCompilationOrder, int parseForInlining);
int parseFiles(const char* proj, std::vector<std::string>& filesCompilationOrder, int parseForInlining, std::map<std::string, std::vector<Messages>>& messages);
void parseFiles(int argc, char** argv);

View File

@@ -2389,7 +2389,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
break;
case PARSE_FILES:
{
int err = parseFiles(proj_name, filesCompilationOrder, parseForInlining);
int err = parseFiles(proj_name, filesCompilationOrder, parseForInlining, SPF_messages);
if (err != 0)
throw err;
}

View File

@@ -145,6 +145,9 @@ enum typeMessage { WARR, ERROR, NOTE };
// 06 "%s clause can be used only once."
// 07 "Variable '%s' can't be used in FILES and EXCEPT clauses at the same time."
// 6000 PARSER GROUP
//
extern int langOfMessages;
struct Messages
{