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

Symbol resolver with EOG power #1315

Merged
merged 1 commit into from
Oct 10, 2023
Merged

Symbol resolver with EOG power #1315

merged 1 commit into from
Oct 10, 2023

Conversation

oxisto
Copy link
Member

@oxisto oxisto commented Sep 6, 2023

This PR leverages the power of the already established EOG to establish a relatively good order of resolving symbols. This may not be 100 % accurate yet, but gives us a good enough approximation for now.

In this PR, we also merged the VariableUsageResolver and FunctionCallResolver into a single SymbolResolver. The code is mostly copy/paste from both resolvers and still has a lot of potential for more refactoring in the future, because both did similar things.

The resolver will look for EOGStartHolder nodes (a new interface), to start the resolving cycle. Examples include function declarations, top-level declarations or catch-clauses of try-statements. After gathering all start nodes, it will follow the EOG edges and resolve variables and functions, depending on the type of node it encounters.

This allows us to resolve scenarios where a variable's type depends on the outcome of a function call and then a method call is called on it (which was not possible to resolve before), like the following:

var variable = method();
variable.method2();

It also slightly improves symbol resolving in the individual languages, primarily Go, by modelling more language specifics, such as built-in functions or type derivation logic.

@oxisto oxisto force-pushed the symbol-resolver-with-eog-power branch from 48c1f9f to 572c7bd Compare September 16, 2023 18:46
@oxisto oxisto force-pushed the symbol-resolver-with-eog-power branch 6 times, most recently from 9c87cb0 to 22bb061 Compare September 25, 2023 19:01
@oxisto oxisto force-pushed the symbol-resolver-with-eog-power branch 4 times, most recently from 687789b to 15127bf Compare September 27, 2023 20:40
@oxisto oxisto marked this pull request as ready for review September 28, 2023 13:54
@oxisto oxisto force-pushed the symbol-resolver-with-eog-power branch 3 times, most recently from c2cea18 to 3273ed3 Compare September 28, 2023 18:08
This was linked to issues Sep 29, 2023
@oxisto oxisto force-pushed the symbol-resolver-with-eog-power branch 5 times, most recently from 420d130 to d399fd6 Compare October 1, 2023 20:42
Copy link
Collaborator

@konradweiss konradweiss left a comment

Choose a reason for hiding this comment

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

Some minor changes, and an idea for how to document and change a Todo in code. I did also ask some questions to help me understand some things that are unclear to me.

@oxisto oxisto force-pushed the symbol-resolver-with-eog-power branch from 8ae3521 to a25a96f Compare October 9, 2023 13:18
@oxisto oxisto requested a review from konradweiss October 9, 2023 13:18
@oxisto
Copy link
Member Author

oxisto commented Oct 9, 2023

We also need to update https://fraunhofer-aisec.github.io/cpg/CPG/specs/eog/#variabledeclaration because the EOG of variable declarations changed.

@oxisto oxisto force-pushed the symbol-resolver-with-eog-power branch from a25a96f to b28ab58 Compare October 9, 2023 16:49
Co-Authored-By: KuechA <[email protected]>
@oxisto oxisto force-pushed the symbol-resolver-with-eog-power branch from b28ab58 to d10154d Compare October 10, 2023 12:00
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 25 Code Smells

90.6% 90.6% Coverage
0.0% 0.0% Duplication

@oxisto oxisto merged commit 9a2ced0 into main Oct 10, 2023
3 checks passed
@oxisto oxisto deleted the symbol-resolver-with-eog-power branch October 10, 2023 12:16
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.

Add unsafe package types Harmonizing Scope Manager Resolution
3 participants