FreeCAD / FreeCAD

This is the official source code of FreeCAD, a free and opensource multiplatform 3D parametric modeler.
https://www.freecad.org
Other
17.58k stars 3.76k forks source link

[Problem] Expression visitor / modifier cannot rewrite expression trees #12799

Open pieterhijma opened 1 month ago

pieterhijma commented 1 month ago

Is there an existing issue for this?

Problem description

The expression visitor (App/Expression.h, App/ExpressionVisitors.h) are incapable of rewriting expression tree. Class ExpressionVisitor allows walking expression trees and gather information, for example gathering all object identifiers. Subclass ExpressionModifier is able to modify individual nodes in the expression tree, for example modify a specific object identifier. However, it is not possible to (easily) rewrite the expression tree such as adding expression nodes or removing ones.

Full version info

OS: Arch Linux
Word size of FreeCAD: 64-bit
Version: 0.22.0dev.36330 +4 (Git)
Build type: DEBUG
Branch: expose-varset
Hash: ec9ac44081e6ab15f5626a25402c6f46aa580e55
Python 3.11.6, Qt 5.15.12, Coin 4.0.2, Vtk , OCC 7.7.2
Locale: English/United States (en_US)
Installed mods: 
  * OpenDark 2023.12.17
  * Ondsel-Lens 2024.1.22.01
  * backup 0.2.3
  * BIM 2021.12.0
  * Assembly3 0.12.2
  * Manipulator 1.5.7
  * fasteners 0.5.10
  * Assembly4 0.50.7
  * DynamicData 2.60.0

Subproject(s) affected?

Core

Anything else?

For context, rewriting expression trees is required for #12532 to add hiddenrefs automatically at selected places.

Code of Conduct

pieterhijma commented 1 month ago

I initially wanted to create a separate PR for this problem with an expression rewriter, but since rewriters typically require private access to expressions, it is necessary to add methods to expressions, making it hard to separate the rewriter from the context in which it is used. I will therefore include the code for the rewriter in #12532.

pieterhijma commented 1 month ago

This commit in PR #12532 adds an expression rewriter, solving this issue.