void Parser::parseStrategiesFromFile(QWidget *parent, std::vector<Strategy*> &res, QString filename) { QFile* file = new QFile(filename); if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) { QMessageBox::critical(parent,"Load XML File Problem", "Couldn't open xml file: " + filename, QMessageBox::Ok); } QXmlStreamReader xml(file); while (!xml.atEnd() && !xml.hasError()) { QXmlStreamReader::TokenType token = xml.readNext(); if (token == QXmlStreamReader::StartElement) { if (xml.name().toString() == "strategy") { //parse strategy header.. QXmlStreamAttributes str_attr = xml.attributes(); QString pos = str_attr.value("position").toString(); std::pair<int, int> from_to = parseStack(str_attr.value("stack").toString()); Strategy *st = new Strategy(pos, from_to.first, from_to.second); //parse strategy body.. parseStrategy(xml, st); res.push_back(st); } } } }
void Parser::Private::parseAnnounceThread() { AnnounceThread at; while (notAtEnd()) { blockingReadNext(); if (reader.isEndElement()) break; if (reader.isStartElement()) { const QStringRef name = reader.name(); if (name == QLatin1String("hthreadid")) at.setHelgrindThreadId(parseInt64(blockingReadElementText(), QLatin1String("announcethread/hthreadid"))); else if (name == QLatin1String("stack")) at.setStack(parseStack()); else if (reader.isStartElement()) reader.skipCurrentElement(); } } emit q->announceThread(at); }
void Parser::Private::parseError() { Error e; QVector<QVector<Frame> > frames; XauxWhat currentAux; QVector<XauxWhat> auxs; int lastAuxWhat = -1; while (notAtEnd()) { blockingReadNext(); if (reader.isEndElement()) break; if (reader.isStartElement()) lastAuxWhat++; const QStringRef name = reader.name(); if (name == QLatin1String("unique")) { e.setUnique(parseHex(blockingReadElementText(), QLatin1String("unique"))); } else if (name == QLatin1String("tid")) { e.setTid(parseInt64(blockingReadElementText(), QLatin1String("error/tid"))); } else if (name == QLatin1String("kind")) { //TODO this is memcheck-specific: e.setKind(parseErrorKind(blockingReadElementText())); } else if (name == QLatin1String("suppression")) { e.setSuppression(parseSuppression()); } else if (name == QLatin1String("xwhat")) { const XWhat xw = parseXWhat(); e.setWhat(xw.text); e.setLeakedBlocks(xw.leakedblocks); e.setLeakedBytes(xw.leakedbytes); e.setHelgrindThreadId(xw.hthreadid); } else if (name == QLatin1String("what")) { e.setWhat(blockingReadElementText()); } else if (name == QLatin1String("xauxwhat")) { if (!currentAux.text.isEmpty()) auxs.push_back(currentAux); currentAux = parseXauxWhat(); } else if (name == QLatin1String("auxwhat")) { const QString aux = blockingReadElementText(); //concatenate multiple consecutive <auxwhat> tags if (lastAuxWhat > 1) { if (!currentAux.text.isEmpty()) auxs.push_back(currentAux); currentAux.clear(); currentAux.text = aux; } else { if (!currentAux.text.isEmpty()) currentAux.text.append(QLatin1Char(' ')); currentAux.text.append(aux); } lastAuxWhat = 0; } else if (name == QLatin1String("stack")) { frames.push_back(parseStack()); } else if (reader.isStartElement()) { reader.skipCurrentElement(); } } if (!currentAux.text.isEmpty()) auxs.push_back(currentAux); //if we have less xaux/auxwhats than stacks, prepend empty xauxwhats //(the first frame usually has not xauxwhat in helgrind and memcheck) while (auxs.size() < frames.size()) auxs.prepend(XauxWhat()); QVector<Stack> stacks; for (int i = 0; i < auxs.size(); ++i) stacks.append(makeStack(auxs[i], frames[i])); e.setStacks(stacks); emit q->error(e); }