Commit 29a93998 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by hjk

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: default avatarhjk <qthjk@ovi.com>
parent 73a2717b
......@@ -129,9 +129,8 @@ void Bind::setDeclSpecifiers(Symbol *symbol, const FullySpecifiedType &declSpeci
symbol->setStorage(storage);
if (Function *funTy = symbol->asFunction()) {
if (declSpecifiers.isVirtual()) {
if (declSpecifiers.isVirtual())
funTy->setVirtual(true);
}
}
if (declSpecifiers.isDeprecated())
......@@ -466,9 +465,8 @@ void Bind::enumerator(EnumeratorAST *ast, Enum *symbol)
EnumeratorDeclaration *e = control()->newEnumeratorDeclaration(ast->identifier_token, name);
e->setType(control()->integerType(IntegerType::Int)); // ### introduce IntegerType::Enumerator
if (ExpressionAST *expr = ast->expression) {
if (ExpressionAST *expr = ast->expression)
e->setConstantValue(asStringLiteral(expr->firstToken(), expr->lastToken()));
}
symbol->addMember(e);
}
......@@ -1845,9 +1843,8 @@ bool Bind::visit(SimpleDeclarationAST *ast)
const Name *declName = 0;
unsigned sourceLocation = location(it->value, ast->firstToken());
if (declaratorId && declaratorId->name) {
if (declaratorId && declaratorId->name)
declName = declaratorId->name->name;
}
Declaration *decl = control()->newDeclaration(sourceLocation, declName);
decl->setType(declTy);
......
......@@ -206,9 +206,8 @@ bool Identifier::isEqualTo(const Name *other) const
return true;
else if (other) {
if (const Identifier *nameId = other->asNameId()) {
if (const Identifier *nameId = other->asNameId())
return equalTo(nameId);
}
}
return false;
}
......@@ -898,9 +898,8 @@ bool Parser::parseConversionFunctionId(NameAST *&node)
return false;
unsigned operator_token = consumeToken();
SpecifierListAST *type_specifier = 0;
if (! parseTypeSpecifier(type_specifier)) {
if (! parseTypeSpecifier(type_specifier))
return false;
}
PtrOperatorListAST *ptr_operators = 0, **ptr_operators_tail = &ptr_operators;
while (parsePtrOperator(*ptr_operators_tail))
ptr_operators_tail = &(*ptr_operators_tail)->next;
......@@ -1550,9 +1549,8 @@ bool Parser::parseDeclarator(DeclaratorAST *&node, SpecifierListAST *decl_specif
for (SpecifierListAST *iter = decl_specifier_list; !hasAuto && iter; iter = iter->next) {
SpecifierAST *spec = iter->value;
if (SimpleSpecifierAST *simpleSpec = spec->asSimpleSpecifier()) {
if (_translationUnit->tokenKind(simpleSpec->specifier_token) == T_AUTO) {
if (_translationUnit->tokenKind(simpleSpec->specifier_token) == T_AUTO)
hasAuto = true;
}
}
}
......@@ -1567,9 +1565,8 @@ bool Parser::parseDeclarator(DeclaratorAST *&node, SpecifierListAST *decl_specif
} else if (LA() == T_LBRACKET) {
ArrayDeclaratorAST *ast = new (_pool) ArrayDeclaratorAST;
ast->lbracket_token = consumeToken();
if (LA() == T_RBRACKET || parseConstantExpression(ast->expression)) {
if (LA() == T_RBRACKET || parseConstantExpression(ast->expression))
match(T_RBRACKET, &ast->rbracket_token);
}
*postfix_ptr = new (_pool) PostfixDeclaratorListAST(ast);
postfix_ptr = &(*postfix_ptr)->next;
} else
......@@ -1715,9 +1712,8 @@ bool Parser::parseEnumSpecifier(SpecifierListAST *&node)
skipUntil(T_IDENTIFIER);
}
if (parseEnumerator(*enumerator_ptr)) {
if (parseEnumerator(*enumerator_ptr))
enumerator_ptr = &(*enumerator_ptr)->next;
}
if (LA() == T_COMMA && LA(2) == T_RBRACE)
ast->stray_comma_token = consumeToken();
......@@ -2182,11 +2178,10 @@ bool Parser::parseQtPropertyDeclaration(DeclarationAST *&node)
SimpleNameAST *property_name = new (_pool) SimpleNameAST;
// special case: keywords are allowed for property names!
if (tok().isKeyword()) {
if (tok().isKeyword())
property_name->identifier_token = consumeToken();
} else {
else
match(T_IDENTIFIER, &property_name->identifier_token);
}
ast->property_name = property_name;
QtPropertyDeclarationItemListAST **iter = &ast->property_declaration_item_list;
......@@ -3484,11 +3479,10 @@ bool Parser::parseForStatement(StatementAST *&node)
ast->colon_token = consumeToken();
blockErrors(blocked);
if (LA() == T_LBRACE) {
if (LA() == T_LBRACE)
parseBracedInitList0x(ast->expression);
} else {
else
parseExpression(ast->expression);
}
match(T_RPAREN, &ast->rparen_token);
parseStatement(ast->statement);
......@@ -5093,11 +5087,10 @@ bool Parser::parseNewArrayDeclarator(NewArrayDeclaratorListAST *&node)
bool Parser::parseNewInitializer(ExpressionAST *&node)
{
DEBUG_THIS_RULE();
if (LA() == T_LPAREN) {
if (LA() == T_LPAREN)
return parseExpressionListParen(node);
} else if (_cxx0xEnabled && LA() == T_LBRACE) {
else if (_cxx0xEnabled && LA() == T_LBRACE)
return parseBracedInitList0x(node);
}
return false;
}
......@@ -5787,9 +5780,8 @@ bool Parser::parseObjCMethodDefinition(DeclarationAST *&node)
// - (void) foo; { body; }
// so a method is a forward declaration when it doesn't have a _body_.
// However, we still need to read the semicolon.
if (LA() == T_SEMICOLON) {
if (LA() == T_SEMICOLON)
ast->semicolon_token = consumeToken();
}
parseFunctionBody(ast->function_body);
......
......@@ -499,9 +499,8 @@ Symbol *Clone::instantiate(Template *templ, const FullySpecifiedType *const args
if (argc < templ->templateParameterCount()) {
for (unsigned i = argc; i < templ->templateParameterCount(); ++i) {
Symbol *formal = templ->templateParameterAt(i);
if (TypenameArgument *tn = formal->asTypenameArgument()) {
if (TypenameArgument *tn = formal->asTypenameArgument())
subst.bind(name(formal->name(), &subst), type(tn->type(), &subst));
}
}
}
if (Symbol *inst = symbol(templ->declaration(), &subst)) {
......
......@@ -89,9 +89,8 @@ protected:
bool preVisit(Symbol *s)
{
if (s->asBlock()) {
if (s->line() < line || (s->line() == line && s->column() <= column)) {
if (s->line() < line || (s->line() == line && s->column() <= column))
return true;
}
// skip blocks
} if (s->line() < line || (s->line() == line && s->column() <= column)) {
symbol = s;
......@@ -594,13 +593,12 @@ void Document::check(CheckMode mode)
if (! _translationUnit->ast())
return; // nothing to do.
if (TranslationUnitAST *ast = _translationUnit->ast()->asTranslationUnit()) {
if (TranslationUnitAST *ast = _translationUnit->ast()->asTranslationUnit())
semantic(ast, _globalNamespace);
} else if (ExpressionAST *ast = _translationUnit->ast()->asExpression()) {
else if (ExpressionAST *ast = _translationUnit->ast()->asExpression())
semantic(ast, _globalNamespace);
} else if (DeclarationAST *ast = translationUnit()->ast()->asDeclaration()) {
else if (DeclarationAST *ast = translationUnit()->ast()->asDeclaration())
semantic(ast, _globalNamespace);
}
}
void Document::keepSourceAndAST()
......
......@@ -406,9 +406,8 @@ FullySpecifiedType UseMinimalNames::apply(const Name *name, Rewrite *rewrite) co
const QList<LookupItem> results = context.lookup(name, scope);
foreach (const LookupItem &r, results) {
if (Symbol *d = r.declaration()) {
if (Symbol *d = r.declaration())
return control->namedType(LookupContext::minimalName(d, _target, control));
}
return r.type();
}
......@@ -605,9 +604,8 @@ CPLUSPLUS_EXPORT QString simplifySTLType(const QString &typeIn)
QRegExp mapRE2(QString::fromLatin1("map<const %1, ?%2, ?std::less<const %3>, ?%4\\s*>")
.arg(keyEsc, valueEsc, keyEsc, allocEsc));
mapRE2.setMinimal(true);
if (mapRE2.indexIn(type) != -1) {
if (mapRE2.indexIn(type) != -1)
type.replace(mapRE2.cap(0), QString::fromLatin1("map<const %1, %2>").arg(key, value));
}
}
}
}
......
......@@ -83,18 +83,14 @@ QString CPlusPlus::toString(const Symbol *s, QString id)
QString CPlusPlus::toString(LookupItem it, QString id)
{
QString result = QString::fromLatin1("%1:").arg(id);
if (it.declaration()) {
if (it.declaration())
result.append(QString::fromLatin1("\n%1").arg(indent(toString(it.declaration(), QLatin1String("Decl")))));
}
if (it.type().isValid()) {
if (it.type().isValid())
result.append(QString::fromLatin1("\n%1").arg(indent(toString(it.type()))));
}
if (it.scope()) {
if (it.scope())
result.append(QString::fromLatin1("\n%1").arg(indent(toString(it.scope(), QLatin1String("Scope")))));
}
if (it.binding()) {
if (it.binding())
result.append(QString::fromLatin1("\n%1").arg(indent(toString(it.binding(), QLatin1String("Binding")))));
}
return result;
}
......@@ -106,9 +102,8 @@ QString CPlusPlus::toString(const ClassOrNamespace *binding, QString id)
QString result = QString::fromLatin1("%0: %1 symbols").arg(
id,
QString::number(binding->symbols().length()));
if (binding->templateId()) {
if (binding->templateId())
result.append(QString::fromLatin1("\n%1").arg(indent(toString(binding->templateId(), QLatin1String("Template")))));
}
return result;
}
......
......@@ -98,11 +98,10 @@ int ExpressionUnderCursor::startOfExpression_helper(BackwardsScanner &tk, int in
return index - 1;
} else if (tk[index - 1].is(T_IDENTIFIER)) {
if (tk[index - 2].is(T_TILDE)) {
if (tk[index - 3].is(T_COLON_COLON)) {
if (tk[index - 3].is(T_COLON_COLON))
return startOfExpression(tk, index - 3);
} else if (tk[index - 3].is(T_DOT) || tk[index - 3].is(T_ARROW)) {
else if (tk[index - 3].is(T_DOT) || tk[index - 3].is(T_ARROW))
return startOfExpression(tk, index - 3);
}
return index - 2;
} else if (tk[index - 2].is(T_COLON_COLON)) {
return startOfExpression(tk, index - 1);
......
......@@ -88,13 +88,12 @@ Icons::IconType Icons::iconTypeForSymbol(const Symbol *symbol)
function = symbol->type()->asFunctionType();
if (function->isSlot()) {
if (function->isPublic()) {
if (function->isPublic())
return SlotPublicIconType;
} else if (function->isProtected()) {
else if (function->isProtected())
return SlotProtectedIconType;
} else if (function->isPrivate()) {
else if (function->isPrivate())
return SlotPrivateIconType;
}
} else if (function->isSignal()) {
return SignalIconType;
} else if (symbol->isPublic()) {
......@@ -107,13 +106,12 @@ Icons::IconType Icons::iconTypeForSymbol(const Symbol *symbol)
} else if (symbol->enclosingScope() && symbol->enclosingScope()->isEnum()) {
return EnumeratorIconType;
} else if (symbol->isDeclaration() || symbol->isArgument()) {
if (symbol->isPublic()) {
if (symbol->isPublic())
return VarPublicIconType;
} else if (symbol->isProtected()) {
else if (symbol->isProtected())
return VarProtectedIconType;
} else if (symbol->isPrivate()) {
else if (symbol->isPrivate())
return VarPrivateIconType;
}
} else if (symbol->isEnum()) {
return EnumIconType;
} else if (symbol->isClass() || symbol->isForwardClassDeclaration()) {
......
......@@ -643,13 +643,11 @@ ClassOrNamespace *ClassOrNamespace::lookupType_helper(const Name *name,
if (const QualifiedNameId *q = name->asQualifiedNameId()) {
QSet<ClassOrNamespace *> innerProcessed;
if (! q->base()) {
if (! q->base())
return globalNamespace()->lookupType_helper(q->name(), &innerProcessed, true, origin);
}
if (ClassOrNamespace *binding = lookupType_helper(q->base(), processed, true, origin)) {
if (ClassOrNamespace *binding = lookupType_helper(q->base(), processed, true, origin))
return binding->lookupType_helper(q->name(), &innerProcessed, false, origin);
}
return 0;
......@@ -966,9 +964,8 @@ bool ClassOrNamespace::NestedClassInstantiator::containsTemplateType(Declaration
NamedType *memberNamedType = findMemberNamedType(memberType);
if (memberNamedType) {
const Name *name = memberNamedType->name();
if (_subst.contains(name)) {
if (_subst.contains(name))
return true;
}
}
return false;
}
......@@ -981,15 +978,12 @@ bool ClassOrNamespace::NestedClassInstantiator::containsTemplateType(Function *
NamedType *ClassOrNamespace::NestedClassInstantiator::findMemberNamedType(Type *memberType) const
{
if (NamedType *namedType = memberType->asNamedType()) {
if (NamedType *namedType = memberType->asNamedType())
return namedType;
}
else if (PointerType *pointerType = memberType->asPointerType()) {
else if (PointerType *pointerType = memberType->asPointerType())
return findMemberNamedType(pointerType->elementType().type());
}
else if (ReferenceType *referenceType = memberType->asReferenceType()) {
else if (ReferenceType *referenceType = memberType->asReferenceType())
return findMemberNamedType(referenceType->elementType().type());
}
return 0;
}
......
......@@ -123,9 +123,8 @@ int OverviewModel::rowCount(const QModelIndex &parent) const
parentSymbol = templateParentSymbol;
if (Scope *parentScope = parentSymbol->asScope()) {
if (!parentScope->isFunction() && !parentScope->isObjCMethod()) {
if (!parentScope->isFunction() && !parentScope->isObjCMethod())
return parentScope->memberCount();
}
}
return 0;
}
......
......@@ -357,9 +357,8 @@ void ResolveExpression::thisObject()
bool ResolveExpression::visit(CompoundExpressionAST *ast)
{
CompoundStatementAST *cStmt = ast->statement;
if (cStmt && cStmt->statement_list) {
if (cStmt && cStmt->statement_list)
accept(cStmt->statement_list->lastValue());
}
return false;
}
......
......@@ -368,9 +368,8 @@ protected:
env, client)
!= 0);
++(*_lex);
if ((*_lex)->is(T_RPAREN)) {
if ((*_lex)->is(T_RPAREN))
++(*_lex);
}
}
}
} else if ((*_lex)->is(T_IDENTIFIER)) {
......@@ -1539,9 +1538,8 @@ void Preprocessor::handleDefineDirective(PPToken *tk)
}
}
} else if (macroReference) {
if (tk->is(T_LPAREN)) {
if (tk->is(T_LPAREN))
m_client->notifyMacroReference(previousOffset, previousLine, *macroReference);
}
macroReference = 0;
}
......
......@@ -174,9 +174,8 @@ bool OptionsParser::checkForPluginOption()
if (!spec)
return false;
spec->addArgument(m_currentArg);
if (requiresParameter && nextToken(RequiredToken)) {
if (requiresParameter && nextToken(RequiredToken))
spec->addArgument(m_currentArg);
}
return true;
}
......
......@@ -335,9 +335,8 @@ bool PluginManager::hasError()
{
foreach (PluginSpec *spec, plugins()) {
// only show errors on startup if plugin is enabled.
if (spec->hasError() && spec->isEnabled() && !spec->isDisabledIndirectly()) {
if (spec->hasError() && spec->isEnabled() && !spec->isDisabledIndirectly())
return true;
}
}
return false;
}
......@@ -505,11 +504,10 @@ QString PluginManager::serializedArguments()
foreach (const QString &argument, m_instance->d->arguments) {
rc += separator;
const QFileInfo fi(argument);
if (fi.exists() && fi.isRelative()) {
if (fi.exists() && fi.isRelative())
rc += fi.absoluteFilePath();
} else {
else
rc += argument;
}
}
}
return rc;
......@@ -857,9 +855,8 @@ void PluginManagerPrivate::writeSettings()
*/
void PluginManagerPrivate::readSettings()
{
if (globalSettings) {
if (globalSettings)
defaultDisabledPlugins = globalSettings->value(QLatin1String(C_IGNORED_PLUGINS)).toStringList();
}
if (settings) {
disabledPlugins = settings->value(QLatin1String(C_IGNORED_PLUGINS)).toStringList();
forceEnabledPlugins = settings->value(QLatin1String(C_FORCEENABLED_PLUGINS)).toStringList();
......@@ -996,9 +993,8 @@ void PluginManagerPrivate::shutdown()
shutdownEventLoop->exec();
}
deleteAll();
if (!allObjects.isEmpty()) {
if (!allObjects.isEmpty())
qDebug() << "There are" << allObjects.size() << "objects left in the plugin manager pool: " << allObjects;
}
}
/*!
......@@ -1270,11 +1266,10 @@ void PluginManagerPrivate::profilingReport(const char *what, const PluginSpec *s
const int absoluteElapsedMS = m_profileTimer->elapsed();
const int elapsedMS = absoluteElapsedMS - m_profileElapsedMS;
m_profileElapsedMS = absoluteElapsedMS;
if (spec) {
if (spec)
qDebug("%-22s %-22s %8dms (%8dms)", what, qPrintable(spec->name()), absoluteElapsedMS, elapsedMS);
} else {
else
qDebug("%-45s %8dms (%8dms)", what, absoluteElapsedMS, elapsedMS);