Qore Programming Language - C/C++ Library  0.8.12.3
QoreType.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreType.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2015 David Nichols
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 QoreBigIntNode* Zero;
47 DLLEXPORT extern QoreFloatNode* ZeroFloat;
48 DLLEXPORT extern QoreNumberNode* ZeroNumber, * InfinityNumber, * NaNumber, * piNumber;
49 
50 DLLEXPORT extern QoreString NothingTypeString, NullTypeString, TrueString,
51  FalseString, EmptyHashString, EmptyListString;
52 
53 class QoreTypeInfo;
54 DLLEXPORT extern const QoreTypeInfo* anyTypeInfo,
55  *bigIntTypeInfo,
56  *floatTypeInfo,
57  *boolTypeInfo,
58  *stringTypeInfo,
59  *binaryTypeInfo,
60  *dateTypeInfo,
61  *objectTypeInfo,
62  *hashTypeInfo,
63  *listTypeInfo,
64  *nothingTypeInfo,
65  *nullTypeInfo,
66  *numberTypeInfo,
67  *runTimeClosureTypeInfo,
68  *callReferenceTypeInfo,
69  *referenceTypeInfo,
70  *userReferenceTypeInfo,
71  *codeTypeInfo, // either closure or callref
72  *softBigIntTypeInfo, // converts to int from float, string, and bool
73  *softFloatTypeInfo, // converts to float from int, string, and bool
74  *softNumberTypeInfo, // xxx
75  *softBoolTypeInfo, // converts to bool from int, float, and string
76  *softStringTypeInfo, // converts to string from int, float, and bool
77  *softDateTypeInfo, // converts to date from int, float, bool, and string
78  *softListTypeInfo, // converts NOTHING -> empty list, list -> the same list, and everything else: list(arg)
79  *somethingTypeInfo, // i.e. not "NOTHING"
80  *dataTypeInfo, // either string or binary
81  *timeoutTypeInfo, // accepts int or date and returns int giving timeout in milliseconds
82  *bigIntOrFloatTypeInfo, // accepts int or float and returns the same
83 
84  *bigIntOrNothingTypeInfo,
85  *floatOrNothingTypeInfo,
86  *numberOrNothingTypeInfo,
87  *stringOrNothingTypeInfo,
88  *boolOrNothingTypeInfo,
89  *binaryOrNothingTypeInfo,
90  *objectOrNothingTypeInfo,
91  *dateOrNothingTypeInfo,
92  *hashOrNothingTypeInfo,
93  *listOrNothingTypeInfo,
94  *nullOrNothingTypeInfo,
95  *codeOrNothingTypeInfo,
96  *dataOrNothingTypeInfo,
97  *referenceOrNothingTypeInfo,
98 
99  *softBigIntOrNothingTypeInfo,
100  *softFloatOrNothingTypeInfo,
101  *softNumberOrNothingTypeInfo,
102  *softBoolOrNothingTypeInfo,
103  *softStringOrNothingTypeInfo,
104  *softDateOrNothingTypeInfo,
105  *softListOrNothingTypeInfo,
106  *timeoutOrNothingTypeInfo;
107 
108 DLLEXPORT qore_type_t get_next_type_id();
109 
111 DLLEXPORT bool compareHard(const AbstractQoreNode* l, const AbstractQoreNode* r, ExceptionSink* xsink);
113 DLLEXPORT bool compareSoft(const AbstractQoreNode* l, const AbstractQoreNode* r, ExceptionSink* xsink);
115 DLLEXPORT bool q_compare_soft(const QoreValue l, const QoreValue r, ExceptionSink* xsink);
116 
117 static inline AbstractQoreNode* boolean_false() {
118  return &False;
119 }
120 
121 static inline AbstractQoreNode* boolean_true() {
122  return &True;
123 }
124 
125 static inline QoreBigIntNode* zero() {
126  Zero->ref();
127  return Zero;
128 }
129 
130 static inline QoreFloatNode* zero_float() {
131  ZeroFloat->ref();
132  return ZeroFloat;
133 }
134 
135 static inline QoreNumberNode* zero_number() {
136  ZeroNumber->ref();
137  return ZeroNumber;
138 }
139 
140 static inline DateTimeNode* zero_date() {
141  ZeroDate->ref();
142  return ZeroDate;
143 }
144 
145 static inline class QoreStringNode* null_string() {
146  NullString->ref();
147  return NullString;
148 }
149 
150 static inline QoreListNode* empty_list() {
151  emptyList->ref();
152  return emptyList;
153 }
154 
155 static inline QoreHashNode* empty_hash() {
156  emptyHash->ref();
157  return emptyHash;
158 }
159 
160 static inline QoreNumberNode* pi_number() {
161  piNumber->ref();
162  return piNumber;
163 }
164 
166 enum qore_type_result_e {
167  QTI_IGNORE = -2,
168  QTI_UNASSIGNED = -1,
169 
170  QTI_NOT_EQUAL = 0,
171  QTI_AMBIGUOUS = 1,
172  QTI_IDENT = 2
173 };
174 
176 class ExternalTypeInfo;
177 struct QoreValue;
178 
180 
183  friend class ExternalTypeInfo;
184 
185 protected:
186  ExternalTypeInfo* typeInfo;
187 
188  DLLLOCAL QoreTypeInfoHelper(ExternalTypeInfo* n_typeInfo) : typeInfo(n_typeInfo) {
189  }
190 
192  DLLEXPORT virtual bool acceptInputImpl(QoreValue& n, ExceptionSink* xsink) const;
193 
194 public:
196  DLLEXPORT QoreTypeInfoHelper(const char* n_tname);
198  DLLEXPORT QoreTypeInfoHelper(qore_type_t id, const char* n_tname);
200  DLLEXPORT virtual ~QoreTypeInfoHelper();
202  DLLEXPORT const QoreTypeInfo* getTypeInfo() const;
204  DLLEXPORT void assign(qore_type_t id);
206  DLLEXPORT void addAcceptsType(const QoreTypeInfo* n_typeInfo);
208  DLLEXPORT void setInt();
210  DLLEXPORT void setInexactReturn();
212  DLLEXPORT void setInputFilter();
214  DLLEXPORT void setIntMatch();
215 
216  DLLEXPORT int doAcceptError(bool priv_error, bool obj, int param_num, const char* param_name, AbstractQoreNode* n, ExceptionSink* xsink) const;
217 };
218 
221 protected:
222  QoreClass* qc;
223 
224 public:
226  DLLEXPORT AbstractQoreClassTypeInfoHelper(const char* name, int n_domain = QDOM_DEFAULT);
230  DLLEXPORT QoreClass *getClass();
232  DLLEXPORT bool hasClass() const;
233 };
234 
235 DLLEXPORT int testObjectClassAccess(const QoreObject *obj, const QoreClass *classtoaccess);
236 
237 DLLEXPORT const QoreClass *typeInfoGetUniqueReturnClass(const QoreTypeInfo* typeInfo);
238 DLLEXPORT bool typeInfoHasType(const QoreTypeInfo* typeInfo);
239 DLLEXPORT const char* typeInfoGetName(const QoreTypeInfo* typeInfo);
240 DLLEXPORT qore_type_result_e typeInfoAcceptsType(const QoreTypeInfo* typeInfo, const QoreTypeInfo* otherTypeInfo);
241 DLLEXPORT qore_type_result_e typeInfoReturnsType(const QoreTypeInfo* typeInfo, const QoreTypeInfo* otherTypeInfo);
242 
243 #endif // _QORE_QORETYPE_H
DLLEXPORT AbstractQoreClassTypeInfoHelper(const char *name, int n_domain=QDOM_DEFAULT)
allocates a QoreTypeInfo object and creates the QoreClass
Qore's arbitrary-precision number value type, dynamically-allocated only, reference counted...
Definition: QoreNumberNode.h:52
Qore's floating-point value type, dynamically-allocated only, reference counted.
Definition: QoreFloatNode.h:40
DLLEXPORT const QoreTypeInfo * getTypeInfo() const
returns a pointer to the object
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:49
DLLEXPORT QoreBoolFalseNode False
Qore's boolean false value.
DLLEXPORT QoreClass * getClass()
returns the QoreClass object created and zeros out the class ptr; can only be called once ...
DLLEXPORT bool hasClass() const
returns true if this object is holding a class pointer, false if not
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
DLLEXPORT void setIntMatch()
set a flag so that any NT_INT in an accept list will match any type with is_int set with QTI_AMBIGUOU...
DLLEXPORT void setInt()
set a flag that means the type is equivalent to an integer
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:82
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
DLLEXPORT QoreBoolTrueNode True
Qore's boolean true value.
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
virtual DLLEXPORT bool acceptInputImpl(QoreValue &n, ExceptionSink *xsink) const
this function must be reimplemented if setInputFilter() is called
Qore's parse tree/value type for date-time values, reference-counted, dynamically-allocated only...
Definition: DateTimeNode.h:44
defines a Qore-language class
Definition: QoreClass.h:195
DLLEXPORT void assign(qore_type_t id)
assigns the typeid to the object
DLLEXPORT void setInputFilter()
set a flag that means that acceptInputImpl() has been reimplemented and should be used ...
DLLEXPORT void setInexactReturn()
set a flag that means that if the return type is matched on input, it matches with QTI_AMBIGUOUS inst...
note that the QoreClass object created by this class must be deleted externally
Definition: QoreType.h:220
DLLEXPORT void ref() const
increments the reference count
the implementation of Qore's object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:64
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:43
DLLEXPORT ~AbstractQoreClassTypeInfoHelper()
delets the QoreClass object managed if it has not been retrieved
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:68
helper type to allocate and manage QoreTypeInfo objects (not exported by the library) ...
Definition: QoreType.h:182
DLLEXPORT void addAcceptsType(const QoreTypeInfo *n_typeInfo)
add another type that the type accepts
this class implements Qore's 64-bit integer data type, reference-counted, dynamically-allocated only ...
Definition: QoreBigIntNode.h:41
virtual DLLEXPORT ~QoreTypeInfoHelper()
deallocates the managed QoreTypeInfo object
#define QDOM_DEFAULT
the default domain (no domain)
Definition: Restrictions.h:137