summaryrefslogtreecommitdiff
path: root/src/libs/cplusplus/BackwardsScanner.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@nokia.com>2010-06-04 12:37:26 +0200
committerErik Verbruggen <erik.verbruggen@nokia.com>2010-06-04 12:37:26 +0200
commit424b9724d6dc4f860cfb8da17d51a715684ad94c (patch)
tree921120642920dd72762ebeef6919181130ccf4f7 /src/libs/cplusplus/BackwardsScanner.cpp
parent5f749306f11dbfd31a6f740ab9b1cb108476e202 (diff)
downloadqt-creator-424b9724d6dc4f860cfb8da17d51a715684ad94c.tar.gz
Revert "Introduced a token cache for the C++ editor."
This reverts commit c2393df02332618c8cf6159d9d6f6a40041ced89.
Diffstat (limited to 'src/libs/cplusplus/BackwardsScanner.cpp')
-rw-r--r--src/libs/cplusplus/BackwardsScanner.cpp53
1 files changed, 26 insertions, 27 deletions
diff --git a/src/libs/cplusplus/BackwardsScanner.cpp b/src/libs/cplusplus/BackwardsScanner.cpp
index bf3d59c4ac..3a0fbb936f 100644
--- a/src/libs/cplusplus/BackwardsScanner.cpp
+++ b/src/libs/cplusplus/BackwardsScanner.cpp
@@ -27,48 +27,33 @@
**
**************************************************************************/
#include "BackwardsScanner.h"
-#include "TokenCache.h"
#include <Token.h>
#include <QtGui/QTextCursor>
-#include <QTextDocument>
using namespace CPlusPlus;
-BackwardsScanner::BackwardsScanner(TokenCache *tokenCache, const QTextCursor &cursor, int maxBlockCount, const QString &suffix)
- : _tokenCache(tokenCache)
- , _offset(0)
+BackwardsScanner::BackwardsScanner(const QTextCursor &cursor, const QString &suffix, int maxBlockCount)
+ : _offset(0)
, _blocksTokenized(0)
, _block(cursor.block())
, _maxBlockCount(maxBlockCount)
{
- int pos = cursor.position() - cursor.block().position();
- _text = _block.text().left(pos);
-
- if (suffix.isEmpty()) {
- _tokens.append(tokenCache->tokensForBlock(_block));
- int last = -1;
- for (int i = _tokens.size() - 1; i >= 0; --i) {
- if (_tokens.at(i).begin() < pos) {
- last = i;
- break;
- }
- }
- for (int i = _tokens.size() - 1; i > last && i >= 0; --i)
- _tokens.removeAt(i);
- } else {
- SimpleLexer tokenize;
- tokenize.setQtMocRunEnabled(true);
- tokenize.setSkipComments(true);
- tokenize.setObjCEnabled(true);
+ _tokenize.setQtMocRunEnabled(true);
+ _tokenize.setSkipComments(true);
+ _tokenize.setObjCEnabled(true);
+ _text = _block.text().left(cursor.position() - cursor.block().position());
+ if (! suffix.isEmpty())
_text += suffix;
- _tokens.append(tokenize(_text, TokenCache::previousBlockState(_block)));
- }
+ _tokens.append(_tokenize(_text, previousBlockState(_block)));
_startToken = _tokens.size();
}
+int BackwardsScanner::state() const
+{ return _tokenize.state(); }
+
SimpleToken BackwardsScanner::LA(int index) const
{ return const_cast<BackwardsScanner *>(this)->fetchToken(_startToken - index); }
@@ -98,7 +83,7 @@ const SimpleToken &BackwardsScanner::fetchToken(int tokenIndex)
adaptedTokens.append(t);
}
- _tokens = _tokenCache->tokensForBlock(_block);
+ _tokens = _tokenize(blockText, previousBlockState(_block));
_offset += _tokens.size();
_tokens += adaptedTokens;
}
@@ -134,6 +119,20 @@ QStringRef BackwardsScanner::textRef(int index) const
return _text.midRef(firstToken.begin(), firstToken.length());
}
+int BackwardsScanner::previousBlockState(const QTextBlock &block)
+{
+ const QTextBlock prevBlock = block.previous();
+
+ if (prevBlock.isValid()) {
+ int state = prevBlock.userState();
+
+ if (state != -1)
+ return state;
+ }
+
+ return 0;
+}
+
int BackwardsScanner::size() const
{
return _tokens.size();