def start_type(self, name): self._types.append(name) _map = {"snake": snake(name), "name": name} print " struct %s:" % ast_cython_c.struct_name(name) print " pass" print " ctypedef int (*visit_%(snake)s_func)(GraphQLAst%(name)s*, void*)" % _map print " ctypedef void (*end_visit_%(snake)s_func)(GraphQLAst%(name)s*, void*)" % _map
def start_type(self, name): self._types.append(name) _map = {'snake': snake(name), 'name': name} print ' struct %s:' % ast_cython_c.struct_name(name) print ' pass' print ' ctypedef int (*visit_%(snake)s_func)(GraphQLAst%(name)s*, void*)' % _map print ' ctypedef void (*end_visit_%(snake)s_func)(GraphQLAst%(name)s*, void*)' % _map
def start_type(self, name): st_name = ast_cython_c.struct_name(name) print ''' cdef class %(name)s(GraphQLAst): cdef %(cmodule)s.%(name)s* _wrapped @staticmethod cdef create(cGraphQLAst.%(name)s *thing) ''' % {'name': st_name, 'cmodule': ast_cython_c.CMODULE_NAME} self._current_type = name
def field_prototype(owning_type, type, name, nullable, plural): _map = { 'cmodule': ast_cython_c.CMODULE_NAME, 'owning_st': ast_cython_c.struct_name(owning_type), 'snake': snake(name), 'return_st': ast_cython_c.struct_name(type) } if plural: return ''' def get_%(snake)s_size(self): return int(%(cmodule)s.%(owning_st)s_get_%(snake)s_size(self._wrapped)) ''' % _map if type in SIMPLE_RETURN_CASTS: # TODO: convert string to unicode if owning_type in SOURCE_TYPE_CASTS: _map['cast'] = SOURCE_TYPE_CASTS[owning_type] else: _map['cast'] = SIMPLE_RETURN_CASTS[type] return ''' def get_%(snake)s(self): val = %(cmodule)s.%(owning_st)s_get_%(snake)s(self._wrapped) if val is None: return None return %(cast)s(val) ''' % _map elif type in ['Type', 'Value']: # XXX this types have no functions... return ''' ''' else: # python object return type return ''' def get_%(snake)s(self): cdef const %(cmodule)s.%(return_st)s *next next = %(cmodule)s.%(owning_st)s_get_%(snake)s(self._wrapped) if next is NULL: return None return %(return_st)s.create(next) ''' % _map
def field_prototype(owning_type, type, name, nullable, plural): _map = {'cmodule': ast_cython_c.CMODULE_NAME, 'owning_st': ast_cython_c.struct_name(owning_type), 'snake': snake(name), 'return_st': ast_cython_c.struct_name(type)} if plural: return ''' def get_%(snake)s_size(self): return int(%(cmodule)s.%(owning_st)s_get_%(snake)s_size(self._wrapped)) ''' % _map if type in SIMPLE_RETURN_CASTS: # TODO: convert string to unicode if owning_type in SOURCE_TYPE_CASTS: _map['cast'] = SOURCE_TYPE_CASTS[owning_type] else: _map['cast'] = SIMPLE_RETURN_CASTS[type] return ''' def get_%(snake)s(self): val = %(cmodule)s.%(owning_st)s_get_%(snake)s(self._wrapped) if val is None: return None return %(cast)s(val) ''' % _map elif type in ['Type', 'Value']: # XXX this types have no functions... return ''' ''' else: # python object return type return ''' def get_%(snake)s(self): cdef %(cmodule)s.%(return_st)s *next next = %(cmodule)s.%(owning_st)s_get_%(snake)s(self._wrapped) if next is NULL: return None return %(return_st)s.create(next) ''' % _map
def start_type(self, name): st_name = ast_cython_c.struct_name(name) print ''' cdef class %(name)s(GraphQLAst): cdef %(cmodule)s.%(name)s* _wrapped @staticmethod cdef create(cGraphQLAst.%(name)s *thing) ''' % { 'name': st_name, 'cmodule': ast_cython_c.CMODULE_NAME } self._current_type = name
def start_type(self, name): self._current_type = name _map = {'snake': snake(name), 'name': name} print ''' cdef class %(name)s(GraphQLAst): @staticmethod cdef create(%(cmodule)s.%(name)s *thing): node = %(name)s() node._wrapped = thing return node ''' % {'name': ast_cython_c.struct_name(name), 'cmodule': ast_cython_c.CMODULE_NAME}
def start_type(self, name): self._current_type = name _map = {'snake': snake(name), 'name': name} print ''' cdef class %(name)s(GraphQLAst): @staticmethod cdef create(const %(cmodule)s.%(name)s *thing): node = %(name)s() node._wrapped = thing return node ''' % { 'name': ast_cython_c.struct_name(name), 'cmodule': ast_cython_c.CMODULE_NAME }