QoreType.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreType.h
Qore Programming Language
Copyright (C) 2003 - 2015 David Nichols
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_QORETYPE_H
#define _QORE_QORETYPE_H
#include <qore/common.h>
#include <qore/node_types.h>
#include <map>
// global default values
DLLEXPORT extern QoreListNode* emptyList;
DLLEXPORT extern QoreHashNode* emptyHash;
DLLEXPORT extern QoreStringNode* NullString;
DLLEXPORT extern DateTimeNode* ZeroDate;
DLLEXPORT extern QoreBigIntNode* Zero;
DLLEXPORT extern QoreFloatNode* ZeroFloat;
DLLEXPORT extern QoreNumberNode* ZeroNumber, * InfinityNumber, * NaNumber, * piNumber;
DLLEXPORT extern QoreString NothingTypeString, NullTypeString, TrueString,
FalseString, EmptyHashString, EmptyListString;
class QoreTypeInfo;
DLLEXPORT extern const QoreTypeInfo* anyTypeInfo,
*bigIntTypeInfo,
*floatTypeInfo,
*boolTypeInfo,
*stringTypeInfo,
*binaryTypeInfo,
*dateTypeInfo,
*objectTypeInfo,
*hashTypeInfo,
*listTypeInfo,
*nothingTypeInfo,
*nullTypeInfo,
*numberTypeInfo,
*runTimeClosureTypeInfo,
*callReferenceTypeInfo,
*referenceTypeInfo,
*userReferenceTypeInfo,
*codeTypeInfo, // either closure or callref
*softBigIntTypeInfo, // converts to int from float, string, and bool
*softFloatTypeInfo, // converts to float from int, string, and bool
*softNumberTypeInfo, // xxx
*softBoolTypeInfo, // converts to bool from int, float, and string
*softStringTypeInfo, // converts to string from int, float, and bool
*softDateTypeInfo, // converts to date from int, float, bool, and string
*softListTypeInfo, // converts NOTHING -> empty list, list -> the same list, and everything else: list(arg)
*somethingTypeInfo, // i.e. not "NOTHING"
*dataTypeInfo, // either string or binary
*timeoutTypeInfo, // accepts int or date and returns int giving timeout in milliseconds
*bigIntOrFloatTypeInfo, // accepts int or float and returns the same
*bigIntOrNothingTypeInfo,
*floatOrNothingTypeInfo,
*numberOrNothingTypeInfo,
*stringOrNothingTypeInfo,
*boolOrNothingTypeInfo,
*binaryOrNothingTypeInfo,
*objectOrNothingTypeInfo,
*dateOrNothingTypeInfo,
*hashOrNothingTypeInfo,
*listOrNothingTypeInfo,
*nullOrNothingTypeInfo,
*codeOrNothingTypeInfo,
*dataOrNothingTypeInfo,
*referenceOrNothingTypeInfo,
*softBigIntOrNothingTypeInfo,
*softFloatOrNothingTypeInfo,
*softNumberOrNothingTypeInfo,
*softBoolOrNothingTypeInfo,
*softStringOrNothingTypeInfo,
*softDateOrNothingTypeInfo,
*softListOrNothingTypeInfo,
*timeoutOrNothingTypeInfo;
DLLEXPORT qore_type_t get_next_type_id();
DLLEXPORT bool compareHard(const AbstractQoreNode* l, const AbstractQoreNode* r, ExceptionSink* xsink);
DLLEXPORT bool compareSoft(const AbstractQoreNode* l, const AbstractQoreNode* r, ExceptionSink* xsink);
DLLEXPORT bool q_compare_soft(const QoreValue l, const QoreValue r, ExceptionSink* xsink);
static inline AbstractQoreNode* boolean_false() {
return &False;
}
static inline AbstractQoreNode* boolean_true() {
return &True;
}
static inline QoreBigIntNode* zero() {
Zero->ref();
return Zero;
}
static inline QoreFloatNode* zero_float() {
ZeroFloat->ref();
return ZeroFloat;
}
static inline QoreNumberNode* zero_number() {
ZeroNumber->ref();
return ZeroNumber;
}
static inline DateTimeNode* zero_date() {
ZeroDate->ref();
return ZeroDate;
}
static inline class QoreStringNode* null_string() {
NullString->ref();
return NullString;
}
static inline QoreListNode* empty_list() {
emptyList->ref();
return emptyList;
}
static inline QoreHashNode* empty_hash() {
emptyHash->ref();
return emptyHash;
}
static inline QoreNumberNode* pi_number() {
piNumber->ref();
return piNumber;
}
enum qore_type_result_e {
QTI_IGNORE = -2,
QTI_UNASSIGNED = -1,
QTI_NOT_EQUAL = 0,
QTI_AMBIGUOUS = 1,
QTI_IDENT = 2
};
class ExternalTypeInfo;
struct QoreValue;
class QoreTypeInfoHelper {
friend class ExternalTypeInfo;
protected:
ExternalTypeInfo* typeInfo;
DLLLOCAL QoreTypeInfoHelper(ExternalTypeInfo* n_typeInfo) : typeInfo(n_typeInfo) {
}
DLLEXPORT virtual bool acceptInputImpl(QoreValue& n, ExceptionSink* xsink) const;
public:
DLLEXPORT QoreTypeInfoHelper(const char* n_tname);
DLLEXPORT QoreTypeInfoHelper(qore_type_t id, const char* n_tname);
DLLEXPORT virtual ~QoreTypeInfoHelper();
DLLEXPORT const QoreTypeInfo* getTypeInfo() const;
DLLEXPORT void assign(qore_type_t id);
DLLEXPORT void addAcceptsType(const QoreTypeInfo* n_typeInfo);
DLLEXPORT void setInt();
DLLEXPORT void setInexactReturn();
DLLEXPORT void setInputFilter();
DLLEXPORT void setIntMatch();
DLLEXPORT int doAcceptError(bool priv_error, bool obj, int param_num, const char* param_name, AbstractQoreNode* n, ExceptionSink* xsink) const;
};
class AbstractQoreClassTypeInfoHelper : public QoreTypeInfoHelper {
protected:
QoreClass* qc;
public:
DLLEXPORT AbstractQoreClassTypeInfoHelper(const char* name, int n_domain = QDOM_DEFAULT);
DLLEXPORT ~AbstractQoreClassTypeInfoHelper();
DLLEXPORT QoreClass *getClass();
DLLEXPORT bool hasClass() const;
};
DLLEXPORT int testObjectClassAccess(const QoreObject *obj, const QoreClass *classtoaccess);
DLLEXPORT const QoreClass *typeInfoGetUniqueReturnClass(const QoreTypeInfo* typeInfo);
DLLEXPORT bool typeInfoHasType(const QoreTypeInfo* typeInfo);
DLLEXPORT const char* typeInfoGetName(const QoreTypeInfo* typeInfo);
DLLEXPORT qore_type_result_e typeInfoAcceptsType(const QoreTypeInfo* typeInfo, const QoreTypeInfo* otherTypeInfo);
DLLEXPORT qore_type_result_e typeInfoReturnsType(const QoreTypeInfo* typeInfo, const QoreTypeInfo* otherTypeInfo);
#endif // _QORE_QORETYPE_H
AbstractQoreClassTypeInfoHelper::AbstractQoreClassTypeInfoHelper
DLLEXPORT AbstractQoreClassTypeInfoHelper(const char *name, int n_domain=QDOM_DEFAULT)
allocates a QoreTypeInfo object and creates the QoreClass
QoreNumberNode
Qore's arbitrary-precision number value type, dynamically-allocated only, reference counted...
Definition: QoreNumberNode.h:52
QoreFloatNode
Qore's floating-point value type, dynamically-allocated only, reference counted.
Definition: QoreFloatNode.h:40
QoreTypeInfoHelper::getTypeInfo
DLLEXPORT const QoreTypeInfo * getTypeInfo() const
returns a pointer to the object
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:49
False
DLLEXPORT QoreBoolFalseNode False
Qore's boolean false value.
AbstractQoreClassTypeInfoHelper::getClass
DLLEXPORT QoreClass * getClass()
returns the QoreClass object created and zeros out the class ptr; can only be called once ...
AbstractQoreClassTypeInfoHelper::hasClass
DLLEXPORT bool hasClass() const
returns true if this object is holding a class pointer, false if not
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
QoreTypeInfoHelper::setIntMatch
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...
QoreTypeInfoHelper::setInt
DLLEXPORT void setInt()
set a flag that means the type is equivalent to an integer
QoreString
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:82
QoreStringNode
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
True
DLLEXPORT QoreBoolTrueNode True
Qore's boolean true value.
QoreListNode
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
QoreTypeInfoHelper::acceptInputImpl
virtual DLLEXPORT bool acceptInputImpl(QoreValue &n, ExceptionSink *xsink) const
this function must be reimplemented if setInputFilter() is called
DateTimeNode
Qore's parse tree/value type for date-time values, reference-counted, dynamically-allocated only...
Definition: DateTimeNode.h:44
QoreClass
defines a Qore-language class
Definition: QoreClass.h:195
QoreTypeInfoHelper::assign
DLLEXPORT void assign(qore_type_t id)
assigns the typeid to the object
QoreTypeInfoHelper::setInputFilter
DLLEXPORT void setInputFilter()
set a flag that means that acceptInputImpl() has been reimplemented and should be used ...
QoreTypeInfoHelper::setInexactReturn
DLLEXPORT void setInexactReturn()
set a flag that means that if the return type is matched on input, it matches with QTI_AMBIGUOUS inst...
AbstractQoreClassTypeInfoHelper
note that the QoreClass object created by this class must be deleted externally
Definition: QoreType.h:220
AbstractQoreNode::ref
DLLEXPORT void ref() const
increments the reference count
QoreObject
the implementation of Qore's object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:64
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:43
AbstractQoreClassTypeInfoHelper::~AbstractQoreClassTypeInfoHelper
DLLEXPORT ~AbstractQoreClassTypeInfoHelper()
delets the QoreClass object managed if it has not been retrieved
qore_type_t
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:68
QoreTypeInfoHelper
helper type to allocate and manage QoreTypeInfo objects (not exported by the library) ...
Definition: QoreType.h:182
common.h
QoreTypeInfoHelper::addAcceptsType
DLLEXPORT void addAcceptsType(const QoreTypeInfo *n_typeInfo)
add another type that the type accepts
QoreBigIntNode
this class implements Qore's 64-bit integer data type, reference-counted, dynamically-allocated only ...
Definition: QoreBigIntNode.h:41
node_types.h
QoreTypeInfoHelper::~QoreTypeInfoHelper
virtual DLLEXPORT ~QoreTypeInfoHelper()
deallocates the managed QoreTypeInfo object
QDOM_DEFAULT
#define QDOM_DEFAULT
the default domain (no domain)
Definition: Restrictions.h:137