| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
| 3 | |
| 4 | #ifndef MOC_H |
| 5 | #define MOC_H |
| 6 | |
| 7 | // -- QtScxml |
| 8 | #include <QtCore/qmap.h> |
| 9 | #include <QtCore/qpair.h> |
| 10 | #include <QtCore/qjsondocument.h> |
| 11 | #include <QtCore/qjsonarray.h> |
| 12 | // -- QtScxml |
| 13 | |
| 14 | #include <private/qtools_p.h> |
| 15 | |
| 16 | QT_BEGIN_NAMESPACE |
| 17 | |
| 18 | struct QMetaObject; |
| 19 | |
| 20 | struct Type |
| 21 | { |
| 22 | enum ReferenceType { NoReference, Reference, RValueReference, Pointer }; |
| 23 | |
| 24 | inline Type() : isVolatile(false), isScoped(false), /* firstToken(NOTOKEN) -- QtScxml ,*/ referenceType(NoReference) {} |
| 25 | inline explicit Type(const QByteArray &_name) |
| 26 | : name(_name), rawName(name), isVolatile(false), isScoped(false), /* firstToken(NOTOKEN) -- QtScxml ,*/ referenceType(NoReference) {} |
| 27 | QByteArray name; |
| 28 | //When used as a return type, the type name may be modified to remove the references. |
| 29 | // rawName is the type as found in the function signature |
| 30 | QByteArray rawName; |
| 31 | uint isVolatile : 1; |
| 32 | uint isScoped : 1; |
| 33 | #if 0 // -- QtScxml |
| 34 | Token firstToken; |
| 35 | #endif // -- QtScxml |
| 36 | ReferenceType referenceType; |
| 37 | }; |
| 38 | Q_DECLARE_TYPEINFO(Type, Q_RELOCATABLE_TYPE); |
| 39 | |
| 40 | struct ClassDef; |
| 41 | struct EnumDef |
| 42 | { |
| 43 | QByteArray name; |
| 44 | QByteArray enumName; |
| 45 | QByteArray type; |
| 46 | QList<QByteArray> values; |
| 47 | bool isEnumClass; // c++11 enum class |
| 48 | EnumDef() : isEnumClass(false) {} |
| 49 | QJsonObject toJson(const ClassDef &cdef) const; |
| 50 | QByteArray qualifiedType(const ClassDef *cdef) const; |
| 51 | }; |
| 52 | Q_DECLARE_TYPEINFO(EnumDef, Q_RELOCATABLE_TYPE); |
| 53 | |
| 54 | struct ArgumentDef |
| 55 | { |
| 56 | ArgumentDef() : isDefault(false) {} |
| 57 | Type type; |
| 58 | QByteArray rightType, normalizedType, name; |
| 59 | QByteArray typeNameForCast; // type name to be used in cast from void * in metacall |
| 60 | bool isDefault; |
| 61 | |
| 62 | QJsonObject toJson() const; |
| 63 | }; |
| 64 | Q_DECLARE_TYPEINFO(ArgumentDef, Q_RELOCATABLE_TYPE); |
| 65 | |
| 66 | struct FunctionDef |
| 67 | { |
| 68 | Type type; |
| 69 | QList<ArgumentDef> arguments; |
| 70 | QByteArray normalizedType; |
| 71 | QByteArray tag; |
| 72 | QByteArray name; |
| 73 | QByteArray inPrivateClass; |
| 74 | |
| 75 | enum Access { Private, Protected, Public }; |
| 76 | Access access = Private; |
| 77 | int revision = 0; |
| 78 | |
| 79 | bool isConst = false; |
| 80 | bool isVirtual = false; |
| 81 | bool isStatic = false; |
| 82 | bool inlineCode = false; |
| 83 | bool wasCloned = false; |
| 84 | |
| 85 | #if 0 // -- QtScxml |
| 86 | bool returnTypeIsVolatile = false; |
| 87 | #endif // -- QtScxml |
| 88 | bool isCompat = false; |
| 89 | bool isInvokable = false; |
| 90 | bool isScriptable = false; |
| 91 | bool isSlot = false; |
| 92 | bool isSignal = false; |
| 93 | bool isPrivateSignal = false; |
| 94 | bool isConstructor = false; |
| 95 | bool isDestructor = false; |
| 96 | bool isAbstract = false; |
| 97 | bool isRawSlot = false; |
| 98 | |
| 99 | QJsonObject toJson() const; |
| 100 | static void accessToJson(QJsonObject *obj, Access acs); |
| 101 | |
| 102 | // -- QtScxml |
| 103 | QByteArray mangledName; |
| 104 | const char *implementation = nullptr; |
| 105 | // -- QtScxml |
| 106 | }; |
| 107 | Q_DECLARE_TYPEINFO(FunctionDef, Q_RELOCATABLE_TYPE); |
| 108 | |
| 109 | struct PropertyDef |
| 110 | { |
| 111 | bool stdCppSet() const { |
| 112 | if (name.isEmpty()) |
| 113 | return false; |
| 114 | QByteArray s("set" ); |
| 115 | s += QtMiscUtils::toAsciiUpper(ch: name[0]); |
| 116 | s += name.mid(index: 1); |
| 117 | return (s == write); |
| 118 | } |
| 119 | |
| 120 | QByteArray name, type, member, read, write, bind, reset, designable, scriptable, stored, user, notify, inPrivateClass; |
| 121 | int notifyId = -1; // -1 means no notifyId, >= 0 means signal defined in this class, < -1 means signal not defined in this class |
| 122 | enum Specification { ValueSpec, ReferenceSpec, PointerSpec }; |
| 123 | Specification gspec = ValueSpec; |
| 124 | int revision = 0; |
| 125 | bool constant = false; |
| 126 | bool final = false; |
| 127 | bool required = false; |
| 128 | int relativeIndex = -1; // property index in current metaobject |
| 129 | |
| 130 | qsizetype location = -1; // token index, used for error reporting |
| 131 | |
| 132 | QJsonObject toJson() const; |
| 133 | |
| 134 | // -- QtScxml |
| 135 | QByteArray mangledName; |
| 136 | // -- QtScxml |
| 137 | }; |
| 138 | Q_DECLARE_TYPEINFO(PropertyDef, Q_RELOCATABLE_TYPE); |
| 139 | |
| 140 | struct PrivateQPropertyDef |
| 141 | { |
| 142 | Type type; |
| 143 | QByteArray name; |
| 144 | QByteArray setter; |
| 145 | QByteArray accessor; |
| 146 | QByteArray storage; |
| 147 | }; |
| 148 | Q_DECLARE_TYPEINFO(PrivateQPropertyDef, Q_RELOCATABLE_TYPE); |
| 149 | |
| 150 | struct ClassInfoDef |
| 151 | { |
| 152 | QByteArray name; |
| 153 | QByteArray value; |
| 154 | }; |
| 155 | Q_DECLARE_TYPEINFO(ClassInfoDef, Q_RELOCATABLE_TYPE); |
| 156 | |
| 157 | struct BaseDef { |
| 158 | QByteArray classname; |
| 159 | QByteArray qualified; |
| 160 | QList<ClassInfoDef> classInfoList; |
| 161 | QMap<QByteArray, bool> enumDeclarations; |
| 162 | QList<EnumDef> enumList; |
| 163 | QMap<QByteArray, QByteArray> flagAliases; |
| 164 | qsizetype begin = 0; |
| 165 | qsizetype end = 0; |
| 166 | qsizetype lineNumber = 0; |
| 167 | }; |
| 168 | |
| 169 | struct SuperClass { |
| 170 | QByteArray classname; |
| 171 | QByteArray qualified; |
| 172 | FunctionDef::Access access; |
| 173 | }; |
| 174 | Q_DECLARE_TYPEINFO(SuperClass, Q_RELOCATABLE_TYPE); |
| 175 | |
| 176 | struct ClassDef : BaseDef { |
| 177 | QList<SuperClass> superclassList; |
| 178 | |
| 179 | struct Interface |
| 180 | { |
| 181 | Interface() { } // for QList, don't use |
| 182 | inline explicit Interface(const QByteArray &_className) |
| 183 | : className(_className) {} |
| 184 | QByteArray className; |
| 185 | QByteArray interfaceId; |
| 186 | }; |
| 187 | QList<QList<Interface>> interfaceList; |
| 188 | |
| 189 | struct PluginData { |
| 190 | QByteArray iid; |
| 191 | QByteArray uri; |
| 192 | QMap<QString, QJsonArray> metaArgs; |
| 193 | QJsonDocument metaData; |
| 194 | } pluginData; |
| 195 | |
| 196 | QList<FunctionDef> constructorList; |
| 197 | QList<FunctionDef> signalList, slotList, methodList, publicList; |
| 198 | QList<QByteArray> nonClassSignalList; |
| 199 | QList<PropertyDef> propertyList; |
| 200 | int revisionedMethods = 0; |
| 201 | |
| 202 | bool hasQObject = false; |
| 203 | bool hasQGadget = false; |
| 204 | bool hasQNamespace = false; |
| 205 | bool requireCompleteMethodTypes = false; |
| 206 | |
| 207 | QJsonObject toJson() const; |
| 208 | }; |
| 209 | Q_DECLARE_TYPEINFO(ClassDef, Q_RELOCATABLE_TYPE); |
| 210 | Q_DECLARE_TYPEINFO(ClassDef::Interface, Q_RELOCATABLE_TYPE); |
| 211 | |
| 212 | struct NamespaceDef : BaseDef { |
| 213 | bool hasQNamespace = false; |
| 214 | bool doGenerate = false; |
| 215 | }; |
| 216 | Q_DECLARE_TYPEINFO(NamespaceDef, Q_RELOCATABLE_TYPE); |
| 217 | |
| 218 | #if 0 // -- QtScxml |
| 219 | class Moc : public Parser |
| 220 | { |
| 221 | public: |
| 222 | enum PropertyMode { Named, Anonymous }; |
| 223 | |
| 224 | Moc() |
| 225 | : noInclude(false), mustIncludeQPluginH(false), requireCompleteTypes(false) |
| 226 | {} |
| 227 | |
| 228 | QByteArray filename; |
| 229 | |
| 230 | bool noInclude; |
| 231 | bool mustIncludeQPluginH; |
| 232 | bool requireCompleteTypes; |
| 233 | QByteArray includePath; |
| 234 | QList<QByteArray> includeFiles; |
| 235 | QList<ClassDef> classList; |
| 236 | QMap<QByteArray, QByteArray> interface2IdMap; |
| 237 | QList<QByteArray> metaTypes; |
| 238 | // map from class name to fully qualified name |
| 239 | QHash<QByteArray, QByteArray> knownQObjectClasses; |
| 240 | QHash<QByteArray, QByteArray> knownGadgets; |
| 241 | QMap<QString, QJsonArray> metaArgs; |
| 242 | QList<QString> parsedPluginMetadataFiles; |
| 243 | |
| 244 | void parse(); |
| 245 | void generate(FILE *out, FILE *jsonOutput); |
| 246 | |
| 247 | bool parseClassHead(ClassDef *def); |
| 248 | inline bool inClass(const ClassDef *def) const { |
| 249 | return index > def->begin && index < def->end - 1; |
| 250 | } |
| 251 | |
| 252 | inline bool inNamespace(const NamespaceDef *def) const { |
| 253 | return index > def->begin && index < def->end - 1; |
| 254 | } |
| 255 | |
| 256 | const QByteArray &toFullyQualified(const QByteArray &name) const noexcept; |
| 257 | |
| 258 | void prependNamespaces(BaseDef &def, const QList<NamespaceDef> &namespaceList) const; |
| 259 | |
| 260 | Type parseType(); |
| 261 | |
| 262 | bool parseEnum(EnumDef *def); |
| 263 | |
| 264 | bool parseFunction(FunctionDef *def, bool inMacro = false); |
| 265 | bool parseMaybeFunction(const ClassDef *cdef, FunctionDef *def); |
| 266 | |
| 267 | void parseSlots(ClassDef *def, FunctionDef::Access access); |
| 268 | void parseSignals(ClassDef *def); |
| 269 | void parseProperty(ClassDef *def, PropertyMode mode); |
| 270 | void parsePluginData(ClassDef *def); |
| 271 | |
| 272 | void createPropertyDef(PropertyDef &def, int propertyIndex, PropertyMode mode); |
| 273 | |
| 274 | void parsePropertyAttributes(PropertyDef &propDef); |
| 275 | void parseEnumOrFlag(BaseDef *def, bool isFlag); |
| 276 | void parseFlag(BaseDef *def); |
| 277 | enum class EncounteredQmlMacro {Yes, No}; |
| 278 | EncounteredQmlMacro parseClassInfo(BaseDef *def); |
| 279 | void parseClassInfo(ClassDef *def); |
| 280 | void parseInterfaces(ClassDef *def); |
| 281 | void parseDeclareInterface(); |
| 282 | void parseDeclareMetatype(); |
| 283 | void parseMocInclude(); |
| 284 | void parseSlotInPrivate(ClassDef *def, FunctionDef::Access access); |
| 285 | QByteArray parsePropertyAccessor(); |
| 286 | void parsePrivateProperty(ClassDef *def, PropertyMode mode); |
| 287 | |
| 288 | void parseFunctionArguments(FunctionDef *def); |
| 289 | |
| 290 | QByteArray lexemUntil(Token); |
| 291 | bool until(Token); |
| 292 | |
| 293 | // test for Q_INVOCABLE, Q_SCRIPTABLE, etc. and set the flags |
| 294 | // in FunctionDef accordingly |
| 295 | bool testFunctionAttribute(FunctionDef *def); |
| 296 | bool testFunctionAttribute(Token tok, FunctionDef *def); |
| 297 | bool testFunctionRevision(FunctionDef *def); |
| 298 | QTypeRevision parseRevision(); |
| 299 | |
| 300 | bool skipCxxAttributes(); |
| 301 | |
| 302 | void checkSuperClasses(ClassDef *def); |
| 303 | void checkProperties(ClassDef* cdef); |
| 304 | bool testForFunctionModifiers(FunctionDef *def); |
| 305 | |
| 306 | void checkListSizes(const ClassDef &def); |
| 307 | }; |
| 308 | #endif // -- QtScxml |
| 309 | |
| 310 | inline QByteArray noRef(const QByteArray &type) |
| 311 | { |
| 312 | if (type.endsWith(c: '&')) { |
| 313 | if (type.endsWith(bv: "&&" )) |
| 314 | return type.left(n: type.size()-2); |
| 315 | return type.left(n: type.size()-1); |
| 316 | } |
| 317 | return type; |
| 318 | } |
| 319 | |
| 320 | QT_END_NAMESPACE |
| 321 | |
| 322 | #endif // MOC_H |
| 323 | |