Commit c37764d8 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau

Merge branch '5.5'

parents a5cf36fe 2720f349
......@@ -238,8 +238,11 @@ ReferencedTopDUContext ParseJob::duChain() const
bool ParseJob::abortRequested() const
{
Q_D(const ParseJob);
return d->abortRequested.load();
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
return d->abortRequested.loadRelaxed() != 0;
#else
return d->abortRequested.load() != 0;
#endif
}
void ParseJob::requestAbort()
......
......@@ -916,7 +916,11 @@ unloadContexts:
it != m_fileEnvironmentInformations.end();) {
ParsingEnvironmentFile* f = it->data();
Q_ASSERT(f->d_func()->classId);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
if (f->ref.loadRelaxed() == 1) {
#else
if (f->ref.load() == 1) {
#endif
Q_ASSERT(!f->d_func()->isDynamic()); //It cannot be dynamic, since we have stored before
//The ParsingEnvironmentFilePointer is only referenced once. This means that it does not belong to any
//loaded top-context, so just remove it to save some memory and processing time.
......
......@@ -127,7 +127,11 @@ bool DUChainLock::lockForWrite(uint timeout)
Q_ASSERT(d->ownReaderRecursion() == 0);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
if (d->m_writer.loadRelaxed() == QThread::currentThread()) {
#else
if (d->m_writer.load() == QThread::currentThread()) {
#endif
//We already hold the write lock, just increase the recursion count and return
d->m_writerRecursion.fetchAndAddRelaxed(1);
return true;
......@@ -140,10 +144,19 @@ bool DUChainLock::lockForWrite(uint timeout)
while (1) {
//Try acquiring the write-lcok
if (d->m_totalReaderRecursion.load() == 0 && d->m_writerRecursion.testAndSetOrdered(0, 1)) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
if (d->m_totalReaderRecursion.loadRelaxed() == 0 &&
#else
if (d->m_totalReaderRecursion.load() == 0 &&
#endif
d->m_writerRecursion.testAndSetOrdered(0, 1)) {
//Now we can be sure that there is no other writer, as we have increased m_writerRecursion from 0 to 1
d->m_writer = QThread::currentThread();
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
if (d->m_totalReaderRecursion.loadRelaxed() == 0) {
#else
if (d->m_totalReaderRecursion.load() == 0) {
#endif
//There is still no readers, we have successfully acquired a write-lock
return true;
} else {
......@@ -173,7 +186,11 @@ void DUChainLock::releaseWriteLock()
//The order is important here, m_writerRecursion protects m_writer
//TODO: could testAndSet here
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
if (d->m_writerRecursion.loadRelaxed() == 1) {
#else
if (d->m_writerRecursion.load() == 1) {
#endif
d->m_writer = nullptr;
d->m_writerRecursion = 0;
} else {
......@@ -185,7 +202,11 @@ bool DUChainLock::currentThreadHasWriteLock() const
{
Q_D(const DUChainLock);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
return d->m_writer.loadRelaxed() == QThread::currentThread();
#else
return d->m_writer.load() == QThread::currentThread();
#endif
}
DUChainReadLocker::DUChainReadLocker(DUChainLock* duChainLock, uint timeout)
......
......@@ -98,17 +98,39 @@ T formatComment_impl(const T& comment)
QList<T> lines = comment.split('\n');
// remove common leading chars from the beginning of lines
// remove common leading & trailing chars from the lines
for (T &l : lines) {
// don't trigger repeated temporary allocations here
static const T tripleSlash("///");
static const T doubleSlash("//");
static const T doubleStar("**");
static const T slashDoubleStar("/**");
strip_impl(tripleSlash, l);
strip_impl(doubleSlash, l);
strip_impl(doubleStar, l);
rStrip_impl(slashDoubleStar, l);
// possible comment starts, sorted from longest to shortest
static const T startMatches[] = {
"//!<", "/*!<", "/**<", "///<",
"///", "//!", "/**", "/*!",
"//", "/*",
"/", "*"
};
// possible comment ends, sorted from longest to shortest
static const T endMatches[] = {
"**/", "*/"
};
l = l.trimmed();
// check for ends first, as the starting pattern "*" might interfere with the ending pattern
for (T const & m : endMatches) {
if (l.endsWith(m)) {
l.chop(m.length());
break;
}
}
for (T const & m : startMatches) {
if (l.startsWith(m)) {
l.remove(0, m.length());
break;
}
}
}
// TODO add method with QStringList specialisation
......
......@@ -34,11 +34,42 @@ void TestDUChain::testFormatComment_data()
QTest::addColumn<QByteArray>("input");
QTest::addColumn<QByteArray>("output");
QTest::newRow("cpp-style") << QByteArrayLiteral("// foo\n// bar") << QByteArrayLiteral("foo\n bar");
QTest::newRow("doxy-cpp-style") << QByteArrayLiteral("/// foo\n/// bar") << QByteArrayLiteral("foo\n bar");
QTest::newRow("c-style") << QByteArrayLiteral("/*\n foo\n bar\n*/") << QByteArrayLiteral("foo\n bar");
QTest::newRow("doxy-c-style") << QByteArrayLiteral("/**\n * foo\n * bar\n */") << QByteArrayLiteral("foo\n bar");
QTest::newRow("doxy-c-style2") << QByteArrayLiteral("/**\n * foo\n * bar\n **/") << QByteArrayLiteral("foo\n bar");
QTest::newRow("cpp-style") << QByteArrayLiteral(
"// foo\n"
"// bar"
) << QByteArrayLiteral("foo\n bar");
QTest::newRow("doxy-cpp-style") << QByteArrayLiteral(
"/// foo\n"
"/// bar"
) << QByteArrayLiteral("foo\n bar");
QTest::newRow("doxy-cpp-excl-style") << QByteArrayLiteral(
"//! foo\n"
"//! bar"
) << QByteArrayLiteral("foo\n bar");
QTest::newRow("doxy-cpp-singleline-style") << QByteArrayLiteral("///< foo") << QByteArrayLiteral("foo");
QTest::newRow("doxy-cpp-excl-singleline-style") << QByteArrayLiteral("//!< foo") << QByteArrayLiteral("foo");
QTest::newRow("c-style") << QByteArrayLiteral(
"/*\n"
" foo\n"
" bar\n*/"
) << QByteArrayLiteral("foo\nbar");
QTest::newRow("doxy-c-style") << QByteArrayLiteral(
"/**\n"
" * foo\n"
" * bar\n */"
) << QByteArrayLiteral("foo\n bar");
QTest::newRow("doxy-c-style2") << QByteArrayLiteral(
"/**\n"
" * foo\n"
" * bar\n **/"
) << QByteArrayLiteral("foo\n bar");
QTest::newRow("real multiline") << QByteArrayLiteral(
"/**\n"
" * This is a real comment of some imaginary code.\n"
......@@ -48,6 +79,40 @@ void TestDUChain::testFormatComment_data()
" */\n"
)
<< QByteArrayLiteral("This is a real comment of some imaginary code.\n\n @param foo bar\n @return meh");
QTest::newRow("doxy-qt-style-after-member") << QByteArrayLiteral(
"/*!< line1\n"
"line2 */"
) << QByteArrayLiteral("line1\nline2");
QTest::newRow("doxy-c-style-after-member") << QByteArrayLiteral(
"/**< line1\n"
"line2 */"
) << QByteArrayLiteral("line1\nline2");
QTest::newRow("doxy-cpp-style-after-member") << QByteArrayLiteral(
"//!< line1\n"
"//!< line2"
) << QByteArrayLiteral("line1\n line2");
QTest::newRow("doxy-cpp-style-after-member2") << QByteArrayLiteral(
"/// line1\n"
"/// < line2"
) << QByteArrayLiteral("line1\n < line2");
QTest::newRow("doxy-qt-style-before-member") << QByteArrayLiteral(
"/*! line1\n"
"line2 */"
) << QByteArrayLiteral("line1\nline2");
QTest::newRow("doxy-qt-style-before-member2") << QByteArrayLiteral(
"/*! line1\n"
" * *line2* */"
) << QByteArrayLiteral("line1\n *line2*");
QTest::newRow("doxy-cpp-style-before-member") << QByteArrayLiteral(
"//! line1\n"
"//! line2"
) << QByteArrayLiteral("line1\n line2");
}
void TestDUChain::testFormatComment()
......
......@@ -52,10 +52,17 @@ struct FakeAtomic
return true; //Always return true, because we handle the deleting by ourself
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
inline int loadRelaxed() const
{
return m_real.ref.loadRelaxed();
}
#else
inline int load() const
{
return m_real.ref.load();
}
#endif
QObject& m_object;
QSharedData& m_real;
......
......@@ -153,11 +153,8 @@ void TestDUChain::testComments_data()
#define PARSE_COMMENTS 0
QTest::newRow("enumerator")
<< "enum Foo { bar1, ///<this is bar1\nbar2 ///<this is bar2\n };"
#if PARSE_COMMENTS
<< ExpectedComment{"Foo::bar1", "this is bar1"};
#else
<< ExpectedComment{"Foo::bar1", "<this is bar1"};
#endif
QTest::newRow("comment-formatting")
<< "/** a\n * multiline\n *\n * comment\n */ int foo;"
#if PARSE_COMMENTS
......
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