-
Notifications
You must be signed in to change notification settings - Fork 60
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
Various fixes for declarations #179
Conversation
Ok, I have no idea, why the CFG tests fail. They also only fail sometimes it seems :( |
The test design here does not make sense in my opinion. It tries to get all AST in |
66dc190
to
561bcbb
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.
This PR breaks half of the tests in Codyze.
Starting with commit b08930a3ce7536d53b942ead94b93c211777480f
("Minor fixes to method and constructor definitions"), various things break:
Type.getTypeName()
returning null is not expected by Codyze- Nodes not having a
code
property - Endless loops somewhere
- ...
I'd recommend to quickly test each CPG version against Codyze to see what breaks and then clearly document the changes so it gets clear what has to be done to upgrade Codyze. Currently, the API of CPG is a constantly moving target and it is very difficult to keep up as users of CPG do not know what they can rely on and no documentation is available.
The main problem is, that I cannot really test codyze because for some reason, this branch leads to Fraunhofer-AISEC/codyze#37. All changes are documented above and they should not introduce anything that "breaks", if they do, then it was always broken and probably worked around in codyze. Seems we have a little bit of a chicken-and-egg problem here. |
So it looks like that it all started with #164 which somehow causes the OGM wrapper within codyze to malfunction and do all kind of crazy things such as not recognising relationships or not finding property values and so on. It seems to have an issue with the cpg/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java Lines 118 to 119 in 6af6499
|
Two field relationships were incorrectly defines as incoming, although they should be outgoing. Together with Fraunhofer-AISEC/codyze#41 this should be enough to successfully run all tests on codyze. |
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.
Codyze tests are now passing, thank you. The newly DeclarationSequence
(and its implication on Codyze) is not yet clear - see my other comment.
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
/** | ||
* This represents a sequence of one or more declaration(s). The purpose of this node is primarily |
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.
This is a breaking change in the CPG structure. What is the rationale behind it? Before, there was a DeclarationStatement
node that had one or multiple declarations (in case of a sequence). There are even extra methods for it (DeclarationStatement.getDeclarations()
, DeclarationStatement.isSingleDeclaration()
, etc.)
This PR now introduces a separate node for DeclarationSequence
. It is unclear how that relates to the existing structure of having 1-n declarations attached to a DeclarationStatement
.
Also, the comment raises more questions: It should not end up in the final graph
-> What is the final graph? As this class inherits from Declaration
which is a Node
, it will indeed be part of the graph. What is the point of having nodes that are not part of the graph?
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.
Declarations can exist without a declaration statement, i.e. directly attached to a translation unit. The problem is that one simple declaration in C++ can actually hold more than one declaration (for example when declaring multiple variables or a class declaration inside a variable declaration).
In the past, we tried to work around this by having two distinct handlers, a DeclarationHandler
, which returns a Declaration
and a DeclarationListHandler
, which returns a List<Declaration>
. This is a constraint, because a handler can either return a type of N
or List<N>
but not both in the same handler.
A C++ simple declaration was first handled by the DeclarationListHandler
's handleSimpleDeclaration and then again by the DeclarationHandler
's handleSimpleDeclaration, which lead to various errors - because some functionality needed to exist in both handlers (and it didn't).
My workaround thus was to create a "virtual" CPG node, called a declaration sequence, which is actually a declaration itself and can hold 0..n declarations. Referring to the final graph means that the declaration sequence's children are being added to the parent's list of declarations before translation is finished. Thus, it has no implications on codyze.
This produces less warnings for some files
Otherwise they would get lost
Kudos, SonarCloud Quality Gate passed!
|
In this process, I have decided to merge the
DeclarationListHandler
into theDeclarationHandler
. Since an handler can only returnNode
types orList<Node>
types, I have introduced theDeclarationSequence
node. This node should not end up in the final graph and will be "flattened" during CPG transformation.Closes #178