예제 #1
0
파일: astgen.py 프로젝트: xcore/tool_sire
 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
예제 #2
0
 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
예제 #3
0
파일: astgen.py 프로젝트: xcore/tool_sire
 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
예제 #4
0
 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
예제 #5
0
    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__)]
예제 #6
0
  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__)]
예제 #7
0
 def name(self, node):
     return util.camel_to_under(node.__class__.__name__)
예제 #8
0
파일: walker.py 프로젝트: xcore/tool_sire
 def name(self, node):
   return util.camel_to_under(node.__class__.__name__)
예제 #9
0
def mangle_subcommand(name):
    return util.camel_to_under(name).replace('_', '-').replace('.', '-')
예제 #10
0
def mangle_subcommand(name):
    return util.camel_to_under(name).replace('_', '-').replace('.', '-')