def visit_children(parent_node): this_level_items = [] for node in get_children_from_same_file(parent_node): item = None if node.kind == cindex.CursorKind.LABEL_STMT: item = Label(node) self._labels.append(item) elif node.kind == cindex.CursorKind.BINARY_OPERATOR: op = Expression._from_clang_node(node) if op.is_assign_op(): self._assignments.append(op) elif node.kind == cindex.CursorKind.COMPOUND_ASSIGNMENT_OPERATOR: op = Expression._from_clang_node(node) self._assignments.append(op) else: item = save_statement(node) this_level_items.append(item) visit_children(node) link_items(this_level_items)
def initializer(self): """Initializer of the variable (:class:`.Expression`). If the variable has no initializer, it returns ``None``. Example: .. code-block:: c int i = 1; // The initializer is 1. int j; // No initializer. """ children = list(self._node.get_children()) if self._no_children_or_only_one_that_is_not_initializer(children): return None return Expression._from_clang_node(children[-1])
def false_value(self): """False value of the ternary operator (:class:`.Expression`).""" return Expression._from_clang_node( nth_item(2, self._node.get_children()))
def cond(self): """Condition of the ternary operator (:class:`.Expression`).""" return Expression._from_clang_node(next(self._node.get_children()))
def condition(self): """Condition of the case (:class:`.Expression`).""" cond = first_child_node(self._node) return Expression._from_clang_node(cond)
def test_from_clang_node_raises_assertion_error_upon_unsupported_expression( self): unsupported_expr = mock.Mock() with self.assertRaisesRegex(AssertionError, r'.*unsupported.*'): Expression._from_clang_node(unsupported_expr)
def condition(self): """Condition of the statement (:class:`.Expression`).""" cond = next(self._node.get_children()) return Expression._from_clang_node(cond)
def rhs(self): """Expression on the right side of operator (:class:`.Expression`).""" return Expression._from_clang_node( nth_item(1, self._node.get_children()))
def lhs(self): """Expression on the left side of operator (:class:`.Expression`).""" return Expression._from_clang_node(next(self._node.get_children()))
def op(self): """Casted expression (:class:`.Expression`).""" return Expression._from_clang_node(last_child_node(self._node))
def op(self): """Operand (:class:`.Expression`).""" return Expression._from_clang_node(first_child_node(self._node))
def return_expr(self): """Returned expression (:class:`.Expression`) or ``None``.""" if any(self._node.get_children()): ret_expr = next(self._node.get_children()) return Expression._from_clang_node(ret_expr) return None