mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Type.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <exception>
4#include <functional>
5#include <mutable/util/fn.hpp>
9#include <vector>
10
11
12namespace m {
13
14struct Type;
15struct ErrorType;
16struct NoneType;
17struct PrimitiveType;
18struct Boolean;
19struct Bitmap;
20struct CharacterSequence;
21struct Date;
22struct DateTime;
23struct Numeric;
24struct FnType;
25
26// forward declare the Type visitor
27struct TypeVisitor;
28struct ConstTypeVisitor;
29
30}
31
32namespace std {
33
34template<>
35struct hash<m::Type>
36{
37 uint64_t operator()(const m::Type &type) const;
38};
39
40}
41
42namespace m {
43
45struct M_EXPORT Type
46{
47#define category_t(X) X(TY_Scalar) X(TY_Vector)
49 protected:
50 static constexpr const char *CATEGORY_TO_STR_[] = { M_ENUM_TO_STR(category_t) };
51#undef category_t
52
53 protected:
55
56 public:
57 template<typename T>
59
60 Type() = default;
61 Type(const Type&) = delete;
62 Type(Type&&) = default;
63 virtual ~Type() { }
64
65 virtual void accept(TypeVisitor &v) = 0;
66 virtual void accept(ConstTypeVisitor &v) const = 0;
67
68 virtual bool operator==(const Type &other) const = 0;
69 bool operator!=(const Type &other) const { return not operator==(other); }
70
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); }
77 bool is_character_sequence() const { return is<const CharacterSequence>(this); }
78 bool is_date() const { return is<const Date>(this); }
79 bool is_date_time() const { return is<const DateTime>(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;
90
92 virtual uint64_t size() const { throw std::logic_error("the size of this type is not defined"); }
93
95 virtual uint64_t alignment() const { throw std::logic_error("the size of this type is not defined"); }
96
98 virtual uint64_t hash() const = 0;
99
101 virtual void print(std::ostream &out) const = 0;
102
103 virtual void dump(std::ostream &out) const = 0;
104 void dump() const;
105
108 friend std::ostream & operator<<(std::ostream &out, const Type &t) {
109 t.print(out);
110 return out;
111 }
113
114 /*----- Type factory methods -------------------------------------------------------------------------------------*/
116 static Pooled<ErrorType> Get_Error();
118 static Pooled<NoneType> Get_None();
120 static Pooled<Boolean> Get_Boolean(category_t category);
122 static Pooled<Bitmap> Get_Bitmap(category_t category, std::size_t length);
124 static Pooled<CharacterSequence> Get_Char(category_t category, std::size_t length);
126 static Pooled<CharacterSequence> Get_Varchar(category_t category, std::size_t length);
128 static Pooled<Date> Get_Date(category_t category);
130 static Pooled<DateTime> Get_Datetime(category_t category);
132 static Pooled<Numeric> Get_Decimal(category_t category, unsigned digits, unsigned scale);
134 static Pooled<Numeric> Get_Integer(category_t category, unsigned num_bytes);
136 static Pooled<Numeric> Get_Float(category_t category);
138 static Pooled<Numeric> Get_Double(category_t category);
140 static Pooled<FnType> Get_Function(const Type *return_type, std::vector<const Type*> parameter_types);
141};
142
143template<typename T>
144bool M_EXPORT is_convertible(const Type *attr);
145
148bool M_EXPORT is_comparable(const Type *first, const Type *second);
149
150template<typename T>
151const PrimitiveType * M_EXPORT get_runtime_type();
152
153}
154
155namespace m {
156
158struct M_EXPORT PrimitiveType : Type
159{
161
162 PrimitiveType(category_t category) : category(category) { }
163 PrimitiveType(const PrimitiveType&) = delete;
165 virtual ~PrimitiveType() { }
166
168 bool is_scalar() const { return category == TY_Scalar; }
170 bool is_vectorial() const { return category == TY_Vector; }
171
173 virtual const PrimitiveType * as_scalar() const = 0;
174
176 virtual const PrimitiveType * as_vectorial() const = 0;
177};
178
180struct M_EXPORT ErrorType: Type
181{
182 friend struct Type;
183
184 private:
186
187 public:
188 ErrorType(ErrorType&&) = default;
189
190 void accept(TypeVisitor &v) override;
191 void accept(ConstTypeVisitor &v) const override;
192
193 bool operator==(const Type &other) const override;
194
195 uint64_t hash() const override;
196
197 void print(std::ostream &out) const override;
198 using Type::dump;
199 void dump(std::ostream &out) const override;
200};
201
203struct M_EXPORT NoneType: Type
204{
205 friend struct Type;
206
207 private:
209
210 public:
211 NoneType(NoneType&&) = default;
212
213 void accept(TypeVisitor &v) override;
214 void accept(ConstTypeVisitor &v) const override;
215
216 bool operator==(const Type &other) const override;
217
218 uint64_t size() const override { return 0; }
219 uint64_t alignment() const override { return 1; }
220
221 uint64_t hash() const override;
222
223 void print(std::ostream &out) const override;
224 using Type::dump;
225 void dump(std::ostream &out) const override;
226};
227
229struct M_EXPORT Boolean : PrimitiveType
230{
231 friend struct Type;
232
233 private:
234 Boolean(category_t category) : PrimitiveType(category) { }
235
236 public:
237 Boolean(Boolean&&) = default;
238
239 void accept(TypeVisitor &v) override;
240 void accept(ConstTypeVisitor &v) const override;
241
242 bool operator==(const Type &other) const override;
243
244 uint64_t size() const override { return 1; }
245 uint64_t alignment() const override { return 1; }
246
247 uint64_t hash() const override;
248
249 void print(std::ostream &out) const override;
250 using Type::dump;
251 void dump(std::ostream &out) const override;
252
253 virtual const PrimitiveType *as_scalar() const override;
254 virtual const PrimitiveType *as_vectorial() const override;
255};
256
258struct M_EXPORT Bitmap : PrimitiveType
259{
260 friend struct Type;
261
262 uint64_t length;
263
264 private:
265 Bitmap(category_t category, uint64_t length) : PrimitiveType(category), length(length) { }
266
267 public:
268 Bitmap(Bitmap&&) = default;
269
270 void accept(TypeVisitor &v) override;
271 void accept(ConstTypeVisitor &v) const override;
272
273 bool operator==(const Type &other) const override;
274
275 uint64_t size() const override { return length; }
276 uint64_t alignment() const override { return 1; }
277
278 uint64_t hash() const override;
279
280 void print(std::ostream &out) const override;
281 using Type::dump;
282 void dump(std::ostream &out) const override;
283
284 virtual const PrimitiveType *as_scalar() const override;
285 virtual const PrimitiveType *as_vectorial() const override;
286};
287
290{
291 friend struct Type;
292
293 std::size_t length;
295
296 private:
297 CharacterSequence(category_t category, std::size_t length, bool is_varying)
298 : PrimitiveType(category)
299 , length(length)
300 , is_varying(is_varying)
301 { }
302
303 public:
305
306 void accept(TypeVisitor &v) override;
307 void accept(ConstTypeVisitor &v) const override;
308
309 bool operator==(const Type &other) const override;
310
314 uint64_t size() const override {
315 if (is_varying)
316 return 8 * (length + 1);
317 else
318 return 8 * length;
319 }
320
321 uint64_t alignment() const override { return 8; }
322
323 uint64_t hash() const override;
324
325 void print(std::ostream &out) const override;
326 using Type::dump;
327 void dump(std::ostream &out) const override;
328
329 virtual const PrimitiveType *as_scalar() const override;
330 virtual const PrimitiveType *as_vectorial() const override;
331};
332
334struct M_EXPORT Date : PrimitiveType
335{
336 friend struct Type;
337
338 private:
339 Date(category_t category) : PrimitiveType(category) { }
340
341 public:
342 Date(Date&&) = default;
343
344 void accept(TypeVisitor &v) override;
345 void accept(ConstTypeVisitor &v) const override;
346
347 bool operator==(const Type &other) const override;
348
349 uint64_t size() const override { return 32; }
350 uint64_t alignment() const override { return 32; }
351
352 uint64_t hash() const override;
353
354 void print(std::ostream &out) const override;
355 using Type::dump;
356 void dump(std::ostream &out) const override;
357
358 virtual const PrimitiveType *as_scalar() const override;
359 virtual const PrimitiveType *as_vectorial() const override;
360};
361
363struct M_EXPORT DateTime : PrimitiveType
364{
365 friend struct Type;
366
367 private:
368 DateTime(category_t category) : PrimitiveType(category) { }
369
370 public:
371 DateTime(DateTime&&) = default;
372
373 void accept(TypeVisitor &v) override;
374 void accept(ConstTypeVisitor &v) const override;
375
376 bool operator==(const Type &other) const override;
377
378 uint64_t size() const override { return 64; }
379 uint64_t alignment() const override { return 64; }
380
381 uint64_t hash() const override;
382
383 void print(std::ostream &out) const override;
384 using Type::dump;
385 void dump(std::ostream &out) const override;
386
387 virtual const PrimitiveType *as_scalar() const override;
388 virtual const PrimitiveType *as_vectorial() const override;
389};
390
392struct M_EXPORT Numeric : PrimitiveType
393{
394 friend struct Type;
395
397 static constexpr std::size_t MAX_DECIMAL_PRECISION = 19;
398
400 static constexpr float DECIMAL_TO_BINARY_DIGITS = 3.32192f;
401
402#define kind_t(X) X(N_Int) X(N_Float) X(N_Decimal)
404private:
405 static constexpr const char *KIND_TO_STR_[] = { M_ENUM_TO_STR(kind_t) };
406#undef kind_t
407 public:
414 unsigned precision;
415 unsigned scale;
416
417 private:
418 Numeric(category_t category, kind_t kind, unsigned precision, unsigned scale)
419 : PrimitiveType(category)
420 , kind(kind)
421 , precision(precision)
422 , scale(scale)
423 { }
424
425 public:
426 Numeric(Numeric&&) = default;
427
428 void accept(TypeVisitor &v) override;
429 void accept(ConstTypeVisitor &v) const override;
430
431 bool operator==(const Type &other) const override;
432
433 uint64_t size() const override {
434 switch (kind) {
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)));
438 }
439 M_unreachable("illegal kind");
440 }
441
442 uint64_t alignment() const override { return size(); }
443
444 uint64_t hash() const override;
445
446 void print(std::ostream &out) const override;
447 using Type::dump;
448 void dump(std::ostream &out) const override;
449
450 virtual const PrimitiveType *as_scalar() const override;
451 virtual const PrimitiveType *as_vectorial() const override;
452};
453
455struct M_EXPORT FnType : Type
456{
457 friend struct Type;
458
460 std::vector<const Type *> parameter_types;
461
462 private:
463 FnType(const Type *return_type, std::vector<const Type*> parameter_types)
464 : return_type(M_notnull(return_type))
465 , parameter_types(parameter_types)
466 { }
467
468 public:
469 FnType(FnType&&) = default;
470
471 void accept(TypeVisitor &v) override;
472 void accept(ConstTypeVisitor &v) const override;
473
474 bool operator==(const Type &other) const override;
475
476 uint64_t hash() const override;
477
478 void print(std::ostream &out) const override;
479 using Type::dump;
480 void dump(std::ostream &out) const override;
481};
482
483/* Given two `Numeric` types, compute the `Numeric` type that is at least as precise as either of them. */
484const Numeric * arithmetic_join(const Numeric *lhs, const Numeric *rhs);
485
486#define M_TYPE_LIST(X) \
487 X(ErrorType) \
488 X(NoneType) \
489 X(Boolean) \
490 X(Bitmap) \
491 X(CharacterSequence) \
492 X(Date) \
493 X(DateTime) \
494 X(Numeric) \
495 X(FnType)
496
499
500inline bool Type::is_integral() const {
501 if (auto n = cast<const Numeric>(this))
502 return n->kind == Numeric::N_Int;
503 return false;
504}
505
506inline bool Type::is_decimal() const {
507 if (auto n = cast<const Numeric>(this))
508 return n->kind == Numeric::N_Decimal;
509 return false;
510}
511
512inline bool Type::is_floating_point() const {
513 if (auto n = cast<const Numeric>(this))
514 return n->kind == Numeric::N_Float;
515 return false;
516}
517
518inline bool Type::is_float() const {
519 if (auto n = cast<const Numeric>(this))
520 return n->kind == Numeric::N_Float and n->precision == 32;
521 return false;
522}
523
524inline bool Type::is_double() const {
525 if (auto n = cast<const Numeric>(this))
526 return n->kind == Numeric::N_Float and n->precision == 64;
527 return false;
528}
529
530template<typename T>
531bool is_convertible(const Type *ty) {
532 /* Boolean */
533 if constexpr (std::is_same_v<T, bool>)
534 return is<const Boolean>(ty);
535
536 /* CharacterSequence */
537 if constexpr (std::is_same_v<T, std::string>)
538 return is<const CharacterSequence>(ty);
539
540 /* Numeric */
541 if constexpr (std::is_arithmetic_v<T>)
542 return is<const Numeric>(ty);
543
544 return false;
545}
546
547inline bool is_comparable(const Type *first, const Type *second) {
548 if (first->is_boolean() and second->is_boolean()) return true;
549 if (first->is_character_sequence() and second->is_character_sequence()) return true;
550 if (first->is_date() and second->is_date()) return true;
551 if (first->is_date_time() and second->is_date_time()) return true;
552 if (first->is_numeric() and second->is_numeric()) return true;
553 return false;
554}
555
556
558template<typename T>
560{
561 if constexpr (std::is_integral_v<T>)
562 return Type::Get_Integer(Type::TY_Vector, sizeof(T));
563 else if constexpr (std::is_same_v<T, float>)
564 return Type::Get_Float(Type::TY_Vector);
565 else if constexpr (std::is_same_v<T, double>)
566 return Type::Get_Double(Type::TY_Vector);
567 else
568 static_assert(not std::is_same_v<T, T>, "unsupported compile-time type T");
569}
570
571}
#define kind_t(X)
Definition: Schema.hpp:829
#define M_TYPE_LIST(X)
Definition: Type.hpp:486
#define category_t(X)
Definition: Type.hpp:47
#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 ...
Definition: Visitor.hpp:181
#define M_unreachable(MSG)
Definition: macro.hpp:146
#define M_notnull(ARG)
Definition: macro.hpp:182
#define M_ENUM_TO_STR(LIST)
Definition: macro.hpp:75
‍mutable namespace
Definition: Backend.hpp:10
bool M_EXPORT is_comparable(const Type *first, const Type *second)
Returns true iff both types have the same PrimitiveType, i.e.
Definition: Type.hpp:547
const Numeric * arithmetic_join(const Numeric *lhs, const Numeric *rhs)
Definition: Type.cpp:24
const Type
Definition: Type.hpp:498
T(x)
bool M_EXPORT is_convertible(const Type *attr)
Definition: Type.hpp:531
and
Definition: enum_ops.hpp:12
const PrimitiveType *M_EXPORT get_runtime_type()
Returns the internal runtime Type of mu*t*able for the compile-time type T.
Definition: Type.hpp:559
STL namespace.
The bitmap type.
Definition: Type.hpp:259
uint64_t length
the number of elements
Definition: Type.hpp:262
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.
Definition: Type.hpp:276
void dump(std::ostream &out) const override
Bitmap(category_t category, uint64_t length)
Definition: Type.hpp:265
uint64_t size() const override
Compute the size in bits of an instance of this type.
Definition: Type.hpp:275
The boolean type.
Definition: Type.hpp:230
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.
Definition: Type.hpp:244
uint64_t alignment() const override
Compute the alignment requirement in bits of an instance of this type.
Definition: Type.hpp:245
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)
Definition: Type.hpp:234
The type of character strings, both fixed length and varying length.
Definition: Type.hpp:290
CharacterSequence(CharacterSequence &&)=default
uint64_t alignment() const override
Compute the alignment requirement in bits of an instance of this type.
Definition: Type.hpp:321
bool operator==(const Type &other) const override
std::size_t length
the maximum length of the string in bytes
Definition: Type.hpp:293
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)
Definition: Type.hpp:294
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)
Definition: Type.hpp:297
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.
Definition: Type.hpp:314
The date type.
Definition: Type.hpp:364
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.
Definition: Type.hpp:378
uint64_t alignment() const override
Compute the alignment requirement in bits of an instance of this type.
Definition: Type.hpp:379
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)
Definition: Type.hpp:368
void accept(TypeVisitor &v) override
The date type.
Definition: Type.hpp:335
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.
Date(Date &&)=default
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)
Definition: Type.hpp:339
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.
Definition: Type.hpp:350
uint64_t size() const override
Compute the size in bits of an instance of this type.
Definition: Type.hpp:349
This Type is assigned when parsing of a data type fails or when semantic analysis detects a type erro...
Definition: Type.hpp:181
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...
Definition: Type.hpp:456
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
Definition: Type.hpp:460
void accept(ConstTypeVisitor &v) const override
void accept(TypeVisitor &v) override
const Type * return_type
Definition: Type.hpp:459
void dump(std::ostream &out) const override
FnType(const Type *return_type, std::vector< const Type * > parameter_types)
‍the types of the parameters
Definition: Type.hpp:463
bool operator==(const Type &other) const override
A Type that represents the absence of any other type.
Definition: Type.hpp:204
void accept(TypeVisitor &v) override
uint64_t alignment() const override
Compute the alignment requirement in bits of an instance of this type.
Definition: Type.hpp:219
bool operator==(const Type &other) const override
NoneType(NoneType &&)=default
void dump(std::ostream &out) const override
void accept(ConstTypeVisitor &v) const override
NoneType()
Definition: Type.hpp:208
uint64_t size() const override
Compute the size in bits of an instance of this type.
Definition: Type.hpp:218
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.
Definition: Type.hpp:393
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.
Definition: Type.hpp:414
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
Definition: Type.hpp:415
uint64_t size() const override
Compute the size in bits of an instance of this type.
Definition: Type.hpp:433
Numeric(Numeric &&)=default
Numeric(category_t category, kind_t kind, unsigned precision, unsigned scale)
Definition: Type.hpp:418
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.
Definition: Type.hpp:442
A pool implements an implicitly garbage-collected set of instances of a class hierarchy.
Definition: Pool.hpp:81
A data type representing a pooled (or internalized) object.
Definition: Pool.hpp:168
PrimitiveTypes represent Types of values.
Definition: Type.hpp:159
bool is_scalar() const
Returns true iff this PrimitiveType is scalar, i.e. if it is for a single value.
Definition: Type.hpp:168
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)
Definition: Type.hpp:162
PrimitiveType(PrimitiveType &&)=default
category_t category
whether this type is scalar or vector
Definition: Type.hpp:160
bool is_vectorial() const
Returns true iff this PrimitiveType is vectorial, i.e. if it is for a sequence of values.
Definition: Type.hpp:170
virtual ~PrimitiveType()
Definition: Type.hpp:165
This class represents types in the SQL type system.
Definition: Type.hpp:46
virtual uint64_t alignment() const
Compute the alignment requirement in bits of an instance of this type.
Definition: Type.hpp:95
Type(const Type &)=delete
bool is_none() const
Definition: Type.hpp:72
bool is_boolean() const
Definition: Type.hpp:75
virtual void accept(ConstTypeVisitor &v) const =0
virtual ~Type()
Definition: Type.hpp:63
bool is_double() const
Returns true iff this type is a 64 bit floating-point type.
Definition: Type.hpp:524
bool is_date() const
Definition: Type.hpp:78
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.
Definition: Type.cpp:104
bool operator!=(const Type &other) const
Definition: Type.hpp:69
bool is_decimal() const
Definition: Type.hpp:506
bool is_date_time() const
Definition: Type.hpp:79
bool is_primitive() const
Returns true iff this Type is a PrimitiveType.
Definition: Type.hpp:74
Type(Type &&)=default
bool is_character_sequence() const
Definition: Type.hpp:77
bool is_error() const
Definition: Type.hpp:71
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.
Definition: Type.hpp:108
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.
Definition: Type.hpp:512
static Pooled< Numeric > Get_Float(category_t category)
Returns a Numeric type of given category for 32 bit floating-points.
Definition: Type.cpp:99
Type()=default
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.
Definition: Type.hpp:518
bool is_bitmap() const
Definition: Type.hpp:76
static Pool< Type > types_
a pool of internalized, parameterized types
Definition: Type.hpp:54
static Pooled< Numeric > Get_Integer(category_t category, unsigned num_bytes)
Returns a Numeric type for integrals of given category and num_bytes bytes.
Definition: Type.cpp:94
bool is_numeric() const
Returns true iff this Type is a Numeric type.
Definition: Type.hpp:81
virtual uint64_t size() const
Compute the size in bits of an instance of this type.
Definition: Type.hpp:92