[Libreoffice-commits] core.git: compilerplugins/clang
Noel Grandin
noel.grandin at collabora.co.uk
Mon Sep 12 06:24:16 UTC 2016
compilerplugins/clang/defaultparams.cxx | 19 ++++++++++++++++---
compilerplugins/clang/overrideparam.cxx | 16 ++++++++++++++--
compilerplugins/clang/singlevalfields.cxx | 3 +++
3 files changed, 33 insertions(+), 5 deletions(-)
New commits:
commit 25e4e9694ce12152693e9d272557e5d546becd40
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Mon Sep 12 08:20:17 2016 +0200
handle nullptr in various clang plugins
since we are using it so widely now, instead of NULL
Change-Id: I990ff1334f657663e8791ab064d69e56636fe6e7
diff --git a/compilerplugins/clang/defaultparams.cxx b/compilerplugins/clang/defaultparams.cxx
index de03087..7755b37 100644
--- a/compilerplugins/clang/defaultparams.cxx
+++ b/compilerplugins/clang/defaultparams.cxx
@@ -26,6 +26,8 @@ public:
virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
bool VisitCallExpr(CallExpr * callExpr);
+private:
+ bool evaluate(const Expr* expr, APSInt& x);
};
bool DefaultParams::VisitCallExpr(CallExpr * callExpr) {
@@ -69,9 +71,7 @@ bool DefaultParams::VisitCallExpr(CallExpr * callExpr) {
if (!found)
{
APSInt x1, x2;
- if (defaultArgExpr->EvaluateAsInt(x1, compiler.getASTContext())
- && arg->EvaluateAsInt(x2, compiler.getASTContext())
- && x1 == x2)
+ if (evaluate(defaultArgExpr, x1) && evaluate(arg, x2) && x1 == x2)
{
found = true;
}
@@ -108,6 +108,19 @@ bool DefaultParams::VisitCallExpr(CallExpr * callExpr) {
return true;
}
+bool DefaultParams::evaluate(const Expr* expr, APSInt& x)
+{
+ if (isa<CXXNullPtrLiteralExpr>(expr)) {
+ x = 0;
+ return true;
+ }
+ if (expr->EvaluateAsInt(x, compiler.getASTContext()))
+ {
+ return true;
+ }
+ return false;
+}
+
loplugin::Plugin::Registration< DefaultParams > X("defaultparams");
}
diff --git a/compilerplugins/clang/overrideparam.cxx b/compilerplugins/clang/overrideparam.cxx
index aca1e95..c9d836c 100644
--- a/compilerplugins/clang/overrideparam.cxx
+++ b/compilerplugins/clang/overrideparam.cxx
@@ -37,6 +37,7 @@ public:
private:
bool hasSameDefaultParams(const ParmVarDecl * parmVarDecl, const ParmVarDecl * superParmVarDecl);
+ bool evaluate(const Expr* expr, APSInt& x);
};
void OverrideParam::run()
@@ -155,8 +156,7 @@ bool OverrideParam::hasSameDefaultParams(const ParmVarDecl * parmVarDecl, const
return true;
}
APSInt x1, x2;
- if (defaultArgExpr->EvaluateAsInt(x1, compiler.getASTContext())
- && superDefaultArgExpr->EvaluateAsInt(x2, compiler.getASTContext()))
+ if (evaluate(defaultArgExpr, x1) && evaluate(superDefaultArgExpr, x2))
{
return x1 == x2;
}
@@ -186,6 +186,18 @@ bool OverrideParam::hasSameDefaultParams(const ParmVarDecl * parmVarDecl, const
#endif
}
+bool OverrideParam::evaluate(const Expr* expr, APSInt& x)
+{
+ if (expr->EvaluateAsInt(x, compiler.getASTContext()))
+ {
+ return true;
+ }
+ if (isa<CXXNullPtrLiteralExpr>(expr)) {
+ x = 0;
+ return true;
+ }
+ return false;
+}
loplugin::Plugin::Registration< OverrideParam > X("overrideparam");
diff --git a/compilerplugins/clang/singlevalfields.cxx b/compilerplugins/clang/singlevalfields.cxx
index 699daaa..aa3aa31 100644
--- a/compilerplugins/clang/singlevalfields.cxx
+++ b/compilerplugins/clang/singlevalfields.cxx
@@ -474,6 +474,9 @@ std::string SingleValFields::getExprValue(const Expr* arg)
{
return x1.toString(10);
}
+ if (isa<CXXNullPtrLiteralExpr>(arg)) {
+ return "0";
+ }
return "?";
}
More information about the Libreoffice-commits
mailing list