Fraunhofer-AISEC / cpg

A library to extract Code Property Graphs from C/C++, Java, Go, Python, Ruby and every other language through LLVM-IR.
https://fraunhofer-aisec.github.io/cpg/
Apache License 2.0
290 stars 62 forks source link

Declaration AST placement #1602

Open maximiliankaul opened 5 months ago

maximiliankaul commented 5 months ago

This is just a reminder to a discussion between @oxisto and myself: https://github.com/Fraunhofer-AISEC/cpg/pull/1555/commits/9d02f6c76f975f39119bf8e844af4c4f5b4fa9c5

oxisto commented 5 months ago

Currently, we place a declaration both on the AST property declarations directly as well as indirectly through the statements property and a DeclarationStatement. This could potentially be a bad idea, since the AST should be a tree, not a graph.

konradweiss commented 2 months ago

Yes, the ast should always be a tree. If it has more connections this can break several things, in the worst case lead to cycles in some algorithms

oxisto commented 2 months ago

Also for this discussion: Currently we model a a: Int or a simple a (the statement, not the expression) as an assignment with no rhs. This works sort-of and the assignment expression will also add a declaration, however the question would be whether we want to directly translate this into a declaration statement / variable declaration.