MCPcopy Create free account
hub / github.com/CheckPointSW/Karta / addHints

Method addHints

src/function_context.py:886–933  ·  view source on GitHub ↗

Add a set of (source) match hints to help us filter our existing hints. Args: hint (collection): a collection of (source) function potential matches (containing FunctionContext instances) is_call (bool): True iff call hints, otherwise xref hints

(self, hints, is_call)

Source from the content-addressed store, hash-verified

884 return (self.call_hints is not None and len(self.call_hints) > 0) or len(self.xref_hints) > 0
885
886 def addHints(self, hints, is_call):
887 """Add a set of (source) match hints to help us filter our existing hints.
888
889 Args:
890 hint (collection): a collection of (source) function potential matches (containing FunctionContext instances)
891 is_call (bool): True iff call hints, otherwise xref hints
892 """
893 new_hints = [x for x in hints if x.isValidCandidate(self)]
894
895 # Saw a collision candidate, after was already matched to one of his friends
896 if self.matched():
897 # Only candidate hints can reach this point, and they all should be matched
898 # Later on, the matching round will declare them as matched
899 if len(new_hints) > 0:
900 self.call_hints = new_hints
901 self.collision_map[new_hints[0].hash].update(new_hints)
902 return
903
904 # normal case
905 if is_call:
906 if self.call_hints is None:
907 self.call_hints = set(new_hints)
908 for hint in new_hints:
909 hint.addFollower(self)
910 else:
911 # linker optimizations edge case
912 new_hashes = [x.hash for x in new_hints]
913 cur_hashes = set(x.hash for x in self.call_hints)
914 for dropped in [x for x in self.call_hints if x.hash not in new_hashes]:
915 dropped.removeFollower(self)
916 # check for a possibile collision option
917 context_intersection = self.call_hints & set(new_hints)
918 context_union = self.call_hints | set(new_hints)
919 hashes_intersection = cur_hashes & set(new_hashes)
920 remaining_hashes = [x.hash for x in context_intersection]
921 if len(hashes_intersection) > len(remaining_hashes):
922 collision_candidates = []
923 for collision_hash in set(hashes_intersection) - set(remaining_hashes):
924 cur_collision_candidates = [x for x in context_union if x.hash == collision_hash]
925 self.collision_map[collision_hash].update(cur_collision_candidates)
926 collision_candidates += cur_collision_candidates
927 self.call_hints = context_intersection | set(collision_candidates)
928 else:
929 self.call_hints = self.call_hints & set(new_hints)
930 else:
931 self.xref_hints += new_hints
932 for hint in new_hints:
933 hint.addFollower(self)
934
935 def removeHint(self, src_ctx, clear=True):
936 """Remove a (source) hint from our possible candidates (he was probably matched without us).

Callers 2

updateHintsMethod · 0.45
matchFilesMethod · 0.45

Calls 4

isValidCandidateMethod · 0.80
addFollowerMethod · 0.80
removeFollowerMethod · 0.80
matchedMethod · 0.45

Tested by

no test coverage detected