Skip to content

Renaming nodes to be shorter and more consistent #1303

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

Merged
merged 34 commits into from
Sep 12, 2023

Conversation

konradweiss
Copy link
Collaborator

@konradweiss konradweiss commented Aug 28, 2023

This PR introduces some renamings with the aim to make the node names more intuitive and more fluently usable when working with the query language and any console scripting interface. The main idea i followed was to name more consistently and omit unnecessary details

  • ParamVariableDeclaration to ParameterDeclaration
  • DeclaredReferenceExpression to Reference to make it shorter and omitting the Expression consistent with Literal.
  • ArraySubscriptionExpression to SubscriptionExpr shorten further and because we use it for other subscriptable constructs that are no arrays.
  • ClassTemplateDeclaration to RecordTemplateDeclaration to be consistent with RecordDeclaration
  • ArrayCreationExpression to NewArrayExpression: to better reflect that is only used in the new context and can be
  • Rename CompoundStatement to Block: I think would be more intuitive.
  • Unify CompoundStatement and CompoundStatementExpression
  • UsingDirective to UsingDeclaration due to it being a declaration
  • ExplicitConstructorInvocation to ConstructorCallExpression to remove unnecessary explicit and invocation and signal that it is a call expression
  • TypeParamDeclaration to TypeParameterDeclaration for consistency

@oxisto
Copy link
Member

oxisto commented Aug 28, 2023

Personally, I wouldn't shorten Statement to Stmt, etc. I kinda like that our classes are complete words and not just abbreviations, which sometimes could be misleading (Decl -> Declaration? Declarator? Declared?)

I do agree with

  • Reference
  • ParameterDeclaration
  • SubscriptionExpression
  • CompoundStatement -> BlockStatement

One question we could explore is whether to drop the added Statement, etc. et all. Do we have a benefit of CallExpression vs. Call? Block instead of CompoundStatement?

@KuechA
Copy link
Contributor

KuechA commented Aug 29, 2023

Tmp for Template is too confusing to me, the rest sounds reasonable. I wouldn't be declined to abbreviate Statement, Declaration, Expression since they occur quite often but I'd also be fine with dropping this information completely. I think the reason to keep it was to know quickly whether it inherits from Statement, Declaration or Expression but at the same time, assigning a wrong type wouldn't be possible anyway

@konradweiss
Copy link
Collaborator Author

@oxisto @KuechA I don't see us dropping the suffix of Statement, Expression, Declaration completely because there are some node names that would be misleading or collide, e.g. CompoundStatement and CompoundStatementExpression and as @KuechA its also good for developers to know what type of node it is. I would incorporate the feedback and still keep the shortening of these three names as my objection to the Decl-Declaration-Declarator Issue is that Decl always stands for Declaration and users who differentiate between Declarator, Declaration and something Declared are so involved that they know our convention. That ofc means we do not abbreviate Declarator and Declared. Unless you have a objection @oxisto ?

@KuechA
Copy link
Contributor

KuechA commented Aug 29, 2023

e.g. CompoundStatement and CompoundStatementExpression

Is this something that we can get rid of? Why can't Block inherit from Expression (which extends Statement)

@konradweiss
Copy link
Collaborator Author

e.g. CompoundStatement and CompoundStatementExpression

Is this something that we can get rid of? Why can't Block inherit from Expression (which extends Statement)

This would make EVERY block of statements an expression, but although I had an initial repulsion to the thought I see it as less problematic the more I think of it. @oxisto What do you think?

@oxisto
Copy link
Member

oxisto commented Aug 29, 2023

e.g. CompoundStatement and CompoundStatementExpression

Is this something that we can get rid of? Why can't Block inherit from Expression (which extends Statement)

This would make EVERY block of statements an expression, but although I had an initial repulsion to the thought I see it as less problematic the more I think of it. @oxisto What do you think?

We could do it similar to the AssignExpression, which is also used as a statement in 90% of the time, but it derives from expression (because of C++ of course).

We then have a property that denotes the usage as expression:

/**
* This property specifies, that this is actually used as an expression. Not many languages
* support that. In the regular case, an assignment is a simple statement and does not hold any
* value itself.
*/
var usedAsExpression = false

We afaik then check in the DFG (EOG?) passes if this property is set and set an additional DFG edge to itself.

@konradweiss
Copy link
Collaborator Author

e.g. CompoundStatement and CompoundStatementExpression

Is this something that we can get rid of? Why can't Block inherit from Expression (which extends Statement)

This would make EVERY block of statements an expression, but although I had an initial repulsion to the thought I see it as less problematic the more I think of it. @oxisto What do you think?

We could do it similar to the AssignExpression, which is also used as a statement in 90% of the time, but it derives from expression (because of C++ of course).

We then have a property that denotes the usage as expression:

/**
* This property specifies, that this is actually used as an expression. Not many languages
* support that. In the regular case, an assignment is a simple statement and does not hold any
* value itself.
*/
var usedAsExpression = false

We afaik then check in the DFG (EOG?) passes if this property is set and set an additional DFG edge to itself.

Ok, I see we ar edoing this, so I would say we just rename CompoundStatementExpression to Block and remove CompundStatement. Here I am fine with removing the suffix cause we use them as Expression and Statement so it does not matter that much.

Can it work without using a variable like usedAsExpression?

@oxisto
Copy link
Member

oxisto commented Aug 29, 2023

e.g. CompoundStatement and CompoundStatementExpression

Is this something that we can get rid of? Why can't Block inherit from Expression (which extends Statement)

This would make EVERY block of statements an expression, but although I had an initial repulsion to the thought I see it as less problematic the more I think of it. @oxisto What do you think?

We could do it similar to the AssignExpression, which is also used as a statement in 90% of the time, but it derives from expression (because of C++ of course).
We then have a property that denotes the usage as expression:

/**
* This property specifies, that this is actually used as an expression. Not many languages
* support that. In the regular case, an assignment is a simple statement and does not hold any
* value itself.
*/
var usedAsExpression = false

We afaik then check in the DFG (EOG?) passes if this property is set and set an additional DFG edge to itself.

Ok, I see we ar edoing this, so I would say we just rename CompoundStatementExpression to Block and remove CompundStatement. Here I am fine with removing the suffix cause we use them as Expression and Statement so it does not matter that much.

Can it work without using a variable like usedAsExpression?

I think we need some kind of property to make the differentiation in the EOG and/or DFG because probably the last statement flows to the expression itself or something. Not sure how the EOG/DFG is implemented for CompoundStatementExpression.

@konradweiss
Copy link
Collaborator Author

e.g. CompoundStatement and CompoundStatementExpression

Is this something that we can get rid of? Why can't Block inherit from Expression (which extends Statement)

This would make EVERY block of statements an expression, but although I had an initial repulsion to the thought I see it as less problematic the more I think of it. @oxisto What do you think?

We could do it similar to the AssignExpression, which is also used as a statement in 90% of the time, but it derives from expression (because of C++ of course).
We then have a property that denotes the usage as expression:

/**
* This property specifies, that this is actually used as an expression. Not many languages
* support that. In the regular case, an assignment is a simple statement and does not hold any
* value itself.
*/
var usedAsExpression = false

We afaik then check in the DFG (EOG?) passes if this property is set and set an additional DFG edge to itself.

Ok, I see we ar edoing this, so I would say we just rename CompoundStatementExpression to Block and remove CompundStatement. Here I am fine with removing the suffix cause we use them as Expression and Statement so it does not matter that much.
Can it work without using a variable like usedAsExpression?

I think we need some kind of property to make the differentiation in the EOG and/or DFG because probably the last statement flows to the expression itself or something. Not sure how the EOG/DFG is implemented for CompoundStatementExpression.

I will see if it is necessary

@oxisto
Copy link
Member

oxisto commented Sep 8, 2023

  • DesignatedInitializerExpression to InitializerExpression : @oxisto Does this still reflect what it is, is there a better name?

I would keep it as DesignatedInitializerExpression for now and merge it as a combination of the initializerlist and the key value expression at some point.

@konradweiss konradweiss marked this pull request as ready for review September 11, 2023 10:51
Copy link
Member

@oxisto oxisto left a comment

Choose a reason for hiding this comment

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

Some smaller things. Looks good overall, I support the renamings

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

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

71.5% 71.5% Coverage
0.1% 0.1% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@konradweiss konradweiss merged commit 15ca3aa into main Sep 12, 2023
@konradweiss konradweiss deleted the refactor/renamingNodes branch September 12, 2023 10:03
oxisto pushed a commit that referenced this pull request Sep 24, 2023
* Renaming nodes to be shorter and more consistent

* Reverting Stmt back to Statement etc.

* Fix naming in python

* Finish renaming nodes

* Replacing outdated names in docs

* Updating names and related to node renaming, unifying BlockStatement and BlockStatementExpression

* Spotless

* Update cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/StatementBuilder.kt

Co-authored-by: KuechA <31155350+KuechA@users.noreply.github.com>

* Fix comments and naming

* Adding Doc and fixing spotless

* <fix some naming

* Spotless

* Fixing Tests

* Fixing golang statement handler

* Spotless go module

* Renaming in tests

* spotless

* More Block name changes

* Fixing import

* newBlock is an Expression (used to be a statement)

* Change edge name of conditional Expression.Fix Documentation and do some variable names refactoring.

* Spotless

* Finish renaming of variables still names Expr

* Reverting InitializerExpression back to DesignatedInitializerEpression to refactor later by merging and spotless

* Rename eci variables

* Spotless

* Renaming SubscriptionExpression to SubscriptExpression and fix comment with Block

* Spotless

* Spotless

---------

Co-authored-by: KuechA <31155350+KuechA@users.noreply.github.com>
Co-authored-by: Maximilian Kaul <maximilian.kaul@aisec.fraunhofer.de>
oxisto pushed a commit that referenced this pull request Sep 24, 2023
* Renaming nodes to be shorter and more consistent

* Reverting Stmt back to Statement etc.

* Fix naming in python

* Finish renaming nodes

* Replacing outdated names in docs

* Updating names and related to node renaming, unifying BlockStatement and BlockStatementExpression

* Spotless

* Update cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/StatementBuilder.kt

Co-authored-by: KuechA <31155350+KuechA@users.noreply.github.com>

* Fix comments and naming

* Adding Doc and fixing spotless

* <fix some naming

* Spotless

* Fixing Tests

* Fixing golang statement handler

* Spotless go module

* Renaming in tests

* spotless

* More Block name changes

* Fixing import

* newBlock is an Expression (used to be a statement)

* Change edge name of conditional Expression.Fix Documentation and do some variable names refactoring.

* Spotless

* Finish renaming of variables still names Expr

* Reverting InitializerExpression back to DesignatedInitializerEpression to refactor later by merging and spotless

* Rename eci variables

* Spotless

* Renaming SubscriptionExpression to SubscriptExpression and fix comment with Block

* Spotless

* Spotless

---------

Co-authored-by: KuechA <31155350+KuechA@users.noreply.github.com>
Co-authored-by: Maximilian Kaul <maximilian.kaul@aisec.fraunhofer.de>
oxisto pushed a commit that referenced this pull request Sep 25, 2023
* Renaming nodes to be shorter and more consistent

* Reverting Stmt back to Statement etc.

* Fix naming in python

* Finish renaming nodes

* Replacing outdated names in docs

* Updating names and related to node renaming, unifying BlockStatement and BlockStatementExpression

* Spotless

* Update cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/StatementBuilder.kt

Co-authored-by: KuechA <31155350+KuechA@users.noreply.github.com>

* Fix comments and naming

* Adding Doc and fixing spotless

* <fix some naming

* Spotless

* Fixing Tests

* Fixing golang statement handler

* Spotless go module

* Renaming in tests

* spotless

* More Block name changes

* Fixing import

* newBlock is an Expression (used to be a statement)

* Change edge name of conditional Expression.Fix Documentation and do some variable names refactoring.

* Spotless

* Finish renaming of variables still names Expr

* Reverting InitializerExpression back to DesignatedInitializerEpression to refactor later by merging and spotless

* Rename eci variables

* Spotless

* Renaming SubscriptionExpression to SubscriptExpression and fix comment with Block

* Spotless

* Spotless

---------

Co-authored-by: KuechA <31155350+KuechA@users.noreply.github.com>
Co-authored-by: Maximilian Kaul <maximilian.kaul@aisec.fraunhofer.de>
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.

None yet

4 participants