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

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

Closed
phiwuu opened this issue Jul 29, 2024 · 0 comments · Fixed by #67
Closed

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

phiwuu opened this issue Jul 29, 2024 · 0 comments · Fixed by #67
Assignees
Labels
lobster-python Affects Python integration

Comments

@phiwuu
Copy link
Member

phiwuu commented Jul 29, 2024

See comment #39 (comment)
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.

@phiwuu phiwuu added the lobster-python Affects Python integration label Jul 29, 2024
kedarnn added a commit that referenced this issue Sep 16, 2024
The identifier now uses counter if there exists multiple functions with
same name.

Issue #58
phiwuu pushed a commit that referenced this issue Sep 16, 2024
The identifier now uses counter if there exists multiple functions with
same name.

Issue #58
kedarnn added a commit that referenced this issue Sep 16, 2024
The identifier now uses counter if there exists multiple functions with
same name.

Issue #58
phiwuu added a commit that referenced this issue Sep 17, 2024
…#67)

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

Issue #58

---------

Co-authored-by: Kedar Navare <[email protected]>
Co-authored-by: Philipp Wullstein-Kammler <[email protected]>
mugdhadhole1 pushed a commit that referenced this issue Oct 9, 2024
…#67)

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

Issue #58

---------

Co-authored-by: Kedar Navare <[email protected]>
Co-authored-by: Philipp Wullstein-Kammler <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lobster-python Affects Python integration
Projects
None yet
4 participants