Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Array access detection] Refactor function that collects candidates. #48

Open
mari-mari opened this issue Jan 31, 2022 · 0 comments
Open
Labels
feature-request New feature or request priority-low Low priority issue refactoring Refactroring request

Comments

@mari-mari
Copy link
Collaborator

Proposal

Pure free-time refactoring issue, originated from some merge request review. One could make the function that collects candidates prettier.

Approach

Something like this could potentially work:

if candidate := self.get_array_access_candidate(candidate):
    self._candidates[base].append(candidate)
    self._update_candidate_offsets(base, offset_class, element_size)

def get_array_access_candidate(candidate) -> Optional[Candidate]:
  operand = candidate.operand
  if not self._is_addition(operand):
    return None
  base, offset = self._get_base_and_offset(operand)
  if not (base and offset):
    return None
  offset_class, index, element_size = self._parse_offset(offset)
  return Candidate(candidate, index, base)

Should be tested, if it works like this.

@mari-mari mari-mari added feature-request New feature or request priority-low Low priority issue refactoring Refactroring request labels Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request priority-low Low priority issue refactoring Refactroring request
Projects
None yet
Development

No branches or pull requests

1 participant