souffle
2.0.2-371-g6315b36
|
Go to the documentation of this file.
40 class TypeEnvironment;
49 virtual ~Type() =
default;
60 return this == &other;
64 return !(*
this == other);
68 return name < other.name;
71 virtual void print(std::ostream& out)
const {
75 friend std::ostream&
operator<<(std::ostream& out,
const Type& t) {
76 return t.print(out), out;
104 void print(std::ostream& out)
const override;
126 void print(std::ostream& out)
const override {
150 void print(std::ostream& out)
const override;
166 void setFields(std::vector<const Type*> newFields) {
167 fields = std::move(newFields);
174 void print(std::ostream& out)
const override;
179 std::vector<const Type*>
fields;
182 const std::vector<const Type*>
fields = {})
197 std::vector<const Type*>
types;
199 void print(std::ostream& out)
const {
201 join(
types,
", ", [](std::ostream& out,
const Type* t) { out << t->getName(); }));
205 void print(std::ostream& out)
const override {
207 join(
branches,
" | ", [](std::ostream& out,
const Branch& branch) { branch.print(out); }));
213 [](
const Branch& left,
const Branch& right) { return left.name < right.name; });
216 const std::vector<const Type*>&
getBranchTypes(
const std::string& constructor)
const {
218 if (branch.name == constructor)
return branch.types;
221 throw std::out_of_range(
"Trying to access non-existing branch.");
249 template <
typename... Types>
251 for (
const Type* cur : toVector<const Type*>(&
types...)) {
252 this->types.insert(cur);
271 std::size_t
size()
const {
272 assert(!
all &&
"Unable to give size of universe.");
294 }
else if (right.
isAll()) {
298 for (
const auto& element : left) {
307 template <
typename F>
309 if (
all)
return whenAll;
312 for (
auto&& t : *
this)
313 if (f(t)) cpy.insert(t);
331 for (
const auto& t : set) {
338 assert(!
all &&
"Unable to enumerate universe.");
344 assert(!
all &&
"Unable to enumerate universe.");
353 return all_of(*
this, [&](
const Type& cur) {
return b.contains(cur); });
363 return !(*
this == other);
367 void print(std::ostream& out)
const {
369 out <<
"{ - all types - }";
387 std::set<const Type*, deref_less<Type>>
types;
404 template <
typename T,
typename... Args>
406 assert(
types.find(name) ==
types.end() &&
"Error: registering present type!");
407 auto* newType =
new T(*
this, name, std::forward<Args>(args)...);
428 fatal(
"There is no constant record type");
454 void print(std::ostream& out)
const;
457 environment.
print(out);
474 std::map<QualifiedName, Own<Type>>
types;
535 template <
typename... Types>
friend std::ostream & operator<<(std::ostream &out, const TypeEnvironment &environment)
bool isOfKind(const Type &type, TypeAttribute kind)
Check if the type is of a kind corresponding to the TypeAttribute.
const Type & getBaseType() const
virtual void print(std::ostream &out) const
void setBranches(std::vector< Branch > bs)
RecordType(const TypeEnvironment &environment, const QualifiedName &name, const std::vector< const Type * > fields={})
const std::vector< const Type * > & getBranchTypes(const std::string &constructor) const
bool isSubsetOf(const TypeSet &b) const
Determines whether this set is a subset of the given set.
Representing the type assigned to a constant.
bool areEquivalentTypes(const Type &a, const Type &b)
Determine if two types are equivalent.
friend std::ostream & operator<<(std::ostream &out, const TypeSet &set)
bool isADTEnum(const AlgebraicDataType &type)
Determine if ADT is enumerations (are all constructors empty)
const std::vector< Branch > & getBranches() const
Return the branches as a sorted vector.
bool operator!=(const TypeSet &other) const
Determines inequality between type sets.
const TypeSet primitiveTypes
void print(std::ostream &out) const override
const Type & getType(const QualifiedName &) const
void insert(const Type &type)
Adds the given type to this set.
const std::vector< const Type * > & getFields() const
static TypeSet intersection(const TypeSet &left, const TypeSet &right)
Calculate intersection of two TypeSet.
void print(std::ostream &out) const
const_iterator end() const
Allows to iterate over the types contained in this set (only if not universal)
const TypeSet constantTypes
PrimitiveType = Number/Unsigned/Float/Symbol The class representing pre-built, concrete types.
const TypeEnvironment & getTypeEnvironment() const
std::vector< Own< ast::Type > > types
bool isType(const QualifiedName &) const
void print(std::ostream &out) const override
void print(std::ostream &out) const
Adds print support for type sets.
TypeSet initializePrimitiveTypes()
A type being a subset of another type.
A union type combining a list of types into a new, aggregated type.
An abstract base class for types to be covered within a type environment.
std::string identifier(std::string id)
Valid C++ identifier, note that this does not ensure the uniqueness of identifiers returned.
const TypeEnvironment & environment
A reference to the type environment this type is associated to.
TypeSet(const Types &... types)
bool haveCommonSupertype(const Type &a, const Type &b)
Determine if there exist a type t such that a <: t and b <: t.
A collection to represent sets of types.
bool isOrderableType(const TypeSet &type)
A record type combining a list of fields into a new, aggregated type.
IterDerefWrapper< Iter > derefIter(const Iter &iter)
A factory function enabling the construction of a dereferencing iterator utilizing the automated dedu...
TypeSet getGreatestCommonSubtypes(const Type &a, const Type &b)
Computes the greatest common sub types of the two given types.
const_iterator begin() const
Allows to iterate over the types contained in this set (only if not universal)
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...
UnionType(const TypeEnvironment &environment, const QualifiedName &name, std::vector< const Type * > elementTypes={})
const TypeSet constantNumericTypes
bool operator<(const Type &other) const
const std::vector< const Type * > & getElementTypes() const
virtual ~TypeEnvironment()=default
bool contains(const Type &type) const
Determines whether a given type is included or not.
TypeAttribute getTypeAttribute(const Type &type)
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...
A wrapper for an iterator obtaining pointers of a certain type, dereferencing values before forwardin...
A type environment is a set of types.
const Type & getConstantType(TypeAttribute type) const
PrimitiveType(const TypeEnvironment &environment, const QualifiedName &name, const ConstantType &base)
friend std::ostream & operator<<(std::ostream &out, const Type &t)
const TypeSet & getConstantTypes() const
bool isAll() const
Universality check.
std::vector< const Type * > elementTypes
const TypeSet & getConstantNumericTypes() const
std::vector< const Type * > fields
IterDerefWrapper< typename std::set< const Type * >::const_iterator > const_iterator
bool operator==(const TypeSet &other) const
Determines equality between type sets.
const QualifiedName & getName() const
Type(const Type &other)=delete
std::map< QualifiedName, Own< Type > > types
The list of covered types.
TypeSet filter(TypeSet whenAll, F &&f) const
AlgebraicDataType(const TypeEnvironment &env, QualifiedName name)
bool all_of(const Container &c, UnaryPredicate p)
A generic test checking whether all elements within a container satisfy a certain predicate.
l j a showGridBackground &&c b raw series this eventEmitter b
bool all
True if it is the all-types set, false otherwise.
bool isNumericType(const TypeSet &type)
Aggregates types using sums and products.
TypeSet initializeConstantTypes()
std::vector< const Type * > types
std::size_t size() const
Determines the size of this set unless it is the universal set.
void fatal(const char *format, const Args &... args)
TypeSet & operator=(const TypeSet &other)=default
void print(std::ostream &out) const
T & createType(const QualifiedName &name, Args &&... args)
create type in this environment
bool operator!=(const Type &other) const
std::string getTypeQualifier(const Type &type)
Returns full type qualifier for a given type.
std::set< const Type *, deref_less< Type > > types
The enumeration of types in case it is not the all-types set.
void print(std::ostream &out) const override
TypeEnvironment()=default
Qualified Name class defines fully/partially qualified names to identify objects in components.
void setFields(std::vector< const Type * > newFields)
void print(std::ostream &out) const override
std::vector< Branch > branches
const TypeSet & getPrimitiveTypes() const
ConstantType(const TypeEnvironment &environment, const QualifiedName &name)
bool isPrimitiveType(const QualifiedName &identifier) const
bool operator==(const Type &other) const
SubsetType(const TypeEnvironment &environment, const QualifiedName &name, const Type &base)
void setElements(std::vector< const Type * > elements)