Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Thomas Schöps
kdevelop
Commits
13a05772
Commit
13a05772
authored
Jun 26, 2019
by
Friedrich W. H. Kossebau
Browse files
kdevplatform/language/backgroundparser: use Q_DECLARE_PRIVATE/Q_D to forward constness to d
parent
cc6c1bac
Changes
6
Hide whitespace changes
Inline
Side-by-side
kdevplatform/language/backgroundparser/backgroundparser.cpp
View file @
13a05772
...
...
@@ -191,7 +191,7 @@ public:
,
m_shuttingDown
(
false
)
,
m_mutex
(
QMutex
::
Recursive
)
{
parser
->
d
=
this
;
//Set this so we can safely call back BackgroundParser from within loadSettings()
parser
->
d
_ptr
=
this
;
//Set this so we can safely call back BackgroundParser from within loadSettings()
m_timer
.
setSingleShot
(
true
);
m_progressTimer
.
setSingleShot
(
true
);
...
...
@@ -497,10 +497,10 @@ public:
ThreadWeaver
::
Queue
m_weaver
;
// generic high-level mutex
QMutex
m_mutex
;
mutable
QMutex
m_mutex
;
// local mutex only protecting m_managed
QMutex
m_managedMutex
;
mutable
QMutex
m_managedMutex
;
// A change tracker for each managed document
QHash
<
IndexedString
,
DocumentChangeTracker
*>
m_managed
;
...
...
@@ -516,7 +516,7 @@ public:
BackgroundParser
::
BackgroundParser
(
ILanguageController
*
languageController
)
:
QObject
(
languageController
)
,
d
(
new
BackgroundParserPrivate
(
this
,
languageController
))
,
d
_ptr
(
new
BackgroundParserPrivate
(
this
,
languageController
))
{
Q_ASSERT
(
ICore
::
self
()
->
documentController
());
connect
(
...
...
@@ -543,12 +543,14 @@ BackgroundParser::BackgroundParser(ILanguageController* languageController)
void
BackgroundParser
::
aboutToQuit
()
{
Q_D
(
BackgroundParser
);
d
->
m_shuttingDown
=
true
;
}
BackgroundParser
::~
BackgroundParser
()
{
delete
d
;
delete
d
_ptr
;
}
QString
BackgroundParser
::
statusName
()
const
...
...
@@ -558,18 +560,25 @@ QString BackgroundParser::statusName() const
void
BackgroundParser
::
loadSettings
()
{
Q_D
(
BackgroundParser
);
d
->
loadSettings
();
}
void
BackgroundParser
::
parseProgress
(
KDevelop
::
ParseJob
*
job
,
float
value
,
const
QString
&
text
)
{
Q_UNUSED
(
text
)
Q_D
(
BackgroundParser
);
d
->
m_jobProgress
[
job
]
=
value
;
updateProgressData
();
}
void
BackgroundParser
::
revertAllRequests
(
QObject
*
notifyWhenReady
)
{
Q_D
(
BackgroundParser
);
QMutexLocker
lock
(
&
d
->
m_mutex
);
for
(
auto
it
=
d
->
m_documents
.
begin
();
it
!=
d
->
m_documents
.
end
();)
{
d
->
m_documentsForPriority
[
it
.
value
().
priority
()].
remove
(
it
.
key
());
...
...
@@ -596,6 +605,8 @@ void BackgroundParser::revertAllRequests(QObject* notifyWhenReady)
void
BackgroundParser
::
addDocument
(
const
IndexedString
&
url
,
TopDUContext
::
Features
features
,
int
priority
,
QObject
*
notifyWhenReady
,
ParseJob
::
SequentialProcessingFlags
flags
,
int
delay
)
{
Q_D
(
BackgroundParser
);
qCDebug
(
LANGUAGE
)
<<
"BackgroundParser::addDocument"
<<
url
<<
url
.
toUrl
();
Q_ASSERT
(
isValidURL
(
url
));
QMutexLocker
lock
(
&
d
->
m_mutex
);
...
...
@@ -630,6 +641,8 @@ void BackgroundParser::addDocument(const IndexedString& url, TopDUContext::Featu
void
BackgroundParser
::
removeDocument
(
const
IndexedString
&
url
,
QObject
*
notifyWhenReady
)
{
Q_D
(
BackgroundParser
);
Q_ASSERT
(
isValidURL
(
url
));
QMutexLocker
lock
(
&
d
->
m_mutex
);
...
...
@@ -658,6 +671,8 @@ void BackgroundParser::removeDocument(const IndexedString& url, QObject* notifyW
void
BackgroundParser
::
parseDocuments
()
{
Q_D
(
BackgroundParser
);
if
(
d
->
isSuspended
()
||
!
d
->
m_loadingProjects
.
empty
())
{
startTimer
(
d
->
m_delay
);
return
;
...
...
@@ -669,6 +684,8 @@ void BackgroundParser::parseDocuments()
void
BackgroundParser
::
parseComplete
(
const
ThreadWeaver
::
JobPointer
&
job
)
{
Q_D
(
BackgroundParser
);
auto
decorator
=
dynamic_cast
<
ThreadWeaver
::
QObjectDecorator
*>
(
job
.
data
());
Q_ASSERT
(
decorator
);
auto
*
parseJob
=
dynamic_cast
<
ParseJob
*>
(
decorator
->
job
());
...
...
@@ -702,6 +719,8 @@ void BackgroundParser::enableProcessing()
int
BackgroundParser
::
priorityForDocument
(
const
IndexedString
&
url
)
const
{
Q_D
(
const
BackgroundParser
);
Q_ASSERT
(
isValidURL
(
url
));
QMutexLocker
lock
(
&
d
->
m_mutex
);
return
d
->
m_documents
[
url
].
priority
();
...
...
@@ -709,6 +728,8 @@ int BackgroundParser::priorityForDocument(const IndexedString& url) const
bool
BackgroundParser
::
isQueued
(
const
IndexedString
&
url
)
const
{
Q_D
(
const
BackgroundParser
);
Q_ASSERT
(
isValidURL
(
url
));
QMutexLocker
lock
(
&
d
->
m_mutex
);
return
d
->
m_documents
.
contains
(
url
);
...
...
@@ -716,18 +737,24 @@ bool BackgroundParser::isQueued(const IndexedString& url) const
int
BackgroundParser
::
queuedCount
()
const
{
Q_D
(
const
BackgroundParser
);
QMutexLocker
lock
(
&
d
->
m_mutex
);
return
d
->
m_documents
.
count
();
}
bool
BackgroundParser
::
isIdle
()
const
{
Q_D
(
const
BackgroundParser
);
QMutexLocker
lock
(
&
d
->
m_mutex
);
return
d
->
m_documents
.
isEmpty
()
&&
d
->
m_weaver
.
isIdle
();
}
void
BackgroundParser
::
setNeededPriority
(
int
priority
)
{
Q_D
(
BackgroundParser
);
QMutexLocker
lock
(
&
d
->
m_mutex
);
d
->
m_neededPriority
=
priority
;
d
->
startTimerThreadSafe
(
d
->
m_delay
);
...
...
@@ -735,6 +762,8 @@ void BackgroundParser::setNeededPriority(int priority)
void
BackgroundParser
::
abortAllJobs
()
{
Q_D
(
BackgroundParser
);
qCDebug
(
LANGUAGE
)
<<
"Aborting all parse jobs"
;
d
->
m_weaver
.
requestAbort
();
...
...
@@ -742,6 +771,8 @@ void BackgroundParser::abortAllJobs()
void
BackgroundParser
::
suspend
()
{
Q_D
(
BackgroundParser
);
d
->
suspend
();
emit
hideProgress
(
this
);
...
...
@@ -749,12 +780,16 @@ void BackgroundParser::suspend()
void
BackgroundParser
::
resume
()
{
Q_D
(
BackgroundParser
);
d
->
resume
();
updateProgressData
();
}
void
BackgroundParser
::
updateProgressData
()
{
Q_D
(
BackgroundParser
);
if
(
d
->
m_doneParseJobs
>=
d
->
m_maxParseJobs
)
{
if
(
d
->
m_doneParseJobs
>
d
->
m_maxParseJobs
)
{
qCDebug
(
LANGUAGE
)
<<
"m_doneParseJobs larger than m_maxParseJobs:"
<<
d
->
m_doneParseJobs
<<
...
...
@@ -788,6 +823,8 @@ void BackgroundParser::updateProgressData()
ParseJob
*
BackgroundParser
::
parseJobForDocument
(
const
IndexedString
&
document
)
const
{
Q_D
(
const
BackgroundParser
);
Q_ASSERT
(
isValidURL
(
document
));
QMutexLocker
lock
(
&
d
->
m_mutex
);
...
...
@@ -797,6 +834,8 @@ ParseJob* BackgroundParser::parseJobForDocument(const IndexedString& document) c
void
BackgroundParser
::
setThreadCount
(
int
threadCount
)
{
Q_D
(
BackgroundParser
);
if
(
d
->
m_threads
!=
threadCount
)
{
d
->
m_threads
=
threadCount
;
d
->
m_weaver
.
setMaximumNumberOfThreads
(
d
->
m_threads
+
1
);
//1 Additional thread for high-priority parsing
...
...
@@ -805,11 +844,15 @@ void BackgroundParser::setThreadCount(int threadCount)
int
BackgroundParser
::
threadCount
()
const
{
Q_D
(
const
BackgroundParser
);
return
d
->
m_threads
;
}
void
BackgroundParser
::
setDelay
(
int
milliseconds
)
{
Q_D
(
BackgroundParser
);
if
(
d
->
m_delay
!=
milliseconds
)
{
d
->
m_delay
=
milliseconds
;
d
->
m_timer
.
setInterval
(
d
->
m_delay
);
...
...
@@ -818,12 +861,16 @@ void BackgroundParser::setDelay(int milliseconds)
QList
<
IndexedString
>
BackgroundParser
::
managedDocuments
()
{
Q_D
(
BackgroundParser
);
QMutexLocker
l
(
&
d
->
m_managedMutex
);
return
d
->
m_managed
.
keys
();
}
bool
BackgroundParser
::
waitForIdle
()
const
{
Q_D
(
const
BackgroundParser
);
QList
<
IndexedString
>
runningParseJobsUrls
;
forever
{
{
...
...
@@ -849,6 +896,8 @@ bool BackgroundParser::waitForIdle() const
DocumentChangeTracker
*
BackgroundParser
::
trackerForUrl
(
const
KDevelop
::
IndexedString
&
url
)
const
{
Q_D
(
const
BackgroundParser
);
if
(
url
.
isEmpty
())
{
// this happens e.g. when setting the final location of a problem that is not
// yet associated with a top ctx.
...
...
@@ -865,6 +914,8 @@ DocumentChangeTracker* BackgroundParser::trackerForUrl(const KDevelop::IndexedSt
void
BackgroundParser
::
documentClosed
(
IDocument
*
document
)
{
Q_D
(
BackgroundParser
);
QMutexLocker
l
(
&
d
->
m_mutex
);
if
(
document
->
textDocument
())
{
...
...
@@ -891,6 +942,8 @@ void BackgroundParser::documentClosed(IDocument* document)
void
BackgroundParser
::
documentLoaded
(
IDocument
*
document
)
{
Q_D
(
BackgroundParser
);
QMutexLocker
l
(
&
d
->
m_mutex
);
if
(
document
->
textDocument
()
&&
document
->
textDocument
()
->
url
().
isValid
())
{
KTextEditor
::
Document
*
textDocument
=
document
->
textDocument
();
...
...
@@ -928,6 +981,8 @@ void BackgroundParser::documentUrlChanged(IDocument* document)
void
BackgroundParser
::
startTimer
(
int
delay
)
{
Q_D
(
BackgroundParser
);
if
(
!
d
->
isSuspended
())
{
d
->
m_timer
.
start
(
delay
);
}
...
...
@@ -935,20 +990,28 @@ void BackgroundParser::startTimer(int delay)
void
BackgroundParser
::
projectAboutToBeOpened
(
IProject
*
project
)
{
Q_D
(
BackgroundParser
);
d
->
m_loadingProjects
.
insert
(
project
);
}
void
BackgroundParser
::
projectOpened
(
IProject
*
project
)
{
Q_D
(
BackgroundParser
);
d
->
m_loadingProjects
.
remove
(
project
);
}
void
BackgroundParser
::
projectOpeningAborted
(
IProject
*
project
)
{
Q_D
(
BackgroundParser
);
d
->
m_loadingProjects
.
remove
(
project
);
}
void
BackgroundParser
::
updateProgressBar
()
{
Q_D
(
BackgroundParser
);
emit
showProgress
(
this
,
0
,
d
->
m_progressMax
,
d
->
m_progressDone
);
}
kdevplatform/language/backgroundparser/backgroundparser.h
View file @
13a05772
...
...
@@ -231,7 +231,8 @@ protected Q_SLOTS:
private:
friend
class
BackgroundParserPrivate
;
class
BackgroundParserPrivate
*
d
;
class
BackgroundParserPrivate
*
d_ptr
;
Q_DECLARE_PRIVATE
(
BackgroundParser
)
private
Q_SLOTS
:
/// Tracking of projects in state of loading.
...
...
kdevplatform/language/backgroundparser/parsejob.cpp
View file @
13a05772
...
...
@@ -101,12 +101,14 @@ public:
ParseJob
::
ParseJob
(
const
IndexedString
&
url
,
KDevelop
::
ILanguageSupport
*
languageSupport
)
:
ThreadWeaver
::
Sequence
()
,
d
(
new
ParseJobPrivate
(
url
,
languageSupport
))
,
d
_ptr
(
new
ParseJobPrivate
(
url
,
languageSupport
))
{
}
ParseJob
::~
ParseJob
()
{
Q_D
(
ParseJob
);
for
(
auto
&
p
:
qAsConst
(
d
->
notify
))
{
if
(
p
)
{
QMetaObject
::
invokeMethod
(
p
.
data
(),
"updateReady"
,
Qt
::
QueuedConnection
,
...
...
@@ -118,56 +120,78 @@ ParseJob::~ParseJob()
ILanguageSupport
*
ParseJob
::
languageSupport
()
const
{
Q_D
(
const
ParseJob
);
return
d
->
languageSupport
;
}
void
ParseJob
::
setParsePriority
(
int
priority
)
{
Q_D
(
ParseJob
);
d
->
parsePriority
=
priority
;
}
int
ParseJob
::
parsePriority
()
const
{
Q_D
(
const
ParseJob
);
return
d
->
parsePriority
;
}
bool
ParseJob
::
requiresSequentialProcessing
()
const
{
Q_D
(
const
ParseJob
);
return
d
->
sequentialProcessingFlags
&
RequiresSequentialProcessing
;
}
bool
ParseJob
::
respectsSequentialProcessing
()
const
{
Q_D
(
const
ParseJob
);
return
d
->
sequentialProcessingFlags
&
RespectsSequentialProcessing
;
}
void
ParseJob
::
setSequentialProcessingFlags
(
SequentialProcessingFlags
flags
)
{
Q_D
(
ParseJob
);
d
->
sequentialProcessingFlags
=
flags
;
}
qint64
ParseJob
::
maximumFileSize
()
const
{
Q_D
(
const
ParseJob
);
return
d
->
maximumFileSize
;
}
void
ParseJob
::
setMaximumFileSize
(
qint64
value
)
{
Q_D
(
ParseJob
);
d
->
maximumFileSize
=
value
;
}
IndexedString
ParseJob
::
document
()
const
{
Q_D
(
const
ParseJob
);
return
d
->
url
;
}
bool
ParseJob
::
success
()
const
{
Q_D
(
const
ParseJob
);
return
!
d
->
aborted
;
}
void
ParseJob
::
setMinimumFeatures
(
TopDUContext
::
Features
features
)
{
Q_D
(
ParseJob
);
d
->
features
=
features
;
}
...
...
@@ -192,37 +216,51 @@ TopDUContext::Features ParseJob::staticMinimumFeatures(const IndexedString& url)
TopDUContext
::
Features
ParseJob
::
minimumFeatures
()
const
{
Q_D
(
const
ParseJob
);
return
(
TopDUContext
::
Features
)(
d
->
features
|
staticMinimumFeatures
(
d
->
url
));
}
void
ParseJob
::
setDuChain
(
const
ReferencedTopDUContext
&
duChain
)
{
Q_D
(
ParseJob
);
d
->
duContext
=
duChain
;
}
ReferencedTopDUContext
ParseJob
::
duChain
()
const
{
Q_D
(
const
ParseJob
);
return
d
->
duContext
;
}
bool
ParseJob
::
abortRequested
()
const
{
Q_D
(
const
ParseJob
);
return
d
->
abortRequested
.
load
();
}
void
ParseJob
::
requestAbort
()
{
Q_D
(
ParseJob
);
d
->
abortRequested
=
1
;
}
void
ParseJob
::
abortJob
()
{
Q_D
(
ParseJob
);
d
->
aborted
=
true
;
setStatus
(
Status_Aborted
);
}
void
ParseJob
::
setNotifyWhenReady
(
const
QVector
<
QPointer
<
QObject
>>&
notify
)
{
Q_D
(
ParseJob
);
d
->
notify
=
notify
;
}
...
...
@@ -242,6 +280,8 @@ void ParseJob::unsetStaticMinimumFeatures(const IndexedString& url, TopDUContext
KDevelop
::
ProblemPointer
ParseJob
::
readContents
()
{
Q_D
(
ParseJob
);
Q_ASSERT
(
!
d
->
hasReadContents
);
d
->
hasReadContents
=
true
;
...
...
@@ -335,6 +375,8 @@ KDevelop::ProblemPointer ParseJob::readContents()
const
KDevelop
::
ParseJob
::
Contents
&
ParseJob
::
contents
()
const
{
Q_D
(
const
ParseJob
);
Q_ASSERT
(
d
->
hasReadContents
);
return
d
->
contents
;
}
...
...
@@ -393,6 +435,8 @@ struct MovingRangeTranslator
void
ParseJob
::
translateDUChainToRevision
(
TopDUContext
*
context
)
{
Q_D
(
ParseJob
);
qint64
targetRevision
=
d
->
contents
.
modification
.
revision
;
if
(
targetRevision
==
-
1
)
{
...
...
@@ -501,6 +545,8 @@ const ParsingEnvironment* ParseJob::environment() const
void
ParseJob
::
highlightDUChain
()
{
Q_D
(
ParseJob
);
ENSURE_CHAIN_NOT_LOCKED
if
(
!
d
->
languageSupport
->
codeHighlighting
()
||
!
duChain
()
||
abortRequested
())
{
// language doesn't support highlighting
...
...
@@ -526,6 +572,8 @@ DataAccessRepository* ParseJob::dataAccessInformation()
bool
ParseJob
::
hasTracker
()
const
{
Q_D
(
const
ParseJob
);
return
d
->
tracker
;
}
}
kdevplatform/language/backgroundparser/parsejob.h
View file @
13a05772
...
...
@@ -42,6 +42,7 @@ class DataAccessRepository;
class
TopDUContext
;
class
ReferencedTopDUContext
;
class
ILanguageSupport
;
class
ParseJobPrivate
;
/**
* The base class for background parser jobs.
...
...
@@ -241,7 +242,8 @@ protected:
bool
hasTracker
()
const
;
private:
const
QScopedPointer
<
class
ParseJobPrivate
>
d
;
const
QScopedPointer
<
class
ParseJobPrivate
>
d_ptr
;
Q_DECLARE_PRIVATE
(
ParseJob
)
};
}
...
...
kdevplatform/language/backgroundparser/parseprojectjob.cpp
View file @
13a05772
...
...
@@ -71,8 +71,10 @@ ParseProjectJob::~ParseProjectJob()
}
ParseProjectJob
::
ParseProjectJob
(
IProject
*
project
,
bool
forceUpdate
,
bool
forceAll
)
:
d
(
new
ParseProjectJobPrivate
(
project
,
forceUpdate
,
forceAll
))
:
d
_ptr
(
new
ParseProjectJobPrivate
(
project
,
forceUpdate
,
forceAll
))
{
Q_D
(
ParseProjectJob
);
connect
(
project
,
&
IProject
::
destroyed
,
this
,
&
ParseProjectJob
::
deleteNow
);
if
(
forceAll
||
ICore
::
self
()
->
projectController
()
->
parseAllProjectSources
())
{
...
...
@@ -104,6 +106,8 @@ void ParseProjectJob::updateProgress()
void
ParseProjectJob
::
updateReady
(
const
IndexedString
&
url
,
const
ReferencedTopDUContext
&
topContext
)
{
Q_D
(
ParseProjectJob
);
Q_UNUSED
(
url
);
Q_UNUSED
(
topContext
);
++
d
->
updated
;
...
...
@@ -116,6 +120,8 @@ void ParseProjectJob::updateReady(const IndexedString& url, const ReferencedTopD
void
ParseProjectJob
::
start
()
{
Q_D
(
ParseProjectJob
);
if
(
ICore
::
self
()
->
shuttingDown
())
{
return
;
}
...
...
kdevplatform/language/backgroundparser/parseprojectjob.h
View file @
13a05772
...
...
@@ -27,6 +27,7 @@
namespace
KDevelop
{
class
ReferencedTopDUContext
;
class
IProject
;
class
ParseProjectJobPrivate
;
///A job that parses all project-files in the given project either
///when KDevelop is configured to parse all files at project import
...
...
@@ -55,7 +56,8 @@ private:
void
updateProgress
();
private:
const
QScopedPointer
<
class
ParseProjectJobPrivate
>
d
;
const
QScopedPointer
<
class
ParseProjectJobPrivate
>
d_ptr
;
Q_DECLARE_PRIVATE
(
ParseProjectJob
)
};
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment