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
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)
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
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)))
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
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)]) ])
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()])
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)
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
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()])
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)
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
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
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
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
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)
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
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
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
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)))
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
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)
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
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)] ) ] )
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
def to_c(self): return fmt.sep( "", [ self.call_expr.to_c(), # expr fmt.block('[', ']', [self.params[0].to_c()]) # index ])
def to_c(self): return fmt.sep( "", [ self.call_expr.to_c(), # expr fmt.block('[', ']', [self.params[0].to_c()]) # index ] )
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))
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)
def to_tl4t(self): return fmt.sep( " ", [ self.p[0].to_tl4t(), self.call_expr.to_tl4t(), self.p[1].to_tl4t() ] )
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
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
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
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
def to_c(self): return fmt.sep( " ", [ fmt.block( "(", ")", self.params[0].ctype_to_c() # type ), self.params[1].to_c() # expr ])
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
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)
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
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
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)
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
def to_c(self): return fmt.sep( " ", [ fmt.block( "(", ")", self.params[0].ctype_to_c() # type ), self.params[1].to_c() # expr ] )
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)
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
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))
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)
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
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