def __call__(self, type_node_list, types_being_wrapped_or_converted): """ Parameters ------------ type_node_list : list/gen of AST node of type a list of types Return ------- two sets : python modules to import, converters to include """ ignored = [util.decay(x.type.get_canonical().spelling) for x in types_being_wrapped_or_converted] m,c = set(), set() unknown_types = {} for x in type_node_list : m1,c1 = set(), set() can = util.decay(x.get_canonical().spelling) for info_cls in self.get_imp_conv: c1 |= set(info_cls().get_converters(can)) m1 |= set(info_cls().get_imports(can)) if not (can in self.basic_types or can in ignored or c1 or m1) : unknown_types[util.decay(x.get_canonical().spelling)] = util.decay(x.spelling) c |= c1 m |= m1 if unknown_types: print 20*'=' + "\nError : The following types can not be converted: \n" for can, x in unknown_types.items() : print "%s (%s)"%(x, can) raise TypeError, "" return sorted(list(m)), sorted(list(c))
def separate_method_and_properties(self, c): """ Treatment of properties Parameters ----------- method_list : a generator of the methods to treat Returns -------- Tuple (proplist, methodlist) where proplist : a list of property_ methodlist : the others methods """ method_list = list(self.get_public_methods(c)) # MUST be a list, or the generator will be exhausted later in mlist = ... if not self.use_properties : return method_list, () class property_: def __init__ (self, **kw) : self.__dict__.update(kw) def maybe_prop(m): return len(list(CL.get_params(m))) == 0 and not m.is_static_method() plist1 = [m for m in method_list if maybe_prop(m)] mlist = [m for m in method_list if not maybe_prop(m)] plist = [] OUT, SEP = '', ' ' for m in plist1: n, set_m = m.spelling, None if n.startswith('set_') : continue # do nothing, will be treated with the get_ if n.startswith('get_') : # treat the corresponding setter n = n[4:] set_m = next( (m for m in plist1 if m.spelling == 'set_' + n), None) if set_m : p = list(CL.get_params(set_m)) if set_m.result_type.spelling == "void" and len(p) ==1 : if not util.decay(p[0].spelling) == m.result_type.spelling : OUT += SEP + "Warning :\n" OUT += SEP + " in get_%s/set_%s\n" %(X,X) OUT += SEP + " The type taken from set_%s is not the return type of get_%s\n"%(X,X) OUT += SEP + " Expected %s\n"%m.result_type.spelling OUT += SEP + " Got %s\n"% decay(p[0].spelling) OUT += SEP + " I am not adding the setter to the property\n" set_m = None OUT += SEP + "%s %s\n" %(m.spelling, set_m.spelling if set_m else '') plist.append(property_(name= n, doc = doc.make_doc(m), getter = m, setter = set_m)) if OUT: print " Class %s : transforming to property : \n%s"%(c.spelling, OUT) return mlist, plist
def __call__(self, type_node_list, types_being_wrapped_or_converted): """ Parameters ------------ type_node_list : list/gen of AST node of type a list of types Return ------- two sets : python modules to import, converters to include """ ignored = [ util.decay(x.type.get_canonical().spelling) for x in types_being_wrapped_or_converted ] m, c = set(), set() unknown_types = {} for x in type_node_list: m1, c1 = set(), set() can = util.decay(x.get_canonical().spelling) for info_cls in self.get_imp_conv: c1 |= set(info_cls().get_converters(can)) m1 |= set(info_cls().get_imports(can)) if not (can in self.basic_types or can in ignored or c1 or m1): unknown_types[util.decay( x.get_canonical().spelling)] = util.decay(x.spelling) c |= c1 m |= m1 if unknown_types: print 20 * '=' + "\nError : The following types can not be converted: \n" for can, x in unknown_types.items(): print "%s (%s)" % (x, can) raise TypeError, "" return sorted(list(m)), sorted(list(c))
def cls(t): tname = util.decay(t) tname = tname.replace(' ', '') for ns in self.namespace_to_factor: tname = re.sub(ns + '::', '', tname) return tname
def separate_method_and_properties(self, c): """ Treatment of properties Parameters ----------- method_list : a generator of the methods to treat Returns -------- Tuple (proplist, methodlist) where proplist : a list of property_ methodlist : the others methods """ method_list = list( self.get_public_methods(c) ) # MUST be a list, or the generator will be exhausted later in mlist = ... if not self.use_properties: return method_list, () class property_: def __init__(self, **kw): self.__dict__.update(kw) def maybe_prop(m): return len(list( CL.get_params(m))) == 0 and not m.is_static_method() plist1 = [m for m in method_list if maybe_prop(m)] mlist = [m for m in method_list if not maybe_prop(m)] plist = [] OUT, SEP = '', ' ' for m in plist1: n, set_m = m.spelling, None if n.startswith('set_'): continue # do nothing, will be treated with the get_ if n.startswith('get_'): # treat the corresponding setter n = n[4:] set_m = next((m for m in plist1 if m.spelling == 'set_' + n), None) if set_m: p = list(CL.get_params(set_m)) if set_m.result_type.spelling == "void" and len(p) == 1: if not util.decay( p[0].spelling) == m.result_type.spelling: OUT += SEP + "Warning :\n" OUT += SEP + " in get_%s/set_%s\n" % (X, X) OUT += SEP + " The type taken from set_%s is not the return type of get_%s\n" % ( X, X) OUT += SEP + " Expected %s\n" % m.result_type.spelling OUT += SEP + " Got %s\n" % decay(p[0].spelling) OUT += SEP + " I am not adding the setter to the property\n" set_m = None OUT += SEP + "%s %s\n" % (m.spelling, set_m.spelling if set_m else '') plist.append( property_(name=n, doc=doc.make_doc(m), getter=m, setter=set_m)) if OUT: print " Class %s : transforming to property : \n%s" % ( c.spelling, OUT) return mlist, plist
def cls(t) : tname = util.decay(t) tname = tname.replace(' ','') for ns in self.namespace_to_factor : tname = re.sub(ns + '::','',tname) return tname