Loading...
Searching...
No Matches
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
33 class _nout ntype: public type {
34 BY_ME(ntype, type)
35 typedef std::map<const ntype*, const ntype*> promoter;
36 typedef std::map<const ntype*, promoter> promoters;
37
38 public:
39 ntype() = default;
40
41 public:
46 nbool operator==(const type& rhs) const override;
47
48 public:
52 template <typename T> nbool isImpli() const { return this->isImpli(ttype<T>::get()); }
53
54 virtual nbool isImpli(const type& to) const;
55 nbool isImpli(const type* it) const BY_SIDE_FUNC(isImpli);
56 nbool isImpli(const typeProvidable& to) const;
57 nbool isImpli(const typeProvidable* it) const BY_SIDE_FUNC(isImpli);
58
59 template <typename T> tstr<T> asImpli(const node& it) const { return this->asImpli(ttype<T>::get()); }
60
61 template <typename T> tstr<T> asImpli(const node* it) const BY_SIDE_FUNC(asImpli<T>);
62
63 virtual str asImpli(const node& from, const type& to) const;
64 str asImpli(const node& from, const type* to) const BY_SIDE_FUNC(to, asImpli(from, *to), str());
65 str asImpli(const node* from, const type& to) const BY_SIDE_FUNC(from, asImpli(*from, to), str());
66 str asImpli(const node* from, const type* to) const BY_SIDE_FUNC(from&& to, asImpli(*from, *to), str());
67
71 virtual nbool isCustom() const { return false; }
72
73 template <typename T> nbool is() const { return this->is(ttype<T>::get()); }
74
75 nbool is(const type& to) const;
76 nbool is(const type* it) const BY_SIDE_FUNC(is);
77
78 template <typename T> tstr<T> as(const node& it) const { return this->as(it, ttype<T>::get()); }
79
80 template <typename T> tstr<T> as(const node* it) const BY_SIDE_FUNC(as<T>);
81
82 str as(const node& from, const type& to) const;
83 str as(const node& from, const type* to) const BY_SIDE_FUNC(to, as(from, *to), str());
84 str as(const node* from, const type& to) const BY_SIDE_FUNC(from, as(*from, to), str());
85 virtual str as(const node* from, const type* to) const BY_SIDE_FUNC(from&& to, as(*from, *to), str());
86
93 virtual nbool isImmutable() const;
94
101 nbool isSameSign(const type& rhs) const;
102
106 const ntype* promote(const ntype& r) const;
107 const ntype* promote(const ntype* it) const BY_SIDE_FUNC(promote);
108 const ntype* promote(const typeProvidable& r) const;
109 const ntype* promote(const typeProvidable* it) const BY_SIDE_FUNC(promote);
110
111 template <typename T> const ntype* promote() const { return promote(ttype<T>::get()); }
112
116 static const ntype* promote(const ntype& l, const ntype& r);
117 static const ntype* promote(const ntype& l, const ntype* r) BY_SIDE_FUNC(r, promote(l, *r), nullptr);
118 static const ntype* promote(const ntype* l, const ntype& r) BY_SIDE_FUNC(l, promote(*l, r), nullptr);
119 static const ntype* promote(const ntype* l, const ntype* r) BY_SIDE_FUNC(l&& r, promote(*l, *r), nullptr);
120
121 const params& getParams() const BY_CONST_FUNC(getParams())
126 virtual params& getParams();
127
128 virtual const node* getRet() const;
129 virtual void setRet(const node& new1);
130 void setRet(const node* it) BY_SIDE_FUNC(setRet);
131
132 std::string createNameWithParams() const;
133
134 const nchar* getMetaTypeName() const override;
135
136 protected:
137 virtual const impliAses& _getImpliAses() const;
138 virtual const ases& _getAses() const;
139
140 private:
141 static promoters* _makeDeducers();
142 static const ntype& _promoteSuperType(const ntype& l, const ntype& r);
143
144 public:
145 const static inline std::string META_TYPENAME = "ntype";
146 };
147
148 typedef std::vector<const ntype*> ntypes;
149} // namespace by
Collection of type converters.
Definition ases.hpp:13
Implicit type conversion collection.
Definition impliAses.hpp:12
Base class for all AST nodes in the byeol language.
Definition node.hpp:195
represents native c++ type system for byeol language
Definition ntype.hpp:33
nbool operator==(const type &rhs) const override
check whether two ntype are same in both of native and byeol runtime environments
nbool isSameSign(const type &rhs) const
const ntype * promote(const ntype &r) const
static const ntype * promote(const ntype &l, const ntype &r)
virtual nbool isImmutable() const
Checks if this type is immutable.
virtual nbool isCustom() const
Definition ntype.hpp:71
const params & getParams() const BY_CONST_FUNC(getParams()) virtual params &getParams()
Retrieves a non-const reference to the parameters associated with this type.
nbool isImpli() const
whether variable 'it' can be a subtype of T in runtime
Definition ntype.hpp:52
Function parameter list container.
Definition params.hpp:16
Definition tnarr.hpp:9
to Top