OpenCoverage

main.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/tools/qmllint/main.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Sergio Martins <sergio.martins@kdab.com>-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the plugins 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 <QDebug>-
30#include <QFile>-
31#include <QFileInfo>-
32#if QT_CONFIG(commandlineparser)-
33#include <QCommandLineParser>-
34#endif-
35#include <QCoreApplication>-
36-
37#include <private/qv4value_p.h>-
38#include <private/qqmljslexer_p.h>-
39#include <private/qqmljsparser_p.h>-
40#include <private/qqmljsengine_p.h>-
41-
42static bool lint_file(const QString &filename, bool silent)-
43{-
44 QFile file(filename);-
45 if (!file.open(QFile::ReadOnly)) {
!file.open(QFile::ReadOnly)Description
TRUEnever evaluated
FALSEnever evaluated
0
46 qWarning() << "Failed to open file" << filename << file.error();-
47 return false;
never executed: return false;
0
48 }-
49-
50 QString code = QString::fromUtf8(file.readAll());-
51 file.close();-
52-
53 QQmlJS::Engine engine;-
54 QQmlJS::Lexer lexer(&engine);-
55-
56 QFileInfo info(filename);-
57 bool isJavaScript = info.suffix().toLower() == QLatin1String("js");-
58 lexer.setCode(code, /*line = */ 1, /*qmlMode=*/ !isJavaScript);-
59 QQmlJS::Parser parser(&engine);-
60-
61 bool success = isJavaScript ? parser.parseProgram() : parser.parse();
isJavaScriptDescription
TRUEnever evaluated
FALSEnever evaluated
0
62-
63 if (!success && !silent) {
!successDescription
TRUEnever evaluated
FALSEnever evaluated
!silentDescription
TRUEnever evaluated
FALSEnever evaluated
0
64 const auto diagnosticMessages = parser.diagnosticMessages();-
65 for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) {-
66 qWarning("%s:%d : %s", qPrintable(filename), m.loc.startLine, qPrintable(m.message));-
67 }
never executed: end of block
0
68 }
never executed: end of block
0
69-
70 return success;
never executed: return success;
0
71}-
72-
73int main(int argv, char *argc[])-
74{-
75 QCoreApplication app(argv, argc);-
76 QCoreApplication::setApplicationName("qmllint");-
77 QCoreApplication::setApplicationVersion("1.0");-
78#if QT_CONFIG(commandlineparser)-
79 QCommandLineParser parser;-
80 parser.setApplicationDescription(QLatin1String("QML syntax verifier"));-
81 parser.addHelpOption();-
82 parser.addVersionOption();-
83 QCommandLineOption silentOption(QStringList() << "s" << "silent", QLatin1String("Don't output syntax errors"));-
84 parser.addOption(silentOption);-
85 parser.addPositionalArgument(QLatin1String("files"), QLatin1String("list of qml or js files to verify"));-
86-
87 parser.process(app);-
88-
89 const auto positionalArguments = parser.positionalArguments();-
90 if (positionalArguments.isEmpty()) {
positionalArguments.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
91 parser.showHelp(-1);-
92 }
never executed: end of block
0
93-
94 bool silent = parser.isSet(silentOption);-
95#else-
96 bool silent = false;-
97#endif-
98 bool success = true;-
99#if QT_CONFIG(commandlineparser)-
100 for (const QString &filename : positionalArguments)-
101#else-
102 const auto arguments = app.arguments();-
103 for (const QString &filename : arguments)-
104#endif-
105 success &= lint_file(filename, silent);
never executed: success &= lint_file(filename, silent);
0
106-
107 return success ? 0 : -1;
never executed: return success ? 0 : -1;
0
108}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0