Skip to content

Commit 4da3fd8

Browse files
YuriUfimtsevusiems
authored andcommitted
Add more shared pointers; remove AbstractMetaType::copy; remove some delete operators and destructors
1 parent 1286d46 commit 4da3fd8

File tree

8 files changed

+60
-99
lines changed

8 files changed

+60
-99
lines changed

generator/abstractmetabuilder.cpp

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,11 @@ AbstractMetaClass *AbstractMetaBuilder::argumentToClass(ArgumentModelItem argume
210210
{
211211
AbstractMetaClass *returned = 0;
212212
bool ok = false;
213-
AbstractMetaType *type = translateType(argument->type(), &ok);
213+
AbstractMetaType::shared_pointer type = translateType(argument->type(), &ok);
214214
if (ok && type != 0 && type->typeEntry() != 0 && type->typeEntry()->isComplex()) {
215215
const TypeEntry *entry = type->typeEntry();
216216
returned = m_meta_classes.findClass(entry->name());
217217
}
218-
delete type;
219218
return returned;
220219
}
221220

@@ -1017,7 +1016,7 @@ AbstractMetaField *AbstractMetaBuilder::traverseField(VariableModelItem field, c
10171016

10181017
bool ok;
10191018
TypeInfo field_type = field->type();
1020-
AbstractMetaType *meta_type = translateType(field_type, &ok);
1019+
AbstractMetaType::shared_pointer meta_type = translateType(field_type, &ok);
10211020

10221021
if (!meta_type || !ok) {
10231022
ReportHandler::warning(QString("skipping field '%1::%2' with unmatched type '%3'")
@@ -1464,7 +1463,7 @@ AbstractMetaFunction *AbstractMetaBuilder::traverseFunction(FunctionModelItem fu
14641463
meta_function->setName(m_current_class->name());
14651464
} else {
14661465
bool ok;
1467-
AbstractMetaType *type = 0;
1466+
AbstractMetaType::shared_pointer type = 0;
14681467

14691468
if (!cast_type.isEmpty()) {
14701469
TypeInfo info;
@@ -1502,7 +1501,7 @@ AbstractMetaFunction *AbstractMetaBuilder::traverseFunction(FunctionModelItem fu
15021501
ArgumentModelItem arg = arguments.at(i);
15031502

15041503
bool ok;
1505-
AbstractMetaType *meta_type = translateType(arg->type(), &ok);
1504+
AbstractMetaType::shared_pointer meta_type = translateType(arg->type(), &ok);
15061505
if (!meta_type || !ok) {
15071506
ReportHandler::warning(QString("skipping function '%1::%2', "
15081507
"unmatched parameter type '%3'")
@@ -1571,7 +1570,7 @@ AbstractMetaFunction *AbstractMetaBuilder::traverseFunction(FunctionModelItem fu
15711570
}
15721571

15731572

1574-
AbstractMetaType *AbstractMetaBuilder::translateType(const TypeInfo &_typei, bool *ok, bool resolveType, bool resolveScope)
1573+
AbstractMetaType::shared_pointer AbstractMetaBuilder::translateType(const TypeInfo &_typei, bool *ok, bool resolveType, bool resolveScope)
15751574
{
15761575
Q_ASSERT(ok);
15771576
*ok = true;
@@ -1581,7 +1580,7 @@ AbstractMetaType *AbstractMetaBuilder::translateType(const TypeInfo &_typei, boo
15811580
TypeInfo typei;
15821581
if (resolveType) {
15831582
bool isok;
1584-
AbstractMetaType *t = translateType(_typei, &isok, false, resolveScope);
1583+
AbstractMetaType::shared_pointer t = translateType(_typei, &isok, false, resolveScope);
15851584
if (t != 0 && isok)
15861585
return t;
15871586
}
@@ -1632,7 +1631,7 @@ AbstractMetaType *AbstractMetaBuilder::translateType(const TypeInfo &_typei, boo
16321631
newInfo.setVolatile(typei.isVolatile());
16331632
newInfo.setMutable(typei.isMutable());
16341633

1635-
AbstractMetaType *elementType = translateType(newInfo, ok);
1634+
AbstractMetaType::shared_pointer elementType = translateType(newInfo, ok);
16361635
if (!(*ok))
16371636
return 0;
16381637

@@ -1644,7 +1643,7 @@ AbstractMetaType *AbstractMetaBuilder::translateType(const TypeInfo &_typei, boo
16441643
if (!isok)
16451644
return 0;
16461645

1647-
AbstractMetaType *arrayType = createMetaType();
1646+
AbstractMetaType::shared_pointer arrayType = createMetaType();
16481647
arrayType->setArrayElementCount(elems);
16491648
arrayType->setArrayElementType(elementType);
16501649
arrayType->setTypeEntry(new ArrayTypeEntry(elementType->typeEntry()));
@@ -1714,7 +1713,7 @@ AbstractMetaType *AbstractMetaBuilder::translateType(const TypeInfo &_typei, boo
17141713

17151714
bool isok;
17161715
info.setQualifiedName(QStringList() << contexts.at(0) << qualified_name);
1717-
AbstractMetaType *t = translateType(info, &isok, true, false);
1716+
AbstractMetaType::shared_pointer t = translateType(info, &isok, true, false);
17181717
if (t != 0 && isok)
17191718
return t;
17201719

@@ -1744,7 +1743,7 @@ AbstractMetaType *AbstractMetaBuilder::translateType(const TypeInfo &_typei, boo
17441743
// These are only implicit and should not appear in code...
17451744
Q_ASSERT(!type->isInterface());
17461745

1747-
AbstractMetaType *meta_type = createMetaType();
1746+
AbstractMetaType::shared_pointer meta_type = createMetaType();
17481747
meta_type->setTypeEntry(type);
17491748
meta_type->setIndirections(typeInfo.indirections);
17501749
meta_type->setReference(typeInfo.is_reference);
@@ -1778,7 +1777,6 @@ AbstractMetaType *AbstractMetaBuilder::translateType(const TypeInfo &_typei, boo
17781777

17791778
AbstractMetaType::shared_pointer targ_type (translateType(info, ok));
17801779
if (!(*ok)) {
1781-
delete meta_type;
17821780
return 0;
17831781
}
17841782

@@ -1796,7 +1794,7 @@ AbstractMetaType *AbstractMetaBuilder::translateType(const TypeInfo &_typei, boo
17961794
return meta_type;
17971795
}
17981796

1799-
void AbstractMetaBuilder::decideUsagePattern(AbstractMetaType *meta_type)
1797+
void AbstractMetaBuilder::decideUsagePattern(AbstractMetaType::shared_pointer meta_type)
18001798
{
18011799
const TypeEntry *type = meta_type->typeEntry();
18021800

@@ -1882,7 +1880,7 @@ void AbstractMetaBuilder::decideUsagePattern(AbstractMetaType *meta_type)
18821880
}
18831881
}
18841882

1885-
QString AbstractMetaBuilder::translateDefaultValue(ArgumentModelItem item, AbstractMetaType *type,
1883+
QString AbstractMetaBuilder::translateDefaultValue(ArgumentModelItem item, AbstractMetaType::shared_pointer type,
18861884
AbstractMetaFunction *fnc, AbstractMetaClass *implementing_class,
18871885
int argument_index)
18881886
{
@@ -1938,16 +1936,16 @@ bool AbstractMetaBuilder::isEnum(const QStringList &qualified_name)
19381936
return item && item->kind() == _EnumModelItem::__node_kind;
19391937
}
19401938

1941-
AbstractMetaType *AbstractMetaBuilder::inheritTemplateType(const QList<AbstractMetaType *> &template_types,
1942-
AbstractMetaType *meta_type, bool *ok)
1939+
AbstractMetaType::shared_pointer AbstractMetaBuilder::inheritTemplateType(const QList<AbstractMetaType::shared_pointer> &template_types,
1940+
AbstractMetaType::shared_pointer meta_type, bool *ok)
19431941
{
19441942
if (ok != 0)
19451943
*ok = true;
19461944
if (!meta_type || (!meta_type->typeEntry()->isTemplateArgument() && !meta_type->hasInstantiations()))
1947-
return meta_type ? meta_type->copy() : 0;
1945+
return meta_type ? meta_type : 0;
19481946

1949-
AbstractMetaType *returned = meta_type->copy();
1950-
returned->setOriginalTemplateType(meta_type->copy());
1947+
AbstractMetaType::shared_pointer returned = meta_type;
1948+
returned->setOriginalTemplateType(meta_type);
19511949

19521950
if (returned->typeEntry()->isTemplateArgument()) {
19531951
const TemplateArgumentEntry *tae = static_cast<const TemplateArgumentEntry *>(returned->typeEntry());
@@ -1960,14 +1958,13 @@ AbstractMetaType *AbstractMetaBuilder::inheritTemplateType(const QList<AbstractM
19601958
return 0;
19611959
}
19621960

1963-
AbstractMetaType *t = returned->copy();
1961+
AbstractMetaType::shared_pointer t = returned;
19641962
t->setTypeEntry(template_types.at(tae->ordinal())->typeEntry());
19651963
t->setIndirections(template_types.at(tae->ordinal())->indirections() + t->indirections()
19661964
? 1
19671965
: 0);
19681966
decideUsagePattern(t);
19691967

1970-
delete returned;
19711968
returned = inheritTemplateType(template_types, t, ok);
19721969
if (ok != 0 && !(*ok))
19731970
return 0;
@@ -1976,7 +1973,7 @@ AbstractMetaType *AbstractMetaBuilder::inheritTemplateType(const QList<AbstractM
19761973
if (returned->hasInstantiations()) {
19771974
auto instantiations = returned->instantiations();
19781975
for (int i=0; i<instantiations.count(); ++i) {
1979-
instantiations[i] = AbstractMetaType::shared_pointer(inheritTemplateType(template_types, instantiations[i].data(), ok));
1976+
instantiations[i] = AbstractMetaType::shared_pointer(inheritTemplateType(template_types, instantiations[i], ok));
19801977
if (ok != 0 && !(*ok))
19811978
return 0;
19821979
}
@@ -1992,12 +1989,12 @@ bool AbstractMetaBuilder::inheritTemplate(AbstractMetaClass *subclass,
19921989
{
19931990
QList<TypeParser::Info> targs = info.template_instantiations;
19941991

1995-
QList<AbstractMetaType *> template_types;
1992+
QList<AbstractMetaType::shared_pointer> template_types;
19961993
for (const TypeParser::Info &i : targs) {
19971994
TypeEntry *t = TypeDatabase::instance()->findType(i.qualified_name.join("::"));
19981995

19991996
if (t != 0) {
2000-
AbstractMetaType *temporary_type = createMetaType();
1997+
AbstractMetaType::shared_pointer temporary_type = createMetaType();
20011998
temporary_type->setTypeEntry(t);
20021999
temporary_type->setConstant(i.is_constant);
20032000
temporary_type->setReference(i.is_reference);
@@ -2016,15 +2013,15 @@ bool AbstractMetaBuilder::inheritTemplate(AbstractMetaClass *subclass,
20162013
f->setArguments(AbstractMetaArgumentList());
20172014

20182015
bool ok = true;
2019-
AbstractMetaType *ftype = function->type();
2016+
AbstractMetaType::shared_pointer ftype = function->type();
20202017
f->setType(inheritTemplateType(template_types, ftype, &ok));
20212018
if (!ok) {
20222019
delete f;
20232020
continue;
20242021
}
20252022

20262023
for (AbstractMetaArgument *argument : function->arguments()) {
2027-
AbstractMetaType *atype = argument->type();
2024+
AbstractMetaType::shared_pointer atype = argument->type();
20282025

20292026
AbstractMetaArgument *arg = argument->copy();
20302027
arg->setType(inheritTemplateType(template_types, atype, &ok));
@@ -2096,12 +2093,6 @@ bool AbstractMetaBuilder::inheritTemplate(AbstractMetaClass *subclass,
20962093
subclass->addFunction(f);
20972094
}
20982095

2099-
// Clean up
2100-
for (AbstractMetaType *type : template_types) {
2101-
delete type;
2102-
}
2103-
2104-
21052096
{
21062097
subclass->setTemplateBaseClass(template_class);
21072098

@@ -2122,7 +2113,7 @@ void AbstractMetaBuilder::parseQ_Property(AbstractMetaClass *meta_class, const Q
21222113

21232114
QStringList qualifiedScopeName = currentScope()->qualifiedName();
21242115
bool ok = false;
2125-
AbstractMetaType *type = 0;
2116+
AbstractMetaType::shared_pointer type = 0;
21262117
int pIndex = 0;
21272118
QString typeName = l.value(pIndex++);
21282119
bool isConst = false;
@@ -2179,7 +2170,6 @@ void AbstractMetaBuilder::parseQ_Property(AbstractMetaClass *meta_class, const Q
21792170
}
21802171

21812172
meta_class->addPropertySpec(spec);
2182-
delete type;
21832173
}
21842174
}
21852175

generator/abstractmetabuilder.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,19 @@ class AbstractMetaBuilder
113113
void setupClonable(AbstractMetaClass *cls);
114114
void setupFunctionDefaults(AbstractMetaFunction *meta_function, AbstractMetaClass *meta_class);
115115

116-
QString translateDefaultValue(ArgumentModelItem item, AbstractMetaType *type,
116+
QString translateDefaultValue(ArgumentModelItem item, AbstractMetaType::shared_pointer type,
117117
AbstractMetaFunction *fnc, AbstractMetaClass *,
118118
int argument_index);
119-
AbstractMetaType *translateType(const TypeInfo &type, bool *ok, bool resolveType = true, bool resolveScope = true);
119+
AbstractMetaType::shared_pointer translateType(const TypeInfo &type, bool *ok, bool resolveType = true, bool resolveScope = true);
120120

121-
void decideUsagePattern(AbstractMetaType *type);
121+
void decideUsagePattern(AbstractMetaType::shared_pointer type);
122122

123123
bool inheritTemplate(AbstractMetaClass *subclass,
124124
const AbstractMetaClass *template_class,
125125
const TypeParser::Info &info);
126-
AbstractMetaType *inheritTemplateType(const QList<AbstractMetaType *> &template_types, AbstractMetaType *meta_type, bool *ok = 0);
126+
AbstractMetaType::shared_pointer inheritTemplateType(const QList<AbstractMetaType::shared_pointer> &template_types,
127+
AbstractMetaType::shared_pointer meta_type,
128+
bool *ok = 0);
127129

128130
bool isQObject(const QString &qualified_name);
129131
bool isEnum(const QStringList &qualified_name);
@@ -144,7 +146,7 @@ class AbstractMetaBuilder
144146
virtual AbstractMetaField *createMetaField() = 0;
145147
virtual AbstractMetaFunction *createMetaFunction() = 0;
146148
virtual AbstractMetaArgument *createMetaArgument() = 0;
147-
virtual AbstractMetaType *createMetaType() = 0;
149+
virtual AbstractMetaType::shared_pointer createMetaType() = 0;
148150

149151
private:
150152
void sortLists();

generator/abstractmetalang.cpp

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,6 @@
4747
/*******************************************************************************
4848
* AbstractMetaType
4949
*/
50-
AbstractMetaType::~AbstractMetaType()
51-
{
52-
delete m_original_template_type;
53-
}
54-
55-
AbstractMetaType *AbstractMetaType::copy() const
56-
{
57-
AbstractMetaType *cpy = new AbstractMetaType;
58-
59-
cpy->setTypeUsagePattern(typeUsagePattern());
60-
cpy->setConstant(isConstant());
61-
cpy->setReference(isReference());
62-
cpy->setIndirections(indirections());
63-
cpy->setInstantiations(instantiations());
64-
cpy->setArrayElementCount(arrayElementCount());
65-
cpy->setOriginalTypeDescription(originalTypeDescription());
66-
cpy->setOriginalTemplateType(originalTemplateType() ? originalTemplateType()->copy() : 0);
67-
68-
cpy->setArrayElementType(arrayElementType() ? arrayElementType()->copy() : 0);
69-
70-
cpy->setTypeEntry(typeEntry());
71-
72-
return cpy;
73-
}
74-
7550
QString AbstractMetaType::cppSignature() const
7651
{
7752
QString s;
@@ -107,7 +82,6 @@ QString AbstractMetaType::cppSignature() const
10782
*/
10883
AbstractMetaVariable::~AbstractMetaVariable()
10984
{
110-
delete m_type;
11185
}
11286

11387
/*******************************************************************************
@@ -118,7 +92,7 @@ AbstractMetaArgument *AbstractMetaArgument::copy() const
11892
AbstractMetaArgument *cpy = new AbstractMetaArgument;
11993
cpy->setName(AbstractMetaVariable::name());
12094
cpy->setDefaultValueExpression(defaultValueExpression());
121-
cpy->setType(type()->copy());
95+
cpy->setType(type());
12296
cpy->setArgumentIndex(argumentIndex());
12397

12498
return cpy;
@@ -156,7 +130,6 @@ QString AbstractMetaArgument::name() const
156130
AbstractMetaFunction::~AbstractMetaFunction()
157131
{
158132
qDeleteAll(m_arguments);
159-
delete m_type;
160133
}
161134

162135
/*******************************************************************************
@@ -257,8 +230,8 @@ uint AbstractMetaFunction::compareTo(const AbstractMetaFunction *other) const
257230
}
258231

259232
// Compare types
260-
AbstractMetaType *t = type();
261-
AbstractMetaType *ot = other->type();
233+
AbstractMetaType::shared_pointer t = type();
234+
AbstractMetaType::shared_pointer ot = other->type();
262235
if ((!t && !ot) || ((t && ot && t->name() == ot->name()))) {
263236
result |= EqualReturnType;
264237
}
@@ -326,7 +299,7 @@ AbstractMetaFunction *AbstractMetaFunction::copy() const
326299
cpy->setAttributes(attributes());
327300
cpy->setDeclaringClass(declaringClass());
328301
if (type())
329-
cpy->setType(type()->copy());
302+
cpy->setType(type());
330303
cpy->setConstant(isConstant());
331304
cpy->setConstexpr(isConstexpr());
332305
cpy->setAuto(isAuto());
@@ -662,7 +635,7 @@ QString AbstractMetaFunction::minimalSignature() const
662635
AbstractMetaArgumentList arguments = this->arguments();
663636

664637
for (int i=0; i<arguments.count(); ++i) {
665-
AbstractMetaType *t = arguments.at(i)->type();
638+
AbstractMetaType::shared_pointer t = arguments.at(i)->type();
666639

667640
if (i > 0)
668641
minimalSignature += ",";
@@ -1236,7 +1209,7 @@ AbstractMetaField *AbstractMetaField::copy() const
12361209
returned->setEnclosingClass(0);
12371210
returned->setAttributes(attributes());
12381211
returned->setName(name());
1239-
returned->setType(type()->copy());
1212+
returned->setType(type());
12401213
returned->setOriginalAttributes(originalAttributes());
12411214

12421215
return returned;
@@ -1314,7 +1287,7 @@ const AbstractMetaFunction *AbstractMetaField::setter() const
13141287
AbstractMetaAttributes::SetterFunction);
13151288
AbstractMetaArgumentList arguments;
13161289
AbstractMetaArgument *argument = new AbstractMetaArgument;
1317-
argument->setType(type()->copy());
1290+
argument->setType(type());
13181291
argument->setName(name());
13191292
arguments.append(argument);
13201293
m_setter->setArguments(arguments);
@@ -1328,7 +1301,7 @@ const AbstractMetaFunction *AbstractMetaField::getter() const
13281301
m_getter = createXetter(this,
13291302
name(),
13301303
AbstractMetaAttributes::GetterFunction);
1331-
m_getter->setType(type()->copy());
1304+
m_getter->setType(type());
13321305
}
13331306

13341307
return m_getter;
@@ -1617,7 +1590,7 @@ AbstractMetaEnum *AbstractMetaClass::findEnumForValue(const QString &enumValueNa
16171590
}
16181591

16191592

1620-
static void add_extra_include_for_type(AbstractMetaClass *meta_class, const AbstractMetaType *type)
1593+
static void add_extra_include_for_type(AbstractMetaClass *meta_class, AbstractMetaType::const_shared_pointer type)
16211594
{
16221595

16231596
if (type == 0)
@@ -1635,7 +1608,7 @@ static void add_extra_include_for_type(AbstractMetaClass *meta_class, const Abst
16351608
if (type->hasInstantiations()) {
16361609
auto &instantiations = type->instantiations();
16371610
for(auto &&instantiation: instantiations)
1638-
add_extra_include_for_type(meta_class, instantiation.data());
1611+
add_extra_include_for_type(meta_class, instantiation);
16391612
}
16401613
}
16411614

0 commit comments

Comments
 (0)