Repository navigation
ExprParser: no dynamic_cast, instantiate node templates once - #65
Merged
Merged
Conversation
The expression nodes are created in G4ExprParser and MCPLExprParser and type-checked in ExprParser. The header-only class templates ExprEntity<T> and ExprEntityConstantValue<T> had their vtables and type information emitted in each library using them, and dynamic_cast between them across libraries can fail on platforms comparing type information by address (e.g. Intel macOS). * Remove all dynamic_cast's: returnType() (final in ExprEntity<T>) is enough to check the type, a new virtual isConstantValue() replaces the check for constant value nodes, and makeobj uses static_cast for the upcast. * Explicitly instantiate the templates for the three value types in the ExprParser library (extern template declarations in ASTNode.hh), so their vtables and type information only exist there. Assisted-by: Claude
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Removes the remaining risk of the cross-module type information issue in
the expression parser.
The expression nodes are created in G4ExprParser and MCPLExprParser, but
type-checked in ExprParser. The header-only class templates ExprEntity
and ExprEntityConstantValue had their vtables and type information
emitted in each library using them, and a dynamic_cast between libraries
can fail on platforms which compare type information by address (e.g.
Intel macOS).
Changes:
ExprEntity, so it already identifies the type.
constant value nodes during optimisation.
a dynamic_cast.
the ExprParser library, with extern template declarations in
ASTNode.hh. Their vtables and type information now only exist in
libExprParser. G4ExprParser and MCPLExprParser no longer contain copies
(checked with nm).
assisted-by: claude