diff options
Diffstat (limited to 'compilerplugins/clang/flatten.cxx')
-rw-r--r-- | compilerplugins/clang/flatten.cxx | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/compilerplugins/clang/flatten.cxx b/compilerplugins/clang/flatten.cxx index a615b8366b63..a3d57812d924 100644 --- a/compilerplugins/clang/flatten.cxx +++ b/compilerplugins/clang/flatten.cxx @@ -7,6 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "compat.hxx" #include "plugin.hxx" #include <cassert> #include <string> @@ -48,7 +49,8 @@ private: SourceRange ignoreMacroExpansions(SourceRange range); SourceRange extendOverComments(SourceRange range); std::string getSourceAsString(SourceRange range); - llvm::Optional<std::string> invertCondition(Expr const * condExpr, SourceRange conditionRange); + compat::optional<std::string> invertCondition( + Expr const * condExpr, SourceRange conditionRange); bool isLargeCompoundStmt(Stmt const *); Stmt const * lastStmtInCompoundStmt = nullptr; @@ -204,7 +206,7 @@ bool Flatten::VisitIfStmt(IfStmt const * ifStmt) report( DiagnosticsEngine::Warning, "large if statement at end of function, rather invert the condition and exit early, and flatten the function", - compat::getBeginLoc(ifStmt)) + ifStmt->getBeginLoc()) << ifStmt->getSourceRange(); } return true; @@ -238,12 +240,12 @@ bool Flatten::VisitIfStmt(IfStmt const * ifStmt) report( DiagnosticsEngine::Warning, "unconditional throw in else branch, rather invert the condition, throw early, and flatten the normal case", - compat::getBeginLoc(elseThrowExpr)) + elseThrowExpr->getBeginLoc()) << elseThrowExpr->getSourceRange(); report( DiagnosticsEngine::Note, "if condition here", - compat::getBeginLoc(ifStmt)) + ifStmt->getBeginLoc()) << ifStmt->getSourceRange(); } } @@ -260,7 +262,7 @@ bool Flatten::VisitIfStmt(IfStmt const * ifStmt) report( DiagnosticsEngine::Warning, "unconditional throw in then branch, just flatten the else", - compat::getBeginLoc(thenThrowExpr)) + thenThrowExpr->getBeginLoc()) << thenThrowExpr->getSourceRange(); } } @@ -301,7 +303,7 @@ bool Flatten::rewrite1(IfStmt const * ifStmt) // in adjusting the formatting I assume that "{" starts on a new line - llvm::Optional<std::string> conditionString = invertCondition(ifStmt->getCond(), conditionRange); + compat::optional<std::string> conditionString = invertCondition(ifStmt->getCond(), conditionRange); if (!conditionString) return false; @@ -391,7 +393,7 @@ bool Flatten::rewriteLargeIf(IfStmt const * ifStmt) // in adjusting the formatting I assume that "{" starts on a new line - llvm::Optional<std::string> conditionString = invertCondition(ifStmt->getCond(), conditionRange); + compat::optional<std::string> conditionString = invertCondition(ifStmt->getCond(), conditionRange); if (!conditionString) return false; @@ -415,7 +417,7 @@ bool Flatten::rewriteLargeIf(IfStmt const * ifStmt) return true; } -llvm::Optional<std::string> Flatten::invertCondition(Expr const * condExpr, SourceRange conditionRange) +compat::optional<std::string> Flatten::invertCondition(Expr const * condExpr, SourceRange conditionRange) { std::string s = getSourceAsString(conditionRange); @@ -454,7 +456,7 @@ llvm::Optional<std::string> Flatten::invertCondition(Expr const * condExpr, Sour s = "!(" + s + ")"; } if (!ok) - return llvm::Optional<std::string>(); + return compat::optional<std::string>(); } else if (auto opCallExpr = dyn_cast<CXXOperatorCallExpr>(condExpr)) { @@ -471,7 +473,7 @@ llvm::Optional<std::string> Flatten::invertCondition(Expr const * condExpr, Sour s = "!(" + s + ")"; } if (!ok) - return llvm::Optional<std::string>(); + return compat::optional<std::string>(); } else if (isa<DeclRefExpr>(condExpr) || isa<CallExpr>(condExpr) || isa<MemberExpr>(condExpr)) s = "!" + s; |