Skip to content

C#: Refactor- and rename operation expressions.#21909

Open
michaelnebel wants to merge 14 commits into
github:mainfrom
michaelnebel:csharp/refactoroperations
Open

C#: Refactor- and rename operation expressions.#21909
michaelnebel wants to merge 14 commits into
github:mainfrom
michaelnebel:csharp/refactoroperations

Conversation

@michaelnebel

@michaelnebel michaelnebel commented May 29, 2026

Copy link
Copy Markdown
Contributor

In this PR we streamline the implementation for operations - they now include assignments as well.
That is,

  • BinaryArithmeticOperation, BinaryBitwiseOperation and BinaryLogicalOperation now include compound assignments (e.g. BinaryArithmeticOperation now include a += b).

Some queries and tests have been re-written slightly and in other places (like guards and data flow, the operations now include compound assignment expressions as well).

@github-actions github-actions Bot added the C# label May 29, 2026
@michaelnebel michaelnebel force-pushed the csharp/refactoroperations branch 2 times, most recently from d13e5e8 to 0834f65 Compare June 4, 2026 11:41
@michaelnebel

Copy link
Copy Markdown
Contributor Author

@aschackmull : We discussed a while back that we should restructure the hierarchy of operation expressions (streamlining it with other languages) such that Operation classes also contain the assignment form expressions. Could you take a look at the content of this PR? I have intentionally not made any upgrade/downgrade scripts yet (in case we need to make changes to the DB scheme).

@michaelnebel michaelnebel requested a review from aschackmull June 12, 2026 08:13
@aschackmull

Copy link
Copy Markdown
Contributor

LGTM!

@michaelnebel michaelnebel force-pushed the csharp/refactoroperations branch from 0834f65 to 346d140 Compare June 12, 2026 13:34
@michaelnebel michaelnebel marked this pull request as ready for review June 12, 2026 13:55
@michaelnebel michaelnebel requested a review from a team as a code owner June 12, 2026 13:55
Copilot AI review requested due to automatic review settings June 12, 2026 13:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR restructures C# “operation” expression types so that the *Operation QL classes also cover compound assignment forms (for example, treating a += b as a BinaryArithmeticOperation). It updates the C# dbscheme categories, refactors/renames the relevant expression class hierarchy, and adjusts affected queries/tests and upgrade/downgrade metadata accordingly.

Changes:

  • Expand arithmetic/bitwise/logical operation classifications to include compound assignments via new/renamed operation groupings.
  • Refactor and deprecate older operation-related QL modules/types (introducing newer *Expr / *Operation naming and aliases).
  • Update tests, change notes, and add dbscheme upgrade/downgrade scaffolding for the refactor.
Show a summary per file
File Description
csharp/ql/test/library-tests/csharp11/operators.ql Updates library-test query predicates to use the renamed assignment bitwise expression type.
csharp/ql/test/library-tests/csharp11/operators.expected Adjusts expected results to reflect compound assignments now matching bitwise operation queries.
csharp/ql/lib/upgrades/3cabc77473cbbda95edebafea345c2e3fdfa12d9/upgrade.properties Adds upgrade metadata for the operations refactor.
csharp/ql/lib/upgrades/3cabc77473cbbda95edebafea345c2e3fdfa12d9/semmlecode.csharp.dbscheme Adds upgrade dbscheme snapshot/scaffolding.
csharp/ql/lib/upgrades/3cabc77473cbbda95edebafea345c2e3fdfa12d9/old.dbscheme Adds “old” dbscheme snapshot for upgrade comparisons.
csharp/ql/lib/semmlecode.csharp.dbscheme Renames/restructures operation-related dbscheme unions to include assignment forms.
csharp/ql/lib/semmle/code/csharp/exprs/Operation.qll Deprecates the prior “operations that also have compound assignment forms” module.
csharp/ql/lib/semmle/code/csharp/exprs/LogicalOperation.qll Updates logical operation taxonomy and introduces a shared null-coalescing operation base.
csharp/ql/lib/semmle/code/csharp/exprs/Expr.qll Switches Operation/UnaryOperation/BinaryOperation/TernaryOperation to the new dbscheme categories.
csharp/ql/lib/semmle/code/csharp/exprs/Call.qll Updates compound-assignment operator call modeling to extend the renamed assignment-call class.
csharp/ql/lib/semmle/code/csharp/exprs/BitwiseOperation.qll Refactors bitwise operation classes to distinguish operation-vs-expression and include assignment forms.
csharp/ql/lib/semmle/code/csharp/exprs/Assignment.qll Renames/restructures assignment-call and assignment operation class hierarchy and adds deprecation aliases.
csharp/ql/lib/semmle/code/csharp/exprs/ArithmeticOperation.qll Refactors arithmetic operation classes to include assignment forms under operation categories.
csharp/ql/lib/semmle/code/csharp/dispatch/Dispatch.qll Updates dispatch modeling to the renamed assignment arithmetic type.
csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll Aligns guard logic with updated arithmetic operation coverage.
csharp/ql/lib/semmle/code/csharp/Assignable.qll Updates assignable-definition logic to the renamed assignment-call class.
csharp/ql/lib/experimental/code/csharp/Cryptography/NonCryptographicHashes.qll Updates experimental query logic to use the renamed/refactored operation/expression classes.
csharp/ql/lib/change-notes/2026-06-12-restructure-operations.md Adds breaking change note describing the expanded *Operation coverage.
csharp/downgrades/d13c4c187d7318fd2b8f35c7e8d7f4dc26be68b1/upgrade.properties Adds downgrade metadata corresponding to the operations refactor.
csharp/downgrades/d13c4c187d7318fd2b8f35c7e8d7f4dc26be68b1/semmlecode.csharp.dbscheme Adds downgrade dbscheme snapshot/scaffolding.
csharp/downgrades/d13c4c187d7318fd2b8f35c7e8d7f4dc26be68b1/old.dbscheme Adds “old” dbscheme snapshot for downgrade comparisons.

Copilot's findings

  • Files reviewed: 21/21 changed files
  • Comments generated: 2

Comment on lines 32 to 36
/**
* A binary logical operation. Either a logical 'and' (`LogicalAndExpr`),
* a logical 'or' (`LogicalAndExpr`), or a null-coalescing operation
* (`NullCoalescingExpr`).
* (`NullCoalescingOperation`).
*/
Comment on lines 146 to +149
/**
* An multiplication assignment operation, for example `x *= y`.
* An multiplication assignment expression, for example `x *= y`.
*/
class AssignMulExpr extends AssignArithmeticOperation, MulOperation, @assign_mul_expr {
class AssignMulExpr extends AssignArithmeticExpr, MulOperation, @assign_mul_expr {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants