summaryrefslogtreecommitdiff
path: root/src/libs/cplusplus/SimpleLexer.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@nokia.com>2010-06-29 17:47:59 +0200
committerErik Verbruggen <erik.verbruggen@nokia.com>2010-07-02 11:18:51 +0200
commite3e8b1a5c01ddc230772ee0553ca325704295312 (patch)
tree9b0ce1ec310800cb6a4816b7a31269e63093aa5f /src/libs/cplusplus/SimpleLexer.cpp
parentbb8aed629f9e48f4a47a6acaae0cd5a80c7e2291 (diff)
downloadqt-creator-e3e8b1a5c01ddc230772ee0553ca325704295312.tar.gz
Removed the TokenCache.
Diffstat (limited to 'src/libs/cplusplus/SimpleLexer.cpp')
-rw-r--r--src/libs/cplusplus/SimpleLexer.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/libs/cplusplus/SimpleLexer.cpp b/src/libs/cplusplus/SimpleLexer.cpp
index 070f7dd737..83f3a5189c 100644
--- a/src/libs/cplusplus/SimpleLexer.cpp
+++ b/src/libs/cplusplus/SimpleLexer.cpp
@@ -170,4 +170,36 @@ QList<SimpleToken> SimpleLexer::operator()(const QString &text, int state)
return tokens;
}
+int SimpleLexer::tokenAt(const QList<SimpleToken> &tokens, int offset)
+{
+ for (int index = tokens.size() - 1; index >= 0; --index) {
+ const SimpleToken &tk = tokens.at(index);
+ if (tk.position() <= offset && tk.end() >= offset)
+ return index;
+ }
+
+ return -1;
+}
+SimpleToken SimpleLexer::tokenAt(const QString &text,
+ int offset,
+ int state,
+ bool qtMocRunEnabled)
+{
+ SimpleLexer tokenize;
+ tokenize.setQtMocRunEnabled(qtMocRunEnabled);
+ const QList<SimpleToken> tokens = tokenize(text, state);
+ const int tokenIdx = tokenAt(tokens, offset);
+ return (tokenIdx == -1) ? SimpleToken() : tokens.at(tokenIdx);
+}
+
+int SimpleLexer::tokenBefore(const QList<SimpleToken> &tokens, int offset)
+{
+ for (int index = tokens.size() - 1; index >= 0; --index) {
+ const SimpleToken &tk = tokens.at(index);
+ if (tk.position() <= offset)
+ return index;
+ }
+
+ return -1;
+}