summaryrefslogtreecommitdiff
path: root/include_server/include_analyzer_memoizing_node.py
diff options
context:
space:
mode:
Diffstat (limited to 'include_server/include_analyzer_memoizing_node.py')
-rwxr-xr-xinclude_server/include_analyzer_memoizing_node.py48
1 files changed, 24 insertions, 24 deletions
diff --git a/include_server/include_analyzer_memoizing_node.py b/include_server/include_analyzer_memoizing_node.py
index c7471f5..e870c1c 100755
--- a/include_server/include_analyzer_memoizing_node.py
+++ b/include_server/include_analyzer_memoizing_node.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python2.4
+#! /usr/bin/env python3
# Copyright 2007 Google Inc.
#
@@ -16,7 +16,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
-
+
"""A graph-based algorithm for memoizing include closure calculations."""
__author__ = "Nils Klarlund"
@@ -66,9 +66,9 @@ class UnionCache(object):
id_map: the set of frozen sets we have seen mapped to {1, 2, ..}
"""
self.members = {}
- self.cache = {}
+ self.cache = {}
self.id_map = {}
-
+
def SetId(self, members):
"""Memoize the frozenset of members and return set id."""
frozen = frozenset(members)
@@ -82,7 +82,7 @@ class UnionCache(object):
def Elements(self, set_id):
"""The frozenset corresponding to a set id."""
return self.members[set_id]
-
+
def Union(self, set1_id, set2_id):
"""Return the set id of the union of sets represented by set ids."""
try:
@@ -108,7 +108,7 @@ class SupportRecord(object):
def __init__(self, support_master):
"""Constructor.
Argument:
- support_master: a record for holding the reverse mapping from symbols to
+ support_master: a record for holding the reverse mapping from symbols to
support records that contain them.
Instance Variables:
support_master: see above
@@ -122,7 +122,7 @@ class SupportRecord(object):
self.valid = True
self.union_cache = support_master.union_cache
self.support_id = self.union_cache.SetId([])
-
+
def Update(self, set_id):
"""Augment the support record with the set represented by set_id.
"""
@@ -148,7 +148,7 @@ class SupportMaster(object):
A map symbol_to_records is maintained. For each symbol s
self.symbol_to_records[s] is the set of support records r whose support set
contains s."""
-
+
def __init__(self):
"""Constructor.
@@ -171,8 +171,8 @@ class SupportMaster(object):
if symbol in self.symbol_to_records:
for support_record in self.symbol_to_records[symbol]:
support_record.valid = False
-
-
+
+
class IncludeAnalyzerMemoizingNode(include_analyzer.IncludeAnalyzer):
"""A memoizing algorithm for include analysis based on a graph construction.
@@ -230,18 +230,18 @@ class IncludeAnalyzerMemoizingNode(include_analyzer.IncludeAnalyzer):
directory as understood above must also be taken into account.
In particular, we also use as keys pairs of the form:
-
+
(realpath index of resolved file, real path index of filedir).
This realpath-oriented memoization is not a frivolous attempt at optimization.
It is essential to avoiding infinite loops as in:
-
+
D/mem.h
D/../D/mem.h
D/../D/../D/mem.h
generated by an include of the form "#include ../D/mem.h" in file mem.h.
-
+
One would think that obviosly these prefixes denote the same location. But
they need not! For D of the first line could be a symbolic link to a real
directory dir1_D. And, the second D could be another symbolic link in
@@ -312,13 +312,13 @@ class IncludeAnalyzerMemoizingNode(include_analyzer.IncludeAnalyzer):
lhs, rhs = d_opt[0], "1"
elif len(d_opt) == 2:
[lhs, rhs] = d_opt
- parse_file.InsertMacroDefInTable(lhs, rhs, self.symbol_table,
+ parse_file.InsertMacroDefInTable(lhs, rhs, self.symbol_table,
self.support_master.InvalidateRecords)
else:
# Assume this is a syntax error of some sort.
pass
-
- # Construct or find the node for filepath_resolved.
+
+ # Construct or find the node for filepath_resolved.
node = self.FindNode(nodes_for_incl_config,
filepath_resolved_pair,
RESOLVED,
@@ -391,8 +391,8 @@ class IncludeAnalyzerMemoizingNode(include_analyzer.IncludeAnalyzer):
# file_dir_idx, because the filepath is resolved against file_dir.
key = (fp, resolution_mode, file_dir_idx)
if key in nodes_for_incl_config:
- # Is the support record valid?
- if nodes_for_incl_config[key][self.SUPPORT_RECORD].valid:
+ # Is the support record valid?
+ if nodes_for_incl_config[key][self.SUPPORT_RECORD].valid:
statistics.master_hit_counter += 1
return nodes_for_incl_config[key]
else:
@@ -408,7 +408,7 @@ class IncludeAnalyzerMemoizingNode(include_analyzer.IncludeAnalyzer):
# code below -- we don't want to reuse an earlier result.
[fp_real_idx, fp_resolved_pair, _, support_record] = node
Debug(DEBUG_TRACE,
- "Invalid record for translation unit: %s, file: %s",
+ "Invalid record for translation unit: %s, file: %s",
self.translation_unit, self._PrintableFilePath(fp))
else:
@@ -485,7 +485,7 @@ class IncludeAnalyzerMemoizingNode(include_analyzer.IncludeAnalyzer):
# Now, we've got the resolution: (search directory, include path).
assert (fp and fp_real_idx and fp_resolved_pair)
(searchdir_idx, includepath_idx) = fp_resolved_pair
-
+
# We need the realpath index of the current file directory. That's because
# we are going to ask whether we have really visited this file, despite the
# failure above to recognize it using a possibly relative name. Here,
@@ -501,9 +501,9 @@ class IncludeAnalyzerMemoizingNode(include_analyzer.IncludeAnalyzer):
except KeyError:
(fp_dirname_idx, fp_dirname_real_idx) = (
self.dirname_cache.Lookup(currdir_idx,
- searchdir_idx,
+ searchdir_idx,
includepath_idx))
-
+
if resolution_mode != RESOLVED:
# See whether we know about filepath post-resolution.
if ((fp_real_idx, fp_dirname_real_idx) in nodes_for_incl_config
@@ -522,7 +522,7 @@ class IncludeAnalyzerMemoizingNode(include_analyzer.IncludeAnalyzer):
statistics.master_miss_counter += 1
# If we're revisiting because the support record was invalid, then it is
# time to set it.
- support_record.valid = True
+ support_record.valid = True
# Try to get the cached result of parsing file.
try:
@@ -573,7 +573,7 @@ class IncludeAnalyzerMemoizingNode(include_analyzer.IncludeAnalyzer):
self.quote_dirs, self.angle_dirs,
self.symbol_table))
for (fp_resolved_pair_, fp_real_idx_) in files:
- node_ = self.FindNode(nodes_for_incl_config,
+ node_ = self.FindNode(nodes_for_incl_config,
fp_resolved_pair_,
RESOLVED, None, fp_real_idx_)
if node_: