OSDN Git Service

QmlJS: Fix uses of Scanner::state().
authorChristian Kamm <christian.d.kamm@nokia.com>
Fri, 3 Jun 2011 06:49:40 +0000 (08:49 +0200)
committerJoerg Bornemann <joerg.bornemann@nokia.com>
Fri, 3 Jun 2011 06:53:24 +0000 (08:53 +0200)
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
src/libs/qmljs/qmljsscanner.cpp
src/libs/qmljs/qmljsscanner.h
src/plugins/qmljseditor/qmljsautocompleter.cpp
src/plugins/qmljseditor/qmljshighlighter.cpp

index 0d4c74b..32ab558 100644 (file)
@@ -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);
     }
 
index 84d8669..1272283 100644 (file)
@@ -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) {
index 777fd1b..b8edf45 100644 (file)
@@ -84,6 +84,8 @@ public:
         MultiLineComment = 1,
         MultiLineStringDQuote = 2,
         MultiLineStringSQuote = 3,
+        MultiLineMask = 3,
+
         RegexpMayFollow = 4 // flag that may be combined with the above
     };
 
index 6bbd07c..b160d3c 100644 (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 (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('\'');
         }
 
index 55b917d..a093c63 100644 (file)
@@ -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;