|
Qore Programming Language
0.8.3
|
00001 /* -*- mode: c++; indent-tabs-mode: nil -*- */ 00002 /* 00003 QoreType.h 00004 00005 Qore Programming Language 00006 00007 Copyright 2003 - 2011 David Nichols 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 */ 00023 00024 #ifndef _QORE_QORETYPE_H 00025 00026 #define _QORE_QORETYPE_H 00027 00028 #include <qore/common.h> 00029 #include <qore/node_types.h> 00030 00031 #include <map> 00032 00033 // global default values 00034 DLLEXPORT extern QoreListNode *emptyList; 00035 DLLEXPORT extern QoreHashNode *emptyHash; 00036 DLLEXPORT extern QoreStringNode *NullString; 00037 DLLEXPORT extern DateTimeNode *ZeroDate; 00038 DLLEXPORT extern QoreBigIntNode *Zero; 00039 00040 DLLEXPORT extern QoreString NothingTypeString, NullTypeString, TrueString, 00041 FalseString, EmptyHashString, EmptyListString; 00042 00043 class QoreTypeInfo; 00044 DLLEXPORT extern const QoreTypeInfo *anyTypeInfo, 00045 *bigIntTypeInfo, 00046 *floatTypeInfo, 00047 *boolTypeInfo, 00048 *stringTypeInfo, 00049 *binaryTypeInfo, 00050 *dateTypeInfo, 00051 *objectTypeInfo, 00052 *hashTypeInfo, 00053 *listTypeInfo, 00054 *nothingTypeInfo, 00055 *nullTypeInfo, 00056 *runTimeClosureTypeInfo, 00057 *callReferenceTypeInfo, 00058 *referenceTypeInfo, 00059 *userReferenceTypeInfo, 00060 *codeTypeInfo, // either closure or callref 00061 *softBigIntTypeInfo, // converts to int from float, string, and bool 00062 *softFloatTypeInfo, // converts to float from int, string, and bool 00063 *softBoolTypeInfo, // converts to bool from int, float, and string 00064 *softStringTypeInfo, // converts to string from int, float, and bool 00065 *softDateTypeInfo, // converts to date from int, float, bool, and string 00066 *softListTypeInfo, // converts NOTHING -> empty list, list -> the same list, and everything else: list(arg) 00067 *somethingTypeInfo, // i.e. not "NOTHING" 00068 *dataTypeInfo, // either string or binary 00069 *timeoutTypeInfo, // accepts int or date and returns int giving timeout in milliseconds 00070 00071 *bigIntOrNothingTypeInfo, 00072 *floatOrNothingTypeInfo, 00073 *stringOrNothingTypeInfo, 00074 *boolOrNothingTypeInfo, 00075 *binaryOrNothingTypeInfo, 00076 *objectOrNothingTypeInfo, 00077 *dateOrNothingTypeInfo, 00078 *hashOrNothingTypeInfo, 00079 *listOrNothingTypeInfo, 00080 *nullOrNothingTypeInfo, 00081 *codeOrNothingTypeInfo, 00082 *dataOrNothingTypeInfo, 00083 00084 *softBigIntOrNothingTypeInfo, 00085 *softFloatOrNothingTypeInfo, 00086 *softBoolOrNothingTypeInfo, 00087 *softStringOrNothingTypeInfo, 00088 *softDateOrNothingTypeInfo, 00089 *softListOrNothingTypeInfo, 00090 *timeoutOrNothingTypeInfo; 00091 00092 DLLEXPORT qore_type_t get_next_type_id(); 00093 00094 DLLEXPORT bool compareHard(const AbstractQoreNode *l, const AbstractQoreNode *r, ExceptionSink *xsink); 00095 DLLEXPORT bool compareSoft(const AbstractQoreNode *l, const AbstractQoreNode *r, ExceptionSink *xsink); 00096 00097 static inline AbstractQoreNode *boolean_false() { 00098 return &False; 00099 } 00100 00101 static inline AbstractQoreNode *boolean_true() { 00102 return &True; 00103 } 00104 00105 static inline QoreBigIntNode *zero() { 00106 Zero->ref(); 00107 return Zero; 00108 } 00109 00110 static inline QoreFloatNode *zero_float() { 00111 return new QoreFloatNode(0.0); 00112 } 00113 00114 static inline DateTimeNode *zero_date() { 00115 ZeroDate->ref(); 00116 return ZeroDate; 00117 } 00118 00119 static inline class QoreStringNode *null_string() { 00120 NullString->ref(); 00121 return NullString; 00122 } 00123 00124 static inline QoreListNode *empty_list() { 00125 emptyList->ref(); 00126 return emptyList; 00127 } 00128 00129 static inline QoreHashNode *empty_hash() { 00130 emptyHash->ref(); 00131 return emptyHash; 00132 } 00133 00135 enum qore_type_result_e { 00136 QTI_IGNORE = -2, 00137 QTI_UNASSIGNED = -1, 00138 00139 QTI_NOT_EQUAL = 0, 00140 QTI_AMBIGUOUS = 1, 00141 QTI_IDENT = 2 00142 }; 00143 00145 class ExternalTypeInfo; 00146 00148 00150 class QoreTypeInfoHelper { 00151 friend class ExternalTypeInfo; 00152 00153 protected: 00154 ExternalTypeInfo *typeInfo; 00155 00156 DLLLOCAL QoreTypeInfoHelper(ExternalTypeInfo *n_typeInfo) : typeInfo(n_typeInfo) { 00157 } 00158 00160 DLLEXPORT virtual bool acceptInputImpl(AbstractQoreNode *&n, ExceptionSink *xsink) const; 00161 00162 public: 00164 DLLEXPORT QoreTypeInfoHelper(const char *n_tname); 00166 DLLEXPORT QoreTypeInfoHelper(qore_type_t id, const char *n_tname); 00168 DLLEXPORT virtual ~QoreTypeInfoHelper(); 00170 DLLEXPORT const QoreTypeInfo *getTypeInfo() const; 00172 DLLEXPORT void assign(qore_type_t id); 00174 DLLEXPORT void addAcceptsType(const QoreTypeInfo *n_typeInfo); 00176 DLLEXPORT void setInt(); 00178 DLLEXPORT void setInexactReturn(); 00180 DLLEXPORT void setInputFilter(); 00182 DLLEXPORT void setIntMatch(); 00183 00184 DLLEXPORT int doAcceptError(bool priv_error, bool obj, int param_num, const char *param_name, AbstractQoreNode *n, ExceptionSink *xsink) const; 00185 }; 00186 00188 class AbstractQoreClassTypeInfoHelper : public QoreTypeInfoHelper { 00189 protected: 00190 QoreClass *qc; 00191 00192 public: 00194 DLLEXPORT AbstractQoreClassTypeInfoHelper(const char *name, int n_domain = QDOM_DEFAULT); 00196 DLLEXPORT ~AbstractQoreClassTypeInfoHelper(); 00198 DLLEXPORT QoreClass *getClass(); 00200 DLLEXPORT bool hasClass() const; 00201 }; 00202 00203 DLLEXPORT int testObjectClassAccess(const QoreObject *obj, const QoreClass *classtoaccess); 00204 00205 DLLEXPORT const QoreClass *typeInfoGetUniqueReturnClass(const QoreTypeInfo *typeInfo); 00206 DLLEXPORT bool typeInfoHasType(const QoreTypeInfo *typeInfo); 00207 DLLEXPORT const char *typeInfoGetName(const QoreTypeInfo *typeInfo); 00208 DLLEXPORT qore_type_result_e typeInfoAcceptsType(const QoreTypeInfo *typeInfo, const QoreTypeInfo *otherTypeInfo); 00209 DLLEXPORT qore_type_result_e typeInfoReturnsType(const QoreTypeInfo *typeInfo, const QoreTypeInfo *otherTypeInfo); 00210 00211 00212 #endif // _QORE_QORETYPE_H