Commit 08a82a9c authored by Igor Kushnir's avatar Igor Kushnir
Browse files

Replace bitwise operators with Q_DECLARE_OPERATORS_FOR_FLAGS

Use default QFlags constructor instead of the deprecated constructor
that takes nullptr.

Remove static_cast<int> inside QCOMPARE in
TestDUChain::testReparseOnDocumentActivated(), because Qt Test prints
QFlags as integer Actual and Expected values.

GIT_SILENT
parent 8552fe7c
Pipeline #38171 failed with stage
in 61 minutes and 6 seconds
......@@ -156,7 +156,7 @@ struct DocumentParsePlan
TopDUContext::Features features() const
{
//Pick the best features
auto ret = ( TopDUContext::Features )0;
TopDUContext::Features ret{};
for (const DocumentParseTarget& target : targets) {
ret |= target.features;
}
......
......@@ -204,7 +204,7 @@ bool ParseJob::hasStaticMinimumFeatures()
TopDUContext::Features ParseJob::staticMinimumFeatures(const IndexedString& url)
{
QMutexLocker lock(&minimumFeaturesMutex);
auto features = ( TopDUContext::Features )0;
TopDUContext::Features features{};
const auto featuresIt = ::staticMinimumFeatures.constFind(url);
if (featuresIt != ::staticMinimumFeatures.constEnd())
......
......@@ -274,7 +274,7 @@ bool ParsingEnvironmentFile::featuresMatch(TopDUContext::Features minimumFeature
const auto imports = this->imports();
for (const ParsingEnvironmentFilePointer& import : imports) {
if (!import->featuresMatch(minimumFeatures &
TopDUContext::Recursive ? minimumFeatures : (( TopDUContext::Features )0),
TopDUContext::Recursive ? minimumFeatures : TopDUContext::Features{},
checked))
return false;
}
......
......@@ -187,8 +187,7 @@ public:
Identity = 4
};
using FeaturesUnderlyingType = quint16;
enum Features : FeaturesUnderlyingType {
enum Feature : quint16 {
///Top-context features standard that can be requested from the duchain, and that are stored in the features() member.
Empty = 0, //Only the top-context structure (imports etc.) is built, but no declarations and no contexts
SimplifiedVisibleDeclarationsAndContexts = 2, //The top-context should only contain publically simplified accessible declarations and contexts, without doing type look-up,
......@@ -208,13 +207,7 @@ public:
///You can define own language-dependent features behind this flag
LastFeature = 512
};
friend Features operator~(Features f) { return static_cast<Features>(~static_cast<FeaturesUnderlyingType>(f)); }
friend Features operator|(Features a, Features b) { return static_cast<Features>(static_cast<FeaturesUnderlyingType>(a)
| static_cast<FeaturesUnderlyingType>(b)); }
friend Features operator&(Features a, Features b) { return static_cast<Features>(static_cast<FeaturesUnderlyingType>(a)
& static_cast<FeaturesUnderlyingType>(b)); }
friend Features& operator|=(Features& a, Features b) { return a = a | b; }
friend Features& operator&=(Features& a, Features b) { return a = a & b; }
Q_DECLARE_FLAGS(Features, Feature)
///Returns the currently active features of this top-context. The features will include AST if ast() is valid.
Features features() const;
......@@ -398,8 +391,17 @@ inline uint qHash(const ReferencedTopDUContext& ctx)
{
return ctx.hash();
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
Q_DECLARE_OPERATORS_FOR_FLAGS(TopDUContext::Features)
#endif
}
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
Q_DECLARE_OPERATORS_FOR_FLAGS(KDevelop::TopDUContext::Features)
#endif
Q_DECLARE_TYPEINFO(KDevelop::ReferencedTopDUContext, Q_MOVABLE_TYPE);
Q_DECLARE_METATYPE(KDevelop::ReferencedTopDUContext)
......
......@@ -1080,8 +1080,8 @@ void TestDUChain::testReparseOnDocumentActivated()
{
DUChainReadLocker lock;
auto ctx = file.topContext();
QCOMPARE(static_cast<int>(ctx->features() & TopDUContext::AllDeclarationsContextsAndUses),
static_cast<int>(TopDUContext::AllDeclarationsContextsAndUses));
QCOMPARE(ctx->features() & TopDUContext::AllDeclarationsContextsAndUses,
TopDUContext::AllDeclarationsContextsAndUses);
QVERIFY(ctx->topContext()->ast());
}
}
......
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