mirror of
https://github.com/python/cpython.git
synced 2024-11-26 11:24:40 +08:00
Added support for optional modifiers to functions/methods (such as C++ const,
static for methods, inline, etc).
This commit is contained in:
parent
da99d1cbfe
commit
8ceeaba012
@ -14,6 +14,7 @@ SelfMode = 4+InMode # this is 'self' -- don't declare it
|
||||
ReturnMode = 8+OutMode # this is the function return value
|
||||
ErrorMode = 16+OutMode # this is an error status -- turn it into an exception
|
||||
RefMode = 32
|
||||
ConstMode = 64
|
||||
|
||||
class Variable:
|
||||
|
||||
@ -47,7 +48,8 @@ class Variable:
|
||||
def getDeclaration(self):
|
||||
"""Return the unadorned declaration of the variable,
|
||||
suitable for use in a formal parameter list."""
|
||||
return self.type.getDeclaration(self.name)
|
||||
refmode = (self.flags & RefMode)
|
||||
return self.type.getDeclaration(self.name, reference=refmode)
|
||||
|
||||
def getargsFormat(self):
|
||||
"""Call the type's getargsFormatmethod."""
|
||||
|
@ -479,6 +479,7 @@ if missing: raise "Missing Types"
|
||||
self.report("(but type matched)")
|
||||
return
|
||||
type, name, args = match.group('type', 'name', 'args')
|
||||
modifiers = self.getmodifiers(match)
|
||||
type = self.pythonizename(type)
|
||||
name = self.pythonizename(name)
|
||||
if name in self.alreadydone:
|
||||
@ -499,8 +500,14 @@ if missing: raise "Missing Types"
|
||||
self.report("*** %s %s unmanageable", type, name)
|
||||
return
|
||||
self.alreadydone.append(name)
|
||||
self.generate(type, name, arglist)
|
||||
if modifiers:
|
||||
self.generate(type, name, arglist, modifiers)
|
||||
else:
|
||||
self.generate(type, name, arglist)
|
||||
|
||||
def getmodifiers(self, match):
|
||||
return []
|
||||
|
||||
def pythonizename(self, name):
|
||||
name = re.sub("\*", " ptr", name)
|
||||
name = name.strip()
|
||||
@ -592,12 +599,16 @@ if missing: raise "Missing Types"
|
||||
##self.report("new: %r", new)
|
||||
return new
|
||||
|
||||
def generate(self, type, name, arglist):
|
||||
self.typeused(type, 'return')
|
||||
classname, listname = self.destination(type, name, arglist)
|
||||
def generate(self, tp, name, arglist, modifiers=[]):
|
||||
|
||||
self.typeused(tp, 'return')
|
||||
if modifiers:
|
||||
classname, listname = self.destination(tp, name, arglist, modifiers)
|
||||
else:
|
||||
classname, listname = self.destination(tp, name, arglist)
|
||||
if not classname or not listname: return
|
||||
if not self.specfile: return
|
||||
self.specfile.write("f = %s(%s, %r,\n" % (classname, type, name))
|
||||
self.specfile.write("f = %s(%s, %r,\n" % (classname, tp, name))
|
||||
for atype, aname, amode in arglist:
|
||||
self.typeused(atype, amode)
|
||||
self.specfile.write(" (%s, %r, %s),\n" %
|
||||
|
Loading…
Reference in New Issue
Block a user