Skip to content

Commit

Permalink
ClangCountVectorCreator: Return line number too
Browse files Browse the repository at this point in the history
A bear will need the line number too to create the result appropriately.
  • Loading branch information
sils committed May 22, 2015
1 parent 7fa6598 commit c802734
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 3 additions & 1 deletion bears/codeclone_detection/ClangCountVectorCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def _get_vectors_for_cursor(self, cursor, filename):

if str(file) == str(filename) and self.is_function_declaration(cursor):
self._get_vector_for_function(cursor)
result = {self.get_identifier_name(cursor): self.count_vectors}

result = {(cursor.extent.start.line,
self.get_identifier_name(cursor)): self.count_vectors}
# Reset local states
self.count_vectors = {}
self.stack = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def setUp(self):

def test_empty_counting(self):
expected_results = {
"test()": {},
"main(int, char *)": {
(6, "test()"): {},
(12, "main(int, char *)"): {
"i": [],
"asd": [],
"t": [],
Expand All @@ -59,8 +59,8 @@ def check_cv_dict(self, actual, expected):

def test_counting(self):
expected_results = {
"test()": {},
"main(int, char *)": {
(6, "test()"): {},
(12, "main(int, char *)"): {
"i": [4, 1],
"asd": [1, 0],
"t": [4, 1],
Expand Down
14 changes: 7 additions & 7 deletions bears/tests/codeclone_detection/ClangCountingConditionsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,28 @@ def test_conversion(self):
def test_used(self):
self.check_counting_condition(
"used",
"used(int, int)",
(1, "used(int, int)"),
{"a": [5],
"b": [6]})

def test_returned(self):
self.check_counting_condition(
"returned",
"returned(int, int)",
(13, "returned(int, int)"),
{"a": [3],
"b": [2]})

def test_is_condition(self):
self.check_counting_condition(
"is_condition",
"loopy(int, int)",
(22, "loopy(int, int)"),
{"a": [2],
"b": [1]})

def test_in_condition(self):
self.check_counting_condition(
"in_condition",
"in_condition(int, int)",
(47, "in_condition(int, int)"),
{"a": [1],
"b": [1],
"c": [1],
Expand All @@ -85,21 +85,21 @@ def test_in_condition(self):
def test_is_assignee(self):
self.check_counting_condition(
"is_assignee",
"assignation(int, int)",
(62, "assignation(int, int)"),
{"a": [3],
"b": [9]})

def test_is_assigner(self):
self.check_counting_condition(
"is_assigner",
"assignation(int, int)",
(62, "assignation(int, int)"),
{"a": [6],
"b": [9]})

def test_loop_content(self):
self.check_counting_condition(
"loop_content",
"loopy(int, int)",
(22, "loopy(int, int)"),
{"a": [0],
"b": [6]})

Expand Down

1 comment on commit c802734

@Makman2
Copy link
Member

Choose a reason for hiding this comment

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

reack

Please sign in to comment.