Qore Programming Language
0.8.11.1
|
The base class for all value and parse types in Qore expression trees. More...
#include <AbstractQoreNode.h>
Public Member Functions | |
DLLEXPORT | AbstractQoreNode (qore_type_t t, bool n_value, bool n_needs_eval, bool n_there_can_be_only_one=false, bool n_custom_reference_handlers=false) |
constructor takes the type More... | |
DLLEXPORT | AbstractQoreNode (const AbstractQoreNode &v) |
copy constructor | |
DLLEXPORT int64 | bigIntEval (ExceptionSink *xsink) const |
evaluates the object and returns a 64-bit integer value More... | |
DLLEXPORT bool | boolEval (ExceptionSink *xsink) const |
evaluates the object and returns a boolean value More... | |
DLLEXPORT void | deref (ExceptionSink *xsink) |
decrements the reference count and calls derefImpl() if there_can_be_only_one is false, otherwise does nothing More... | |
DLLEXPORT AbstractQoreNode * | eval (ExceptionSink *xsink) const |
evaluates the object and returns a value (or 0) More... | |
DLLEXPORT AbstractQoreNode * | eval (bool &needs_deref, ExceptionSink *xsink) const |
optionally evaluates the argument More... | |
DLLEXPORT double | floatEval (ExceptionSink *xsink) const |
evaluates the object and returns a floating-point value More... | |
DLLEXPORT int64 | getAsBigInt () const |
returns the 64-bit integer value of the object More... | |
DLLEXPORT bool | getAsBool () const |
returns the boolean value of the object More... | |
DLLEXPORT double | getAsFloat () const |
returns the float value of the object More... | |
DLLEXPORT int | getAsInt () const |
returns the integer value of the object More... | |
virtual DLLEXPORT int | getAsString (QoreString &str, int foff, ExceptionSink *xsink) const =0 |
concatenate the verbose string representation of the value (including all contained values for container types) to an existing QoreString More... | |
virtual DLLEXPORT QoreString * | getAsString (bool &del, int foff, ExceptionSink *xsink) const =0 |
returns a QoreString giving the verbose string representation of the value (including all contained values for container types) More... | |
virtual DLLEXPORT class DateTime * | getDateTimeRepresentation (bool &del) const |
returns the DateTime representation of this type (default implementation: returns ZeroDate, del = false) More... | |
virtual DLLEXPORT void | getDateTimeRepresentation (DateTime &dt) const |
assigns the date representation of a value to the DateTime reference passed, default implementation does nothing More... | |
virtual DLLEXPORT QoreString * | getStringRepresentation (bool &del) const |
returns the value of the type converted to a string, default implementation: returns the empty string More... | |
virtual DLLEXPORT void | getStringRepresentation (QoreString &str) const |
concatentates the value of the type to an existing QoreString reference, default implementation does nothing More... | |
DLLLOCAL qore_type_t | getType () const |
returns the data type More... | |
virtual DLLEXPORT const char * | getTypeName () const =0 |
returns the type name as a c string More... | |
DLLEXPORT int | integerEval (ExceptionSink *xsink) const |
evaluates the object and returns an integer value More... | |
virtual DLLEXPORT bool | is_equal_hard (const AbstractQoreNode *v, ExceptionSink *xsink) const =0 |
tests for equality ("deep compare" including all contained values for container types) without type conversions (hard compare) More... | |
virtual DLLEXPORT bool | is_equal_soft (const AbstractQoreNode *v, ExceptionSink *xsink) const =0 |
tests for equality ("deep compare" including all contained values for container types) with possible type conversion (soft compare) More... | |
DLLLOCAL bool | is_value () const |
returns true if the node represents a value More... | |
DLLLOCAL bool | isReferenceCounted () const |
returns true if the object is reference-counted | |
DLLLOCAL bool | needs_eval () const |
returns true if the object needs evaluation to return a value, false if not More... | |
virtual DLLEXPORT AbstractQoreNode * | parseInit (LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo) |
for use by parse types to initialize them for execution during stage 1 parsing More... | |
virtual DLLEXPORT AbstractQoreNode * | realCopy () const =0 |
returns a copy of the object; the caller owns the reference count More... | |
DLLEXPORT void | ref () const |
increments the reference count | |
DLLEXPORT AbstractQoreNode * | refSelf () const |
returns "this" with an incremented reference count More... | |
![]() | |
DLLEXPORT | QoreReferenceCounter () |
creates the reference counter object | |
DLLEXPORT | ~QoreReferenceCounter () |
destroys the reference counter object | |
DLLLOCAL bool | is_unique () const |
returns true if the reference count is 1 More... | |
DLLLOCAL int | reference_count () const |
gets the reference count More... | |
DLLEXPORT bool | ROdereference () const |
atomically decrements the reference count More... | |
DLLEXPORT void | ROreference () const |
atomically increments the reference count | |
Protected Member Functions | |
virtual DLLEXPORT | ~AbstractQoreNode () |
default destructor does nothing More... | |
Protected Attributes | |
bool | custom_reference_handlers: 1 |
set to one for objects that need custom reference handlers | |
bool | needs_eval_flag: 1 |
if this is true then the type can be evaluated | |
bool | there_can_be_only_one: 1 |
if this is set to true, then reference counting is turned off for objects of this class | |
qore_type_t | type: 11 |
the type of the object More... | |
bool | value: 1 |
this is true for values, if false then either the type needs evaluation to produce a value or is a parse expression | |
![]() | |
QoreThreadLock | mRO |
pthread lock to ensure atomicity of updates for architectures where we don't have an atomic increment and decrement implementation | |
The base class for all value and parse types in Qore expression trees.
Defines the interface for all value and parse types in Qore expression trees. Default implementations are given for most virtual functions.
|
protectedvirtual |
default destructor does nothing
The destructor is protected because it should not be called directly, which also means that these objects cannot normally be created on the stack. They are referenced counted, and the deref() function should be used to decrement the reference count rather than using the delete operator. Because the QoreObject class at least could throw a Qore Exception when it is deleted, AbstractQoreNode::deref() takes an ExceptionSink pointer argument by default as well.
DLLEXPORT AbstractQoreNode::AbstractQoreNode | ( | qore_type_t | t, |
bool | n_value, | ||
bool | n_needs_eval, | ||
bool | n_there_can_be_only_one = false , |
||
bool | n_custom_reference_handlers = false |
||
) |
constructor takes the type
The type code for the class is passed as the argument to the constructor
t | the Qore type code identifying this class in the Qore type system |
n_value | determines if this is a value type or not |
n_needs_eval | determines if the type needs evaluation when AbstractQoreNode::eval() is called |
n_there_can_be_only_one | whereas this type is normally reference counted, if this is set to true, then referencing counting is turned off for this type. This can only be turned on when the type represents a single value. |
n_custom_reference_handlers | if true then the class implements its own reference handlers |
DLLEXPORT int64 AbstractQoreNode::bigIntEval | ( | ExceptionSink * | xsink | ) | const |
evaluates the object and returns a 64-bit integer value
if needs_eval() returns true, then returns bigIntEvalImpl() otherwise returns getAsBigInt()
xsink | if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT bool AbstractQoreNode::boolEval | ( | ExceptionSink * | xsink | ) | const |
evaluates the object and returns a boolean value
if needs_eval() returns true, then returns boolEvalImpl() otherwise returns getAsBool()
xsink | if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT void AbstractQoreNode::deref | ( | ExceptionSink * | xsink | ) |
decrements the reference count and calls derefImpl() if there_can_be_only_one is false, otherwise does nothing
if there_can_be_only_one is false, calls derefImpl() and deletes the object when the reference count = 0. The ExceptionSink argument is needed for those types that could throw an exception when they are deleted (ex: QoreObject)
xsink | if an error occurs, the Qore-language exception information will be added here |
Referenced by discard().
DLLEXPORT AbstractQoreNode* AbstractQoreNode::eval | ( | ExceptionSink * | xsink | ) | const |
evaluates the object and returns a value (or 0)
return value requires a deref(xsink) (if not 0). If needs_eval() returns false, then this function just returns refSelf(). Otherwise evalImpl() is returned.
xsink | if an error occurs, the Qore-language exception information will be added here |
Referenced by QoreNodeEvalOptionalRefHolder::QoreNodeEvalOptionalRefHolder().
DLLEXPORT AbstractQoreNode* AbstractQoreNode::eval | ( | bool & | needs_deref, |
ExceptionSink * | xsink | ||
) | const |
optionally evaluates the argument
return value requires a deref(xsink) if needs_deref is true if needs_eval() is true, needs_deref = true, returns evalImpl() otherwise needs_deref = false returns "this" NOTE: do not use this function directly, use the QoreNodeEvalOptionalRefHolder class instead
needs_deref | this is an output parameter, if needs_deref is true then the value returned must be dereferenced |
xsink | if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT double AbstractQoreNode::floatEval | ( | ExceptionSink * | xsink | ) | const |
evaluates the object and returns a floating-point value
if needs_eval() returns true, then returns floatEvalImpl() otherwise returns getAsFloat()
xsink | if an error occurs, the Qore-language exception information will be added here |
DLLEXPORT int64 AbstractQoreNode::getAsBigInt | ( | ) | const |
returns the 64-bit integer value of the object
calls getAsBitIntImpl() if necessary (there is an optimization for the QoreBigIntNode class) to return the integer value of the object
Referenced by get_bigint_param(), get_bigint_param_with_default(), and QoreBigIntNode::getValue().
DLLEXPORT bool AbstractQoreNode::getAsBool | ( | ) | const |
returns the boolean value of the object
calls getAsBoolImpl() if necessary (there is an optimization for the QoreBoolNode class) to return the boolean value of the object
Referenced by get_bool_param().
DLLEXPORT double AbstractQoreNode::getAsFloat | ( | ) | const |
returns the float value of the object
calls getAsFloatImpl() if necessary (there is an optimization for the QoreFloatNode class) to return the floating-point value of the object
Referenced by get_float_param(), and QoreFloatNode::getValue().
DLLEXPORT int AbstractQoreNode::getAsInt | ( | ) | const |
returns the integer value of the object
calls getAsIntImpl() if necessary (there is an optimization for the QoreBigIntNode class) to return the integer value of the object
Referenced by get_int_param(), and get_int_param_with_default().
|
pure virtual |
concatenate the verbose string representation of the value (including all contained values for container types) to an existing QoreString
used for n and N printf formatting
str | the string representation of the type will be concatenated to this QoreString reference |
foff | for multi-line formatting offset, -1 = no line breaks |
xsink | if an error occurs, the Qore-language exception information will be added here |
Implemented in DateTimeNode, QoreObject, QoreNumberNode, QoreListNode, QoreHashNode, QoreStringNode, QoreFloatNode, AbstractCallReferenceNode, QoreBigIntNode, ReferenceNode, QoreBoolNode, QoreNullNode, BinaryNode, and QoreNothingNode.
|
pure virtual |
returns a QoreString giving the verbose string representation of the value (including all contained values for container types)
Used for n and N printf formatting. Do not call this function directly; use the QoreNodeAsStringHelper class (defined in QoreStringNode.h) instead
del | if this is true when the function returns, then the returned QoreString pointer should be deleted, if false, then it must not be |
foff | for multi-line formatting offset, -1 = no line breaks |
xsink | if an error occurs, the Qore-language exception information will be added here |
Implemented in DateTimeNode, QoreObject, QoreNumberNode, QoreListNode, QoreHashNode, QoreStringNode, QoreFloatNode, AbstractCallReferenceNode, QoreBigIntNode, ReferenceNode, QoreNullNode, QoreBoolNode, BinaryNode, and QoreNothingNode.
|
virtual |
returns the DateTime representation of this type (default implementation: returns ZeroDate, del = false)
NOTE: Use the DateTimeValueHelper class instead of using this function directly
del | output parameter: if del is true, then the returned DateTime pointer belongs to the caller (and must be deleted manually), if false, then it must not be |
Reimplemented in DateTimeNode, QoreStringNode, QoreNumberNode, QoreFloatNode, QoreBigIntNode, and QoreBoolNode.
Referenced by DateTimeNodeValueHelper::DateTimeNodeValueHelper(), and DateTimeValueHelper::DateTimeValueHelper().
|
virtual |
assigns the date representation of a value to the DateTime reference passed, default implementation does nothing
dt | the DateTime reference to be assigned |
Reimplemented in DateTimeNode, QoreStringNode, QoreNumberNode, QoreFloatNode, QoreBigIntNode, and QoreBoolNode.
|
virtual |
returns the value of the type converted to a string, default implementation: returns the empty string
NOTE: do not use this function directly, use QoreStringValueHelper instead
del | output parameter: if del is true, then the resulting QoreString pointer belongs to the caller (and must be deleted manually), if false it must not be |
Reimplemented in DateTimeNode, QoreStringNode, QoreNumberNode, QoreFloatNode, QoreBigIntNode, and QoreBoolNode.
Referenced by QoreStringValueHelper::QoreStringValueHelper().
|
virtual |
concatentates the value of the type to an existing QoreString reference, default implementation does nothing
str | a reference to a QoreString where the value of the type will be concatenated |
Reimplemented in DateTimeNode, QoreStringNode, QoreNumberNode, QoreFloatNode, QoreBigIntNode, and QoreBoolNode.
|
inline |
returns the data type
References type.
Referenced by DateTimeNodeValueHelper::DateTimeNodeValueHelper(), DateTimeValueHelper::DateTimeValueHelper(), get_param_type(), is_nothing(), is_null(), QoreStringValueHelper::QoreStringValueHelper(), test_binary_param(), test_callref_param(), test_date_param(), test_hash_param(), test_list_param(), test_object_param(), test_reference_param(), and test_string_param().
|
pure virtual |
returns the type name as a c string
Implemented in DateTimeNode, QoreNumberNode, QoreObject, QoreStringNode, QoreListNode, QoreHashNode, QoreFloatNode, QoreBigIntNode, AbstractCallReferenceNode, QoreNullNode, ReferenceNode, BinaryNode, QoreNothingNode, and QoreBoolNode.
DLLEXPORT int AbstractQoreNode::integerEval | ( | ExceptionSink * | xsink | ) | const |
evaluates the object and returns an integer value
if needs_eval() returns true, then returns integerEvalImpl() otherwise returns getAsInteger()
xsink | if an error occurs, the Qore-language exception information will be added here |
|
pure virtual |
tests for equality ("deep compare" including all contained values for container types) without type conversions (hard compare)
v | the value to compare |
xsink | if an error occurs, the Qore-language exception information will be added here |
Implemented in DateTimeNode, QoreObject, QoreNumberNode, QoreStringNode, QoreListNode, QoreHashNode, QoreFloatNode, QoreBigIntNode, QoreNullNode, ReferenceNode, BinaryNode, QoreNothingNode, and QoreBoolNode.
|
pure virtual |
tests for equality ("deep compare" including all contained values for container types) with possible type conversion (soft compare)
v | the value to compare |
xsink | if an error occurs, the Qore-language exception information will be added here |
Implemented in DateTimeNode, QoreObject, QoreNumberNode, QoreStringNode, QoreListNode, QoreHashNode, QoreFloatNode, QoreBigIntNode, ReferenceNode, QoreNullNode, BinaryNode, QoreBoolNode, and QoreNothingNode.
|
inline |
returns true if the node represents a value
References value.
|
inline |
returns true if the object needs evaluation to return a value, false if not
default implementation returns false
References needs_eval_flag.
|
virtual |
for use by parse types to initialize them for execution during stage 1 parsing
This function should only be overridden by types that can appear in the parse tree (i.e. are recognized by the parser)
oflag | non-zero if initialized within class code |
pflag | bitfield parse flag |
lvids | the number of new local variables declared in this node |
typeInfo | any available type constraints on the initialized value or expression |
FIXME: add QoreProgramLocation& arg
Reimplemented in QoreListNode, QoreHashNode, QoreStringNode, QoreNumberNode, QoreFloatNode, QoreBigIntNode, QoreNullNode, BinaryNode, QoreNothingNode, and QoreBoolNode.
|
pure virtual |
returns a copy of the object; the caller owns the reference count
Implemented in UniqueValueQoreNode, DateTimeNode, QoreObject, QoreNumberNode, QoreStringNode, QoreListNode, QoreHashNode, QoreFloatNode, QoreBigIntNode, ReferenceNode, and BinaryNode.
DLLEXPORT AbstractQoreNode* AbstractQoreNode::refSelf | ( | ) | const |
returns "this" with an incremented reference count
|
protected |
the type of the object
instead of using a virtual method to return a default type code for each implemented type, it's stored as an attribute of the base class. This makes it possible to avoid making virtual function calls as a performance optimization in many cases, also it allows very fast type determination without making either a virtual function call or using dynamic_cast<> at the expense of more memory usage
Referenced by getType().