Skip to content

Commit

Permalink
remove line number from tag and added counter logic for each function (
Browse files Browse the repository at this point in the history
…bmw-software-engineering#67)

The identifier uses counter if there exist multiple functions with the same name.

Issue bmw-software-engineering#58

---------

Co-authored-by: Kedar Navare <[email protected]>
Co-authored-by: Philipp Wullstein-Kammler <[email protected]>
  • Loading branch information
3 people authored Sep 17, 2024
1 parent 9c9d863 commit c59ee91
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

### 0.9.18-dev

* The `lobster-python` tool adds the counter logic to the function
identifier. This improves the situations where different functions have
the same name. Line numbers are no longer used in the identifier.

* The `lobster-codebeamer` tool now supports `refs` as an upstream reference

* The `lobster-online-report` tool now works with config files located in
Expand Down
35 changes: 33 additions & 2 deletions lobster/tools/python/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import os.path
import multiprocessing
import functools
import re

from libcst.metadata import PositionProvider
import libcst as cst
Expand All @@ -32,6 +33,28 @@

LOBSTER_TRACE_PREFIX = "# lobster-trace: "
LOBSTER_JUST_PREFIX = "# lobster-exclude: "
func_name = []


def count_occurrence_of_last_function_from_function_name_list(function_names):
"""
Function returns a function name
(last function from the list of function names)
and its occurrence from the given list of function names
Example: function_names = ['hello.add:2', 'hello.sub:5', 'hello.add:8']
returns : hello.add-2
"""
function_and_file_name = re.split(r"[.:]", function_names[-1])
filename = function_and_file_name[0]
last_function = function_and_file_name[1]
count = 0
for element in range(0, len(function_names) - 1):
if re.split(r"[.:]", function_names[element])[1] == last_function:
count += 1
function_name = (filename + "." + last_function +
("-" + str(count) if count > 0 else ''))

return function_name


def parse_value(val):
Expand Down Expand Up @@ -197,13 +220,21 @@ def to_lobster(self, schema, items):
assert schema is Implementation or schema is Activity
assert isinstance(items, list)

func_name.append(self.fqn())
tagname = count_occurrence_of_last_function_from_function_name_list(
func_name
)
pattern = r"[-]"
val = re.split(pattern, tagname)
name_value = val[0]

if schema is Implementation:
l_item = Implementation(tag = Tracing_Tag("python",
self.fqn()),
tagname),
location = self.location,
language = "Python",
kind = self.kind,
name = self.fqn())
name = name_value)
else:
if not self.name.startswith("test"):
return
Expand Down
Binary file not shown.
28 changes: 28 additions & 0 deletions test-system/lobster-python/multiple_identical_function_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
flag = False
requirements_global = None

if flag == True:
def get_requirements(requirements):
return requirements
else:
def set_requirements(requirements):
requirements_global = requirements
return requirements_global


def get_requirements(requirements):
return requirements


def display_requirements():
print(get_requirements())


def set_requirements(requirements):
requirements_global = requirements
return requirements_global


def get_requirements(requirements):
return requirements

0 comments on commit c59ee91

Please sign in to comment.