Qore Programming Language  1.12.0
QoreType.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreType.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2022 Qore Technologies, s.r.o.
8 
9  Permission is hereby granted, free of charge, to any person obtaining a
10  copy of this software and associated documentation files (the "Software"),
11  to deal in the Software without restriction, including without limitation
12  the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  and/or sell copies of the Software, and to permit persons to whom the
14  Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  DEALINGS IN THE SOFTWARE.
26 
27  Note that the Qore library is released under a choice of three open-source
28  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29  information.
30 */
31 
32 #ifndef _QORE_QORETYPE_H
33 
34 #define _QORE_QORETYPE_H
35 
36 #include <qore/common.h>
37 #include <qore/node_types.h>
38 
39 #include <map>
40 
41 // global default values
42 DLLEXPORT extern QoreListNode* emptyList;
43 DLLEXPORT extern QoreHashNode* emptyHash;
44 DLLEXPORT extern QoreStringNode* NullString;
45 DLLEXPORT extern DateTimeNode* ZeroDate;
46 DLLEXPORT extern QoreNumberNode* ZeroNumber, * InfinityNumber, * NaNumber, * piNumber;
47 
48 DLLEXPORT extern QoreString NothingTypeString, NullTypeString, TrueString,
49  FalseString, EmptyHashString, EmptyListString;
50 
51 DLLEXPORT extern const QoreTypeInfo* anyTypeInfo,
52  *autoTypeInfo,
53  *bigIntTypeInfo,
54  *floatTypeInfo,
55  *boolTypeInfo,
56  *stringTypeInfo,
57  *binaryTypeInfo,
58  *dateTypeInfo,
59  *objectTypeInfo,
60  *hashTypeInfo,
61  *emptyHashTypeInfo,
62  *autoHashTypeInfo,
63  *listTypeInfo,
64  *autoListTypeInfo,
65  *emptyListTypeInfo,
66  *nothingTypeInfo,
67  *nullTypeInfo,
68  *numberTypeInfo,
69  *runTimeClosureTypeInfo,
70  *callReferenceTypeInfo,
71  *referenceTypeInfo,
72  *codeTypeInfo, // either closure or callref
73  *hexBinaryTypeInfo,
74  *base64BinaryTypeInfo,
75  *softBinaryTypeInfo, // converts to binary from string and null
76  *softBigIntTypeInfo, // converts to int from float, string, bool, number, and null
77  *softFloatTypeInfo, // converts to float from int, string, bool, number, and null
78  *softNumberTypeInfo, // converts to number from int, string, bool, float, and null
79  *softBoolTypeInfo, // converts to bool from int, float, string, number, and null
80  *softStringTypeInfo, // converts to string from int, float, bool, number, and null
81  *softDateTypeInfo, // converts to date from int, float, bool, string, number, and null
82  *softListTypeInfo, // converts NOTHING -> empty list, list -> the same list, and everything else: list(arg)
83  *softAutoListTypeInfo,
84  *dataTypeInfo, // either string or binary
85  *timeoutTypeInfo, // accepts int or date and returns int giving timeout in milliseconds
86  *bigIntOrFloatTypeInfo, // accepts int or float and returns the same
87  *bigIntFloatOrNumberTypeInfo, // accepts int or float and returns the same
88  *floatOrNumberTypeInfo, // accepts float or number and returns the same
89 
90  *bigIntOrNothingTypeInfo,
91  *floatOrNothingTypeInfo,
92  *numberOrNothingTypeInfo,
93  *stringOrNothingTypeInfo,
94  *boolOrNothingTypeInfo,
95  *binaryOrNothingTypeInfo,
96  *objectOrNothingTypeInfo,
97  *dateOrNothingTypeInfo,
98  *hashOrNothingTypeInfo,
99  *autoHashOrNothingTypeInfo,
100  *listOrNothingTypeInfo,
101  *autoListOrNothingTypeInfo,
102  *nullOrNothingTypeInfo,
103  *codeOrNothingTypeInfo,
104  *dataOrNothingTypeInfo,
105  *referenceOrNothingTypeInfo,
106 
107  *hexBinaryOrNothingTypeInfo,
108  *base64BinaryOrNothingTypeInfo,
109  *softBinaryOrNothingTypeInfo,
110  *softBigIntOrNothingTypeInfo,
111  *softFloatOrNothingTypeInfo,
112  *softNumberOrNothingTypeInfo,
113  *softBoolOrNothingTypeInfo,
114  *softStringOrNothingTypeInfo,
115  *softDateOrNothingTypeInfo,
116  *softListOrNothingTypeInfo,
117  *softAutoListOrNothingTypeInfo,
118  *timeoutOrNothingTypeInfo;
119 
120 DLLEXPORT qore_type_t get_next_type_id();
121 
123 DLLEXPORT bool compareHard(const AbstractQoreNode* l, const AbstractQoreNode* r, ExceptionSink* xsink);
125 DLLEXPORT bool compareSoft(const AbstractQoreNode* l, const AbstractQoreNode* r, ExceptionSink* xsink);
127 DLLEXPORT bool q_compare_soft(const QoreValue l, const QoreValue r, ExceptionSink* xsink);
128 
129 static inline QoreNumberNode* zero_number() {
130  ZeroNumber->ref();
131  return ZeroNumber;
132 }
133 
134 static inline DateTimeNode* zero_date() {
135  ZeroDate->ref();
136  return ZeroDate;
137 }
138 
139 static inline class QoreStringNode* null_string() {
140  NullString->ref();
141  return NullString;
142 }
143 
144 static inline QoreListNode* empty_list() {
145  emptyList->ref();
146  return emptyList;
147 }
148 
149 static inline QoreHashNode* empty_hash() {
150  emptyHash->ref();
151  return emptyHash;
152 }
153 
154 static inline QoreNumberNode* pi_number() {
155  piNumber->ref();
156  return piNumber;
157 }
158 
160 enum qore_type_result_e {
161  QTI_IGNORE = -2,
162  QTI_UNASSIGNED = -1,
163 
164  QTI_NOT_EQUAL = 0,
165  QTI_WILDCARD = 1,
166  QTI_AMBIGUOUS = 2,
167  QTI_NEAR = 3,
168  QTI_IDENT = 4
169 };
170 
171 DLLEXPORT int testObjectClassAccess(const QoreObject* obj, const QoreClass* classtoaccess);
172 
173 DLLEXPORT const QoreClass* typeInfoGetUniqueReturnClass(const QoreTypeInfo* typeInfo);
174 DLLEXPORT bool typeInfoHasType(const QoreTypeInfo* typeInfo);
175 DLLEXPORT const char* typeInfoGetName(const QoreTypeInfo* typeInfo);
176 DLLEXPORT const QoreTypeInfo* typeInfoGetElementType(const QoreTypeInfo* typeInfo);
177 DLLEXPORT const TypedHashDecl* typeInfoGetTypedHash(const QoreTypeInfo* typeInfo);
178 
179 DLLEXPORT qore_type_result_e typeInfoAcceptsType(const QoreTypeInfo* typeInfo, const QoreTypeInfo* otherTypeInfo);
180 DLLEXPORT qore_type_result_e typeInfoReturnsType(const QoreTypeInfo* typeInfo, const QoreTypeInfo* otherTypeInfo);
181 
182 // Returns a non "or nothing" type for the given "or nothing" type
187 DLLEXPORT const QoreTypeInfo* qore_get_value_type(const QoreTypeInfo* typeInfo);
188 
189 DLLEXPORT const QoreTypeInfo* qore_get_or_nothing_type(const QoreTypeInfo* typeInfo);
190 
191 // @since %Qore 0.8.13
192 DLLEXPORT const QoreTypeInfo* qore_get_complex_hash_type(const QoreTypeInfo* valueTypeInfo);
193 // @since %Qore 0.8.13
194 DLLEXPORT const QoreTypeInfo* qore_get_complex_hash_or_nothing_type(const QoreTypeInfo* valueTypeInfo);
195 // @since %Qore 0.8.13
196 DLLEXPORT const QoreTypeInfo* qore_get_complex_list_type(const QoreTypeInfo* valueTypeInfo);
197 // @since %Qore 0.8.13
198 DLLEXPORT const QoreTypeInfo* qore_get_complex_list_or_nothing_type(const QoreTypeInfo* valueTypeInfo);
199 // @since %Qore 0.8.13
200 DLLEXPORT const QoreTypeInfo* qore_get_complex_softlist_type(const QoreTypeInfo* valueTypeInfo);
201 // @since %Qore 0.8.13
202 DLLEXPORT const QoreTypeInfo* qore_get_complex_softlist_or_nothing_type(const QoreTypeInfo* valueTypeInfo);
203 // @since %Qore 0.8.13
204 DLLEXPORT const QoreTypeInfo* qore_get_complex_reference_type(const QoreTypeInfo* valueTypeInfo);
205 // @since %Qore 0.8.13
206 DLLEXPORT const QoreTypeInfo* qore_get_complex_reference_or_nothing_type(const QoreTypeInfo* valueTypeInfo);
207 
208 // @since %Qore 0.9.4
209 DLLEXPORT const QoreTypeInfo* qore_get_type_from_string(const char* str, ExceptionSink& xsink);
210 
211 // @since %Qore 1.0
212 DLLEXPORT const QoreClass* type_info_get_return_class(const QoreTypeInfo* typeInfo);
213 
214 #endif // _QORE_QORETYPE_H
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
DLLEXPORT void ref() const
increments the reference count
Qore's parse tree/value type for date-time values, reference-counted, dynamically-allocated only.
Definition: DateTimeNode.h:45
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
defines a Qore-language class
Definition: QoreClass.h:249
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
Qore's arbitrary-precision number value type, dynamically-allocated only, reference counted.
Definition: QoreNumberNode.h:51
the implementation of Qore's object data type, reference counted, dynamically-allocated only
Definition: QoreObject.h:60
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
typed hash declaration
Definition: TypedHashDecl.h:44
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode)
Definition: common.h:70
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:275