Qore Programming Language: AbstractQoreNode Class Reference

Qore Programming Language 0.8.11

- Main Page
- Related Pages
- Modules
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
AbstractQoreNode Class Referenceabstract

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

`#include <AbstractQoreNode.h>`

Inheritance diagram for AbstractQoreNode:
[legend]
Collaboration diagram for AbstractQoreNode:
[legend]

## 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...
Public Member Functions inherited from QoreReferenceCounter
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
Protected Attributes inherited from QoreReferenceCounter
QoreThreadLock | mRO
| pthread lock to ensure atomicity of updates for architectures where we don't have an atomic increment and decrement implementation

## 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

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

Parameters

  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

## Member Function Documentation

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()

Parameters

  xsink | if an error occurs, the Qore-language exception information will be added here

Returns
  the result of the evaluation of the object

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()

Parameters

  xsink | if an error occurs, the Qore-language exception information will be added here

Returns
  the result of the evaluation of the object

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

  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.

ReferenceHolder<AbstractQoreNode> value(n->eval(xsink));
if (!value) // note that if a qore-language exception occured, then value = 0
return 0;
...
return value.release();

Parameters

  xsink | if an error occurs, the Qore-language exception information will be added here

Returns
  the result of the evaluation, if non-0, must be dereferenced manually

See Also
  ReferenceHolder

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

Parameters

  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

See Also
  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()

Parameters

  xsink | if an error occurs, the Qore-language exception information will be added here

Returns
  the result of the evaluation of the object

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().

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

  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

Returns
  -1 for exception raised, 0 = OK

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

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

  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

See Also
  QoreNodeAsStringHelper

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

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

  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

See Also
  DateTimeValueHelper

Reimplemented in DateTimeNode, QoreStringNode, QoreNumberNode, QoreFloatNode, QoreBigIntNode, and QoreBoolNode.

Referenced by DateTimeNodeValueHelper::DateTimeNodeValueHelper(), and DateTimeValueHelper::DateTimeValueHelper().

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

  dt | the DateTime reference to be assigned

Reimplemented in DateTimeNode, QoreStringNode, QoreNumberNode, QoreFloatNode, QoreBigIntNode, and QoreBoolNode.

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

  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

Returns
  a QoreString pointer, use the del output parameter to determine ownership of the pointer

See Also
  QoreStringValueHelper

Reimplemented in DateTimeNode, QoreStringNode, QoreNumberNode, QoreFloatNode, QoreBigIntNode, and QoreBoolNode.

Referenced by QoreStringValueHelper::QoreStringValueHelper().

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

  str | a reference to a QoreString where the value of the type will be concatenated

Reimplemented in DateTimeNode, QoreStringNode, QoreNumberNode, QoreFloatNode, QoreBigIntNode, and QoreBoolNode.

DLLLOCAL qore_type_t AbstractQoreNode::getType | ( |  | ) | const
| inline

returns the data type

Returns
  the data type of the object

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().

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, 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()

Parameters

  xsink | if an error occurs, the Qore-language exception information will be added here

Returns
  the result of the evaluation of the object

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

  v | the value to compare
  xsink | if an error occurs, the Qore-language exception information will be added here

Returns
  true if the objects are equal, false if not

Implemented in DateTimeNode, QoreObject, QoreNumberNode, QoreStringNode, QoreListNode, QoreHashNode, QoreFloatNode, QoreBigIntNode, QoreNullNode, ReferenceNode, BinaryNode, QoreNothingNode, and QoreBoolNode.

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

  v | the value to compare
  xsink | if an error occurs, the Qore-language exception information will be added here

Returns
  true if the objects are equal, false if not

Implemented in DateTimeNode, QoreObject, QoreNumberNode, QoreStringNode, QoreListNode, QoreHashNode, QoreFloatNode, QoreBigIntNode, ReferenceNode, QoreNullNode, BinaryNode, QoreBoolNode, and QoreNothingNode.

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

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

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

References needs_eval_flag.

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

Parameters

  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

Returns
  new object

FIXME: add QoreProgramLocation& arg

Reimplemented in QoreListNode, QoreHashNode, QoreStringNode, QoreNumberNode, QoreFloatNode, QoreBigIntNode, QoreNullNode, BinaryNode, QoreNothingNode, and QoreBoolNode.

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, QoreObject, QoreNumberNode, QoreStringNode, QoreListNode, QoreHashNode, QoreFloatNode, QoreBigIntNode, ReferenceNode, and BinaryNode.

DLLEXPORT AbstractQoreNode* AbstractQoreNode::refSelf | ( |  | ) | const

returns "this" with an incremented reference count

Returns
  "this" with an incremented reference count

## Member Data Documentation

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 making either a virtual function call or using dynamic_cast<> at the expense of more memory usage

Referenced by getType().

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

- include/qore/AbstractQoreNode.h (6585)