I understand the requirement to stay close to the Java code.
In the C++ runtime one of the basic decisions is which classes to pass by value and which to pass by reference. Java pass by reference looks just like a C++ pass by value, so it’s easy to do the wrong thing or miss a case when translating code. I think it’s important to make those decisions at the class level (eg. declare the class final without virtual methods, or removing the copy constructor and operator=()) so that use of the class is enforced one way or another at compile time.
Once you do pass by value, you can get rid of the virtual methods and should prevent inheritance to avoid object slicing. This makes a lot of sense for runtime-generated objects. My changes to Interval and IntervalSet fall into that category.
Where you do want inheritance, passing by value is a bug — That’s what I changed in the XPath and ParseTreePatternMatcher code. At this point I’m not planning to be a user of that code either, but the code as it stands slices objects.
I also removed “read only” attributes: The natural way to do that in C++ is through constness, that avoids needing to maintain user code to check a read-only flag.
Most (all?) of the changes in this patch address those issues.
On a pull request: I was waiting for feedback on the one I have currently open before opening a new one. Do you want me to add these changes to the one currently open, or wait for it to be resolved one way or another and then open a new one?
Jan.