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

@@ -251,11 +251,10 @@ void BaseSymbolGroupNode::addChild(AbstractSymbolGroupNode *c)
std::ostream &operator<<(std::ostream &str, const DEBUG_SYMBOL_PARAMETERS &parameters)
{
str << "parent=";
if (parameters.ParentSymbol == DEBUG_ANY_ID) {
if (parameters.ParentSymbol == DEBUG_ANY_ID)
str << "DEBUG_ANY_ID";
} else {
else
str << parameters.ParentSymbol ;
}
if (parameters.Flags != 0 && parameters.Flags != 1)
str << " flags=" << parameters.Flags;
// Detailed flags:
@@ -669,17 +668,15 @@ bool SymbolGroupNode::notifyIndexesMoved(ULONG index, bool inserted, ULONG offse
if (m_index == DEBUG_ANY_ID || m_index < index)
return false;
if (inserted) {
if (inserted)
m_index += offset;
} else {
else
m_index -= offset;
}
if (m_parameters.ParentSymbol != DEBUG_ANY_ID && m_parameters.ParentSymbol >= index) {
if (inserted) {
if (inserted)
m_parameters.ParentSymbol += offset;
} else {
else
m_parameters.ParentSymbol -= offset;
}
}
return true;
}
@@ -732,9 +729,8 @@ static inline void fixNames(bool isTopLevel, StringVector *names, StringVector *
* 3) For toplevels: Fix shadowed variables in the order the debugger expects them:
\code
int x; // Occurrence (1), should be reported as name="x <shadowed 1>"/iname="x#1"
if (true) {
if (true)
int x = 5; (2) // Occurrence (2), should be reported as name="x"/iname="x"
}
\endcode */
StringVector::iterator nameIt = names->begin();
const StringVector::iterator namesEnd = names->end();
@@ -1103,11 +1099,10 @@ int SymbolGroupNode::dumpNode(std::ostream &str,
// Emulate gdb's behaviour of returning the referenced address
// for pointers.
str << std::hex << std::showbase;
if (referencedAddr) {
if (referencedAddr)
str << ",addr=\"" << referencedAddr << "\",origaddr=\"" << addr << '"';
} else {
else
str << ",addr=\"" << addr << '"';
}
str << std::noshowbase << std::dec;
}
const ULONG s = size();
@@ -1141,11 +1136,10 @@ int SymbolGroupNode::dumpNode(std::ostream &str,
if (m_dumperContainerSize > 0) {
childCountGuess = m_dumperContainerSize; // See Obscured handling
} else {
if (children().empty()) {
if (children().empty())
childCountGuess = m_parameters.SubElements; // Guess
} else {
else
childCountGuess = unsigned(children().size());
}
}
}
// No children..suppose we are editable and enabled.
@@ -1646,11 +1640,10 @@ SymbolGroupNodeVisitor::VisitResult
if (!realNode->isExpanded() || realNode->testFlags(SymbolGroupNode::Uninitialized|SymbolGroupNode::ExpandedByDumper))
visitChildren = false;
// Comma between same level children given obscured children
if (depth == m_lastDepth) {
if (depth == m_lastDepth)
m_os << ',';
} else {
else
m_lastDepth = depth;
}
if (m_parameters.humanReadable()) {
m_os << '\n';
indentStream(m_os, depth * 2);