Skip to content

Commit

Permalink
ClangCountingConditions: Add more documentation
Browse files Browse the repository at this point in the history
See #554
  • Loading branch information
sils committed May 25, 2015
1 parent ce0f552 commit a9ac349
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bears/codeclone_detection/ClangCountingConditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ def _get_binop_operator(cursor):


def _stack_contains_operators(stack, operators):
"""
Checks if one of the given operators is within the stack.
:param stack: The stack holding a tuple holding the parent cursors
and the child number.
:param operators: A list of strings. E.g. ["+", "-"]
:return: True if the operator was found.
"""
for elem, child_num in stack:
if elem.kind in [CursorKind.BINARY_OPERATOR,
CursorKind.COMPOUND_ASSIGNMENT_OPERATOR]:
Expand All @@ -165,14 +173,29 @@ def _stack_contains_operators(stack, operators):


def in_sum(cursor, stack):
"""
A counting condition returning true if the variable is used in a sum
statement, i.e. within the operators +, - and their associated compound
operators.
"""
return _stack_contains_operators(stack, ['+', '-', '+=', '-='])


def in_product(cursor, stack):
"""
A counting condition returning true if the variable is used in a product
statement, i.e. within the operators *, /, % and their associated compound
operators.
"""
return _stack_contains_operators(stack, ['*', '/', '%', '*=', '/=', '%='])


def in_binary_operation(cursor, stack):
"""
A counting condition returning true if the variable is used in a binary
operation, i.e. within the operators |, & and their associated compound
operators.
"""
return _stack_contains_operators(stack, ['&', '|', '&=', '|='])


Expand Down

1 comment on commit a9ac349

@Udayan12167
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack.

Please sign in to comment.