mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-12 17:19:05 -05:00
cmExprParserHelper: Simplify error state tracking
Errors always have explanation strings, so use the presence of such a string to track whether an error has occurred. This avoids an extra variable.
This commit is contained in:
@@ -39,10 +39,9 @@ int cmExprParserHelper::ParseString(const char* str, int verb)
|
|||||||
yyscan_t yyscanner;
|
yyscan_t yyscanner;
|
||||||
cmExpr_yylex_init(&yyscanner);
|
cmExpr_yylex_init(&yyscanner);
|
||||||
cmExpr_yyset_extra(this, yyscanner);
|
cmExpr_yyset_extra(this, yyscanner);
|
||||||
int res;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
res = cmExpr_yyparse(yyscanner);
|
int res = cmExpr_yyparse(yyscanner);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
std::string e = "cannot parse the expression: \"" + InputBuffer + "\": ";
|
std::string e = "cannot parse the expression: \"" + InputBuffer + "\": ";
|
||||||
e += ErrorString;
|
e += ErrorString;
|
||||||
@@ -55,19 +54,16 @@ int cmExprParserHelper::ParseString(const char* str, int verb)
|
|||||||
e += fail.what();
|
e += fail.what();
|
||||||
e += ".";
|
e += ".";
|
||||||
this->SetError(std::move(e));
|
this->SetError(std::move(e));
|
||||||
res = 1;
|
|
||||||
} catch (std::out_of_range const&) {
|
} catch (std::out_of_range const&) {
|
||||||
std::string e = "cannot evaluate the expression: \"" + InputBuffer +
|
std::string e = "cannot evaluate the expression: \"" + InputBuffer +
|
||||||
"\": a numeric value is out of range.";
|
"\": a numeric value is out of range.";
|
||||||
this->SetError(std::move(e));
|
this->SetError(std::move(e));
|
||||||
res = 1;
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
std::string e = "cannot parse the expression: \"" + InputBuffer + "\".";
|
std::string e = "cannot parse the expression: \"" + InputBuffer + "\".";
|
||||||
this->SetError(std::move(e));
|
this->SetError(std::move(e));
|
||||||
res = 1;
|
|
||||||
}
|
}
|
||||||
cmExpr_yylex_destroy(yyscanner);
|
cmExpr_yylex_destroy(yyscanner);
|
||||||
if (res != 0) {
|
if (!this->ErrorString.empty()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user