Use QList instead of QVector in moc
Task-number: QTBUG-84469 Change-Id: Id95a656e6277a7c348c02c3267a45ac176c1643b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
95a5cd71b6
commit
670c5bd140
@ -80,12 +80,19 @@ QT_FOR_EACH_STATIC_TYPE(RETURN_METATYPENAME_STRING)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Generator::Generator(ClassDef *classDef, const QVector<QByteArray> &metaTypes, const QHash<QByteArray, QByteArray> &knownQObjectClasses, const QHash<QByteArray, QByteArray> &knownGadgets, FILE *outfile, bool requireCompleteTypes)
|
||||
: out(outfile), cdef(classDef), metaTypes(metaTypes), knownQObjectClasses(knownQObjectClasses)
|
||||
, knownGadgets(knownGadgets), requireCompleteTypes(requireCompleteTypes)
|
||||
{
|
||||
if (cdef->superclassList.size())
|
||||
purestSuperClass = cdef->superclassList.constFirst().first;
|
||||
Generator::Generator(ClassDef *classDef, const QList<QByteArray> &metaTypes,
|
||||
const QHash<QByteArray, QByteArray> &knownQObjectClasses,
|
||||
const QHash<QByteArray, QByteArray> &knownGadgets, FILE *outfile,
|
||||
bool requireCompleteTypes)
|
||||
: out(outfile),
|
||||
cdef(classDef),
|
||||
metaTypes(metaTypes),
|
||||
knownQObjectClasses(knownQObjectClasses),
|
||||
knownGadgets(knownGadgets),
|
||||
requireCompleteTypes(requireCompleteTypes)
|
||||
{
|
||||
if (cdef->superclassList.size())
|
||||
purestSuperClass = cdef->superclassList.constFirst().first;
|
||||
}
|
||||
|
||||
static inline int lengthOfEscapeSequence(const QByteArray &s, int i)
|
||||
@ -127,7 +134,7 @@ int Generator::stridx(const QByteArray &s)
|
||||
// Returns the sum of all parameters (including return type) for the given
|
||||
// \a list of methods. This is needed for calculating the size of the methods'
|
||||
// parameter type/name meta-data.
|
||||
static int aggregateParameterCount(const QVector<FunctionDef> &list)
|
||||
static int aggregateParameterCount(const QList<FunctionDef> &list)
|
||||
{
|
||||
int sum = 0;
|
||||
for (int i = 0; i < list.count(); ++i)
|
||||
@ -150,22 +157,22 @@ bool Generator::registerableMetaType(const QByteArray &propertyType)
|
||||
return true;
|
||||
}
|
||||
|
||||
static const QVector<QByteArray> smartPointers = QVector<QByteArray>()
|
||||
static const QList<QByteArray> smartPointers = QList<QByteArray>()
|
||||
#define STREAM_SMART_POINTER(SMART_POINTER) << #SMART_POINTER
|
||||
QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(STREAM_SMART_POINTER)
|
||||
QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(STREAM_SMART_POINTER)
|
||||
#undef STREAM_SMART_POINTER
|
||||
;
|
||||
;
|
||||
|
||||
for (const QByteArray &smartPointer : smartPointers) {
|
||||
if (propertyType.startsWith(smartPointer + "<") && !propertyType.endsWith("&"))
|
||||
return knownQObjectClasses.contains(propertyType.mid(smartPointer.size() + 1, propertyType.size() - smartPointer.size() - 1 - 1));
|
||||
}
|
||||
|
||||
static const QVector<QByteArray> oneArgTemplates = QVector<QByteArray>()
|
||||
static const QList<QByteArray> oneArgTemplates = QList<QByteArray>()
|
||||
#define STREAM_1ARG_TEMPLATE(TEMPLATENAME) << #TEMPLATENAME
|
||||
QT_FOR_EACH_AUTOMATIC_TEMPLATE_1ARG(STREAM_1ARG_TEMPLATE)
|
||||
QT_FOR_EACH_AUTOMATIC_TEMPLATE_1ARG(STREAM_1ARG_TEMPLATE)
|
||||
#undef STREAM_1ARG_TEMPLATE
|
||||
;
|
||||
;
|
||||
for (const QByteArray &oneArgTemplateType : oneArgTemplates) {
|
||||
if (propertyType.startsWith(oneArgTemplateType + "<") && propertyType.endsWith(">")) {
|
||||
const int argumentSize = propertyType.size() - oneArgTemplateType.size() - 1
|
||||
@ -199,7 +206,7 @@ void Generator::generateCode()
|
||||
|
||||
// filter out undeclared enumerators and sets
|
||||
{
|
||||
QVector<EnumDef> enumList;
|
||||
QList<EnumDef> enumList;
|
||||
for (int i = 0; i < cdef->enumList.count(); ++i) {
|
||||
EnumDef def = cdef->enumList.at(i);
|
||||
if (cdef->enumDeclarations.contains(def.name)) {
|
||||
@ -455,7 +462,7 @@ void Generator::generateCode()
|
||||
//
|
||||
// Build extra array
|
||||
//
|
||||
QVector<QByteArray> extraList;
|
||||
QList<QByteArray> extraList;
|
||||
QMultiHash<QByteArray, QByteArray> knownExtraMetaObject = knownGadgets;
|
||||
knownExtraMetaObject.unite(knownQObjectClasses);
|
||||
|
||||
@ -574,7 +581,8 @@ void Generator::generateCode()
|
||||
fprintf(out, "%s%s", needsComma ? ", " : "", p.type.data());
|
||||
needsComma = true;
|
||||
}
|
||||
for (const QVector<FunctionDef> &methodContainer: {cdef->signalList, cdef->slotList, cdef->methodList} ) {
|
||||
for (const QList<FunctionDef> &methodContainer :
|
||||
{ cdef->signalList, cdef->slotList, cdef->methodList }) {
|
||||
for (int i = 0; i< methodContainer.count(); ++i) {
|
||||
const FunctionDef& fdef = methodContainer.at(i);
|
||||
fprintf(out, "%s%s", needsComma ? ", " : "", fdef.type.name.data());
|
||||
@ -621,7 +629,7 @@ void Generator::generateCode()
|
||||
cname, cname);
|
||||
}
|
||||
for (int i = 0; i < cdef->interfaceList.size(); ++i) {
|
||||
const QVector<ClassDef::Interface> &iface = cdef->interfaceList.at(i);
|
||||
const QList<ClassDef::Interface> &iface = cdef->interfaceList.at(i);
|
||||
for (int j = 0; j < iface.size(); ++j) {
|
||||
fprintf(out, " if (!strcmp(_clname, %s))\n return ", iface.at(j).interfaceId.constData());
|
||||
for (int k = j; k >= 0; --k)
|
||||
@ -695,7 +703,7 @@ void Generator::generateClassInfos()
|
||||
}
|
||||
}
|
||||
|
||||
void Generator::registerFunctionStrings(const QVector<FunctionDef>& list)
|
||||
void Generator::registerFunctionStrings(const QList<FunctionDef> &list)
|
||||
{
|
||||
for (int i = 0; i < list.count(); ++i) {
|
||||
const FunctionDef &f = list.at(i);
|
||||
@ -715,13 +723,14 @@ void Generator::registerFunctionStrings(const QVector<FunctionDef>& list)
|
||||
}
|
||||
}
|
||||
|
||||
void Generator::registerByteArrayVector(const QVector<QByteArray> &list)
|
||||
void Generator::registerByteArrayVector(const QList<QByteArray> &list)
|
||||
{
|
||||
for (const QByteArray &ba : list)
|
||||
strreg(ba);
|
||||
}
|
||||
|
||||
void Generator::generateFunctions(const QVector<FunctionDef>& list, const char *functype, int type, int ¶msIndex, int &initialMetatypeOffset)
|
||||
void Generator::generateFunctions(const QList<FunctionDef> &list, const char *functype, int type,
|
||||
int ¶msIndex, int &initialMetatypeOffset)
|
||||
{
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
@ -769,7 +778,7 @@ void Generator::generateFunctions(const QVector<FunctionDef>& list, const char *
|
||||
}
|
||||
}
|
||||
|
||||
void Generator::generateFunctionRevisions(const QVector<FunctionDef>& list, const char *functype)
|
||||
void Generator::generateFunctionRevisions(const QList<FunctionDef> &list, const char *functype)
|
||||
{
|
||||
if (list.count())
|
||||
fprintf(out, "\n // %ss: revision\n", functype);
|
||||
@ -779,7 +788,7 @@ void Generator::generateFunctionRevisions(const QVector<FunctionDef>& list, cons
|
||||
}
|
||||
}
|
||||
|
||||
void Generator::generateFunctionParameters(const QVector<FunctionDef>& list, const char *functype)
|
||||
void Generator::generateFunctionParameters(const QList<FunctionDef> &list, const char *functype)
|
||||
{
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
@ -968,7 +977,7 @@ void Generator::generateMetacall()
|
||||
|
||||
|
||||
bool needElse = false;
|
||||
QVector<FunctionDef> methodList;
|
||||
QList<FunctionDef> methodList;
|
||||
methodList += cdef->signalList;
|
||||
methodList += cdef->slotList;
|
||||
methodList += cdef->methodList;
|
||||
@ -1031,7 +1040,8 @@ QMultiMap<QByteArray, int> Generator::automaticPropertyMetaTypesHelper()
|
||||
return automaticPropertyMetaTypes;
|
||||
}
|
||||
|
||||
QMap<int, QMultiMap<QByteArray, int> > Generator::methodsWithAutomaticTypesHelper(const QVector<FunctionDef> &methodList)
|
||||
QMap<int, QMultiMap<QByteArray, int>>
|
||||
Generator::methodsWithAutomaticTypesHelper(const QList<FunctionDef> &methodList)
|
||||
{
|
||||
QMap<int, QMultiMap<QByteArray, int> > methodsWithAutomaticTypes;
|
||||
for (int i = 0; i < methodList.size(); ++i) {
|
||||
@ -1085,7 +1095,7 @@ void Generator::generateStaticMetacall()
|
||||
isUsed_a = true;
|
||||
}
|
||||
|
||||
QVector<FunctionDef> methodList;
|
||||
QList<FunctionDef> methodList;
|
||||
methodList += cdef->signalList;
|
||||
methodList += cdef->slotList;
|
||||
methodList += cdef->methodList;
|
||||
|
@ -37,19 +37,24 @@ class Generator
|
||||
{
|
||||
FILE *out;
|
||||
ClassDef *cdef;
|
||||
QVector<uint> meta_data;
|
||||
QList<uint> meta_data;
|
||||
|
||||
public:
|
||||
Generator(ClassDef *classDef, const QVector<QByteArray> &metaTypes, const QHash<QByteArray, QByteArray> &knownQObjectClasses, const QHash<QByteArray, QByteArray> &knownGadgets, FILE *outfile = nullptr, bool requireCompleteTypes = false);
|
||||
Generator(ClassDef *classDef, const QList<QByteArray> &metaTypes,
|
||||
const QHash<QByteArray, QByteArray> &knownQObjectClasses,
|
||||
const QHash<QByteArray, QByteArray> &knownGadgets, FILE *outfile = nullptr,
|
||||
bool requireCompleteTypes = false);
|
||||
void generateCode();
|
||||
private:
|
||||
bool registerableMetaType(const QByteArray &propertyType);
|
||||
void registerClassInfoStrings();
|
||||
void generateClassInfos();
|
||||
void registerFunctionStrings(const QVector<FunctionDef> &list);
|
||||
void registerByteArrayVector(const QVector<QByteArray> &list);
|
||||
void generateFunctions(const QVector<FunctionDef> &list, const char *functype, int type, int ¶msIndex, int &initialMetatypeOffset);
|
||||
void generateFunctionRevisions(const QVector<FunctionDef> &list, const char *functype);
|
||||
void generateFunctionParameters(const QVector<FunctionDef> &list, const char *functype);
|
||||
void registerFunctionStrings(const QList<FunctionDef> &list);
|
||||
void registerByteArrayVector(const QList<QByteArray> &list);
|
||||
void generateFunctions(const QList<FunctionDef> &list, const char *functype, int type,
|
||||
int ¶msIndex, int &initialMetatypeOffset);
|
||||
void generateFunctionRevisions(const QList<FunctionDef> &list, const char *functype);
|
||||
void generateFunctionParameters(const QList<FunctionDef> &list, const char *functype);
|
||||
void generateTypeInfo(const QByteArray &typeName, bool allowEmptyName = false);
|
||||
void registerEnumStrings();
|
||||
void generateEnums(int index);
|
||||
@ -61,13 +66,14 @@ private:
|
||||
void generateQPropertyApi();
|
||||
void generatePluginMetaData();
|
||||
QMultiMap<QByteArray, int> automaticPropertyMetaTypesHelper();
|
||||
QMap<int, QMultiMap<QByteArray, int> > methodsWithAutomaticTypesHelper(const QVector<FunctionDef> &methodList);
|
||||
QMap<int, QMultiMap<QByteArray, int>>
|
||||
methodsWithAutomaticTypesHelper(const QList<FunctionDef> &methodList);
|
||||
|
||||
void strreg(const QByteArray &); // registers a string
|
||||
int stridx(const QByteArray &); // returns a string's id
|
||||
QVector<QByteArray> strings;
|
||||
QList<QByteArray> strings;
|
||||
QByteArray purestSuperClass;
|
||||
QVector<QByteArray> metaTypes;
|
||||
QList<QByteArray> metaTypes;
|
||||
QHash<QByteArray, QByteArray> knownQObjectClasses;
|
||||
QHash<QByteArray, QByteArray> knownGadgets;
|
||||
bool requireCompleteTypes;
|
||||
|
@ -607,7 +607,7 @@ bool Moc::parseMaybeQProperty(ClassDef *def)
|
||||
|
||||
void Moc::parse()
|
||||
{
|
||||
QVector<NamespaceDef> namespaceList;
|
||||
QList<NamespaceDef> namespaceList;
|
||||
bool templateClass = false;
|
||||
while (hasNext()) {
|
||||
Token t = next();
|
||||
@ -1008,7 +1008,7 @@ void Moc::parse()
|
||||
}
|
||||
}
|
||||
|
||||
static bool any_type_contains(const QVector<PropertyDef> &properties, const QByteArray &pattern)
|
||||
static bool any_type_contains(const QList<PropertyDef> &properties, const QByteArray &pattern)
|
||||
{
|
||||
for (const auto &p : properties) {
|
||||
if (p.type.contains(pattern))
|
||||
@ -1017,7 +1017,7 @@ static bool any_type_contains(const QVector<PropertyDef> &properties, const QByt
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool any_arg_contains(const QVector<FunctionDef> &functions, const QByteArray &pattern)
|
||||
static bool any_arg_contains(const QList<FunctionDef> &functions, const QByteArray &pattern)
|
||||
{
|
||||
for (const auto &f : functions) {
|
||||
for (const auto &arg : f.arguments) {
|
||||
@ -1042,7 +1042,7 @@ static QByteArrayList make_candidates()
|
||||
return result;
|
||||
}
|
||||
|
||||
static QByteArrayList requiredQtContainers(const QVector<ClassDef> &classes)
|
||||
static QByteArrayList requiredQtContainers(const QList<ClassDef> &classes)
|
||||
{
|
||||
static const QByteArrayList candidates = make_candidates();
|
||||
|
||||
@ -1608,7 +1608,7 @@ void Moc::parseInterfaces(ClassDef *def)
|
||||
{
|
||||
next(LPAREN);
|
||||
while (test(IDENTIFIER)) {
|
||||
QVector<ClassDef::Interface> iface;
|
||||
QList<ClassDef::Interface> iface;
|
||||
iface += ClassDef::Interface(lexem());
|
||||
while (test(SCOPE)) {
|
||||
iface.last().className += lexem();
|
||||
@ -1966,7 +1966,7 @@ QJsonObject ClassDef::toJson() const
|
||||
if (classInfos.size())
|
||||
cls[QLatin1String("classInfos")] = classInfos;
|
||||
|
||||
const auto appendFunctions = [&cls](const QString &type, const QVector<FunctionDef> &funcs) {
|
||||
const auto appendFunctions = [&cls](const QString &type, const QList<FunctionDef> &funcs) {
|
||||
QJsonArray jsonFuncs;
|
||||
|
||||
for (const FunctionDef &fdef: funcs)
|
||||
@ -2017,7 +2017,7 @@ QJsonObject ClassDef::toJson() const
|
||||
cls[QLatin1String("enums")] = enums;
|
||||
|
||||
QJsonArray ifaces;
|
||||
for (const QVector<Interface> &ifaceList: interfaceList) {
|
||||
for (const QList<Interface> &ifaceList : interfaceList) {
|
||||
QJsonArray jsonList;
|
||||
for (const Interface &iface: ifaceList) {
|
||||
QJsonObject ifaceJson;
|
||||
|
@ -67,7 +67,7 @@ struct EnumDef
|
||||
{
|
||||
QByteArray name;
|
||||
QByteArray enumName;
|
||||
QVector<QByteArray> values;
|
||||
QList<QByteArray> values;
|
||||
bool isEnumClass; // c++11 enum class
|
||||
EnumDef() : isEnumClass(false) {}
|
||||
QJsonObject toJson(const ClassDef &cdef) const;
|
||||
@ -89,7 +89,7 @@ Q_DECLARE_TYPEINFO(ArgumentDef, Q_MOVABLE_TYPE);
|
||||
struct FunctionDef
|
||||
{
|
||||
Type type;
|
||||
QVector<ArgumentDef> arguments;
|
||||
QList<ArgumentDef> arguments;
|
||||
QByteArray normalizedType;
|
||||
QByteArray tag;
|
||||
QByteArray name;
|
||||
@ -168,26 +168,26 @@ Q_DECLARE_TYPEINFO(ClassInfoDef, Q_MOVABLE_TYPE);
|
||||
struct BaseDef {
|
||||
QByteArray classname;
|
||||
QByteArray qualified;
|
||||
QVector<ClassInfoDef> classInfoList;
|
||||
QList<ClassInfoDef> classInfoList;
|
||||
QMap<QByteArray, bool> enumDeclarations;
|
||||
QVector<EnumDef> enumList;
|
||||
QList<EnumDef> enumList;
|
||||
QMap<QByteArray, QByteArray> flagAliases;
|
||||
int begin = 0;
|
||||
int end = 0;
|
||||
};
|
||||
|
||||
struct ClassDef : BaseDef {
|
||||
QVector<QPair<QByteArray, FunctionDef::Access> > superclassList;
|
||||
QList<QPair<QByteArray, FunctionDef::Access>> superclassList;
|
||||
|
||||
struct Interface
|
||||
{
|
||||
Interface() {} // for QVector, don't use
|
||||
Interface() { } // for QList, don't use
|
||||
inline explicit Interface(const QByteArray &_className)
|
||||
: className(_className) {}
|
||||
QByteArray className;
|
||||
QByteArray interfaceId;
|
||||
};
|
||||
QVector<QVector<Interface> >interfaceList;
|
||||
QList<QList<Interface>> interfaceList;
|
||||
|
||||
struct PluginData {
|
||||
QByteArray iid;
|
||||
@ -196,11 +196,11 @@ struct ClassDef : BaseDef {
|
||||
QJsonDocument metaData;
|
||||
} pluginData;
|
||||
|
||||
QVector<FunctionDef> constructorList;
|
||||
QVector<FunctionDef> signalList, slotList, methodList, publicList;
|
||||
QVector<QByteArray> nonClassSignalList;
|
||||
QVector<PropertyDef> propertyList;
|
||||
QVector<PrivateQPropertyDef> privateQProperties;
|
||||
QList<FunctionDef> constructorList;
|
||||
QList<FunctionDef> signalList, slotList, methodList, publicList;
|
||||
QList<QByteArray> nonClassSignalList;
|
||||
QList<PropertyDef> propertyList;
|
||||
QList<PrivateQPropertyDef> privateQProperties;
|
||||
QHash<QByteArray, bool> qPropertyMembersMaybeWithNotifier;
|
||||
int revisionedMethods = 0;
|
||||
|
||||
@ -232,15 +232,15 @@ public:
|
||||
bool mustIncludeQPluginH;
|
||||
bool requireCompleteTypes;
|
||||
QByteArray includePath;
|
||||
QVector<QByteArray> includeFiles;
|
||||
QVector<ClassDef> classList;
|
||||
QList<QByteArray> includeFiles;
|
||||
QList<ClassDef> classList;
|
||||
QMap<QByteArray, QByteArray> interface2IdMap;
|
||||
QVector<QByteArray> metaTypes;
|
||||
QList<QByteArray> metaTypes;
|
||||
// map from class name to fully qualified name
|
||||
QHash<QByteArray, QByteArray> knownQObjectClasses;
|
||||
QHash<QByteArray, QByteArray> knownGadgets;
|
||||
QMap<QString, QJsonArray> metaArgs;
|
||||
QVector<QString> parsedPluginMetadataFiles;
|
||||
QList<QString> parsedPluginMetadataFiles;
|
||||
|
||||
void parse();
|
||||
void generate(FILE *out, FILE *jsonOutput);
|
||||
|
@ -120,7 +120,7 @@ struct Symbol
|
||||
};
|
||||
Q_DECLARE_TYPEINFO(Symbol, Q_MOVABLE_TYPE);
|
||||
|
||||
typedef QVector<Symbol> Symbols;
|
||||
typedef QList<Symbol> Symbols;
|
||||
|
||||
struct SafeSymbols {
|
||||
Symbols symbols;
|
||||
|
Loading…
Reference in New Issue
Block a user