1.1 --- a/branching.py Tue Aug 30 16:51:10 2016 +0200
1.2 +++ b/branching.py Tue Aug 30 17:25:15 2016 +0200
1.3 @@ -180,10 +180,6 @@
1.4
1.5 self.loop_branches = []
1.6
1.7 - # Inherited usage.
1.8 -
1.9 - self.inherited = None
1.10 -
1.11 # Structure assembly methods.
1.12
1.13 def new_branchpoint(self, loop_node=False):
1.14 @@ -452,63 +448,6 @@
1.15 for branch in branches:
1.16 branch.contributors.add(contributor)
1.17
1.18 - # Namespace methods.
1.19 -
1.20 - def inherit_branches(self, tracker, names):
1.21 -
1.22 - """
1.23 - Propagate branches from the given 'tracker' excluding those associated
1.24 - with 'names'.
1.25 - """
1.26 -
1.27 - # For each inherited name, create a branch connected to the inherited
1.28 - # branches.
1.29 -
1.30 - self.inherited = {}
1.31 -
1.32 - for name, branches in tracker.attribute_branches[-1].items():
1.33 -
1.34 - # Do not inherit any listed names (typically parameters) or any
1.35 - # special names.
1.36 -
1.37 - if name in names or name.startswith("$"):
1.38 - continue
1.39 -
1.40 - # Make a tentative assignment for the name.
1.41 -
1.42 - contributor = Branch([name], True)
1.43 - init_item(self.assignments, name, list)
1.44 - self.assignments[name].append(contributor)
1.45 -
1.46 - # Connect the inherited branch to the new one.
1.47 -
1.48 - for branch in branches:
1.49 - init_item(contributor.suppliers, name, set)
1.50 - contributor.suppliers[name].add(branch)
1.51 - branch.contributors.add(contributor)
1.52 -
1.53 - # Record the inherited branch.
1.54 -
1.55 - self.inherited[name] = [contributor]
1.56 -
1.57 - self.attribute_branches[-1].update(self.inherited)
1.58 -
1.59 - def disconnect_name(self, name):
1.60 -
1.61 - "Disconnect inherited branches for 'name'."
1.62 -
1.63 - if not self.inherited or not self.inherited.has_key(name):
1.64 - return
1.65 -
1.66 - # Remove the new branch from the inherited branches for the name.
1.67 -
1.68 - for contributor in self.inherited[name]:
1.69 - for supplier in contributor.suppliers[name]:
1.70 - supplier.contributors.remove(contributor)
1.71 - del contributor.suppliers[name]
1.72 -
1.73 - del self.inherited[name]
1.74 -
1.75 # Attribute usage methods.
1.76
1.77 def tracking_name(self, name):
1.78 @@ -518,13 +457,11 @@
1.79 if it is.
1.80 """
1.81
1.82 - return self.assignments.has_key(name) and \
1.83 - (not self.inherited or not self.inherited.has_key(name)) and \
1.84 - self.have_name(name)
1.85 + return self.assignments.has_key(name) and self.have_name(name)
1.86
1.87 def have_name(self, name):
1.88
1.89 - "Return whether 'name' is known, perhaps having been inherited."
1.90 + "Return whether 'name' is known."
1.91
1.92 return self.attribute_branches[-1].get(name)
1.93
1.94 @@ -539,8 +476,6 @@
1.95 branch = Branch(names, True, values)
1.96
1.97 for name in names:
1.98 - self.disconnect_name(name)
1.99 -
1.100 branches[name] = [branch]
1.101 init_item(self.assignments, name, list)
1.102 self.assignments[name].append(branch)
2.1 --- a/inspector.py Tue Aug 30 16:51:10 2016 +0200
2.2 +++ b/inspector.py Tue Aug 30 17:25:15 2016 +0200
2.3 @@ -67,11 +67,6 @@
2.4 self.in_conditional = False
2.5 self.global_attr_accesses = {}
2.6
2.7 - # Nested scope handling.
2.8 -
2.9 - self.parent_function = None
2.10 - self.propagated_names = {}
2.11 -
2.12 # Usage tracking.
2.13
2.14 self.trackers = []
2.15 @@ -917,9 +912,6 @@
2.16
2.17 # Reset conditional tracking to focus on the function contents.
2.18
2.19 - parent_function = self.parent_function
2.20 - self.parent_function = self.in_function and self.get_namespace_path() or None
2.21 -
2.22 in_conditional = self.in_conditional
2.23 self.in_conditional = False
2.24
2.25 @@ -931,34 +923,19 @@
2.26 # Track attribute usage within the namespace.
2.27
2.28 path = self.get_namespace_path()
2.29 - init_item(self.propagated_names, path, set)
2.30
2.31 self.start_tracking(locals)
2.32 self.process_structure_node(n.code)
2.33 self.stop_tracking()
2.34
2.35 - # Propagate names from parent scopes.
2.36 -
2.37 - for local in self.propagated_names[path]:
2.38 - if not local in argnames and self.trackers[-1].have_name(local):
2.39 - argnames.append(local)
2.40 - defaults.append((local, Reference("<var>")))
2.41 - self.set_function_local(local)
2.42 -
2.43 - # Exit to the parent and note propagated names.
2.44 + # Exit to the parent.
2.45
2.46 self.exit_namespace()
2.47
2.48 - parent = self.get_namespace_path()
2.49 - if self.propagated_names.has_key(parent):
2.50 - for local in self.propagated_names[path]:
2.51 - self.propagated_names[parent].add(local)
2.52 -
2.53 # Update flags.
2.54
2.55 self.in_function = in_function
2.56 self.in_conditional = in_conditional
2.57 - self.parent_function = parent_function
2.58
2.59 # Define the function using the appropriate name.
2.60
2.61 @@ -1170,14 +1147,7 @@
2.62
2.63 branches = tracker.tracking_name(n.name)
2.64
2.65 - # Find names inherited from a parent scope.
2.66 -
2.67 - if not branches and self.parent_function:
2.68 - branches = tracker.have_name(n.name)
2.69 - if branches:
2.70 - self.propagate_name(n.name)
2.71 -
2.72 - # Local or inherited name.
2.73 + # Local name.
2.74
2.75 if branches:
2.76 self.record_branches_for_access(branches, n.name, None)
2.77 @@ -1340,12 +1310,6 @@
2.78 tracker = BranchTracker()
2.79 self.trackers.append(tracker)
2.80
2.81 - # For functions created from expressions or for functions within
2.82 - # functions, propagate usage to the new namespace.
2.83 -
2.84 - if self.parent_function:
2.85 - tracker.inherit_branches(parent, names)
2.86 -
2.87 # Record the given names established as new branches.
2.88
2.89 tracker.assign_names(names)
2.90 @@ -1387,13 +1351,6 @@
2.91 self.attr_usage[self.name] = tracker.get_all_usage()
2.92 self.name_initialisers[self.name] = tracker.get_all_values()
2.93
2.94 - def propagate_name(self, name):
2.95 -
2.96 - "Propagate the given 'name' into the current namespace."
2.97 -
2.98 - path = self.get_namespace_path()
2.99 - self.propagated_names[path].add(name)
2.100 -
2.101 def record_assignments_for_access(self, tracker):
2.102
2.103 """