Exemplo n.º 1
0
def parse_typedef(node):
    """Parse a <typedef> node
    <typedef>typedef <type>struct <name>A</name> *</type> <name>hello_t</name>;</typedef>
    <typedef>typedef <type><struct>struct <name>_stritem</name> <block> ... </struct></type> <name>item</name>;</typedef>
    :return (alias, original)
    """
    assert(domutil.is_element(node) and node.tagName == 'typedef')
    type_node = domutil.get_first_child_by_tagname(node, 'type')
    # support <function_decl> in <typedef>, i.e. typdef void *func(int a, int b)
    # return: (func, '')
    if not type_node:
        function_decl_node = domutil.get_first_child_by_tagname(node, 'function_decl')
        name_node = domutil.get_first_child_by_tagname(function_decl_node, 'name')
        alias = domutil.get_text_content(name_node)
        return (alias.strip(), '')
    name_node = domutil.get_first_child_by_tagname(node, 'name')
    original = domutil.get_text_content_except(type_node, 'block')
    alias = domutil.get_text_content(name_node)
    return (alias.strip(), original.strip())
Exemplo n.º 2
0
def resolve(node, exception = set()):
    """Resolve the identifiers used in node
    """
    # to_resolve = extract_to_resolve(node, exception)
    to_resolve = extract_to_resolve_from_code(domutil.get_text_content_except(node, 'comment'), exception)
    result = {}
    resolved = set()
    unresolved = set()
    while to_resolve:
        new_resolve = {}
        local_result, local_resolved = local.resolve(to_resolve)
        result.update(local_result)
        sys_resolved = sys.resolve(to_resolve - local_resolved)
        unresolved.update(to_resolve - local_resolved - sys_resolved)
        resolved.update(local_resolved | sys_resolved)
        new_code = ''
        for text,_,_ in local_result.values():
            new_code += text
        to_resolve = extract_to_resolve_from_code(new_code, exception | resolved | unresolved)
    if unresolved:
        if config.get('show_unresolved') == 'true':
            print('unresolved: '+repr(list(unresolved)))
    return result