# HG changeset patch # User Paul Boddie # Date 1352760942 -3600 # Node ID 258047e2cd793d63b0dd796824178002138236b0 # Parent a94153ef2e5a51be885d38f507634ca93c28be4f Added a get_unit method to support/fix generic AST dispatch error handling. diff -r a94153ef2e5a -r 258047e2cd79 micropython/ast.py --- a/micropython/ast.py Tue Nov 06 00:16:26 2012 +0100 +++ b/micropython/ast.py Mon Nov 12 23:55:42 2012 +0100 @@ -77,6 +77,9 @@ def __repr__(self): return "Translation(%r)" % self.module + def get_unit(self): + return self.unit + def get_module_code(self): """ diff -r a94153ef2e5a -r 258047e2cd79 micropython/common.py --- a/micropython/common.py Tue Nov 06 00:16:26 2012 +0100 +++ b/micropython/common.py Mon Nov 12 23:55:42 2012 +0100 @@ -53,13 +53,7 @@ except NodeProcessingError, exc: if exc.astnode is None: exc.astnode = node - - # NOTE: Should perhaps specialise the subclasses appropriately. - - if isinstance(self, (compiler.ast.Class, compiler.ast.Function, compiler.ast.Module)): - exc.unit_name = self.unit.full_name() - else: - exc.unit_name = self.full_name() + exc.unit_name = self.get_unit().full_name() raise def possible_accessor_types(self, node, defining_users=1): @@ -210,9 +204,9 @@ # Access and slicing. - "AssSlice" : "setslice", + "AssSlice" : "setslice", # Python 2.7 "Slice" : "getslice", - "AssSubscript" : "setitem", + "AssSubscript" : "setitem", # Python 2.7 "Subscript" : "getitem", } diff -r a94153ef2e5a -r 258047e2cd79 micropython/inspect.py --- a/micropython/inspect.py Tue Nov 06 00:16:26 2012 +0100 +++ b/micropython/inspect.py Mon Nov 12 23:55:42 2012 +0100 @@ -488,6 +488,8 @@ return (self.namespaces[-1:] or [self])[0] + get_unit = get_namespace # compatibility method for error handling + def use_name(self, name, node=None, value=None, ns=None): """ diff -r a94153ef2e5a -r 258047e2cd79 micropython/report.py --- a/micropython/report.py Tue Nov 06 00:16:26 2012 +0100 +++ b/micropython/report.py Mon Nov 12 23:55:42 2012 +0100 @@ -635,6 +635,9 @@ self.program.unknown_target_nodes = [] self.units = [] + def get_unit(self): + return self.units[-1] + def to_stream(self, stream): "Write the annotated code to the given 'stream'."