From b729d4b9738592bfb7bfd8f111b1173d7bfafefe Mon Sep 17 00:00:00 2001
From: Christian Kamm <christian.d.kamm@nokia.com>
Date: Fri, 3 Jun 2011 08:49:40 +0200
Subject: [PATCH] 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>
---
 src/libs/qmljs/qmljscodeformatter.cpp          |  4 ++--
 src/libs/qmljs/qmljsscanner.cpp                | 10 ++++------
 src/libs/qmljs/qmljsscanner.h                  |  2 ++
 src/plugins/qmljseditor/qmljsautocompleter.cpp |  4 ++--
 src/plugins/qmljseditor/qmljshighlighter.cpp   |  4 ++--
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/libs/qmljs/qmljscodeformatter.cpp b/src/libs/qmljs/qmljscodeformatter.cpp
index 0d4c74bd585..32ab5585da2 100644
--- a/src/libs/qmljs/qmljscodeformatter.cpp
+++ b/src/libs/qmljs/qmljscodeformatter.cpp
@@ -463,7 +463,7 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
                 leave();
                 continue;
             } else if (m_tokenIndex == m_tokens.size() - 1
-                       && lexerState == Scanner::Normal) {
+                       && (lexerState & Scanner::MultiLineMask) == Scanner::Normal) {
                 leave();
             } else if (m_tokenIndex == 0) {
                 // to allow enter/leave to update the indentDepth
@@ -488,7 +488,7 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
     }
     if (topState != multiline_comment_start
             && topState != multiline_comment_cont
-            && lexerState == Scanner::MultiLineComment) {
+            && (lexerState & Scanner::MultiLineMask) == Scanner::MultiLineComment) {
         enter(multiline_comment_start);
     }
 
diff --git a/src/libs/qmljs/qmljsscanner.cpp b/src/libs/qmljs/qmljsscanner.cpp
index 84d86692882..12722839aa1 100644
--- a/src/libs/qmljs/qmljsscanner.cpp
+++ b/src/libs/qmljs/qmljsscanner.cpp
@@ -166,22 +166,22 @@ static int findRegExpEnd(const QString &text, int start)
 
 static inline int multiLineState(int state)
 {
-    return state & 0x3;
+    return state & Scanner::MultiLineMask;
 }
 
 static inline void setMultiLineState(int *state, int s)
 {
-    *state = s | (*state & ~0x3);
+    *state = s | (*state & ~Scanner::MultiLineMask);
 }
 
 static inline bool regexpMayFollow(int state)
 {
-    return state & 0x4;
+    return state & Scanner::RegexpMayFollow;
 }
 
 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)
@@ -189,8 +189,6 @@ QList<Token> Scanner::operator()(const QString &text, int startState)
     _state = startState;
     QList<Token> tokens;
 
-    // ### handle multi line comment state.
-
     int index = 0;
 
     if (multiLineState(_state) == MultiLineComment) {
diff --git a/src/libs/qmljs/qmljsscanner.h b/src/libs/qmljs/qmljsscanner.h
index 777fd1ba052..b8edf455e8a 100644
--- a/src/libs/qmljs/qmljsscanner.h
+++ b/src/libs/qmljs/qmljsscanner.h
@@ -84,6 +84,8 @@ public:
         MultiLineComment = 1,
         MultiLineStringDQuote = 2,
         MultiLineStringSQuote = 3,
+        MultiLineMask = 3,
+
         RegexpMayFollow = 4 // flag that may be combined with the above
     };
 
diff --git a/src/plugins/qmljseditor/qmljsautocompleter.cpp b/src/plugins/qmljseditor/qmljsautocompleter.cpp
index 6bbd07c5fee..b160d3cedfb 100644
--- a/src/plugins/qmljseditor/qmljsautocompleter.cpp
+++ b/src/plugins/qmljseditor/qmljsautocompleter.cpp
@@ -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 (quote != QLatin1Char('"') && quote != QLatin1Char('\'')) {
             const int startState = blockStartState(cursor.block());
-            if (startState == Scanner::MultiLineStringDQuote)
+            if ((startState & Scanner::MultiLineMask) == Scanner::MultiLineStringDQuote)
                 quote = QLatin1Char('"');
-            else if (startState == Scanner::MultiLineStringSQuote)
+            else if ((startState & Scanner::MultiLineMask) == Scanner::MultiLineStringSQuote)
                 quote = QLatin1Char('\'');
         }
 
diff --git a/src/plugins/qmljseditor/qmljshighlighter.cpp b/src/plugins/qmljseditor/qmljshighlighter.cpp
index 55b917db357..a093c639381 100644
--- a/src/plugins/qmljseditor/qmljshighlighter.cpp
+++ b/src/plugins/qmljseditor/qmljshighlighter.cpp
@@ -108,7 +108,7 @@ void Highlighter::highlightBlock(const QString &text)
                     onClosingParenthesis('-', token.end() - 1, index == tokens.size()-1);
                     m_inMultilineComment = false;
                 } else if (!m_inMultilineComment
-                           && m_scanner.state() == Scanner::MultiLineComment
+                           && (m_scanner.state() & Scanner::MultiLineMask) == Scanner::MultiLineComment
                            && index == tokens.size() - 1) {
                     onOpeningParenthesis('+', token.offset, index == 0);
                     m_inMultilineComment = true;
@@ -337,7 +337,7 @@ int Highlighter::onBlockStart()
     if (previousState != -1) {
         state = previousState & 0xff;
         m_braceDepth = (previousState >> 8);
-        m_inMultilineComment = (state == Scanner::MultiLineComment);
+        m_inMultilineComment = ((state & Scanner::MultiLineMask) == Scanner::MultiLineComment);
     }
     m_foldingIndent = m_braceDepth;
 
-- 
GitLab