Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b7c298f

Browse files
committed
Jack Jansen: Support for conditional inclusion of methods and functions
1 parent 35c09f2 commit b7c298f

3 files changed

Lines changed: 33 additions & 8 deletions

File tree

Tools/bgen/bgen/bgenGenerator.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,26 @@
1414

1515
class BaseFunctionGenerator:
1616

17-
def __init__(self, name):
17+
def __init__(self, name, condition=None):
1818
print "<--", name
1919
self.name = name
2020
self.prefix = name
2121
self.objecttype = "PyObject" # Type of _self argument to function
22+
self.condition = condition
2223

2324
def setprefix(self, prefix):
2425
self.prefix = prefix
2526

2627
def generate(self):
2728
print "-->", self.name
29+
if self.condition:
30+
Output()
31+
Output(self.condition)
2832
self.functionheader()
2933
self.functionbody()
3034
self.functiontrailer()
35+
if self.condition:
36+
Output("#endif")
3137

3238
def functionheader(self):
3339
Output()
@@ -50,8 +56,13 @@ def reference(self, name = None):
5056
if name is None:
5157
name = self.name
5258
docstring = self.docstring()
59+
if self.condition:
60+
Output()
61+
Output(self.condition)
5362
Output("{\"%s\", (PyCFunction)%s_%s, 1,", name, self.prefix, self.name)
5463
Output(" %s},", stringify(docstring))
64+
if self.condition:
65+
Output("#endif")
5566

5667
def docstring(self):
5768
return None
@@ -73,8 +84,8 @@ def stringify(str):
7384

7485
class ManualGenerator(BaseFunctionGenerator):
7586

76-
def __init__(self, name, body):
77-
BaseFunctionGenerator.__init__(self, name)
87+
def __init__(self, name, body, condition=None):
88+
BaseFunctionGenerator.__init__(self, name, condition=condition)
7889
self.body = body
7990

8091
def functionbody(self):
@@ -87,8 +98,8 @@ def setselftype(self, selftype, itselftype):
8798

8899
class FunctionGenerator(BaseFunctionGenerator):
89100

90-
def __init__(self, returntype, name, *argumentList):
91-
BaseFunctionGenerator.__init__(self, name)
101+
def __init__(self, returntype, name, *argumentList, **conditionlist):
102+
BaseFunctionGenerator.__init__(self, name, **conditionlist)
92103
self.returntype = returntype
93104
self.argumentList = []
94105
self.setreturnvar()

Tools/bgen/bgen/bgenlocations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#
44

55
# Where to find the Universal Header include files:
6-
MWERKSDIR="flap:Metrowerks:Metrowerks CodeWarrior:"
7-
INCLUDEDIR=MWERKSDIR + "MacOS Support:Headers:Universal Headers:"
6+
MWERKSDIR="Macintosh HD:SWDev:Codewarrior Pro 5:Metrowerks CodeWarrior:"
7+
INCLUDEDIR=MWERKSDIR + "MacOS Support:Universal:Interfaces:CIncludes:"
88

99
# Where to put the python definitions file:
10-
TOOLBOXDIR="flap:Jack:Python:Mac:Lib:lib-toolbox:"
10+
TOOLBOXDIR="Macintosh HD:SWDev:Jack:Python:Mac:Lib:lib-toolbox:"
1111

1212
# Creator for C files:
1313
CREATOR="CWIE"

Tools/bgen/bgen/scantools.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,23 @@ def writeinitialdefs(self):
9999
def initblacklists(self):
100100
self.blacklistnames = self.makeblacklistnames()
101101
self.blacklisttypes = ["unknown", "-"] + self.makeblacklisttypes()
102+
self.greydictnames = self.greylist2dict(self.makegreylist())
103+
104+
def greylist2dict(self, list):
105+
rv = {}
106+
for define, namelist in list:
107+
for name in namelist:
108+
rv[name] = define
109+
return rv
102110

103111
def makeblacklistnames(self):
104112
return []
105113

106114
def makeblacklisttypes(self):
107115
return []
116+
117+
def makegreylist(self):
118+
return []
108119

109120
def initrepairinstructions(self):
110121
self.repairinstructions = self.makerepairinstructions()
@@ -395,6 +406,7 @@ def dosymdef(self):
395406
self.defsfile.write("%s = %s\n" % (name, defn))
396407
else:
397408
self.defsfile.write("# %s = %s\n" % (name, defn))
409+
# XXXX No way to handle greylisted names
398410

399411
def dofuncspec(self):
400412
raw = self.line
@@ -519,6 +531,8 @@ def generate(self, type, name, arglist):
519531
self.typeused(atype, amode)
520532
self.specfile.write(" (%s, %s, %s),\n" %
521533
(atype, `aname`, amode))
534+
if self.greydictnames.has_key(name):
535+
self.specfile.write(" condition=%s,\n"%`self.greydictnames[name]`)
522536
self.specfile.write(")\n")
523537
self.specfile.write("%s.append(f)\n\n" % listname)
524538

0 commit comments

Comments
 (0)