bmw-software-engineering / lobster

Lightweight Open BMW Software Traceability Evidence Report
GNU Affero General Public License v3.0
12 stars 6 forks source link

`lobster-python` shall not use line number as identifier #58

Open phiwuu opened 1 month ago

phiwuu commented 1 month ago

See comment https://github.com/bmw-software-engineering/lobster/pull/39#discussion_r1655077765 lobster-python shall not use line numbers as unique identifiers.

Instead, use the following logic to deduce the name inside the lobster file:

  1. for the first occurrence per file, just take the name as is
  2. for the second and all consecutive occurrences of functions with the same name in the same file, append a counter value (which just indicates how many times the function has been declared previously).

Example: Python file 1: First func becomes func Second func becomes func-2 Third func becomes func-3 and so on

Python file 2: First func becomes func Second func becomes func-2 Third func becomes func-3 and so on

Consider the following Python code file.py:

if True:
    def hello_world():
        return 1
else:
    def hello_world():
        return 2

def hello_universe():
    return 3

print(hello_world())

The expected lobster-python output file shall look like this:

{
  "data": [
    {
      "tag": "python file.hello_world",
      "location": {
        "kind": "file",
        "file": ".\\file.py",
        "line": 2,
        "column": null
      },
      "name": "file.hello_world",
      "messages": [],
      "just_up": [],
      "just_down": [],
      "just_global": [],
      "language": "Python",
      "kind": "Function"
    },
    {
      "tag": "python file.hello_world-2",
      "location": {
        "kind": "file",
        "file": ".\\file.py",
        "line": 5,
        "column": null
      },
      "name": "file.hello_world",
      "messages": [],
      "just_up": [],
      "just_down": [],
      "just_global": [],
      "language": "Python",
      "kind": "Function"
    },
    {
      "tag": "python file.hello_universe",
      "location": {
        "kind": "file",
        "file": ".\\file.py",
        "line": 9,
        "column": null
      },
      "name": "file.hello_universe",
      "messages": [],
      "just_up": [],
      "just_down": [],
      "just_global": [],
      "language": "Python",
      "kind": "Function"
    }
  ],
  "generator": "lobster_python",
  "schema": "lobster-imp-trace",
  "version": 3
}

The new feature here are the lines "tag": "python file.hello_world" and "tag": "python file.hello_world-2". No line number shall be appended, but instead a counter (starting from 2).

If hello_world or hello_universe are defined again in different files, then the generation of the tags shall not be influenced by those other files. That is, the tag generator shall only look at one single file at a time.