forked from qt-creator/qt-creator
Introduced token caching to prevent repetetive tokenizing.
Also removed TokenUnderCursor as it's functionality is in the token cache. Reviewed-by: ckamm
This commit is contained in:
@@ -51,11 +51,11 @@
|
||||
#include <cplusplus/Overview.h>
|
||||
#include <cplusplus/OverviewModel.h>
|
||||
#include <cplusplus/SimpleLexer.h>
|
||||
#include <cplusplus/TokenUnderCursor.h>
|
||||
#include <cplusplus/MatchingText.h>
|
||||
#include <cplusplus/BackwardsScanner.h>
|
||||
#include <cplusplus/FastPreprocessor.h>
|
||||
#include <cplusplus/CheckUndefinedSymbols.h>
|
||||
#include <cplusplus/TokenCache.h>
|
||||
|
||||
#include <cpptools/cppmodelmanagerinterface.h>
|
||||
|
||||
@@ -534,7 +534,7 @@ struct FindCanonicalSymbol
|
||||
SemanticInfo info;
|
||||
|
||||
FindCanonicalSymbol(CPPEditor *editor, const SemanticInfo &info)
|
||||
: editor(editor), info(info)
|
||||
: editor(editor), expressionUnderCursor(editor->tokenCache()), info(info)
|
||||
{
|
||||
typeOfExpression.init(info.doc, info.snapshot);
|
||||
}
|
||||
@@ -728,6 +728,11 @@ void CPPEditor::cut()
|
||||
finishRename();
|
||||
}
|
||||
|
||||
TokenCache *CPPEditor::tokenCache() const
|
||||
{
|
||||
return m_modelManager->tokenCache(editableInterface());
|
||||
}
|
||||
|
||||
void CPPEditor::startRename()
|
||||
{
|
||||
m_inRenameChanged = false;
|
||||
@@ -1207,7 +1212,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
|
||||
SimpleLexer tokenize;
|
||||
tokenize.setQtMocRunEnabled(true);
|
||||
const QString blockText = cursor.block().text();
|
||||
const QList<SimpleToken> tokens = tokenize(blockText, BackwardsScanner::previousBlockState(cursor.block()));
|
||||
const QList<SimpleToken> tokens = tokenize(blockText, TokenCache::previousBlockState(cursor.block()));
|
||||
|
||||
bool recognizedQtMethod = false;
|
||||
|
||||
@@ -1254,10 +1259,8 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
|
||||
}
|
||||
|
||||
if (! recognizedQtMethod) {
|
||||
static TokenUnderCursor tokenUnderCursor;
|
||||
|
||||
QTextBlock block;
|
||||
const SimpleToken tk = tokenUnderCursor(tc, &block);
|
||||
const QTextBlock block = tc.block();
|
||||
const SimpleToken tk = tokenCache()->tokenUnderCursor(tc);
|
||||
|
||||
beginOfToken = block.position() + tk.begin();
|
||||
endOfToken = block.position() + tk.end();
|
||||
@@ -1287,7 +1290,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
|
||||
return link;
|
||||
|
||||
// Evaluate the type of the expression under the cursor
|
||||
ExpressionUnderCursor expressionUnderCursor;
|
||||
ExpressionUnderCursor expressionUnderCursor(tokenCache());
|
||||
const QString expression = expressionUnderCursor(tc);
|
||||
|
||||
TypeOfExpression typeOfExpression;
|
||||
@@ -1386,13 +1389,13 @@ bool CPPEditor::isElectricCharacter(const QChar &ch) const
|
||||
QString CPPEditor::insertMatchingBrace(const QTextCursor &tc, const QString &text,
|
||||
const QChar &la, int *skippedChars) const
|
||||
{
|
||||
MatchingText m;
|
||||
MatchingText m(tokenCache());
|
||||
return m.insertMatchingBrace(tc, text, la, skippedChars);
|
||||
}
|
||||
|
||||
QString CPPEditor::insertParagraphSeparator(const QTextCursor &tc) const
|
||||
{
|
||||
MatchingText m;
|
||||
MatchingText m(tokenCache());
|
||||
return m.insertParagraphSeparator(tc);
|
||||
}
|
||||
|
||||
@@ -1415,8 +1418,7 @@ bool CPPEditor::contextAllowsAutoParentheses(const QTextCursor &cursor,
|
||||
|
||||
bool CPPEditor::isInComment(const QTextCursor &cursor) const
|
||||
{
|
||||
CPlusPlus::TokenUnderCursor tokenUnderCursor;
|
||||
const SimpleToken tk = tokenUnderCursor(cursor);
|
||||
const SimpleToken tk = tokenCache()->tokenUnderCursor(cursor);
|
||||
|
||||
if (tk.isComment()) {
|
||||
const int pos = cursor.selectionEnd() - cursor.block().position();
|
||||
@@ -1470,7 +1472,7 @@ void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedCha
|
||||
|
||||
const TabSettings &ts = tabSettings();
|
||||
|
||||
BackwardsScanner tk(tc, QString(), 400);
|
||||
BackwardsScanner tk(tokenCache(), tc, 400);
|
||||
const int tokenCount = tk.startToken();
|
||||
|
||||
if (tokenCount != 0) {
|
||||
|
||||
Reference in New Issue
Block a user