| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/tools/qmlmin/main.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||
| 3 | - | |||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||
| 5 | - | |||||||||||||||||||||||||
| 6 | - | |||||||||||||||||||||||||
| 7 | - | |||||||||||||||||||||||||
| 8 | namespace QQmlJS { | - | ||||||||||||||||||||||||
| 9 | - | |||||||||||||||||||||||||
| 10 | enum RegExpFlag { | - | ||||||||||||||||||||||||
| 11 | Global = 0x01, | - | ||||||||||||||||||||||||
| 12 | IgnoreCase = 0x02, | - | ||||||||||||||||||||||||
| 13 | Multiline = 0x04 | - | ||||||||||||||||||||||||
| 14 | }; | - | ||||||||||||||||||||||||
| 15 | - | |||||||||||||||||||||||||
| 16 | - | |||||||||||||||||||||||||
| 17 | class QmlminLexer: protected Lexer, public Directives | - | ||||||||||||||||||||||||
| 18 | { | - | ||||||||||||||||||||||||
| 19 | QQmlJS::Engine _engine; | - | ||||||||||||||||||||||||
| 20 | QString _fileName; | - | ||||||||||||||||||||||||
| 21 | QString _directives; | - | ||||||||||||||||||||||||
| 22 | - | |||||||||||||||||||||||||
| 23 | protected: | - | ||||||||||||||||||||||||
| 24 | QVector<int> _stateStack; | - | ||||||||||||||||||||||||
| 25 | QList<int> _tokens; | - | ||||||||||||||||||||||||
| 26 | QList<QString> _tokenStrings; | - | ||||||||||||||||||||||||
| 27 | int yytoken = -1; | - | ||||||||||||||||||||||||
| 28 | QString yytokentext; | - | ||||||||||||||||||||||||
| 29 | - | |||||||||||||||||||||||||
| 30 | void lex() { | - | ||||||||||||||||||||||||
| 31 | if (_tokens.isEmpty()
| 339844-8894968 | ||||||||||||||||||||||||
| 32 | _tokens.append(Lexer::lex()); | - | ||||||||||||||||||||||||
| 33 | _tokenStrings.append(tokenText()); | - | ||||||||||||||||||||||||
| 34 | } executed 8894968 times by 1 test: end of blockExecuted by:
| 8894968 | ||||||||||||||||||||||||
| 35 | - | |||||||||||||||||||||||||
| 36 | yytoken = _tokens.takeFirst(); | - | ||||||||||||||||||||||||
| 37 | yytokentext = _tokenStrings.takeFirst(); | - | ||||||||||||||||||||||||
| 38 | } executed 9234812 times by 1 test: end of blockExecuted by:
| 9234812 | ||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||
| 40 | int lookaheadToken() | - | ||||||||||||||||||||||||
| 41 | { | - | ||||||||||||||||||||||||
| 42 | if (yytoken < 0
| 398546-851740 | ||||||||||||||||||||||||
| 43 | lex(); executed 851740 times by 1 test: lex();Executed by:
| 851740 | ||||||||||||||||||||||||
| 44 | return executed 1250286 times by 1 test: yytoken;return yytoken;Executed by:
executed 1250286 times by 1 test: return yytoken;Executed by:
| 1250286 | ||||||||||||||||||||||||
| 45 | } | - | ||||||||||||||||||||||||
| 46 | - | |||||||||||||||||||||||||
| 47 | void pushToken(int token) | - | ||||||||||||||||||||||||
| 48 | { | - | ||||||||||||||||||||||||
| 49 | _tokens.prepend(yytoken); | - | ||||||||||||||||||||||||
| 50 | _tokenStrings.prepend(yytokentext); | - | ||||||||||||||||||||||||
| 51 | yytoken = token; | - | ||||||||||||||||||||||||
| 52 | yytokentext = QString(); | - | ||||||||||||||||||||||||
| 53 | } executed 48632 times by 1 test: end of blockExecuted by:
| 48632 | ||||||||||||||||||||||||
| 54 | - | |||||||||||||||||||||||||
| 55 | public: | - | ||||||||||||||||||||||||
| 56 | QmlminLexer() | - | ||||||||||||||||||||||||
| 57 | : Lexer(&_engine), _stateStack(128) {} executed 39940 times by 1 test: end of blockExecuted by:
| 39940 | ||||||||||||||||||||||||
| 58 | virtual ~QmlminLexer() {} | - | ||||||||||||||||||||||||
| 59 | - | |||||||||||||||||||||||||
| 60 | QString fileName() const { return executed 76 times by 1 test: _fileName;return _fileName;Executed by:
executed 76 times by 1 test: }return _fileName;Executed by:
| 76 | ||||||||||||||||||||||||
| 61 | - | |||||||||||||||||||||||||
| 62 | bool operator()(const QString &fileName, const QString &code) | - | ||||||||||||||||||||||||
| 63 | { | - | ||||||||||||||||||||||||
| 64 | int startToken = T_FEED_JS_SCRIPT; | - | ||||||||||||||||||||||||
| 65 | const QFileInfo fileInfo(fileName); | - | ||||||||||||||||||||||||
| 66 | if (fileInfo.suffix().toLower() == QLatin1String("qml")
| 10608-29332 | ||||||||||||||||||||||||
| 67 | startToken = T_FEED_UI_PROGRAM; executed 29332 times by 1 test: startToken = T_FEED_UI_PROGRAM;Executed by:
| 29332 | ||||||||||||||||||||||||
| 68 | setCode(code, 1, startToken == T_FEED_UI_PROGRAM); | - | ||||||||||||||||||||||||
| 69 | _fileName = fileName; | - | ||||||||||||||||||||||||
| 70 | _directives.clear(); | - | ||||||||||||||||||||||||
| 71 | return executed 39940 times by 1 test: parse(startToken);return parse(startToken);Executed by:
executed 39940 times by 1 test: return parse(startToken);Executed by:
| 39940 | ||||||||||||||||||||||||
| 72 | } | - | ||||||||||||||||||||||||
| 73 | - | |||||||||||||||||||||||||
| 74 | QString directives() | - | ||||||||||||||||||||||||
| 75 | { | - | ||||||||||||||||||||||||
| 76 | return executed 10586 times by 1 test: _directives;return _directives;Executed by:
executed 10586 times by 1 test: return _directives;Executed by:
| 10586 | ||||||||||||||||||||||||
| 77 | } | - | ||||||||||||||||||||||||
| 78 | - | |||||||||||||||||||||||||
| 79 | - | |||||||||||||||||||||||||
| 80 | - | |||||||||||||||||||||||||
| 81 | - | |||||||||||||||||||||||||
| 82 | void pragmaLibrary() override | - | ||||||||||||||||||||||||
| 83 | { | - | ||||||||||||||||||||||||
| 84 | _directives += QLatin1String(".pragma library\n"); | - | ||||||||||||||||||||||||
| 85 | } executed 178 times by 1 test: end of blockExecuted by:
| 178 | ||||||||||||||||||||||||
| 86 | - | |||||||||||||||||||||||||
| 87 | void importFile(const QString &jsfile, const QString &module, int line, int column) override | - | ||||||||||||||||||||||||
| 88 | { | - | ||||||||||||||||||||||||
| 89 | _directives += QLatin1String(".import"); | - | ||||||||||||||||||||||||
| 90 | _directives += QLatin1Char('"'); | - | ||||||||||||||||||||||||
| 91 | _directives += quote(jsfile); | - | ||||||||||||||||||||||||
| 92 | _directives += QLatin1Char('"'); | - | ||||||||||||||||||||||||
| 93 | _directives += QLatin1String("as "); | - | ||||||||||||||||||||||||
| 94 | _directives += module; | - | ||||||||||||||||||||||||
| 95 | _directives += QLatin1Char('\n'); | - | ||||||||||||||||||||||||
| 96 | (void)line;; | - | ||||||||||||||||||||||||
| 97 | (void)column;; | - | ||||||||||||||||||||||||
| 98 | } executed 872 times by 1 test: end of blockExecuted by:
| 872 | ||||||||||||||||||||||||
| 99 | - | |||||||||||||||||||||||||
| 100 | void importModule(const QString &uri, const QString &version, const QString &module, int line, int column) override | - | ||||||||||||||||||||||||
| 101 | { | - | ||||||||||||||||||||||||
| 102 | _directives += QLatin1String(".import "); | - | ||||||||||||||||||||||||
| 103 | _directives += uri; | - | ||||||||||||||||||||||||
| 104 | _directives += QLatin1Char(' '); | - | ||||||||||||||||||||||||
| 105 | _directives += version; | - | ||||||||||||||||||||||||
| 106 | _directives += QLatin1String(" as "); | - | ||||||||||||||||||||||||
| 107 | _directives += module; | - | ||||||||||||||||||||||||
| 108 | _directives += QLatin1Char('\n'); | - | ||||||||||||||||||||||||
| 109 | (void)line;; | - | ||||||||||||||||||||||||
| 110 | (void)column;; | - | ||||||||||||||||||||||||
| 111 | } executed 312 times by 1 test: end of blockExecuted by:
| 312 | ||||||||||||||||||||||||
| 112 | - | |||||||||||||||||||||||||
| 113 | protected: | - | ||||||||||||||||||||||||
| 114 | virtual bool parse(int startToken) = 0; | - | ||||||||||||||||||||||||
| 115 | - | |||||||||||||||||||||||||
| 116 | static QString quote(const QString &string) | - | ||||||||||||||||||||||||
| 117 | { | - | ||||||||||||||||||||||||
| 118 | QString quotedString; | - | ||||||||||||||||||||||||
| 119 | for (const QChar &ch : string) { | - | ||||||||||||||||||||||||
| 120 | if (ch == QLatin1Char('"')
| 19620-3624962 | ||||||||||||||||||||||||
| 121 | quotedString += QLatin1String("\\\""); executed 19620 times by 1 test: quotedString += QLatin1String("\\\"");Executed by:
| 19620 | ||||||||||||||||||||||||
| 122 | else { | - | ||||||||||||||||||||||||
| 123 | if (ch == QLatin1Char('\\')
executed 2024 times by 1 test: quotedString += QLatin1String("\\\\");Executed by:
| 2024-3622938 | ||||||||||||||||||||||||
| 124 | else if (ch == QLatin1Char('\"')
never executed: quotedString += QLatin1String("\\\""); | 0-3622938 | ||||||||||||||||||||||||
| 125 | else if (ch == QLatin1Char('\b')
executed 28 times by 1 test: quotedString += QLatin1String("\\b");Executed by:
| 28-3622910 | ||||||||||||||||||||||||
| 126 | else if (ch == QLatin1Char('\f')
executed 200 times by 1 test: quotedString += QLatin1String("\\f");Executed by:
| 200-3622710 | ||||||||||||||||||||||||
| 127 | else if (ch == QLatin1Char('\n')
executed 7328 times by 1 test: quotedString += QLatin1String("\\n");Executed by:
| 7328-3615382 | ||||||||||||||||||||||||
| 128 | else if (ch == QLatin1Char('\r')
executed 336 times by 1 test: quotedString += QLatin1String("\\r");Executed by:
| 336-3615046 | ||||||||||||||||||||||||
| 129 | else if (ch == QLatin1Char('\t')
executed 5864 times by 1 test: quotedString += QLatin1String("\\t");Executed by:
| 5864-3609182 | ||||||||||||||||||||||||
| 130 | else if (ch == QLatin1Char('\v')
executed 108 times by 1 test: quotedString += QLatin1String("\\v");Executed by:
| 108-3609074 | ||||||||||||||||||||||||
| 131 | else if (ch == QLatin1Char('\0')
executed 24 times by 1 test: quotedString += QLatin1String("\\0");Executed by:
| 24-3609050 | ||||||||||||||||||||||||
| 132 | else quotedString += ch; executed 3609050 times by 1 test: quotedString += ch;Executed by:
| 3609050 | ||||||||||||||||||||||||
| 133 | } | - | ||||||||||||||||||||||||
| 134 | } | - | ||||||||||||||||||||||||
| 135 | return executed 205310 times by 1 test: quotedString;return quotedString;Executed by:
executed 205310 times by 1 test: return quotedString;Executed by:
| 205310 | ||||||||||||||||||||||||
| 136 | } | - | ||||||||||||||||||||||||
| 137 | - | |||||||||||||||||||||||||
| 138 | bool isIdentChar(const QChar &ch) const | - | ||||||||||||||||||||||||
| 139 | { | - | ||||||||||||||||||||||||
| 140 | if (ch.isLetterOrNumber()
| 1609510-3510010 | ||||||||||||||||||||||||
| 141 | return executed 1609510 times by 1 test: true;return true;Executed by:
executed 1609510 times by 1 test: return true;Executed by:
| 1609510 | ||||||||||||||||||||||||
| 142 | else if (ch == QLatin1Char('_')
| 0-3509546 | ||||||||||||||||||||||||
| 143 | return executed 464 times by 1 test: true;return true;Executed by:
executed 464 times by 1 test: return true;Executed by:
| 464 | ||||||||||||||||||||||||
| 144 | return executed 3509546 times by 1 test: false;return false;Executed by:
executed 3509546 times by 1 test: return false;Executed by:
| 3509546 | ||||||||||||||||||||||||
| 145 | } | - | ||||||||||||||||||||||||
| 146 | - | |||||||||||||||||||||||||
| 147 | bool isRegExpRule(int ruleno) const | - | ||||||||||||||||||||||||
| 148 | { | - | ||||||||||||||||||||||||
| 149 | return executed 60844938 times by 1 test: ruleno == 128 ||return ruleno == 128 || ruleno == 129;Executed by:
executed 60844938 times by 1 test: return ruleno == 128 || ruleno == 129;Executed by:
| 60844938 | ||||||||||||||||||||||||
| 150 | ruleno == 129; executed 60844938 times by 1 test: return ruleno == 128 || ruleno == 129;Executed by:
| 60844938 | ||||||||||||||||||||||||
| 151 | } | - | ||||||||||||||||||||||||
| 152 | - | |||||||||||||||||||||||||
| 153 | void handleLookaheads(int ruleno) { | - | ||||||||||||||||||||||||
| 154 | if (ruleno == 420
| 1250286-59594652 | ||||||||||||||||||||||||
| 155 | int token = lookaheadToken(); | - | ||||||||||||||||||||||||
| 156 | if (token == T_LBRACE
| 33624-1216662 | ||||||||||||||||||||||||
| 157 | pushToken(T_FORCE_BLOCK); executed 33624 times by 1 test: pushToken(T_FORCE_BLOCK);Executed by:
| 33624 | ||||||||||||||||||||||||
| 158 | else if (token == T_FUNCTION
| 0-1201654 | ||||||||||||||||||||||||
| 159 | pushToken(T_FORCE_DECLARATION); executed 15008 times by 1 test: pushToken(T_FORCE_DECLARATION);Executed by:
| 15008 | ||||||||||||||||||||||||
| 160 | } executed 1250286 times by 1 test: else if (ruleno == 498end of blockExecuted by:
| 0-59594652 | ||||||||||||||||||||||||
| 161 | int token = lookaheadToken(); | - | ||||||||||||||||||||||||
| 162 | if (token == T_LBRACE
| 0 | ||||||||||||||||||||||||
| 163 | pushToken(T_FORCE_BLOCK); never executed: pushToken(T_FORCE_BLOCK); | 0 | ||||||||||||||||||||||||
| 164 | } never executed: else if (ruleno == 568end of block
| 0-59594652 | ||||||||||||||||||||||||
| 165 | int token = lookaheadToken(); | - | ||||||||||||||||||||||||
| 166 | if (token == T_FUNCTION
| 0 | ||||||||||||||||||||||||
| 167 | pushToken(T_FORCE_DECLARATION); never executed: pushToken(T_FORCE_DECLARATION); | 0 | ||||||||||||||||||||||||
| 168 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 169 | } executed 60844938 times by 1 test: end of blockExecuted by:
| 60844938 | ||||||||||||||||||||||||
| 170 | - | |||||||||||||||||||||||||
| 171 | bool scanRestOfRegExp(int ruleno, QString *restOfRegExp) | - | ||||||||||||||||||||||||
| 172 | { | - | ||||||||||||||||||||||||
| 173 | if (! scanRegExp(ruleno == 128 ? Lexer::NoPrefix : Lexer::EqualPrefix)
| 0-7464 | ||||||||||||||||||||||||
| 174 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 175 | - | |||||||||||||||||||||||||
| 176 | *restOfRegExp = regExpPattern(); | - | ||||||||||||||||||||||||
| 177 | if (ruleno == 129
| 0-7464 | ||||||||||||||||||||||||
| 178 | ((! restOfRegExp->isEmpty()) ? static_cast<void>(0) : qt_assert("! restOfRegExp->isEmpty()", __FILE__, 215)); | - | ||||||||||||||||||||||||
| 179 | ((restOfRegExp->at(0) == QLatin1Char('=')) ? static_cast<void>(0) : qt_assert("restOfRegExp->at(0) == QLatin1Char('=')", __FILE__, 216)); | - | ||||||||||||||||||||||||
| 180 | *restOfRegExp = restOfRegExp->mid(1); | - | ||||||||||||||||||||||||
| 181 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 182 | *restOfRegExp += QLatin1Char('/'); | - | ||||||||||||||||||||||||
| 183 | const RegExpFlag flags = (RegExpFlag) regExpFlags(); | - | ||||||||||||||||||||||||
| 184 | if (flags & Global
| 992-6472 | ||||||||||||||||||||||||
| 185 | * executed 992 times by 1 test: restOfRegExp += QLatin1Char('g');*restOfRegExp += QLatin1Char('g');Executed by:
executed 992 times by 1 test: *restOfRegExp += QLatin1Char('g');Executed by:
| 992 | ||||||||||||||||||||||||
| 186 | if (flags & IgnoreCase
| 1256-6208 | ||||||||||||||||||||||||
| 187 | * executed 1256 times by 1 test: restOfRegExp += QLatin1Char('i');*restOfRegExp += QLatin1Char('i');Executed by:
executed 1256 times by 1 test: *restOfRegExp += QLatin1Char('i');Executed by:
| 1256 | ||||||||||||||||||||||||
| 188 | if (flags & Multiline
| 888-6576 | ||||||||||||||||||||||||
| 189 | * executed 888 times by 1 test: restOfRegExp += QLatin1Char('m');*restOfRegExp += QLatin1Char('m');Executed by:
executed 888 times by 1 test: *restOfRegExp += QLatin1Char('m');Executed by:
| 888 | ||||||||||||||||||||||||
| 190 | - | |||||||||||||||||||||||||
| 191 | if (regExpFlags() == 0
| 2784-4680 | ||||||||||||||||||||||||
| 192 | - | |||||||||||||||||||||||||
| 193 | - | |||||||||||||||||||||||||
| 194 | - | |||||||||||||||||||||||||
| 195 | *restOfRegExp += QLatin1Char(' '); | - | ||||||||||||||||||||||||
| 196 | } executed 4680 times by 1 test: end of blockExecuted by:
| 4680 | ||||||||||||||||||||||||
| 197 | return executed 7464 times by 1 test: true;return true;Executed by:
executed 7464 times by 1 test: return true;Executed by:
| 7464 | ||||||||||||||||||||||||
| 198 | } | - | ||||||||||||||||||||||||
| 199 | }; | - | ||||||||||||||||||||||||
| 200 | - | |||||||||||||||||||||||||
| 201 | - | |||||||||||||||||||||||||
| 202 | class Minify: public QmlminLexer | - | ||||||||||||||||||||||||
| 203 | { | - | ||||||||||||||||||||||||
| 204 | QString _minifiedCode; | - | ||||||||||||||||||||||||
| 205 | int _maxWidth; | - | ||||||||||||||||||||||||
| 206 | int _width; | - | ||||||||||||||||||||||||
| 207 | - | |||||||||||||||||||||||||
| 208 | public: | - | ||||||||||||||||||||||||
| 209 | Minify(int maxWidth); | - | ||||||||||||||||||||||||
| 210 | - | |||||||||||||||||||||||||
| 211 | QString minifiedCode() const; | - | ||||||||||||||||||||||||
| 212 | - | |||||||||||||||||||||||||
| 213 | protected: | - | ||||||||||||||||||||||||
| 214 | void append(const QString &s); | - | ||||||||||||||||||||||||
| 215 | bool parse(int startToken) override; | - | ||||||||||||||||||||||||
| 216 | void escape(const QChar &ch, QString *out); | - | ||||||||||||||||||||||||
| 217 | }; | - | ||||||||||||||||||||||||
| 218 | - | |||||||||||||||||||||||||
| 219 | Minify::Minify(int maxWidth) | - | ||||||||||||||||||||||||
| 220 | : _maxWidth(maxWidth), _width(0) | - | ||||||||||||||||||||||||
| 221 | { | - | ||||||||||||||||||||||||
| 222 | } executed 20008 times by 1 test: end of blockExecuted by:
| 20008 | ||||||||||||||||||||||||
| 223 | - | |||||||||||||||||||||||||
| 224 | QString Minify::minifiedCode() const | - | ||||||||||||||||||||||||
| 225 | { | - | ||||||||||||||||||||||||
| 226 | return executed 39864 times by 1 test: _minifiedCode;return _minifiedCode;Executed by:
executed 39864 times by 1 test: return _minifiedCode;Executed by:
| 39864 | ||||||||||||||||||||||||
| 227 | } | - | ||||||||||||||||||||||||
| 228 | - | |||||||||||||||||||||||||
| 229 | void Minify::append(const QString &s) | - | ||||||||||||||||||||||||
| 230 | { | - | ||||||||||||||||||||||||
| 231 | if (!s.isEmpty()
| 4892-548296 | ||||||||||||||||||||||||
| 232 | if (_maxWidth
| 0-548296 | ||||||||||||||||||||||||
| 233 | - | |||||||||||||||||||||||||
| 234 | int segmentLength = s.count(); | - | ||||||||||||||||||||||||
| 235 | if (_width
| 19770-528526 | ||||||||||||||||||||||||
| 236 | _minifiedCode.append(QLatin1Char('\n')); | - | ||||||||||||||||||||||||
| 237 | _width = 0; | - | ||||||||||||||||||||||||
| 238 | } executed 177076 times by 1 test: end of blockExecuted by:
| 177076 | ||||||||||||||||||||||||
| 239 | - | |||||||||||||||||||||||||
| 240 | _width += segmentLength; | - | ||||||||||||||||||||||||
| 241 | } executed 548296 times by 1 test: end of blockExecuted by:
| 548296 | ||||||||||||||||||||||||
| 242 | - | |||||||||||||||||||||||||
| 243 | _minifiedCode.append(s); | - | ||||||||||||||||||||||||
| 244 | } executed 548296 times by 1 test: end of blockExecuted by:
| 548296 | ||||||||||||||||||||||||
| 245 | } executed 553188 times by 1 test: end of blockExecuted by:
| 553188 | ||||||||||||||||||||||||
| 246 | - | |||||||||||||||||||||||||
| 247 | void Minify::escape(const QChar &ch, QString *out) | - | ||||||||||||||||||||||||
| 248 | { | - | ||||||||||||||||||||||||
| 249 | out->append(QLatin1String("\\u")); | - | ||||||||||||||||||||||||
| 250 | const QString hx = QString::number(ch.unicode(), 16); | - | ||||||||||||||||||||||||
| 251 | switch (hx.length()) { | - | ||||||||||||||||||||||||
| 252 | case never executed: 1:case 1:never executed: out->append(QLatin1String("000")); break;case 1:never executed: break; | 0 | ||||||||||||||||||||||||
| 253 | case executed 4 times by 1 test: 2:case 2:Executed by:
executed 4 times by 1 test: out->append(QLatin1String("00")); break;case 2:Executed by:
executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||||||||
| 254 | case never executed: 3:case 3:never executed: out->append(QLatin1Char('0')); break;case 3:never executed: break; | 0 | ||||||||||||||||||||||||
| 255 | case never executed: 4:case 4:never executed: break;case 4:never executed: break; | 0 | ||||||||||||||||||||||||
| 256 | default never executed: :default:never executed: ((!"unreachable") ? static_cast<void>(0) : qt_assert("!\"unreachable\"", __FILE__, 293));default: | 0 | ||||||||||||||||||||||||
| 257 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 258 | out->append(hx); | - | ||||||||||||||||||||||||
| 259 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 260 | - | |||||||||||||||||||||||||
| 261 | bool Minify::parse(int startToken) | - | ||||||||||||||||||||||||
| 262 | { | - | ||||||||||||||||||||||||
| 263 | int yyaction = 0; | - | ||||||||||||||||||||||||
| 264 | int yytos = -1; | - | ||||||||||||||||||||||||
| 265 | QString assembled; | - | ||||||||||||||||||||||||
| 266 | - | |||||||||||||||||||||||||
| 267 | _minifiedCode.clear(); | - | ||||||||||||||||||||||||
| 268 | _tokens.append(startToken); | - | ||||||||||||||||||||||||
| 269 | _tokenStrings.append(QString()); | - | ||||||||||||||||||||||||
| 270 | - | |||||||||||||||||||||||||
| 271 | if (startToken == T_FEED_JS_SCRIPT
| 5320-14688 | ||||||||||||||||||||||||
| 272 | - | |||||||||||||||||||||||||
| 273 | DiagnosticMessage error; | - | ||||||||||||||||||||||||
| 274 | if (scanDirectives(this, &error)
| 22-5298 | ||||||||||||||||||||||||
| 275 | - | |||||||||||||||||||||||||
| 276 | append(directives()); | - | ||||||||||||||||||||||||
| 277 | - | |||||||||||||||||||||||||
| 278 | _tokens.append(tokenKind()); | - | ||||||||||||||||||||||||
| 279 | _tokenStrings.append(tokenText()); | - | ||||||||||||||||||||||||
| 280 | } executed 5298 times by 1 test: else {end of blockExecuted by:
| 5298 | ||||||||||||||||||||||||
| 281 | std::cerr << QtPrivate::asString(fileName()).toLocal8Bit().constData() << ':' << tokenStartLine() << ':' | - | ||||||||||||||||||||||||
| 282 | << tokenStartColumn() << ": syntax error" << std::endl; | - | ||||||||||||||||||||||||
| 283 | return executed 22 times by 1 test: false;return false;Executed by:
executed 22 times by 1 test: return false;Executed by:
| 22 | ||||||||||||||||||||||||
| 284 | } | - | ||||||||||||||||||||||||
| 285 | } | - | ||||||||||||||||||||||||
| 286 | - | |||||||||||||||||||||||||
| 287 | do { | - | ||||||||||||||||||||||||
| 288 | if (++
| 8-35040890 | ||||||||||||||||||||||||
| 289 | _stateStack.resize(_stateStack.size() * 2); executed 8 times by 1 test: _stateStack.resize(_stateStack.size() * 2);Executed by:
| 8 | ||||||||||||||||||||||||
| 290 | - | |||||||||||||||||||||||||
| 291 | _stateStack[yytos] = yyaction; | - | ||||||||||||||||||||||||
| 292 | - | |||||||||||||||||||||||||
| 293 | again: code before this statement executed 35040898 times by 1 test: again:Executed by:
| 35040898 | ||||||||||||||||||||||||
| 294 | if (yytoken == -1
| 4191852-21942928 | ||||||||||||||||||||||||
| 295 | lex(); executed 4191852 times by 1 test: lex();Executed by:
| 4191852 | ||||||||||||||||||||||||
| 296 | - | |||||||||||||||||||||||||
| 297 | yyaction = t_action(yyaction, yytoken); | - | ||||||||||||||||||||||||
| 298 | if (yyaction > 0
| 4617682-30543590 | ||||||||||||||||||||||||
| 299 | if (yyaction == ACCEPT_STATE
| 19932-4597750 | ||||||||||||||||||||||||
| 300 | --yytos; | - | ||||||||||||||||||||||||
| 301 | if (!assembled.isEmpty()
| 5276-14656 | ||||||||||||||||||||||||
| 302 | append(assembled); executed 14656 times by 1 test: append(assembled);Executed by:
| 14656 | ||||||||||||||||||||||||
| 303 | return executed 19932 times by 1 test: true;return true;Executed by:
executed 19932 times by 1 test: return true;Executed by:
| 19932 | ||||||||||||||||||||||||
| 304 | } | - | ||||||||||||||||||||||||
| 305 | - | |||||||||||||||||||||||||
| 306 | const QChar lastChar = assembled.isEmpty()
| 39192-4022462 | ||||||||||||||||||||||||
| 307 | : _minifiedCode.at(_minifiedCode.length() - 1)) | - | ||||||||||||||||||||||||
| 308 | : assembled.at(assembled.length() - 1); | - | ||||||||||||||||||||||||
| 309 | - | |||||||||||||||||||||||||
| 310 | if (yytoken == T_SEMICOLON
| 533234-4064516 | ||||||||||||||||||||||||
| 311 | assembled += QLatin1Char(';'); | - | ||||||||||||||||||||||||
| 312 | - | |||||||||||||||||||||||||
| 313 | append(assembled); | - | ||||||||||||||||||||||||
| 314 | assembled.clear(); | - | ||||||||||||||||||||||||
| 315 | - | |||||||||||||||||||||||||
| 316 | } executed 533234 times by 1 test: else if (yytoken == T_PLUSend of blockExecuted by:
| 592-4018228 | ||||||||||||||||||||||||
| 317 | if (lastChar == QLatin1Char(spell[yytoken][0])
| 40-85226 | ||||||||||||||||||||||||
| 318 | - | |||||||||||||||||||||||||
| 319 | assembled += QLatin1Char(' '); | - | ||||||||||||||||||||||||
| 320 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||||||||||||||
| 321 | - | |||||||||||||||||||||||||
| 322 | assembled += QLatin1String(spell[yytoken]); | - | ||||||||||||||||||||||||
| 323 | - | |||||||||||||||||||||||||
| 324 | } executed 85266 times by 1 test: else if (yytoken == T_NUMERIC_LITERALend of blockExecuted by:
| 85266-3584802 | ||||||||||||||||||||||||
| 325 | if (isIdentChar(lastChar)
| 92852-301596 | ||||||||||||||||||||||||
| 326 | assembled += QLatin1Char(' '); executed 92852 times by 1 test: assembled += QLatin1Char(' ');Executed by:
| 92852 | ||||||||||||||||||||||||
| 327 | - | |||||||||||||||||||||||||
| 328 | if (yytokentext.startsWith('.')
| 348-394100 | ||||||||||||||||||||||||
| 329 | assembled += QLatin1Char('0'); executed 348 times by 1 test: assembled += QLatin1Char('0');Executed by:
| 348 | ||||||||||||||||||||||||
| 330 | - | |||||||||||||||||||||||||
| 331 | assembled += yytokentext; | - | ||||||||||||||||||||||||
| 332 | - | |||||||||||||||||||||||||
| 333 | if (assembled.endsWith(QLatin1Char('.'))
| 22-394426 | ||||||||||||||||||||||||
| 334 | assembled += QLatin1Char('0'); executed 22 times by 1 test: assembled += QLatin1Char('0');Executed by:
| 22 | ||||||||||||||||||||||||
| 335 | - | |||||||||||||||||||||||||
| 336 | } executed 394448 times by 1 test: else if (yytoken == T_IDENTIFIERend of blockExecuted by:
| 394448-2352780 | ||||||||||||||||||||||||
| 337 | QString identifier = yytokentext; | - | ||||||||||||||||||||||||
| 338 | - | |||||||||||||||||||||||||
| 339 | if (classify(identifier.constData(), identifier.size(), qmlMode()) != T_IDENTIFIER
| 4-1232018 | ||||||||||||||||||||||||
| 340 | - | |||||||||||||||||||||||||
| 341 | - | |||||||||||||||||||||||||
| 342 | const QChar ch = identifier.at(identifier.length() - 1); | - | ||||||||||||||||||||||||
| 343 | identifier.chop(1); | - | ||||||||||||||||||||||||
| 344 | escape(ch, &identifier); | - | ||||||||||||||||||||||||
| 345 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 346 | - | |||||||||||||||||||||||||
| 347 | if (isIdentChar(lastChar)
| 158358-1073664 | ||||||||||||||||||||||||
| 348 | assembled += QLatin1Char(' '); executed 158358 times by 1 test: assembled += QLatin1Char(' ');Executed by:
| 158358 | ||||||||||||||||||||||||
| 349 | - | |||||||||||||||||||||||||
| 350 | assembled += identifier; | - | ||||||||||||||||||||||||
| 351 | - | |||||||||||||||||||||||||
| 352 | } executed 1232022 times by 1 test: else if (yytoken == T_STRING_LITERALend of blockExecuted by:
| 176-2148518 | ||||||||||||||||||||||||
| 353 | assembled += QLatin1Char('"'); | - | ||||||||||||||||||||||||
| 354 | assembled += quote(yytokentext); | - | ||||||||||||||||||||||||
| 355 | assembled += QLatin1Char('"'); | - | ||||||||||||||||||||||||
| 356 | } executed 204438 times by 1 test: else {end of blockExecuted by:
| 204438 | ||||||||||||||||||||||||
| 357 | if (isIdentChar(lastChar)
| 802234-1346108 | ||||||||||||||||||||||||
| 358 | if (! yytokentext.isEmpty()
| 1400-1344708 | ||||||||||||||||||||||||
| 359 | const QChar ch = yytokentext.at(0); | - | ||||||||||||||||||||||||
| 360 | if (isIdentChar(ch)
| 12656-1332052 | ||||||||||||||||||||||||
| 361 | assembled += QLatin1Char(' '); executed 12656 times by 1 test: assembled += QLatin1Char(' ');Executed by:
| 12656 | ||||||||||||||||||||||||
| 362 | } executed 1344708 times by 1 test: end of blockExecuted by:
| 1344708 | ||||||||||||||||||||||||
| 363 | } executed 1346108 times by 1 test: end of blockExecuted by:
| 1346108 | ||||||||||||||||||||||||
| 364 | assembled += yytokentext; | - | ||||||||||||||||||||||||
| 365 | } executed 2148342 times by 1 test: end of blockExecuted by:
| 2148342 | ||||||||||||||||||||||||
| 366 | yytoken = -1; | - | ||||||||||||||||||||||||
| 367 | } executed 4597750 times by 1 test: else if (yyaction < 0end of blockExecuted by:
| 120428-30423162 | ||||||||||||||||||||||||
| 368 | const int ruleno = -yyaction - 1; | - | ||||||||||||||||||||||||
| 369 | yytos -= rhs[ruleno]; | - | ||||||||||||||||||||||||
| 370 | - | |||||||||||||||||||||||||
| 371 | handleLookaheads(ruleno); | - | ||||||||||||||||||||||||
| 372 | - | |||||||||||||||||||||||||
| 373 | if (isRegExpRule(ruleno)
| 3732-30419430 | ||||||||||||||||||||||||
| 374 | QString restOfRegExp; | - | ||||||||||||||||||||||||
| 375 | - | |||||||||||||||||||||||||
| 376 | if (! scanRestOfRegExp(ruleno, &restOfRegExp)
| 0-3732 | ||||||||||||||||||||||||
| 377 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 378 | - | |||||||||||||||||||||||||
| 379 | assembled += restOfRegExp; | - | ||||||||||||||||||||||||
| 380 | } executed 3732 times by 1 test: end of blockExecuted by:
| 3732 | ||||||||||||||||||||||||
| 381 | yyaction = nt_action(_stateStack[yytos], lhs[ruleno] - TERMINAL_COUNT); | - | ||||||||||||||||||||||||
| 382 | } executed 30423162 times by 1 test: end of blockExecuted by:
| 30423162 | ||||||||||||||||||||||||
| 383 | } executed 35141340 times by 1 test: while (yyactionend of blockExecuted by:
| 120428-35141340 | ||||||||||||||||||||||||
| 384 | - | |||||||||||||||||||||||||
| 385 | const int yyerrorstate = _stateStack[yytos]; | - | ||||||||||||||||||||||||
| 386 | - | |||||||||||||||||||||||||
| 387 | - | |||||||||||||||||||||||||
| 388 | if (yytoken != -1
| 0-120428 | ||||||||||||||||||||||||
| 389 | || t_action(yyerrorstate, T_COMPATIBILITY_SEMICOLON)
| 2-54 | ||||||||||||||||||||||||
| 390 | _tokens.prepend(yytoken); | - | ||||||||||||||||||||||||
| 391 | _tokenStrings.prepend(yytokentext); | - | ||||||||||||||||||||||||
| 392 | yyaction = yyerrorstate; | - | ||||||||||||||||||||||||
| 393 | yytoken = T_SEMICOLON; | - | ||||||||||||||||||||||||
| 394 | goto executed 120374 times by 1 test: again;goto again;Executed by:
executed 120374 times by 1 test: goto again;Executed by:
| 120374 | ||||||||||||||||||||||||
| 395 | } | - | ||||||||||||||||||||||||
| 396 | - | |||||||||||||||||||||||||
| 397 | std::cerr << QtPrivate::asString(fileName()).toLocal8Bit().constData() << ':' << tokenStartLine() << ':' << tokenStartColumn() | - | ||||||||||||||||||||||||
| 398 | << ": syntax error" << std::endl; | - | ||||||||||||||||||||||||
| 399 | return executed 54 times by 1 test: false;return false;Executed by:
executed 54 times by 1 test: return false;Executed by:
| 54 | ||||||||||||||||||||||||
| 400 | } | - | ||||||||||||||||||||||||
| 401 | - | |||||||||||||||||||||||||
| 402 | - | |||||||||||||||||||||||||
| 403 | class Tokenize: public QmlminLexer | - | ||||||||||||||||||||||||
| 404 | { | - | ||||||||||||||||||||||||
| 405 | QStringList _minifiedCode; | - | ||||||||||||||||||||||||
| 406 | - | |||||||||||||||||||||||||
| 407 | public: | - | ||||||||||||||||||||||||
| 408 | Tokenize() {} | - | ||||||||||||||||||||||||
| 409 | - | |||||||||||||||||||||||||
| 410 | QStringList tokenStream() const; | - | ||||||||||||||||||||||||
| 411 | - | |||||||||||||||||||||||||
| 412 | protected: | - | ||||||||||||||||||||||||
| 413 | bool parse(int startToken) override; | - | ||||||||||||||||||||||||
| 414 | }; | - | ||||||||||||||||||||||||
| 415 | - | |||||||||||||||||||||||||
| 416 | QStringList Tokenize::tokenStream() const | - | ||||||||||||||||||||||||
| 417 | { | - | ||||||||||||||||||||||||
| 418 | return executed 19932 times by 1 test: _minifiedCode;return _minifiedCode;Executed by:
executed 19932 times by 1 test: return _minifiedCode;Executed by:
| 19932 | ||||||||||||||||||||||||
| 419 | } | - | ||||||||||||||||||||||||
| 420 | - | |||||||||||||||||||||||||
| 421 | bool Tokenize::parse(int startToken) | - | ||||||||||||||||||||||||
| 422 | { | - | ||||||||||||||||||||||||
| 423 | int yyaction = 0; | - | ||||||||||||||||||||||||
| 424 | int yytos = -1; | - | ||||||||||||||||||||||||
| 425 | - | |||||||||||||||||||||||||
| 426 | _minifiedCode.clear(); | - | ||||||||||||||||||||||||
| 427 | _tokens.append(startToken); | - | ||||||||||||||||||||||||
| 428 | _tokenStrings.append(QString()); | - | ||||||||||||||||||||||||
| 429 | - | |||||||||||||||||||||||||
| 430 | if (startToken == T_FEED_JS_SCRIPT
| 5288-14644 | ||||||||||||||||||||||||
| 431 | - | |||||||||||||||||||||||||
| 432 | DiagnosticMessage error; | - | ||||||||||||||||||||||||
| 433 | if (scanDirectives(this, &error)
| 0-5288 | ||||||||||||||||||||||||
| 434 | - | |||||||||||||||||||||||||
| 435 | - | |||||||||||||||||||||||||
| 436 | _minifiedCode.append(directives()); | - | ||||||||||||||||||||||||
| 437 | - | |||||||||||||||||||||||||
| 438 | _tokens.append(tokenKind()); | - | ||||||||||||||||||||||||
| 439 | _tokenStrings.append(tokenText()); | - | ||||||||||||||||||||||||
| 440 | } executed 5288 times by 1 test: else {end of blockExecuted by:
| 5288 | ||||||||||||||||||||||||
| 441 | std::cerr << QtPrivate::asString(fileName()).toLocal8Bit().constData() << ':' << tokenStartLine() << ':' | - | ||||||||||||||||||||||||
| 442 | << tokenStartColumn() << ": syntax error" << std::endl; | - | ||||||||||||||||||||||||
| 443 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 444 | } | - | ||||||||||||||||||||||||
| 445 | } | - | ||||||||||||||||||||||||
| 446 | - | |||||||||||||||||||||||||
| 447 | do { | - | ||||||||||||||||||||||||
| 448 | if (++
| 8-35038844 | ||||||||||||||||||||||||
| 449 | _stateStack.resize(_stateStack.size() * 2); executed 8 times by 1 test: _stateStack.resize(_stateStack.size() * 2);Executed by:
| 8 | ||||||||||||||||||||||||
| 450 | - | |||||||||||||||||||||||||
| 451 | _stateStack[yytos] = yyaction; | - | ||||||||||||||||||||||||
| 452 | - | |||||||||||||||||||||||||
| 453 | again: code before this statement executed 35038852 times by 1 test: again:Executed by:
| 35038852 | ||||||||||||||||||||||||
| 454 | if (yytoken == -1
| 4191220-21942220 | ||||||||||||||||||||||||
| 455 | lex(); executed 4191220 times by 1 test: lex();Executed by:
| 4191220 | ||||||||||||||||||||||||
| 456 | - | |||||||||||||||||||||||||
| 457 | yyaction = t_action(yyaction, yytoken); | - | ||||||||||||||||||||||||
| 458 | if (yyaction > 0
| 4617076-30542112 | ||||||||||||||||||||||||
| 459 | if (yyaction == ACCEPT_STATE
| 19932-4597144 | ||||||||||||||||||||||||
| 460 | --yytos; | - | ||||||||||||||||||||||||
| 461 | return executed 19932 times by 1 test: true;return true;Executed by:
executed 19932 times by 1 test: return true;Executed by:
| 19932 | ||||||||||||||||||||||||
| 462 | } | - | ||||||||||||||||||||||||
| 463 | - | |||||||||||||||||||||||||
| 464 | if (yytoken == T_SEMICOLON
| 533188-4063956 | ||||||||||||||||||||||||
| 465 | _minifiedCode += QLatin1String(";"); executed 533188 times by 1 test: _minifiedCode += QLatin1String(";");Executed by:
| 533188 | ||||||||||||||||||||||||
| 466 | else | - | ||||||||||||||||||||||||
| 467 | _minifiedCode += yytokentext; executed 4063956 times by 1 test: _minifiedCode += yytokentext;Executed by:
| 4063956 | ||||||||||||||||||||||||
| 468 | - | |||||||||||||||||||||||||
| 469 | yytoken = -1; | - | ||||||||||||||||||||||||
| 470 | } executed 4597144 times by 1 test: else if (yyaction < 0end of blockExecuted by:
| 120336-30421776 | ||||||||||||||||||||||||
| 471 | const int ruleno = -yyaction - 1; | - | ||||||||||||||||||||||||
| 472 | yytos -= rhs[ruleno]; | - | ||||||||||||||||||||||||
| 473 | - | |||||||||||||||||||||||||
| 474 | handleLookaheads(ruleno); | - | ||||||||||||||||||||||||
| 475 | - | |||||||||||||||||||||||||
| 476 | if (isRegExpRule(ruleno)
| 3732-30418044 | ||||||||||||||||||||||||
| 477 | QString restOfRegExp; | - | ||||||||||||||||||||||||
| 478 | - | |||||||||||||||||||||||||
| 479 | if (! scanRestOfRegExp(ruleno, &restOfRegExp)
| 0-3732 | ||||||||||||||||||||||||
| 480 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 481 | - | |||||||||||||||||||||||||
| 482 | _minifiedCode.last().append(restOfRegExp); | - | ||||||||||||||||||||||||
| 483 | } executed 3732 times by 1 test: end of blockExecuted by:
| 3732 | ||||||||||||||||||||||||
| 484 | - | |||||||||||||||||||||||||
| 485 | yyaction = nt_action(_stateStack[yytos], lhs[ruleno] - TERMINAL_COUNT); | - | ||||||||||||||||||||||||
| 486 | } executed 30421776 times by 1 test: end of blockExecuted by:
| 30421776 | ||||||||||||||||||||||||
| 487 | } executed 35139256 times by 1 test: while (yyactionend of blockExecuted by:
| 120336-35139256 | ||||||||||||||||||||||||
| 488 | - | |||||||||||||||||||||||||
| 489 | const int yyerrorstate = _stateStack[yytos]; | - | ||||||||||||||||||||||||
| 490 | - | |||||||||||||||||||||||||
| 491 | - | |||||||||||||||||||||||||
| 492 | if (yytoken != -1
| 0-120336 | ||||||||||||||||||||||||
| 493 | || t_action(yyerrorstate, T_COMPATIBILITY_SEMICOLON)
| 0-2 | ||||||||||||||||||||||||
| 494 | _tokens.prepend(yytoken); | - | ||||||||||||||||||||||||
| 495 | _tokenStrings.prepend(yytokentext); | - | ||||||||||||||||||||||||
| 496 | yyaction = yyerrorstate; | - | ||||||||||||||||||||||||
| 497 | yytoken = T_SEMICOLON; | - | ||||||||||||||||||||||||
| 498 | goto executed 120336 times by 1 test: again;goto again;Executed by:
executed 120336 times by 1 test: goto again;Executed by:
| 120336 | ||||||||||||||||||||||||
| 499 | } | - | ||||||||||||||||||||||||
| 500 | - | |||||||||||||||||||||||||
| 501 | std::cerr << QtPrivate::asString(fileName()).toLocal8Bit().constData() << ':' << tokenStartLine() << ':' | - | ||||||||||||||||||||||||
| 502 | << tokenStartColumn() << ": syntax error" << std::endl; | - | ||||||||||||||||||||||||
| 503 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 504 | } | - | ||||||||||||||||||||||||
| 505 | - | |||||||||||||||||||||||||
| 506 | } | - | ||||||||||||||||||||||||
| 507 | - | |||||||||||||||||||||||||
| 508 | static void usage(bool showHelp = false) | - | ||||||||||||||||||||||||
| 509 | { | - | ||||||||||||||||||||||||
| 510 | std::cerr << "Usage: qmlmin [options] file" << std::endl; | - | ||||||||||||||||||||||||
| 511 | - | |||||||||||||||||||||||||
| 512 | if (showHelp
| 0 | ||||||||||||||||||||||||
| 513 | std::cerr << " Removes comments and layout characters" << std::endl | - | ||||||||||||||||||||||||
| 514 | << " The options are:" << std::endl | - | ||||||||||||||||||||||||
| 515 | << " -o<file> write output to file rather than stdout" << std::endl | - | ||||||||||||||||||||||||
| 516 | << " -v --verify-only just run the verifier, no output" << std::endl | - | ||||||||||||||||||||||||
| 517 | << " -w<width> restrict line characters to width" << std::endl | - | ||||||||||||||||||||||||
| 518 | << " -h display this output" << std::endl; | - | ||||||||||||||||||||||||
| 519 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 520 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 521 | - | |||||||||||||||||||||||||
| 522 | int runQmlmin(int argc, char *argv[]) | - | ||||||||||||||||||||||||
| 523 | { | - | ||||||||||||||||||||||||
| 524 | QCoreApplication app(argc, argv); | - | ||||||||||||||||||||||||
| 525 | QCoreApplication::setApplicationVersion(QLatin1String("5.12.0")); | - | ||||||||||||||||||||||||
| 526 | - | |||||||||||||||||||||||||
| 527 | const QStringList args = app.arguments(); | - | ||||||||||||||||||||||||
| 528 | - | |||||||||||||||||||||||||
| 529 | QString fileName; | - | ||||||||||||||||||||||||
| 530 | QString outputFile; | - | ||||||||||||||||||||||||
| 531 | bool verifyOnly = false; | - | ||||||||||||||||||||||||
| 532 | - | |||||||||||||||||||||||||
| 533 | - | |||||||||||||||||||||||||
| 534 | int width = | - | ||||||||||||||||||||||||
| 535 | (0x7fff * 2 + 1) | - | ||||||||||||||||||||||||
| 536 | ; | - | ||||||||||||||||||||||||
| 537 | - | |||||||||||||||||||||||||
| 538 | int index = 1; | - | ||||||||||||||||||||||||
| 539 | while (index < args.size()
| 10042-30126 | ||||||||||||||||||||||||
| 540 | const QString arg = args.at(index++); | - | ||||||||||||||||||||||||
| 541 | const QString next = index < args.size()
| 10042-20084 | ||||||||||||||||||||||||
| 542 | - | |||||||||||||||||||||||||
| 543 | if (arg == QLatin1String("-h")
| 0-30126 | ||||||||||||||||||||||||
| 544 | usage( true); | - | ||||||||||||||||||||||||
| 545 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||||||||
| 546 | } else if (arg == QLatin1String("-v")
| 0-30126 | ||||||||||||||||||||||||
| 547 | verifyOnly = true; | - | ||||||||||||||||||||||||
| 548 | } executed 10042 times by 1 test: else if (arg == QLatin1String("-o")end of blockExecuted by:
| 0-20084 | ||||||||||||||||||||||||
| 549 | if (next.isEmpty()
| 0 | ||||||||||||||||||||||||
| 550 | std::cerr << "qmlmin: argument to '-o' is missing" << std::endl; | - | ||||||||||||||||||||||||
| 551 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 552 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 553 | ; never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 554 | } else { | - | ||||||||||||||||||||||||
| 555 | outputFile = next; | - | ||||||||||||||||||||||||
| 556 | ++index; | - | ||||||||||||||||||||||||
| 557 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 558 | } else if (arg.startsWith(QLatin1String("-o"))
| 0-20084 | ||||||||||||||||||||||||
| 559 | outputFile = arg.mid(2); | - | ||||||||||||||||||||||||
| 560 | - | |||||||||||||||||||||||||
| 561 | if (outputFile.isEmpty()
| 0 | ||||||||||||||||||||||||
| 562 | std::cerr << "qmlmin: argument to '-o' is missing" << std::endl; | - | ||||||||||||||||||||||||
| 563 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 564 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 565 | ; never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 566 | } | - | ||||||||||||||||||||||||
| 567 | } never executed: else if (arg == QLatin1String("-w")end of block
| 0-20084 | ||||||||||||||||||||||||
| 568 | if (next.isEmpty()
| 0 | ||||||||||||||||||||||||
| 569 | std::cerr << "qmlmin: argument to '-w' is missing" << std::endl; | - | ||||||||||||||||||||||||
| 570 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 571 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 572 | ; never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 573 | } else { | - | ||||||||||||||||||||||||
| 574 | bool ok; | - | ||||||||||||||||||||||||
| 575 | width = next.toInt(&ok); | - | ||||||||||||||||||||||||
| 576 | - | |||||||||||||||||||||||||
| 577 | if (!ok
| 0 | ||||||||||||||||||||||||
| 578 | std::cerr << "qmlmin: argument to '-w' is invalid" << std::endl; | - | ||||||||||||||||||||||||
| 579 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 580 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 581 | ; never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 582 | } | - | ||||||||||||||||||||||||
| 583 | - | |||||||||||||||||||||||||
| 584 | ++index; | - | ||||||||||||||||||||||||
| 585 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 586 | } else if (arg.startsWith(QLatin1String("-w"))
| 10042 | ||||||||||||||||||||||||
| 587 | bool ok; | - | ||||||||||||||||||||||||
| 588 | width = arg.midRef(2).toInt(&ok); | - | ||||||||||||||||||||||||
| 589 | - | |||||||||||||||||||||||||
| 590 | if (!ok
| 0-10042 | ||||||||||||||||||||||||
| 591 | std::cerr << "qmlmin: argument to '-w' is invalid" << std::endl; | - | ||||||||||||||||||||||||
| 592 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 593 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 594 | ; never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 595 | } | - | ||||||||||||||||||||||||
| 596 | } executed 10042 times by 1 test: else {end of blockExecuted by:
| 10042 | ||||||||||||||||||||||||
| 597 | const bool isInvalidOpt = arg.startsWith(QLatin1Char('-')); | - | ||||||||||||||||||||||||
| 598 | if (! isInvalidOpt
| 0-10042 | ||||||||||||||||||||||||
| 599 | fileName = arg; executed 10042 times by 1 test: fileName = arg;Executed by:
| 10042 | ||||||||||||||||||||||||
| 600 | else { | - | ||||||||||||||||||||||||
| 601 | usage( isInvalidOpt); | - | ||||||||||||||||||||||||
| 602 | if (isInvalidOpt
| 0 | ||||||||||||||||||||||||
| 603 | std::cerr << "qmlmin: invalid option '" << QtPrivate::asString(arg).toLocal8Bit().constData() << '\'' << std::endl; never executed: std::cerr << "qmlmin: invalid option '" << QtPrivate::asString(arg).toLocal8Bit().constData() << '\'' << std::endl; | 0 | ||||||||||||||||||||||||
| 604 | else | - | ||||||||||||||||||||||||
| 605 | std::cerr << "qmlmin: too many input files specified" << std::endl; never executed: std::cerr << "qmlmin: too many input files specified" << std::endl; | 0 | ||||||||||||||||||||||||
| 606 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 607 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 608 | ; never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 609 | } | - | ||||||||||||||||||||||||
| 610 | } | - | ||||||||||||||||||||||||
| 611 | } | - | ||||||||||||||||||||||||
| 612 | - | |||||||||||||||||||||||||
| 613 | if (fileName.isEmpty()
| 0-10042 | ||||||||||||||||||||||||
| 614 | usage(); | - | ||||||||||||||||||||||||
| 615 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||||||||
| 616 | } | - | ||||||||||||||||||||||||
| 617 | - | |||||||||||||||||||||||||
| 618 | QFile file(fileName); | - | ||||||||||||||||||||||||
| 619 | if (! file.open(QFile::ReadOnly)
| 0-10042 | ||||||||||||||||||||||||
| 620 | std::cerr << "qmlmin: '" << QtPrivate::asString(fileName).toLocal8Bit().constData() << "' no such file or directory" << std::endl; | - | ||||||||||||||||||||||||
| 621 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 622 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 623 | ; never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 624 | } | - | ||||||||||||||||||||||||
| 625 | - | |||||||||||||||||||||||||
| 626 | const QString code = QString::fromUtf8(file.readAll()); | - | ||||||||||||||||||||||||
| 627 | file.close(); | - | ||||||||||||||||||||||||
| 628 | - | |||||||||||||||||||||||||
| 629 | QQmlJS::Minify minify(width); | - | ||||||||||||||||||||||||
| 630 | if (! minify(fileName, code)
| 76-9966 | ||||||||||||||||||||||||
| 631 | std::cerr << "qmlmin: cannot minify '" << QtPrivate::asString(fileName).toLocal8Bit().constData() << "' (not a valid QML/JS file)" << std::endl; | - | ||||||||||||||||||||||||
| 632 | return executed 76 times by 1 test: return 1 ;Executed by:
executed 76 times by 1 test: return 1 ;Executed by:
| 76 | ||||||||||||||||||||||||
| 633 | 1 executed 76 times by 1 test: return 1 ;Executed by:
| 76 | ||||||||||||||||||||||||
| 634 | ; executed 76 times by 1 test: return 1 ;Executed by:
| 76 | ||||||||||||||||||||||||
| 635 | } | - | ||||||||||||||||||||||||
| 636 | - | |||||||||||||||||||||||||
| 637 | - | |||||||||||||||||||||||||
| 638 | - | |||||||||||||||||||||||||
| 639 | - | |||||||||||||||||||||||||
| 640 | QQmlJS::Minify secondMinify(width); | - | ||||||||||||||||||||||||
| 641 | if (! secondMinify(fileName, minify.minifiedCode())
| 0-9966 | ||||||||||||||||||||||||
| 642 | std::cerr << "qmlmin: cannot minify '" << QtPrivate::asString(fileName).toLocal8Bit().constData() << '\'' << std::endl; | - | ||||||||||||||||||||||||
| 643 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 644 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 645 | ; never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 646 | } | - | ||||||||||||||||||||||||
| 647 | - | |||||||||||||||||||||||||
| 648 | QQmlJS::Tokenize originalTokens, minimizedTokens; | - | ||||||||||||||||||||||||
| 649 | originalTokens(fileName, code); | - | ||||||||||||||||||||||||
| 650 | minimizedTokens(fileName, minify.minifiedCode()); | - | ||||||||||||||||||||||||
| 651 | - | |||||||||||||||||||||||||
| 652 | if (originalTokens.tokenStream().size() != minimizedTokens.tokenStream().size()
| 0-9966 | ||||||||||||||||||||||||
| 653 | std::cerr << "qmlmin: cannot minify '" << QtPrivate::asString(fileName).toLocal8Bit().constData() << '\'' << std::endl; | - | ||||||||||||||||||||||||
| 654 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 655 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 656 | ; never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 657 | } | - | ||||||||||||||||||||||||
| 658 | - | |||||||||||||||||||||||||
| 659 | if (! verifyOnly
| 0-9966 | ||||||||||||||||||||||||
| 660 | if (outputFile.isEmpty()
| 0 | ||||||||||||||||||||||||
| 661 | const QByteArray chars = minify.minifiedCode().toUtf8(); | - | ||||||||||||||||||||||||
| 662 | std::cout << chars.constData(); | - | ||||||||||||||||||||||||
| 663 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||
| 664 | QFile file(outputFile); | - | ||||||||||||||||||||||||
| 665 | if (! file.open(QFile::WriteOnly)
| 0 | ||||||||||||||||||||||||
| 666 | std::cerr << "qmlmin: cannot minify '" << QtPrivate::asString(fileName).toLocal8Bit().constData() << "' (permission denied)" << std::endl; | - | ||||||||||||||||||||||||
| 667 | return never executed: return 1 ;never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 668 | 1 never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 669 | ; never executed: return 1 ; | 0 | ||||||||||||||||||||||||
| 670 | } | - | ||||||||||||||||||||||||
| 671 | - | |||||||||||||||||||||||||
| 672 | file.write(minify.minifiedCode().toUtf8()); | - | ||||||||||||||||||||||||
| 673 | file.close(); | - | ||||||||||||||||||||||||
| 674 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 675 | } | - | ||||||||||||||||||||||||
| 676 | - | |||||||||||||||||||||||||
| 677 | return executed 9966 times by 1 test: 0;return 0;Executed by:
executed 9966 times by 1 test: return 0;Executed by:
| 9966 | ||||||||||||||||||||||||
| 678 | } | - | ||||||||||||||||||||||||
| 679 | - | |||||||||||||||||||||||||
| 680 | - | |||||||||||||||||||||||||
| 681 | - | |||||||||||||||||||||||||
| 682 | int main(int argc, char **argv) | - | ||||||||||||||||||||||||
| 683 | { | - | ||||||||||||||||||||||||
| 684 | return executed 10042 times by 1 test: ::runQmlmin(argc, argv);return ::runQmlmin(argc, argv);Executed by:
executed 10042 times by 1 test: return ::runQmlmin(argc, argv);Executed by:
| 10042 | ||||||||||||||||||||||||
| 685 | } | - | ||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |