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

Code and location from children #1411

Merged
merged 7 commits into from
Jan 16, 2024
Merged

Conversation

konradweiss
Copy link
Collaborator

This PR allows the setting of a node's code and location region as the code and location of its children.
Sometimes, when we translate a parent node in the language-specific AST with its children into the CPG AST, we have to set a specific intermediate Node between that has no language-specific AST that can give it a proper code and location.

This PR provides the function codeAndLocationFromChildren(frontend: LanguageFrontend<S, *>, parentNode: S) that is purely optional and can be used in language frontends to cover the use-case mentioned above and set the region of the node to the start and end region of its children. The code is then extracted from the language-specific AST parent using the newly determined location region.

The function modifies the base node, meaning it should be used after construction:
newBlock(...).codecodeAndLocationFromChildren()
or before returning the node if the children are processed and returned after construction:
return block..codecodeAndLocationFromChildren()

@konradweiss
Copy link
Collaborator Author

The quality gate fails because I cannot test it without using the function in a frontend, which I will add and then test in #1388. And unfortunately cannot add with the Fluent Node DSL as I need access to rawNodes and a valid frontend unless I heavily restructure the code just to make it testable and jump through some more hoops.

@konradweiss konradweiss marked this pull request as ready for review January 14, 2024 22:50
@konradweiss konradweiss requested a review from oxisto as a code owner January 14, 2024 22:50
@konradweiss konradweiss requested a review from KuechA January 15, 2024 08:59
@oxisto oxisto enabled auto-merge (squash) January 16, 2024 07:26
@oxisto oxisto force-pushed the feature/codeAlocation-from-children branch from b6cb824 to dd971d7 Compare January 16, 2024 07:29
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions

11.6% Coverage on New Code (required ≥ 75%)

See analysis details on SonarCloud

@oxisto oxisto merged commit abbff30 into main Jan 16, 2024
3 of 4 checks passed
@oxisto oxisto deleted the feature/codeAlocation-from-children branch January 16, 2024 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants