diff options
author | Brad King <brad.king@kitware.com> | 2018-07-16 17:04:06 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-07-16 17:04:06 (GMT) |
commit | dd5c54600b6f651898925bfd9ec4406ccfc7be95 (patch) | |
tree | e8cc6f03cabef23ef1897cae611edd017b6b7ce2 | |
parent | 185bcface43d95b062c5be16321ae9aa59ed0057 (diff) | |
download | CMake-dd5c54600b6f651898925bfd9ec4406ccfc7be95.zip CMake-dd5c54600b6f651898925bfd9ec4406ccfc7be95.tar.gz CMake-dd5c54600b6f651898925bfd9ec4406ccfc7be95.tar.bz2 |
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.
-rw-r--r-- | Source/cmExprParserHelper.cxx | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/Source/cmExprParserHelper.cxx b/Source/cmExprParserHelper.cxx index 1f38d33..821667b 100644 --- a/Source/cmExprParserHelper.cxx +++ b/Source/cmExprParserHelper.cxx @@ -39,10 +39,9 @@ int cmExprParserHelper::ParseString(const char* str, int verb) yyscan_t yyscanner; cmExpr_yylex_init(&yyscanner); cmExpr_yyset_extra(this, yyscanner); - int res; try { - res = cmExpr_yyparse(yyscanner); + int res = cmExpr_yyparse(yyscanner); if (res != 0) { std::string e = "cannot parse the expression: \"" + InputBuffer + "\": "; e += ErrorString; @@ -55,19 +54,16 @@ int cmExprParserHelper::ParseString(const char* str, int verb) e += fail.what(); e += "."; this->SetError(std::move(e)); - res = 1; } catch (std::out_of_range const&) { std::string e = "cannot evaluate the expression: \"" + InputBuffer + "\": a numeric value is out of range."; this->SetError(std::move(e)); - res = 1; } catch (...) { std::string e = "cannot parse the expression: \"" + InputBuffer + "\"."; this->SetError(std::move(e)); - res = 1; } cmExpr_yylex_destroy(yyscanner); - if (res != 0) { + if (!this->ErrorString.empty()) { return 0; } |