Add dynamic cast shortcuts to value range storage
Introduces `dyn_` methods to `vrange_storage` for safer dynamic casting to specific range types.
This commit enhances the vrange_storage class in GCC by adding dyn_irange, dyn_prange, and dyn_frange methods. These methods act as convenient shortcuts, similar to dynamic_cast in C++, allowing developers to safely attempt casting to specific range types. If the cast is successful, the corresponding storage object is returned; otherwise, NULL is returned, simplifying error handling and code readability when working with different range types.
In Details
This patch introduces dyn_ accessor methods (e.g., dyn_irange) to vrange_storage. These methods function as type-safe downcasts, analogous to dynamic_cast in C++, allowing users to obtain pointers to specific vrange subclasses (irange, prange, frange) from a base vrange_storage object. They return NULL on type mismatch, simplifying the handling of diverse value range representations within the compiler's analysis passes, such as in value-range-storage.cc.
- vrange_storage
- A base class in GCC's intermediate representation that stores information about the possible range of values a variable can hold. It serves as a common interface for different types of range information.
- dynamic cast
- A C++ feature that allows casting a pointer or reference to a base class to a pointer or reference to a derived class. It includes runtime type checking to ensure the cast is safe.
- irange
- Represents an integer range within GCC's value range analysis.
- prange
- Represents a pointer range within GCC's value range analysis.
- frange
- Represents a floating-point range within GCC's value range analysis.