forked from qt-creator/qt-creator
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:
@@ -188,9 +188,8 @@ QVariant CallModel::data(const QModelIndex &index, int role) const
|
||||
return parentCost;
|
||||
}
|
||||
|
||||
if (role == FunctionCallRole) {
|
||||
if (role == FunctionCallRole)
|
||||
return QVariant::fromValue(call);
|
||||
}
|
||||
|
||||
if (role == RelativeTotalCostRole) {
|
||||
const quint64 totalCost = d->m_data->totalCost(d->m_event);
|
||||
|
||||
@@ -312,9 +312,8 @@ QVariant DataModel::data(const QModelIndex &index, int role) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (role == FunctionRole) {
|
||||
if (role == FunctionRole)
|
||||
return QVariant::fromValue(func);
|
||||
}
|
||||
|
||||
if (role == ParentCostRole) {
|
||||
const quint64 totalCost = d->m_data->totalCost(d->m_event);
|
||||
@@ -326,18 +325,15 @@ QVariant DataModel::data(const QModelIndex &index, int role) const
|
||||
const quint64 totalCost = d->m_data->totalCost(d->m_event);
|
||||
if (index.column() == SelfCostColumn)
|
||||
return double(func->selfCost(d->m_event)) / totalCost;
|
||||
if (index.column() == InclusiveCostColumn) {
|
||||
if (index.column() == InclusiveCostColumn)
|
||||
return double(func->inclusiveCost(d->m_event)) / totalCost;
|
||||
}
|
||||
}
|
||||
|
||||
if (role == LineNumberRole) {
|
||||
if (role == LineNumberRole)
|
||||
return func->lineNumber();
|
||||
}
|
||||
|
||||
if (role == FileNameRole) {
|
||||
if (role == FileNameRole)
|
||||
return func->file();
|
||||
}
|
||||
|
||||
if (role == Qt::TextAlignmentRole) {
|
||||
if (index.column() == CalledColumn)
|
||||
|
||||
@@ -201,9 +201,8 @@ QString Function::location() const
|
||||
|
||||
if (!f.isEmpty()) {
|
||||
QFileInfo info(f);
|
||||
if (info.exists()) {
|
||||
if (info.exists())
|
||||
f = info.canonicalFilePath();
|
||||
}
|
||||
}
|
||||
|
||||
QString o = object();
|
||||
@@ -287,11 +286,10 @@ void Function::addCostItem(const CostItem *item)
|
||||
d->m_costItems.append(item);
|
||||
|
||||
// accumulate costs
|
||||
if (item->call()) {
|
||||
if (item->call())
|
||||
d->accumulateCost(d->m_inclusiveCost, item->costs());
|
||||
} else {
|
||||
else
|
||||
d->accumulateCost(d->m_selfCost, item->costs());
|
||||
}
|
||||
}
|
||||
|
||||
void Function::finalize()
|
||||
|
||||
@@ -137,9 +137,8 @@ void ParseData::Private::addCompressedString(NameLookupTable &lookup, const QStr
|
||||
|
||||
void ParseData::Private::cycleDetection()
|
||||
{
|
||||
if (m_cycleCacheValid) {
|
||||
if (m_cycleCacheValid)
|
||||
return;
|
||||
}
|
||||
cleanupFunctionCycles();
|
||||
Internal::CycleDetection algorithm(m_q);
|
||||
m_cycleCache = algorithm.run(m_functions);
|
||||
|
||||
@@ -537,9 +537,8 @@ void Parser::Private::parseCostItem(const char *begin, const char *end)
|
||||
skipSpace(¤t, end);
|
||||
}
|
||||
|
||||
if (call) {
|
||||
if (call)
|
||||
call->setCosts(costItem->costs());
|
||||
}
|
||||
|
||||
currentFunction->addCostItem(costItem);
|
||||
}
|
||||
|
||||
@@ -116,9 +116,8 @@ bool DataProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_
|
||||
return false;
|
||||
|
||||
// if the filter regexp is a non-empty string, ignore our filters
|
||||
if (!filterRegExp().isEmpty()) {
|
||||
if (!filterRegExp().isEmpty())
|
||||
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
|
||||
}
|
||||
|
||||
// check max rows
|
||||
if (m_maxRows > 0 && source_row > m_maxRows)
|
||||
@@ -141,9 +140,8 @@ bool DataProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isValid) {
|
||||
if (!isValid)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// check minimum inclusive costs
|
||||
|
||||
@@ -256,9 +256,8 @@ void Visualisation::Private::handleMousePressEvent(QMouseEvent *event,
|
||||
if (itemAtPos) {
|
||||
const Function *func = q->functionForItem(itemAtPos);
|
||||
|
||||
if (doubleClicked) {
|
||||
if (doubleClicked)
|
||||
q->functionActivated(func);
|
||||
}
|
||||
else {
|
||||
q->scene()->clearSelection();
|
||||
itemAtPos->setSelected(true);
|
||||
|
||||
@@ -414,9 +414,8 @@ void MemcheckErrorDelegate::copy()
|
||||
const QString relativeTo = relativeToPath();
|
||||
|
||||
foreach (const Stack &stack, error.stacks()) {
|
||||
if (!stack.auxWhat().isEmpty()) {
|
||||
if (!stack.auxWhat().isEmpty())
|
||||
stream << stack.auxWhat();
|
||||
}
|
||||
int i = 1;
|
||||
foreach (const Frame &frame, stack.frames()) {
|
||||
stream << " " << i++ << ": " << makeFrameName(frame, relativeTo) << "\n";
|
||||
|
||||
@@ -231,9 +231,8 @@ void MemcheckTool::maybeActiveRunConfigurationChanged()
|
||||
ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
|
||||
if (ProjectExplorer::Project *project = pe->startupProject()) {
|
||||
if (ProjectExplorer::Target *target = project->activeTarget()) {
|
||||
if (ProjectExplorer::RunConfiguration *rc = target->activeRunConfiguration()) {
|
||||
if (ProjectExplorer::RunConfiguration *rc = target->activeRunConfiguration())
|
||||
settings = rc->extraAspect<AnalyzerRunConfigurationAspect>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -171,11 +171,10 @@ void ValgrindEngine::receiveProcessError(const QString &error, QProcess::Process
|
||||
{
|
||||
if (e == QProcess::FailedToStart) {
|
||||
const QString &valgrind = m_settings->subConfig<ValgrindBaseSettings>()->valgrindExecutable();
|
||||
if (!valgrind.isEmpty()) {
|
||||
if (!valgrind.isEmpty())
|
||||
emit outputReceived(tr("** Error: \"%1\" could not be started: %2 **\n").arg(valgrind).arg(error), Utils::ErrorMessageFormat);
|
||||
} else {
|
||||
else
|
||||
emit outputReceived(tr("** Error: no valgrind executable set **\n"), Utils::ErrorMessageFormat);
|
||||
}
|
||||
} else if (m_isStopping && e == QProcess::Crashed) { // process gets killed on stop
|
||||
emit outputReceived(tr("** Process Terminated **\n"), Utils::ErrorMessageFormat);
|
||||
} else {
|
||||
|
||||
@@ -224,29 +224,23 @@ QString Error::toXml() const
|
||||
}
|
||||
|
||||
foreach (const Stack &stack, d->stacks) {
|
||||
if (!stack.auxWhat().isEmpty()) {
|
||||
if (!stack.auxWhat().isEmpty())
|
||||
stream << " <auxwhat>" << stack.auxWhat() << "</auxwhat>\n";
|
||||
}
|
||||
stream << " <stack>\n";
|
||||
|
||||
foreach (const Frame &frame, stack.frames()) {
|
||||
stream << " <frame>\n";
|
||||
stream << " <ip>0x" << QString::number(frame.instructionPointer(), 16) << "</ip>\n";
|
||||
if (!frame.object().isEmpty()) {
|
||||
if (!frame.object().isEmpty())
|
||||
stream << " <obj>" << frame.object() << "</obj>\n";
|
||||
}
|
||||
if (!frame.functionName().isEmpty()) {
|
||||
if (!frame.functionName().isEmpty())
|
||||
stream << " <fn>" << frame.functionName() << "</fn>\n";
|
||||
}
|
||||
if (!frame.directory().isEmpty()) {
|
||||
if (!frame.directory().isEmpty())
|
||||
stream << " <dir>" << frame.directory() << "</dir>\n";
|
||||
}
|
||||
if (!frame.file().isEmpty()) {
|
||||
if (!frame.file().isEmpty())
|
||||
stream << " <file>" << frame.file() << "</file>\n";
|
||||
}
|
||||
if (frame.line() != -1) {
|
||||
if (frame.line() != -1)
|
||||
stream << " <line>" << frame.line() << "</line>";
|
||||
}
|
||||
stream << " </frame>\n";
|
||||
}
|
||||
|
||||
|
||||
@@ -221,9 +221,8 @@ QXmlStreamReader::TokenType Parser::Private::blockingReadNext()
|
||||
QIODevice *dev = reader.device();
|
||||
QAbstractSocket *sock = qobject_cast<QAbstractSocket *>(dev);
|
||||
|
||||
if (!sock || sock->state() != QAbstractSocket::ConnectedState) {
|
||||
if (!sock || sock->state() != QAbstractSocket::ConnectedState)
|
||||
throw ParserException(dev->errorString());
|
||||
}
|
||||
}
|
||||
} else if (reader.hasError()) {
|
||||
throw ParserException(reader.errorString()); //TODO add line, column?
|
||||
|
||||
@@ -105,11 +105,10 @@ void SuppressionFrame::setObject(const QString &obj)
|
||||
|
||||
QString SuppressionFrame::toString() const
|
||||
{
|
||||
if (!d->fun.isEmpty()) {
|
||||
if (!d->fun.isEmpty())
|
||||
return QLatin1String("fun:") + d->fun;
|
||||
} else {
|
||||
else
|
||||
return QLatin1String("obj:") + d->obj;
|
||||
}
|
||||
}
|
||||
|
||||
class Suppression::Private : public QSharedData
|
||||
|
||||
Reference in New Issue
Block a user