def fix_switch_cases(switch_node):
 assert isinstance(switch_node, c_ast.Switch)
 if (not isinstance(switch_node.stmt, c_ast.Compound)):
  return switch_node
 new_compound = c_ast.Compound([], switch_node.stmt.coord)
 last_case = None
 for child in switch_node.stmt.block_items:
  if isinstance(child, (c_ast.Case, c_ast.Default)):
   new_compound.block_items.append(child)
   _extract_nested_case(child, new_compound.block_items)
   last_case = new_compound.block_items[(-1)]
  elif (last_case is None):
   new_compound.block_items.append(child)
  else:
   last_case.stmts.append(child)
 switch_node.stmt = new_compound
 return switch_node

def fix_switch_cases ( switch_node ) : assert isinstance ( switch_node , c_ast . Switch ) if ( not isinstance ( switch_node . stmt , c_ast . Compound ) ) : return switch_node new_compound = c_ast . Compound ( [ ] , switch_node . stmt . coord ) last_case = None for child in switch_node . stmt . block_items : if isinstance ( child , ( c_ast . Case , c_ast . Default ) ) : new_compound . block_items . append ( child ) _extract_nested_case ( child , new_compound . block_items ) last_case = new_compound . block_items [ ( - 1 ) ] elif ( last_case is None ) : new_compound . block_items . append ( child ) else : last_case . stmts . append ( child ) switch_node . stmt = new_compound return switch_node
the case statements in a switch come out of parsing with one child node .