# Path: krakatau-lib/src/main/resources/Lib/Krakatau/java/stringescape.py
# def escapeString(u):
#     if set(u) <= ok_chars:
#         return u 
# 
#     escaped = []
#     for c in u:
#         if c in ok_chars:
#             escaped.append(c)
#         elif c in late_escape:
#             escaped.append(late_escape[c])
#         else:
#             i = ord(c)
#             if i <= 0xFFFF:
#                 escaped.append(r'\u{0:04x}'.format(i))
#             else:
#                 i -= 0x10000
#                 high = 0xD800 + (i>>10)
#                 low = 0xDC00 + (i & 0x3FF)
#                 escaped.append(r'\u{0:04x}\u{1:04x}'.format(high,low))
#     return ''.join(escaped)
# 
# Path: krakatau-lib/src/main/resources/Lib/Krakatau/ssa/objtypes.py
# def TypeTT(baset, dim):
# def baset(tt): return tt[0]
# def dim(tt): return tt[1]
# def withDimInc(tt, inc): return TypeTT(baset(tt), dim(tt)+inc)
# def withNoDim(tt): return TypeTT(baset(tt), 0)
# def isBaseTClass(tt): return not baset(tt).startswith('.')
# def className(tt): return baset(tt) if not baset(tt).startswith('.') else None
# def primName(tt): return baset(tt)[1:] if baset(tt).startswith('.') else None
# def isSubtype(env, x, y):
# def commonSupertype(env, tts):
# def verifierToSynthetic_seq(vtypes):
# def verifierToSynthetic(vtype):
# def declTypeToActual(env, decltype):


from . import ast
from .stringescape import escapeString as escape
from ..ssa import objtypes
            'throws': tree(self.throws),
        }

class FieldDef(object):
    def __init__(self, flags, type_, class_, name, desc, expr=None):
        self.flagstr = flags + ' ' if flags else ''
        self.type_ = type_
        self.name = name
        self.expr = None if expr is None else ast.makeCastExpr(type_.tt, expr)
        self.triple = class_.name, name, desc

    def print_(self, printer, print_):
        name = escape(printer.fieldName(*self.triple))
        if self.expr is not None:
            return '{}{} {} = {};'.format(self.flagstr, print_(self.type_), name, print_(self.expr))
        return '{}{} {};'.format(self.flagstr, print_(self.type_), name)

    def tree(self, printer, tree):
        return {
            'triple': self.triple,
            'type': tree(self.type_),
            'flags': self.flagstr.split(),
            'expr': tree(self.expr),
        }

class ClassDef(object):
    def __init__(self, flags, isInterface, name, superc, interfaces, fields, methods):
        self.flagstr = flags + ' ' if flags else ''
        self.isInterface = isInterface
        self.name = ast.TypeName(objtypes.TypeTT(name,0))

# Path: krakatau-lib/src/main/resources/Lib/Krakatau/java/stringescape.py
# def escapeString(u):
#     if set(u) <= ok_chars:
#         return u 
# 
#     escaped = []
#     for c in u:
#         if c in ok_chars:
#             escaped.append(c)
#         elif c in late_escape:
#             escaped.append(late_escape[c])
#         else:
#             i = ord(c)
#             if i <= 0xFFFF:
#                 escaped.append(r'\u{0:04x}'.format(i))
#             else:
#                 i -= 0x10000
#                 high = 0xD800 + (i>>10)
#                 low = 0xDC00 + (i & 0x3FF)
#                 escaped.append(r'\u{0:04x}\u{1:04x}'.format(high,low))
#     return ''.join(escaped)
# 
# Path: krakatau-lib/src/main/resources/Lib/Krakatau/ssa/objtypes.py
# def TypeTT(baset, dim):
# def baset(tt): return tt[0]
# def dim(tt): return tt[1]
# def withDimInc(tt, inc): return TypeTT(baset(tt), dim(tt)+inc)
# def withNoDim(tt): return TypeTT(baset(tt), 0)
# def isBaseTClass(tt): return not baset(tt).startswith('.')
# def className(tt): return baset(tt) if not baset(tt).startswith('.') else None
# def primName(tt): return baset(tt)[1:] if baset(tt).startswith('.') else None
# def isSubtype(env, x, y):
# def commonSupertype(env, tts):
# def verifierToSynthetic_seq(vtypes):
# def verifierToSynthetic(vtype):
# def declTypeToActual(env, decltype):


# Path: krakatau-lib/src/main/resources/Lib/Krakatau/java/ast2.py
from . import ast
from .stringescape import escapeString as escape
from ..ssa import objtypes

            'throws': tree(self.throws),
        }

class FieldDef(object):
    def __init__(self, flags, type_, class_, name, desc, expr=None):
        self.flagstr = flags + ' ' if flags else ''
        self.type_ = type_
        self.name = name
        self.expr = None if expr is None else ast.makeCastExpr(type_.tt, expr)
        self.triple = class_.name, name, desc

    def print_(self, printer, print_):
        name = escape(printer.fieldName(*self.triple))
        if self.expr is not None:
            return '{}{} {} = {};'.format(self.flagstr, print_(self.type_), name, print_(self.expr))
        return '{}{} {};'.format(self.flagstr, print_(self.type_), name)

    def tree(self, printer, tree):
        return {
            'triple': self.triple,
            'type': tree(self.type_),
            'flags': self.flagstr.split(),
            'expr': tree(self.expr),
        }

class ClassDef(object):
    def __init__(self, flags, isInterface, name, superc, interfaces, fields, methods):
        self.flagstr = flags + ' ' if flags else ''
        self.isInterface = isInterface
        self.name = ast.TypeName(objtypes.TypeTT(name,0))

        self.super = ast.TypeName(objtypes.TypeTT(superc,0)) if superc is not None else None