Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
d9ff26b1
Kaydet (Commit)
d9ff26b1
authored
Şub 05, 1995
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
reorganized class structure so Manualgenerator works again
üst
4df16c79
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
56 deletions
+74
-56
bgenGenerator.py
Tools/bgen/bgen/bgenGenerator.py
+74
-56
No files found.
Tools/bgen/bgen/bgenGenerator.py
Dosyayı görüntüle @
d9ff26b1
...
...
@@ -12,17 +12,84 @@ OUT = "out"
INOUT
=
IN_OUT
=
"in-out"
class
FunctionGenerator
:
class
Base
FunctionGenerator
:
def
__init__
(
self
,
returntype
,
name
,
*
argumentList
):
def
__init__
(
self
,
name
):
print
"<--"
,
name
self
.
returntype
=
returntype
self
.
name
=
name
self
.
prefix
=
name
self
.
objecttype
=
"PyObject"
# Type of _self argument to function
def
setprefix
(
self
,
prefix
):
self
.
prefix
=
prefix
def
generate
(
self
):
print
"-->"
,
self
.
name
self
.
functionheader
()
self
.
functionbody
()
self
.
functiontrailer
()
def
functionheader
(
self
):
Output
()
Output
(
"static PyObject *
%
s_
%
s(_self, _args)"
,
self
.
prefix
,
self
.
name
)
IndentLevel
()
Output
(
"
%
s *_self;"
,
self
.
objecttype
)
Output
(
"PyObject *_args;"
)
DedentLevel
()
OutLbrace
()
Output
(
"PyObject *_res = NULL;"
)
def
functionbody
(
self
):
Output
(
"/* XXX To be provided */"
)
def
functiontrailer
(
self
):
OutRbrace
()
def
reference
(
self
,
name
=
None
):
if
name
is
None
:
name
=
self
.
name
docstring
=
self
.
docstring
()
Output
(
"{
\"
%
s
\"
, (PyCFunction)
%
s_
%
s, 1,"
,
name
,
self
.
prefix
,
self
.
name
)
Output
(
"
%
s},"
,
stringify
(
docstring
))
def
docstring
(
self
):
return
None
_stringify_map
=
{
'
\n
'
:
'
\\
n'
,
'
\t
'
:
'
\\
t'
,
'
\r
'
:
'
\\
r'
,
'
\b
'
:
'
\\
b'
,
'
\
e'
:
'
\\
e'
,
'
\a
'
:
'
\\
a'
,
'
\f
'
:
'
\\
f'
,
'"'
:
'
\\
"'
}
def
stringify
(
str
):
if
str
is
None
:
return
"NULL"
res
=
'"'
map
=
_stringify_map
for
c
in
str
:
if
map
.
has_key
(
c
):
res
=
res
+
map
[
c
]
elif
' '
<=
c
<=
'~'
:
res
=
res
+
c
else
:
res
=
res
+
'
\\
%03
o'
%
ord
(
c
)
res
=
res
+
'"'
return
res
class
ManualGenerator
(
BaseFunctionGenerator
):
def
__init__
(
self
,
name
,
body
):
BaseFunctionGenerator
.
__init__
(
self
,
name
)
self
.
body
=
body
def
functionbody
(
self
):
Output
(
"
%
s"
,
self
.
body
)
class
FunctionGenerator
(
BaseFunctionGenerator
):
def
__init__
(
self
,
returntype
,
name
,
*
argumentList
):
BaseFunctionGenerator
.
__init__
(
self
,
name
)
self
.
returntype
=
returntype
self
.
argumentList
=
[]
self
.
setreturnvar
()
self
.
parseArgumentList
(
argumentList
)
self
.
prefix
=
"XXX"
# Will be changed by setprefix() call
self
.
objecttype
=
"PyObject"
# Type of _self argument to function
self
.
itselftype
=
None
# Type of _self->ob_itself, if defined
def
setreturnvar
(
self
):
...
...
@@ -35,9 +102,6 @@ class FunctionGenerator:
def
makereturnvar
(
self
):
return
Variable
(
self
.
returntype
,
"_rv"
,
OutMode
)
def
setprefix
(
self
,
prefix
):
self
.
prefix
=
prefix
def
setselftype
(
self
,
selftype
,
itselftype
):
self
.
objecttype
=
selftype
self
.
itselftype
=
itselftype
...
...
@@ -49,13 +113,6 @@ class FunctionGenerator:
if
name
is
None
:
name
=
"_arg
%
d"
%
iarg
arg
=
Variable
(
type
,
name
,
mode
)
self
.
argumentList
.
append
(
arg
)
def
reference
(
self
,
name
=
None
):
if
name
is
None
:
name
=
self
.
name
docstring
=
self
.
docstring
()
Output
(
"{
\"
%
s
\"
, (PyCFunction)
%
s_
%
s, 1,"
,
name
,
self
.
prefix
,
self
.
name
)
Output
(
"
%
s},"
,
stringify
(
docstring
))
def
docstring
(
self
):
import
string
...
...
@@ -89,27 +146,13 @@ class FunctionGenerator:
else
:
outstr
=
"(
%
s)"
%
string
.
joinfields
(
output
,
", "
)
return
instr
+
" -> "
+
outstr
def
generate
(
self
):
print
"-->"
,
self
.
name
self
.
functionheader
()
def
functionbody
(
self
):
self
.
declarations
()
self
.
getargs
()
self
.
callit
()
self
.
checkit
()
self
.
returnvalue
()
self
.
functiontrailer
()
def
functionheader
(
self
):
Output
()
Output
(
"static PyObject *
%
s_
%
s(_self, _args)"
,
self
.
prefix
,
self
.
name
)
IndentLevel
()
Output
(
"
%
s *_self;"
,
self
.
objecttype
)
Output
(
"PyObject *_args;"
)
DedentLevel
()
OutLbrace
()
Output
(
"PyObject *_res = NULL;"
)
def
declarations
(
self
):
for
arg
in
self
.
argumentList
:
...
...
@@ -182,9 +225,6 @@ class FunctionGenerator:
arg
.
cleanup
()
Output
(
"return _res;"
)
def
functiontrailer
(
self
):
OutRbrace
()
class
MethodGenerator
(
FunctionGenerator
):
...
...
@@ -197,29 +237,6 @@ class MethodGenerator(FunctionGenerator):
self
.
argumentList
.
append
(
self
.
itself
)
FunctionGenerator
.
parseArgumentList
(
self
,
args
)
class
ManualGenerator
(
FunctionGenerator
):
def
__init__
(
self
,
name
,
body
):
self
.
name
=
name
self
.
body
=
body
def
definition
(
self
):
self
.
functionheader
()
Output
(
"
%
s"
,
self
.
body
)
self
.
functiontrailer
()
_stringify_map
=
{
'
\n
'
:
'
\\
n'
,
'
\t
'
:
'
\\
t'
,
'
\r
'
:
'
\\
r'
,
'
\b
'
:
'
\\
b'
,
'
\
e'
:
'
\\
e'
,
'
\a
'
:
'
\\
a'
,
'
\f
'
:
'
\\
f'
,
'"'
:
'
\\
"'
}
def
stringify
(
str
):
if
str
is
None
:
return
"None"
res
=
'"'
map
=
_stringify_map
for
c
in
str
:
if
map
.
has_key
(
c
):
res
=
res
+
map
[
c
]
elif
' '
<=
c
<=
'~'
:
res
=
res
+
c
else
:
res
=
res
+
'
\\
%03
o'
%
ord
(
c
)
res
=
res
+
'"'
return
res
def
_test
():
void
=
None
...
...
@@ -233,5 +250,6 @@ def _test():
print
"/* START */"
eggs
.
generate
()
if
__name__
==
"__main__"
:
_test
()
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