Example #1
0
 def visitName(self, node, ctype=None):
     if isinstance(node.ctx, ast.Param):
         if node.id not in self.argtypes:
             raise CTypeError(node.id, 'function %s() requires argument %r' % (self.func_name, node.id))
         ctype = self.argtypes[node.id]
         return cast.CName(node.id, ast.Param(), ctype, **n(node))
     elif isinstance(node.ctx, ast.Load):
         try:
             ctype = self.scope(node.id)
         except NameError as err:
             raise cast.CError(node, NameError, err.args[0])
             
         return cast.CName(node.id, ast.Load(), ctype, **n(node))
     
     elif isinstance(node.ctx, ast.Store):
         assert type is not None
         
         if node.id in self.locls:
             ectype = self.locls[node.id]
             try:
                 greatest_common_type(ctype, ectype)
             except: # Raise a custom exception if the types are not compatible
                 raise
             ctype = ectype
             
         self.locls[node.id] = ctype
         
         return cast.CName(node.id, ast.Store(), ctype, **n(node))
     else:
         assert False
Example #2
0
    def visitName(self, node, ctype=None):
        if isinstance(node.ctx, ast.Param):
            if node.id not in self.argtypes:
                raise CTypeError(
                    node.id, 'function %s() requires argument %r' %
                    (self.func_name, node.id))
            ctype = self.argtypes[node.id]
            return cast.CName(node.id, ast.Param(), ctype, **n(node))
        elif isinstance(node.ctx, ast.Load):
            try:
                ctype = self.scope(node.id)
            except NameError as err:
                raise cast.CError(node, NameError, err.args[0])

            return cast.CName(node.id, ast.Load(), ctype, **n(node))

        elif isinstance(node.ctx, ast.Store):
            assert type is not None

            if node.id in self.locls:
                ectype = self.locls[node.id]
                try:
                    greatest_common_type(ctype, ectype)
                except:  # Raise a custom exception if the types are not compatible
                    raise
                ctype = ectype

            self.locls[node.id] = ctype

            return cast.CName(node.id, ast.Store(), ctype, **n(node))
        else:
            assert False
Example #3
0
    def visitNum(self, node):
        type_map = {int:ctypes.c_int, float:ctypes.c_double}
        num_type = type(node.n)
#        ctype = rttt.const_type(type_map[num_type])
        return cast.CNum(node.n, type_map[num_type], **n(node))
Example #4
0
 def visitNum(self, node):
     type_map = {int: ctypes.c_int, float: ctypes.c_double}
     num_type = type(node.n)
     #        ctype = rttt.const_type(type_map[num_type])
     return cast.CNum(node.n, type_map[num_type], **n(node))