1 #!/usr/bin/env python 2 3 """ 4 Error classes. 5 6 Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Paul Boddie <paul@boddie.org.uk> 7 8 This program is free software; you can redistribute it and/or modify it under 9 the terms of the GNU General Public License as published by the Free Software 10 Foundation; either version 3 of the License, or (at your option) any later 11 version. 12 13 This program is distributed in the hope that it will be useful, but WITHOUT 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 details. 17 18 You should have received a copy of the GNU General Public License along with 19 this program. If not, see <http://www.gnu.org/licenses/>. 20 """ 21 22 class ProcessingError(Exception): 23 24 "A processing error." 25 26 pass 27 28 class TableError(ProcessingError): 29 30 "An error occurring during access to a lookup table." 31 32 pass 33 34 class TableGenerationError(ProcessingError): 35 36 "An error occurring when generating a lookup table." 37 38 pass 39 40 class NodeProcessingError(ProcessingError): 41 42 "A processing error associated with a particular program node." 43 44 def __init__(self, message): 45 self.message = message 46 self.unit_name = None 47 self.astnode = None 48 49 def get_lineno(self, node): 50 if node is None: 51 return None 52 53 lineno = node.lineno 54 if lineno is not None: 55 return lineno 56 else: 57 for child in node.getChildNodes(): 58 lineno = self.get_lineno(child) 59 if lineno is not None: 60 return lineno 61 return None 62 63 def __repr__(self): 64 return "Error in %r at line %r: %s" % (self.unit_name, self.get_lineno(self.astnode), self.message) 65 66 def __str__(self): 67 return repr(self) 68 69 class InspectError(NodeProcessingError): 70 71 "An error during the module inspection process." 72 73 pass 74 75 class TranslateError(NodeProcessingError): 76 77 "An error during the module translation process." 78 79 pass 80 81 class TranslationNotImplementedError(TranslateError): 82 83 "An error caused by a node not being supported in translation." 84 85 pass 86 87 # vim: tabstop=4 expandtab shiftwidth=4