Qore Programming Language  0.9.3.1
AbstractQoreNode Class Referenceabstract

The base class for all value and parse types in Qore expression trees. More...

#include <AbstractQoreNode.h>

Inheritance diagram for AbstractQoreNode:
Collaboration diagram for AbstractQoreNode:

Public Member Methods

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
 
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 (ExceptionSink *xsink) const
 evaluates the object and returns a value (or 0) More...
 
DLLEXPORT QoreValue eval (bool &needs_deref, ExceptionSink *xsink) const
 optionally evaluates the argument 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 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 QoreStringgetAsString (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 DateTimegetDateTimeRepresentation (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 QoreStringgetStringRepresentation (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...
 
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 AbstractQoreNodeoperator= (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 AbstractQoreNoderealCopy () const =0
 returns a copy of the object; the caller owns the reference count More...
 
DLLEXPORT void ref () const
 increments the reference count
 
DLLEXPORT AbstractQoreNoderefSelf () 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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ AbstractQoreNode()

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

Parameters
tthe Qore type code identifying this class in the Qore type system
n_valuedetermines if this is a value type or not
n_needs_evaldetermines if the type needs evaluation when AbstractQoreNode::eval() is called
n_there_can_be_only_onewhereas 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_handlersif true then the class implements its own reference handlers

◆ ~AbstractQoreNode()

virtual DLLEXPORT AbstractQoreNode::~AbstractQoreNode ( )
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.

Member Function Documentation

◆ customDeref()

virtual DLLEXPORT void AbstractQoreNode::customDeref ( ExceptionSink xsink)
virtual

only called when custom_reference_handlers = true. The default implementation does nothing (calls assert(false) in debug mode)

Reimplemented in QoreObject.

◆ customRef()

virtual DLLEXPORT void AbstractQoreNode::customRef ( ) const
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.

◆ deref()

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)

Parameters
xsinkif an error occurs, the Qore-language exception information will be added here

Referenced by discard().

◆ derefImpl()

virtual DLLEXPORT bool AbstractQoreNode::derefImpl ( ExceptionSink xsink)
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)

Parameters
xsinkif an error occurs, the Qore-language exception information will be added here
Returns
true if the object can be deleted, false if not (externally-managed)

Reimplemented in FunctionCallReferenceNode, ReferenceNode, QoreListNode, QoreObject, and QoreHashNode.

◆ eval() [1/2]

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.

ValueHolder value(n->eval(xsink));
if (!*value) // note that if a qore-language exception occured, then value = 0
return 0;
...
return value.release();
Parameters
xsinkif an error occurs, the Qore-language exception information will be added here
Returns
the result of the evaluation, if the return value contains a referenced value, it must be dereferenced manually
See also

◆ eval() [2/2]

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"

Parameters
needs_derefthis is an output parameter, if needs_deref is true then the value returned must be dereferenced
xsinkif an error occurs, the Qore-language exception information will be added here
Note
do not use this function directly, use the ValueEvalRefHolder class instead
See also
ValueEvalRefHolder

◆ evalImpl()

virtual DLLEXPORT QoreValue AbstractQoreNode::evalImpl ( bool &  needs_deref,
ExceptionSink xsink 
) const
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"

Parameters
needs_derefthis is an output parameter, if needs_deref is true then the value returned must be dereferenced
xsinkif an error occurs, the Qore-language exception information will be added here
Note
do not use this function directly, use the ValueEvalRefHolder class instead
See also
eval(bool&, ExceptionSink*)

Implemented in SimpleValueQoreNode, LocalFunctionCallReferenceNode, ResolvedCallReferenceNode, LocalMethodCallReferenceNode, LocalStaticMethodCallReferenceNode, QoreListNode, QoreObject, QoreHashNode, QoreNullNode, AbstractCallReferenceNode, QoreNothingNode, and ReferenceNode.

◆ getAsBigInt()

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

◆ getAsBigIntImpl()

virtual DLLLOCAL int64 AbstractQoreNode::getAsBigIntImpl ( ) const
inlinevirtual

default implementation, returns 0

This function is called by the normal class function "getAsBigInt()"

Returns
the value of the object interpreted as a 64-bit integer

◆ getAsBool()

DLLEXPORT bool AbstractQoreNode::getAsBool ( ) const

returns the boolean value of the object

calls getAsBoolImpl() if necessary to return the boolean value of the object

◆ getAsBoolImpl()

virtual DLLLOCAL bool AbstractQoreNode::getAsBoolImpl ( ) const
inlinevirtual

default implementation, returns false

This function is called by the normal class function "getAsBool()"

Returns
the value of the object interpreted as a boolean

Reimplemented in QoreObject, QoreHashNode, QoreListNode, AbstractCallReferenceNode, and BinaryNode.

◆ getAsFloat()

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

◆ getAsFloatImpl()

virtual DLLLOCAL double AbstractQoreNode::getAsFloatImpl ( ) const
inlinevirtual

default implementation, returns 0.0

This function is called by the normal class function "getAsFloat()"

Returns
the value of the object interpreted as a floating-point number

◆ getAsInt()

DLLEXPORT int AbstractQoreNode::getAsInt ( ) const

returns the integer value of the object

calls getAsIntImpl() if necessary to return the integer value of the object

◆ getAsIntImpl()

virtual DLLLOCAL int AbstractQoreNode::getAsIntImpl ( ) const
inlinevirtual

default implementation, returns 0

This function is called by the normal class function "getAsInt()"

Returns
the value of the object interpreted as an integer

◆ getAsString() [1/2]

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

Parameters
strthe string representation of the type will be concatenated to this QoreString reference
fofffor multi-line formatting offset, -1 = no line breaks
xsinkif an error occurs, the Qore-language exception information will be added here
Returns
-1 for exception raised, 0 = OK

Implemented in DateTimeNode, QoreNumberNode, QoreObject, QoreStringNode, QoreHashNode, QoreListNode, ReferenceNode, QoreNullNode, AbstractCallReferenceNode, BinaryNode, and QoreNothingNode.

◆ getAsString() [2/2]

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

Parameters
delif this is true when the function returns, then the returned QoreString pointer should be deleted, if false, then it must not be
fofffor multi-line formatting offset, -1 = no line breaks
xsinkif an error occurs, the Qore-language exception information will be added here
See also
QoreNodeAsStringHelper

Implemented in DateTimeNode, QoreNumberNode, QoreObject, QoreStringNode, QoreHashNode, QoreListNode, ReferenceNode, QoreNullNode, AbstractCallReferenceNode, BinaryNode, and QoreNothingNode.

◆ getDateTimeRepresentation() [1/2]

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

Parameters
deloutput 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
See also
DateTimeValueHelper

Reimplemented in DateTimeNode, QoreStringNode, and QoreNumberNode.

◆ getDateTimeRepresentation() [2/2]

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

Parameters
dtthe DateTime reference to be assigned

Reimplemented in DateTimeNode, QoreStringNode, and QoreNumberNode.

◆ getStringRepresentation() [1/2]

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

Parameters
deloutput 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
Returns
a QoreString pointer, use the del output parameter to determine ownership of the pointer
See also
QoreStringValueHelper

Reimplemented in DateTimeNode, QoreStringNode, and QoreNumberNode.

◆ getStringRepresentation() [2/2]

virtual DLLEXPORT void AbstractQoreNode::getStringRepresentation ( QoreString str) const
virtual

concatentates the value of the type to an existing QoreString reference, default implementation does nothing

Parameters
stra reference to a QoreString where the value of the type will be concatenated

Reimplemented in DateTimeNode, QoreStringNode, and QoreNumberNode.

◆ getType()

DLLLOCAL qore_type_t AbstractQoreNode::getType ( ) const
inline

returns the data type

Returns
the data type of the object

Referenced by is_nothing(), and is_null().

◆ getTypeName()

virtual DLLEXPORT const char* AbstractQoreNode::getTypeName ( ) const
pure virtual

returns the type name as a c string

Returns
the type name as a c string

Implemented in DateTimeNode, QoreNumberNode, QoreStringNode, QoreObject, QoreHashNode, QoreListNode, ReferenceNode, QoreNullNode, BinaryNode, QoreNothingNode, and AbstractCallReferenceNode.

◆ is_equal_hard()

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)

Parameters
vthe value to compare
xsinkif an error occurs, the Qore-language exception information will be added here
Returns
true if the objects are equal, false if not

Implemented in RunTimeResolvedMethodReferenceNode, RunTimeObjectMethodReferenceNode, DateTimeNode, LocalFunctionCallReferenceNode, QoreNumberNode, QoreStringNode, QoreObject, LocalMethodCallReferenceNode, QoreHashNode, ResolvedCallReferenceNode, QoreListNode, LocalStaticMethodCallReferenceNode, ReferenceNode, QoreNullNode, BinaryNode, and QoreNothingNode.

◆ is_equal_soft()

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)

Parameters
vthe value to compare
xsinkif an error occurs, the Qore-language exception information will be added here
Returns
true if the objects are equal, false if not

Implemented in RunTimeResolvedMethodReferenceNode, RunTimeObjectMethodReferenceNode, DateTimeNode, LocalFunctionCallReferenceNode, QoreNumberNode, QoreStringNode, LocalMethodCallReferenceNode, QoreObject, ResolvedCallReferenceNode, QoreHashNode, QoreListNode, ReferenceNode, LocalStaticMethodCallReferenceNode, QoreNullNode, BinaryNode, and QoreNothingNode.

◆ is_value()

DLLLOCAL bool AbstractQoreNode::is_value ( ) const
inline

returns true if the node represents a value

Returns
true if the object is a value, false if not

◆ needs_eval()

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

Returns
true if the type supports evaluation of this object, false if not

◆ parseInit()

virtual DLLLOCAL void AbstractQoreNode::parseInit ( QoreValue val,
LocalVar *  oflag,
int  pflag,
int &  lvids,
const QoreTypeInfo *&  typeInfo 
)
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)

Parameters
valthe containing QoreValue
oflagnon-zero if initialized within class code
pflagbitfield parse flag
lvidsthe number of new local variables declared in this node
typeInfoany available type constraints on the initialized value or expression

Reimplemented in QoreListNode, QoreHashNode, QoreNumberNode, QoreStringNode, DateTimeNode, UnresolvedStaticMethodCallReferenceNode, ResolvedCallReferenceNode, QoreNullNode, BinaryNode, QoreNothingNode, and UnresolvedProgramCallReferenceNode.

◆ realCopy()

virtual DLLEXPORT AbstractQoreNode* AbstractQoreNode::realCopy ( ) const
pure virtual

returns a copy of the object; the caller owns the reference count

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.

◆ refSelf()

DLLEXPORT AbstractQoreNode* AbstractQoreNode::refSelf ( ) const

returns "this" with an incremented reference count

Returns
"this" with an incremented reference count

Member Data Documentation

◆ type

qore_type_t AbstractQoreNode::type
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


The documentation for this class was generated from the following file: