OpenCoverage

main.cpp

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

Generated by Squish Coco 4.2.0