Qore Programming Language  0.8.7
 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 
90  *softBigIntOrNothingTypeInfo,
91  *softFloatOrNothingTypeInfo,
92  *softNumberOrNothingTypeInfo,
93  *softBoolOrNothingTypeInfo,
94  *softStringOrNothingTypeInfo,
95  *softDateOrNothingTypeInfo,
96  *softListOrNothingTypeInfo,
97  *timeoutOrNothingTypeInfo;
98 
99 DLLEXPORT qore_type_t get_next_type_id();
100 
101 DLLEXPORT bool compareHard(const AbstractQoreNode* l, const AbstractQoreNode* r, ExceptionSink* xsink);
102 DLLEXPORT bool compareSoft(const AbstractQoreNode* l, const AbstractQoreNode* r, ExceptionSink* xsink);
103 
104 static inline AbstractQoreNode* boolean_false() {
105  return &False;
106 }
107 
108 static inline AbstractQoreNode* boolean_true() {
109  return &True;
110 }
111 
112 static inline QoreBigIntNode* zero() {
113  Zero->ref();
114  return Zero;
115 }
116 
117 static inline QoreFloatNode* zero_float() {
118  ZeroFloat->ref();
119  return ZeroFloat;
120 }
121 
122 static inline QoreNumberNode* zero_number() {
123  ZeroNumber->ref();
124  return ZeroNumber;
125 }
126 
127 static inline DateTimeNode* zero_date() {
128  ZeroDate->ref();
129  return ZeroDate;
130 }
131 
132 static inline class QoreStringNode* null_string() {
133  NullString->ref();
134  return NullString;
135 }
136 
137 static inline QoreListNode* empty_list() {
138  emptyList->ref();
139  return emptyList;
140 }
141 
142 static inline QoreHashNode* empty_hash() {
143  emptyHash->ref();
144  return emptyHash;
145 }
146 
147 static inline QoreNumberNode* pi_number() {
148  piNumber->ref();
149  return piNumber;
150 }
151 
153 enum qore_type_result_e {
154  QTI_IGNORE = -2,
155  QTI_UNASSIGNED = -1,
156 
157  QTI_NOT_EQUAL = 0,
158  QTI_AMBIGUOUS = 1,
159  QTI_IDENT = 2
160 };
161 
163 class ExternalTypeInfo;
164 
166 
169  friend class ExternalTypeInfo;
170 
171 protected:
172  ExternalTypeInfo* typeInfo;
173 
174  DLLLOCAL QoreTypeInfoHelper(ExternalTypeInfo* n_typeInfo) : typeInfo(n_typeInfo) {
175  }
176 
178  DLLEXPORT virtual bool acceptInputImpl(AbstractQoreNode*& n, ExceptionSink* xsink) const;
179 
180 public:
182  DLLEXPORT QoreTypeInfoHelper(const char* n_tname);
184  DLLEXPORT QoreTypeInfoHelper(qore_type_t id, const char* n_tname);
186  DLLEXPORT virtual ~QoreTypeInfoHelper();
188  DLLEXPORT const QoreTypeInfo* getTypeInfo() const;
190  DLLEXPORT void assign(qore_type_t id);
192  DLLEXPORT void addAcceptsType(const QoreTypeInfo* n_typeInfo);
194  DLLEXPORT void setInt();
196  DLLEXPORT void setInexactReturn();
198  DLLEXPORT void setInputFilter();
200  DLLEXPORT void setIntMatch();
201 
202  DLLEXPORT int doAcceptError(bool priv_error, bool obj, int param_num, const char* param_name, AbstractQoreNode* n, ExceptionSink* xsink) const;
203 };
204 
207 protected:
208  QoreClass* qc;
209 
210 public:
212  DLLEXPORT AbstractQoreClassTypeInfoHelper(const char* name, int n_domain = QDOM_DEFAULT);
216  DLLEXPORT QoreClass *getClass();
218  DLLEXPORT bool hasClass() const;
219 };
220 
221 DLLEXPORT int testObjectClassAccess(const QoreObject *obj, const QoreClass *classtoaccess);
222 
223 DLLEXPORT const QoreClass *typeInfoGetUniqueReturnClass(const QoreTypeInfo* typeInfo);
224 DLLEXPORT bool typeInfoHasType(const QoreTypeInfo* typeInfo);
225 DLLEXPORT const char* typeInfoGetName(const QoreTypeInfo* typeInfo);
226 DLLEXPORT qore_type_result_e typeInfoAcceptsType(const QoreTypeInfo* typeInfo, const QoreTypeInfo* otherTypeInfo);
227 DLLEXPORT qore_type_result_e typeInfoReturnsType(const QoreTypeInfo* typeInfo, const QoreTypeInfo* otherTypeInfo);
228 
229 #endif // _QORE_QORETYPE_H