Commit 8552fe7c authored by Igor Kushnir's avatar Igor Kushnir
Browse files

Overload bitwise operators for TopDUContext::Features

Less casting leads to more readable code.

static_cast<int> inside QCOMPARE in
TestDUChain::testReparseOnDocumentActivated() to make Qt Test print
Actual and Expected values.

GIT_SILENT
parent b6dab981
......@@ -158,7 +158,7 @@ struct DocumentParsePlan
//Pick the best features
auto ret = ( TopDUContext::Features )0;
for (const DocumentParseTarget& target : targets) {
ret = ( TopDUContext::Features ) (ret | target.features);
ret |= target.features;
}
return ret;
......
......@@ -209,7 +209,7 @@ TopDUContext::Features ParseJob::staticMinimumFeatures(const IndexedString& url)
const auto featuresIt = ::staticMinimumFeatures.constFind(url);
if (featuresIt != ::staticMinimumFeatures.constEnd())
for (const TopDUContext::Features f : *featuresIt)
features = ( TopDUContext::Features )(features | f);
features |= f;
return features;
}
......@@ -218,7 +218,7 @@ TopDUContext::Features ParseJob::minimumFeatures() const
{
Q_D(const ParseJob);
return ( TopDUContext::Features )(d->features | staticMinimumFeatures(d->url));
return d->features | staticMinimumFeatures(d->url);
}
void ParseJob::setDuChain(const ReferencedTopDUContext& duChain)
......
......@@ -146,8 +146,8 @@ void ParseProjectJob::queueFilesToParse()
if (processingLevel & TopDUContext::VisibleDeclarationsAndContexts) {
processingLevel = TopDUContext::AllDeclarationsContextsAndUses;
}
processingLevel = ( TopDUContext::Features )(TopDUContext::ForceUpdate | processingLevel);
openDocumentProcessingLevel = TopDUContext::Features(TopDUContext::ForceUpdate | openDocumentProcessingLevel);
processingLevel |= TopDUContext::ForceUpdate;
openDocumentProcessingLevel |= TopDUContext::ForceUpdate;
}
if (auto currentDocument = ICore::self()->documentController()->activeDocument()) {
......
......@@ -234,11 +234,11 @@ struct InsertIntoDUChain
* @param features The features that should be requested for the top-context
* @param update Whether the top-context should be updated if it already exists. Else it will be deleted.
*/
void parse(uint features = TopDUContext::AllDeclarationsContextsAndUses, bool update = false)
void parse(TopDUContext::Features features = TopDUContext::AllDeclarationsContextsAndUses, bool update = false)
{
if (!update)
release();
m_topContext = DUChain::self()->waitForUpdate(m_insertedCode.file(), ( TopDUContext::Features )features, false);
m_topContext = DUChain::self()->waitForUpdate(m_insertedCode.file(), features, false);
Q_ASSERT(m_topContext);
DUChainReadLocker lock;
Q_ASSERT(!m_topContext->parsingEnvironmentFile()->isProxyContext());
......
......@@ -1659,13 +1659,8 @@ void DUChain::documentLoadedPrepare(KDevelop::IDocument* doc)
if (needsUpdate || !(standardContext->features() & TopDUContext::AllDeclarationsContextsAndUses)) {
ICore::self()->languageController()->backgroundParser()->addDocument(IndexedString(doc->url()),
( TopDUContext::Features )(TopDUContext
::
AllDeclarationsContextsAndUses
|
TopDUContext
::
ForceUpdate));
TopDUContext::AllDeclarationsContextsAndUses
| TopDUContext::ForceUpdate);
return;
}
}
......@@ -1686,10 +1681,8 @@ void DUChain::documentRenamed(KDevelop::IDocument* doc)
qCWarning(LANGUAGE) << "Strange, url of renamed document is invalid!";
} else {
ICore::self()->languageController()->backgroundParser()->addDocument(IndexedString(doc->url()),
( TopDUContext::Features )(TopDUContext::
AllDeclarationsContextsAndUses
| TopDUContext::
ForceUpdate));
TopDUContext::AllDeclarationsContextsAndUses
| TopDUContext::ForceUpdate);
}
}
......
......@@ -260,12 +260,10 @@ bool ParsingEnvironmentFile::featuresMatch(TopDUContext::Features minimumFeature
checked.insert(this);
TopDUContext::Features localRequired =
( TopDUContext::Features ) (minimumFeatures | ParseJob::staticMinimumFeatures(url()));
auto localRequired = minimumFeatures | ParseJob::staticMinimumFeatures(url());
//Check other 'local' requirements
localRequired =
( TopDUContext::Features )(localRequired & (TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST));
localRequired &= (TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST);
if (!satisfied(features(), localRequired))
return false;
......
......@@ -604,19 +604,19 @@ void TopDUContext::deleteSelf()
TopDUContext::Features TopDUContext::features() const
{
uint ret = d_func()->m_features;
auto ret = d_func()->m_features;
if (ast())
ret |= TopDUContext::AST;
return ( TopDUContext::Features )ret;
return ret;
}
void TopDUContext::setFeatures(Features features)
{
features = ( TopDUContext::Features )(features & (~Recursive)); //Remove the "Recursive" flag since that's only for searching
features = ( TopDUContext::Features )(features & (~ForceUpdateRecursive)); //Remove the update flags
features = ( TopDUContext::Features )(features & (~AST)); //Remove the AST flag, it's only used while updating
features &= ~Recursive; //Remove the "Recursive" flag since that's only for searching
features &= ~ForceUpdateRecursive; //Remove the update flags
features &= ~AST; //Remove the AST flag, it's only used while updating
d_func_dynamic()->m_features = features;
//Replicate features to ParsingEnvironmentFile
......
......@@ -187,7 +187,8 @@ public:
Identity = 4
};
enum Features : quint16 {
using FeaturesUnderlyingType = quint16;
enum Features : FeaturesUnderlyingType {
///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,
......@@ -207,6 +208,13 @@ 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; }
///Returns the currently active features of this top-context. The features will include AST if ast() is valid.
Features features() const;
......
......@@ -326,7 +326,7 @@ QWidget *TextDocument::createViewWidget(QWidget *parent)
connect(d->document.data(), &KTextEditor::Document::reloaded,
this, [] (KTextEditor::Document* document) {
ICore::self()->languageController()->backgroundParser()->addDocument(IndexedString(document->url()),
(TopDUContext::Features) ( TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::ForceUpdate ),
TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::ForceUpdate,
BackgroundParser::BestPriority, nullptr);
});
......
......@@ -88,7 +88,7 @@ void Manager::init()
QCoreApplication::exit(1);
}
uint features = TopDUContext::VisibleDeclarationsAndContexts;
TopDUContext::Features features = TopDUContext::VisibleDeclarationsAndContexts;
if (m_args->isSet(QStringLiteral("features"))) {
QString featuresStr = m_args->value(QStringLiteral("features"));
if (featuresStr == QLatin1String("visible-declarations")) {
......@@ -139,7 +139,7 @@ void Manager::init()
const auto files = m_args->positionalArguments();
for (const auto& file : files) {
addToBackgroundParser(file, ( TopDUContext::Features )features);
addToBackgroundParser(file, features);
}
m_allFilesAdded = 1;
......
......@@ -262,7 +262,7 @@ void ClangParseJob::run(ThreadWeaver::JobPointer /*self*/, ThreadWeaver::Thread*
// it is very hard to check this for all included files of this TU, and previously lead to problems
// when we tried to skip function bodies as an optimization for files that where not open in the editor.
// now, we always build everything, which is correct but a tad bit slower. we can try to optimize later.
setMinimumFeatures(static_cast<TopDUContext::Features>(minimumFeatures() | TopDUContext::AllDeclarationsContextsAndUses));
setMinimumFeatures(minimumFeatures() | TopDUContext::AllDeclarationsContextsAndUses);
if (minimumFeatures() & AttachASTWithoutUpdating) {
// The context doesn't need to be updated, but has no AST attached (restored from disk),
......@@ -352,7 +352,7 @@ void ClangParseJob::run(ThreadWeaver::JobPointer /*self*/, ThreadWeaver::Thread*
auto file = parsingEnvironmentFile(context);
Q_ASSERT(file);
// verify that features and environment where properly set in ClangHelpers::buildDUChain
Q_ASSERT(file->featuresSatisfied(TopDUContext::Features(minimumFeatures() & ~TopDUContext::ForceUpdateRecursive)));
Q_ASSERT(file->featuresSatisfied(minimumFeatures() & ~TopDUContext::ForceUpdateRecursive));
if (trackerForUrl(context->url())) {
Q_ASSERT(file->featuresSatisfied(TopDUContext::AllDeclarationsContextsAndUses));
}
......
......@@ -398,7 +398,7 @@ void TestDUChain::testReparse()
file.setFileContents(QStringLiteral("int main()\n{\nfloat i = 13; return i - 5;\n}\n"));
}
file.parse(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::ForceUpdateRecursive));
file.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::ForceUpdateRecursive);
}
}
......@@ -418,7 +418,7 @@ void TestDUChain::testReparseError()
QCOMPARE(file.topContext()->problems().size(), 0);
}
file.parse(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::ForceUpdateRecursive));
file.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::ForceUpdateRecursive);
}
}
......@@ -628,7 +628,7 @@ void TestDUChain::testReparseBaseClasses()
QVERIFY(bDecl->isPublicBaseClass(aDecl, file.topContext(), &distance));
QCOMPARE(distance, 1);
file.parse(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::ForceUpdateRecursive));
file.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::ForceUpdateRecursive);
}
}
......@@ -657,7 +657,7 @@ void TestDUChain::testReparseBaseClassesTemplates()
QVERIFY(bDecl->isPublicBaseClass(aDecl, file.topContext(), &distance));
QCOMPARE(distance, 1);
file.parse(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::ForceUpdateRecursive));
file.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::ForceUpdateRecursive);
}
}
......@@ -776,7 +776,7 @@ void TestDUChain::testParsingEnvironment()
ClangParsingEnvironment lastEnv;
{
TestFile file(QStringLiteral("int main() {}\n"), QStringLiteral("cpp"));
auto astFeatures = static_cast<TopDUContext::Features>(features | TopDUContext::AST);
const auto astFeatures = features | TopDUContext::AST;
file.parse(astFeatures);
file.setKeepDUChainData(true);
QVERIFY(file.waitForParsed());
......@@ -875,7 +875,7 @@ void TestDUChain::testActiveDocumentHasASTAttached()
ClangParsingEnvironment lastEnv;
{
TestFile file(QStringLiteral("int main() {}\n"), QStringLiteral("cpp"));
auto astFeatures = static_cast<TopDUContext::Features>(features | TopDUContext::AST);
const auto astFeatures = features | TopDUContext::AST;
file.parse(astFeatures);
file.setKeepDUChainData(true);
QVERIFY(file.waitForParsed());
......@@ -1080,7 +1080,8 @@ void TestDUChain::testReparseOnDocumentActivated()
{
DUChainReadLocker lock;
auto ctx = file.topContext();
QCOMPARE(ctx->features() & TopDUContext::AllDeclarationsContextsAndUses, static_cast<int>(TopDUContext::AllDeclarationsContextsAndUses));
QCOMPARE(static_cast<int>(ctx->features() & TopDUContext::AllDeclarationsContextsAndUses),
static_cast<int>(TopDUContext::AllDeclarationsContextsAndUses));
QVERIFY(ctx->topContext()->ast());
}
}
......@@ -1092,7 +1093,7 @@ void TestDUChain::testReparseInclude()
"int main() { return foo(); }", QStringLiteral("cpp"), &header);
// Use TopDUContext::AST to imitate that document is opened in the editor, so that ClangParseJob can store translation unit, that'll be used for reparsing.
impl.parse(TopDUContext::Features(TopDUContext::AllDeclarationsAndContexts|TopDUContext::AST));
impl.parse(TopDUContext::AllDeclarationsAndContexts | TopDUContext::AST);
QVERIFY(impl.waitForParsed(5000));
{
DUChainReadLocker lock;
......@@ -1101,7 +1102,7 @@ void TestDUChain::testReparseInclude()
QCOMPARE(implCtx->importedParentContexts().size(), 1);
}
impl.parse(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses|TopDUContext::AST));
impl.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST);
QVERIFY(impl.waitForParsed(5000));
DUChainReadLocker lock;
......@@ -1139,7 +1140,7 @@ void TestDUChain::testReparseChangeEnvironment()
uint hashes[3] = {0, 0, 0};
for (int i = 0; i < 3; ++i) {
impl.parse(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses|TopDUContext::AST|TopDUContext::ForceUpdate));
impl.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST | TopDUContext::ForceUpdate);
QVERIFY(impl.waitForParsed(5000));
{
......@@ -1192,7 +1193,7 @@ void TestDUChain::testMacroDependentHeader()
"int bqm = bq.m;\n"
, QStringLiteral("cpp"), &header);
impl.parse(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses|TopDUContext::AST|TopDUContext::ForceUpdate));
impl.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST | TopDUContext::ForceUpdate);
QVERIFY(impl.waitForParsed(500000));
DUChainReadLocker lock;
......@@ -1246,7 +1247,7 @@ void TestDUChain::testHeaderParsingOrder1()
"#include \"" + header.url().str() + "\"\n"
"B c;", QStringLiteral("cpp"), &header);
impl.parse(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses|TopDUContext::AST|TopDUContext::ForceUpdate));
impl.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST | TopDUContext::ForceUpdate);
QVERIFY(impl.waitForParsed(500000));
DUChainReadLocker lock;
......@@ -1286,7 +1287,7 @@ void TestDUChain::testHeaderParsingOrder2()
"#include \"" + header2.url().str() + "\"\n"
"B c;", QStringLiteral("cpp"), &header);
impl.parse(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses|TopDUContext::AST|TopDUContext::ForceUpdate));
impl.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST | TopDUContext::ForceUpdate);
QVERIFY(impl.waitForParsed(500000));
DUChainReadLocker lock;
......@@ -1441,7 +1442,7 @@ void TestDUChain::testEnvironmentWithDifferentOrderOfElements()
uint previousHash = 0;
for (int i: {0, 1, 2, 3}) {
file.parse(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses|TopDUContext::AST|TopDUContext::ForceUpdate));
file.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST | TopDUContext::ForceUpdate);
QVERIFY(file.waitForParsed(5000));
......@@ -1487,7 +1488,7 @@ void TestDUChain::testEnvironmentWithDifferentOrderOfElements()
void TestDUChain::testReparseMacro()
{
TestFile file(QStringLiteral("#define DECLARE(a) typedef struct a##_ {} *a;\nDECLARE(D);\nD d;"), QStringLiteral("cpp"));
file.parse(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses|TopDUContext::AST));
file.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST);
QVERIFY(file.waitForParsed(5000));
{
......@@ -1495,7 +1496,7 @@ void TestDUChain::testReparseMacro()
QVERIFY(file.topContext());
}
file.parse(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses|TopDUContext::AST|TopDUContext::ForceUpdate));
file.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST | TopDUContext::ForceUpdate);
QVERIFY(file.waitForParsed(5000));
DUChainReadLocker lock;
......@@ -1602,13 +1603,13 @@ void TestDUChain::testReparseIncludeGuard()
TestFile header(QStringLiteral("#ifndef GUARD\n#define GUARD\nint something;\n#endif\n"), QStringLiteral("h"));
TestFile impl("#include \"" + header.url().str() + "\"\n", QStringLiteral("cpp"), &header);
QVERIFY(impl.parseAndWait(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST )));
QVERIFY(impl.parseAndWait(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST));
{
DUChainReadLocker lock;
QCOMPARE(static_cast<TopDUContext*>(impl.topContext()->
importedParentContexts().first().context(impl.topContext()))->problems().size(), 0);
}
QVERIFY(impl.parseAndWait(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::ForceUpdateRecursive)));
QVERIFY(impl.parseAndWait(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::ForceUpdateRecursive));
{
DUChainReadLocker lock;
QCOMPARE(static_cast<TopDUContext*>(impl.topContext()->
......@@ -1623,7 +1624,7 @@ void TestDUChain::testIncludeGuardHeaderHeaderOnly()
// test that we do NOT get a warning for single standalone header file with include guards
TestFile header(code, QStringLiteral("h"));
QVERIFY(header.parseAndWait(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST)));
QVERIFY(header.parseAndWait(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST));
{
DUChainReadLocker lock;
QCOMPARE(header.topContext()->problems().size(), 0);
......@@ -1653,7 +1654,7 @@ void TestDUChain::testIncludeGuardHeaderWarning()
TestFile header(QStringLiteral("int something;\n"), QStringLiteral("h"));
TestFile impl("#include \"" + header.url().str() + "\"\n", QStringLiteral("cpp"));
QVERIFY(impl.parseAndWait(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST | TopDUContext::ForceUpdate)));
QVERIFY(impl.parseAndWait(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST | TopDUContext::ForceUpdate));
{
DUChainReadLocker lock;
QVERIFY(impl.topContext());
......@@ -1769,10 +1770,10 @@ void TestDUChain::testReparseUnchanged()
QVERIFY(implCtx->problems().isEmpty());
};
impl.parseAndWait(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST ));
impl.parseAndWait(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST);
checkProblems(false);
impl.parseAndWait(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::ForceUpdateRecursive));
impl.parseAndWait(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::ForceUpdateRecursive);
checkProblems(true);
}
......@@ -1803,7 +1804,7 @@ void TestDUChain::testDeclarationsInsideMacroExpansion()
TestFile header(QStringLiteral("#define DECLARE(a) typedef struct a##__ {int var;} *a\nDECLARE(D);\n"), QStringLiteral("h"));
TestFile file("#include \"" + header.url().str() + "\"\nint main(){\nD d; d->var;}\n", QStringLiteral("cpp"));
file.parse(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses|TopDUContext::AST));
file.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST);
QVERIFY(file.waitForParsed(5000));
{
......@@ -1811,7 +1812,7 @@ void TestDUChain::testDeclarationsInsideMacroExpansion()
QVERIFY(file.topContext());
}
file.parse(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses|TopDUContext::AST|TopDUContext::ForceUpdate));
file.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST | TopDUContext::ForceUpdate);
QVERIFY(file.waitForParsed(5000));
DUChainReadLocker lock;
......
......@@ -426,7 +426,7 @@ void TestProblems::testProblemsForIncludedFiles()
TestFile header(QStringLiteral("#pragma once\n//TODO: header\n"), QStringLiteral("h"));
TestFile file("#include \"" + header.url().str() + "\"\n//TODO: source\n", QStringLiteral("cpp"));
file.parse(TopDUContext::Features(TopDUContext::AllDeclarationsContextsAndUses|TopDUContext::AST | TopDUContext::ForceUpdate));
file.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST | TopDUContext::ForceUpdate);
QVERIFY(file.waitForParsed(5000));
{
......
......@@ -108,8 +108,7 @@ void ProblemReporterModel::forceFullUpdate()
if (documents.size() == 1)
updateType = TopDUContext::ForceUpdateRecursive;
DUChain::self()->updateContextForUrl(
document,
(TopDUContext::Features)(updateType | TopDUContext::VisibleDeclarationsAndContexts));
document, updateType | TopDUContext::VisibleDeclarationsAndContexts);
}
}
......
......@@ -270,8 +270,7 @@ void ParseSession::reparseImporters()
void ParseSession::scheduleForParsing(const IndexedString& url, int priority)
{
BackgroundParser* bgparser = KDevelop::ICore::self()->languageController()->backgroundParser();
auto features = (TopDUContext::Features)
(TopDUContext::ForceUpdate | TopDUContext::AllDeclarationsContextsAndUses);
const auto features = TopDUContext::ForceUpdate | TopDUContext::AllDeclarationsContextsAndUses;
if (bgparser->isQueued(url)) {
bgparser->removeDocument(url);
......
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