souffle  2.0.2-371-g6315b36
TypeSystem.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file TypeSystem.h
12  *
13  * Covers basic operations constituting Souffle's type system.
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/QualifiedName.h"
20 #include "ast/Type.h"
21 #include "souffle/TypeAttribute.h"
27 #include <algorithm>
28 #include <iostream>
29 #include <map>
30 #include <memory>
31 #include <optional>
32 #include <set>
33 #include <stdexcept>
34 #include <string>
35 #include <utility>
36 #include <vector>
37 
38 namespace souffle::ast::analysis {
39 
40 class TypeEnvironment;
41 
42 /**
43  * An abstract base class for types to be covered within a type environment.
44  */
45 class Type {
46 public:
47  Type(const Type& other) = delete;
48 
49  virtual ~Type() = default;
50 
51  const QualifiedName& getName() const {
52  return name;
53  }
54 
55  const TypeEnvironment& getTypeEnvironment() const {
56  return environment;
57  }
58 
59  bool operator==(const Type& other) const {
60  return this == &other;
61  }
62 
63  bool operator!=(const Type& other) const {
64  return !(*this == other);
65  }
66 
67  bool operator<(const Type& other) const {
68  return name < other.name;
69  }
70 
71  virtual void print(std::ostream& out) const {
72  out << name;
73  }
74 
75  friend std::ostream& operator<<(std::ostream& out, const Type& t) {
76  return t.print(out), out;
77  }
78 
79 protected:
82 
83  /** A reference to the type environment this type is associated to. */
85 
87 };
88 
89 /**
90  * Representing the type assigned to a constant.
91  * ConstantType = NumberConstant/UnsignedConstant/FloatConstant/SymbolConstant
92  */
93 class ConstantType : public Type {
95 
96  friend class TypeEnvironment;
97 };
98 
99 /**
100  * A type being a subset of another type.
101  */
102 class SubsetType : virtual public Type {
103 public:
104  void print(std::ostream& out) const override;
105 
106  const Type& getBaseType() const {
107  return baseType;
108  }
109 
110 protected:
113 
114 private:
115  friend class TypeEnvironment;
116 
117  const Type& baseType;
118 };
119 
120 /**
121  * PrimitiveType = Number/Unsigned/Float/Symbol
122  * The class representing pre-built, concrete types.
123  */
124 class PrimitiveType : public SubsetType {
125 public:
126  void print(std::ostream& out) const override {
127  out << name;
128  }
129 
130 private:
133 
134  friend class TypeEnvironment;
135 };
136 
137 /**
138  * A union type combining a list of types into a new, aggregated type.
139  */
140 class UnionType : public Type {
141 public:
142  const std::vector<const Type*>& getElementTypes() const {
143  return elementTypes;
144  }
145 
146  void setElements(std::vector<const Type*> elements) {
147  elementTypes = std::move(elements);
148  }
149 
150  void print(std::ostream& out) const override;
151 
152 protected:
153  friend class TypeEnvironment;
154  std::vector<const Type*> elementTypes;
155 
157  std::vector<const Type*> elementTypes = {})
158  : Type(environment, name), elementTypes(std::move(elementTypes)) {}
159 };
160 
161 /**
162  * A record type combining a list of fields into a new, aggregated type.
163  */
164 struct RecordType : public Type {
165 public:
166  void setFields(std::vector<const Type*> newFields) {
167  fields = std::move(newFields);
168  }
169 
170  const std::vector<const Type*>& getFields() const {
171  return fields;
172  }
173 
174  void print(std::ostream& out) const override;
175 
176 protected:
177  friend class TypeEnvironment;
178 
179  std::vector<const Type*> fields;
180 
182  const std::vector<const Type*> fields = {})
184 };
185 
186 /**
187  * @class AlgebraicDataType
188  * @brief Aggregates types using sums and products.
189  *
190  *
191  * Invariant: branches are in stored in lexicographical order.
192  */
193 class AlgebraicDataType : public Type {
194 public:
195  struct Branch {
196  std::string name; // < the name of the branch
197  std::vector<const Type*> types; // < Product type associated with this branch.
198 
199  void print(std::ostream& out) const {
200  out << tfm::format("%s {%s}", this->name,
201  join(types, ", ", [](std::ostream& out, const Type* t) { out << t->getName(); }));
202  }
203  };
204 
205  void print(std::ostream& out) const override {
206  out << tfm::format("%s = %s", name,
207  join(branches, " | ", [](std::ostream& out, const Branch& branch) { branch.print(out); }));
208  }
209 
210  void setBranches(std::vector<Branch> bs) {
211  branches = std::move(bs);
212  std::sort(branches.begin(), branches.end(),
213  [](const Branch& left, const Branch& right) { return left.name < right.name; });
214  }
215 
216  const std::vector<const Type*>& getBranchTypes(const std::string& constructor) const {
217  for (auto& branch : branches) {
218  if (branch.name == constructor) return branch.types;
219  }
220  // Branch doesn't exist.
221  throw std::out_of_range("Trying to access non-existing branch.");
222  }
223 
224  /** Return the branches as a sorted vector */
225  const std::vector<Branch>& getBranches() const {
226  return branches;
227  }
228 
229 private:
230  AlgebraicDataType(const TypeEnvironment& env, QualifiedName name) : Type(env, std::move(name)) {}
231 
232  friend class TypeEnvironment;
233 
234  std::vector<Branch> branches;
235 };
236 
237 /**
238  * A collection to represent sets of types. In addition to ordinary set capabilities
239  * it may also represent the set of all types -- without being capable of iterating over those.
240  *
241  * It is the basic entity to conduct sub- and super-type computations.
242  */
243 struct TypeSet {
244 public:
246 
247  TypeSet(bool all = false) : all(all) {}
248 
249  template <typename... Types>
250  explicit TypeSet(const Types&... types) : all(false) {
251  for (const Type* cur : toVector<const Type*>(&types...)) {
252  this->types.insert(cur);
253  }
254  }
255 
256  TypeSet(const TypeSet& other) = default;
257  TypeSet(TypeSet&& other) = default;
258  TypeSet& operator=(const TypeSet& other) = default;
259  TypeSet& operator=(TypeSet&& other) = default;
260 
261  bool empty() const {
262  return !all && types.empty();
263  }
264 
265  /** Universality check */
266  bool isAll() const {
267  return all;
268  }
269 
270  /** Determines the size of this set unless it is the universal set */
271  std::size_t size() const {
272  assert(!all && "Unable to give size of universe.");
273  return types.size();
274  }
275 
276  /** Determines whether a given type is included or not */
277  bool contains(const Type& type) const {
278  return all || types.find(&type) != types.end();
279  }
280 
281  /** Adds the given type to this set */
282  void insert(const Type& type) {
283  if (!all) {
284  types.insert(&type);
285  }
286  }
287 
288  /** Calculate intersection of two TypeSet */
289  static TypeSet intersection(const TypeSet& left, const TypeSet& right) {
290  TypeSet result;
291 
292  if (left.isAll()) {
293  return right;
294  } else if (right.isAll()) {
295  return left;
296  }
297 
298  for (const auto& element : left) {
299  if (right.contains(element)) {
300  result.insert(element);
301  }
302  }
303 
304  return result;
305  }
306 
307  template <typename F>
308  TypeSet filter(TypeSet whenAll, F&& f) const {
309  if (all) return whenAll;
310 
311  TypeSet cpy;
312  for (auto&& t : *this)
313  if (f(t)) cpy.insert(t);
314  return cpy;
315  }
316 
317  /** Inserts all the types of the given set into this set */
318  void insert(const TypeSet& set) {
319  if (all) {
320  return;
321  }
322 
323  // if the other set is universal => make this one universal
324  if (set.isAll()) {
325  all = true;
326  types.clear();
327  return;
328  }
329 
330  // add types one by one
331  for (const auto& t : set) {
332  insert(t);
333  }
334  }
335 
336  /** Allows to iterate over the types contained in this set (only if not universal) */
337  const_iterator begin() const {
338  assert(!all && "Unable to enumerate universe.");
339  return derefIter(types.begin());
340  }
341 
342  /** Allows to iterate over the types contained in this set (only if not universal) */
343  const_iterator end() const {
344  assert(!all && "Unable to enumerate universe.");
345  return derefIter(types.end());
346  }
347 
348  /** Determines whether this set is a subset of the given set */
349  bool isSubsetOf(const TypeSet& b) const {
350  if (all) {
351  return b.isAll();
352  }
353  return all_of(*this, [&](const Type& cur) { return b.contains(cur); });
354  }
355 
356  /** Determines equality between type sets */
357  bool operator==(const TypeSet& other) const {
358  return all == other.all && types == other.types;
359  }
360 
361  /** Determines inequality between type sets */
362  bool operator!=(const TypeSet& other) const {
363  return !(*this == other);
364  }
365 
366  /** Adds print support for type sets */
367  void print(std::ostream& out) const {
368  if (all) {
369  out << "{ - all types - }";
370  } else {
371  out << "{"
372  << join(types, ",", [](std::ostream& out, const Type* type) { out << type->getName(); })
373  << "}";
374  }
375  }
376 
377  friend std::ostream& operator<<(std::ostream& out, const TypeSet& set) {
378  set.print(out);
379  return out;
380  }
381 
382 private:
383  /** True if it is the all-types set, false otherwise */
384  bool all;
385 
386  /** The enumeration of types in case it is not the all-types set */
387  std::set<const Type*, deref_less<Type>> types;
388 };
389 
390 /**
391  * A type environment is a set of types. It's main purpose is to provide an enumeration
392  * of all all types within a given program. Additionally, it manages the life cycle of
393  * type instances.
394  */
395 class TypeEnvironment {
396 public:
397  TypeEnvironment() = default;
398 
399  TypeEnvironment(const TypeEnvironment&) = delete;
400 
401  virtual ~TypeEnvironment() = default;
402 
403  /** create type in this environment */
404  template <typename T, typename... Args>
405  T& createType(const QualifiedName& name, Args&&... args) {
406  assert(types.find(name) == types.end() && "Error: registering present type!");
407  auto* newType = new T(*this, name, std::forward<Args>(args)...);
408  types[name] = Own<Type>(newType);
409  return *newType;
410  }
411 
412  bool isType(const QualifiedName&) const;
413  bool isType(const Type& type) const;
414 
415  const Type& getType(const QualifiedName&) const;
416  const Type& getType(const ast::Type&) const;
417 
418  const Type& getConstantType(TypeAttribute type) const {
419  switch (type) {
420  case TypeAttribute::Signed: return getType("__numberConstant");
421  case TypeAttribute::Unsigned: return getType("__unsignedConstant");
422  case TypeAttribute::Float: return getType("__floatConstant");
423  case TypeAttribute::Symbol: return getType("__symbolConstant");
425  case TypeAttribute::ADT: break;
426  }
427 
428  fatal("There is no constant record type");
429  }
430 
431  bool isPrimitiveType(const QualifiedName& identifier) const {
432  if (isType(identifier)) {
434  }
435  return false;
436  }
437 
438  bool isPrimitiveType(const Type& type) const {
439  return primitiveTypes.contains(type);
440  }
441 
442  const TypeSet& getConstantTypes() const {
443  return constantTypes;
444  }
445 
446  const TypeSet& getPrimitiveTypes() const {
447  return primitiveTypes;
448  }
449 
450  const TypeSet& getConstantNumericTypes() const {
451  return constantNumericTypes;
452  }
453 
454  void print(std::ostream& out) const;
455 
456  friend std::ostream& operator<<(std::ostream& out, const TypeEnvironment& environment) {
457  environment.print(out);
458  return out;
459  }
460 
461  TypeSet getTypes() const {
463  for (auto& type : types) {
464  types.insert(type);
465  }
466  return types;
467  }
468 
469 private:
472 
473  /** The list of covered types. */
474  std::map<QualifiedName, Own<Type>> types;
475 
478  TypeSet(getType("__numberConstant"), getType("__unsignedConstant"), getType("__floatConstant"));
479 
481 };
482 
483 // ---------------------------------------------------------------
484 // Type Utilities
485 // ---------------------------------------------------------------
486 
487 /**
488  * Determines whether type a is a subtype of type b.
489  */
490 bool isSubtypeOf(const Type& a, const Type& b);
491 
492 /**
493  * Returns full type qualifier for a given type
494  */
495 std::string getTypeQualifier(const Type& type);
496 
497 /**
498  * Check if the type is of a kind corresponding to the TypeAttribute.
499  */
500 bool isOfKind(const Type& type, TypeAttribute kind);
501 bool isOfKind(const TypeSet& typeSet, TypeAttribute kind);
502 
504 std::optional<TypeAttribute> getTypeAttribute(const TypeSet&);
505 
506 inline bool isNumericType(const TypeSet& type) {
509 }
510 
511 inline bool isOrderableType(const TypeSet& type) {
513 }
514 
515 // -- Greatest Common Sub Types --------------------------------------
516 
517 /**
518  * Computes the greatest common sub types of the two given types.
519  */
520 TypeSet getGreatestCommonSubtypes(const Type& a, const Type& b);
521 
522 /**
523  * Computes the greatest common sub types of all the types in the given set.
524  */
526 
527 /**
528  * The set of pair-wise greatest common sub types of the types in the two given sets.
529  */
531 
532 /**
533  * Computes the greatest common sub types of the given types.
534  */
535 template <typename... Types>
536 TypeSet getGreatestCommonSubtypes(const Types&... types) {
538 }
539 
540 /**
541  * Determine if there exist a type t such that a <: t and b <: t
542  */
543 bool haveCommonSupertype(const Type& a, const Type& b);
544 
545 /**
546  * Determine if two types are equivalent.
547  * That is, check if a <: b and b <: a
548  */
549 bool areEquivalentTypes(const Type& a, const Type& b);
550 
551 /**
552  * Determine if ADT is enumerations (are all constructors empty)
553  */
554 bool isADTEnum(const AlgebraicDataType& type);
555 
556 } // namespace souffle::ast::analysis
souffle::ast::analysis::TypeEnvironment::getTypes
TypeSet getTypes() const
Definition: TypeSystem.h:467
souffle::ast::analysis::TypeEnvironment::operator<<
friend std::ostream & operator<<(std::ostream &out, const TypeEnvironment &environment)
Definition: TypeSystem.h:462
souffle::ast::analysis::isOfKind
bool isOfKind(const Type &type, TypeAttribute kind)
Check if the type is of a kind corresponding to the TypeAttribute.
Definition: TypeSystem.cpp:189
souffle::TypeAttribute::Record
@ Record
souffle::ast::analysis::SubsetType::getBaseType
const Type & getBaseType() const
Definition: TypeSystem.h:112
souffle::ast::analysis::TypeSet::empty
bool empty() const
Definition: TypeSystem.h:267
souffle::ast::analysis::Type::print
virtual void print(std::ostream &out) const
Definition: TypeSystem.h:77
souffle::ast::analysis::AlgebraicDataType::setBranches
void setBranches(std::vector< Branch > bs)
Definition: TypeSystem.h:216
souffle::ast::analysis::RecordType::RecordType
RecordType(const TypeEnvironment &environment, const QualifiedName &name, const std::vector< const Type * > fields={})
Definition: TypeSystem.h:187
souffle::ast::analysis::AlgebraicDataType::getBranchTypes
const std::vector< const Type * > & getBranchTypes(const std::string &constructor) const
Definition: TypeSystem.h:222
TypeAttribute
Type attribute class.
souffle::ast::analysis::TypeSet::isSubsetOf
bool isSubsetOf(const TypeSet &b) const
Determines whether this set is a subset of the given set.
Definition: TypeSystem.h:355
souffle::ast::analysis::AlgebraicDataType::Branch::name
std::string name
Definition: TypeSystem.h:202
souffle::ast::analysis::ConstantType
Representing the type assigned to a constant.
Definition: TypeSystem.h:99
souffle::ast::analysis::areEquivalentTypes
bool areEquivalentTypes(const Type &a, const Type &b)
Determine if two types are equivalent.
Definition: TypeSystem.cpp:373
tinyformat::format
void format(std::ostream &out, const char *fmt)
Definition: tinyformat.h:1089
souffle::ast::analysis::TypeSet::operator<<
friend std::ostream & operator<<(std::ostream &out, const TypeSet &set)
Definition: TypeSystem.h:383
souffle::ast::analysis::isADTEnum
bool isADTEnum(const AlgebraicDataType &type)
Determine if ADT is enumerations (are all constructors empty)
Definition: TypeSystem.cpp:377
souffle::ast::analysis::AlgebraicDataType::getBranches
const std::vector< Branch > & getBranches() const
Return the branches as a sorted vector.
Definition: TypeSystem.h:231
souffle::ast::analysis::TypeSet::operator!=
bool operator!=(const TypeSet &other) const
Determines inequality between type sets.
Definition: TypeSystem.h:368
souffle::ast::analysis::TypeEnvironment::primitiveTypes
const TypeSet primitiveTypes
Definition: TypeSystem.h:486
souffle::ast::analysis::SubsetType::print
void print(std::ostream &out) const override
Definition: TypeSystem.cpp:34
souffle::ast::analysis::TypeEnvironment::getType
const Type & getType(const QualifiedName &) const
Definition: TypeSystem.cpp:81
souffle::ast::analysis::TypeSet::insert
void insert(const Type &type)
Adds the given type to this set.
Definition: TypeSystem.h:288
souffle::ast::analysis::RecordType::getFields
const std::vector< const Type * > & getFields() const
Definition: TypeSystem.h:176
souffle::ast::analysis::TypeSet::intersection
static TypeSet intersection(const TypeSet &left, const TypeSet &right)
Calculate intersection of two TypeSet.
Definition: TypeSystem.h:295
souffle::ast::analysis::TypeEnvironment::print
void print(std::ostream &out) const
Definition: TypeSystem.cpp:247
souffle::ast::analysis::TypeSet::end
const_iterator end() const
Allows to iterate over the types contained in this set (only if not universal)
Definition: TypeSystem.h:349
souffle::ast::analysis::TypeEnvironment::constantTypes
const TypeSet constantTypes
Definition: TypeSystem.h:482
souffle::TypeAttribute::Symbol
@ Symbol
souffle::ast::analysis::PrimitiveType
PrimitiveType = Number/Unsigned/Float/Symbol The class representing pre-built, concrete types.
Definition: TypeSystem.h:130
souffle::ast::analysis::Type::getTypeEnvironment
const TypeEnvironment & getTypeEnvironment() const
Definition: TypeSystem.h:61
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
types
std::vector< Own< ast::Type > > types
Definition: ComponentInstantiation.cpp:64
souffle::ast::analysis::AlgebraicDataType::Branch
Definition: TypeSystem.h:201
MiscUtil.h
souffle::ast::analysis::TypeEnvironment::isType
bool isType(const QualifiedName &) const
Definition: TypeSystem.cpp:73
souffle::ast::analysis::PrimitiveType::print
void print(std::ostream &out) const override
Definition: TypeSystem.h:132
souffle::ast::analysis::TypeSet::print
void print(std::ostream &out) const
Adds print support for type sets.
Definition: TypeSystem.h:373
souffle::ast::analysis::TypeEnvironment::initializePrimitiveTypes
TypeSet initializePrimitiveTypes()
Definition: TypeSystem.cpp:58
souffle::ast::analysis::SubsetType
A type being a subset of another type.
Definition: TypeSystem.h:108
base
T & base
Definition: Reader.h:60
souffle::ast::analysis::UnionType
A union type combining a list of types into a new, aggregated type.
Definition: TypeSystem.h:146
souffle::ast::analysis::Type
An abstract base class for types to be covered within a type environment.
Definition: TypeSystem.h:51
souffle::identifier
std::string identifier(std::string id)
Valid C++ identifier, note that this does not ensure the uniqueness of identifiers returned.
Definition: StringUtil.h:387
souffle::ast::analysis::Type::environment
const TypeEnvironment & environment
A reference to the type environment this type is associated to.
Definition: TypeSystem.h:90
tinyformat.h
souffle::ast::analysis::TypeSet::TypeSet
TypeSet(const Types &... types)
Definition: TypeSystem.h:256
souffle::ast::analysis::haveCommonSupertype
bool haveCommonSupertype(const Type &a, const Type &b)
Determine if there exist a type t such that a <: t and b <: t.
Definition: TypeSystem.cpp:337
souffle::ast::analysis::TypeSet
A collection to represent sets of types.
Definition: TypeSystem.h:249
souffle::ast::analysis::isOrderableType
bool isOrderableType(const TypeSet &type)
Definition: TypeSystem.h:517
souffle::ast::analysis::RecordType
A record type combining a list of fields into a new, aggregated type.
Definition: TypeSystem.h:170
souffle::TypeAttribute::Signed
@ Signed
souffle::derefIter
IterDerefWrapper< Iter > derefIter(const Iter &iter)
A factory function enabling the construction of a dereferencing iterator utilizing the automated dedu...
Definition: ContainerUtil.h:252
souffle::ast::analysis::getGreatestCommonSubtypes
TypeSet getGreatestCommonSubtypes(const Type &a, const Type &b)
Computes the greatest common sub types of the two given types.
Definition: TypeSystem.cpp:254
souffle::ast::analysis::TypeSet::begin
const_iterator begin() const
Allows to iterate over the types contained in this set (only if not universal)
Definition: TypeSystem.h:343
souffle::ast::analysis::isSubtypeOf
static TypeConstraint isSubtypeOf(const TypeVar &a, const TypeVar &b)
A constraint factory ensuring that all the types associated to the variable a are subtypes of the var...
Definition: TypeConstraints.cpp:27
souffle::ast::analysis::UnionType::UnionType
UnionType(const TypeEnvironment &environment, const QualifiedName &name, std::vector< const Type * > elementTypes={})
Definition: TypeSystem.h:162
souffle::ast::analysis::TypeEnvironment::constantNumericTypes
const TypeSet constantNumericTypes
Definition: TypeSystem.h:483
souffle::ast::analysis::Type::operator<
bool operator<(const Type &other) const
Definition: TypeSystem.h:73
souffle::TypeAttribute::Unsigned
@ Unsigned
souffle::ast::analysis::UnionType::getElementTypes
const std::vector< const Type * > & getElementTypes() const
Definition: TypeSystem.h:148
ContainerUtil.h
souffle::ast::analysis::TypeEnvironment::~TypeEnvironment
virtual ~TypeEnvironment()=default
souffle::ast::analysis::TypeSet::contains
bool contains(const Type &type) const
Determines whether a given type is included or not.
Definition: TypeSystem.h:283
souffle::ast::analysis::getTypeAttribute
TypeAttribute getTypeAttribute(const Type &type)
Definition: TypeSystem.cpp:353
souffle::join
detail::joined_sequence< Iter, Printer > join(const Iter &a, const Iter &b, const std::string &sep, const Printer &p)
Creates an object to be forwarded to some output stream for printing sequences of elements interspers...
Definition: StreamUtil.h:175
souffle::IterDerefWrapper
A wrapper for an iterator obtaining pointers of a certain type, dereferencing values before forwardin...
Definition: ContainerUtil.h:203
souffle::ast::analysis::TypeEnvironment
A type environment is a set of types.
Definition: TypeSystem.h:401
souffle::ast::analysis::TypeEnvironment::getConstantType
const Type & getConstantType(TypeAttribute type) const
Definition: TypeSystem.h:424
souffle::ast::analysis::PrimitiveType::PrimitiveType
PrimitiveType(const TypeEnvironment &environment, const QualifiedName &name, const ConstantType &base)
Definition: TypeSystem.h:137
souffle::ast::analysis::Type::operator<<
friend std::ostream & operator<<(std::ostream &out, const Type &t)
Definition: TypeSystem.h:81
Type.h
souffle::ast::analysis::TypeEnvironment::getConstantTypes
const TypeSet & getConstantTypes() const
Definition: TypeSystem.h:448
souffle::TypeAttribute::ADT
@ ADT
souffle::ast::analysis::TypeSet::isAll
bool isAll() const
Universality check.
Definition: TypeSystem.h:272
souffle::ast::analysis::UnionType::elementTypes
std::vector< const Type * > elementTypes
Definition: TypeSystem.h:160
souffle::ast::analysis::TypeEnvironment::getConstantNumericTypes
const TypeSet & getConstantNumericTypes() const
Definition: TypeSystem.h:456
souffle::ast::analysis::RecordType::fields
std::vector< const Type * > fields
Definition: TypeSystem.h:185
souffle::ast::analysis::Type::name
QualifiedName name
Definition: TypeSystem.h:92
souffle::ast::analysis::TypeSet::const_iterator
IterDerefWrapper< typename std::set< const Type * >::const_iterator > const_iterator
Definition: TypeSystem.h:251
souffle::ast::analysis::TypeSet::operator==
bool operator==(const TypeSet &other) const
Determines equality between type sets.
Definition: TypeSystem.h:363
souffle::ast::analysis::Type::getName
const QualifiedName & getName() const
Definition: TypeSystem.h:57
souffle::ast::analysis::Type::Type
Type(const Type &other)=delete
souffle::ast::analysis::TypeEnvironment::types
std::map< QualifiedName, Own< Type > > types
The list of covered types.
Definition: TypeSystem.h:480
souffle::ast::analysis::TypeSet::filter
TypeSet filter(TypeSet whenAll, F &&f) const
Definition: TypeSystem.h:314
souffle::ast::analysis::AlgebraicDataType::AlgebraicDataType
AlgebraicDataType(const TypeEnvironment &env, QualifiedName name)
Definition: TypeSystem.h:236
souffle::all_of
bool all_of(const Container &c, UnaryPredicate p)
A generic test checking whether all elements within a container satisfy a certain predicate.
Definition: FunctionalUtil.h:110
souffle::ast::analysis::SubsetType::baseType
const Type & baseType
Definition: TypeSystem.h:123
QualifiedName.h
b
l j a showGridBackground &&c b raw series this eventEmitter b
Definition: htmlJsChartistMin.h:15
souffle::ast::analysis::TypeSet::all
bool all
True if it is the all-types set, false otherwise.
Definition: TypeSystem.h:390
std
Definition: Brie.h:3053
souffle::ast::analysis::isNumericType
bool isNumericType(const TypeSet &type)
Definition: TypeSystem.h:512
souffle::ast::analysis::AlgebraicDataType
Aggregates types using sums and products.
Definition: TypeSystem.h:199
souffle::ast::analysis::TypeEnvironment::initializeConstantTypes
TypeSet initializeConstantTypes()
Definition: TypeSystem.cpp:49
souffle::ast::analysis::AlgebraicDataType::Branch::types
std::vector< const Type * > types
Definition: TypeSystem.h:203
souffle::ast::analysis::TypeSet::size
std::size_t size() const
Determines the size of this set unless it is the universal set.
Definition: TypeSystem.h:277
StreamUtil.h
souffle::fatal
void fatal(const char *format, const Args &... args)
Definition: MiscUtil.h:198
souffle::ast::analysis
Definition: Aggregate.cpp:39
souffle::ast::analysis::Type::~Type
virtual ~Type()=default
souffle::ast::analysis::TypeSet::operator=
TypeSet & operator=(const TypeSet &other)=default
souffle::ast::analysis::AlgebraicDataType::Branch::print
void print(std::ostream &out) const
Definition: TypeSystem.h:205
souffle::ast::analysis::TypeEnvironment::createType
T & createType(const QualifiedName &name, Args &&... args)
create type in this environment
Definition: TypeSystem.h:411
souffle::ast::analysis::Type::operator!=
bool operator!=(const Type &other) const
Definition: TypeSystem.h:69
souffle::ast::analysis::getTypeQualifier
std::string getTypeQualifier(const Type &type)
Returns full type qualifier for a given type.
Definition: TypeSystem.cpp:204
souffle::ast::analysis::TypeSet::TypeSet
TypeSet(bool all=false)
Definition: TypeSystem.h:253
FunctionalUtil.h
souffle::ast::analysis::TypeSet::types
std::set< const Type *, deref_less< Type > > types
The enumeration of types in case it is not the all-types set.
Definition: TypeSystem.h:393
souffle::ast::analysis::UnionType::print
void print(std::ostream &out) const override
Definition: TypeSystem.cpp:38
souffle::ast::analysis::TypeEnvironment::TypeEnvironment
TypeEnvironment()=default
souffle::TypeAttribute::Float
@ Float
souffle::ast::QualifiedName
Qualified Name class defines fully/partially qualified names to identify objects in components.
Definition: QualifiedName.h:39
souffle::ast::analysis::RecordType::setFields
void setFields(std::vector< const Type * > newFields)
Definition: TypeSystem.h:172
souffle::ast::analysis::RecordType::print
void print(std::ostream &out) const override
Definition: TypeSystem.cpp:43
souffle::ast::analysis::AlgebraicDataType::branches
std::vector< Branch > branches
Definition: TypeSystem.h:240
souffle::ast::analysis::TypeEnvironment::getPrimitiveTypes
const TypeSet & getPrimitiveTypes() const
Definition: TypeSystem.h:452
souffle::ast::analysis::ConstantType::ConstantType
ConstantType(const TypeEnvironment &environment, const QualifiedName &name)
Definition: TypeSystem.h:100
souffle::ast::analysis::TypeEnvironment::isPrimitiveType
bool isPrimitiveType(const QualifiedName &identifier) const
Definition: TypeSystem.h:437
std::type
ElementType type
Definition: span.h:640
souffle::ast::analysis::Type::operator==
bool operator==(const Type &other) const
Definition: TypeSystem.h:65
TypeAttribute.h
souffle::ast::analysis::SubsetType::SubsetType
SubsetType(const TypeEnvironment &environment, const QualifiedName &name, const Type &base)
Definition: TypeSystem.h:117
souffle::ast::analysis::UnionType::setElements
void setElements(std::vector< const Type * > elements)
Definition: TypeSystem.h:152