self.is_in_class = False
self.class_name = None
+ def _fmt_basic_c_type_modifiers(self, ctype):
+ longness = ctype.longness
+ modifiers = ''
+ if longness < 0:
+ modifiers = 'short '
+ elif longness > 0:
+ modifiers = 'long ' * longness
+ signed = ctype.signed
+ if signed == 0:
+ modifiers = 'unsigned ' + modifiers
+ elif signed == 2:
+ modifiers = 'signed ' + modifiers
+ return modifiers[:-1] # strip final space
+
def _fmt_arg_type(self, arg):
try:
- return arg.base_type.name
+ base_type = arg.base_type
+ arg_type = base_type.name
except AttributeError:
- return ""
+ return ''
+ if base_type.is_basic_c_type:
+ modifiers = self._fmt_basic_c_type_modifiers(base_type)
+ if modifiers:
+ arg_type = '%s %s' % (modifiers, arg_type)
+ return arg_type
def _fmt_arg_name(self, arg):
try:
arglist.append('**%s' % kargs.name)
return arglist
+ def _fmt_ret_type(self, ret):
+ ret_type = ret.name
+ if ret_type is None:
+ return ''
+ modifiers = self._fmt_basic_c_type_modifiers(ret)
+ if modifiers:
+ ret_type = '%s %s' % (modifiers, ret_type)
+ return ret_type
+
def _fmt_signature(self, cls_name, func_name, args,
npargs=0, pargs=None,
nkargs=0, kargs=None,
arglist = self._fmt_arglist(args,
npargs, pargs,
nkargs, kargs)
- arglist = ', '.join(arglist)
- func_doc = '%s(%s)' % (func_name, arglist)
+ arglist_doc = ', '.join(arglist)
+ func_doc = '%s(%s)' % (func_name, arglist_doc)
if cls_name:
- func_doc = ('%s.' % cls_name) + func_doc
+ func_doc = '%s.%s' % (cls_name, func_doc)
if return_type:
- func_doc = func_doc + ' -> %s' % return_type
+ ret_doc = self._fmt_ret_type(return_type)
+ if ret_doc:
+ func_doc = '%s -> %s' % (func_doc, ret_doc)
return func_doc
def _embed_signature(self, signature, node_doc):
signature = self._fmt_signature(
self.class_name, node.declarator.base.name,
node.declarator.args,
- return_type=node.base_type.name)
+ return_type=node.base_type)
else: # should not fall here ...
assert False
if signature:
'with_doc_2(a, b, c)\n\n Existing string\n '
>>> types.__doc__
- 'types(Ext a, int b, int c, float d, e)'
+ 'types(Ext a, int b, unsigned short int c, float d, e)'
+
+ >>> print (f_c.__doc__)
+ f_c(char c) -> char
+
+ >>> print (f_uc.__doc__)
+ f_uc(unsigned char c) -> unsigned char
+
+ >>> print (f_sc.__doc__)
+ f_sc(signed char c) -> signed char
+
+
+ >>> print (f_s.__doc__)
+ f_s(short int s) -> short int
+
+ >>> print (f_us.__doc__)
+ f_us(unsigned short int s) -> unsigned short int
+
+ >>> print (f_ss.__doc__)
+ f_ss(signed short int s) -> signed short int
+
+
+ >>> print (f_i.__doc__)
+ f_i(int i) -> int
+
+ >>> print (f_ui.__doc__)
+ f_ui(unsigned int i) -> unsigned int
+
+ >>> print (f_si.__doc__)
+ f_si(signed int i) -> signed int
+
+
+ >>> print (f_l.__doc__)
+ f_l(long int l) -> long int
+
+ >>> print (f_ul.__doc__)
+ f_ul(unsigned long int l) -> unsigned long int
+
+ >>> print (f_sl.__doc__)
+ f_sl(signed long int l) -> signed long int
+
+
+ >>> print (f_L.__doc__)
+ f_L(long long int L) -> long long int
+
+ >>> print (f_uL.__doc__)
+ f_uL(unsigned long long int L) -> unsigned long long int
+
+ >>> print (f_sL.__doc__)
+ f_sL(signed long long int L) -> signed long long int
+
+
+ >>> print (f_f.__doc__)
+ f_f(float f) -> float
+
+ >>> print (f_d.__doc__)
+ f_d(double d) -> double
+
+ >>> print (f_D.__doc__)
+ f_D(long double D) -> long double
"""
Existing string
"""
pass
+
+cpdef char f_c(char c):
+ return c
+
+cpdef unsigned char f_uc(unsigned char c):
+ return c
+
+cpdef signed char f_sc(signed char c):
+ return c
+
+
+cpdef short f_s(short s):
+ return s
+
+cpdef unsigned short f_us(unsigned short s):
+ return s
+
+cpdef signed short f_ss(signed short s):
+ return s
+
+
+cpdef int f_i(int i):
+ return i
+
+cpdef unsigned int f_ui(unsigned int i):
+ return i
+
+cpdef signed int f_si(signed int i):
+ return i
+
+
+cpdef long f_l(long l):
+ return l
+
+cpdef unsigned long f_ul(unsigned long l):
+ return l
+
+cpdef signed long f_sl(signed long l):
+ return l
+
+
+cpdef long long f_L(long long L):
+ return L
+
+cpdef unsigned long long f_uL(unsigned long long L):
+ return L
+
+cpdef signed long long f_sL(signed long long L):
+ return L
+
+
+cpdef float f_f(float f):
+ return f
+
+cpdef double f_d(double d):
+ return d
+
+cpdef long double f_D(long double D):
+ return D