mirror of
https://github.com/python/cpython
synced 2024-10-14 21:49:11 +00:00
Jack Jansen: Support for conditional inclusion of methods and functions
This commit is contained in:
parent
35c09f2e51
commit
b7c298f806
|
@ -14,20 +14,26 @@
|
|||
|
||||
class BaseFunctionGenerator:
|
||||
|
||||
def __init__(self, name):
|
||||
def __init__(self, name, condition=None):
|
||||
print "<--", name
|
||||
self.name = name
|
||||
self.prefix = name
|
||||
self.objecttype = "PyObject" # Type of _self argument to function
|
||||
self.condition = condition
|
||||
|
||||
def setprefix(self, prefix):
|
||||
self.prefix = prefix
|
||||
|
||||
def generate(self):
|
||||
print "-->", self.name
|
||||
if self.condition:
|
||||
Output()
|
||||
Output(self.condition)
|
||||
self.functionheader()
|
||||
self.functionbody()
|
||||
self.functiontrailer()
|
||||
if self.condition:
|
||||
Output("#endif")
|
||||
|
||||
def functionheader(self):
|
||||
Output()
|
||||
|
@ -50,8 +56,13 @@ def reference(self, name = None):
|
|||
if name is None:
|
||||
name = self.name
|
||||
docstring = self.docstring()
|
||||
if self.condition:
|
||||
Output()
|
||||
Output(self.condition)
|
||||
Output("{\"%s\", (PyCFunction)%s_%s, 1,", name, self.prefix, self.name)
|
||||
Output(" %s},", stringify(docstring))
|
||||
if self.condition:
|
||||
Output("#endif")
|
||||
|
||||
def docstring(self):
|
||||
return None
|
||||
|
@ -73,8 +84,8 @@ def stringify(str):
|
|||
|
||||
class ManualGenerator(BaseFunctionGenerator):
|
||||
|
||||
def __init__(self, name, body):
|
||||
BaseFunctionGenerator.__init__(self, name)
|
||||
def __init__(self, name, body, condition=None):
|
||||
BaseFunctionGenerator.__init__(self, name, condition=condition)
|
||||
self.body = body
|
||||
|
||||
def functionbody(self):
|
||||
|
@ -87,8 +98,8 @@ def setselftype(self, selftype, itselftype):
|
|||
|
||||
class FunctionGenerator(BaseFunctionGenerator):
|
||||
|
||||
def __init__(self, returntype, name, *argumentList):
|
||||
BaseFunctionGenerator.__init__(self, name)
|
||||
def __init__(self, returntype, name, *argumentList, **conditionlist):
|
||||
BaseFunctionGenerator.__init__(self, name, **conditionlist)
|
||||
self.returntype = returntype
|
||||
self.argumentList = []
|
||||
self.setreturnvar()
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
#
|
||||
|
||||
# Where to find the Universal Header include files:
|
||||
MWERKSDIR="flap:Metrowerks:Metrowerks CodeWarrior:"
|
||||
INCLUDEDIR=MWERKSDIR + "MacOS Support:Headers:Universal Headers:"
|
||||
MWERKSDIR="Macintosh HD:SWDev:Codewarrior Pro 5:Metrowerks CodeWarrior:"
|
||||
INCLUDEDIR=MWERKSDIR + "MacOS Support:Universal:Interfaces:CIncludes:"
|
||||
|
||||
# Where to put the python definitions file:
|
||||
TOOLBOXDIR="flap:Jack:Python:Mac:Lib:lib-toolbox:"
|
||||
TOOLBOXDIR="Macintosh HD:SWDev:Jack:Python:Mac:Lib:lib-toolbox:"
|
||||
|
||||
# Creator for C files:
|
||||
CREATOR="CWIE"
|
||||
|
|
|
@ -99,12 +99,23 @@ def writeinitialdefs(self):
|
|||
def initblacklists(self):
|
||||
self.blacklistnames = self.makeblacklistnames()
|
||||
self.blacklisttypes = ["unknown", "-"] + self.makeblacklisttypes()
|
||||
self.greydictnames = self.greylist2dict(self.makegreylist())
|
||||
|
||||
def greylist2dict(self, list):
|
||||
rv = {}
|
||||
for define, namelist in list:
|
||||
for name in namelist:
|
||||
rv[name] = define
|
||||
return rv
|
||||
|
||||
def makeblacklistnames(self):
|
||||
return []
|
||||
|
||||
def makeblacklisttypes(self):
|
||||
return []
|
||||
|
||||
def makegreylist(self):
|
||||
return []
|
||||
|
||||
def initrepairinstructions(self):
|
||||
self.repairinstructions = self.makerepairinstructions()
|
||||
|
@ -395,6 +406,7 @@ def dosymdef(self):
|
|||
self.defsfile.write("%s = %s\n" % (name, defn))
|
||||
else:
|
||||
self.defsfile.write("# %s = %s\n" % (name, defn))
|
||||
# XXXX No way to handle greylisted names
|
||||
|
||||
def dofuncspec(self):
|
||||
raw = self.line
|
||||
|
@ -519,6 +531,8 @@ def generate(self, type, name, arglist):
|
|||
self.typeused(atype, amode)
|
||||
self.specfile.write(" (%s, %s, %s),\n" %
|
||||
(atype, `aname`, amode))
|
||||
if self.greydictnames.has_key(name):
|
||||
self.specfile.write(" condition=%s,\n"%`self.greydictnames[name]`)
|
||||
self.specfile.write(")\n")
|
||||
self.specfile.write("%s.append(f)\n\n" % listname)
|
||||
|
||||
|
|
Loading…
Reference in a new issue