comparison python/ppci/errors.py @ 295:917eab04b8b7

Added disasm
author Windel Bouwman
date Thu, 28 Nov 2013 21:10:32 +0100
parents 6aa721e7b10b
children 9417caea2eb3
comparison
equal deleted inserted replaced
294:e89cca5779b0 295:917eab04b8b7
43 del self.diags[:] 43 del self.diags[:]
44 self.sources.clear() 44 self.sources.clear()
45 45
46 def printErrors(self): 46 def printErrors(self):
47 if len(self.diags) > 0: 47 if len(self.diags) > 0:
48 print('==============')
49 print('{0} Errors'.format(len(self.diags))) 48 print('{0} Errors'.format(len(self.diags)))
50 for d in self.diags: 49 for d in self.diags:
51 print('==============')
52 self.printError(d) 50 self.printError(d)
53 print('==============')
54 51
55 def printError(self, e): 52 def printError(self, e):
56 def printLine(row, txt): 53 def printLine(row, txt):
57 print(str(row)+':'+txt) 54 print(str(row)+':'+txt)
58 print(type(e), e, e.msg) 55 print('==============')
59 if not e.loc: 56 if not e.loc:
60 print('Error: {0}'.format(e)) 57 print('Error: {0}'.format(e))
61 else: 58 else:
62 if e.loc.filename not in self.sources: 59 if e.loc.filename not in self.sources:
63 print('Error: {0}'.format(e)) 60 print('Error: {0}'.format(e))
64 return 61 return
62 print("File: {}".format(e.loc.filename))
65 source = self.sources[e.loc.filename] 63 source = self.sources[e.loc.filename]
66 lines = source.split('\n') 64 lines = source.split('\n')
67 ro, co = e.row, e.col 65 ro, co = e.row, e.col
68 prerow = ro - 2 66 prerow = ro - 2
69 if prerow < 1: 67 if prerow < 1:
79 printLine(ro, lines[ro-1]) 77 printLine(ro, lines[ro-1])
80 print(' '*(len(str(ro)+':')+co-1) + '^ Error: {0}'.format(e.msg)) 78 print(' '*(len(str(ro)+':')+co-1) + '^ Error: {0}'.format(e.msg))
81 # print trailing source line: 79 # print trailing source line:
82 for r in range(ro+1, afterrow+1): 80 for r in range(ro+1, afterrow+1):
83 printLine(r, lines[r-1]) 81 printLine(r, lines[r-1])
82 print('==============')