Qore Programming Language
0.9.16
|
The base class for all value and parse types in Qore expression trees. More...
#include <AbstractQoreNode.h>
Public Member Methods | |
DLLEXPORT | AbstractQoreNode (const AbstractQoreNode &v) |
copy constructor | |
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... | |
virtual DLLEXPORT void | customDeref (ExceptionSink *xsink) |
virtual DLLEXPORT void | customRef () const |
special processing when the object's reference count transitions from 0-1 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... | |
virtual DLLEXPORT bool | derefImpl (ExceptionSink *xsink) |
decrements the reference count More... | |
DLLEXPORT QoreValue | eval (bool &needs_deref, ExceptionSink *xsink) const |
optionally evaluates the argument More... | |
DLLEXPORT QoreValue | eval (ExceptionSink *xsink) const |
evaluates the object and returns a value (or 0) More... | |
virtual DLLEXPORT QoreValue | evalImpl (bool &needs_deref, ExceptionSink *xsink) const =0 |
optionally evaluates the argument More... | |
DLLEXPORT int64 | getAsBigInt () const |
returns the 64-bit integer value of the object More... | |
virtual DLLLOCAL int64 | getAsBigIntImpl () const |
default implementation, returns 0 More... | |
DLLEXPORT bool | getAsBool () const |
returns the boolean value of the object More... | |
virtual DLLLOCAL bool | getAsBoolImpl () const |
default implementation, returns false More... | |
DLLEXPORT double | getAsFloat () const |
returns the float value of the object More... | |
virtual DLLLOCAL double | getAsFloatImpl () const |
default implementation, returns 0.0 More... | |
DLLEXPORT int | getAsInt () const |
returns the integer value of the object More... | |
virtual DLLLOCAL int | getAsIntImpl () const |
default implementation, returns 0 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 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 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 const DLLEXPORT char * | getTypeName () const =0 |
returns the type name as a c string 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... | |
DLLLOCAL AbstractQoreNode & | operator= (const AbstractQoreNode &) |
this function is not implemented; it is here as a private function in order to prohibit it from being used | |
virtual DLLLOCAL void | parseInit (QoreValue &val, LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo) |
for use by parse types to initialize them for execution during stage 1 parsing; not exported in the library; this method's API/ABI subject to change at any time 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... | |
Public Member Methods inherited from QoreReferenceCounter | |
DLLEXPORT | QoreReferenceCounter () |
creates the reference counter object | |
DLLEXPORT | QoreReferenceCounter (const QoreReferenceCounter &old) |
creates a new object with a reference count of 1 More... | |
DLLEXPORT | ~QoreReferenceCounter () |
destroys the reference counter object | |
DLLEXPORT bool | is_unique () const |
returns true if the reference count is 1 More... | |
DLLEXPORT 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 | |
Private Member Methods | |
virtual DLLEXPORT | ~AbstractQoreNode () |
default destructor does nothing More... | |
Private 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 | |
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.
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 |
|
privatevirtual |
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.
|
virtual |
only called when custom_reference_handlers = true. The default implementation does nothing (calls assert(false) in debug mode)
Reimplemented in QoreObject.
|
virtual |
special processing when the object's reference count transitions from 0-1
only called when custom_reference_handlers = true. The default implementation does nothing (calls assert(false) in debug mode)
Reimplemented in QoreObject.
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().
|
virtual |
decrements the reference count
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 |
Reimplemented in FunctionCallReferenceNode, ReferenceNode, QoreListNode, QoreObject, and QoreHashNode.
DLLEXPORT QoreValue AbstractQoreNode::eval | ( | bool & | needs_deref, |
ExceptionSink * | xsink | ||
) | const |
optionally evaluates the argument
return value requires a dereference if needs_deref is true if needs_eval() is true, needs_deref = true, returns evalImpl() otherwise needs_deref = false returns "this"
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 QoreValue 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 |
|
pure virtual |
optionally evaluates the argument
return value requires a dereference if needs_deref is true if needs_eval() is true, needs_deref = true, returns evalImpl() otherwise needs_deref = false returns "this"
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 |
Implemented in SimpleValueQoreNode, LocalFunctionCallReferenceNode, ResolvedCallReferenceNode, LocalMethodCallReferenceNode, LocalStaticMethodCallReferenceNode, QoreListNode, QoreObject, QoreHashNode, QoreNullNode, AbstractCallReferenceNode, QoreNothingNode, and ReferenceNode.
DLLEXPORT int64 AbstractQoreNode::getAsBigInt | ( | ) | const |
returns the 64-bit integer value of the object
calls getAsBitIntImpl() if necessary to return the integer value of the object
|
inlinevirtual |
default implementation, returns 0
This function is called by the normal class function "getAsBigInt()"
DLLEXPORT bool AbstractQoreNode::getAsBool | ( | ) | const |
returns the boolean value of the object
calls getAsBoolImpl() if necessary to return the boolean value of the object
|
inlinevirtual |
default implementation, returns false
This function is called by the normal class function "getAsBool()"
Reimplemented in QoreObject, QoreHashNode, QoreListNode, AbstractCallReferenceNode, and BinaryNode.
DLLEXPORT double AbstractQoreNode::getAsFloat | ( | ) | const |
returns the float value of the object
calls getAsFloatImpl() if necessary to return the floating-point value of the object
|
inlinevirtual |
default implementation, returns 0.0
This function is called by the normal class function "getAsFloat()"
DLLEXPORT int AbstractQoreNode::getAsInt | ( | ) | const |
returns the integer value of the object
calls getAsIntImpl() if necessary to return the integer value of the object
|
inlinevirtual |
default implementation, returns 0
This function is called by the normal class function "getAsInt()"
|
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 QoreStringNode, DateTimeNode, QoreObject, QoreHashNode, QoreListNode, ReferenceNode, AbstractCallReferenceNode, QoreNumberNode, QoreNullNode, BinaryNode, and QoreNothingNode.
|
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 QoreStringNode, DateTimeNode, QoreObject, QoreHashNode, QoreListNode, ReferenceNode, AbstractCallReferenceNode, QoreNumberNode, QoreNullNode, 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, and QoreNumberNode.
|
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, and QoreNumberNode.
|
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, and QoreNumberNode.
|
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, and QoreNumberNode.
|
inline |
|
pure virtual |
returns the type name as a c string
Implemented in DateTimeNode, QoreNumberNode, QoreStringNode, QoreObject, QoreHashNode, QoreListNode, ReferenceNode, QoreNullNode, BinaryNode, QoreNothingNode, and AbstractCallReferenceNode.
|
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 RunTimeResolvedMethodReferenceNode, RunTimeObjectMethodReferenceNode, DateTimeNode, LocalFunctionCallReferenceNode, QoreNumberNode, QoreStringNode, QoreObject, LocalMethodCallReferenceNode, QoreHashNode, ResolvedCallReferenceNode, QoreListNode, LocalStaticMethodCallReferenceNode, ReferenceNode, QoreNullNode, BinaryNode, and QoreNothingNode.
|
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 RunTimeResolvedMethodReferenceNode, RunTimeObjectMethodReferenceNode, DateTimeNode, LocalFunctionCallReferenceNode, QoreNumberNode, QoreStringNode, LocalMethodCallReferenceNode, QoreObject, ResolvedCallReferenceNode, QoreHashNode, QoreListNode, ReferenceNode, LocalStaticMethodCallReferenceNode, QoreNullNode, BinaryNode, and QoreNothingNode.
|
inline |
returns true if the node represents a value
|
inline |
returns true if the object needs evaluation to return a value, false if not
default implementation returns false
|
virtual |
for use by parse types to initialize them for execution during stage 1 parsing; not exported in the library; this method's API/ABI subject to change at any time
This function should only be overridden by types that can appear in the parse tree (i.e. are recognized by the parser)
val | the containing QoreValue |
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 |
Reimplemented in QoreListNode, QoreHashNode, QoreStringNode, DateTimeNode, UnresolvedStaticMethodCallReferenceNode, BinaryNode, QoreNothingNode, UnresolvedProgramCallReferenceNode, QoreNumberNode, ResolvedCallReferenceNode, and QoreNullNode.
|
pure virtual |
returns a copy of the object; the caller owns the reference count
Implemented in UniqueValueQoreNode, DateTimeNode, QoreNumberNode, QoreStringNode, ResolvedCallReferenceNode, QoreObject, QoreHashNode, QoreListNode, ReferenceNode, and BinaryNode.
DLLEXPORT AbstractQoreNode* AbstractQoreNode::refSelf | ( | ) | const |
returns "this" with an incremented reference count
|
private |
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