int EventTypeSet::addKnownDerivedTypes() { int addCount = 0; int addDiff, i; int knownCount = EventType::knownTypeCount(); while (1) { addDiff = 0; for (i=0; i<knownCount; i++) { EventType* t = EventType::knownType(i); if (t->isReal()) continue; if (index(t->name()) != ProfileCostArray::InvalidIndex) continue; t->setEventTypeSet(this); if (t->parseFormula()) { addDiff++; add(new EventType(t->name(), t->longName(), t->formula())); } t->setEventTypeSet(0); } if (addDiff == 0) break; addCount += addDiff; } return addCount; }
// checks for existing types and sets coefficients bool EventType::parseFormula() { if (_parsed) return true; if (_inParsing) { qDebug("TraceEventType::parseFormula: Recursion detected."); return false; } if (!_set) { qDebug("TraceEventType::parseFormula: Container of this event type unknown!"); return false; } _inParsing = true; for (int i=0; i<ProfileCostArray::MaxRealIndex;i++) _coefficient[i] = 0; QRegExp rx( "((?:\\+|\\-)?)\\s*(\\d*)\\s*\\*?\\s*(\\w+)" ); int factor, pos; QString costName; EventType* eventType; pos = 0; while (1) { pos = rx.search(_formula, pos); if (pos<0) break; pos += rx.matchedLength(); if (rx.cap(0).isEmpty()) break; //qDebug("parseFormula: matched '%s','%s','%s'", // qPrintable(rx.cap(1)), qPrintable(rx.cap(2)), qPrintable(rx.cap(3))); costName = rx.cap(3); eventType = _set->type(costName); if (!eventType) { // qDebug("Cost type '%s': In formula cost '%s' unknown.", // qPrintable(_name), qPrintable(costName)); _inParsing = false; return false; } factor = (rx.cap(2).isEmpty()) ? 1 : rx.cap(2).toInt(); if (rx.cap(1) == "-") factor = -factor; if (eventType->isReal()) _coefficient[eventType->realIndex()] += factor; else { eventType->parseFormula(); for (int i=0; i<ProfileCostArray::MaxRealIndex;i++) _coefficient[i] += factor * eventType->_coefficient[i]; } } _inParsing = false; _parsed = true; return true; }