| 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:LGPL$ | 
| 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 Lesser General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | 
| 21 | ** packaging of this file. Please review the following information to | 
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | 
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | 
| 24 | ** | 
| 25 | ** GNU General Public License Usage | 
| 26 | ** Alternatively, this file may be used under the terms of the GNU | 
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | 
| 28 | ** Public license version 3 or any later version approved by the KDE Free | 
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | 
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | 
| 31 | ** included in the packaging of this file. Please review the following | 
| 32 | ** information to ensure the GNU General Public License requirements will | 
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | 
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | 
| 35 | ** | 
| 36 | ** $QT_END_LICENSE$ | 
| 37 | ** | 
| 38 | ****************************************************************************/ | 
| 39 | #ifndef QV4COMPILER_P_H | 
| 40 | #define QV4COMPILER_P_H | 
| 41 |  | 
| 42 | // | 
| 43 | //  W A R N I N G | 
| 44 | //  ------------- | 
| 45 | // | 
| 46 | // This file is not part of the Qt API.  It exists purely as an | 
| 47 | // implementation detail.  This header file may change from version to | 
| 48 | // version without notice, or even be removed. | 
| 49 | // | 
| 50 | // We mean it. | 
| 51 | // | 
| 52 |  | 
| 53 | #include <QtCore/qstring.h> | 
| 54 | #include <QtCore/qhash.h> | 
| 55 | #include <QtCore/qstringlist.h> | 
| 56 | #include <private/qv4compilerglobal_p.h> | 
| 57 | #include <private/qqmljsastfwd_p.h> | 
| 58 | #include <private/qv4compileddata_p.h> | 
| 59 | #include <private/qv4staticvalue_p.h> | 
| 60 |  | 
| 61 | QT_BEGIN_NAMESPACE | 
| 62 |  | 
| 63 | class QQmlPropertyData; | 
| 64 |  | 
| 65 | namespace QV4 { | 
| 66 |  | 
| 67 | namespace CompiledData { | 
| 68 | struct Unit; | 
| 69 | struct Lookup; | 
| 70 | struct RegExp; | 
| 71 | struct JSClassMember; | 
| 72 | } | 
| 73 |  | 
| 74 | namespace Compiler { | 
| 75 |  | 
| 76 | struct Context; | 
| 77 | struct Module; | 
| 78 | struct Class; | 
| 79 | struct TemplateObject; | 
| 80 |  | 
| 81 | struct Q_QMLCOMPILER_PRIVATE_EXPORT StringTableGenerator { | 
| 82 |     StringTableGenerator(); | 
| 83 |  | 
| 84 |     int registerString(const QString &str); | 
| 85 |     int getStringId(const QString &string) const; | 
| 86 |     QString stringForIndex(int index) const { return strings.at(i: index); } | 
| 87 |     uint stringCount() const { return strings.size() - backingUnitTableSize; } | 
| 88 |  | 
| 89 |     uint sizeOfTableAndData() const { return stringDataSize + ((stringCount() * sizeof(uint) + 7) & ~7); } | 
| 90 |  | 
| 91 |     void freeze() { frozen = true; } | 
| 92 |  | 
| 93 |     void clear(); | 
| 94 |  | 
| 95 |     void initializeFromBackingUnit(const CompiledData::Unit *unit); | 
| 96 |  | 
| 97 |     void serialize(CompiledData::Unit *unit); | 
| 98 |     QStringList allStrings() const { return strings.mid(pos: backingUnitTableSize); } | 
| 99 |  | 
| 100 | private: | 
| 101 |     QHash<QString, int> stringToId; | 
| 102 |     QStringList strings; | 
| 103 |     uint stringDataSize; | 
| 104 |     uint backingUnitTableSize = 0; | 
| 105 |     bool frozen = false; | 
| 106 | }; | 
| 107 |  | 
| 108 | struct Q_QMLCOMPILER_PRIVATE_EXPORT JSUnitGenerator { | 
| 109 |     static void generateUnitChecksum(CompiledData::Unit *unit); | 
| 110 |  | 
| 111 |     struct MemberInfo { | 
| 112 |         QString name; | 
| 113 |         bool isAccessor; | 
| 114 |     }; | 
| 115 |  | 
| 116 |     JSUnitGenerator(Module *module); | 
| 117 |  | 
| 118 |     int registerString(const QString &str) { return stringTable.registerString(str); } | 
| 119 |     int getStringId(const QString &string) const { return stringTable.getStringId(string); } | 
| 120 |     QString stringForIndex(int index) const { return stringTable.stringForIndex(index); } | 
| 121 |  | 
| 122 |     int registerGetterLookup(const QString &name); | 
| 123 |     int registerGetterLookup(int nameIndex); | 
| 124 |     int registerSetterLookup(const QString &name); | 
| 125 |     int registerSetterLookup(int nameIndex); | 
| 126 |     int registerGlobalGetterLookup(int nameIndex); | 
| 127 |     int registerQmlContextPropertyGetterLookup(int nameIndex); | 
| 128 |  | 
| 129 |     int registerRegExp(QQmlJS::AST::RegExpLiteral *regexp); | 
| 130 |  | 
| 131 |     int registerConstant(ReturnedValue v); | 
| 132 |     ReturnedValue constant(int idx); | 
| 133 |  | 
| 134 |     int registerJSClass(const QStringList &members); | 
| 135 |  | 
| 136 |     int registerTranslation(const CompiledData::TranslationData &translation); | 
| 137 |  | 
| 138 |     enum GeneratorOption { | 
| 139 |         GenerateWithStringTable, | 
| 140 |         GenerateWithoutStringTable | 
| 141 |     }; | 
| 142 |  | 
| 143 |     QV4::CompiledData::Unit *generateUnit(GeneratorOption option = GenerateWithStringTable); | 
| 144 |     void writeFunction(char *f, Context *irFunction) const; | 
| 145 |     void writeClass(char *f, const Class &c); | 
| 146 |     void writeTemplateObject(char *f, const TemplateObject &o); | 
| 147 |     void writeBlock(char *f, Context *irBlock) const; | 
| 148 |  | 
| 149 |     StringTableGenerator stringTable; | 
| 150 |     QString codeGeneratorName; | 
| 151 | private: | 
| 152 |     CompiledData::Unit (GeneratorOption option, quint32_le *functionOffsets, uint *jsClassDataOffset); | 
| 153 |  | 
| 154 |     Module *module; | 
| 155 |  | 
| 156 |     QList<CompiledData::Lookup> lookups; | 
| 157 |     QVector<CompiledData::RegExp> regexps; | 
| 158 |     QVector<ReturnedValue> constants; | 
| 159 |     QByteArray jsClassData; | 
| 160 |     QVector<int> jsClassOffsets; | 
| 161 |     QVector<CompiledData::TranslationData> translations; | 
| 162 | }; | 
| 163 |  | 
| 164 | } | 
| 165 |  | 
| 166 | } | 
| 167 |  | 
| 168 | QT_END_NAMESPACE | 
| 169 |  | 
| 170 | #endif | 
| 171 |  |