Remove braces for single lines of conditions

#!/usr/bin/env ruby

Dir.glob('**/*.cpp') { |file|
  # skip ast (excluding paste, astpath, and canv'ast'imer)
  next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
  s = File.read(file)
  next if s.include?('qlalr')
  orig = s.dup
  s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
    res = $&
    if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
      res
    else
      res.gsub!('} else', 'else')
      res.gsub!(/\n +} *\n/m, "\n")
      res.gsub(/ *{$/, '')
    end
  }
  s.gsub!(/ *$/, '')
  File.open(file, 'wb').write(s) if s != orig
}

Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
Orgad Shaneh
2013-01-08 03:32:53 +02:00
committed by hjk
parent 73a2717bed
commit 29a93998df
396 changed files with 1856 additions and 3135 deletions

View File

@@ -127,9 +127,8 @@ void Canvas::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget
painter->setWorldTransform(scale * old);
painter->drawPixmap(0, 0, m_context->pixmap());
painter->setWorldTransform(old);
if (clip()) {
if (clip())
painter->restore();
}
}
} else {
painter->drawPixmap(0, 0, m_context->pixmap());

View File

@@ -46,9 +46,8 @@ void CanvasTimer::handleTimeout()
{
Q_ASSERT(m_value.isFunction());
m_value.call();
if (isSingleShot()) {
if (isSingleShot())
removeTimer(this);
}
}
void CanvasTimer::createTimer(QObject *parent, const QScriptValue &val, long timeout, bool singleshot)

View File

@@ -99,9 +99,8 @@ QColor colorFromString(const QString &name)
if (name.startsWith(QLatin1String("rgba("))) {
++itr; ++itr; ++itr; ++itr; ++itr;
compo = parseNumbersList(itr);
if (compo.size() != 4) {
if (compo.size() != 4)
return QColor();
}
//alpha seems to be always between 0-1
compo[3] *= 255;
return QColor((int)compo[0], (int)compo[1],
@@ -109,26 +108,23 @@ QColor colorFromString(const QString &name)
} else if (name.startsWith(QLatin1String("rgb("))) {
++itr; ++itr; ++itr; ++itr;
compo = parseNumbersList(itr);
if (compo.size() != 3) {
if (compo.size() != 3)
return QColor();
}
return QColor((int)qClamp(compo[0], qreal(0), qreal(255)),
(int)qClamp(compo[1], qreal(0), qreal(255)),
(int)qClamp(compo[2], qreal(0), qreal(255)));
} else if (name.startsWith(QLatin1String("hsla("))) {
++itr; ++itr; ++itr; ++itr; ++itr;
compo = parseNumbersList(itr);
if (compo.size() != 4) {
if (compo.size() != 4)
return QColor();
}
return QColor::fromHslF(compo[0], compo[1],
compo[2], compo[3]);
} else if (name.startsWith(QLatin1String("hsl("))) {
++itr; ++itr; ++itr; ++itr; ++itr;
compo = parseNumbersList(itr);
if (compo.size() != 3) {
if (compo.size() != 3)
return QColor();
}
return QColor::fromHslF(compo[0], compo[1],
compo[2]);
} else {
@@ -141,31 +137,30 @@ QColor colorFromString(const QString &name)
static QPainter::CompositionMode compositeOperatorFromString(const QString &compositeOperator)
{
if (compositeOperator == QLatin1String("source-over")) {
if (compositeOperator == QLatin1String("source-over"))
return QPainter::CompositionMode_SourceOver;
} else if (compositeOperator == QLatin1String("source-out")) {
else if (compositeOperator == QLatin1String("source-out"))
return QPainter::CompositionMode_SourceOut;
} else if (compositeOperator == QLatin1String("source-in")) {
else if (compositeOperator == QLatin1String("source-in"))
return QPainter::CompositionMode_SourceIn;
} else if (compositeOperator == QLatin1String("source-atop")) {
else if (compositeOperator == QLatin1String("source-atop"))
return QPainter::CompositionMode_SourceAtop;
} else if (compositeOperator == QLatin1String("destination-atop")) {
else if (compositeOperator == QLatin1String("destination-atop"))
return QPainter::CompositionMode_DestinationAtop;
} else if (compositeOperator == QLatin1String("destination-in")) {
else if (compositeOperator == QLatin1String("destination-in"))
return QPainter::CompositionMode_DestinationIn;
} else if (compositeOperator == QLatin1String("destination-out")) {
else if (compositeOperator == QLatin1String("destination-out"))
return QPainter::CompositionMode_DestinationOut;
} else if (compositeOperator == QLatin1String("destination-over")) {
else if (compositeOperator == QLatin1String("destination-over"))
return QPainter::CompositionMode_DestinationOver;
} else if (compositeOperator == QLatin1String("darker")) {
else if (compositeOperator == QLatin1String("darker"))
return QPainter::CompositionMode_SourceOver;
} else if (compositeOperator == QLatin1String("lighter")) {
else if (compositeOperator == QLatin1String("lighter"))
return QPainter::CompositionMode_SourceOver;
} else if (compositeOperator == QLatin1String("copy")) {
else if (compositeOperator == QLatin1String("copy"))
return QPainter::CompositionMode_Source;
} else if (compositeOperator == QLatin1String("xor")) {
else if (compositeOperator == QLatin1String("xor"))
return QPainter::CompositionMode_Xor;
}
return QPainter::CompositionMode_SourceOver;
}
@@ -833,11 +828,10 @@ void Context2D::arc(qreal xc, qreal yc, qreal radius,
double width = radius*2;
double height = radius*2;
if (!anticlockwise && (ea < sa)) {
if (!anticlockwise && (ea < sa))
span += 360;
} else if (anticlockwise && (sa < ea)) {
else if (anticlockwise && (sa < ea))
span -= 360;
}
//### this is also due to switched coordinate system
// we would end up with a 0 span instead of 360

View File

@@ -76,9 +76,8 @@ void LocalQmlProfilerRunner::stop()
if (QmlProfilerPlugin::debugOutput)
qWarning("QmlProfiler: Stopping application ...");
if (m_launcher.isRunning()) {
if (m_launcher.isRunning())
m_launcher.stop();
}
}
quint16 LocalQmlProfilerRunner::debugPort() const

View File

@@ -326,11 +326,10 @@ void QmlProfilerClientManager::retryMessageBoxFinished(int result)
// fall through
}
default: {
if (d->connection) {
if (d->connection)
QmlProfilerTool::logStatus(QLatin1String("QML Profiler: Failed to connect! ") + d->connection->errorString());
} else {
else
QmlProfilerTool::logStatus(QLatin1String("QML Profiler: Failed to connect!"));
}
emit connectionFailed();
break;
@@ -399,9 +398,8 @@ void QmlProfilerClientManager::profilerStateChanged()
QTC_ASSERT(d->profilerState, return);
switch (d->profilerState->currentState()) {
case QmlProfilerStateManager::AppStopRequested :
if (d->profilerState->serverRecording()) {
if (d->profilerState->serverRecording())
stopClientsRecording();
}
else
d->profilerState->setCurrentState(QmlProfilerStateManager::AppReadyToStop);
break;

View File

@@ -312,9 +312,8 @@ void QmlProfilerDataModel::addRangedEvent(int type, int bindingType, qint64 star
details = data.join(QLatin1String(" ")).replace(QLatin1Char('\n'),QLatin1Char(' ')).simplified();
QRegExp rewrite(QLatin1String("\\(function \\$(\\w+)\\(\\) \\{ (return |)(.+) \\}\\)"));
bool match = rewrite.exactMatch(details);
if (match) {
if (match)
details = rewrite.cap(1) + QLatin1String(": ") + rewrite.cap(3);
}
if (details.startsWith(QLatin1String("file://")))
details = details.mid(details.lastIndexOf(QLatin1Char('/')) + 1);
}
@@ -510,11 +509,10 @@ QmlEventType QmlProfilerDataModel::qmlEventTypeAsEnum(const QString &typeString)
} else {
bool isNumber = false;
int type = typeString.toUInt(&isNumber);
if (isNumber) {
if (isNumber)
return (QmlEventType)type;
} else {
else
return MaximumQmlEventType;
}
}
}
@@ -843,9 +841,8 @@ void QmlProfilerDataModel::QmlProfilerDataModelPrivate::prepareForDisplay()
typeCounts[typeNumber] = new QmlRangeEventTypeCount;
typeCounts[typeNumber]->nestingCount = 0;
}
if (eventStartData.nestingLevel > typeCounts[typeNumber]->nestingCount) {
if (eventStartData.nestingLevel > typeCounts[typeNumber]->nestingCount)
typeCounts[typeNumber]->nestingCount = eventStartData.nestingLevel;
}
if (!typeCounts[typeNumber]->eventIds.contains(eventStartData.statsInfo->eventId))
typeCounts[typeNumber]->eventIds << eventStartData.statsInfo->eventId;
}
@@ -1133,9 +1130,8 @@ void QmlProfilerDataModel::QmlProfilerDataModelPrivate::redoTree(qint64 fromTime
int level = startInstanceList[index].level;
QmlRangeEventData *parentEvent = listedRootEvent;
if (level > Constants::QML_MIN_LEVEL && lastParent.contains(level-1)) {
if (level > Constants::QML_MIN_LEVEL && lastParent.contains(level-1))
parentEvent = lastParent[level-1];
}
if (!eventDescription->parentHash.contains(parentEvent->eventHashStr)) {
QmlRangeEventRelative *newParentEvent = new QmlRangeEventRelative(parentEvent);
@@ -1165,9 +1161,8 @@ void QmlProfilerDataModel::QmlProfilerDataModelPrivate::redoTree(qint64 fromTime
lastParent[level] = eventDescription;
if (level == Constants::QML_MIN_LEVEL) {
if (level == Constants::QML_MIN_LEVEL)
totalTime += duration;
}
}
// fake rootEvent statistics
@@ -1564,9 +1559,8 @@ void QmlProfilerDataModel::load()
currentEvent->location.line = readData.toInt();
break;
}
if (elementName == QLatin1String("column")) {
if (elementName == QLatin1String("column"))
currentEvent->location.column = readData.toInt();
}
if (elementName == QLatin1String("details")) {
currentEvent->details = readData;
break;

View File

@@ -77,9 +77,8 @@ protected:
virtual bool preVisit(QmlJS::AST::Node *node)
{
if (QmlJS::AST::cast<QmlJS::AST::UiQualifiedId *>(node)) {
if (QmlJS::AST::cast<QmlJS::AST::UiQualifiedId *>(node))
return false;
}
return containsLocation(node->firstSourceLocation(), node->lastSourceLocation());
}

View File

@@ -341,16 +341,14 @@ void QmlProfilerEngine::processIsRunning(quint16 port)
void QmlProfilerEngine::registerProfilerStateManager( QmlProfilerStateManager *profilerState )
{
// disconnect old
if (d->m_profilerState) {
if (d->m_profilerState)
disconnect(d->m_profilerState, SIGNAL(stateChanged()), this, SLOT(profilerStateChanged()));
}
d->m_profilerState = profilerState;
// connect
if (d->m_profilerState) {
if (d->m_profilerState)
connect(d->m_profilerState, SIGNAL(stateChanged()), this, SLOT(profilerStateChanged()));
}
}
void QmlProfilerEngine::profilerStateChanged()

View File

@@ -171,9 +171,8 @@ void QmlProfilerEventsWidget::profilerDataModelStateChanged()
{
if (d->m_profilerDataModel) {
QmlProfilerDataModel::State newState = d->m_profilerDataModel->currentState();
if (newState == QmlProfilerDataModel::Empty) {
if (newState == QmlProfilerDataModel::Empty)
clear();
}
}
}
@@ -601,9 +600,8 @@ void QmlProfilerEventsMainView::QmlProfilerEventsMainViewPrivate::buildModelFrom
continue;
QList<QStandardItem *> newRow;
if (m_fieldShown[Name]) {
if (m_fieldShown[Name])
newRow << new EventsViewItem(binding->displayName);
}
if (m_fieldShown[Type]) {
QString typeString = QmlProfilerEventsMainView::nameForType(binding->eventType);
@@ -695,9 +693,8 @@ void QmlProfilerEventsMainView::QmlProfilerEventsMainViewPrivate::buildV8ModelFr
QV8EventData *v8event = list.at(index);
QList<QStandardItem *> newRow;
if (m_fieldShown[Name]) {
if (m_fieldShown[Name])
newRow << new EventsViewItem(v8event->displayName);
}
if (m_fieldShown[Percent]) {
newRow << new EventsViewItem(QString::number(v8event->totalPercent,'f',2)+QLatin1String(" %"));
@@ -813,9 +810,8 @@ void QmlProfilerEventsMainView::jumpToItem(const QModelIndex &index)
emit eventSelected(infoItem->data(EventIdRole).toInt());
// show in timelinerenderer
if (d->m_viewType == EventsView) {
if (d->m_viewType == EventsView)
emit showEventInTimeline(infoItem->data(EventIdRole).toInt());
}
d->m_preventSelectBounce = false;
}

View File

@@ -250,9 +250,8 @@ IAnalyzerEngine *QmlProfilerTool::createEngine(const AnalyzerStartParameters &sp
}
// FIXME: Check that there's something sensible in sp.connParams
if (isTcpConnection) {
if (isTcpConnection)
d->m_profilerConnections->setTcpConnection(sp.connParams.host, sp.connParams.port);
}
d->m_runConfiguration = runConfiguration;
@@ -404,9 +403,8 @@ void QmlProfilerTool::populateFileFinder(QString projectDirectory, QString activ
sourceFiles << project->files(Project::ExcludeGeneratedFiles);
if (!projects.isEmpty()) {
if (projectDirectory.isEmpty()) {
if (projectDirectory.isEmpty())
projectDirectory = projects.first()->projectDirectory();
}
if (activeSysroot.isEmpty()) {
if (Target *target = projects.first()->activeTarget())
@@ -711,9 +709,8 @@ void QmlProfilerTool::clientRecordingChanged()
{
// if application is running, display server record changes
// if application is stopped, display client record changes
if (d->m_profilerState->currentState() != QmlProfilerStateManager::AppRunning) {
if (d->m_profilerState->currentState() != QmlProfilerStateManager::AppRunning)
setRecording(d->m_profilerState->clientRecording());
}
}
void QmlProfilerTool::serverRecordingChanged()

View File

@@ -193,9 +193,8 @@ void QV8ProfilerDataModel::addV8Event(int depth,
parentEvent = &d->v8RootEvent;
d->v8MeasuredTime += totalTime;
}
if (depth > 0 && d->v8parents.contains(depth-1)) {
if (depth > 0 && d->v8parents.contains(depth-1))
parentEvent = d->v8parents.value(depth-1);
}
if (parentEvent != 0) {
if (!eventData->parentHash.contains(parentEvent->eventHashStr)) {
@@ -385,9 +384,8 @@ void QV8ProfilerDataModel::load(QXmlStreamReader &stream)
childrenTimes[eventIndex] =
attributes.value(QLatin1String("childrenTimes")).toString();
}
if (attributes.hasAttribute(QLatin1String("parentTimes"))) {
if (attributes.hasAttribute(QLatin1String("parentTimes")))
parentTimes[eventIndex] = attributes.value(QLatin1String("parentTimes")).toString();
}
}
stream.readNext();
@@ -451,12 +449,10 @@ void QV8ProfilerDataModel::load(QXmlStreamReader &stream)
if (v8eventBuffer.value(childIndex)) {
QV8EventSub *newChild = new QV8EventSub(v8eventBuffer[childIndex]);
QV8EventSub *newParent = new QV8EventSub(v8eventBuffer[parentIndex]);
if (childrenTimesStrings.count() > ndx) {
if (childrenTimesStrings.count() > ndx)
newChild->totalTime = childrenTimesStrings[ndx].toDouble();
}
if (parentTimesStrings.count() > ndx) {
if (parentTimesStrings.count() > ndx)
newParent->totalTime = parentTimesStrings[ndx].toDouble();
}
v8eventBuffer[parentIndex]->childrenHash.insert(
newChild->reference->displayName,
newChild);