| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/parser/qqmljslexer_p.h |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
| 5 | ** | - | ||||||
| 6 | ** This file is part of the QtQml module of the Qt Toolkit. | - | ||||||
| 7 | ** | - | ||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||
| 9 | ** Commercial License Usage | - | ||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||
| 16 | ** | - | ||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
| 24 | ** | - | ||||||
| 25 | ** GNU General Public License Usage | - | ||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
| 35 | ** | - | ||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||
| 37 | ** | - | ||||||
| 38 | ****************************************************************************/ | - | ||||||
| 39 | - | |||||||
| 40 | #ifndef QQMLJSLEXER_P_H | - | ||||||
| 41 | #define QQMLJSLEXER_P_H | - | ||||||
| 42 | - | |||||||
| 43 | // | - | ||||||
| 44 | // W A R N I N G | - | ||||||
| 45 | // ------------- | - | ||||||
| 46 | // | - | ||||||
| 47 | // This file is not part of the Qt API. It exists purely as an | - | ||||||
| 48 | // implementation detail. This header file may change from version to | - | ||||||
| 49 | // version without notice, or even be removed. | - | ||||||
| 50 | // | - | ||||||
| 51 | // We mean it. | - | ||||||
| 52 | // | - | ||||||
| 53 | - | |||||||
| 54 | #include <private/qqmljsglobal_p.h> | - | ||||||
| 55 | #include <private/qqmljsgrammar_p.h> | - | ||||||
| 56 | - | |||||||
| 57 | #include <QtCore/qstring.h> | - | ||||||
| 58 | #include <QtCore/qstack.h> | - | ||||||
| 59 | - | |||||||
| 60 | QT_QML_BEGIN_NAMESPACE | - | ||||||
| 61 | - | |||||||
| 62 | namespace QQmlJS { | - | ||||||
| 63 | - | |||||||
| 64 | class Engine; | - | ||||||
| 65 | class DiagnosticMessage; | - | ||||||
| 66 | class Directives; | - | ||||||
| 67 | - | |||||||
| 68 | class QML_PARSER_EXPORT Lexer: public QQmlJSGrammar | - | ||||||
| 69 | { | - | ||||||
| 70 | public: | - | ||||||
| 71 | enum { | - | ||||||
| 72 | T_ABSTRACT = T_RESERVED_WORD, | - | ||||||
| 73 | T_BOOLEAN = T_RESERVED_WORD, | - | ||||||
| 74 | T_BYTE = T_RESERVED_WORD, | - | ||||||
| 75 | T_CHAR = T_RESERVED_WORD, | - | ||||||
| 76 | T_DOUBLE = T_RESERVED_WORD, | - | ||||||
| 77 | T_FINAL = T_RESERVED_WORD, | - | ||||||
| 78 | T_FLOAT = T_RESERVED_WORD, | - | ||||||
| 79 | T_GOTO = T_RESERVED_WORD, | - | ||||||
| 80 | T_IMPLEMENTS = T_RESERVED_WORD, | - | ||||||
| 81 | T_INT = T_RESERVED_WORD, | - | ||||||
| 82 | T_INTERFACE = T_RESERVED_WORD, | - | ||||||
| 83 | T_LONG = T_RESERVED_WORD, | - | ||||||
| 84 | T_NATIVE = T_RESERVED_WORD, | - | ||||||
| 85 | T_PACKAGE = T_RESERVED_WORD, | - | ||||||
| 86 | T_PRIVATE = T_RESERVED_WORD, | - | ||||||
| 87 | T_PROTECTED = T_RESERVED_WORD, | - | ||||||
| 88 | T_SHORT = T_RESERVED_WORD, | - | ||||||
| 89 | T_SYNCHRONIZED = T_RESERVED_WORD, | - | ||||||
| 90 | T_THROWS = T_RESERVED_WORD, | - | ||||||
| 91 | T_TRANSIENT = T_RESERVED_WORD, | - | ||||||
| 92 | T_VOLATILE = T_RESERVED_WORD | - | ||||||
| 93 | }; | - | ||||||
| 94 | - | |||||||
| 95 | enum Error { | - | ||||||
| 96 | NoError, | - | ||||||
| 97 | IllegalCharacter, | - | ||||||
| 98 | IllegalNumber, | - | ||||||
| 99 | UnclosedStringLiteral, | - | ||||||
| 100 | IllegalEscapeSequence, | - | ||||||
| 101 | IllegalUnicodeEscapeSequence, | - | ||||||
| 102 | UnclosedComment, | - | ||||||
| 103 | IllegalExponentIndicator, | - | ||||||
| 104 | IllegalIdentifier, | - | ||||||
| 105 | IllegalHexadecimalEscapeSequence | - | ||||||
| 106 | }; | - | ||||||
| 107 | - | |||||||
| 108 | enum RegExpBodyPrefix { | - | ||||||
| 109 | NoPrefix, | - | ||||||
| 110 | EqualPrefix | - | ||||||
| 111 | }; | - | ||||||
| 112 | - | |||||||
| 113 | enum RegExpFlag { | - | ||||||
| 114 | RegExp_Global = 0x01, | - | ||||||
| 115 | RegExp_IgnoreCase = 0x02, | - | ||||||
| 116 | RegExp_Multiline = 0x04 | - | ||||||
| 117 | }; | - | ||||||
| 118 | - | |||||||
| 119 | enum ParseModeFlags { | - | ||||||
| 120 | QmlMode = 0x1, | - | ||||||
| 121 | YieldIsKeyword = 0x2, | - | ||||||
| 122 | StaticIsKeyword = 0x4 | - | ||||||
| 123 | }; | - | ||||||
| 124 | - | |||||||
| 125 | public: | - | ||||||
| 126 | Lexer(Engine *engine); | - | ||||||
| 127 | - | |||||||
| 128 | int parseModeFlags() const { | - | ||||||
| 129 | int flags = 0; | - | ||||||
| 130 | if (qmlMode())
| 4616183-24544091 | ||||||
| 131 | flags |= QmlMode|StaticIsKeyword; executed 4616183 times by 143 tests: flags |= QmlMode|StaticIsKeyword;Executed by:
| 4616183 | ||||||
| 132 | if (yieldIsKeyWord())
| 116088-29052789 | ||||||
| 133 | flags |= YieldIsKeyword; executed 116092 times by 2 tests: flags |= YieldIsKeyword;Executed by:
| 116092 | ||||||
| 134 | if (_staticIsKeyword)
| 84259-29106226 | ||||||
| 135 | flags |= StaticIsKeyword; executed 84260 times by 2 tests: flags |= StaticIsKeyword;Executed by:
| 84260 | ||||||
| 136 | return flags; executed 29190215 times by 148 tests: return flags;Executed by:
| 29190215 | ||||||
| 137 | } | - | ||||||
| 138 | - | |||||||
| 139 | bool qmlMode() const; | - | ||||||
| 140 | bool yieldIsKeyWord() const { return _generatorLevel != 0; } executed 29164647 times by 148 tests: return _generatorLevel != 0;Executed by:
| 29164647 | ||||||
| 141 | void setStaticIsKeyword(bool b) { _staticIsKeyword = b; } executed 49114 times by 2 tests: end of blockExecuted by:
| 49114 | ||||||
| 142 | - | |||||||
| 143 | QString code() const; | - | ||||||
| 144 | void setCode(const QString &code, int lineno, bool qmlMode = true); | - | ||||||
| 145 | - | |||||||
| 146 | int lex(); | - | ||||||
| 147 | - | |||||||
| 148 | bool scanRegExp(RegExpBodyPrefix prefix = NoPrefix); | - | ||||||
| 149 | bool scanDirectives(Directives *directives, DiagnosticMessage *error); | - | ||||||
| 150 | - | |||||||
| 151 | int regExpFlags() const { return _patternFlags; } executed 1077704 times by 10 tests: return _patternFlags;Executed by:
| 1077704 | ||||||
| 152 | QString regExpPattern() const { return _tokenText; } executed 1070192 times by 10 tests: return _tokenText;Executed by:
| 1070192 | ||||||
| 153 | - | |||||||
| 154 | int tokenKind() const { return _tokenKind; } executed 1778771 times by 27 tests: return _tokenKind;Executed by:
| 1778771 | ||||||
| 155 | int tokenOffset() const { return _tokenStartPtr - _code.unicode(); } executed 76807374 times by 148 tests: return _tokenStartPtr - _code.unicode();Executed by:
| 76807374 | ||||||
| 156 | int tokenLength() const { return _tokenLength; } executed 75901609 times by 147 tests: return _tokenLength;Executed by:
| 75901609 | ||||||
| 157 | - | |||||||
| 158 | int tokenStartLine() const { return _tokenLine; } executed 76991332 times by 148 tests: return _tokenLine;Executed by:
| 76991332 | ||||||
| 159 | int tokenStartColumn() const { return _tokenColumn; } executed 77024699 times by 148 tests: return _tokenColumn;Executed by:
| 77024699 | ||||||
| 160 | - | |||||||
| 161 | inline QStringRef tokenSpell() const { return _tokenSpell; } executed 74819225 times by 147 tests: return _tokenSpell;Executed by:
| 74819225 | ||||||
| 162 | double tokenValue() const { return _tokenValue; } executed 74776242 times by 147 tests: return _tokenValue;Executed by:
| 74776242 | ||||||
| 163 | QString tokenText() const; | - | ||||||
| 164 | - | |||||||
| 165 | Error errorCode() const; | - | ||||||
| 166 | QString errorMessage() const; | - | ||||||
| 167 | - | |||||||
| 168 | bool prevTerminator() const; | - | ||||||
| 169 | bool followsClosingBrace() const; | - | ||||||
| 170 | bool canInsertAutomaticSemicolon(int token) const; | - | ||||||
| 171 | - | |||||||
| 172 | enum ParenthesesState { | - | ||||||
| 173 | IgnoreParentheses, | - | ||||||
| 174 | CountParentheses, | - | ||||||
| 175 | BalancedParentheses | - | ||||||
| 176 | }; | - | ||||||
| 177 | - | |||||||
| 178 | void enterGeneratorBody() { ++_generatorLevel; } executed 18020 times by 2 tests: end of blockExecuted by:
| 18020 | ||||||
| 179 | void leaveGeneratorBody() { --_generatorLevel; } executed 17329 times by 2 tests: end of blockExecuted by:
| 17329 | ||||||
| 180 | - | |||||||
| 181 | protected: | - | ||||||
| 182 | static int classify(const QChar *s, int n, int parseModeFlags); | - | ||||||
| 183 | - | |||||||
| 184 | private: | - | ||||||
| 185 | inline void scanChar(); | - | ||||||
| 186 | int scanToken(); | - | ||||||
| 187 | int scanNumber(QChar ch); | - | ||||||
| 188 | enum ScanStringMode { | - | ||||||
| 189 | SingleQuote = '\'', | - | ||||||
| 190 | DoubleQuote = '"', | - | ||||||
| 191 | TemplateHead = '`', | - | ||||||
| 192 | TemplateContinuation = 0 | - | ||||||
| 193 | }; | - | ||||||
| 194 | int scanString(ScanStringMode mode); | - | ||||||
| 195 | - | |||||||
| 196 | bool isLineTerminator() const; | - | ||||||
| 197 | unsigned isLineTerminatorSequence() const; | - | ||||||
| 198 | static bool isIdentLetter(QChar c); | - | ||||||
| 199 | static bool isDecimalDigit(ushort c); | - | ||||||
| 200 | static bool isHexDigit(QChar c); | - | ||||||
| 201 | static bool isOctalDigit(ushort c); | - | ||||||
| 202 | - | |||||||
| 203 | void syncProhibitAutomaticSemicolon(); | - | ||||||
| 204 | uint decodeUnicodeEscapeCharacter(bool *ok); | - | ||||||
| 205 | QChar decodeHexEscapeCharacter(bool *ok); | - | ||||||
| 206 | - | |||||||
| 207 | private: | - | ||||||
| 208 | Engine *_engine; | - | ||||||
| 209 | - | |||||||
| 210 | QString _code; | - | ||||||
| 211 | QString _tokenText; | - | ||||||
| 212 | QString _errorMessage; | - | ||||||
| 213 | QStringRef _tokenSpell; | - | ||||||
| 214 | - | |||||||
| 215 | const QChar *_codePtr; | - | ||||||
| 216 | const QChar *_endPtr; | - | ||||||
| 217 | const QChar *_tokenStartPtr; | - | ||||||
| 218 | - | |||||||
| 219 | QChar _char; | - | ||||||
| 220 | Error _errorCode; | - | ||||||
| 221 | - | |||||||
| 222 | int _currentLineNumber; | - | ||||||
| 223 | int _currentColumnNumber; | - | ||||||
| 224 | double _tokenValue; | - | ||||||
| 225 | - | |||||||
| 226 | // parentheses state | - | ||||||
| 227 | ParenthesesState _parenthesesState; | - | ||||||
| 228 | int _parenthesesCount; | - | ||||||
| 229 | - | |||||||
| 230 | // template string stack | - | ||||||
| 231 | QStack<int> _outerTemplateBraceCount; | - | ||||||
| 232 | int _bracesCount = -1; | - | ||||||
| 233 | - | |||||||
| 234 | int _stackToken; | - | ||||||
| 235 | - | |||||||
| 236 | int _patternFlags; | - | ||||||
| 237 | int _tokenKind; | - | ||||||
| 238 | int _tokenLength; | - | ||||||
| 239 | int _tokenLine; | - | ||||||
| 240 | int _tokenColumn; | - | ||||||
| 241 | - | |||||||
| 242 | bool _validTokenText; | - | ||||||
| 243 | bool _prohibitAutomaticSemicolon; | - | ||||||
| 244 | bool _restrictedKeyword; | - | ||||||
| 245 | bool _terminator; | - | ||||||
| 246 | bool _followsClosingBrace; | - | ||||||
| 247 | bool _delimited; | - | ||||||
| 248 | bool _qmlMode; | - | ||||||
| 249 | int _generatorLevel = 0; | - | ||||||
| 250 | bool _staticIsKeyword = false; | - | ||||||
| 251 | }; | - | ||||||
| 252 | - | |||||||
| 253 | } // end of namespace QQmlJS | - | ||||||
| 254 | - | |||||||
| 255 | QT_QML_END_NAMESPACE | - | ||||||
| 256 | - | |||||||
| 257 | #endif // LEXER_H | - | ||||||
| Source code | Switch to Preprocessed file |