diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2005-06-21 20:54:51 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2005-06-21 20:54:51 (GMT) |
commit | 8ceeaba012807ff79f6d65a98f74ee9f7baf230f (patch) | |
tree | 5a6d7e32d2156044bb3ffa11796c3822f7a342ba /Tools | |
parent | da99d1cbfeedafd41263ac2d1b397d57c14ab28e (diff) | |
download | cpython-8ceeaba012807ff79f6d65a98f74ee9f7baf230f.zip cpython-8ceeaba012807ff79f6d65a98f74ee9f7baf230f.tar.gz cpython-8ceeaba012807ff79f6d65a98f74ee9f7baf230f.tar.bz2 |
Added support for optional modifiers to functions/methods (such as C++ const,
static for methods, inline, etc).
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/bgen/bgen/bgenVariable.py | 4 | ||||
-rw-r--r-- | Tools/bgen/bgen/scantools.py | 21 |
2 files changed, 19 insertions, 6 deletions
diff --git a/Tools/bgen/bgen/bgenVariable.py b/Tools/bgen/bgen/bgenVariable.py index a71d0f5..01cab56 100644 --- a/Tools/bgen/bgen/bgenVariable.py +++ b/Tools/bgen/bgen/bgenVariable.py @@ -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.""" diff --git a/Tools/bgen/bgen/scantools.py b/Tools/bgen/bgen/scantools.py index 7d2488e..2423e43 100644 --- a/Tools/bgen/bgen/scantools.py +++ b/Tools/bgen/bgen/scantools.py @@ -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" % |