示例#1
0
文件: to_fmt.py 项目: vhb/pyrser
def to_fmt(self, with_from=False) -> fmt.indentable:
    txt = fmt.block("{\n", "\n}", [])
    items = fmt.sep("\n---\n", [])
    for k in sorted(self._internal.keys()):
        items.lsdata.append(fmt.sep(": ", [k, fmt.tab([self._internal[k].to_fmt(with_from)])]))
    txt.lsdata.append(fmt.tab([items]))
    return txt
示例#2
0
def to_c(self):
    lsparams = []
    for p in self.params:
        lsparams.append(p.to_c())
    if type(self.call_expr) is nodes.Raw and self.call_expr.value == ",":
        return fmt.sep(str(self.call_expr.to_c()) + ' ', lsparams)
    return fmt.sep(' ' + str(self.call_expr.to_c()) + ' ', lsparams)
示例#3
0
 def to_tl4t(self):
     params = []
     for p in self.p:
         params.append(p.to_tl4t())
     parenth = fmt.block('(', ')', fmt.sep(', ', params))
     lsblock = fmt.sep('', [self.call_expr.to_tl4t(), parenth])
     return lsblock
示例#4
0
文件: to_c.py 项目: Py0s/KooC
def to_c(self):
    lsparams = []
    for p in self.params:
        lsparams.append(p.to_c())
    if type(self.call_expr) is nodes.Raw and self.call_expr.value == ",":
        return fmt.sep(str(self.call_expr.to_c()) + ' ', lsparams)
    return fmt.sep(' ' + str(self.call_expr.to_c()) + ' ', lsparams)
示例#5
0
def to_c(self):
    if self.already_imported:
        return fmt.sep("", [])
    lsbody = []
    lsbody.append(self.ifndef.to_c())
    lsbody.append(self.define.to_c())
    lsbody.append(self.body.to_c())
    lsbody.append(self.endif.to_c())
    return fmt.end("\n\n", fmt.tab(fmt.sep("\n", lsbody)))
示例#6
0
文件: to_fmt.py 项目: vhb/pyrser
def to_fmt(self, with_from=False) -> fmt.indentable:
    txt = fmt.block('{\n', '\n}', [])
    items = fmt.sep('\n---\n', [])
    for k in sorted(self._internal.keys()):
        items.lsdata.append(
            fmt.sep(': ',
                    [k, fmt.tab([self._internal[k].to_fmt(with_from)])]))
    txt.lsdata.append(fmt.tab([items]))
    return txt
示例#7
0
def to_c(self):
    lsparams = []
    # TODO: add forward declarations
    for p in self.params:
        lsparams.append(p.to_c())
    return fmt.sep("", [
        self.call_expr.to_c(),
        fmt.block('(', ')', [fmt.sep(', ', lsparams)])
    ])
示例#8
0
def to_c(self):
    if isinstance(self.params[0], nodes.CType):
        return fmt.sep(
            " ",
            [
                self.call_expr.to_c(),  # sizeof/typeof ...
                fmt.block("(", ")", self.params[0].ctype_to_c())  # type/expr
            ])
    else:
        return fmt.sep(" ", [self.call_expr.to_c(), self.params[0].to_c()])
示例#9
0
def to_c(self):
    body = ';\n'
    if self.body is not None and hasattr(self.body, 'to_c'):
        body = fmt.tab(self.body.to_c())
    lswh = [
        fmt.sep(" ",
                ["switch",
                 fmt.block('(', ')\n', [self.condition.to_c()])]), body
    ]
    return fmt.sep("", lswh)
示例#10
0
文件: tl4t.py 项目: Atch0um/pyrser
 def to_tl4t(self):
     params = []
     for p in self.p:
         params.append(p.to_tl4t())
     parenth = fmt.block('(', ')', fmt.sep(', ', params))
     lsblock = fmt.sep('', [
         self.call_expr.to_tl4t(),
         parenth
     ])
     return lsblock
示例#11
0
文件: to_c.py 项目: Py0s/KooC
def to_c(self):
    if isinstance(self.params[0], nodes.CType):
        return fmt.sep(
            " ",
            [
                self.call_expr.to_c(),  # sizeof/typeof ...
                fmt.block("(", ")", self.params[0].ctype_to_c())  # type/expr
            ]
        )
    else:
        return fmt.sep(" ", [self.call_expr.to_c(), self.params[0].to_c()])
示例#12
0
def to_c(self):
    body = ';\n'
    if self.body is not None and hasattr(self.body, 'to_c'):
        body = fmt.tab(self.body.to_c())
    lsdo = [
        fmt.sep("\n", ["do", body]),
        fmt.sep(
            " ",
            ["while", fmt.block('(', ');\n', [self.condition.to_c()])])
    ]
    return fmt.sep("", lsdo)
示例#13
0
文件: to_fmt.py 项目: vhb/pyrser
def to_fmt(self, with_from=False) -> fmt.indentable:
    """
    Return a Fmt representation of Translator for pretty-printing
    """
    txt = fmt.sep("\n", [
        fmt.sep(" ", [
            self._type_source, "to", self._type_target, '=',
            self._fun.to_fmt()
        ]),
        self._notify.get_content(with_from)
    ])
    return txt
示例#14
0
 def to_fmt(self) -> fmt.indentable:
     txt = fmt.sep("", [self.name])
     if len(self.attributes) > 0:
         lsattr = fmt.sep(", ", [])
         lkey = sorted(self.attributes.keys())
         for k in lkey:
             t = k
             if self.attributes[k] is not None:
                 t += '=' + str(self.attributes[k])
             lsattr.lsdata.append(t)
         txt.lsdata.append(fmt.block("[", "]", lsattr))
     return txt
示例#15
0
文件: tuple.py 项目: Atch0um/pyrser
 def to_fmt(self) -> fmt.indentable:
     """
     Return an Fmt representation for pretty-printing
     """
     lsb = []
     if len(self._lsig) > 0:
         for s in self._lsig:
             lsb.append(s.to_fmt())
     block = fmt.block("(", ")", fmt.sep(', ', lsb))
     qual = "tuple"
     txt = fmt.sep("", [qual, block])
     return txt
示例#16
0
 def to_fmt(self) -> fmt.indentable:
     """
     Return an Fmt representation for pretty-printing
     """
     lsb = []
     if len(self._lsig) > 0:
         for s in self._lsig:
             lsb.append(s.to_fmt())
     block = fmt.block("(", ")", fmt.sep(', ', lsb))
     qual = "tuple"
     txt = fmt.sep("", [qual, block])
     return txt
示例#17
0
文件: to_fmt.py 项目: vhb/pyrser
def to_fmt(self, with_from=False) -> fmt.indentable:
    """
    Return a Fmt representation of Translator for pretty-printing
    """
    txt = fmt.sep(
        "\n",
        [
            fmt.sep(" ", [self._type_source, "to", self._type_target, "=", self._fun.to_fmt()]),
            self._notify.get_content(with_from),
        ],
    )
    return txt
示例#18
0
 def to_fmt(self) -> fmt.indentable:
     txt = fmt.sep("", [self.name])
     if len(self.attributes) > 0:
         lsattr = fmt.sep(", ", [])
         lkey = sorted(self.attributes.keys())
         for k in lkey:
             t = k
             if self.attributes[k] is not None:
                 t += '=' + str(self.attributes[k])
             lsattr.lsdata.append(t)
         txt.lsdata.append(fmt.block("[", "]", lsattr))
     return txt
示例#19
0
文件: to_c.py 项目: Py0s/KooC
def to_c(self):
    body = ';\n'
    if self.body is not None and hasattr(self.body, 'to_c'):
        body = fmt.tab(self.body.to_c())
    lswh = [
        fmt.sep(
            " ",
            [
                "while",
                fmt.block('(', ')\n', [self.condition.to_c()])
            ]),
        body
    ]
    return fmt.sep("", lswh)
示例#20
0
 def to_tl4t(self) -> fmt.indentable:
     params = []
     if self.p is not None:
         for p in self.p:
             params.append(p.to_tl4t())
     parenth = fmt.block('(', ')', fmt.sep(", ", params))
     lsdecl = fmt.sep(
         ' ', ["fun", fmt.sep('', [self.name, parenth]), ":", self.t])
     lsblock = None
     if hasattr(self, 'block'):
         lsblock = fmt.sep("\n", [lsdecl, self.block.to_tl4t()])
     else:
         lsblock = fmt.end(";\n", lsdecl)
     return lsblock
示例#21
0
文件: to_fmt.py 项目: vhb/pyrser
def to_fmt(self):
    """
    Return an Fmt representation for pretty-printing
    """
    qual = "evalctx"
    lseval = []
    block = fmt.block(":\n", "", fmt.tab(lseval))
    txt = fmt.sep(" ", [qual, block])
    lseval.append(self._sig.to_fmt())
    if len(self.resolution) > 0:
        lsb = []
        for k in sorted(self.resolution.keys()):
            s = self.resolution[k]
            if s is not None:
                lsb.append(
                    fmt.end("\n", ["'%s': %s (%s)" % (k, s, s().show_name())]))
            else:
                lsb.append(fmt.end("\n", ["'%s': Unresolved" % (k)]))
        if self._translate_to is not None:
            lsb.append("use translator:")
            lsb.append(self._translate_to.to_fmt())
        if self._variadic_types is not None:
            lsb.append("variadic types:\n")
            arity = self._sig.arity
            for t in self._variadic_types:
                lsb.append("[%d] : %s\n" % (arity, t))
                arity += 1
        lseval.append(fmt.block("\nresolution :\n", "", fmt.tab(lsb)))
    return txt
示例#22
0
 def to_fmt(self) -> fmt.indentable:
     lsub = []
     txtfinal = fmt.sep(".", lsub)
     lself = []
     txtself = fmt.sep("", lself)
     lself.append(self.__name.to_fmt())
     if len(self.__params) > 0:
         lsp = []
         for p in self.__params:
             lsp.append(p.to_fmt())
         txtparams = fmt.block("<", ">", lsp)
         lself.append(txtparams)
     lsub.append(lself)
     if self.__subcomponent is not None:
         lsub.append(self.__subcomponent.to_fmt())
     return txtfinal
示例#23
0
def to_c(self):
    lsbody = []
    i = 0
    for it in self.body:
        subbody = it.to_c()
        if hasattr(it, 'designation'):
            subbody = fmt.sep("", [it.designation, subbody])
        if isinstance(subbody, fmt.block):
            lsbody.append(fmt.tab(["\n", subbody]))
        else:
            lsbody.append(subbody)
        i += 1
        if i > 8:
            lsbody[-1] = "\n" + str(lsbody[-1])
            i = 0
    return fmt.block("{ ", " }", fmt.tab(fmt.sep(', ', lsbody)))
示例#24
0
文件: to_fmt.py 项目: vhb/pyrser
def to_fmt(self):
    """
    Return an Fmt representation for pretty-printing
    """
    qual = "evalctx"
    lseval = []
    block = fmt.block(":\n", "", fmt.tab(lseval))
    txt = fmt.sep(" ", [qual, block])
    lseval.append(self._sig.to_fmt())
    if len(self.resolution) > 0:
        lsb = []
        for k in sorted(self.resolution.keys()):
            s = self.resolution[k]
            if s is not None:
                lsb.append(fmt.end("\n", ["'%s': %s (%s)" % (k, s, s().show_name())]))
            else:
                lsb.append(fmt.end("\n", ["'%s': Unresolved" % (k)]))
        if self._translate_to is not None:
            lsb.append("use translator:")
            lsb.append(self._translate_to.to_fmt())
        if self._variadic_types is not None:
            lsb.append("variadic types:\n")
            arity = self._sig.arity
            for t in self._variadic_types:
                lsb.append("[%d] : %s\n" % (arity, t))
                arity += 1
        lseval.append(fmt.block("\nresolution :\n", "", fmt.tab(lsb)))
    return txt
示例#25
0
文件: to_c.py 项目: bew/kooc.tek
def to_c(self):
    lsdata = []
    lsdata.append('// begin of module ' + self.name + ' header\n')

    # - generate function prototypes
    for func in self.declallfuncs():
        # mangle
        func._name = mangler.mangle_module(func._name,
                                           func._ctype,
                                           typeName=self.name)
        if hasattr(func, 'body'):
            delattr(func, 'body')

        lsdata.append(func.to_c())

    # - generate extern variable declarations
    for v in self.declallvars():
        var = copy.deepcopy(v)

        # mangle
        #name = mangler.mangle_module(var._name, var._ctype, typeName = self.name)
        #print('name variable after mangling:', name)

        # transform to extern declaration
        var._ctype._storage = nodes.Storages.EXTERN
        delattr(var, '_assign_expr')

        lsdata.append(var.to_c())

    lsdata.append('// end of module ' + self.name + ' header\n')
    return fmt.sep("\n", lsdata)
示例#26
0
 def to_fmt(self) -> fmt.indentable:
     lsub = []
     txtfinal = fmt.sep(".", lsub)
     lself = []
     txtself = fmt.sep("", lself)
     lself.append(self.__name.to_fmt())
     if len(self.__params) > 0:
         lsp = []
         for p in self.__params:
             lsp.append(p.to_fmt())
         txtparams = fmt.block("<", ">", lsp)
         lself.append(txtparams)
     lsub.append(lself)
     if self.__subcomponent is not None:
         lsub.append(self.__subcomponent.to_fmt())
     return txtfinal
示例#27
0
文件: to_c.py 项目: Py0s/KooC
def to_c(self):
    lsbody = []
    i = 0
    for it in self.body:
        subbody = it.to_c()
        if hasattr(it, 'designation'):
            subbody = fmt.sep("", [it.designation, subbody])
        if isinstance(subbody, fmt.block):
            lsbody.append(fmt.tab(["\n", subbody]))
        else:
            lsbody.append(subbody)
        i += 1
        if i > 8:
            lsbody[-1] = "\n" + str(lsbody[-1])
            i = 0
    return fmt.block("{ ", " }", fmt.tab(fmt.sep(', ', lsbody)))
示例#28
0
文件: match.py 项目: Atch0um/pyrser
 def to_fmt(self) -> fmt.indentable:
     res = fmt.sep('', [])
     if self.v is None:
         res.lsdata.append('*')
     else:
         res.lsdata.append(repr(self.v))
     return res
示例#29
0
文件: to_c.py 项目: Py0s/KooC
def to_c(self):
    lsparams = []
    # TODO: add forward declarations
    for p in self.params:
        lsparams.append(p.to_c())
    return fmt.sep(
        "",
        [
            self.call_expr.to_c(),
            fmt.block(
                '(',
                ')',
                [fmt.sep(', ', lsparams)]
            )
        ]
    )
示例#30
0
文件: match.py 项目: vhb/pyrser
 def to_fmt(self) -> fmt.indentable:
     res = fmt.sep('', [])
     if self.v is None:
         res.lsdata.append('*')
     else:
         res.lsdata.append(repr(self.v))
     return res
示例#31
0
 def to_fmt(self) -> fmt.indentable:
     res = fmt.sep('\n', [])
     res.lsdata.append("kind: %s" % self.kind)
     if self.parent is not None:
         res.lsdata.append("parent: %d" % id(self.parent))
     res.lsdata.append("node: %d" % id(self.node))
     return res
示例#32
0
def to_c(self):
    return fmt.sep(
        "",
        [
            self.call_expr.to_c(),  # expr
            fmt.block('[', ']', [self.params[0].to_c()])  # index
        ])
示例#33
0
文件: to_c.py 项目: Py0s/KooC
def to_c(self):
    return fmt.sep(
        "",
        [
            self.call_expr.to_c(),  # expr
            fmt.block('[', ']', [self.params[0].to_c()])  # index
        ]
    )
示例#34
0
def to_c(self):
    if ((hasattr(self, 'body') and self.body is not None
         and hasattr(self.body, 'to_c'))):
        return fmt.sep("\n",
                       [self.ctype.ctype_to_c(self._name),
                        self.body.to_c()])
    else:
        return fmt.end(';\n', decl_to_c(self))
示例#35
0
 def dbg_str(self) -> str:
     txt = fmt.sep('\n', [])
     txt.lsdata.append("id parent = %d" % id(self.parent))
     n = self.node()
     txt.lsdata.append("node = %s - %s" % (type(n), str(n)))
     d = CaptureContext.kind_of_node
     txt.lsdata.append("kind = %s" % list(d.keys())[list(d.values()).index(self.kind)])
     txt.lsdata.append("value = %s" % repr(self.value))
     return str(txt)
示例#36
0
文件: tl4t.py 项目: Atch0um/pyrser
 def to_tl4t(self):
     return fmt.sep(
         " ",
         [
             self.p[0].to_tl4t(),
             self.call_expr.to_tl4t(),
             self.p[1].to_tl4t()
         ]
     )
示例#37
0
文件: tl4t.py 项目: Atch0um/pyrser
 def to_tl4t(self) -> fmt.indentable:
     lssub = []
     for s in self.body:
         lssub.append(s.to_tl4t())
     lsblock = None
     if self.root:
         lsblock = fmt.sep('', lssub)
     else:
         lsblock = fmt.block('{\n', '}', [fmt.tab(lssub)])
     return lsblock
示例#38
0
 def to_tl4t(self) -> fmt.indentable:
     lssub = []
     for s in self.body:
         lssub.append(s.to_tl4t())
     lsblock = None
     if self.root:
         lsblock = fmt.sep('', lssub)
     else:
         lsblock = fmt.block('{\n', '}', [fmt.tab(lssub)])
     return lsblock
示例#39
0
文件: match.py 项目: Atch0um/pyrser
 def to_fmt(self) -> fmt.indentable:
     res = fmt.sep(' ', [])
     if self.v is not None:
         res.lsdata.append(self.v.to_fmt())
     if self.clean_event:
         res.lsdata.append('?')
     else:
         res.lsdata.append('??')
     res.lsdata.append('<' + repr(self.precond) + '>')
     return res
示例#40
0
文件: match.py 项目: Atch0um/pyrser
 def to_fmt(self) -> fmt.indentable:
     n = '*'
     if self.name is not None:
         n = self.name
     n = '.' + n
     v = '*'
     if self.v is not None:
         v = self.v.to_fmt()
     res = fmt.sep('=', [n, v])
     return res
示例#41
0
文件: match.py 项目: vhb/pyrser
 def to_fmt(self) -> fmt.indentable:
     n = '*'
     if self.name is not None:
         n = self.name
     n = '.' + n
     v = '*'
     if self.v is not None:
         v = self.v.to_fmt()
     res = fmt.sep('=', [n, v])
     return res
示例#42
0
文件: match.py 项目: vhb/pyrser
 def to_fmt(self) -> fmt.indentable:
     res = fmt.sep(' ', [])
     if self.v is not None:
         res.lsdata.append(self.v.to_fmt())
     if self.clean_event:
         res.lsdata.append('?')
     else:
         res.lsdata.append('??')
     res.lsdata.append('<' + repr(self.precond) + '>')
     return res
示例#43
0
文件: to_fmt.py 项目: vhb/pyrser
def to_fmt(self):
    """
    Return an Fmt representation for pretty-printing
    """
    params = ""
    txt = fmt.sep(" ", ["var"])
    name = self.show_name()
    if name != "":
        txt.lsdata.append(name)
    txt.lsdata.append(": " + self.tret)
    return txt
示例#44
0
def to_c(self):
    return fmt.sep(
        " ",
        [
            fmt.block(
                "(",
                ")",
                self.params[0].ctype_to_c()  # type
            ),
            self.params[1].to_c()  # expr
        ])
示例#45
0
文件: match.py 项目: vhb/pyrser
 def to_fmt(self) -> fmt.indentable:
     res = fmt.sep('', [])
     if self.t is not object:
         res.lsdata.append(self.t.__name__)
     else:
         res.lsdata.append('*')
     iparen = []
     if self.attrs is not None:
         # TODO: render unknown attr (.?) at the end after ..., also unknown attr implie 'unstrict' mode
         iparen = fmt.sep(', ', [])
         for a in self.attrs:
             iparen.lsdata.append(a.to_fmt())
     if not self.strict:
         iparen.lsdata.append('...')
     if self.iskindof:
         paren = fmt.block('^(', ')', iparen)
     else:
         paren = fmt.block('(', ')', iparen)
     res.lsdata.append(paren)
     return res
示例#46
0
文件: match.py 项目: vhb/pyrser
 def to_fmt(self) -> fmt.indentable:
     res = fmt.sep('', [])
     if self.t is not object:
         res.lsdata.append(self.t.__name__)
     else:
         res.lsdata.append('*')
     iparen = []
     if self.attrs is not None:
         # TODO: render unknown attr (.?) at the end after ..., also unknown attr implie 'unstrict' mode
         iparen = fmt.sep(', ', [])
         for a in self.attrs:
             iparen.lsdata.append(a.to_fmt())
     if not self.strict:
         iparen.lsdata.append('...')
     if self.iskindof:
         paren = fmt.block('^(', ')', iparen)
     else:
         paren = fmt.block('(', ')', iparen)
     res.lsdata.append(paren)
     return res
示例#47
0
文件: to_c.py 项目: bew/kooc.tek
def to_c(self):
    # generate implemention for the class
    implem_lsdata = []
    implem_lsdata.append('// begin of class ' + self.name + ' implem')

    klass = self.bind_mc()

    implem_lsdata.append(klass.structs['vtable'].to_c())
    implem_lsdata.append(klass.structs['metadata'].to_c())
    implem_lsdata.append('// end of class ' + self.name + ' implem\n')
    return fmt.sep('\n', implem_lsdata)
示例#48
0
 def to_fmt(self):
     """
     Return an Fmt representation for pretty-printing
     """
     params = ""
     txt = fmt.sep(" ", ['var'])
     name = self.show_name()
     if name != "":
         txt.lsdata.append(name)
     txt.lsdata.append(': ' + self.tret)
     return txt
示例#49
0
文件: tl4t.py 项目: Atch0um/pyrser
 def to_tl4t(self) -> fmt.indentable:
     params = []
     if self.p is not None:
         for p in self.p:
             params.append(p.to_tl4t())
     parenth = fmt.block('(', ')', fmt.sep(", ", params))
     lsdecl = fmt.sep(
         ' ',
         [
             "fun",
             fmt.sep('', [self.name, parenth]),
             ":",
             self.t
         ]
     )
     lsblock = None
     if hasattr(self, 'block'):
         lsblock = fmt.sep("\n", [lsdecl, self.block.to_tl4t()])
     else:
         lsblock = fmt.end(";\n", lsdecl)
     return lsblock
示例#50
0
文件: to_c.py 项目: Py0s/KooC
def to_c(self):
    thenbody = ';\n'
    if self.thencond is not None and hasattr(self.thencond, 'to_c'):
        thenbody = fmt.tab(self.thencond.to_c())
    lsif = [
        fmt.sep(" ", ["if", fmt.block('(', ')\n', [self.condition.to_c()])]),
        thenbody
    ]
    if self.elsecond is not None and hasattr(self.elsecond, 'to_c'):
        lsif.append("else\n")
        lsif.append(fmt.tab(self.elsecond.to_c()))
    return fmt.end("", lsif)
示例#51
0
文件: val.py 项目: Py0s/KooC
 def to_fmt(self):
     """
     Return an Fmt representation for pretty-printing
     """
     params = ""
     txt = fmt.sep(" ", ['val'])
     name = self.show_name()
     if name != "":
         txt.lsdata.append(name)
     txt.lsdata.append('(%s)' % self.value)
     txt.lsdata.append(': ' + self.tret)
     return txt
示例#52
0
文件: to_c.py 项目: Py0s/KooC
def to_c(self):
    return fmt.sep(
        " ",
        [
            fmt.block(
                "(",
                ")",
                self.params[0].ctype_to_c()  # type
            ),
            self.params[1].to_c()  # expr
        ]
    )
示例#53
0
def to_c(self):
    init_body = None
    if type(self.init) is nodes.Decl:
        init_body = decl_to_c(self.init)
    elif self.init is not None and hasattr(self.init, 'expr'):
        init_body = self.init.expr.to_c()
    cond_body = None
    if self.condition is not None and hasattr(self.condition, 'expr'):
        cond_body = self.condition.expr.to_c()
    inc_body = None
    if self.increment is not None and hasattr(self.increment, 'to_c'):
        inc_body = self.increment.to_c()
    lsfor = [
        fmt.sep(" ", [
            "for",
            fmt.block('(', ')\n',
                      [fmt.sep("; ", [init_body, cond_body, inc_body])])
        ]),
        fmt.tab(self.body.to_c())
    ]
    return fmt.end("", lsfor)
示例#54
0
文件: state.py 项目: vhb/pyrser
 def to_fmt(self) -> str:
     """
     Provide a useful representation of the register.
     """
     infos = fmt.end(";\n", [])
     s = fmt.sep(', ', [])
     for ids in sorted(self.states.keys()):
         s.lsdata.append(str(ids))
     infos.lsdata.append(fmt.block('(', ')', [s]))
     infos.lsdata.append("events:" + repr(self.events))
     infos.lsdata.append("named_events:" + repr(list(self.named_events.keys())))
     infos.lsdata.append("uid_events:" + repr(list(self.uid_events.keys())))
     return infos
示例#55
0
文件: to_c.py 项目: Py0s/KooC
def to_c(self):
    if ((hasattr(self, 'body')
         and self.body is not None
         and hasattr(self.body, 'to_c'))):
        return fmt.sep(
            "\n",
            [
                self.ctype.ctype_to_c(self._name),
                self.body.to_c()
            ]
        )
    else:
        return fmt.end(';\n', decl_to_c(self))
示例#56
0
def to_c(self):
    thenbody = ';\n'
    if self.thencond is not None and hasattr(self.thencond, 'to_c'):
        thenbody = fmt.tab(self.thencond.to_c())
    lsif = [
        fmt.sep(" ",
                ["if", fmt.block('(', ')\n', [self.condition.to_c()])]),
        thenbody
    ]
    if self.elsecond is not None and hasattr(self.elsecond, 'to_c'):
        lsif.append("else\n")
        lsif.append(fmt.tab(self.elsecond.to_c()))
    return fmt.end("", lsif)
示例#57
0
文件: tl4t.py 项目: Atch0um/pyrser
 def to_tl4t(self) -> fmt.indentable:
     lsdecl = [
         "var",
         self.name,
     ]
     if self.t is not None:
         lsdecl.append(":")
         lsdecl.append(self.t)
     if self.expr is not None:
         lsdecl.append("=")
         lsdecl.append(self.expr.to_tl4t())
     else:
         lsdecl[-1] += ";\n"
     return fmt.sep(" ", lsdecl)
示例#58
0
文件: to_c.py 项目: Py0s/KooC
def to_c(self):
    condexpr = None
    if self.params[0] is not None and hasattr(self.params[0], 'to_c'):
        condexpr = self.params[0].to_c()
    thenexpr = None
    if self.params[1] is not None and hasattr(self.params[1], 'to_c'):
        thenexpr = self.params[1].to_c()
    content = fmt.sep("", [condexpr, ' ? ', thenexpr])
    if len(self.params) > 2:
        elseexpr = None
        if self.params[2] is not None and hasattr(self.params[2], 'to_c'):
            elseexpr = self.params[2].to_c()
        content.lsdata.append(' : ')
        content.lsdata.append(elseexpr)
    return content
示例#59
0
文件: to_fmt.py 项目: vhb/pyrser
def to_fmt(self) -> fmt.indentable:
    """
    Return an Fmt representation for pretty-printing
    """
    qual = "type"
    txt = fmt.sep(" ", [qual])
    txt.lsdata.append(self.show_name())
    if hasattr(self, "_hsig") and len(self._hsig) > 0:
        lsb = []
        for k in sorted(self._hsig.keys()):
            s = self._hsig[k]
            lsb.append(fmt.end("\n", [s.to_fmt()]))
        block = fmt.block(":\n", "", fmt.tab(lsb))
        txt.lsdata.append(block)
    return txt