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

Skip to content

Commit ededa90

Browse files
committed
- Added support for inherent pointer types (typedefs of arrays)
- Added a debug class variable to enable parser debugging.
1 parent da70485 commit ededa90

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Tools/bgen/bgen/scantools.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333
class Scanner:
3434

35+
# Set to 1 in subclass to debug your scanner patterns.
36+
debug = 0
37+
3538
def __init__(self, input = None, output = None, defsoutput = None):
3639
self.initsilent()
3740
self.initblacklists()
@@ -119,6 +122,7 @@ def makegreylist(self):
119122

120123
def initrepairinstructions(self):
121124
self.repairinstructions = self.makerepairinstructions()
125+
self.inherentpointertypes = self.makeinherentpointertypes()
122126

123127
def makerepairinstructions(self):
124128
"""Parse the repair file into repair instructions.
@@ -210,6 +214,9 @@ def makerepairinstructions(self):
210214
replacements.append(replacement)
211215
list.append((fpat, patterns, replacements))
212216
return list
217+
218+
def makeinherentpointertypes(self):
219+
return []
213220

214221
def openrepairfile(self, filename = "REPAIR"):
215222
try:
@@ -395,14 +402,24 @@ def scan(self):
395402
while 1:
396403
try: line = self.getline()
397404
except EOFError: break
405+
if self.debug:
406+
self.report("LINE: %s" % `line`)
398407
if self.comment1.match(line) >= 0:
399408
line = self.comment1.group('rest')
409+
if self.debug:
410+
self.report("\tafter comment1: %s" % `line`)
400411
while self.comment2.match(line) >= 0:
401412
line = self.comment2.group('rest1')+self.comment2.group('rest2')
413+
if self.debug:
414+
self.report("\tafter comment2: %s" % `line`)
402415
if self.defsfile and self.sym.match(line) >= 0:
416+
if self.debug:
417+
self.report("\tmatches sym.")
403418
self.dosymdef()
404419
continue
405420
if self.head.match(line) >= 0:
421+
if self.debug:
422+
self.report("\tmatches head.")
406423
self.dofuncspec()
407424
continue
408425
except EOFError:
@@ -411,6 +428,8 @@ def scan(self):
411428

412429
def dosymdef(self):
413430
name, defn = self.sym.group('name', 'defn')
431+
if self.debug:
432+
self.report("\tsym: name=%s, defn=%s" % (`name`, `defn`))
414433
if not name in self.blacklistnames:
415434
self.defsfile.write("%s = %s\n" % (name, defn))
416435
else:
@@ -421,16 +440,29 @@ def dofuncspec(self):
421440
raw = self.line
422441
while self.tail.search(raw) < 0:
423442
line = self.getline()
443+
if self.debug:
444+
self.report("* CONTINUATION LINE: %s" % `line`)
424445
if self.comment1.match(line) >= 0:
425446
line = self.comment1.group('rest')
447+
if self.debug:
448+
self.report("\tafter comment1: %s" % `line`)
426449
while self.comment2.match(line) >= 0:
427450
line = self.comment2.group('rest1')+self.comment2.group('rest2')
451+
if self.debug:
452+
self.report("\tafter comment1: %s" % `line`)
428453
raw = raw + line
454+
if self.debug:
455+
self.report("* WHOLE LINE: %s" % `raw`)
429456
self.processrawspec(raw)
430457

431458
def processrawspec(self, raw):
432459
if self.whole.search(raw) < 0:
433460
self.report("Bad raw spec: %s", `raw`)
461+
if self.debug:
462+
if self.type.search(raw) < 0:
463+
self.report("(Type already doesn't match)")
464+
else:
465+
self.report("(Type matched: %s)" % `self.type.group('type')`)
434466
return
435467
type, name, args = self.whole.group('type', 'name', 'args')
436468
type = regsub.gsub("\*", " ptr", type)
@@ -486,6 +518,8 @@ def modifyarg(self, type, name, mode):
486518
elif type[-4:] == "_ptr":
487519
type = type[:-4]
488520
mode = "OutMode"
521+
elif type in self.inherentpointertypes:
522+
mode = "OutMode"
489523
if type[-4:] == "_far":
490524
type = type[:-4]
491525
return type, name, mode

0 commit comments

Comments
 (0)