Skip to content

Commit 4c61ee7

Browse files
committed
Remove figureOutEnumValues and company
The resulting enumValueRedirection was not used in the PythonQt generator. Perhaps it was a remnant of the original Java wrapper generator.
1 parent f88bbbb commit 4c61ee7

File tree

4 files changed

+0
-239
lines changed

4 files changed

+0
-239
lines changed

generator/abstractmetabuilder.cpp

Lines changed: 0 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@ bool AbstractMetaBuilder::build()
602602
}
603603
}
604604

605-
figureOutEnumValues();
606605
checkFunctionModifications();
607606

608607
for (AbstractMetaClass *cls : m_meta_classes) {
@@ -761,223 +760,6 @@ AbstractMetaClass *AbstractMetaBuilder::traverseNamespace(NamespaceModelItem nam
761760
return meta_class;
762761
}
763762

764-
struct Operator
765-
{
766-
enum Type { Plus, ShiftLeft, None };
767-
768-
Operator() : type(None) { }
769-
770-
int calculate(int x) {
771-
switch (type) {
772-
case Plus: return x + value;
773-
case ShiftLeft: return x << value;
774-
case None: return x;
775-
}
776-
return x;
777-
}
778-
779-
Type type;
780-
int value;
781-
};
782-
783-
784-
785-
Operator findOperator(QString *s) {
786-
const char *names[] = {
787-
"+",
788-
"<<"
789-
};
790-
791-
for (int i=0; i<Operator::None; ++i) {
792-
QString name = QLatin1String(names[i]);
793-
QString str = *s;
794-
int splitPoint = str.indexOf(name);
795-
if (splitPoint > 0) {
796-
bool ok;
797-
QString right = str.mid(splitPoint + name.length());
798-
Operator op;
799-
op.value = right.toInt(&ok);
800-
if (ok) {
801-
op.type = Operator::Type(i);
802-
*s = str.left(splitPoint).trimmed();
803-
return op;
804-
}
805-
}
806-
}
807-
return Operator();
808-
}
809-
810-
int AbstractMetaBuilder::figureOutEnumValue(const QString &stringValue,
811-
int oldValuevalue,
812-
AbstractMetaEnum *meta_enum,
813-
AbstractMetaFunction *meta_function)
814-
{
815-
Q_UNUSED(meta_function)
816-
if (stringValue.isEmpty())
817-
return oldValuevalue;
818-
819-
QStringList stringValues = stringValue.split("|");
820-
821-
int returnValue = 0;
822-
823-
bool matched = false;
824-
825-
for (int i=0; i<stringValues.size(); ++i) {
826-
QString s = stringValues.at(i).trimmed();
827-
828-
bool ok;
829-
int v;
830-
831-
Operator op = findOperator(&s);
832-
833-
if (s.length() > 0 && s.at(0) == QLatin1Char('0'))
834-
v = s.toUInt(&ok, 0);
835-
else
836-
v = s.toInt(&ok);
837-
838-
if (ok) {
839-
matched = true;
840-
841-
} else if (m_enum_values.contains(s)) {
842-
v = m_enum_values[s]->value();
843-
matched = true;
844-
845-
} else {
846-
AbstractMetaEnumValue *ev = 0;
847-
848-
if (meta_enum && (ev = meta_enum->values().find(s))) {
849-
v = ev->value();
850-
matched = true;
851-
852-
} else if (meta_enum && (ev = meta_enum->enclosingClass()->findEnumValue(s, meta_enum))) {
853-
v = ev->value();
854-
matched = true;
855-
856-
} else {
857-
/*
858-
if (meta_enum)
859-
ReportHandler::warning("unhandled enum value: " + s + " in "
860-
+ meta_enum->enclosingClass()->name() + "::"
861-
+ meta_enum->name());
862-
else
863-
ReportHandler::warning("unhandled enum value: Unknown enum");
864-
*/
865-
}
866-
}
867-
868-
if (matched)
869-
returnValue |= op.calculate(v);
870-
}
871-
872-
if (!matched) {
873-
/* not helpful...
874-
QString warn = QString("unmatched enum %1").arg(stringValue);
875-
876-
if (meta_function != 0) {
877-
warn += QString(" when parsing default value of '%1' in class '%2'")
878-
.arg(meta_function->name())
879-
.arg(meta_function->implementingClass()->name());
880-
}
881-
882-
ReportHandler::warning(warn);
883-
*/
884-
returnValue = oldValuevalue;
885-
}
886-
887-
return returnValue;
888-
}
889-
890-
void AbstractMetaBuilder::figureOutEnumValuesForClass(AbstractMetaClass *meta_class,
891-
QSet<AbstractMetaClass *> *classes)
892-
{
893-
AbstractMetaClass *base = meta_class->baseClass();
894-
895-
if (base != 0 && !classes->contains(base))
896-
figureOutEnumValuesForClass(base, classes);
897-
898-
if (classes->contains(meta_class))
899-
return;
900-
901-
AbstractMetaEnumList enums = meta_class->enums();
902-
for (AbstractMetaEnum *e : enums) {
903-
if (!e) {
904-
ReportHandler::warning("bad enum in class " + meta_class->name());
905-
continue;
906-
}
907-
AbstractMetaEnumValueList lst = e->values();
908-
int value = 0;
909-
for (int i=0; i<lst.size(); ++i) {
910-
value = figureOutEnumValue(lst.at(i)->stringValue(), value, e);
911-
lst.at(i)->setValue(value);
912-
value++;
913-
}
914-
915-
// Check for duplicate values...
916-
EnumTypeEntry *ete = e->typeEntry();
917-
if (!ete->forceInteger()) {
918-
QHash<int, AbstractMetaEnumValue *> entries;
919-
for (AbstractMetaEnumValue *v : lst) {
920-
921-
bool vRejected = ete->isEnumValueRejected(v->name());
922-
923-
AbstractMetaEnumValue *current = entries.value(v->value());
924-
if (current) {
925-
bool currentRejected = ete->isEnumValueRejected(current->name());
926-
if (!currentRejected && !vRejected) {
927-
/* Removed because I don't see the sense of rejecting duplicate values...
928-
ReportHandler::warning(
929-
QString("duplicate enum values: %1::%2, %3 and %4 are %5, already rejected: (%6)")
930-
.arg(meta_class->name())
931-
.arg(e->name())
932-
.arg(v->name())
933-
.arg(entries[v->value()]->name())
934-
.arg(v->value())
935-
.arg(ete->enumValueRejections().join(", ")));
936-
continue;
937-
*/
938-
}
939-
}
940-
941-
if (!vRejected)
942-
entries[v->value()] = v;
943-
}
944-
945-
// Entries now contain all the original entries, no
946-
// rejected ones... Use this to generate the enumValueRedirection table.
947-
for (AbstractMetaEnumValue *reject : lst) {
948-
if (!ete->isEnumValueRejected(reject->name()))
949-
continue;
950-
951-
AbstractMetaEnumValue *used = entries.value(reject->value());
952-
if (!used) {
953-
ReportHandler::warning(
954-
QString::fromLatin1("Rejected enum has no alternative...: %1::%2")
955-
.arg(meta_class->name())
956-
.arg(reject->name()));
957-
continue;
958-
}
959-
ete->addEnumValueRedirection(reject->name(), used->name());
960-
}
961-
962-
}
963-
}
964-
965-
966-
967-
*classes += meta_class;
968-
}
969-
970-
971-
void AbstractMetaBuilder::figureOutEnumValues()
972-
{
973-
// Keep a set of classes that we already traversed. We use this to
974-
// enforce that we traverse base classes prior to subclasses.
975-
QSet<AbstractMetaClass *> classes;
976-
for (AbstractMetaClass *c : m_meta_classes) {
977-
figureOutEnumValuesForClass(c, &classes);
978-
}
979-
}
980-
981763

982764
AbstractMetaEnum *AbstractMetaBuilder::traverseEnum(EnumModelItem enum_item, AbstractMetaClass *enclosing, const QSet<QString> &enumsDeclarations)
983765
{

generator/abstractmetabuilder.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ class AbstractMetaBuilder
8484

8585
void autoAddQEnumsForClassItem(ClassModelItem item);
8686

87-
void figureOutEnumValuesForClass(AbstractMetaClass *meta_class, QSet<AbstractMetaClass *> *classes);
88-
int figureOutEnumValue(const QString &name, int value, AbstractMetaEnum *meta_enum, AbstractMetaFunction *meta_function = 0);
89-
void figureOutEnumValues();
90-
9187
void addAbstractMetaClass(AbstractMetaClass *cls);
9288
AbstractMetaClass *traverseTypeAlias(TypeAliasModelItem item);
9389
AbstractMetaClass *traverseClass(ClassModelItem item);

generator/typesystem.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,19 +1742,6 @@ QString FlagsTypeEntry::jniName() const
17421742
return "jint";
17431743
}
17441744

1745-
void EnumTypeEntry::addEnumValueRedirection(const QString &rejected, const QString &usedValue)
1746-
{
1747-
m_enum_redirections << EnumValueRedirection(rejected, usedValue);
1748-
}
1749-
1750-
QString EnumTypeEntry::enumValueRedirection(const QString &value) const
1751-
{
1752-
for (int i=0; i<m_enum_redirections.size(); ++i)
1753-
if (m_enum_redirections.at(i).rejected == value)
1754-
return m_enum_redirections.at(i).used;
1755-
return QString();
1756-
}
1757-
17581745
QString FlagsTypeEntry::qualifiedTargetLangName() const
17591746
{
17601747
return javaPackage() + "." + m_enum->javaQualifier() + "." + targetLangName();

generator/typesystem.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,6 @@ class EnumTypeEntry : public TypeEntry
727727
void addEnumValueRejection(const QString &name) { m_rejected_enums << name; }
728728
QStringList enumValueRejections() const { return m_rejected_enums; }
729729

730-
void addEnumValueRedirection(const QString &rejected, const QString &usedValue);
731-
QString enumValueRedirection(const QString &value) const;
732-
733730
bool isEnumClass() const { return m_enum_class; }
734731
void setEnumClass(bool enum_class) { m_enum_class = enum_class; }
735732

@@ -746,7 +743,6 @@ class EnumTypeEntry : public TypeEntry
746743
QString m_upper_bound;
747744

748745
QStringList m_rejected_enums;
749-
QList<EnumValueRedirection> m_enum_redirections;
750746

751747
FlagsTypeEntry *m_flags;
752748

0 commit comments

Comments
 (0)