nany
classdef.hxx
1 #pragma once
2 #include "classdef.h"
3 
4 
5 namespace ny {
6 
7 
9  : qualifiers() {
10 }
11 
12 
14  : kind(nyt_any)
15  , clid(clid) {
16 }
17 
18 
19 inline bool Classdef::isBuiltin() const {
20  return (kind != nyt_void) and (kind != nyt_any);
21 }
22 
23 
24 inline bool Classdef::isBuiltinOrVoid() const {
25  return kind != nyt_any;
26 }
27 
28 
29 inline bool Classdef::isRawPointer() const {
30  return kind == nyt_ptr and (atom == nullptr);
31 }
32 
33 
34 inline bool Classdef::isBuiltinU64() const {
35  return kind == nyt_u64;
36 }
37 
38 
39 inline bool Classdef::isBuiltinU32() const {
40  return kind == nyt_u32;
41 }
42 
43 
44 inline bool Classdef::isBuiltinU8() const {
45  return kind == nyt_u8;
46 }
47 
48 
49 inline bool Classdef::isBuiltingUnsigned() const {
50  switch (kind) {
51  case nyt_u8:
52  case nyt_u16:
53  case nyt_u32:
54  case nyt_u64:
55  return true;
56  default:
57  return false;
58  }
59 }
60 
61 
62 inline bool Classdef::isVoid() const {
63  return kind == nyt_void;
64 }
65 
66 
67 inline bool Classdef::isLinkedToAtom() const {
68  assert((nullptr == atom or (kind == nyt_any))
69  and "the kind of a classdef must be 'any' if an atom is provided");
70  return nullptr != atom;
71 }
72 
73 
74 inline bool Classdef::isAny() const {
75  return (nullptr == atom) and (kind == nyt_any);
76 }
77 
78 
79 inline bool Classdef::hasAtom() const {
80  return nullptr != atom;
81 }
82 
83 
84 inline bool Classdef::isVariable() const {
85  return instance;
86 }
87 
88 
89 inline void Classdef::mutateToVoid() {
90  kind = nyt_void;
91  atom = nullptr;
92 }
93 
94 
95 inline void Classdef::mutateToBuiltin(nytype_t newkind) {
96  assert(newkind != nyt_void and newkind != nyt_any);
97  kind = newkind;
98  atom = nullptr;
99 }
100 
101 inline void Classdef::mutateToBuiltinOrVoid(nytype_t newkind) {
102  assert(newkind != nyt_any);
103  kind = newkind;
104  atom = nullptr;
105 }
106 
107 inline void Classdef::mutateToAny() {
108  kind = nyt_any;
109  atom = nullptr;
110 }
111 
112 
113 inline void Classdef::mutateToAtom(Atom* newAtom) {
114  kind = nyt_any;
115  atom = newAtom;
116 }
117 
118 
119 inline void Classdef::mutateToPtr2Func(Atom* newAtom) {
120  kind = nyt_ptr;
121  atom = newAtom;
122 }
123 
124 
125 inline bool Classdef::hasConstraints() const {
126  return not isAny() or not interface.empty() or not followup.empty(); // TODO qualifiers ???
127 }
128 
129 
130 inline void Classdef::import(const Classdef& rhs) {
131  kind = rhs.kind;
132  atom = rhs.atom;
133  parentclid = rhs.parentclid;
134  instance = rhs.instance;
135  interface = rhs.interface; // mandatory to preserve constraints
136  followup = rhs.followup; // same here
137  origins = rhs.origins;
138  // qualifiers should be preserved
139  // qualifiers = rhs.qualifiers;
140 }
141 
142 
143 inline YString Classdef::print(const ClassdefTableView& table) const {
144  YString out;
145  print(out, table);
146  return out;
147 }
148 
149 
150 } // namespace ny
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 'atom' is provided)
Definition: classdef.hxx:67
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
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
bool empty() const
Get if the container is empty.
Definition: interface.hxx:25
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
Definition: ast.cpp:6
bool isBuiltinU64() const
Get if the classdef is a builtin u64.
Definition: classdef.hxx:34
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
bool isBuiltin() const
Get if the classdef is a builtin type (not 'void')
Definition: classdef.hxx:19
bool isAny() const
Get if the type is 'any'.
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
void import(const Classdef &rhs)
Import from another classdef.
Definition: classdef.hxx:130
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 ('void' included)
Definition: classdef.hxx:24
CLID parentclid
Parent class ID.
Definition: classdef.h:134
void mutateToVoid()
Mutate the defintiion to 'void'.
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
Classdef()
Default constructor.
Definition: classdef.hxx:8
Definition: classdef-table-view.h:9