Error() and Warning() functions for reporting compiler errors/warnings now respects newlines as part of valid error messages.
This commit is contained in:
2
lex.ll
2
lex.ll
@@ -704,7 +704,7 @@ lEscapeChar(char *str, char *pChar, SourcePos *pos)
|
|||||||
str = tail - 1;
|
str = tail - 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Error(*pos, "Bad character escape sequence: '%s'\n.", str);
|
Error(*pos, "Bad character escape sequence: '%s'.", str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
stmt.cpp
24
stmt.cpp
@@ -2281,26 +2281,22 @@ GotoStmt::EmitCode(FunctionEmitContext *ctx) const {
|
|||||||
|
|
||||||
llvm::BasicBlock *bb = ctx->GetLabeledBasicBlock(label);
|
llvm::BasicBlock *bb = ctx->GetLabeledBasicBlock(label);
|
||||||
if (bb == NULL) {
|
if (bb == NULL) {
|
||||||
/* Label wasn't found. Emit an error */
|
/* Label wasn't found. Look for suggestions that are close */
|
||||||
Error(identifierPos,
|
|
||||||
"No label named \"%s\" found in current function.",
|
|
||||||
label.c_str());
|
|
||||||
|
|
||||||
/* Look for suggestions that are close */
|
|
||||||
std::vector<std::string> labels = ctx->GetLabels();
|
std::vector<std::string> labels = ctx->GetLabels();
|
||||||
std::vector<std::string> matches = MatchStrings(label, labels);
|
std::vector<std::string> matches = MatchStrings(label, labels);
|
||||||
|
std::string match_output;
|
||||||
if (! matches.empty()) {
|
if (! matches.empty()) {
|
||||||
/* Print up to 5 matches. Don't want to spew too much */
|
/* Print up to 5 matches. Don't want to spew too much */
|
||||||
std::string match_output("Did you mean\n");
|
match_output += "\nDid you mean:";
|
||||||
for (unsigned int i=0; i<matches.size() && i<5; i++)
|
for (unsigned int i=0; i<matches.size() && i<5; i++)
|
||||||
match_output += " " + matches[i] + "?\n";
|
match_output += "\n " + matches[i] + "?";
|
||||||
|
|
||||||
/*TODO. Embed these suggestions IN the error message
|
|
||||||
itself. Currently it looks ugly since line breaks
|
|
||||||
are ignored inside Error() strings. Multiple
|
|
||||||
Error() messages are not an option either */
|
|
||||||
printf("%s", match_output.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Label wasn't found. Emit an error */
|
||||||
|
Error(identifierPos,
|
||||||
|
"No label named \"%s\" found in current function.%s",
|
||||||
|
label.c_str(), match_output.c_str());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
18
util.cpp
18
util.cpp
@@ -237,6 +237,20 @@ lPrintWithWordBreaks(const char *buf, int indent, int columnWidth, FILE *out) {
|
|||||||
} while (*msgPos != '\0' && *msgPos != 'm');
|
} while (*msgPos != '\0' && *msgPos != 'm');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
else if (*msgPos == '\n') {
|
||||||
|
// Handle newlines cleanly
|
||||||
|
column = indent;
|
||||||
|
outStr.push_back('\n');
|
||||||
|
for (int i = 0; i < indent; ++i)
|
||||||
|
outStr.push_back(' ');
|
||||||
|
// Respect spaces after newlines
|
||||||
|
++msgPos;
|
||||||
|
while (*msgPos == ' ') {
|
||||||
|
outStr.push_back(' ');
|
||||||
|
++msgPos;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
while (*msgPos != '\0' && isspace(*msgPos))
|
while (*msgPos != '\0' && isspace(*msgPos))
|
||||||
++msgPos;
|
++msgPos;
|
||||||
@@ -314,7 +328,7 @@ lPrint(const char *type, bool isError, SourcePos p, const char *fmt,
|
|||||||
int indent = 0;
|
int indent = 0;
|
||||||
if (p.first_line == 0) {
|
if (p.first_line == 0) {
|
||||||
// We don't have a valid SourcePos, so create a message without it
|
// We don't have a valid SourcePos, so create a message without it
|
||||||
if (asprintf(&formattedBuf, "%s%s%s%s%s: %s%s\n", lStartBold(),
|
if (asprintf(&formattedBuf, "%s%s%s%s%s: %s%s", lStartBold(),
|
||||||
isError ? lStartRed() : lStartBlue(), type,
|
isError ? lStartRed() : lStartBlue(), type,
|
||||||
lResetColor(), lStartBold(), errorBuf,
|
lResetColor(), lStartBold(), errorBuf,
|
||||||
lResetColor()) == -1) {
|
lResetColor()) == -1) {
|
||||||
@@ -325,7 +339,7 @@ lPrint(const char *type, bool isError, SourcePos p, const char *fmt,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Create an error message that includes the file and line number
|
// Create an error message that includes the file and line number
|
||||||
if (asprintf(&formattedBuf, "%s%s:%d:%d: %s%s%s%s: %s%s\n",
|
if (asprintf(&formattedBuf, "%s%s:%d:%d: %s%s%s%s: %s%s",
|
||||||
lStartBold(), p.name, p.first_line, p.first_column,
|
lStartBold(), p.name, p.first_line, p.first_column,
|
||||||
isError ? lStartRed() : lStartBlue(), type,
|
isError ? lStartRed() : lStartBlue(), type,
|
||||||
lResetColor(), lStartBold(), errorBuf,
|
lResetColor(), lStartBold(), errorBuf,
|
||||||
|
|||||||
Reference in New Issue
Block a user