16uint64_t std::hash<m::Type>::operator()(
const m::Type &type)
const {
return type.
hash(); }
27 static constexpr double LOG_2_OF_10 = 3.321928094887362;
33 Numeric::kind_t kind = std::max(lhs->kind, rhs->kind);
36 unsigned precision_lhs, precision_rhs;
38 case Numeric::N_Int: precision_lhs = 8 * lhs->
precision;
break;
39 case Numeric::N_Float: precision_lhs = lhs->
precision;
break;
40 case Numeric::N_Decimal: precision_lhs = std::ceil(LOG_2_OF_10 * lhs->
precision);
break;
43 case Numeric::N_Int: precision_rhs = 8 * rhs->
precision;
break;
44 case Numeric::N_Float: precision_rhs = rhs->
precision;
break;
45 case Numeric::N_Decimal: precision_rhs = std::ceil(LOG_2_OF_10 * rhs->
precision);
break;
47 int precision = std::max(precision_lhs, precision_rhs);
52 case Numeric::N_Float: {
54 M_insist(precision == 64,
"Illegal floating-point precision");
58 case Numeric::N_Decimal:
return Type::Get_Decimal(category, precision / LOG_2_OF_10, scale);
91 return types_(
Numeric{category, Numeric::N_Decimal, digits, scale});
96 return types_(
Numeric{category, Numeric::N_Int, num_bytes, 0});
116#define ACCEPT(TYPE) \
117 void TYPE::accept(TypeVisitor &v) { v(*this); } \
118 void TYPE::accept(ConstTypeVisitor &v) const { v(*this); }
130 if (
auto o = cast<const Boolean>(&other))
131 return this->
category == o->category;
137 if (
auto o = cast<const Bitmap>(&other))
144 if (
auto o = cast<const CharacterSequence>(&other))
151 if (
auto o = cast<const Date>(&other))
152 return this->
category == o->category;
158 if (
auto o = cast<const DateTime>(&other))
159 return this->
category == o->category;
165 if (
auto o = cast<const Numeric>(&other)) {
167 this->kind == o->kind
and
169 this->
scale == o->scale;
176 if (
auto o = cast<const FnType>(&other)) {
177 if (this->
return_type != o->return_type)
return false;
178 if (this->
parameter_types.size() != o->parameter_types.size())
return false;
210 return ((uint64_t(
precision) << 32) ^ (uint64_t(
scale) << 3) ^ (uint64_t(kind) << 1)) | uint64_t(
category);
217 h = (h << 7) ^ p->hash();
282void Date::print(std::ostream &out)
const { out <<
"DATE"; }
295 else if (
precision == 64) out <<
"DOUBLE";
296 else out <<
"[IllegalFloatingPoint]";
320void ErrorType::dump(std::ostream &out)
const { out <<
"[ErrorType]" << std::endl; }
322void NoneType::dump(std::ostream &out)
const { out <<
"[NoneType]" << std::endl; }
337 << (
is_varying ?
"true" :
"false") <<
", length = " <<
length <<
" }" << std::endl;
353 <<
", precision = " <<
precision <<
", scale = " <<
scale <<
" }" << std::endl;
358 out <<
"FnType{\n return_type: ";
360 out <<
" parameter_types: {\n";
365 out <<
'}' << std::endl;
const Numeric * arithmetic_join(const Numeric *lhs, const Numeric *rhs)
uint64_t length
the number of elements
bool operator==(const Type &other) const override
virtual const PrimitiveType * as_vectorial() const override
Convert this PrimitiveType to its vectorial equivalent.
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.
virtual const PrimitiveType * as_vectorial() const override
Convert this PrimitiveType to its vectorial equivalent.
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.
bool operator==(const Type &other) const override
void print(std::ostream &out) const override
Print a textual representation of this Type to out.
The type of character strings, both fixed length and varying length.
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 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.
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.
bool operator==(const Type &other) 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.
void print(std::ostream &out) const override
Print a textual representation of this Type to out.
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.
uint64_t hash() const override
Compute the 64 bit hash of this Type.
bool operator==(const Type &other) const override
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.
uint64_t hash() const override
Compute the 64 bit hash of this Type.
bool operator==(const Type &other) const override
The function type defines the type and count of the arguments and the type of the return value of a S...
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
bool operator==(const Type &other) const override
A Type that represents the absence of any other type.
bool operator==(const Type &other) const override
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.
unsigned precision
The precision gives the maximum number of digits that can be represented by that type.
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
static constexpr const char * KIND_TO_STR_[]
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.
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.
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.
static Pooled< CharacterSequence > Get_Char(category_t category, std::size_t length)
Returns a CharacterSequence type of the given category and fixed length.
static Pooled< NoneType > Get_None()
Returns a NoneType.
static Pooled< Bitmap > Get_Bitmap(category_t category, std::size_t length)
Returns a Bitmap type of the given category and length.
static Pooled< Numeric > Get_Double(category_t category)
Returns a Numeric type of given category for 64 bit floating-points.
static M_LCOV_EXCL_STOP Pooled< ErrorType > Get_Error()
Returns a ErrorType.
static constexpr const char * CATEGORY_TO_STR_[]
declaration for constexpr static field, see C++17 inline variables
static Pooled< Numeric > Get_Decimal(category_t category, unsigned digits, unsigned scale)
Returns a Numeric type for decimals of given category, decimal digits, and scale.
static Pooled< Date > Get_Date(category_t category)
Returns a Date type of the given category.
static Pooled< Boolean > Get_Boolean(category_t category)
Returns a Boolean type of the given category.
static Pooled< DateTime > Get_Datetime(category_t category)
Returns a DateTime type of the given category.
virtual uint64_t hash() const =0
Compute the 64 bit hash of this Type.
static Pooled< Numeric > Get_Float(category_t category)
Returns a Numeric type of given category for 32 bit floating-points.
virtual void dump(std::ostream &out) const =0
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.
static Pooled< CharacterSequence > Get_Varchar(category_t category, std::size_t length)
Returns a CharacterSequence type of the given category and varying length.
static Pooled< FnType > Get_Function(const Type *return_type, std::vector< const Type * > parameter_types)
Returns a FnType for a function with parameter types parameter_types and return type return_type.