#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 | |
DLLEXPORT bool | getAsBool () const |
returns the boolean value of the object | |
DLLEXPORT int | getAsInt () const |
returns the integer value of the object | |
DLLEXPORT int64 | getAsBigInt () const |
returns the 64-bit integer value of the object | |
DLLEXPORT double | getAsFloat () const |
returns the float value of the object | |
virtual DLLEXPORT QoreString * | getStringRepresentation (bool &del) const |
returns the value of the type converted to a string, default implementation: returns the empty string | |
virtual DLLEXPORT void | getStringRepresentation (QoreString &str) const |
concatentates the value of the type to an existing QoreString reference, default implementation does nothing | |
virtual DLLEXPORT class DateTime * | getDateTimeRepresentation (bool &del) const |
returns the DateTime representation of this type (default implementation: returns ZeroDate, del = false) | |
virtual DLLEXPORT void | getDateTimeRepresentation (DateTime &dt) const |
assigns the date representation of a value to the DateTime reference passed, default implementation does nothing | |
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 | |
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) | |
DLLLOCAL bool | needs_eval () const |
returns true if the object needs evaluation to return a value, false if not | |
virtual DLLEXPORT AbstractQoreNode * | realCopy () const =0 |
returns a copy of the object; the caller owns the reference count | |
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) | |
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) | |
DLLLOCAL qore_type_t | getType () const |
returns the data type | |
virtual DLLEXPORT const char * | getTypeName () const =0 |
returns the type name as a c string | |
virtual DLLEXPORT AbstractQoreNode * | parseInit (LocalVar *oflag, int pflag, int &lvids) |
for use by parse types to initialize them for execution during stage 1 parsing | |
DLLEXPORT AbstractQoreNode * | eval (ExceptionSink *xsink) const |
evaluates the object and returns a value (or 0) | |
DLLEXPORT AbstractQoreNode * | eval (bool &needs_deref, ExceptionSink *xsink) const |
optionally evaluates the argument | |
DLLEXPORT int64 | bigIntEval (ExceptionSink *xsink) const |
evaluates the object and returns a 64-bit integer value | |
DLLEXPORT int | integerEval (ExceptionSink *xsink) const |
evaluates the object and returns an integer value | |
DLLEXPORT bool | boolEval (ExceptionSink *xsink) const |
evaluates the object and returns a boolean value | |
DLLEXPORT double | floatEval (ExceptionSink *xsink) const |
evaluates the object and returns a floating-point value | |
DLLLOCAL bool | is_value () const |
returns true if the node represents a value | |
DLLEXPORT void | deref (ExceptionSink *xsink) |
decrements the reference count and calls derefImpl() if there_can_be_only_one is false, otherwise does nothing | |
DLLEXPORT AbstractQoreNode * | refSelf () const |
returns "this" with an incremented reference count | |
DLLEXPORT void | ref () const |
increments the reference count | |
DLLEXPORT bool | isReferenceCounted () const |
returns true if the object is reference-counted | |
Protected Member Functions | |
virtual DLLEXPORT | ~AbstractQoreNode () |
default destructor does nothing | |
Protected Attributes | |
qore_type_t | type: 11 |
the type of the object | |
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 | |
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 | |
bool | custom_reference_handlers: 1 |
set to one for objects that need custom reference handlers |
Defines the interface for all value and parse types in Qore expression trees. Default implementations are given for most virtual functions.
virtual DLLEXPORT AbstractQoreNode::~AbstractQoreNode | ( | ) | [protected, virtual] |
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 | ( | 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 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.
ReferenceHolder<AbstractQoreNode> value(n->eval(xsink)); if (!value) // note that if a qore-language exception occured, then value = 0 return 0; ... return value.release();
xsink | if an error occurs, the Qore-language exception information will be added here |
Referenced by QoreNodeEvalOptionalRefHolder::QoreNodeEvalOptionalRefHolder().
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().
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
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().
virtual DLLEXPORT QoreString* AbstractQoreNode::getAsString | ( | bool & | del, | |
int | foff, | |||
ExceptionSink * | xsink | |||
) | const [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 BinaryNode, AbstractCallReferenceNode, DateTimeNode, QoreBigIntNode, QoreBoolNode, QoreFloatNode, QoreHashNode, QoreListNode, QoreNothingNode, QoreNullNode, QoreObject, QoreStringNode, and ReferenceNode.
virtual DLLEXPORT int AbstractQoreNode::getAsString | ( | QoreString & | str, | |
int | foff, | |||
ExceptionSink * | xsink | |||
) | const [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 BinaryNode, AbstractCallReferenceNode, DateTimeNode, QoreBigIntNode, QoreBoolNode, QoreFloatNode, QoreHashNode, QoreListNode, QoreNothingNode, QoreNullNode, QoreObject, QoreStringNode, and ReferenceNode.
Referenced by QoreNodeAsStringHelper::QoreNodeAsStringHelper().
virtual DLLEXPORT void AbstractQoreNode::getDateTimeRepresentation | ( | DateTime & | dt | ) | const [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, QoreBigIntNode, QoreBoolNode, QoreFloatNode, and QoreStringNode.
virtual DLLEXPORT class DateTime* AbstractQoreNode::getDateTimeRepresentation | ( | bool & | del | ) | const [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, QoreBigIntNode, QoreBoolNode, QoreFloatNode, and QoreStringNode.
Referenced by DateTimeNodeValueHelper::DateTimeNodeValueHelper(), and DateTimeValueHelper::DateTimeValueHelper().
virtual DLLEXPORT void AbstractQoreNode::getStringRepresentation | ( | QoreString & | str | ) | const [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, QoreBigIntNode, QoreBoolNode, QoreFloatNode, and QoreStringNode.
virtual DLLEXPORT QoreString* AbstractQoreNode::getStringRepresentation | ( | bool & | del | ) | const [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, QoreBigIntNode, QoreBoolNode, QoreFloatNode, and QoreStringNode.
Referenced by QoreStringValueHelper::QoreStringValueHelper().
DLLLOCAL qore_type_t AbstractQoreNode::getType | ( | ) | const [inline] |
returns the data type
References type.
Referenced by DateTimeNodeValueHelper::DateTimeNodeValueHelper(), DateTimeValueHelper::DateTimeValueHelper(), get_param_type(), ReferenceHelper::getType(), 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().
virtual DLLEXPORT const char* AbstractQoreNode::getTypeName | ( | ) | const [pure virtual] |
returns the type name as a c string
Implemented in BinaryNode, AbstractCallReferenceNode, DateTimeNode, QoreBigIntNode, QoreBoolNode, QoreFloatNode, QoreHashNode, QoreListNode, QoreNothingNode, QoreNullNode, QoreObject, QoreStringNode, and ReferenceNode.
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 |
virtual DLLEXPORT bool AbstractQoreNode::is_equal_hard | ( | const AbstractQoreNode * | v, | |
ExceptionSink * | xsink | |||
) | const [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 BinaryNode, DateTimeNode, QoreBigIntNode, QoreBoolNode, QoreFloatNode, QoreHashNode, QoreListNode, QoreNothingNode, QoreNullNode, QoreObject, QoreStringNode, and ReferenceNode.
virtual DLLEXPORT bool AbstractQoreNode::is_equal_soft | ( | const AbstractQoreNode * | v, | |
ExceptionSink * | xsink | |||
) | const [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 BinaryNode, DateTimeNode, QoreBigIntNode, QoreBoolNode, QoreFloatNode, QoreHashNode, QoreListNode, QoreNothingNode, QoreNullNode, QoreObject, QoreStringNode, and ReferenceNode.
DLLLOCAL bool AbstractQoreNode::is_value | ( | ) | const [inline] |
returns true if the node represents a value
References value.
DLLLOCAL bool AbstractQoreNode::needs_eval | ( | ) | const [inline] |
returns true if the object needs evaluation to return a value, false if not
default implementation returns false
References needs_eval_flag.
virtual DLLEXPORT AbstractQoreNode* AbstractQoreNode::parseInit | ( | LocalVar * | oflag, | |
int | pflag, | |||
int & | lvids | |||
) | [inline, virtual] |
for use by parse types to initialize them for execution during stage 1 parsing
oflag | non-zero if initialized within class code | |
pflag | bitfield parse flag | |
lvids | the number of new local variables declared in this node |
virtual DLLEXPORT AbstractQoreNode* AbstractQoreNode::realCopy | ( | ) | const [pure virtual] |
returns a copy of the object; the caller owns the reference count
Implemented in UniqueValueQoreNode, BinaryNode, DateTimeNode, QoreBigIntNode, QoreFloatNode, QoreHashNode, QoreListNode, QoreObject, QoreStringNode, and ReferenceNode.
DLLEXPORT AbstractQoreNode* AbstractQoreNode::refSelf | ( | ) | const |
returns "this" with an incremented reference count
qore_type_t AbstractQoreNode::type [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 makiing either a virtual function call or using dynamic_cast<> at the expense of more memory usage
Referenced by getType().