QmlJS: Fix uses of Scanner::state().

Change-Id: I5195fc43e8a6653bf52c0eaa6cddb8dfd25b6217
Reviewed-on: http://codereview.qt.nokia.com/319
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@nokia.com>
This commit is contained in:
Christian Kamm
2011-06-03 08:49:40 +02:00
committed by Joerg Bornemann
parent 362aef67e0
commit b729d4b973
5 changed files with 12 additions and 12 deletions

View File

@@ -463,7 +463,7 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
leave(); leave();
continue; continue;
} else if (m_tokenIndex == m_tokens.size() - 1 } else if (m_tokenIndex == m_tokens.size() - 1
&& lexerState == Scanner::Normal) { && (lexerState & Scanner::MultiLineMask) == Scanner::Normal) {
leave(); leave();
} else if (m_tokenIndex == 0) { } else if (m_tokenIndex == 0) {
// to allow enter/leave to update the indentDepth // to allow enter/leave to update the indentDepth
@@ -488,7 +488,7 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
} }
if (topState != multiline_comment_start if (topState != multiline_comment_start
&& topState != multiline_comment_cont && topState != multiline_comment_cont
&& lexerState == Scanner::MultiLineComment) { && (lexerState & Scanner::MultiLineMask) == Scanner::MultiLineComment) {
enter(multiline_comment_start); enter(multiline_comment_start);
} }

View File

@@ -166,22 +166,22 @@ static int findRegExpEnd(const QString &text, int start)
static inline int multiLineState(int state) static inline int multiLineState(int state)
{ {
return state & 0x3; return state & Scanner::MultiLineMask;
} }
static inline void setMultiLineState(int *state, int s) static inline void setMultiLineState(int *state, int s)
{ {
*state = s | (*state & ~0x3); *state = s | (*state & ~Scanner::MultiLineMask);
} }
static inline bool regexpMayFollow(int state) static inline bool regexpMayFollow(int state)
{ {
return state & 0x4; return state & Scanner::RegexpMayFollow;
} }
static inline void setRegexpMayFollow(int *state, bool on) static inline void setRegexpMayFollow(int *state, bool on)
{ {
*state = (on << 2) | (*state & 0x3); *state = (on ? Scanner::RegexpMayFollow : 0) | (*state & ~Scanner::RegexpMayFollow);
} }
QList<Token> Scanner::operator()(const QString &text, int startState) QList<Token> Scanner::operator()(const QString &text, int startState)
@@ -189,8 +189,6 @@ QList<Token> Scanner::operator()(const QString &text, int startState)
_state = startState; _state = startState;
QList<Token> tokens; QList<Token> tokens;
// ### handle multi line comment state.
int index = 0; int index = 0;
if (multiLineState(_state) == MultiLineComment) { if (multiLineState(_state) == MultiLineComment) {

View File

@@ -84,6 +84,8 @@ public:
MultiLineComment = 1, MultiLineComment = 1,
MultiLineStringDQuote = 2, MultiLineStringDQuote = 2,
MultiLineStringSQuote = 3, MultiLineStringSQuote = 3,
MultiLineMask = 3,
RegexpMayFollow = 4 // flag that may be combined with the above RegexpMayFollow = 4 // flag that may be combined with the above
}; };

View File

@@ -188,9 +188,9 @@ bool AutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
// if a string literal doesn't start with a quote, it must be multiline // if a string literal doesn't start with a quote, it must be multiline
if (quote != QLatin1Char('"') && quote != QLatin1Char('\'')) { if (quote != QLatin1Char('"') && quote != QLatin1Char('\'')) {
const int startState = blockStartState(cursor.block()); const int startState = blockStartState(cursor.block());
if (startState == Scanner::MultiLineStringDQuote) if ((startState & Scanner::MultiLineMask) == Scanner::MultiLineStringDQuote)
quote = QLatin1Char('"'); quote = QLatin1Char('"');
else if (startState == Scanner::MultiLineStringSQuote) else if ((startState & Scanner::MultiLineMask) == Scanner::MultiLineStringSQuote)
quote = QLatin1Char('\''); quote = QLatin1Char('\'');
} }

View File

@@ -108,7 +108,7 @@ void Highlighter::highlightBlock(const QString &text)
onClosingParenthesis('-', token.end() - 1, index == tokens.size()-1); onClosingParenthesis('-', token.end() - 1, index == tokens.size()-1);
m_inMultilineComment = false; m_inMultilineComment = false;
} else if (!m_inMultilineComment } else if (!m_inMultilineComment
&& m_scanner.state() == Scanner::MultiLineComment && (m_scanner.state() & Scanner::MultiLineMask) == Scanner::MultiLineComment
&& index == tokens.size() - 1) { && index == tokens.size() - 1) {
onOpeningParenthesis('+', token.offset, index == 0); onOpeningParenthesis('+', token.offset, index == 0);
m_inMultilineComment = true; m_inMultilineComment = true;
@@ -337,7 +337,7 @@ int Highlighter::onBlockStart()
if (previousState != -1) { if (previousState != -1) {
state = previousState & 0xff; state = previousState & 0xff;
m_braceDepth = (previousState >> 8); m_braceDepth = (previousState >> 8);
m_inMultilineComment = (state == Scanner::MultiLineComment); m_inMultilineComment = ((state & Scanner::MultiLineMask) == Scanner::MultiLineComment);
} }
m_foldingIndent = m_braceDepth; m_foldingIndent = m_braceDepth;