'Get the start scope for the given line.
"linenum" appears to be 0-based, however all CIX line data
is 1-based so we\'ll convert here.
Dev Notes:
- XXX Add built-in scope.'

def scope_stack_from_tree_and_linenum(self, tree, linenum):

    linenum += 1
    scope_stack = [tree.find('file/scope')]
    while True:
        next_scope_could_be = None
        for scope in scope_stack[(-1)].findall('scope'):
            start = int(scope.get('line'))
            if ((start <= linenum) and ((not scope.get('lineend')) or (linenum <= int(scope.get('lineend'))))):
                next_scope_could_be = scope
            elif (start > linenum):
                break
        if (next_scope_could_be is not None):
            scope_stack.append(next_scope_could_be)
        else:
            break
    return scope_stack
