ntype.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include "core/common.hpp"
5
6namespace by {
7
8 class node;
9 template <typename T, typename TACTIC> class tnarr;
10 typedef tnarr<node, strTactic> narr;
11 class params;
12 class ases;
13 class impliAses;
14
19 class _nout ntype: public type {
20 BY_ME(ntype, type)
21 typedef std::map<const ntype*, const ntype*> deducer;
22 typedef std::map<const ntype*, deducer> deducers;
23 friend class seq;
24 friend class arr;
25 friend class genericOrigin;
26
27 public:
28 ntype() = default;
29
30 public:
31 nbool operator==(const type& rhs) const override;
32
33 public:
34 // ntype:
36 template <typename T> nbool isImpli() const { return this->isImpli(ttype<T>::get()); }
37
38 virtual nbool isImpli(const type& to) const;
39 nbool isImpli(const type* it) const BY_SIDE_FUNC(isImpli);
40 nbool isImpli(const typeProvidable& to) const;
41 nbool isImpli(const typeProvidable* it) const BY_SIDE_FUNC(isImpli);
42
43 template <typename T> tstr<T> asImpli(const node& it) const { return this->asImpli(ttype<T>::get()); }
44
45 template <typename T> tstr<T> asImpli(const node* it) const BY_SIDE_FUNC(asImpli<T>);
46
47 virtual str asImpli(const node& from, const type& to) const;
48 str asImpli(const node& from, const type* to) const BY_SIDE_FUNC(to, asImpli(from, *to), str());
49 str asImpli(const node* from, const type& to) const BY_SIDE_FUNC(from, asImpli(*from, to), str());
50 str asImpli(const node* from, const type* to) const BY_SIDE_FUNC(from&& to, asImpli(*from, *to), str());
51
53 virtual nbool isCustom() const { return false; }
54
55 template <typename T> nbool is() const { return this->is(ttype<T>::get()); }
56
57 nbool is(const type& to) const;
58 nbool is(const type* it) const BY_SIDE_FUNC(is);
59
60 template <typename T> tstr<T> as(const node& it) const { return this->as(it, ttype<T>::get()); }
61
62 template <typename T> tstr<T> as(const node* it) const BY_SIDE_FUNC(as<T>);
63
64 str as(const node& from, const type& to) const;
65 str as(const node& from, const type* to) const BY_SIDE_FUNC(to, as(from, *to), str());
66 str as(const node* from, const type& to) const BY_SIDE_FUNC(from, as(*from, to), str());
67 str as(const node* from, const type* to) const BY_SIDE_FUNC(from&& to, as(*from, *to), str());
68
69 virtual nbool isImmutable() const;
71 const ntype* deduce(const ntype& r) const;
72 const ntype* deduce(const ntype* it) const BY_SIDE_FUNC(deduce);
73 const ntype* deduce(const typeProvidable& r) const;
74 const ntype* deduce(const typeProvidable* it) const BY_SIDE_FUNC(deduce);
75
76 template <typename T> const ntype* deduce() const { return deduce(ttype<T>::get()); }
77
79 static const ntype* deduce(const ntype& l, const ntype& r);
80 static const ntype* deduce(const ntype& l, const ntype* r) BY_SIDE_FUNC(r, deduce(l, *r), nullptr);
81 static const ntype* deduce(const ntype* l, const ntype& r) BY_SIDE_FUNC(l, deduce(*l, r), nullptr);
82 static const ntype* deduce(const ntype* l, const ntype* r) BY_SIDE_FUNC(l&& r, deduce(*l, *r), nullptr);
83
84 const params& getParams() const BY_CONST_FUNC(getParams())
85 virtual params& getParams();
86
87 virtual const node* getRet() const;
88 virtual void setRet(const node& new1);
89 void setRet(const node* it) BY_SIDE_FUNC(setRet);
90
91 std::string createNameWithParams() const;
92
93 const nchar* getMetaTypeName() const override;
94
95 protected:
96 // ntype:
97 virtual const impliAses& _getImpliAses() const;
98 virtual const ases& _getAses() const;
99
100 private:
101 static deducers* _makeDeducers();
102 static const ntype& _deduceSuperType(const ntype& l, const ntype& r);
103
104 public:
105 const static inline std::string META_TYPENAME = "ntype";
106 };
107
108 typedef std::vector<const ntype*> ntypes;
109} // namespace by
Managed array container for byeol language.
Definition: arr.hpp:14
Collection of type converters.
Definition: ases.hpp:12
Generic type origin with type parameters.
Definition: genericOrigin.hpp:15
Implicit type conversion collection.
Definition: impliAses.hpp:11
Base class for all AST nodes in byeol language.
Definition: node.hpp:30
Native type system for byeol language.
Definition: ntype.hpp:19
const ntype * deduce(const ntype &r) const
virtual nbool isCustom() const
Definition: ntype.hpp:53
static const ntype * deduce(const ntype &l, const ntype &r)
nbool isImpli() const
whether variable 'it' can be a subtype of T
Definition: ntype.hpp:36
Function parameter list container.
Definition: params.hpp:15
Managed sequence container for integer ranges.
Definition: seq.hpp:16
Strong reference smart pointer with strict type checking.
Definition: tstr.hpp:13
Template type wrapper for type metadata management.
Definition: ttype.hpp:16
Base class for runtime type information in byeol language.
Definition: type.hpp:12
Interface for objects that can provide their type information.
Definition: typeProvidable.hpp:12