def gen_accept(self): src = ' def accept(self, visitor):\n' src += ' tag = visitor.visit_{}(self)\n'.format( (util.camel_to_under(self.name))) src += ' visitor.down(tag)\n' if self.all_entries: src += " for c in self.children():\n" src += " c.accept(visitor)\n" src += ' visitor.up(tag)\n\n' return src
def gen_visitor(self): """ Generate a base visitor class that does nothing. """ src = 'class NodeVisitor(object):\n' src += ' def up(self, tag): pass\n' src += ' def down(self, tag): pass\n' for x in self.node_cfg: src += ' def visit_'+util.camel_to_under(x.name)+'(self, node): pass\n' src += '\n\n' return src
def gen_visitor(self): """ Generate a base visitor class that does nothing. """ src = 'class NodeVisitor(object):\n' src += ' def up(self, tag): pass\n' src += ' def down(self, tag): pass\n' for x in self.node_cfg: src += ' def visit_' + util.camel_to_under( x.name) + '(self, node): pass\n' src += '\n\n' return src
def get_elem_type(self, elem): """ Given an element, return its type """ assert isinstance(elem, ast.Elem) # If its an expression group, get_expr_type if isinstance(elem, ast.ElemGroup): return self.get_expr_type(elem.expr) # If its a single identifer, look it up (if it exists) elif isinstance(elem, ast.ElemId): s = self.sym.lookup(elem.name) if s: return s.type else: self.nodecl_error(elem.name) return None # If its a subscripted identifier, lookup and return subscripted type elif isinstance(elem, ast.ElemSub): s = self.sym.lookup(elem.name) if s: #print(s.type.subscriptOf()) return s.type.subscriptOf() else: self.nodecl_error(elem.name) return None # If it is an array slice elif isinstance(elem, ast.ElemSlice): s = self.sym.lookup(elem.name) if s: return s.type else: self.nodecl_error(elem.name) return None # Otherwise, return the specified elem type else: return elem_types[util.camel_to_under(elem.__class__.__name__)]
def name(self, node): return util.camel_to_under(node.__class__.__name__)
def mangle_subcommand(name): return util.camel_to_under(name).replace('_', '-').replace('.', '-')