When using ConstantExpr we often need the result of the expression to be kept in the AST. Currently this is done on a by the node that needs the result and has been done multiple times for enumerator, for constexpr variables... . This patch adds to ConstantExpr the ability to store the result of evaluating the expression. no functional changes expected.
Changes:
- Add trailling object to ConstantExpr that can hold an APValue or an uint64_t. the uint64_t is here because most ConstantExpr yield integral values so there is an optimized layout for integral values.
- Add basic* serialization support for the trailing result.
- Move conversion functions from an enum to a fltSemantics from clang::FloatingLiteral to llvm::APFloatBase. this change is to make it usable for serializing APValues.
- Add basic* Import support for the trailing result.
- ConstantExpr created in CheckConvertedConstantExpression now stores the result in the ConstantExpr Node.
- Adapt AST dump to print the result when present.
basic* : None, Indeterminate, Int, Float, FixedPoint, ComplexInt, ComplexFloat,
the result is not yet used anywhere but for -ast-dump.
We'll need cleanups for APSInts too, in the case where they don't fit into their inline storage. Maybe instead of storing a trailing APSInt we could store a trailing uint64_t (and put the bit-width and Signed flag into the ConstantExprBits), and use the APValue representation for APSInts that don't fit in 64 bits? (That'd avoid needing a separate list of cleanups and would also make ConstantExpr 16 bytes smaller in the common case of storing an int that fits in 64 bits.)
As an alternative, we could tail-allocate a sequence of uint64_ts for an APSInt that's larger than 64 bits, but that would force a memory allocation and a copy on every access to the value, so I think it's not worthwhile.