summaryrefslogtreecommitdiff
path: root/src/libs/cplusplus/SimpleLexer.cpp
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2009-09-21 15:11:18 +0200
committerRoberto Raggi <roberto.raggi@nokia.com>2009-09-21 15:14:28 +0200
commit6c9670c3db856f8be50cf89a03eefefeeb3f6392 (patch)
tree1a42e010966629d59c27ead8bece244e75764816 /src/libs/cplusplus/SimpleLexer.cpp
parentcaa164a4ab7094fa134031db1a04c1c469542f63 (diff)
downloadqt-creator-6c9670c3db856f8be50cf89a03eefefeeb3f6392.tar.gz
Use the backward scanner to indent labeled statements, ctor-initializers and access specifiers.
Diffstat (limited to 'src/libs/cplusplus/SimpleLexer.cpp')
-rw-r--r--src/libs/cplusplus/SimpleLexer.cpp36
1 files changed, 31 insertions, 5 deletions
diff --git a/src/libs/cplusplus/SimpleLexer.cpp b/src/libs/cplusplus/SimpleLexer.cpp
index 7e60f76115..8c023d8603 100644
--- a/src/libs/cplusplus/SimpleLexer.cpp
+++ b/src/libs/cplusplus/SimpleLexer.cpp
@@ -35,6 +35,17 @@
using namespace CPlusPlus;
+SimpleToken::SimpleToken(const Token &token, const QStringRef &text)
+ : _kind(token.f.kind)
+ , _flags(0)
+ , _position(token.begin())
+ , _length(token.f.length)
+ , _text(text)
+{
+ f._whitespace = token.f.whitespace;
+ f._newline = token.f.newline;
+}
+
bool SimpleToken::isLiteral() const
{
return _kind >= T_FIRST_LITERAL && _kind <= T_LAST_LITERAL;
@@ -60,6 +71,11 @@ bool SimpleToken::isObjCAtKeyword() const
return _kind >= T_FIRST_OBJC_AT_KEYWORD && _kind <= T_LAST_OBJC_AT_KEYWORD;
}
+const char *SimpleToken::name() const
+{
+ return Token::name(_kind);
+}
+
SimpleLexer::SimpleLexer()
: _lastState(0),
_skipComments(false),
@@ -113,6 +129,7 @@ QList<SimpleToken> SimpleLexer::operator()(const QString &text, int state)
Lexer lex(firstChar, lastChar);
lex.setQtMocRunEnabled(_qtMocRunEnabled);
lex.setObjCEnabled(_objCEnabled);
+ lex.setStartWithNewline(true);
if (! _skipComments)
lex.setScanCommentTokens(true);
@@ -122,17 +139,26 @@ QList<SimpleToken> SimpleLexer::operator()(const QString &text, int state)
bool inPreproc = false;
+ bool first = true;
+
for (;;) {
Token tk;
lex(&tk);
if (tk.is(T_EOF_SYMBOL))
break;
- SimpleToken simpleTk;
- simpleTk._kind = int(tk.f.kind);
- simpleTk._position = int(lex.tokenOffset());
- simpleTk._length = int(lex.tokenLength());
- simpleTk._text = text.midRef(simpleTk._position, simpleTk._length);
+ Q_ASSERT(lex.tokenOffset() == tk.begin());
+ Q_ASSERT(lex.tokenLength() == tk.f.length);
+
+ QStringRef spell = text.midRef(lex.tokenOffset(), lex.tokenLength());
+ SimpleToken simpleTk(tk, spell);
+
+ if (first) {
+ first = false;
+
+ Q_ASSERT(tk.f.newline);
+ Q_ASSERT(simpleTk.followsNewline());
+ }
lex.setScanAngleStringLiteralTokens(false);