[Python-checkins] python/dist/src/Tools/bgen/bgen bgenType.py, 1.12, 1.13 bgenVariable.py, 1.2, 1.3 scantools.py, 1.35, 1.36

jackjansen@users.sourceforge.net jackjansen at users.sourceforge.net
Tue Jun 14 23:32:53 CEST 2005


Update of /cvsroot/python/python/dist/src/Tools/bgen/bgen
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29410
Modified Files:
	bgenType.py bgenVariable.py scantools.py 
Log Message:
More tweaks for C++ support. Still doesn't seem to break anything:-)
Index: bgenType.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/bgen/bgen/bgenType.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- bgenType.py	18 Jul 2004 06:02:01 -0000	1.12
+++ bgenType.py	14 Jun 2005 21:32:51 -0000	1.13
@@ -19,12 +19,15 @@
 self.typeName = typeName
 self.fmt = fmt
 
- def declare(self, name):
+ def declare(self, name, reference=False):
 """Declare a variable of the type with a given name.
 
 Example: int.declare('spam') prints "int spam;"
 """
- Output("%s %s;", self.typeName, name)
+ if reference:
+ Output("%s& %s;", self.typeName, name)
+ else:
+ Output("%s %s;", self.typeName, name)
 
 def getargs(self):
 return self.getargsFormat(), self.getargsArgs()
@@ -64,6 +67,11 @@
 """
 return "&" + name
 
+ def passReference(self, name):
+ """Return an argument for C++ pass-by-reference.
+ Default is to call passInput().
+ """
+ return self.passInput(name)
 def errorCheck(self, name):
 """Check for an error returned in the variable.
 
@@ -172,7 +180,7 @@
 self.substitute = substitute
 self.typeName = None # Don't show this argument in __doc__ string
 
- def declare(self, name):
+ def declare(self, name, reference=False):
 pass
 
 def getargsFormat(self):
@@ -236,6 +244,25 @@
 
 def mkvalueArgs(self, name):
 return "%s, %s" % (self.new, name)
+ 
+class OpaqueByRefType(OpaqueType):
+ """An opaque object type, passed by reference.
+
+ Instantiate with the type name, and optionally an object type name whose
+ New/Convert functions will be used.
+ """
+ 
+ def passInput(self, name):
+ return name
+ 
+# def passOutput(self, name):
+# return name
+ 
+ def mkvalueFormat(self):
+ return "O"
+ 
+ def mkvalueArgs(self, name):
+ return "%s(%s)" % (self.new, name)
 
 class OpaqueByValueStructType(OpaqueByValueType):
 """Similar to OpaqueByValueType, but we also pass this to mkvalue by
Index: bgenVariable.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/bgen/bgen/bgenVariable.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- bgenVariable.py	19 Jan 2003 21:53:57 -0000	1.2
+++ bgenVariable.py	14 Jun 2005 21:32:51 -0000	1.3
@@ -13,7 +13,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
 
 class Variable:
 
@@ -39,7 +39,9 @@
 
 If it is "self", it is not declared.
 """
- if self.flags != SelfMode:
+ if self.flags == ReturnMode+RefMode:
+ self.type.declare(self.name, reference=True)
+ elif self.flags != SelfMode:
 self.type.declare(self.name)
 
 def getargsFormat(self):
@@ -62,6 +64,8 @@
 """
 if self.mode == InMode:
 return self.type.passInput(self.name)
+ if self.mode & RefMode:
+ return self.type.passReference(self.name)
 if self.mode in (OutMode, InOutMode):
 return self.type.passOutput(self.name)
 # XXX Shouldn't get here
Index: scantools.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/bgen/bgen/scantools.py,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- scantools.py	18 Jul 2004 06:02:01 -0000	1.35
+++ scantools.py	14 Jun 2005 21:32:51 -0000	1.36
@@ -466,6 +466,7 @@
 if self.debug:
 self.report("* WHOLE LINE: %r" % (raw,))
 self.processrawspec(raw)
+ return raw
 
 def processrawspec(self, raw):
 match = self.whole.search(raw)
@@ -478,8 +479,8 @@
 self.report("(but type matched)")
 return
 type, name, args = match.group('type', 'name', 'args')
- type = re.sub("\*", " ptr", type)
- type = re.sub("[ \t]+", "_", type)
+ type = self.pythonizename(type)
+ name = self.pythonizename(name)
 if name in self.alreadydone:
 self.report("Name has already been defined: %r", name)
 return
@@ -500,6 +501,12 @@
 self.alreadydone.append(name)
 self.generate(type, name, arglist)
 
+ def pythonizename(self, name):
+ name = re.sub("\*", " ptr", name)
+ name = name.strip()
+ name = re.sub("[ \t]+", "_", name)
+ return name
+
 def extractarglist(self, args):
 args = args.strip()
 if not args or args == "void":
@@ -522,9 +529,7 @@
 if array:
 # array matches an optional [] after the argument name
 type = type + " ptr "
- type = re.sub("\*", " ptr ", type)
- type = type.strip()
- type = re.sub("[ \t]+", "_", type)
+ type = self.pythonizename(type)
 return self.modifyarg(type, name, mode)
 
 def modifyarg(self, type, name, mode):
@@ -590,6 +595,7 @@
 def generate(self, type, name, arglist):
 self.typeused(type, 'return')
 classname, listname = self.destination(type, 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))
 for atype, aname, amode in arglist:


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /