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