Skip to content

Commit 754e509

Browse files
committed
dont need generic message anymore
1 parent aaea761 commit 754e509

2 files changed

Lines changed: 3 additions & 95 deletions

File tree

lib/errorlogger.cpp

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)
191191
attr = errmsg->Attribute("verbose");
192192
mVerboseMessage = attr ? attr : "";
193193

194-
attr = errmsg->Attribute("generic");
195-
mGenericMessage = attr ? attr : "";
196-
197194
attr = errmsg->Attribute("hash");
198195
hash = attr ? strToInt<std::size_t>(attr) : 0;
199196

@@ -217,75 +214,6 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)
217214
}
218215

219216
// Convert instance-specific messages to generic ones
220-
static std::string makeGeneric(const std::string &message)
221-
{
222-
std::string result = message;
223-
224-
// Handle format string patterns first (before general single-quoted replacement)
225-
result = std::regex_replace(result, std::regex(R"(%[a-zA-Z0-9]+)"), "format specifier");
226-
227-
// Handle specific casting patterns
228-
result = std::regex_replace(
229-
result,
230-
std::regex(
231-
R"(Casting between (?:(?:const\s+|unsigned\s+|signed\s+)*[a-zA-Z_][a-zA-Z0-9_]*\s*\*+\s*and\s*(?:const\s+|unsigned\s+|signed\s+)*[a-zA-Z_][a-zA-Z0-9_]*\s*\*+) which have)"),
232-
"Casting between incompatible pointer types which have");
233-
234-
// Handle specific pointer type patterns (after casting patterns)
235-
result = std::regex_replace(
236-
result, std::regex(R"(\b(?:const\s+|unsigned\s+|signed\s+)*[a-zA-Z_][a-zA-Z0-9_]*\s*\*+)"), "pointer type");
237-
238-
// Handle specific patterns that need special treatment
239-
// Iterator condition patterns
240-
result = std::regex_replace(
241-
result,
242-
std::regex(
243-
R"(Either the condition '[^']*' is redundant or there is possible dereference of an invalid iterator[^.]*\.)"),
244-
"Either the condition is redundant or there is possible dereference of an invalid iterator.");
245-
246-
// Access moved variable patterns
247-
result = std::regex_replace(result, std::regex(R"(Access of moved variable '[^']*')"), "Access of moved variable");
248-
249-
// Variable/function/parameter patterns (before general replacement)
250-
result = std::regex_replace(result, std::regex(R"(Variable '[^']*')"), "Variable");
251-
result = std::regex_replace(result, std::regex(R"(variable '[^']*')"), "variable");
252-
result = std::regex_replace(result, std::regex(R"(Function '[^']*')"), "Function");
253-
result = std::regex_replace(result, std::regex(R"(function '[^']*')"), "function");
254-
result = std::regex_replace(result, std::regex(R"(Parameter '[^']*')"), "Parameter");
255-
result = std::regex_replace(result, std::regex(R"(parameter '[^']*')"), "parameter");
256-
result = std::regex_replace(result, std::regex(R"(Member variable '[^']*')"), "Member variable");
257-
result = std::regex_replace(result, std::regex(R"(member variable '[^']*')"), "member variable");
258-
259-
// Replace double-quoted strings with generic placeholder
260-
result = std::regex_replace(result, std::regex(R"("(?:[^"\\]|\\.)*")"), "\"string\"");
261-
262-
// Replace all remaining single-quoted identifiers with generic placeholder
263-
result = std::regex_replace(result, std::regex(R"('[^']*')"), "'identifier'");
264-
265-
// Replace all numbers with generic placeholder
266-
result = std::regex_replace(result, std::regex(R"(\b\d+\b)"), "N");
267-
268-
// Replace array access patterns
269-
result = std::regex_replace(result, std::regex(R"(\[[^\]]+\])"), "[index]");
270-
271-
// Clean up patterns that may have resulted in redundant text
272-
result = std::regex_replace(result, std::regex(R"(Variable 'identifier')"), "Variable");
273-
result = std::regex_replace(result, std::regex(R"(Function 'identifier')"), "Function");
274-
result = std::regex_replace(result, std::regex(R"(Parameter 'identifier')"), "Parameter");
275-
result = std::regex_replace(result, std::regex(R"(Member variable 'identifier')"), "Member variable");
276-
277-
// Clean up trailing colons that don't reference anything
278-
result = std::regex_replace(result, std::regex(R"(:\s*$)"), "");
279-
280-
// Clean up multiple spaces
281-
result = std::regex_replace(result, std::regex(R"(\s+)"), " ");
282-
283-
// Trim whitespace
284-
result = std::regex_replace(result, std::regex(R"(^\s+|\s+$)"), "");
285-
286-
return result;
287-
}
288-
289217
void ErrorMessage::setmsg(const std::string &msg)
290218
{
291219
// If a message ends to a '\n' and contains only a one '\n'
@@ -303,18 +231,12 @@ void ErrorMessage::setmsg(const std::string &msg)
303231
if (pos == std::string::npos) {
304232
mShortMessage = replaceStr(msg, "$symbol", symbolName);
305233
mVerboseMessage = replaceStr(msg, "$symbol", symbolName);
306-
// Set generic message (remove symbol names and make generic)
307-
const std::string msgWithoutSymbol = replaceStr(msg, "$symbol", "");
308-
mGenericMessage = makeGeneric(msgWithoutSymbol);
309234
} else if (startsWith(msg,"$symbol:")) {
310235
mSymbolNames += msg.substr(8, pos-7);
311236
setmsg(msg.substr(pos + 1));
312237
} else {
313238
mShortMessage = replaceStr(msg.substr(0, pos), "$symbol", symbolName);
314239
mVerboseMessage = replaceStr(msg.substr(pos + 1), "$symbol", symbolName);
315-
// Set generic message (remove symbol names and make generic)
316-
const std::string msgWithoutSymbol = replaceStr(msg.substr(0, pos), "$symbol", "");
317-
mGenericMessage = makeGeneric(msgWithoutSymbol);
318240
}
319241
}
320242

@@ -365,12 +287,10 @@ std::string ErrorMessage::serialize() const
365287

366288
const std::string saneShortMessage = fixInvalidChars(mShortMessage);
367289
const std::string saneVerboseMessage = fixInvalidChars(mVerboseMessage);
368-
const std::string saneGenericMessage = fixInvalidChars(mGenericMessage);
369290

370291
serializeString(oss, saneShortMessage);
371292
serializeString(oss, saneVerboseMessage);
372293
serializeString(oss, mSymbolNames);
373-
serializeString(oss, saneGenericMessage);
374294
oss += std::to_string(callStack.size());
375295
oss += " ";
376296

@@ -398,9 +318,9 @@ void ErrorMessage::deserialize(const std::string &data)
398318
callStack.clear();
399319

400320
std::istringstream iss(data);
401-
std::array<std::string, 11> results;
321+
std::array<std::string, 10> results;
402322
std::size_t elem = 0;
403-
while (iss.good() && elem < 11) {
323+
while (iss.good() && elem < 10) {
404324
unsigned int len = 0;
405325
if (!(iss >> len))
406326
throw InternalError(nullptr, "Internal Error: Deserialization of error message failed - invalid length");
@@ -426,7 +346,7 @@ void ErrorMessage::deserialize(const std::string &data)
426346
if (!iss.good())
427347
throw InternalError(nullptr, "Internal Error: Deserialization of error message failed - premature end of data");
428348

429-
if (elem != 11)
349+
if (elem != 10)
430350
throw InternalError(nullptr, "Internal Error: Deserialization of error message failed - insufficient elements");
431351

432352
id = std::move(results[0]);
@@ -450,7 +370,6 @@ void ErrorMessage::deserialize(const std::string &data)
450370
mShortMessage = std::move(results[7]);
451371
mVerboseMessage = std::move(results[8]);
452372
mSymbolNames = std::move(results[9]);
453-
mGenericMessage = std::move(results[10]);
454373

455374
unsigned int stackSize = 0;
456375
if (!(iss >> stackSize))

lib/errorlogger.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,6 @@ class CPPCHECKLIB ErrorMessage {
200200
return mSymbolNames;
201201
}
202202

203-
/** Generic message (instance-specific variables replaced with generic terms) */
204-
const std::string &genericMessage() const {
205-
return mGenericMessage;
206-
}
207-
208-
/** set generic message */
209-
void setGenericMessage(const std::string &msg);
210-
211203
static ErrorMessage fromInternalError(const InternalError &internalError, const TokenList *tokenList, const std::string &filename, const std::string& msg = "");
212204

213205
private:
@@ -221,9 +213,6 @@ class CPPCHECKLIB ErrorMessage {
221213

222214
/** symbol names */
223215
std::string mSymbolNames;
224-
225-
/** Generic message */
226-
std::string mGenericMessage;
227216
};
228217

229218
/**

0 commit comments

Comments
 (0)