# HG changeset patch # User Paul Boddie # Date 1382742288 -7200 # Node ID 4c28c198f424064f129b14e5b15cc210a5f70eda # Parent e57bf0bb98f1a42829055dc9cc76b0ad676d21ce Separated the definition of "path-sensitive" values from general namespace access. diff -r e57bf0bb98f1 -r 4c28c198f424 micropython/branch.py --- a/micropython/branch.py Fri Oct 25 19:41:48 2013 +0200 +++ b/micropython/branch.py Sat Oct 26 01:04:48 2013 +0200 @@ -1,7 +1,7 @@ #!/usr/bin/env python """ -Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Paul Boddie +Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -328,7 +328,7 @@ return users[name] - def _define_attribute_user(self, node): + def _define_attribute_user(self, node, value): """ Define 'node' as the user of attributes, indicating the point where the @@ -336,11 +336,14 @@ """ name = node.name - self._define_attribute_user_for_name(node, name) + self._define_attribute_user_for_name(node, name, value) + + def _define_attribute_user_for_name(self, node, name, value=None): - def _define_attribute_user_for_name(self, node, name): - - "Define 'node' as the user of attributes for the given 'name'." + """ + Define 'node' as the user of attributes for the given 'name', having the + specified 'value'. + """ users = self.attribute_users[-1] @@ -350,19 +353,26 @@ # Record the attribute combinations for the name. - self._init_attribute_user_for_name(node, name) + self._init_attribute_user_for_name(node, name, value) # Remember this user. self.all_attribute_users.add(node) - def _init_attribute_user_for_name(self, node, name): + def _init_attribute_user_for_name(self, node, name, value=None): "Make sure that 'node' is initialised for 'name'." self._init_attribute_user(node) node._attrnames[name] = None + # Assigned values for names. + + if value: + if node._values is None: + node._values = {} + node._values[name] = value + def _init_attribute_user(self, node): # Attribute usage for names. diff -r e57bf0bb98f1 -r 4c28c198f424 micropython/data.py --- a/micropython/data.py Fri Oct 25 19:41:48 2013 +0200 +++ b/micropython/data.py Sat Oct 26 01:04:48 2013 +0200 @@ -259,15 +259,6 @@ self.namespace[name] = Attr(None, self, name) attr = self.namespace[name] - # Also direct assignments to individual name users. - - users = self.attribute_users[-1] - - if users.has_key(name): - for user in users[name]: - user._values = user._values or {} - user._values[name] = attr_or_value - # Update the attribute records. self._set_using_attr(attr, attr_or_value, single_assignment) @@ -1440,13 +1431,13 @@ self.importer.use_name(attrname, self.full_name(), value) return [] - def _define_attribute_user_for_name(self, node, name): + def _define_attribute_user_for_name(self, node, name, value=None): if self.can_use_name_for_usage(name): - NamespaceDict._define_attribute_user_for_name(self, node, name) + NamespaceDict._define_attribute_user_for_name(self, node, name, value) - def _init_attribute_user_for_name(self, node, name): + def _init_attribute_user_for_name(self, node, name, value=None): if self.can_use_name_for_usage(name): - NamespaceDict._init_attribute_user_for_name(self, node, name) + NamespaceDict._init_attribute_user_for_name(self, node, name, value) def _define_attribute_accessor(self, name, attrname, node, value): if self.can_use_name_for_usage(name): diff -r e57bf0bb98f1 -r 4c28c198f424 micropython/inspect.py --- a/micropython/inspect.py Fri Oct 25 19:41:48 2013 +0200 +++ b/micropython/inspect.py Sat Oct 26 01:04:48 2013 +0200 @@ -566,14 +566,14 @@ def resume_abandoned_branches(self): self.get_namespace()._resume_abandoned_branches() - def define_attribute_user(self, node): + def define_attribute_user(self, node, value): """ Define 'node' as the user of attributes, indicating the point where the user is defined. """ - self.get_namespace()._define_attribute_user(node) + self.get_namespace()._define_attribute_user(node, value) def use_attribute(self, name, attrname, value=None): @@ -919,7 +919,7 @@ self._visitAssName(node) def _visitAssName(self, node): - self.define_attribute_user(node) + self.define_attribute_user(node, self.expr) self.store(node.name, self.expr) # Ensure the presence of the given name in this namespace. @@ -1034,7 +1034,7 @@ self.namespaces.pop() self.store(node.name, cls, static_def=True) - self.define_attribute_user(node) + self.define_attribute_user(node, cls) self.add_object(cls) # Process the class body in its own namespace.