Qore Programming Language  0.8.11.1
QoreType.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreType.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2014 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 
110 DLLEXPORT bool compareHard(const AbstractQoreNode* l, const AbstractQoreNode* r, ExceptionSink* xsink);
111 DLLEXPORT bool compareSoft(const AbstractQoreNode* l, const AbstractQoreNode* r, ExceptionSink* xsink);
112 
113 static inline AbstractQoreNode* boolean_false() {
114  return &False;
115 }
116 
117 static inline AbstractQoreNode* boolean_true() {
118  return &True;
119 }
120 
121 static inline QoreBigIntNode* zero() {
122  Zero->ref();
123  return Zero;
124 }
125 
126 static inline QoreFloatNode* zero_float() {
127  ZeroFloat->ref();
128  return ZeroFloat;
129 }
130 
131 static inline QoreNumberNode* zero_number() {
132  ZeroNumber->ref();
133  return ZeroNumber;
134 }
135 
136 static inline DateTimeNode* zero_date() {
137  ZeroDate->ref();
138  return ZeroDate;
139 }
140 
141 static inline class QoreStringNode* null_string() {
142  NullString->ref();
143  return NullString;
144 }
145 
146 static inline QoreListNode* empty_list() {
147  emptyList->ref();
148  return emptyList;
149 }
150 
151 static inline QoreHashNode* empty_hash() {
152  emptyHash->ref();
153  return emptyHash;
154 }
155 
156 static inline QoreNumberNode* pi_number() {
157  piNumber->ref();
158  return piNumber;
159 }
160 
162 enum qore_type_result_e {
163  QTI_IGNORE = -2,
164  QTI_UNASSIGNED = -1,
165 
166  QTI_NOT_EQUAL = 0,
167  QTI_AMBIGUOUS = 1,
168  QTI_IDENT = 2
169 };
170 
172 class ExternalTypeInfo;
173 
175 
178  friend class ExternalTypeInfo;
179 
180 protected:
181  ExternalTypeInfo* typeInfo;
182 
183  DLLLOCAL QoreTypeInfoHelper(ExternalTypeInfo* n_typeInfo) : typeInfo(n_typeInfo) {
184  }
185 
187  DLLEXPORT virtual bool acceptInputImpl(AbstractQoreNode*& n, ExceptionSink* xsink) const;
188 
189 public:
191  DLLEXPORT QoreTypeInfoHelper(const char* n_tname);
193  DLLEXPORT QoreTypeInfoHelper(qore_type_t id, const char* n_tname);
195  DLLEXPORT virtual ~QoreTypeInfoHelper();
197  DLLEXPORT const QoreTypeInfo* getTypeInfo() const;
199  DLLEXPORT void assign(qore_type_t id);
201  DLLEXPORT void addAcceptsType(const QoreTypeInfo* n_typeInfo);
203  DLLEXPORT void setInt();
205  DLLEXPORT void setInexactReturn();
207  DLLEXPORT void setInputFilter();
209  DLLEXPORT void setIntMatch();
210 
211  DLLEXPORT int doAcceptError(bool priv_error, bool obj, int param_num, const char* param_name, AbstractQoreNode* n, ExceptionSink* xsink) const;
212 };
213 
216 protected:
217  QoreClass* qc;
218 
219 public:
221  DLLEXPORT AbstractQoreClassTypeInfoHelper(const char* name, int n_domain = QDOM_DEFAULT);
225  DLLEXPORT QoreClass *getClass();
227  DLLEXPORT bool hasClass() const;
228 };
229 
230 DLLEXPORT int testObjectClassAccess(const QoreObject *obj, const QoreClass *classtoaccess);
231 
232 DLLEXPORT const QoreClass *typeInfoGetUniqueReturnClass(const QoreTypeInfo* typeInfo);
233 DLLEXPORT bool typeInfoHasType(const QoreTypeInfo* typeInfo);
234 DLLEXPORT const char* typeInfoGetName(const QoreTypeInfo* typeInfo);
235 DLLEXPORT qore_type_result_e typeInfoAcceptsType(const QoreTypeInfo* typeInfo, const QoreTypeInfo* otherTypeInfo);
236 DLLEXPORT qore_type_result_e typeInfoReturnsType(const QoreTypeInfo* typeInfo, const QoreTypeInfo* otherTypeInfo);
237 
238 #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
signed short qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:67
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:50
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:48
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
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:194
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:215
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
helper type to allocate and manage QoreTypeInfo objects (not exported by the library) ...
Definition: QoreType.h:177
virtual DLLEXPORT bool acceptInputImpl(AbstractQoreNode *&n, ExceptionSink *xsink) const
this function must be reimplemented if setInputFilter() is called
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:110