souffle  2.0.2-371-g6315b36
SubsetType.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2020 The Souffle Developers. 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 SubsetType.h
12  *
13  * Defines the subset type class
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/Node.h"
20 #include "ast/QualifiedName.h"
21 #include "ast/Type.h"
22 #include "parser/SrcLocation.h"
23 #include <iostream>
24 #include <string>
25 #include <utility>
26 
27 namespace souffle::ast {
28 
29 /**
30  * @class SubsetType
31  * @brief Defines subset type class
32  *
33  * Example:
34  * .type A <: B
35  */
36 class SubsetType : public Type {
37 public:
38  SubsetType(QualifiedName name, QualifiedName baseTypeName, SrcLocation loc = {})
39  : Type(std::move(name), std::move(loc)), baseType(std::move(baseTypeName)) {}
40 
41  SubsetType* clone() const override {
42  return new SubsetType(getQualifiedName(), getBaseType(), getSrcLoc());
43  }
44 
45  /** Return base type */
46  const QualifiedName& getBaseType() const {
47  return baseType;
48  }
49 
50 protected:
51  void print(std::ostream& os) const override {
52  os << ".type " << getQualifiedName() << " <: " << getBaseType();
53  }
54 
55  bool equal(const Node& node) const override {
56  const auto& other = static_cast<const SubsetType&>(node);
57  return getQualifiedName() == other.getQualifiedName() && baseType == other.baseType;
58  }
59 
60 private:
61  /** Base type */
62  const QualifiedName baseType;
63 };
64 
65 } // namespace souffle::ast
souffle::ast::analysis::SubsetType::getBaseType
const Type & getBaseType() const
Definition: TypeSystem.h:112
souffle::ast::analysis::SubsetType::print
void print(std::ostream &out) const override
Definition: TypeSystem.cpp:34
SrcLocation.h
souffle::ast::analysis::SubsetType
A type being a subset of another type.
Definition: TypeSystem.h:108
souffle::ast::SubsetType::getBaseType
const QualifiedName & getBaseType() const
Return base type.
Definition: SubsetType.h:52
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
Type.h
Node.h
souffle::ast::analysis::Type::name
QualifiedName name
Definition: TypeSystem.h:92
souffle::ast::analysis::Type::Type
Type(const Type &other)=delete
souffle::ast::Node
Abstract class for syntactic elements in an input program.
Definition: Node.h:40
souffle::ast::analysis::SubsetType::baseType
const Type & baseType
Definition: TypeSystem.h:123
QualifiedName.h
souffle::ast
Definition: Aggregator.h:35
souffle::ast::QualifiedName
Qualified Name class defines fully/partially qualified names to identify objects in components.
Definition: QualifiedName.h:39
souffle::ast::analysis::SubsetType::SubsetType
SubsetType(const TypeEnvironment &environment, const QualifiedName &name, const Type &base)
Definition: TypeSystem.h:117