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:
9
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
9
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
@@ -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);
|
||||
|
||||
3
src/libs/3rdparty/cplusplus/Literals.cpp
vendored
3
src/libs/3rdparty/cplusplus/Literals.cpp
vendored
@@ -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;
|
||||
}
|
||||
|
||||
30
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
30
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
@@ -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);
|
||||
|
||||
|
||||
3
src/libs/3rdparty/cplusplus/Templates.cpp
vendored
3
src/libs/3rdparty/cplusplus/Templates.cpp
vendored
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user