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

Skip to content

Commit 8ceeaba

Browse files
committed
Added support for optional modifiers to functions/methods (such as C++ const,
static for methods, inline, etc).
1 parent da99d1c commit 8ceeaba

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

Tools/bgen/bgen/bgenVariable.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
ReturnMode = 8+OutMode # this is the function return value
1515
ErrorMode = 16+OutMode # this is an error status -- turn it into an exception
1616
RefMode = 32
17+
ConstMode = 64
1718

1819
class Variable:
1920

@@ -47,7 +48,8 @@ def declare(self):
4748
def getDeclaration(self):
4849
"""Return the unadorned declaration of the variable,
4950
suitable for use in a formal parameter list."""
50-
return self.type.getDeclaration(self.name)
51+
refmode = (self.flags & RefMode)
52+
return self.type.getDeclaration(self.name, reference=refmode)
5153

5254
def getargsFormat(self):
5355
"""Call the type's getargsFormatmethod."""

Tools/bgen/bgen/scantools.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ def processrawspec(self, raw):
479479
self.report("(but type matched)")
480480
return
481481
type, name, args = match.group('type', 'name', 'args')
482+
modifiers = self.getmodifiers(match)
482483
type = self.pythonizename(type)
483484
name = self.pythonizename(name)
484485
if name in self.alreadydone:
@@ -499,8 +500,14 @@ def processrawspec(self, raw):
499500
self.report("*** %s %s unmanageable", type, name)
500501
return
501502
self.alreadydone.append(name)
502-
self.generate(type, name, arglist)
503+
if modifiers:
504+
self.generate(type, name, arglist, modifiers)
505+
else:
506+
self.generate(type, name, arglist)
503507

508+
def getmodifiers(self, match):
509+
return []
510+
504511
def pythonizename(self, name):
505512
name = re.sub("\*", " ptr", name)
506513
name = name.strip()
@@ -592,12 +599,16 @@ def substituteargs(self, pattern, replacement, old):
592599
##self.report("new: %r", new)
593600
return new
594601

595-
def generate(self, type, name, arglist):
596-
self.typeused(type, 'return')
597-
classname, listname = self.destination(type, name, arglist)
602+
def generate(self, tp, name, arglist, modifiers=[]):
603+
604+
self.typeused(tp, 'return')
605+
if modifiers:
606+
classname, listname = self.destination(tp, name, arglist, modifiers)
607+
else:
608+
classname, listname = self.destination(tp, name, arglist)
598609
if not classname or not listname: return
599610
if not self.specfile: return
600-
self.specfile.write("f = %s(%s, %r,\n" % (classname, type, name))
611+
self.specfile.write("f = %s(%s, %r,\n" % (classname, tp, name))
601612
for atype, aname, amode in arglist:
602613
self.typeused(atype, amode)
603614
self.specfile.write(" (%s, %r, %s),\n" %

0 commit comments

Comments
 (0)