def scan_va_list_tag(syntax_tree):
    '''Scan use of __va_list_tag.'''
    try:
        postorder = lambda tree: _scan_tree(tree, syntax_tree)
        traverse_postorder(syntax_tree, postorder)
    except StopIteration:
        pass
def scan_required_nodes(syntax_tree, check_required):
    """Breadth-first scan for required symbols."""

    def _scan_required(tree):
        """Mark nodes as required."""
        if not check_required(tree):
            return
        tree.annotate(annotations.REQUIRED, True)
        _scan_type_definition(tree.type, todo, visited)
        if tree.is_field_decl():
            _scan_type_definition(tree.semantic_parent.type, todo, visited)
        elif tree.kind == CursorKind.FUNCTION_DECL:
            if not tree.type.is_function_variadic() and tree.get_num_arguments() > 0:
                for arg in tree.get_arguments():
                    _scan_type_definition(arg.type, todo, visited)
            if tree.result_type.kind != TypeKind.VOID:
                _scan_type_definition(tree.result_type, todo, visited)

    visited = set()
    todo = []
    traverse_postorder(syntax_tree, _scan_required)
    call_scan_type_definition = lambda tree: _scan_type_definition(tree.type, todo, visited)
    while todo:
        # Trick is to copy todo and then empty it without creating a new list.
        trees = list(todo)
        todo[:] = []
        for tree in trees:
            tree.annotate(annotations.REQUIRED, True)
            traverse_postorder(tree, call_scan_type_definition)
def scan_va_list_tag(syntax_tree):
    '''Scan use of __va_list_tag.'''
    try:
        postorder = lambda tree: _scan_tree(tree, syntax_tree)
        traverse_postorder(syntax_tree, postorder)
    except StopIteration:
        pass
def scan_required_nodes(syntax_tree, check_required):
    '''Breadth-first scan for required symbols.'''
    def _scan_required(tree):
        '''Mark nodes as required.'''
        if not check_required(tree):
            return
        tree.annotate(annotations.REQUIRED, True)
        _scan_type_definition(tree.type, todo, visited)
        if tree.is_field_decl():
            _scan_type_definition(tree.semantic_parent.type, todo, visited)
        elif tree.kind == CursorKind.FUNCTION_DECL:
            if (not tree.type.is_function_variadic()
                    and tree.get_num_arguments() > 0):
                for arg in tree.get_arguments():
                    _scan_type_definition(arg.type, todo, visited)
            if tree.result_type.kind != TypeKind.VOID:
                _scan_type_definition(tree.result_type, todo, visited)

    visited = set()
    todo = []
    traverse_postorder(syntax_tree, _scan_required)
    call_scan_type_definition = lambda tree: \
        _scan_type_definition(tree.type, todo, visited)
    while todo:
        # Trick is to copy todo and then empty it without creating a new list.
        trees = list(todo)
        todo[:] = []
        for tree in trees:
            tree.annotate(annotations.REQUIRED, True)
            traverse_postorder(tree, call_scan_type_definition)
def scan_anonymous_pod(syntax_tree):
    """Scan anonymous PODs."""
    traverse_postorder(syntax_tree, _scan_tree)
示例#6
0
def scan_and_rename(syntax_tree, rename):
    '''Scan syntax tree and rename nodes.'''
    traverse_postorder(syntax_tree, rename)
def scan_forward_decl(syntax_tree):
    '''Scan syntax tree for forward declarations.'''
    has_seen = set()
    traverse_postorder(syntax_tree, lambda tree: _scan_tree(tree, has_seen))
示例#8
0
def custom_pass(syntax_tree, func):
    '''Run a custom pass over the tree.'''
    from cbind.passes.util import traverse_postorder
    traverse_postorder(syntax_tree, func)
示例#9
0
def scan_anonymous_pod(syntax_tree):
    '''Scan anonymous PODs.'''
    traverse_postorder(syntax_tree, _scan_tree)