20struct CharacterSequence;
37 uint64_t operator()(
const m::Type &type)
const;
47#define category_t(X) X(TY_Scalar) X(TY_Vector)
65 virtual void accept(TypeVisitor &v) = 0;
71 bool is_error()
const {
return Get_Error() ==
this; }
72 bool is_none()
const {
return Get_None() ==
this; }
74 bool is_primitive()
const {
return is<const PrimitiveType>(
this); }
75 bool is_boolean()
const {
return is<const Boolean>(
this); }
76 bool is_bitmap()
const {
return is<const Bitmap>(
this); }
78 bool is_date()
const {
return is<const Date>(
this); }
81 bool is_numeric()
const {
return is<const Numeric>(
this); }
82 bool is_integral()
const;
83 bool is_decimal()
const;
85 bool is_floating_point()
const;
87 bool is_float()
const;
89 bool is_double()
const;
92 virtual uint64_t
size()
const {
throw std::logic_error(
"the size of this type is not defined"); }
95 virtual uint64_t
alignment()
const {
throw std::logic_error(
"the size of this type is not defined"); }
98 virtual uint64_t
hash()
const = 0;
101 virtual void print(std::ostream &out)
const = 0;
103 virtual void dump(std::ostream &out)
const = 0;
140 static Pooled<FnType> Get_Function(
const Type *return_type, std::vector<const Type*> parameter_types);
148bool M_EXPORT
is_comparable(
const Type *first,
const Type *second);
168 bool is_scalar()
const {
return category == TY_Scalar; }
195 uint64_t
hash()
const override;
197 void print(std::ostream &out)
const override;
199 void dump(std::ostream &out)
const override;
218 uint64_t
size()
const override {
return 0; }
221 uint64_t
hash()
const override;
223 void print(std::ostream &out)
const override;
225 void dump(std::ostream &out)
const override;
244 uint64_t
size()
const override {
return 1; }
247 uint64_t
hash()
const override;
249 void print(std::ostream &out)
const override;
251 void dump(std::ostream &out)
const override;
275 uint64_t
size()
const override {
return length; }
278 uint64_t
hash()
const override;
280 void print(std::ostream &out)
const override;
282 void dump(std::ostream &out)
const override;
300 , is_varying(is_varying)
314 uint64_t
size()
const override {
316 return 8 * (length + 1);
323 uint64_t
hash()
const override;
325 void print(std::ostream &out)
const override;
327 void dump(std::ostream &out)
const override;
349 uint64_t
size()
const override {
return 32; }
352 uint64_t
hash()
const override;
354 void print(std::ostream &out)
const override;
356 void dump(std::ostream &out)
const override;
378 uint64_t
size()
const override {
return 64; }
381 uint64_t
hash()
const override;
383 void print(std::ostream &out)
const override;
385 void dump(std::ostream &out)
const override;
397 static constexpr std::size_t MAX_DECIMAL_PRECISION = 19;
400 static constexpr float DECIMAL_TO_BINARY_DIGITS = 3.32192f;
402#define kind_t(X) X(N_Int) X(N_Float) X(N_Decimal)
421 , precision(precision)
433 uint64_t
size()
const override {
435 case N_Int:
return 8 * precision;
436 case N_Float:
return precision;
437 case N_Decimal:
return ceil_to_pow_2(uint32_t(std::ceil(DECIMAL_TO_BINARY_DIGITS * precision)));
444 uint64_t
hash()
const override;
446 void print(std::ostream &out)
const override;
448 void dump(std::ostream &out)
const override;
463 FnType(
const Type *return_type, std::vector<const Type*> parameter_types)
465 , parameter_types(parameter_types)
476 uint64_t
hash()
const override;
478 void print(std::ostream &out)
const override;
480 void dump(std::ostream &out)
const override;
486#define M_TYPE_LIST(X) \
491 X(CharacterSequence) \
500inline
bool Type::is_integral()
const {
501 if (
auto n = cast<const Numeric>(
this))
502 return n->kind == Numeric::N_Int;
507 if (
auto n = cast<const Numeric>(
this))
508 return n->kind == Numeric::N_Decimal;
513 if (
auto n = cast<const Numeric>(
this))
514 return n->kind == Numeric::N_Float;
519 if (
auto n = cast<const Numeric>(
this))
520 return n->kind == Numeric::N_Float
and n->precision == 32;
525 if (
auto n = cast<const Numeric>(
this))
526 return n->kind == Numeric::N_Float
and n->precision == 64;
533 if constexpr (std::is_same_v<T, bool>)
534 return is<const Boolean>(ty);
537 if constexpr (std::is_same_v<T, std::string>)
538 return is<const CharacterSequence>(ty);
541 if constexpr (std::is_arithmetic_v<T>)
542 return is<const Numeric>(ty);
561 if constexpr (std::is_integral_v<T>)
563 else if constexpr (std::is_same_v<T, float>)
565 else if constexpr (std::is_same_v<T, double>)
568 static_assert(not std::is_same_v<T, T>,
"unsupported compile-time type T");
#define M_DECLARE_VISITOR(VISITOR_NAME, BASE_CLASS, CLASS_LIST)
Defines a visitor VISITOR_NAME to visit the class hierarchy rooted in BASE_CLASS and with subclasses ...
#define M_unreachable(MSG)
#define M_ENUM_TO_STR(LIST)
bool M_EXPORT is_comparable(const Type *first, const Type *second)
Returns true iff both types have the same PrimitiveType, i.e.
const Numeric * arithmetic_join(const Numeric *lhs, const Numeric *rhs)
bool M_EXPORT is_convertible(const Type *attr)
const PrimitiveType *M_EXPORT get_runtime_type()
Returns the internal runtime Type of mu*t*able for the compile-time type T.
uint64_t length
the number of elements
Bitmap(Bitmap &&)=default
bool operator==(const Type &other) const override
void accept(ConstTypeVisitor &v) const override
virtual const PrimitiveType * as_vectorial() const override
Convert this PrimitiveType to its vectorial equivalent.
void accept(TypeVisitor &v) override
virtual const PrimitiveType * as_scalar() const override
Convert this PrimitiveType to its scalar equivalent.
uint64_t hash() const override
Compute the 64 bit hash of this Type.
void print(std::ostream &out) const override
Print a textual representation of this Type to out.
uint64_t alignment() const override
Compute the alignment requirement in bits of an instance of this type.
void dump(std::ostream &out) const override
Bitmap(category_t category, uint64_t length)
uint64_t size() const override
Compute the size in bits of an instance of this type.
void accept(ConstTypeVisitor &v) const override
virtual const PrimitiveType * as_vectorial() const override
Convert this PrimitiveType to its vectorial equivalent.
void accept(TypeVisitor &v) override
Boolean(Boolean &&)=default
void dump(std::ostream &out) const override
uint64_t hash() const override
Compute the 64 bit hash of this Type.
virtual const PrimitiveType * as_scalar() const override
Convert this PrimitiveType to its scalar equivalent.
uint64_t size() const override
Compute the size in bits of an instance of this type.
uint64_t alignment() const override
Compute the alignment requirement in bits of an instance of this type.
bool operator==(const Type &other) const override
void print(std::ostream &out) const override
Print a textual representation of this Type to out.
Boolean(category_t category)
The type of character strings, both fixed length and varying length.
CharacterSequence(CharacterSequence &&)=default
uint64_t alignment() const override
Compute the alignment requirement in bits of an instance of this type.
bool operator==(const Type &other) const override
std::size_t length
the maximum length of the string in bytes
virtual const PrimitiveType * as_vectorial() const override
Convert this PrimitiveType to its vectorial equivalent.
void dump(std::ostream &out) const override
void print(std::ostream &out) const override
Print a textual representation of this Type to out.
bool is_varying
true if varying, false otherwise; corresponds to Char(N) and Varchar(N)
virtual const PrimitiveType * as_scalar() const override
Convert this PrimitiveType to its scalar equivalent.
void accept(TypeVisitor &v) override
uint64_t hash() const override
Compute the 64 bit hash of this Type.
CharacterSequence(category_t category, std::size_t length, bool is_varying)
void accept(ConstTypeVisitor &v) const override
uint64_t size() const override
Returns the number of bits required to store a sequence of length many characters.
virtual const PrimitiveType * as_vectorial() const override
Convert this PrimitiveType to its vectorial equivalent.
bool operator==(const Type &other) const override
DateTime(DateTime &&)=default
uint64_t hash() const override
Compute the 64 bit hash of this Type.
void dump(std::ostream &out) const override
virtual const PrimitiveType * as_scalar() const override
Convert this PrimitiveType to its scalar equivalent.
uint64_t size() const override
Compute the size in bits of an instance of this type.
uint64_t alignment() const override
Compute the alignment requirement in bits of an instance of this type.
void accept(ConstTypeVisitor &v) const override
void print(std::ostream &out) const override
Print a textual representation of this Type to out.
DateTime(category_t category)
void accept(TypeVisitor &v) override
void accept(TypeVisitor &v) override
void print(std::ostream &out) const override
Print a textual representation of this Type to out.
virtual const PrimitiveType * as_scalar() const override
Convert this PrimitiveType to its scalar equivalent.
virtual const PrimitiveType * as_vectorial() const override
Convert this PrimitiveType to its vectorial equivalent.
void accept(ConstTypeVisitor &v) const override
uint64_t hash() const override
Compute the 64 bit hash of this Type.
Date(category_t category)
bool operator==(const Type &other) const override
void dump(std::ostream &out) const override
uint64_t alignment() const override
Compute the alignment requirement in bits of an instance of this type.
uint64_t size() const override
Compute the size in bits of an instance of this type.
This Type is assigned when parsing of a data type fails or when semantic analysis detects a type erro...
void print(std::ostream &out) const override
Print a textual representation of this Type to out.
void dump(std::ostream &out) const override
uint64_t hash() const override
Compute the 64 bit hash of this Type.
bool operator==(const Type &other) const override
void accept(TypeVisitor &v) override
void accept(ConstTypeVisitor &v) const override
ErrorType(ErrorType &&)=default
The function type defines the type and count of the arguments and the type of the return value of a S...
FnType(FnType &&)=default
void print(std::ostream &out) const override
Print a textual representation of this Type to out.
uint64_t hash() const override
Compute the 64 bit hash of this Type.
std::vector< const Type * > parameter_types
the type of the return value
void accept(ConstTypeVisitor &v) const override
void accept(TypeVisitor &v) override
void dump(std::ostream &out) const override
FnType(const Type *return_type, std::vector< const Type * > parameter_types)
the types of the parameters
bool operator==(const Type &other) const override
A Type that represents the absence of any other type.
void accept(TypeVisitor &v) override
uint64_t alignment() const override
Compute the alignment requirement in bits of an instance of this type.
bool operator==(const Type &other) const override
NoneType(NoneType &&)=default
void dump(std::ostream &out) const override
void accept(ConstTypeVisitor &v) const override
uint64_t size() const override
Compute the size in bits of an instance of this type.
void print(std::ostream &out) const override
Print a textual representation of this Type to out.
uint64_t hash() const override
Compute the 64 bit hash of this Type.
The numeric type represents integer and floating-point types of different precision and scale.
void dump(std::ostream &out) const override
M_DECLARE_ENUM(kind_t) kind
the kind of numeric type
void accept(TypeVisitor &v) override
unsigned precision
The precision gives the maximum number of digits that can be represented by that type.
void accept(ConstTypeVisitor &v) const override
void print(std::ostream &out) const override
Print a textual representation of this Type to out.
bool operator==(const Type &other) const override
unsigned scale
the number of decimal digits right of the decimal point
uint64_t size() const override
Compute the size in bits of an instance of this type.
Numeric(Numeric &&)=default
Numeric(category_t category, kind_t kind, unsigned precision, unsigned scale)
virtual const PrimitiveType * as_scalar() const override
Convert this PrimitiveType to its scalar equivalent.
uint64_t hash() const override
Compute the 64 bit hash of this Type.
virtual const PrimitiveType * as_vectorial() const override
Convert this PrimitiveType to its vectorial equivalent.
uint64_t alignment() const override
Compute the alignment requirement in bits of an instance of this type.
A pool implements an implicitly garbage-collected set of instances of a class hierarchy.
A data type representing a pooled (or internalized) object.
PrimitiveTypes represent Types of values.
bool is_scalar() const
Returns true iff this PrimitiveType is scalar, i.e. if it is for a single value.
virtual const PrimitiveType * as_scalar() const =0
Convert this PrimitiveType to its scalar equivalent.
virtual const PrimitiveType * as_vectorial() const =0
Convert this PrimitiveType to its vectorial equivalent.
PrimitiveType(const PrimitiveType &)=delete
PrimitiveType(category_t category)
PrimitiveType(PrimitiveType &&)=default
category_t category
whether this type is scalar or vector
bool is_vectorial() const
Returns true iff this PrimitiveType is vectorial, i.e. if it is for a sequence of values.
This class represents types in the SQL type system.
virtual uint64_t alignment() const
Compute the alignment requirement in bits of an instance of this type.
Type(const Type &)=delete
virtual void accept(ConstTypeVisitor &v) const =0
bool is_double() const
Returns true iff this type is a 64 bit floating-point type.
virtual void accept(TypeVisitor &v)=0
static Pooled< Numeric > Get_Double(category_t category)
Returns a Numeric type of given category for 64 bit floating-points.
bool operator!=(const Type &other) const
bool is_date_time() const
bool is_primitive() const
Returns true iff this Type is a PrimitiveType.
bool is_character_sequence() const
virtual uint64_t hash() const =0
Compute the 64 bit hash of this Type.
M_DECLARE_ENUM(category_t)
a category for whether this type is scalar or vectorial
M_LCOV_EXCL_START friend std::ostream & operator<<(std::ostream &out, const Type &t)
Print a textual representation of Type t to out.
virtual void print(std::ostream &out) const =0
Print a textual representation of this Type to out.
bool is_floating_point() const
Returns true iff this type is a floating-point type, i.e. f32 or f64.
static Pooled< Numeric > Get_Float(category_t category)
Returns a Numeric type of given category for 32 bit floating-points.
virtual bool operator==(const Type &other) const =0
virtual void dump(std::ostream &out) const =0
bool is_float() const
Returns true iff this type is a 32 bit floating-point type.
static Pool< Type > types_
a pool of internalized, parameterized types
static Pooled< Numeric > Get_Integer(category_t category, unsigned num_bytes)
Returns a Numeric type for integrals of given category and num_bytes bytes.
bool is_numeric() const
Returns true iff this Type is a Numeric type.
virtual uint64_t size() const
Compute the size in bits of an instance of this type.