def METHOD_NAME(node, local_names, global_names):
    if isinstance(node, tree.GlobalStmt):
        global_names.update([n.value for n in node.get_global_names()])
    elif isinstance(node, tree.Name):
        if node.value in global_names:
            return
        if node.is_definition():  # local def
            locs.append(node)
            local_names.add(node.value)
        elif node.value in local_names:  # use of local
            locs.append(node)
    elif isinstance(node, tree.BaseNode):
        # ref: jedi/parser/grammar*.txt
        if node.type == "trailer" and node.children[0].value == ".":
            # this is attribute
            return
        if isinstance(node, tree.Function):
            global_names = set()  # outer global statement doesn't have effect anymore
        for child in node.children:
            METHOD_NAME(child, local_names, global_names)