-
Notifications
You must be signed in to change notification settings - Fork 62
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
Added basic implementation of operator overloading #1606
Conversation
eecbd7b
to
3924bb5
Compare
f86c2ac
to
432105b
Compare
a1badb9
to
9cd5df4
Compare
a0c3a4e
to
4cc7f4a
Compare
4cc7f4a
to
5ffe807
Compare
5ffe807
to
f055ceb
Compare
cdd2f29
to
16c584e
Compare
f055ceb
to
494a5a9
Compare
1cde93a
to
cea51b3
Compare
494a5a9
to
da8ba63
Compare
c3db66d
to
89ea939
Compare
750138e
to
74d0c81
Compare
01c17f6
to
7241b17
Compare
Since the frontend has to implement this feature, it would make sense to add this to the documentation page https://github.com/Fraunhofer-AISEC/cpg/blob/main/docs/docs/CPG/impl/language.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed the stuff I understand. These parts look good to merge after some minor improvements. However, I'm uncertain about too much of the internal pass / graph stuff to click on "approve"...
cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/LanguageTraits.kt
Show resolved
Hide resolved
cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/ArgumentHolder.kt
Show resolved
Hide resolved
cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/StatementHolder.kt
Show resolved
Hide resolved
cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/collections/EdgeList.kt
Show resolved
Hide resolved
...c/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/OperatorCallExpression.kt
Show resolved
Hide resolved
...language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/StatementHandler.kt
Show resolved
Hide resolved
...language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/StatementHandler.kt
Outdated
Show resolved
Hide resolved
...language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/StatementHandler.kt
Outdated
Show resolved
Hide resolved
...language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/StatementHandler.kt
Outdated
Show resolved
Hide resolved
40b46d3
to
b4b8938
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some short question from my side and we should be ready to merge.
cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/LanguageTraits.kt
Show resolved
Hide resolved
cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt
Show resolved
Hide resolved
cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt
Show resolved
Hide resolved
This PR makes sure that Python now properly uses our `TypeResolver` by only setting the unqualified name for a type and let the type resolver handle the rest. Otherwise we will get incorrect results, e.g., when retrieving name of a type within a class.
b4b8938
to
f08b313
Compare
Quality Gate passedIssues Measures |
This PR adds basic functionality for resolving operator overloading for languages that support it (via the trait
HasOperatorOverloading
- which is currently python and C++). The respective frontend looks for function declarations that match entries inoverloadedOperatorNames
and creates anOperatorDeclaration
.The
SymbolResolver
is then looking for specific expressions (that implementHasOverloadedOperation
) to see whether the expression is really an overloaded call to an operator declaration. In this case, the expression is replaced with anOperatorCallExpression
, pointing to the respectiveOperatorDeclaration
. This happens only if a declaration was found, currently, noOperatorDeclaration
is inferred. This might be something for the future.Currently the following nodes support
HasOverloadedOperation
and should work:BinaryOperator
: Tested in C++ and PythonUnaryOperator
: Tested in C++ and PythonMemberExpression
: Only really possible in C++, also tested in C++. This is basically the main trick behind every smart pointer framework by overriding the->
operator.CallExpression
: Not testedThere are probably more expressions, such as array indices, etc. that currently do not implement
HasOverloadedOperation
yet.This PR depends on the following PRs which need to be resolved first:
OperatorDeclaration
#1605