| souffle
    2.0.2-371-g6315b36
    | 
 
 
 
Go to the documentation of this file.
   24 #include <initializer_list> 
   40                     [&](std::ostream& out, 
const Type* fieldType) { out << fieldType->
getName(); }));
 
   44     auto& signedConstant = createType<ConstantType>(
"__numberConstant");
 
   45     auto& floatConstant = createType<ConstantType>(
"__floatConstant");
 
   46     auto& symbolConstant = createType<ConstantType>(
"__symbolConstant");
 
   47     auto& unsignedConstant = createType<ConstantType>(
"__unsignedConstant");
 
   49     return TypeSet(signedConstant, floatConstant, symbolConstant, unsignedConstant);
 
   53 #define CREATE_PRIMITIVE(TYPE)                    \ 
   54     auto& TYPE##Type = createType<PrimitiveType>( \ 
   55             #TYPE, static_cast<const ConstantType&>(getType("__" #TYPE "Constant"))); 
   62     return TypeSet(numberType, floatType, symbolType, unsignedType);
 
   64 #undef CREATE_PRIMITIVE 
   72     return this == &
type.getTypeEnvironment();
 
   76     return *
types.at(ident);
 
   80     return getType(astTypeDeclaration.getQualifiedName());
 
   94 #define FORWARD(TYPE) \ 
   95     if (auto* t = dynamic_cast<const TYPE##Type*>(&type)) return visit##TYPE##Type(*t); 
  104         fatal(
"Unsupported type encountered!");
 
  108 #define VISIT(TYPE)                                             \ 
  109     virtual R visit##TYPE##Type(const TYPE##Type& type) const { \ 
  110         return visitType(type);                                 \ 
  119     virtual R 
visitType(const Type& )
 const {
 
  130 template <
typename R>
 
  133     mutable std::map<const Type*, R> 
seen;
 
  138         if (pos != 
seen.end()) {
 
  153         explicit visitor(
const Type& root) : root(root) {}
 
  162         bool visitAlgebraicDataType(
const AlgebraicDataType& 
type)
 const override {
 
  166         bool visitUnionType(
const UnionType& 
type)
 const override {
 
  167             return type == root ||
 
  168                    all_of(
type.getElementTypes(), [&](
const Type* cur) { return this->visit(*cur); });
 
  171         bool visitRecordType(
const RecordType& 
type)
 const override {
 
  175         bool visitType(
const Type& )
 const override {
 
  180     return visitor(root).visit(
type);
 
  185         return isA<RecordType>(
type);
 
  187         return isA<AlgebraicDataType>(
type);
 
  194     return !typeSet.
empty() && !typeSet.
isAll() &&
 
  199     std::string kind = [&]() {
 
  213             fatal(
"Unsupported kind");
 
  221     assert(&a.getTypeEnvironment() == &
b.getTypeEnvironment() &&
 
  222             "Types must be in the same type environment");
 
  228     if (isA<UnionType>(a)) {
 
  233     if (isA<UnionType>(
b)) {
 
  234         return any_of(
static_cast<const UnionType&
>(
b).getElementTypes(),
 
  243     for (
const auto& cur : 
types) {
 
  244         out << 
"\t" << *cur.second << 
"\n";
 
  250             "Types must be in the same type environment");
 
  260     if (isA<UnionType>(a) && isA<UnionType>(
b)) {
 
  262         struct collector : 
public TypeVisitor<void> {
 
  265             collector(
const Type& 
b, TypeSet& res) : 
b(
b), res(res) {}
 
  267             void visit(
const Type& 
type)
 const override {
 
  274             void visitUnionType(
const UnionType& 
type)
 const override {
 
  275                 for (
const auto& cur : 
type.getElementTypes()) {
 
  282         collector(
b, res).visit(a);
 
  291     if (set.empty() || set.isAll()) {
 
  296     greatestCommonSubtypes.
insert(*set.begin());
 
  298     for (
auto& 
type : set) {
 
  302     return greatestCommonSubtypes;
 
  323     for (
const Type& x : a) {
 
  324         for (
const Type& y : 
b) {
 
  332     assert(&a.getTypeEnvironment() == &
b.getTypeEnvironment() &&
 
  333             "Types must be in the same type environment");
 
  343     return any_of(a.getTypeEnvironment().getTypes(),
 
  344             [&](
const Type& 
type) { return isSubtypeOf(a, type) && isSubtypeOf(b, type); });
 
  351             return typeAttribute;
 
  354     fatal(
"Unknown type class");
 
  361             return typeAttribute;
 
  372     return all_of(
type.getBranches(), [](
auto& branch) { return branch.types.empty(); });
 
  
bool isOfKind(const Type &type, TypeAttribute kind)
Check if the type is of a kind corresponding to the TypeAttribute.
Representing the type assigned to a constant.
bool areEquivalentTypes(const Type &a, const Type &b)
Determine if two types are equivalent.
bool isADTEnum(const AlgebraicDataType &type)
Determine if ADT is enumerations (are all constructors empty)
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.
virtual R visitType(const Type &) const
void print(std::ostream &out) const
const TypeEnvironment & getTypeEnvironment() const
bool isType(const QualifiedName &) const
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.
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.
TypeSet getGreatestCommonSubtypes(const Type &a, const Type &b)
Computes the greatest common sub types of the two given types.
virtual ~TypeVisitor()=default
A visitor for types visiting each type only once (effectively breaking recursive cycles).
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...
bool isOfRootType(const Type &type, const Type &root)
Determines whether the given type is a sub-type of the given root type.
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...
bool any_of(const Container &c, UnaryPredicate p)
A generic test checking whether any elements within a container satisfy a certain predicate.
#define CREATE_PRIMITIVE(TYPE)
bool isAll() const
Universality check.
std::vector< const Type * > elementTypes
std::vector< const Type * > fields
const QualifiedName & getName() const
std::map< QualifiedName, Own< Type > > types
The list of covered types.
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
TypeSet initializeConstantTypes()
void fatal(const char *format, const Args &... args)
std::string getTypeQualifier(const Type &type)
Returns full type qualifier for a given type.
void print(std::ostream &out) const override
Qualified Name class defines fully/partially qualified names to identify objects in components.
void print(std::ostream &out) const override
std::map< const Type *, R > seen
virtual R visit(const Type &type) const
R operator()(const Type &type) const
R visit(const Type &type) const override