# HG changeset patch # User Paul Boddie # Date 1472570715 -7200 # Node ID d40bc8b5118e28c00af2c912022b6a8abb7b7b9a # Parent 5366b587e3facfb210dff22f937b8612e066c356 Removed name inheritance from outer scopes. diff -r 5366b587e3fa -r d40bc8b5118e branching.py --- a/branching.py Tue Aug 30 16:51:10 2016 +0200 +++ b/branching.py Tue Aug 30 17:25:15 2016 +0200 @@ -180,10 +180,6 @@ self.loop_branches = [] - # Inherited usage. - - self.inherited = None - # Structure assembly methods. def new_branchpoint(self, loop_node=False): @@ -452,63 +448,6 @@ for branch in branches: branch.contributors.add(contributor) - # Namespace methods. - - def inherit_branches(self, tracker, names): - - """ - Propagate branches from the given 'tracker' excluding those associated - with 'names'. - """ - - # For each inherited name, create a branch connected to the inherited - # branches. - - self.inherited = {} - - for name, branches in tracker.attribute_branches[-1].items(): - - # Do not inherit any listed names (typically parameters) or any - # special names. - - if name in names or name.startswith("$"): - continue - - # Make a tentative assignment for the name. - - contributor = Branch([name], True) - init_item(self.assignments, name, list) - self.assignments[name].append(contributor) - - # Connect the inherited branch to the new one. - - for branch in branches: - init_item(contributor.suppliers, name, set) - contributor.suppliers[name].add(branch) - branch.contributors.add(contributor) - - # Record the inherited branch. - - self.inherited[name] = [contributor] - - self.attribute_branches[-1].update(self.inherited) - - def disconnect_name(self, name): - - "Disconnect inherited branches for 'name'." - - if not self.inherited or not self.inherited.has_key(name): - return - - # Remove the new branch from the inherited branches for the name. - - for contributor in self.inherited[name]: - for supplier in contributor.suppliers[name]: - supplier.contributors.remove(contributor) - del contributor.suppliers[name] - - del self.inherited[name] - # Attribute usage methods. def tracking_name(self, name): @@ -518,13 +457,11 @@ if it is. """ - return self.assignments.has_key(name) and \ - (not self.inherited or not self.inherited.has_key(name)) and \ - self.have_name(name) + return self.assignments.has_key(name) and self.have_name(name) def have_name(self, name): - "Return whether 'name' is known, perhaps having been inherited." + "Return whether 'name' is known." return self.attribute_branches[-1].get(name) @@ -539,8 +476,6 @@ branch = Branch(names, True, values) for name in names: - self.disconnect_name(name) - branches[name] = [branch] init_item(self.assignments, name, list) self.assignments[name].append(branch) diff -r 5366b587e3fa -r d40bc8b5118e inspector.py --- a/inspector.py Tue Aug 30 16:51:10 2016 +0200 +++ b/inspector.py Tue Aug 30 17:25:15 2016 +0200 @@ -67,11 +67,6 @@ self.in_conditional = False self.global_attr_accesses = {} - # Nested scope handling. - - self.parent_function = None - self.propagated_names = {} - # Usage tracking. self.trackers = [] @@ -917,9 +912,6 @@ # Reset conditional tracking to focus on the function contents. - parent_function = self.parent_function - self.parent_function = self.in_function and self.get_namespace_path() or None - in_conditional = self.in_conditional self.in_conditional = False @@ -931,34 +923,19 @@ # Track attribute usage within the namespace. path = self.get_namespace_path() - init_item(self.propagated_names, path, set) self.start_tracking(locals) self.process_structure_node(n.code) self.stop_tracking() - # Propagate names from parent scopes. - - for local in self.propagated_names[path]: - if not local in argnames and self.trackers[-1].have_name(local): - argnames.append(local) - defaults.append((local, Reference(""))) - self.set_function_local(local) - - # Exit to the parent and note propagated names. + # Exit to the parent. self.exit_namespace() - parent = self.get_namespace_path() - if self.propagated_names.has_key(parent): - for local in self.propagated_names[path]: - self.propagated_names[parent].add(local) - # Update flags. self.in_function = in_function self.in_conditional = in_conditional - self.parent_function = parent_function # Define the function using the appropriate name. @@ -1170,14 +1147,7 @@ branches = tracker.tracking_name(n.name) - # Find names inherited from a parent scope. - - if not branches and self.parent_function: - branches = tracker.have_name(n.name) - if branches: - self.propagate_name(n.name) - - # Local or inherited name. + # Local name. if branches: self.record_branches_for_access(branches, n.name, None) @@ -1340,12 +1310,6 @@ tracker = BranchTracker() self.trackers.append(tracker) - # For functions created from expressions or for functions within - # functions, propagate usage to the new namespace. - - if self.parent_function: - tracker.inherit_branches(parent, names) - # Record the given names established as new branches. tracker.assign_names(names) @@ -1387,13 +1351,6 @@ self.attr_usage[self.name] = tracker.get_all_usage() self.name_initialisers[self.name] = tracker.get_all_values() - def propagate_name(self, name): - - "Propagate the given 'name' into the current namespace." - - path = self.get_namespace_path() - self.propagated_names[path].add(name) - def record_assignments_for_access(self, tracker): """