Qore Programming Language  0.8.11
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreType.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreType.h
4 
5  Qore Programming Language
6 
7  Copyright 2003 - 2013 David Nichols
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 
24 #ifndef _QORE_QORETYPE_H
25 
26 #define _QORE_QORETYPE_H
27 
28 #include <qore/common.h>
29 #include <qore/node_types.h>
30 
31 #include <map>
32 
33 // global default values
34 DLLEXPORT extern QoreListNode* emptyList;
35 DLLEXPORT extern QoreHashNode* emptyHash;
36 DLLEXPORT extern QoreStringNode* NullString;
37 DLLEXPORT extern DateTimeNode* ZeroDate;
38 DLLEXPORT extern QoreBigIntNode* Zero;
39 DLLEXPORT extern QoreFloatNode* ZeroFloat;
40 DLLEXPORT extern QoreNumberNode* ZeroNumber, * InfinityNumber, * NaNumber, * piNumber;
41 
42 DLLEXPORT extern QoreString NothingTypeString, NullTypeString, TrueString,
43  FalseString, EmptyHashString, EmptyListString;
44 
45 class QoreTypeInfo;
46 DLLEXPORT extern const QoreTypeInfo* anyTypeInfo,
47  *bigIntTypeInfo,
48  *floatTypeInfo,
49  *boolTypeInfo,
50  *stringTypeInfo,
51  *binaryTypeInfo,
52  *dateTypeInfo,
53  *objectTypeInfo,
54  *hashTypeInfo,
55  *listTypeInfo,
56  *nothingTypeInfo,
57  *nullTypeInfo,
58  *numberTypeInfo,
59  *runTimeClosureTypeInfo,
60  *callReferenceTypeInfo,
61  *referenceTypeInfo,
62  *userReferenceTypeInfo,
63  *codeTypeInfo, // either closure or callref
64  *softBigIntTypeInfo, // converts to int from float, string, and bool
65  *softFloatTypeInfo, // converts to float from int, string, and bool
66  *softNumberTypeInfo, // xxx
67  *softBoolTypeInfo, // converts to bool from int, float, and string
68  *softStringTypeInfo, // converts to string from int, float, and bool
69  *softDateTypeInfo, // converts to date from int, float, bool, and string
70  *softListTypeInfo, // converts NOTHING -> empty list, list -> the same list, and everything else: list(arg)
71  *somethingTypeInfo, // i.e. not "NOTHING"
72  *dataTypeInfo, // either string or binary
73  *timeoutTypeInfo, // accepts int or date and returns int giving timeout in milliseconds
74  *bigIntOrFloatTypeInfo, // accepts int or float and returns the same
75 
76  *bigIntOrNothingTypeInfo,
77  *floatOrNothingTypeInfo,
78  *numberOrNothingTypeInfo,
79  *stringOrNothingTypeInfo,
80  *boolOrNothingTypeInfo,
81  *binaryOrNothingTypeInfo,
82  *objectOrNothingTypeInfo,
83  *dateOrNothingTypeInfo,
84  *hashOrNothingTypeInfo,
85  *listOrNothingTypeInfo,
86  *nullOrNothingTypeInfo,
87  *codeOrNothingTypeInfo,
88  *dataOrNothingTypeInfo,
89  *referenceOrNothingTypeInfo,
90 
91  *softBigIntOrNothingTypeInfo,
92  *softFloatOrNothingTypeInfo,
93  *softNumberOrNothingTypeInfo,
94  *softBoolOrNothingTypeInfo,
95  *softStringOrNothingTypeInfo,
96  *softDateOrNothingTypeInfo,
97  *softListOrNothingTypeInfo,
98  *timeoutOrNothingTypeInfo;
99 
100 DLLEXPORT qore_type_t get_next_type_id();
101 
102 DLLEXPORT bool compareHard(const AbstractQoreNode* l, const AbstractQoreNode* r, ExceptionSink* xsink);
103 DLLEXPORT bool compareSoft(const AbstractQoreNode* l, const AbstractQoreNode* r, ExceptionSink* xsink);
104 
105 static inline AbstractQoreNode* boolean_false() {
106  return &False;
107 }
108 
109 static inline AbstractQoreNode* boolean_true() {
110  return &True;
111 }
112 
113 static inline QoreBigIntNode* zero() {
114  Zero->ref();
115  return Zero;
116 }
117 
118 static inline QoreFloatNode* zero_float() {
119  ZeroFloat->ref();
120  return ZeroFloat;
121 }
122 
123 static inline QoreNumberNode* zero_number() {
124  ZeroNumber->ref();
125  return ZeroNumber;
126 }
127 
128 static inline DateTimeNode* zero_date() {
129  ZeroDate->ref();
130  return ZeroDate;
131 }
132 
133 static inline class QoreStringNode* null_string() {
134  NullString->ref();
135  return NullString;
136 }
137 
138 static inline QoreListNode* empty_list() {
139  emptyList->ref();
140  return emptyList;
141 }
142 
143 static inline QoreHashNode* empty_hash() {
144  emptyHash->ref();
145  return emptyHash;
146 }
147 
148 static inline QoreNumberNode* pi_number() {
149  piNumber->ref();
150  return piNumber;
151 }
152 
154 enum qore_type_result_e {
155  QTI_IGNORE = -2,
156  QTI_UNASSIGNED = -1,
157 
158  QTI_NOT_EQUAL = 0,
159  QTI_AMBIGUOUS = 1,
160  QTI_IDENT = 2
161 };
162 
164 class ExternalTypeInfo;
165 
167 
170  friend class ExternalTypeInfo;
171 
172 protected:
173  ExternalTypeInfo* typeInfo;
174 
175  DLLLOCAL QoreTypeInfoHelper(ExternalTypeInfo* n_typeInfo) : typeInfo(n_typeInfo) {
176  }
177 
179  DLLEXPORT virtual bool acceptInputImpl(AbstractQoreNode*& n, ExceptionSink* xsink) const;
180 
181 public:
183  DLLEXPORT QoreTypeInfoHelper(const char* n_tname);
185  DLLEXPORT QoreTypeInfoHelper(qore_type_t id, const char* n_tname);
187  DLLEXPORT virtual ~QoreTypeInfoHelper();
189  DLLEXPORT const QoreTypeInfo* getTypeInfo() const;
191  DLLEXPORT void assign(qore_type_t id);
193  DLLEXPORT void addAcceptsType(const QoreTypeInfo* n_typeInfo);
195  DLLEXPORT void setInt();
197  DLLEXPORT void setInexactReturn();
199  DLLEXPORT void setInputFilter();
201  DLLEXPORT void setIntMatch();
202 
203  DLLEXPORT int doAcceptError(bool priv_error, bool obj, int param_num, const char* param_name, AbstractQoreNode* n, ExceptionSink* xsink) const;
204 };
205 
208 protected:
209  QoreClass* qc;
210 
211 public:
213  DLLEXPORT AbstractQoreClassTypeInfoHelper(const char* name, int n_domain = QDOM_DEFAULT);
217  DLLEXPORT QoreClass *getClass();
219  DLLEXPORT bool hasClass() const;
220 };
221 
222 DLLEXPORT int testObjectClassAccess(const QoreObject *obj, const QoreClass *classtoaccess);
223 
224 DLLEXPORT const QoreClass *typeInfoGetUniqueReturnClass(const QoreTypeInfo* typeInfo);
225 DLLEXPORT bool typeInfoHasType(const QoreTypeInfo* typeInfo);
226 DLLEXPORT const char* typeInfoGetName(const QoreTypeInfo* typeInfo);
227 DLLEXPORT qore_type_result_e typeInfoAcceptsType(const QoreTypeInfo* typeInfo, const QoreTypeInfo* otherTypeInfo);
228 DLLEXPORT qore_type_result_e typeInfoReturnsType(const QoreTypeInfo* typeInfo, const QoreTypeInfo* otherTypeInfo);
229 
230 #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:44
Qore's floating-point value type, dynamically-allocated only, reference counted.
Definition: QoreFloatNode.h:32
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:41
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:47
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:59
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:42
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:40
DLLEXPORT QoreBoolTrueNode True
Qore's boolean true value.
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:44
Qore's parse tree/value type for date-time values, reference-counted, dynamically-allocated only...
Definition: DateTimeNode.h:36
defines a Qore-language class
Definition: QoreClass.h:186
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:207
DLLEXPORT void ref() const
increments the reference count
the implementation of Qore's object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:56
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:35
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:169
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:33
virtual DLLEXPORT ~QoreTypeInfoHelper()
deallocates the managed QoreTypeInfo object
#define QDOM_DEFAULT
the default domain (no domain)
Definition: Restrictions.h:102