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

Skip to content

Commit f158887

Browse files
committed
Two patches from Jack Jansen:
Three bgen mods: - support for FSSpecs passed-by-value and points-passed-by-reference added. - strip single-line comments when parsing header files - if a definition is blacklisted _do_ output it, but in comment
1 parent 6d7e47b commit f158887

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

Tools/bgen/bgen/macsupport.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ScriptCode = Type("ScriptCode", "h")
1616
Size = Type("Size", "l")
1717
Style = Type("Style", "b")
18-
StyleParameter = Type("StyleParameter", "h")
18+
StyleParameter = Type("Style", "h")
1919
CharParameter = Type("CharParameter", "h")
2020
TextEncoding = Type("TextEncoding", "l")
2121

@@ -31,7 +31,7 @@
3131
Str255 = OpaqueArrayType("Str255", "PyMac_BuildStr255", "PyMac_GetStr255")
3232

3333
# File System Specifications
34-
FSSpec_ptr = OpaqueType("FSSpec", "PyMac_BuildFSSpec", "PyMac_GetFSSpec")
34+
FSSpec = FSSpec_ptr = OpaqueType("FSSpec", "PyMac_BuildFSSpec", "PyMac_GetFSSpec")
3535

3636
# OSType and ResType: 4-byte character strings
3737
def OSTypeType(typename):
@@ -66,6 +66,7 @@ def OSTypeType(typename):
6666
# Quickdraw data types
6767
Rect = Rect_ptr = OpaqueType("Rect", "PyMac_BuildRect", "PyMac_GetRect")
6868
Point = OpaqueByValueType("Point", "PyMac_BuildPoint", "PyMac_GetPoint")
69+
Point_ptr = OpaqueType("Point", "PyMac_BuildPoint", "PyMac_GetPoint")
6970

7071
# Event records
7172
EventRecord = OpaqueType("EventRecord", "PyMac_BuildEventRecord", "PyMac_GetEventRecord")
@@ -84,7 +85,6 @@ def errorCheck(self, name):
8485
# Various buffer types
8586

8687
InBuffer = VarInputBufferType('char', 'long', 'l') # (buf, len)
87-
OptionalInBuffer = OptionalVarInputBufferType('char', 'long', 'l') # (buf, len)
8888

8989
InOutBuffer = HeapInputOutputBufferType('char', 'long', 'l') # (inbuf, outbuf, len)
9090
VarInOutBuffer = VarHeapInputOutputBufferType('char', 'long', 'l') # (inbuf, outbuf, &len)
@@ -151,9 +151,9 @@ def errorCheck(self, name):
151151
# This requires that the OSErr type (defined above) has a non-trivial
152152
# errorCheck method.
153153
class OSErrMixIn:
154-
"Mix-in class to treat OSErr/OSStatus return values special"
154+
"Mix-in class to treat OSErr return values special"
155155
def makereturnvar(self):
156-
if self.returntype.__class__ == OSErrType:
156+
if self.returntype is OSErr:
157157
return Variable(self.returntype, "_err", ErrorMode)
158158
else:
159159
return Variable(self.returntype, "_rv", OutMode)

Tools/bgen/bgen/scantools.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,13 @@ def initpatterns(self):
234234
self.args_pat = "(\(<args>\([^(;=)]+\|([^(;=)]*)\)*\))"
235235
self.whole_pat = self.type_pat + self.name_pat + self.args_pat
236236
# self.sym_pat = "^[ \t]*\(<name>[a-zA-Z0-9_]+\)[ \t]*=" + \
237-
# "[ \t]*\(<defn>[-0-9'\"][^\t\n,;}]*\),?"
237+
# "[ \t]*\(<defn>[-0-9'\"(][^\t\n,;}]*\),?"
238238
self.sym_pat = "^[ \t]*\(<name>[a-zA-Z0-9_]+\)[ \t]*=" + \
239-
"[ \t]*\(<defn>[-0-9_a-zA-Z'\"][^\t\n,;}]*\),?"
239+
"[ \t]*\(<defn>[-0-9_a-zA-Z'\"(][^\t\n,;}]*\),?"
240240
self.asplit_pat = "^\(<type>.*[^a-zA-Z0-9_]\)\(<name>[a-zA-Z0-9_]+\)$"
241+
self.comment1_pat = "\(<rest>.*\)//.*"
242+
# note that the next pattern only removes comments that are wholly within one line
243+
self.comment2_pat = "\(<rest>.*\)/\*.*\*/"
241244

242245
def compilepatterns(self):
243246
for name in dir(self):
@@ -372,6 +375,10 @@ def scan(self):
372375
while 1:
373376
try: line = self.getline()
374377
except EOFError: break
378+
if self.comment1.match(line) >= 0:
379+
line = self.comment1.group('rest')
380+
if self.comment2.match(line) >= 0:
381+
line = self.comment2.group('rest')
375382
if self.defsfile and self.sym.match(line) >= 0:
376383
self.dosymdef()
377384
continue
@@ -386,6 +393,8 @@ def dosymdef(self):
386393
name, defn = self.sym.group('name', 'defn')
387394
if not name in self.blacklistnames:
388395
self.defsfile.write("%s = %s\n" % (name, defn))
396+
else:
397+
self.defsfile.write("# %s = %s\n" % (name, defn))
389398

390399
def dofuncspec(self):
391400
raw = self.line

0 commit comments

Comments
 (0)