Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b6216dd2
Commit
b6216dd2
authored
Jun 28, 2005
by
Jack Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More factorization to help C++ support.
parent
02c64d56
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
18 deletions
+51
-18
Tools/bgen/bgen/bgenBuffer.py
Tools/bgen/bgen/bgenBuffer.py
+16
-6
Tools/bgen/bgen/bgenStackBuffer.py
Tools/bgen/bgen/bgenStackBuffer.py
+3
-0
Tools/bgen/bgen/bgenStringBuffer.py
Tools/bgen/bgen/bgenStringBuffer.py
+3
-0
Tools/bgen/bgen/bgenType.py
Tools/bgen/bgen/bgenType.py
+16
-5
Tools/bgen/bgen/bgenVariable.py
Tools/bgen/bgen/bgenVariable.py
+5
-4
Tools/bgen/bgen/scantools.py
Tools/bgen/bgen/scantools.py
+8
-3
No files found.
Tools/bgen/bgen/bgenBuffer.py
View file @
b6216dd2
...
@@ -38,10 +38,11 @@ class FixedInputOutputBufferType(InputOnlyType):
...
@@ -38,10 +38,11 @@ class FixedInputOutputBufferType(InputOnlyType):
self
.
sizeformat
=
sizeformat
or
type2format
[
sizetype
]
self
.
sizeformat
=
sizeformat
or
type2format
[
sizetype
]
self
.
label_needed
=
0
self
.
label_needed
=
0
def
getDeclarations
(
self
,
name
,
reference
=
False
):
def
get
Arg
Declarations
(
self
,
name
,
reference
=
False
):
if
reference
:
if
reference
:
raise
RuntimeError
,
"Cannot pass buffer types by reference"
raise
RuntimeError
,
"Cannot pass buffer types by reference"
return
self
.
getBufferDeclarations
(
name
)
+
self
.
getSizeDeclarations
(
name
)
return
(
self
.
getBufferDeclarations
(
name
)
+
self
.
getSizeDeclarations
(
name
))
def
getBufferDeclarations
(
self
,
name
):
def
getBufferDeclarations
(
self
,
name
):
return
self
.
getInputBufferDeclarations
(
name
)
+
self
.
getOutputBufferDeclarations
(
name
)
return
self
.
getInputBufferDeclarations
(
name
)
+
self
.
getOutputBufferDeclarations
(
name
)
...
@@ -53,10 +54,10 @@ class FixedInputOutputBufferType(InputOnlyType):
...
@@ -53,10 +54,10 @@ class FixedInputOutputBufferType(InputOnlyType):
return
[
"%s %s__out__[%s]"
%
(
self
.
datatype
,
name
,
self
.
size
)]
return
[
"%s %s__out__[%s]"
%
(
self
.
datatype
,
name
,
self
.
size
)]
def
getSizeDeclarations
(
self
,
name
):
def
getSizeDeclarations
(
self
,
name
):
return
[
return
[
"%s %s__len__"
%
(
self
.
sizetype
,
name
)]
"%s %s__len__"
%
(
self
.
sizetype
,
name
),
"int %s__in_len__"
%
(
name
)
def
getAuxDeclarations
(
self
,
name
):
]
return
[
"int %s__in_len__"
%
(
name
)
]
def
getargsFormat
(
self
):
def
getargsFormat
(
self
):
return
"s#"
return
"s#"
...
@@ -189,6 +190,9 @@ class StructInputOutputBufferType(FixedInputOutputBufferType):
...
@@ -189,6 +190,9 @@ class StructInputOutputBufferType(FixedInputOutputBufferType):
return
[
"%s *%s__in__"
%
(
self
.
type
,
name
)]
return
[
"%s *%s__in__"
%
(
self
.
type
,
name
)]
def
getSizeDeclarations
(
self
,
name
):
def
getSizeDeclarations
(
self
,
name
):
return
[]
def
getAuxDeclarations
(
self
,
name
):
return
[
"int %s__in_len__"
%
(
name
)]
return
[
"int %s__in_len__"
%
(
name
)]
def
getOutputBufferDeclarations
(
self
,
name
):
def
getOutputBufferDeclarations
(
self
,
name
):
...
@@ -248,6 +252,9 @@ class StructOutputBufferType(OutputOnlyBufferMixIn, StructInputOutputBufferType)
...
@@ -248,6 +252,9 @@ class StructOutputBufferType(OutputOnlyBufferMixIn, StructInputOutputBufferType)
def
getSizeDeclarations
(
self
,
name
):
def
getSizeDeclarations
(
self
,
name
):
return
[]
return
[]
def
getAuxDeclarations
(
self
,
name
):
return
[]
def
passOutput
(
self
,
name
):
def
passOutput
(
self
,
name
):
return
"&%s__out__"
%
name
return
"&%s__out__"
%
name
...
@@ -262,5 +269,8 @@ class ArrayOutputBufferType(OutputOnlyBufferMixIn, StructInputOutputBufferType):
...
@@ -262,5 +269,8 @@ class ArrayOutputBufferType(OutputOnlyBufferMixIn, StructInputOutputBufferType):
def
getSizeDeclarations
(
self
,
name
):
def
getSizeDeclarations
(
self
,
name
):
return
[]
return
[]
def
getAuxDeclarations
(
self
,
name
):
return
[]
def
passOutput
(
self
,
name
):
def
passOutput
(
self
,
name
):
return
"%s__out__"
%
name
return
"%s__out__"
%
name
Tools/bgen/bgen/bgenStackBuffer.py
View file @
b6216dd2
...
@@ -23,6 +23,9 @@ class VarStackOutputBufferType(StackOutputBufferType):
...
@@ -23,6 +23,9 @@ class VarStackOutputBufferType(StackOutputBufferType):
"""
"""
def
getSizeDeclarations
(
self
,
name
):
def
getSizeDeclarations
(
self
,
name
):
return
[]
def
getAuxDeclarations
(
self
,
name
):
return
[
"int %s__len__ = %s"
%
(
name
,
self
.
size
)]
return
[
"int %s__len__ = %s"
%
(
name
,
self
.
size
)]
def
passOutput
(
self
,
name
):
def
passOutput
(
self
,
name
):
...
...
Tools/bgen/bgen/bgenStringBuffer.py
View file @
b6216dd2
...
@@ -26,6 +26,9 @@ class StringBufferMixIn:
...
@@ -26,6 +26,9 @@ class StringBufferMixIn:
def
getSizeDeclarations
(
self
,
name
):
def
getSizeDeclarations
(
self
,
name
):
return
[]
return
[]
def
getAuxDeclarations
(
self
,
name
):
return
[]
def
getargsFormat
(
self
):
def
getargsFormat
(
self
):
return
"s"
return
"s"
...
...
Tools/bgen/bgen/bgenType.py
View file @
b6216dd2
...
@@ -24,17 +24,25 @@ class Type:
...
@@ -24,17 +24,25 @@ class Type:
Example: int.declare('spam') prints "int spam;"
Example: int.declare('spam') prints "int spam;"
"""
"""
for
decl
in
self
.
getDeclarations
(
name
,
reference
):
for
decl
in
self
.
getArgDeclarations
(
name
,
reference
):
Output
(
"%s;"
,
decl
)
for
decl
in
self
.
getAuxDeclarations
(
name
):
Output
(
"%s;"
,
decl
)
Output
(
"%s;"
,
decl
)
def
getDeclarations
(
self
,
name
,
reference
=
False
):
def
get
Arg
Declarations
(
self
,
name
,
reference
=
False
):
"""Return
a string declaring a variable or argument, without
"""Return
the main part of the declarations for this type: the items
any syntactic adornment
"""
that will be passed as arguments in the C/C++ function call.
"""
if
reference
:
if
reference
:
return
[
"%s& %s"
%
(
self
.
typeName
,
name
)]
return
[
"%s& %s"
%
(
self
.
typeName
,
name
)]
else
:
else
:
return
[
"%s %s"
%
(
self
.
typeName
,
name
)]
return
[
"%s %s"
%
(
self
.
typeName
,
name
)]
def
getAuxDeclarations
(
self
,
name
):
"""Return any auxiliary declarations needed for implementing this
type, such as helper variables used to hold sizes, etc. These declarations
are not part of the C/C++ function call interface."""
return
[]
def
getargs
(
self
):
def
getargs
(
self
):
return
self
.
getargsFormat
(),
self
.
getargsArgs
()
return
self
.
getargsFormat
(),
self
.
getargsArgs
()
...
@@ -187,7 +195,10 @@ class FakeType(InputOnlyType):
...
@@ -187,7 +195,10 @@ class FakeType(InputOnlyType):
self
.
substitute
=
substitute
self
.
substitute
=
substitute
self
.
typeName
=
None
# Don't show this argument in __doc__ string
self
.
typeName
=
None
# Don't show this argument in __doc__ string
def
getDeclarations
(
self
,
name
,
reference
=
False
):
def
getArgDeclarations
(
self
,
name
,
reference
=
False
):
return
[]
def
getAuxDeclarations
(
self
,
name
,
reference
=
False
):
return
[]
return
[]
def
getargsFormat
(
self
):
def
getargsFormat
(
self
):
...
...
Tools/bgen/bgen/bgenVariable.py
View file @
b6216dd2
...
@@ -45,11 +45,12 @@ class Variable:
...
@@ -45,11 +45,12 @@ class Variable:
elif
self
.
flags
!=
SelfMode
:
elif
self
.
flags
!=
SelfMode
:
self
.
type
.
declare
(
self
.
name
)
self
.
type
.
declare
(
self
.
name
)
def
getDeclarations
(
self
):
def
getArgDeclarations
(
self
):
"""Return the unadorned declaration of the variable,
suitable for use in a formal parameter list."""
refmode
=
(
self
.
flags
&
RefMode
)
refmode
=
(
self
.
flags
&
RefMode
)
return
self
.
type
.
getDeclarations
(
self
.
name
,
reference
=
refmode
)
return
self
.
type
.
getArgDeclarations
(
self
.
name
,
reference
=
refmode
)
def
getAuxDeclarations
(
self
):
return
self
.
type
.
getAuxDeclarations
(
self
.
name
)
def
getargsFormat
(
self
):
def
getargsFormat
(
self
):
"""Call the type's getargsFormatmethod."""
"""Call the type's getargsFormatmethod."""
...
...
Tools/bgen/bgen/scantools.py
View file @
b6216dd2
...
@@ -482,8 +482,7 @@ if missing: raise "Missing Types"
...
@@ -482,8 +482,7 @@ if missing: raise "Missing Types"
modifiers = self.getmodifiers(match)
modifiers = self.getmodifiers(match)
type = self.pythonizename(type)
type = self.pythonizename(type)
name = self.pythonizename(name)
name = self.pythonizename(name)
if name in self.alreadydone:
if self.checkduplicate(name):
self.report("
Name
has
already
been
defined
:
%
r", name)
return
return
self.report("
==>
%
s
%
s
<==
", type, name)
self.report("
==>
%
s
%
s
<==
", type, name)
if self.blacklisted(type, name):
if self.blacklisted(type, name):
...
@@ -499,7 +498,6 @@ if missing: raise "Missing Types"
...
@@ -499,7 +498,6 @@ if missing: raise "Missing Types"
## self.report("
%
r", arg)
## self.report("
%
r", arg)
self.report("
***
%
s
%
s
unmanageable
", type, name)
self.report("
***
%
s
%
s
unmanageable
", type, name)
return
return
self.alreadydone.append(name)
if modifiers:
if modifiers:
self.generate(type, name, arglist, modifiers)
self.generate(type, name, arglist, modifiers)
else:
else:
...
@@ -508,6 +506,13 @@ if missing: raise "Missing Types"
...
@@ -508,6 +506,13 @@ if missing: raise "Missing Types"
def getmodifiers(self, match):
def getmodifiers(self, match):
return []
return []
def checkduplicate(self, name):
if name in self.alreadydone:
self.report("
Name
has
already
been
defined
:
%
r", name)
return True
self.alreadydone.append(name)
return False
def pythonizename(self, name):
def pythonizename(self, name):
name = re.sub("
\
*
", "
ptr
", name)
name = re.sub("
\
*
", "
ptr
", name)
name = name.strip()
name = name.strip()
...
...
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