Kaydet (Commit) 75dd5d2e authored tarafından Noel Grandin's avatar Noel Grandin

add EvaluateAsInt compat function for latest clang

the old EvaluateAsInt method has been dropped as from current clang

Change-Id: Ie30d1547ad8de777badff4b380d2fc9fb261e8fe
Reviewed-on: https://gerrit.libreoffice.org/64107
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst ecdf05d1
...@@ -156,6 +156,18 @@ inline bool CPlusPlus17(clang::LangOptions const & opts) { ...@@ -156,6 +156,18 @@ inline bool CPlusPlus17(clang::LangOptions const & opts) {
#endif #endif
} }
inline bool EvaluateAsInt(clang::Expr const * expr, llvm::APSInt& intRes, const clang::ASTContext& ctx) {
#if CLANG_VERSION >= 80000
clang::Expr::EvalResult res;
bool b = expr->EvaluateAsInt(res, ctx);
if (b && res.Val.isInt())
intRes = res.Val.getInt();
return b;
#else
return expr->EvaluateAsInt(intRes, ctx);
#endif
}
// Work around <http://reviews.llvm.org/D22128>: // Work around <http://reviews.llvm.org/D22128>:
// //
// SfxErrorHandler::GetClassString (svtools/source/misc/ehdl.cxx): // SfxErrorHandler::GetClassString (svtools/source/misc/ehdl.cxx):
......
...@@ -170,7 +170,7 @@ std::string ConstantParam::getCallValue(const Expr* arg) ...@@ -170,7 +170,7 @@ std::string ConstantParam::getCallValue(const Expr* arg)
return "unknown1"; return "unknown1";
} }
APSInt x1; APSInt x1;
if (arg->EvaluateAsInt(x1, compiler.getASTContext())) if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
{ {
return x1.toString(10); return x1.toString(10);
} }
......
...@@ -139,7 +139,7 @@ std::unique_ptr<APSInt> ExpressionAlwaysZero::getExprValue(Expr const * expr) ...@@ -139,7 +139,7 @@ std::unique_ptr<APSInt> ExpressionAlwaysZero::getExprValue(Expr const * expr)
return std::unique_ptr<APSInt>(); return std::unique_ptr<APSInt>();
} }
APSInt x1; APSInt x1;
if (expr->EvaluateAsInt(x1, compiler.getASTContext())) if (compat::EvaluateAsInt(expr, x1, compiler.getASTContext()))
return std::unique_ptr<APSInt>(new APSInt(x1)); return std::unique_ptr<APSInt>(new APSInt(x1));
return std::unique_ptr<APSInt>(); return std::unique_ptr<APSInt>();
} }
......
...@@ -160,7 +160,7 @@ void LoopVarTooSmall::checkSubExpr(Expr const * expr, bool positive) { ...@@ -160,7 +160,7 @@ void LoopVarTooSmall::checkSubExpr(Expr const * expr, bool positive) {
// //
// with dependent type T: // with dependent type T:
if (!binOpRHS->isValueDependent() if (!binOpRHS->isValueDependent()
&& binOpRHS->EvaluateAsInt(aIntResult, compiler.getASTContext())) && compat::EvaluateAsInt(binOpRHS, aIntResult, compiler.getASTContext()))
{ {
if (less && aIntResult.isStrictlyPositive()) { if (less && aIntResult.isStrictlyPositive()) {
--aIntResult; --aIntResult;
......
...@@ -161,7 +161,7 @@ void Plugin::registerPlugin( Plugin* (*create)( const InstantiationData& ), cons ...@@ -161,7 +161,7 @@ void Plugin::registerPlugin( Plugin* (*create)( const InstantiationData& ), cons
bool Plugin::evaluate(const Expr* expr, APSInt& x) bool Plugin::evaluate(const Expr* expr, APSInt& x)
{ {
if (expr->EvaluateAsInt(x, compiler.getASTContext())) if (compat::EvaluateAsInt(expr, x, compiler.getASTContext()))
{ {
return true; return true;
} }
......
...@@ -110,7 +110,7 @@ llvm::Optional<APSInt> PointerBool::getCallValue(const Expr* arg) ...@@ -110,7 +110,7 @@ llvm::Optional<APSInt> PointerBool::getCallValue(const Expr* arg)
return llvm::Optional<APSInt>(); return llvm::Optional<APSInt>();
} }
APSInt x1; APSInt x1;
if (arg->EvaluateAsInt(x1, compiler.getASTContext())) if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
{ {
return x1; return x1;
} }
......
...@@ -186,7 +186,7 @@ std::string ReturnConstant::getExprValue(Expr const* arg) ...@@ -186,7 +186,7 @@ std::string ReturnConstant::getExprValue(Expr const* arg)
return "unknown"; return "unknown";
} }
APSInt x1; APSInt x1;
if (arg->EvaluateAsInt(x1, compiler.getASTContext())) if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
{ {
return x1.toString(10); return x1.toString(10);
} }
......
...@@ -235,7 +235,7 @@ bool ShouldReturnBool::isExprOneOrZero(const Expr* arg) const ...@@ -235,7 +235,7 @@ bool ShouldReturnBool::isExprOneOrZero(const Expr* arg) const
return false; return false;
} }
APSInt x1; APSInt x1;
if (arg->EvaluateAsInt(x1, compiler.getASTContext())) if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
{ {
return x1 == 1 || x1 == 0; return x1 == 1 || x1 == 0;
} }
......
...@@ -461,7 +461,7 @@ std::string SingleValFields::getExprValue(const Expr* arg) ...@@ -461,7 +461,7 @@ std::string SingleValFields::getExprValue(const Expr* arg)
} }
} }
APSInt x1; APSInt x1;
if (arg->EvaluateAsInt(x1, compiler.getASTContext())) if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
return x1.toString(10); return x1.toString(10);
if (isa<CXXNullPtrLiteralExpr>(arg)) if (isa<CXXNullPtrLiteralExpr>(arg))
return "0"; return "0";
......
...@@ -130,7 +130,7 @@ bool StaticConstField::TraverseConstructorInitializer(CXXCtorInitializer* init) ...@@ -130,7 +130,7 @@ bool StaticConstField::TraverseConstructorInitializer(CXXCtorInitializer* init)
else else
{ {
APSInt x1; APSInt x1;
if (initexpr->EvaluateAsInt(x1, compiler.getASTContext())) if (compat::EvaluateAsInt(initexpr, x1, compiler.getASTContext()))
{ {
value = x1.toString(10); value = x1.toString(10);
found = true; found = true;
......
...@@ -848,7 +848,7 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) { ...@@ -848,7 +848,7 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) {
return true; return true;
} }
APSInt res; APSInt res;
if (!expr->getArg(1)->EvaluateAsInt( if (!compat::EvaluateAsInt(expr->getArg(1),
res, compiler.getASTContext())) res, compiler.getASTContext()))
{ {
return true; return true;
...@@ -863,14 +863,14 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) { ...@@ -863,14 +863,14 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) {
return true; return true;
} }
APSInt enc; APSInt enc;
if (!expr->getArg(2)->EvaluateAsInt( if (!compat::EvaluateAsInt(expr->getArg(2),
enc, compiler.getASTContext())) enc, compiler.getASTContext()))
{ {
return true; return true;
} }
auto const encIsAscii = enc == 11; // RTL_TEXTENCODING_ASCII_US auto const encIsAscii = enc == 11; // RTL_TEXTENCODING_ASCII_US
auto const encIsUtf8 = enc == 76; // RTL_TEXTENCODING_UTF8 auto const encIsUtf8 = enc == 76; // RTL_TEXTENCODING_UTF8
if (!expr->getArg(3)->EvaluateAsInt( if (!compat::EvaluateAsInt(expr->getArg(3),
res, compiler.getASTContext()) res, compiler.getASTContext())
|| res != 0x333) // OSTRING_TO_OUSTRING_CVTFLAGS || res != 0x333) // OSTRING_TO_OUSTRING_CVTFLAGS
{ {
...@@ -1438,7 +1438,7 @@ bool StringConstant::isStringConstant( ...@@ -1438,7 +1438,7 @@ bool StringConstant::isStringConstant(
bool StringConstant::isZero(Expr const * expr) { bool StringConstant::isZero(Expr const * expr) {
APSInt res; APSInt res;
return expr->EvaluateAsInt(res, compiler.getASTContext()) && res == 0; return compat::EvaluateAsInt(expr, res, compiler.getASTContext()) && res == 0;
} }
void StringConstant::reportChange( void StringConstant::reportChange(
...@@ -1729,7 +1729,7 @@ void StringConstant::handleCharLen( ...@@ -1729,7 +1729,7 @@ void StringConstant::handleCharLen(
return; return;
} }
APSInt res; APSInt res;
if (expr->getArg(arg2)->EvaluateAsInt(res, compiler.getASTContext())) { if (compat::EvaluateAsInt(expr->getArg(arg2), res, compiler.getASTContext())) {
if (res != n) { if (res != n) {
return; return;
} }
...@@ -1754,7 +1754,7 @@ void StringConstant::handleCharLen( ...@@ -1754,7 +1754,7 @@ void StringConstant::handleCharLen(
&cont2, &emb2, &trm2) &cont2, &emb2, &trm2)
&& n2 == n && cont2 == cont && emb2 == emb && trm2 == trm && n2 == n && cont2 == cont && emb2 == emb && trm2 == trm
//TODO: same strings //TODO: same strings
&& subs->getIdx()->EvaluateAsInt(res, compiler.getASTContext()) && compat::EvaluateAsInt(subs->getIdx(), res, compiler.getASTContext())
&& res == 0)) && res == 0))
{ {
return; return;
...@@ -1981,7 +1981,7 @@ void StringConstant::handleFunArgOstring( ...@@ -1981,7 +1981,7 @@ void StringConstant::handleFunArgOstring(
&cont, &emb, &trm)) &cont, &emb, &trm))
{ {
APSInt res; APSInt res;
if (cexpr->getArg(1)->EvaluateAsInt( if (compat::EvaluateAsInt(cexpr->getArg(1),
res, compiler.getASTContext())) res, compiler.getASTContext()))
{ {
if (res == n && !emb && trm) { if (res == n && !emb && trm) {
......
...@@ -58,7 +58,7 @@ public: ...@@ -58,7 +58,7 @@ public:
return true; return true;
} }
APSInt res; APSInt res;
if (expr->getSubExpr()->EvaluateAsInt(res, compiler.getASTContext()) if (compat::EvaluateAsInt(expr->getSubExpr(), res, compiler.getASTContext())
&& res >= 0 && res <= 0x7F) && res >= 0 && res <= 0x7F)
{ {
return true; return true;
......
...@@ -301,7 +301,7 @@ bool UnusedFields::isSomeKindOfZero(const Expr* arg) ...@@ -301,7 +301,7 @@ bool UnusedFields::isSomeKindOfZero(const Expr* arg)
return cxxConstructExpr->getConstructor()->isDefaultConstructor(); return cxxConstructExpr->getConstructor()->isDefaultConstructor();
} }
APSInt x1; APSInt x1;
if (arg->EvaluateAsInt(x1, compiler.getASTContext())) if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
{ {
return x1 == 0; return x1 == 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment