nany
classdef.h
1 #pragma once
2 #include <yuni/yuni.h>
3 #include <yuni/core/string.h>
4 #include <yuni/core/smartptr/intrusive.h>
5 #include "details/ir/fwd.h"
6 #include "details/utils/clid.h"
7 #include "nany/nany.h"
8 #include "type.h"
9 #include <vector>
10 #include "qualifiers.h"
11 #include "interface.h"
12 #include "funcdef.h"
13 #include "classdef-follow.h"
14 #include "details/reporting/report.h"
15 
16 
17 namespace ny {
18 
19 
20 struct Atom;
21 
22 
24 struct Classdef final
25  : public Yuni::IIntrusiveSmartPtr<Classdef, false, Yuni::Policy::SingleThreaded> {
27  static const Classdef nullcdef;
28 
29 public:
31 
32  Classdef();
35  Classdef(const Classdef&) = default;
37  explicit Classdef(const CLID&);
39 
41 
42  bool isBuiltin() const;
45  bool isBuiltinOrVoid() const;
47  bool isRawPointer() const;
49  bool isBuiltinU64() const;
51  bool isBuiltinU32() const;
53  bool isBuiltinU8() const;
55  bool isBuiltingUnsigned() const;
56 
58  bool isVoid() const;
60  bool isLinkedToAtom() const;
62  bool isAny() const;
64  bool isClass() const;
66  bool isClass(const AnyString& name) const;
67 
69  bool isVariable() const;
71  bool hasAtom() const;
72 
74  bool hasConstraints() const;
76 
78 
79  void mutateToVoid();
81 
83  void mutateToBuiltin(nytype_t);
84 
86  void mutateToBuiltinOrVoid(nytype_t);
87 
89  void mutateToAny();
90 
92  void mutateToAtom(Atom*);
93 
95  void mutateToPtr2Func(Atom*);
96 
98  void import(const Classdef& rhs);
100 
101 
103 
104 
109  void print(Yuni::String& out, const ClassdefTableView& table, bool clearBefore = true) const;
110  YString print(const ClassdefTableView& table) const;
111  void print(Logs::Report&, const ClassdefTableView& table) const;
113 
114 
116 
117  bool operator == (const Classdef&) const;
120  bool operator != (const Classdef&) const;
122  Classdef& operator = (const Classdef&) = delete;
124 
125 
126 public:
128  nytype_t kind = nyt_void;
130  Atom* atom = nullptr;
136  bool instance = false;
137 
144 
145  struct {
146  uint line = 0;
147  uint offset = 0;
149  const char* filename = nullptr;
150  }
151  origins;
152 
153 
154 private:
155  template<class T, class TableT> void doPrint(T& out, const TableT& table) const;
156 
157 }; // struct Classdef
158 
159 
160 } // namespace ny
161 
162 #include "classdef.hxx"
const char * filename
filename (acquired by the classdef-table)
Definition: classdef.h:149
ClassdefFollow followup
Other calls to follow.
Definition: classdef.h:143
void mutateToBuiltin(nytype_t)
Mutate the type to builtin (not void)
Definition: classdef.hxx:95
bool isLinkedToAtom() const
Get if the type is defined by an atom (an &#39;atom&#39; is provided)
Definition: classdef.hxx:67
Definition: classdef-follow.h:11
bool isBuiltingUnsigned() const
Get if the classdef is a builtin unsigned int (u32, u64...)
Definition: classdef.hxx:49
ClassdefInterface interface
Interface.
Definition: classdef.h:141
Definition: interface.h:11
bool operator==(const Classdef &) const
Comparison.
void mutateToAny()
Mutate the type to any.
Definition: classdef.hxx:107
Definition: clid.h:11
bool hasAtom() const
Get if the classdef has a linked atom.
Definition: classdef.hxx:79
CLID clid
Classdef ID.
Definition: classdef.h:132
void mutateToAtom(Atom *)
Mutate to a well-known type (from atom)
Definition: classdef.hxx:113
Class definition.
Definition: classdef.h:24
bool isBuiltinU8() const
Get if the classdef is a builtin u32.
Definition: classdef.hxx:44
Atom * atom
Atom.
Definition: classdef.h:130
Qualifiers qualifiers
All qualifiers (can be shared between several classdef)
Definition: classdef.h:139
Definition: ast.cpp:6
bool isBuiltinU64() const
Get if the classdef is a builtin u64.
Definition: classdef.hxx:34
bool isClass() const
Get if the type is a class.
Definition: classdef.cpp:54
bool instance
Has a value ? (is a variable)
Definition: classdef.h:136
void mutateToPtr2Func(Atom *)
Mutate to a ptr-2-func/method.
Definition: classdef.hxx:119
Classdef & operator=(const Classdef &)=delete
Assignment.
bool isBuiltin() const
Get if the classdef is a builtin type (not &#39;void&#39;)
Definition: classdef.hxx:19
bool isAny() const
Get if the type is &#39;any&#39;.
Definition: classdef.hxx:74
bool hasConstraints() const
Get if the classdef has some constraints.
Definition: classdef.hxx:125
Definition of a single class or function.
Definition: atom.h:37
void mutateToBuiltinOrVoid(nytype_t)
Mutate the type to builtin (or void)
Definition: classdef.hxx:101
bool operator!=(const Classdef &) const
Not equal.
bool isVoid() const
Get if the classdef is void.
Definition: classdef.hxx:62
nytype_t kind
Inner builtin type (custom type if == nyt_any)
Definition: classdef.h:128
bool isVariable() const
Get if is a variable.
Definition: classdef.hxx:84
bool isRawPointer() const
Get if the classdef is a builtin pointer.
Definition: classdef.hxx:29
bool isBuiltinOrVoid() const
Get if the classdef is a builtin type (&#39;void&#39; included)
Definition: classdef.hxx:24
Definition: report.h:17
CLID parentclid
Parent class ID.
Definition: classdef.h:134
void mutateToVoid()
Mutate the defintiion to &#39;void&#39;.
Definition: classdef.hxx:89
void print(Yuni::String &out, const ClassdefTableView &table, bool clearBefore=true) const
Export the classdef to a human readable string.
Definition: classdef.cpp:42
bool isBuiltinU32() const
Get if the classdef is a builtin u32.
Definition: classdef.hxx:39
static const Classdef nullcdef
Null cdef.
Definition: classdef.h:27
Definition: qualifiers.h:9
Classdef()
Default constructor.
Definition: classdef.hxx:8
Definition: classdef-table-view.h:9