FreeCAD / FreeCAD/FreeCAD

[Problem] Expression visitor / modifier cannot rewrite expression trees

Open
#12,799 2 comments 0 reactions 0 assignees View on GitHub
Mod: Core Type: Feature
Dominant language
C++
Stars
33.6k
Forks
6k
Avg merge
3d 17h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### 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

```shell
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

- [X] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Research direction

Start by reading App/Expression.h and App/ExpressionVisitors.h to understand the existing ExpressionVisitor and ExpressionModifier behavior. Review issue #12532 for the stated use case, then define the rewrite behavior needed for adding and removing expression nodes and how completion would be verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.