CppTools: Cancel parsing if editor is closed

The m_parserFuture.cancel() in ~BuiltinEditorDocumentProcessor() did not
cancel anything. Thus, closing a document while the parser was running
led to a blocking UI thread.

Now it cancels at the next include directive it encounters.

Change-Id: I092fddbbd747e0bc95265b6e9b4fcc26b3f76cb3
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Nikolai Kosjar
2016-07-27 14:48:42 +02:00
committed by Tim Jenssen
parent c8020af997
commit ad49e64ff0
11 changed files with 48 additions and 8 deletions

View File

@@ -762,6 +762,11 @@ QByteArray Preprocessor::run(const QString &fileName,
return preprocessed;
}
void Preprocessor::setCancelChecker(const Preprocessor::CancelChecker &cancelChecker)
{
m_cancelChecker = cancelChecker;
}
bool Preprocessor::expandFunctionlikeMacros() const
{
return m_expandFunctionlikeMacros;
@@ -1636,6 +1641,9 @@ void Preprocessor::handlePreprocessorDirective(PPToken *tk)
void Preprocessor::handleIncludeDirective(PPToken *tk, bool includeNext)
{
if (m_cancelChecker && m_cancelChecker())
return;
m_state.m_lexer->setScanAngleStringLiteralTokens(true);
lex(tk); // consume "include" token
m_state.m_lexer->setScanAngleStringLiteralTokens(false);

View File

@@ -56,6 +56,8 @@
#include <QByteArray>
#include <QPair>
#include <functional>
namespace CPlusPlus {
class Environment;
@@ -81,6 +83,9 @@ public:
QByteArray run(const QString &filename, const QByteArray &source,
bool noLines = false, bool markGeneratedTokens = true);
using CancelChecker = std::function<bool()>;
void setCancelChecker(const CancelChecker &cancelChecker);
bool expandFunctionlikeMacros() const;
void setExpandFunctionlikeMacros(bool expandFunctionlikeMacros);
@@ -253,6 +258,7 @@ private:
Client *m_client;
Environment *m_env;
QByteArray m_scratchBuffer;
CancelChecker m_cancelChecker;
bool m_expandFunctionlikeMacros;
bool m_keepComments;