analyzer: code cosmetics

Change-Id: Id00cf1be9d07e47f7b61b8cc7e940629c84a48c1
Reviewed-on: http://codereview.qt.nokia.com/2707
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
hjk
2011-08-05 18:03:37 +02:00
committed by hjk
parent 1f36bcaca3
commit 7b3ba73a01
7 changed files with 163 additions and 163 deletions

View File

@@ -44,33 +44,65 @@
#include "xmlprotocol/modelhelpers.h" #include "xmlprotocol/modelhelpers.h"
#include "xmlprotocol/suppression.h" #include "xmlprotocol/suppression.h"
#include <texteditor/basetexteditor.h> #include <coreplugin/coreconstants.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <coreplugin/coreconstants.h> #include <texteditor/basetexteditor.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QClipboard>
#include <QtGui/QLabel> #include <QtGui/QLabel>
#include <QtGui/QListView> #include <QtGui/QListView>
#include <QtGui/QMenu>
#include <QtGui/QPainter> #include <QtGui/QPainter>
#include <QtGui/QScrollBar> #include <QtGui/QScrollBar>
#include <QtGui/QSortFilterProxyModel> #include <QtGui/QSortFilterProxyModel>
#include <QtGui/QStyledItemDelegate>
#include <QtGui/QVBoxLayout> #include <QtGui/QVBoxLayout>
#include <QtGui/QAction>
#include <QtGui/QClipboard>
#include <QtGui/QApplication>
#include <QtGui/QMenu>
using namespace Valgrind::XmlProtocol; using namespace Valgrind::XmlProtocol;
namespace Valgrind { namespace Valgrind {
namespace Internal { namespace Internal {
class MemcheckErrorDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
/// This delegate can only work on one view at a time, parent. parent will also be the parent
/// in the QObject parent-child system.
explicit MemcheckErrorDelegate(QListView *parent);
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
public slots:
void currentChanged(const QModelIndex &now, const QModelIndex &previous);
void viewResized();
void layoutChanged();
void copy();
private slots:
void verticalScrolled();
void openLinkInEditor(const QString &link);
private:
// the constness of this method is a necessary lie because it is called from paint() const.
QWidget *createDetailsWidget(const QModelIndex &errorIndex, QWidget *parent) const;
static const int s_itemMargin = 2;
mutable QPersistentModelIndex m_detailsIndex;
mutable QWidget *m_detailsWidget;
mutable int m_detailsWidgetHeight;
};
MemcheckErrorDelegate::MemcheckErrorDelegate(QListView *parent) MemcheckErrorDelegate::MemcheckErrorDelegate(QListView *parent)
: QStyledItemDelegate(parent), : QStyledItemDelegate(parent),
m_detailsWidget(0) m_detailsWidget(0)
@@ -84,8 +116,7 @@ QSize MemcheckErrorDelegate::sizeHint(const QStyleOptionViewItem &opt, const QMo
const QListView *view = qobject_cast<const QListView *>(parent()); const QListView *view = qobject_cast<const QListView *>(parent());
const int viewportWidth = view->viewport()->width(); const int viewportWidth = view->viewport()->width();
const bool isSelected = view->selectionModel()->currentIndex() == index; const bool isSelected = view->selectionModel()->currentIndex() == index;
const int dy = 2 * s_itemMargin;
int dy = 2 * s_itemMargin;
if (!isSelected) { if (!isSelected) {
QFontMetrics fm(opt.font); QFontMetrics fm(opt.font);
@@ -153,20 +184,20 @@ static QString makeFrameName(const Frame &frame, const QString &relativeTo,
return QString("0x%1").arg(frame.instructionPointer(), 0, 16); return QString("0x%1").arg(frame.instructionPointer(), 0, 16);
} }
QString relativeToPath() static QString relativeToPath()
{ {
// project for which we insert the snippet // The project for which we insert the snippet.
const ProjectExplorer::Project *project = const ProjectExplorer::Project *project =
ProjectExplorer::ProjectExplorerPlugin::instance()->startupProject(); ProjectExplorer::ProjectExplorerPlugin::instance()->startupProject();
QString relativeTo( project ? project->projectDirectory() : QDir::homePath() ); QString relativeTo(project ? project->projectDirectory() : QDir::homePath());
if (!relativeTo.endsWith(QDir::separator())) if (!relativeTo.endsWith(QDir::separator()))
relativeTo.append(QDir::separator()); relativeTo.append(QDir::separator());
return relativeTo; return relativeTo;
} }
QString errorLocation(const QModelIndex &index, const Error &error, static QString errorLocation(const QModelIndex &index, const Error &error,
bool link = false, const QString &linkAttr = QString()) bool link = false, const QString &linkAttr = QString())
{ {
const ErrorListModel *model = 0; const ErrorListModel *model = 0;
@@ -190,9 +221,7 @@ QWidget *MemcheckErrorDelegate::createDetailsWidget(const QModelIndex &errorInde
// don't include frameName here as it should wrap if required and pre-line is not supported // don't include frameName here as it should wrap if required and pre-line is not supported
// by Qt yet it seems // by Qt yet it seems
const QString displayTextTemplate = QString("<code style='white-space:pre'>%1:</code> %2"); const QString displayTextTemplate = QString("<code style='white-space:pre'>%1:</code> %2");
const QString relativeTo = relativeToPath();
QString relativeTo = relativeToPath();
const Error error = errorIndex.data(ErrorListModel::ErrorRole).value<Error>(); const Error error = errorIndex.data(ErrorListModel::ErrorRole).value<Error>();
QLabel *errorLabel = new QLabel(); QLabel *errorLabel = new QLabel();
@@ -541,3 +570,5 @@ void MemcheckErrorView::setCurrentRow(int row)
} // namespace Internal } // namespace Internal
} // namespace Valgrind } // namespace Valgrind
#include "memcheckerrorview.moc"

View File

@@ -36,53 +36,14 @@
#define MEMCHECKERRORVIEW_H #define MEMCHECKERRORVIEW_H
#include <QtGui/QListView> #include <QtGui/QListView>
#include <QtGui/QStyledItemDelegate>
#include <QtGui/QLabel>
namespace Analyzer { namespace Analyzer {
class AnalyzerSettings; class AnalyzerSettings;
} }
namespace ProjectExplorer {
class Project;
}
namespace Valgrind { namespace Valgrind {
namespace Internal { namespace Internal {
class MemcheckErrorDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
/// This delegate can only work on one view at a time, parent. parent will also be the parent
/// in the QObject parent-child system.
explicit MemcheckErrorDelegate(QListView *parent);
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
public slots:
void currentChanged(const QModelIndex &now, const QModelIndex &previous);
void viewResized();
void layoutChanged();
void copy();
private slots:
void verticalScrolled();
void openLinkInEditor(const QString &link);
private:
// the constness of this method is a necessary lie because it is called from paint() const.
QWidget *createDetailsWidget(const QModelIndex &errorIndex, QWidget *parent) const;
static const int s_itemMargin = 2;
mutable QPersistentModelIndex m_detailsIndex;
mutable QWidget *m_detailsWidget;
mutable int m_detailsWidgetHeight;
};
class MemcheckErrorView : public QListView class MemcheckErrorView : public QListView
{ {
Q_OBJECT Q_OBJECT

View File

@@ -137,17 +137,23 @@ QString ErrorListModel::Private::formatLocation(const Error &error) const
QVariant ErrorListModel::Private::errorData(int row, int column, int role) const QVariant ErrorListModel::Private::errorData(int row, int column, int role) const
{ {
// A dummy entry.
if (row == 0 && errors.isEmpty()) {
if (role == Qt::DisplayRole)
return tr("No errors found");
if (role == ErrorRole)
return tr("No errors found");
return QVariant();
}
if (row < 0 || row >= errors.size()) if (row < 0 || row >= errors.size())
return QVariant(); return QVariant();
const Error &error = errors[row];
const QVector<Stack> stacks = error.stacks(); const Error &error = errors.at(row);
const Stack stack = !stacks.isEmpty() ? stacks.first() : Stack();
if (error.stacks().count()) if (error.stacks().count())
switch (role) { switch (role) {
case Qt::DisplayRole: case Qt::DisplayRole: {
{
switch (column) { switch (column) {
case WhatColumn: case WhatColumn:
return error.what(); return error.what();
@@ -155,8 +161,7 @@ QVariant ErrorListModel::Private::errorData(int row, int column, int role) const
return formatLocation(error); return formatLocation(error);
case AbsoluteFilePathColumn: case AbsoluteFilePathColumn:
return formatAbsoluteFilePath(error); return formatAbsoluteFilePath(error);
case LineColumn: case LineColumn: {
{
const qint64 line = findRelevantFrame(error).line(); const qint64 line = findRelevantFrame(error).line();
return line > 0 ? line : QVariant(); return line > 0 ? line : QVariant();
} }
@@ -177,17 +182,14 @@ QVariant ErrorListModel::Private::errorData(int row, int column, int role) const
} }
} }
case Qt::ToolTipRole: case Qt::ToolTipRole:
{
return toolTipForFrame(findRelevantFrame(error)); return toolTipForFrame(findRelevantFrame(error));
}
case ErrorRole: case ErrorRole:
return QVariant::fromValue<Error>(error); return QVariant::fromValue<Error>(error);
case AbsoluteFilePathRole: case AbsoluteFilePathRole:
return formatAbsoluteFilePath(error); return formatAbsoluteFilePath(error);
case FileRole: case FileRole:
return findRelevantFrame(error).file(); return findRelevantFrame(error).file();
case LineRole: case LineRole: {
{
const qint64 line = findRelevantFrame(error).line(); const qint64 line = findRelevantFrame(error).line();
return line > 0 ? line : QVariant(); return line > 0 ? line : QVariant();
} }
@@ -200,8 +202,6 @@ QVariant ErrorListModel::data(const QModelIndex &index, int role) const
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
QTC_ASSERT(index.model() == this, return QVariant());
if (!index.parent().isValid()) if (!index.parent().isValid())
return d->errorData(index.row(), index.column(), role); return d->errorData(index.row(), index.column(), role);
@@ -241,13 +241,9 @@ QVariant ErrorListModel::headerData(int section, Qt::Orientation orientation, in
int ErrorListModel::rowCount(const QModelIndex &parent) const int ErrorListModel::rowCount(const QModelIndex &parent) const
{ {
//root if (parent.isValid())
if (!parent.isValid()) return 0;
return d->errors.count(); return qMax(1, d->errors.count());
QTC_ASSERT(parent.model() == this, return 0);
return 0;
} }
int ErrorListModel::columnCount(const QModelIndex &parent) const int ErrorListModel::columnCount(const QModelIndex &parent) const
@@ -286,7 +282,7 @@ Error ErrorListModel::error(const QModelIndex &index) const
const int r = index.row(); const int r = index.row();
if (r < 0 || r >= d->errors.size()) if (r < 0 || r >= d->errors.size())
return Error(); return Error();
return d->errors[r]; return d->errors.at(r);
} }
void ErrorListModel::clear() void ErrorListModel::clear()

View File

@@ -47,9 +47,10 @@ class Frame;
class ErrorListModel : public QAbstractItemModel class ErrorListModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
public: public:
enum Column { enum Column {
WhatColumn=0, WhatColumn = 0,
LocationColumn, LocationColumn,
AbsoluteFilePathColumn, AbsoluteFilePathColumn,
LineColumn, LineColumn,
@@ -63,7 +64,7 @@ public:
}; };
enum Role { enum Role {
ErrorRole=Qt::UserRole, ErrorRole = Qt::UserRole,
AbsoluteFilePathRole, AbsoluteFilePathRole,
FileRole, FileRole,
LineRole LineRole
@@ -96,7 +97,7 @@ public:
void clear(); void clear();
public Q_SLOTS: public slots:
void addError(const Valgrind::XmlProtocol::Error &error); void addError(const Valgrind::XmlProtocol::Error &error);
private: private:

View File

@@ -94,21 +94,22 @@ namespace XmlProtocol {
class Parser::Private class Parser::Private
{ {
Parser *const q;
public: public:
explicit Private(Parser *qq); explicit Private(Parser *qq);
void parse(QIODevice *device); void parse(QIODevice *device);
QString errorString;
void parse_error(); private:
void parseError();
QVector<Frame> parseStack(); QVector<Frame> parseStack();
Suppression parseSuppression(); Suppression parseSuppression();
SuppressionFrame parseSuppressionFrame(); SuppressionFrame parseSuppressionFrame();
Frame parse_frame(); Frame parseFrame();
void parse_status(); void parseStatus();
void parse_errorcounts(); void parseErrorCounts();
void parse_suppcounts(); void parseSuppressionCounts();
void parse_announcethread(); void parseAnnounceThread();
void checkProtocolVersion(const QString &versionStr); void checkProtocolVersion(const QString &versionStr);
void checkTool(const QString &tool); void checkTool(const QString &tool);
XWhat parseXWhat(); XWhat parseXWhat();
@@ -124,12 +125,14 @@ public:
QString blockingReadElementText(); QString blockingReadElementText();
Tool tool; Tool tool;
QString errorString;
QXmlStreamReader reader; QXmlStreamReader reader;
QHash<QString,MemcheckErrorKind> errorKindsByName_memcheck; QHash<QString, MemcheckErrorKind> errorKindsByName_memcheck;
QHash<QString,HelgrindErrorKind> errorKindsByName_helgrind; QHash<QString, HelgrindErrorKind> errorKindsByName_helgrind;
QHash<QString,PtrcheckErrorKind> errorKindsByName_ptrcheck; QHash<QString, PtrcheckErrorKind> errorKindsByName_ptrcheck;
QHash<QString,Parser::Tool> toolsByName; QHash<QString, Parser::Tool> toolsByName;
private:
Parser *const q;
}; };
#undef ADD_ENUM #undef ADD_ENUM
@@ -137,9 +140,9 @@ public:
Parser::Private::Private(Parser *qq) Parser::Private::Private(Parser *qq)
: q(qq), : q(qq)
tool(Parser::Unknown)
{ {
tool = Parser::Unknown;
toolsByName.insert(QLatin1String("memcheck"), Parser::Memcheck); toolsByName.insert(QLatin1String("memcheck"), Parser::Memcheck);
toolsByName.insert(QLatin1String("ptrcheck"), Parser::Ptrcheck); toolsByName.insert(QLatin1String("ptrcheck"), Parser::Ptrcheck);
toolsByName.insert(QLatin1String("exp-ptrcheck"), Parser::Ptrcheck); toolsByName.insert(QLatin1String("exp-ptrcheck"), Parser::Ptrcheck);
@@ -311,13 +314,14 @@ XWhat Parser::Private::parseXWhat()
blockingReadNext(); blockingReadNext();
if (reader.isEndElement()) if (reader.isEndElement())
break; break;
if (reader.name() == QLatin1String("text")) const QStringRef name = reader.name();
if (name == QLatin1String("text"))
what.text = blockingReadElementText(); what.text = blockingReadElementText();
else if (reader.name() == QLatin1String("leakedbytes")) else if (name == QLatin1String("leakedbytes"))
what.leakedbytes = parseInt64(blockingReadElementText(), QLatin1String("error/xwhat[memcheck]/leakedbytes")); what.leakedbytes = parseInt64(blockingReadElementText(), QLatin1String("error/xwhat[memcheck]/leakedbytes"));
else if (reader.name() == QLatin1String("leakedblocks")) else if (name == QLatin1String("leakedblocks"))
what.leakedblocks = parseInt64(blockingReadElementText(), QLatin1String("error/xwhat[memcheck]/leakedblocks")); what.leakedblocks = parseInt64(blockingReadElementText(), QLatin1String("error/xwhat[memcheck]/leakedblocks"));
else if (reader.name() == QLatin1String("hthreadid")) else if (name == QLatin1String("hthreadid"))
what.hthreadid = parseInt64(blockingReadElementText(), QLatin1String("error/xwhat[memcheck]/hthreadid")); what.hthreadid = parseInt64(blockingReadElementText(), QLatin1String("error/xwhat[memcheck]/hthreadid"));
else if (reader.isStartElement()) else if (reader.isStartElement())
reader.skipCurrentElement(); reader.skipCurrentElement();
@@ -332,15 +336,16 @@ XauxWhat Parser::Private::parseXauxWhat()
blockingReadNext(); blockingReadNext();
if (reader.isEndElement()) if (reader.isEndElement())
break; break;
if (reader.name() == QLatin1String("text")) const QStringRef name = reader.name();
if (name == QLatin1String("text"))
what.text = blockingReadElementText(); what.text = blockingReadElementText();
else if (reader.name() == QLatin1String("file")) else if (name == QLatin1String("file"))
what.file = blockingReadElementText(); what.file = blockingReadElementText();
else if (reader.name() == QLatin1String("dir")) else if (name == QLatin1String("dir"))
what.dir = blockingReadElementText(); what.dir = blockingReadElementText();
else if (reader.name() == QLatin1String("line")) else if (name == QLatin1String("line"))
what.line = parseInt64(blockingReadElementText(), QLatin1String("error/xauxwhat/line")); what.line = parseInt64(blockingReadElementText(), QLatin1String("error/xauxwhat/line"));
else if (reader.name() == QLatin1String("hthreadid")) else if (name == QLatin1String("hthreadid"))
what.hthreadid = parseInt64(blockingReadElementText(), QLatin1String("error/xauxwhat/hthreadid")); what.hthreadid = parseInt64(blockingReadElementText(), QLatin1String("error/xauxwhat/hthreadid"));
else if (reader.isStartElement()) else if (reader.isStartElement())
reader.skipCurrentElement(); reader.skipCurrentElement();
@@ -425,7 +430,7 @@ static Stack makeStack(const XauxWhat &xauxwhat, const QVector<Frame> &frames)
return s; return s;
} }
void Parser::Private::parse_error() void Parser::Private::parseError()
{ {
Error e; Error e;
QVector<QVector<Frame> > frames; QVector<QVector<Frame> > frames;
@@ -439,29 +444,30 @@ void Parser::Private::parse_error()
break; break;
if (reader.isStartElement()) if (reader.isStartElement())
lastAuxWhat++; lastAuxWhat++;
if (reader.name() == QLatin1String("unique")) const QStringRef name = reader.name();
if (name == QLatin1String("unique"))
e.setUnique(parseHex(blockingReadElementText(), QLatin1String("unique"))); e.setUnique(parseHex(blockingReadElementText(), QLatin1String("unique")));
else if ( reader.name() == QLatin1String("tid")) else if (name == QLatin1String("tid"))
e.setTid(parseInt64(blockingReadElementText(), QLatin1String("error/tid"))); e.setTid(parseInt64(blockingReadElementText(), QLatin1String("error/tid")));
else if (reader.name() == QLatin1String("kind")) //TODO this is memcheck-specific: else if (name == QLatin1String("kind")) //TODO this is memcheck-specific:
e.setKind(parseErrorKind(blockingReadElementText())); e.setKind(parseErrorKind(blockingReadElementText()));
else if (reader.name() == QLatin1String("suppression")) else if (name == QLatin1String("suppression"))
e.setSuppression(parseSuppression()); e.setSuppression(parseSuppression());
else if (reader.name() == QLatin1String("xwhat")) { else if (name == QLatin1String("xwhat")) {
const XWhat xw = parseXWhat(); const XWhat xw = parseXWhat();
e.setWhat(xw.text); e.setWhat(xw.text);
e.setLeakedBlocks(xw.leakedblocks); e.setLeakedBlocks(xw.leakedblocks);
e.setLeakedBytes(xw.leakedbytes); e.setLeakedBytes(xw.leakedbytes);
e.setHelgrindThreadId(xw.hthreadid); e.setHelgrindThreadId(xw.hthreadid);
} }
else if (reader.name() == QLatin1String("what")) else if (name == QLatin1String("what"))
e.setWhat(blockingReadElementText()); e.setWhat(blockingReadElementText());
else if (reader.name() == QLatin1String("xauxwhat")) { else if (name == QLatin1String("xauxwhat")) {
if (!currentAux.text.isEmpty()) if (!currentAux.text.isEmpty())
auxs.push_back(currentAux); auxs.push_back(currentAux);
currentAux = parseXauxWhat(); currentAux = parseXauxWhat();
} }
else if (reader.name() == QLatin1String("auxwhat")) { else if (name == QLatin1String("auxwhat")) {
const QString aux = blockingReadElementText(); const QString aux = blockingReadElementText();
//concatenate multiple consecutive <auxwhat> tags //concatenate multiple consecutive <auxwhat> tags
if (lastAuxWhat > 1) { if (lastAuxWhat > 1) {
@@ -476,7 +482,7 @@ void Parser::Private::parse_error()
} }
lastAuxWhat = 0; lastAuxWhat = 0;
} }
else if (reader.name() == QLatin1String("stack")) { else if (name == QLatin1String("stack")) {
frames.push_back(parseStack()); frames.push_back(parseStack());
} }
else if (reader.isStartElement()) else if (reader.isStartElement())
@@ -499,7 +505,7 @@ void Parser::Private::parse_error()
emit q->error(e); emit q->error(e);
} }
Frame Parser::Private::parse_frame() Frame Parser::Private::parseFrame()
{ {
Frame frame; Frame frame;
@@ -508,17 +514,18 @@ Frame Parser::Private::parse_frame()
if (reader.isEndElement()) if (reader.isEndElement())
break; break;
if (reader.isStartElement()) { if (reader.isStartElement()) {
if (reader.name() == QLatin1String("ip")) const QStringRef name = reader.name();
if (name == QLatin1String("ip"))
frame.setInstructionPointer(parseHex(blockingReadElementText(), QLatin1String("error/frame/ip"))); frame.setInstructionPointer(parseHex(blockingReadElementText(), QLatin1String("error/frame/ip")));
else if (reader.name() == QLatin1String("obj")) else if (name == QLatin1String("obj"))
frame.setObject(blockingReadElementText()); frame.setObject(blockingReadElementText());
else if (reader.name() == QLatin1String("fn")) else if (name == QLatin1String("fn"))
frame.setFunctionName( blockingReadElementText()); frame.setFunctionName( blockingReadElementText());
else if (reader.name() == QLatin1String("dir")) else if (name == QLatin1String("dir"))
frame.setDirectory(blockingReadElementText()); frame.setDirectory(blockingReadElementText());
else if (reader.name() == QLatin1String("file")) else if (name == QLatin1String("file"))
frame.setFile( blockingReadElementText()); frame.setFile( blockingReadElementText());
else if (reader.name() == QLatin1String("line")) else if (name == QLatin1String("line"))
frame.setLine(parseInt64(blockingReadElementText(), QLatin1String("error/frame/line"))); frame.setLine(parseInt64(blockingReadElementText(), QLatin1String("error/frame/line")));
else if (reader.isStartElement()) else if (reader.isStartElement())
reader.skipCurrentElement(); reader.skipCurrentElement();
@@ -528,7 +535,7 @@ Frame Parser::Private::parse_frame()
return frame; return frame;
} }
void Parser::Private::parse_announcethread() void Parser::Private::parseAnnounceThread()
{ {
AnnounceThread at; AnnounceThread at;
@@ -537,9 +544,10 @@ void Parser::Private::parse_announcethread()
if (reader.isEndElement()) if (reader.isEndElement())
break; break;
if (reader.isStartElement()) { if (reader.isStartElement()) {
if (reader.name() == QLatin1String("hthreadid")) const QStringRef name = reader.name();
if (name == QLatin1String("hthreadid"))
at.setHelgrindThreadId(parseInt64(blockingReadElementText(), QLatin1String("announcethread/hthreadid"))); at.setHelgrindThreadId(parseInt64(blockingReadElementText(), QLatin1String("announcethread/hthreadid")));
else if (reader.name() == QLatin1String("stack")) else if (name == QLatin1String("stack"))
at.setStack(parseStack()); at.setStack(parseStack());
else if (reader.isStartElement()) else if (reader.isStartElement())
reader.skipCurrentElement(); reader.skipCurrentElement();
@@ -549,7 +557,7 @@ void Parser::Private::parse_announcethread()
emit q->announceThread(at); emit q->announceThread(at);
} }
void Parser::Private::parse_errorcounts() void Parser::Private::parseErrorCounts()
{ {
while (notAtEnd()) { while (notAtEnd()) {
blockingReadNext(); blockingReadNext();
@@ -564,9 +572,10 @@ void Parser::Private::parse_errorcounts()
if (reader.isEndElement()) if (reader.isEndElement())
break; break;
if (reader.isStartElement()) { if (reader.isStartElement()) {
if (reader.name() == QLatin1String("unique")) const QStringRef name = reader.name();
if (name == QLatin1String("unique"))
unique = parseHex(blockingReadElementText(), QLatin1String("errorcounts/pair/unique")); unique = parseHex(blockingReadElementText(), QLatin1String("errorcounts/pair/unique"));
else if (reader.name() == QLatin1String("count")) else if (name == QLatin1String("count"))
count = parseInt64(blockingReadElementText(), QLatin1String("errorcounts/pair/count")); count = parseInt64(blockingReadElementText(), QLatin1String("errorcounts/pair/count"));
else if (reader.isStartElement()) else if (reader.isStartElement())
reader.skipCurrentElement(); reader.skipCurrentElement();
@@ -581,7 +590,7 @@ void Parser::Private::parse_errorcounts()
} }
void Parser::Private::parse_suppcounts() void Parser::Private::parseSuppressionCounts()
{ {
while (notAtEnd()) { while (notAtEnd()) {
blockingReadNext(); blockingReadNext();
@@ -589,22 +598,23 @@ void Parser::Private::parse_suppcounts()
break; break;
if (reader.isStartElement()) { if (reader.isStartElement()) {
if (reader.name() == QLatin1String("pair")) { if (reader.name() == QLatin1String("pair")) {
QString name; QString pairName;
qint64 count = 0; qint64 count = 0;
while (notAtEnd()) { while (notAtEnd()) {
blockingReadNext(); blockingReadNext();
if (reader.isEndElement()) if (reader.isEndElement())
break; break;
if (reader.isStartElement()) { if (reader.isStartElement()) {
if (reader.name() == QLatin1String("name")) const QStringRef name = reader.name();
name = blockingReadElementText(); if (name == QLatin1String("name"))
else if (reader.name() == QLatin1String("count")) pairName = blockingReadElementText();
else if (name == QLatin1String("count"))
count = parseInt64(blockingReadElementText(), QLatin1String("suppcounts/pair/count")); count = parseInt64(blockingReadElementText(), QLatin1String("suppcounts/pair/count"));
else if (reader.isStartElement()) else if (reader.isStartElement())
reader.skipCurrentElement(); reader.skipCurrentElement();
} }
} }
emit q->suppressionCount(name, count); emit q->suppressionCount(pairName, count);
} }
else if (reader.isStartElement()) else if (reader.isStartElement())
reader.skipCurrentElement(); reader.skipCurrentElement();
@@ -612,7 +622,7 @@ void Parser::Private::parse_suppcounts()
} }
} }
void Parser::Private::parse_status() void Parser::Private::parseStatus()
{ {
Status s; Status s;
@@ -621,9 +631,10 @@ void Parser::Private::parse_status()
if (reader.isEndElement()) if (reader.isEndElement())
break; break;
if (reader.isStartElement()) { if (reader.isStartElement()) {
if (reader.name() == QLatin1String("state")) const QStringRef name = reader.name();
if (name == QLatin1String("state"))
s.setState(parseState(blockingReadElementText())); s.setState(parseState(blockingReadElementText()));
else if (reader.name() == QLatin1String("time")) else if (name == QLatin1String("time"))
s.setTime(blockingReadElementText()); s.setTime(blockingReadElementText());
else if (reader.isStartElement()) else if (reader.isStartElement())
reader.skipCurrentElement(); reader.skipCurrentElement();
@@ -642,7 +653,7 @@ QVector<Frame> Parser::Private::parseStack()
break; break;
if (reader.isStartElement()) { if (reader.isStartElement()) {
if (reader.name() == QLatin1String("frame")) if (reader.name() == QLatin1String("frame"))
frames.append(parse_frame()); frames.append(parseFrame());
} }
} }
@@ -658,9 +669,10 @@ SuppressionFrame Parser::Private::parseSuppressionFrame()
if (reader.isEndElement()) if (reader.isEndElement())
break; break;
if (reader.isStartElement()) { if (reader.isStartElement()) {
if (reader.name() == QLatin1String("obj")) const QStringRef name = reader.name();
if (name == QLatin1String("obj"))
frame.setObject(blockingReadElementText()); frame.setObject(blockingReadElementText());
else if (reader.name() == QLatin1String("fun")) else if (name == QLatin1String("fun"))
frame.setFunction( blockingReadElementText()); frame.setFunction( blockingReadElementText());
else if (reader.isStartElement()) else if (reader.isStartElement())
reader.skipCurrentElement(); reader.skipCurrentElement();
@@ -679,15 +691,16 @@ Suppression Parser::Private::parseSuppression()
if (reader.isEndElement()) if (reader.isEndElement())
break; break;
if (reader.isStartElement()) { if (reader.isStartElement()) {
if (reader.name() == QLatin1String("sname")) const QStringRef name = reader.name();
if (name == QLatin1String("sname"))
supp.setName(blockingReadElementText()); supp.setName(blockingReadElementText());
else if (reader.name() == QLatin1String("skind")) else if (name == QLatin1String("skind"))
supp.setKind(blockingReadElementText()); supp.setKind(blockingReadElementText());
else if (reader.name() == QLatin1String("skaux")) else if (name == QLatin1String("skaux"))
supp.setAuxKind(blockingReadElementText()); supp.setAuxKind(blockingReadElementText());
else if (reader.name() == QLatin1String("rawtext")) else if (name == QLatin1String("rawtext"))
supp.setRawText(blockingReadElementText()); supp.setRawText(blockingReadElementText());
else if (reader.name() == QLatin1String("sframe")) else if (name == QLatin1String("sframe"))
frames.push_back(parseSuppressionFrame()); frames.push_back(parseSuppressionFrame());
} }
} }
@@ -704,19 +717,20 @@ void Parser::Private::parse(QIODevice *device)
try { try {
while (notAtEnd()) { while (notAtEnd()) {
blockingReadNext(); blockingReadNext();
if (reader.name() == QLatin1String("error")) QStringRef name = reader.name();
parse_error(); if (name == QLatin1String("error"))
else if (reader.name() == QLatin1String("announcethread")) parseError();
parse_announcethread(); else if (name == QLatin1String("announcethread"))
else if (reader.name() == QLatin1String("status")) parseAnnounceThread();
parse_status(); else if (name == QLatin1String("status"))
else if (reader.name() == QLatin1String("errorcounts")) parseStatus();
parse_errorcounts(); else if (name == QLatin1String("errorcounts"))
else if (reader.name() == QLatin1String("suppcounts")) parseErrorCounts();
parse_suppcounts(); else if (name == QLatin1String("suppcounts"))
else if (reader.name() == QLatin1String("protocolversion")) parseSuppressionCounts();
else if (name == QLatin1String("protocolversion"))
checkProtocolVersion(blockingReadElementText()); checkProtocolVersion(blockingReadElementText());
else if (reader.name() == QLatin1String("protocoltool")) else if (name == QLatin1String("protocoltool"))
checkTool(blockingReadElementText()); checkTool(blockingReadElementText());
} }
} catch (const ParserException &e) { } catch (const ParserException &e) {

View File

@@ -39,8 +39,6 @@
#include <QtCore/QString> #include <QtCore/QString>
#include <QtCore/QVector> #include <QtCore/QVector>
#include <algorithm>
namespace Valgrind { namespace Valgrind {
namespace XmlProtocol { namespace XmlProtocol {
@@ -80,11 +78,10 @@ void Stack::swap(Stack &other)
qSwap(d, other.d); qSwap(d, other.d);
} }
Stack &Stack::operator=(const Stack &other) void Stack::operator=(const Stack &other)
{ {
Stack tmp(other); Stack tmp(other);
swap(tmp); swap(tmp);
return *this;
} }
bool Stack::operator==(const Stack &other) const bool Stack::operator==(const Stack &other) const

View File

@@ -32,8 +32,8 @@
** **
**************************************************************************/ **************************************************************************/
#ifndef LIBVALGRIND_PROTOCOL_STACK_H #ifndef VALGRIND_PROTOCOL_STACK_H
#define LIBVALGRIND_PROTOCOL_STACK_H #define VALGRIND_PROTOCOL_STACK_H
#include <QtCore/QSharedDataPointer> #include <QtCore/QSharedDataPointer>
@@ -52,7 +52,7 @@ public:
Stack(); Stack();
Stack(const Stack &other); Stack(const Stack &other);
~Stack(); ~Stack();
Stack &operator=(const Stack &other); void operator=(const Stack &other);
void swap(Stack &other); void swap(Stack &other);
bool operator==(const Stack &other) const; bool operator==(const Stack &other) const;
@@ -84,4 +84,4 @@ private:
} // namespace XmlProtocol } // namespace XmlProtocol
} // namespace Stack } // namespace Stack
#endif // LIBVALGRIND_PROTOCOL_STACK_H #endif // VALGRIND_PROTOCOL_STACK_H