10#include <private/qqmljsast_p.h>
17
18
25
26
27
30 return QStringList() <<
"*.qml";
34
35
36
37
38
39
42 static const QSet<QString> topic_commands{
50 if (!in.open(QIODevice::ReadOnly)) {
51 location.error(QStringLiteral(
"Cannot open QML file '%1'").arg(filePath));
55 QString document = in.readAll();
58 QString newCode = document;
61 QQmlJS::Engine engine{};
62 QQmlJS::Lexer lexer{&engine};
63 lexer.setCode(newCode, 1);
65 QQmlJS::Parser parser{&engine};
68 QQmlJS::AST::UiProgram *ast = parser.ast();
69 QmlDocVisitor visitor(filePath, newCode, &engine, topic_commands + CodeParser::common_meta_commands,
71 QQmlJS::AST::Node::accept(ast, &visitor);
73 Location(filePath).warning(
"Could not analyze QML file, output is incomplete.");
75 const auto &messages = parser.diagnosticMessages();
76 for (
const auto &msg : messages) {
77 qCDebug(lcQdoc,
"%s: %d: %d: QML syntax error: %s", qUtf8Printable(filePath),
78 msg.loc.startLine, msg.loc.startColumn, qUtf8Printable(msg.message));
83
84
85
86
89 QChar *data = str.data() + idx;
90 const QChar space(QLatin1Char(
' '));
91 for (
int ii = 0; ii < n; ++ii)
96
97
98
99
100
101
104 const QString pragma(QLatin1String(
"pragma"));
106 QQmlJS::Lexer l(
nullptr);
107 l.setCode(script, 0);
112 if (token != QQmlJSGrammar::T_DOT)
115 int startOffset = l.tokenOffset();
116 int startLine = l.tokenStartLine();
120 if (token != QQmlJSGrammar::T_IDENTIFIER || l.tokenStartLine() != startLine
121 || script.mid(l.tokenOffset(), l.tokenLength()) != pragma)
126 if (token != QQmlJSGrammar::T_IDENTIFIER || l.tokenStartLine() != startLine)
129 QString pragmaValue = script.mid(l.tokenOffset(), l.tokenLength());
130 int endOffset = l.tokenLength() + l.tokenOffset();
133 if (l.tokenStartLine() == startLine)
136 if (pragmaValue == QLatin1String(
"library"))
The Location class provides a way to mark a location in a file.
QString language() override
Returns "QML".
QStringList sourceFileNameFilter() override
Returns a string list containing "*.qml".
void parseSourceFile(const Location &location, const QString &filePath, CppCodeParser &) override
Parses the source file at filePath and inserts the contents into the database.
void extractPragmas(QString &script)
Copy & paste from src/declarative/qml/qdeclarativescriptparser.cpp, then modified to return no values...
#define COMMAND_QMLSIGNAL
#define COMMAND_QMLPROPERTYGROUP
#define COMMAND_QMLPROPERTY
#define COMMAND_QMLATTACHEDPROPERTY
#define COMMAND_QMLBASICTYPE
#define COMMAND_QMLMETHOD
#define COMMAND_QMLVALUETYPE
#define COMMAND_QMLATTACHEDMETHOD
#define COMMAND_QMLATTACHEDSIGNAL
Combined button and popup list for selecting options.
void replaceWithSpace(QString &str, int idx, int n)
Copy and paste from src/declarative/qml/qdeclarativescriptparser.cpp.