aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSergio Martins <smartins@kde.org>2017-10-12 19:24:33 +0100
committerSergio Martins <iamsergio@gmail.com>2017-10-12 19:24:33 +0100
commit1b4c1c6dfc0a301c03804ddb43342e9f3b87e670 (patch)
tree1188e085ed8a7ddbcd02a6e1c188b37f087abb04 /src
parent9e802c0b7c245e86c58f5af72902027c2a87b3a9 (diff)
Reduce some duplicated code
Diffstat (limited to 'src')
-rw-r--r--src/QtUtils.cpp4
-rw-r--r--src/TypeUtils.h6
2 files changed, 8 insertions, 2 deletions
diff --git a/src/QtUtils.cpp b/src/QtUtils.cpp
index b26d4af1..e44ad176 100644
--- a/src/QtUtils.cpp
+++ b/src/QtUtils.cpp
@@ -151,9 +151,9 @@ bool QtUtils::isConvertibleTo(const Type *source, const Type *target)
return true;
// "QString" can convert to "const QString &" and vice versa
- if (source->isReferenceType() && source->getPointeeType().isConstQualified() && source->getPointeeType().getTypePtrOrNull() == target)
+ if (TypeUtils::isConstRef(source) && source->getPointeeType().getTypePtrOrNull() == target)
return true;
- if (target->isReferenceType() && target->getPointeeType().isConstQualified() && target->getPointeeType().getTypePtrOrNull() == source)
+ if (TypeUtils::isConstRef(target) && target->getPointeeType().getTypePtrOrNull() == source)
return true;
return false;
diff --git a/src/TypeUtils.h b/src/TypeUtils.h
index 9c77bf9b..ea62b431 100644
--- a/src/TypeUtils.h
+++ b/src/TypeUtils.h
@@ -205,6 +205,12 @@ namespace TypeUtils
return nullptr;
}
+
+ // Example: const QString &
+ inline bool isConstRef(const clang::Type *t)
+ {
+ return t && t->isReferenceType() && t->getPointeeType().isConstQualified();
+ }
}
#endif