Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
e05e7c05
Commit
e05e7c05
authored
Sep 20, 2008
by
LisandroDalcin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Signature embedding: Proper display of native types (#2).
parent
3ed359ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
157 additions
and
8 deletions
+157
-8
Cython/Compiler/AutoDocTransforms.py
Cython/Compiler/AutoDocTransforms.py
+38
-7
tests/run/embedsignatures.pyx
tests/run/embedsignatures.pyx
+119
-1
No files found.
Cython/Compiler/AutoDocTransforms.py
View file @
e05e7c05
...
...
@@ -17,11 +17,31 @@ class EmbedSignature(CythonTransform):
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:
...
...
@@ -68,6 +88,15 @@ class EmbedSignature(CythonTransform):
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,
...
...
@@ -75,12 +104,14 @@ class EmbedSignature(CythonTransform):
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):
...
...
@@ -133,7 +164,7 @@ class EmbedSignature(CythonTransform):
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:
...
...
tests/run/embedsignatures.pyx
View file @
e05e7c05
...
...
@@ -48,7 +48,66 @@ __doc__ = ur"""
'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
"""
...
...
@@ -105,3 +164,62 @@ def with_doc_2(a, b, c):
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment