@@ -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
982764AbstractMetaEnum *AbstractMetaBuilder::traverseEnum (EnumModelItem enum_item, AbstractMetaClass *enclosing, const QSet<QString> &enumsDeclarations)
983765{
0 commit comments