1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQMLCUSTOMPARSER_H
5#define QQMLCUSTOMPARSER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQml/qqmlerror.h>
19#include <QtQml/private/qqmlbinding_p.h>
20#include <private/qv4compileddata_p.h>
21
22#include <QtCore/qbytearray.h>
23
24QT_BEGIN_NAMESPACE
25
26class QQmlPropertyValidator;
27class QQmlEnginePrivate;
28
29class Q_QML_PRIVATE_EXPORT QQmlCustomParser
30{
31public:
32 enum Flag {
33 NoFlag = 0x00000000,
34 AcceptsAttachedProperties = 0x00000001,
35 AcceptsSignalHandlers = 0x00000002
36 };
37 Q_DECLARE_FLAGS(Flags, Flag)
38
39 QQmlCustomParser() : engine(nullptr), validator(nullptr), m_flags(NoFlag) {}
40 QQmlCustomParser(Flags f) : engine(nullptr), validator(nullptr), m_flags(f) {}
41 virtual ~QQmlCustomParser() {}
42
43 void clearErrors();
44 Flags flags() const { return m_flags; }
45
46 virtual void verifyBindings(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &, const QList<const QV4::CompiledData::Binding *> &) = 0;
47 virtual void applyBindings(QObject *, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &, const QList<const QV4::CompiledData::Binding *> &) = 0;
48
49 QVector<QQmlError> errors() const { return exceptions; }
50
51protected:
52 void error(const QV4::CompiledData::Binding *binding, const QString& description)
53 { error(location: binding->location, description); }
54 void error(const QV4::CompiledData::Object *object, const QString& description)
55 { error(location: object->location, description); }
56 void error(const QV4::CompiledData::Location &location, const QString& description);
57
58 int evaluateEnum(const QString &, bool *ok) const;
59
60 const QMetaObject *resolveType(const QString&) const;
61
62private:
63 QVector<QQmlError> exceptions;
64 QQmlEnginePrivate *engine;
65 const QQmlPropertyValidator *validator;
66 Flags m_flags;
67 QBiPointer<const QQmlImports, QQmlTypeNameCache> imports;
68 friend class QQmlPropertyValidator;
69 friend class QQmlObjectCreator;
70};
71Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlCustomParser::Flags)
72
73QT_END_NAMESPACE
74
75#endif
76

source code of qtdeclarative/src/qml/qml/qqmlcustomparser_p.h