# Path: javadecompiler/Krakatau/ssa/objtypes.py
# def isSubtype(env, x, y):
# def commonSupertype(env, tts):
# def verifierToSynthetic_seq(vtypes):
# def verifierToSynthetic(vtype):
# def declTypeToActual(env, decltype):


from . import ast
from .setree import SEBlockItem, SEScope, SEIf, SESwitch, SETry, SEWhile
from ..ssa import ssa_types, ssa_ops, ssa_jumps, objtypes
from ..namegen import LabelGen
from ..verifier.descriptors import parseFieldDescriptor, parseMethodDescriptor
from .. import opnames
    #Create a fake key to represent the beginning of the conditional statement itself
    #doesn't matter what it is as long as it's unique
    midk = begink + (-1,)
    node = current.head.node
    jump = node.block.jump

    if isinstance(current, SEIf):
        parts = [_createASTSub(info, scope, ftitem, True) for scope in current.getScopes()]
        cmp_str = _cmp_strs[jump.cmp]
        exprs = [info.var(node, var) for var in jump.params]
        ifexpr = ast.BinaryInfix(cmp_str, exprs, objtypes.BoolTT)
        new = ast.IfStatement(info.labelgen, midk, endk, ifexpr, tuple(parts))

    elif isinstance(current, SESwitch):
        ftitems = current.ordered[1:] + [ftitem]
        parts = [_createASTSub(info, item, newft, True) for item, newft in zip(current.ordered, ftitems)]
        for part in parts:
            part.breakKey = endk #createSub will assume break should be ft, which isn't the case with switch statements

        expr = info.var(node, jump.params[0])
        pairs = zip(current.ordered_keysets, parts)
        new = ast.SwitchStatement(info.labelgen, midk, endk, expr, pairs)

    #bundle head and if together so we can return as single statement
    headscope = _createASTBlock(info, midk, node)
    assert(headscope.jumpKey is None)
    headscope.jumpKey = midk
    return ast.StatementBlock(info.labelgen, begink, endk, [headscope, new], endk)

def createAST(method, ssagraph, seroot, namegen):

# Path: javadecompiler/Krakatau/ssa/objtypes.py
# def isSubtype(env, x, y):
# def commonSupertype(env, tts):
# def verifierToSynthetic_seq(vtypes):
# def verifierToSynthetic(vtype):
# def declTypeToActual(env, decltype):


# Path: javadecompiler/Krakatau/java/astgen.py
from . import ast
from .setree import SEBlockItem, SEScope, SEIf, SESwitch, SETry, SEWhile
from ..ssa import ssa_types, ssa_ops, ssa_jumps, objtypes
from ..namegen import LabelGen
from ..verifier.descriptors import parseFieldDescriptor, parseMethodDescriptor
from .. import opnames

    #Create a fake key to represent the beginning of the conditional statement itself
    #doesn't matter what it is as long as it's unique
    midk = begink + (-1,)
    node = current.head.node
    jump = node.block.jump

    if isinstance(current, SEIf):
        parts = [_createASTSub(info, scope, ftitem, True) for scope in current.getScopes()]
        cmp_str = _cmp_strs[jump.cmp]
        exprs = [info.var(node, var) for var in jump.params]
        ifexpr = ast.BinaryInfix(cmp_str, exprs, objtypes.BoolTT)
        new = ast.IfStatement(info.labelgen, midk, endk, ifexpr, tuple(parts))

    elif isinstance(current, SESwitch):
        ftitems = current.ordered[1:] + [ftitem]
        parts = [_createASTSub(info, item, newft, True) for item, newft in zip(current.ordered, ftitems)]
        for part in parts:
            part.breakKey = endk #createSub will assume break should be ft, which isn't the case with switch statements

        expr = info.var(node, jump.params[0])
        pairs = zip(current.ordered_keysets, parts)
        new = ast.SwitchStatement(info.labelgen, midk, endk, expr, pairs)

    #bundle head and if together so we can return as single statement
    headscope = _createASTBlock(info, midk, node)
    assert(headscope.jumpKey is None)
    headscope.jumpKey = midk
    return ast.StatementBlock(info.labelgen, begink, endk, [headscope, new], endk)

def createAST(method, ssagraph, seroot, namegen):

    info = VarInfo(method, ssagraph.blocks, namegen)