All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AbstractQoreNode.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
AbstractQoreNode.h
Qore Programming Language
Copyright (C) 2003 - 2015 David Nichols
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_ABSTRACTQORENODE_H
#define _QORE_ABSTRACTQORENODE_H
#include <qore/common.h>
#include <qore/QoreReferenceCounter.h>
#include <qore/node_types.h>
#include <string>
#include <assert.h>
#define FMT_YAML_SHORT -2
#define FMT_NONE -1
#define FMT_NORMAL 0
class LocalVar;
class QoreTypeInfo;
class AbstractQoreNode : public QoreReferenceCounter {
private:
DLLLOCAL AbstractQoreNode& operator=(const AbstractQoreNode&);
DLLLOCAL virtual bool getAsBoolImpl() const { return false; }
DLLLOCAL virtual int getAsIntImpl() const { return 0; }
DLLLOCAL virtual int64 getAsBigIntImpl() const { return 0; }
DLLLOCAL virtual double getAsFloatImpl() const { return 0.0; }
DLLEXPORT virtual AbstractQoreNode* evalImpl(ExceptionSink* xsink) const = 0;
DLLEXPORT virtual AbstractQoreNode* evalImpl(bool& needs_deref, ExceptionSink* xsink) const = 0;
DLLEXPORT virtual int64 bigIntEvalImpl(ExceptionSink* xsink) const;
DLLEXPORT virtual int integerEvalImpl(ExceptionSink* xsink) const;
DLLEXPORT virtual bool boolEvalImpl(ExceptionSink* xsink) const;
DLLEXPORT virtual double floatEvalImpl(ExceptionSink* xsink) const;
DLLEXPORT virtual bool derefImpl(ExceptionSink* xsink);
DLLEXPORT virtual void customRef() const;
DLLEXPORT virtual void customDeref(ExceptionSink* xsink);
protected:
qore_type_t type : 11;
bool value : 1;
bool needs_eval_flag : 1;
bool there_can_be_only_one : 1;
bool custom_reference_handlers : 1;
bool has_value_api : 1;
DLLEXPORT virtual ~AbstractQoreNode();
public:
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);
DLLEXPORT AbstractQoreNode(const AbstractQoreNode& v);
DLLEXPORT bool getAsBool() const;
DLLEXPORT int getAsInt() const;
DLLEXPORT int64 getAsBigInt() const;
DLLEXPORT double getAsFloat() const;
DLLEXPORT virtual QoreString *getStringRepresentation(bool& del) const;
DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
DLLEXPORT virtual class DateTime *getDateTimeRepresentation(bool& del) const;
DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
DLLEXPORT virtual int getAsString(QoreString &str, int foff, ExceptionSink* xsink) const = 0;
DLLEXPORT virtual QoreString *getAsString(bool& del, int foff, ExceptionSink* xsink) const = 0;
DLLLOCAL bool needs_eval() const {
return needs_eval_flag;
}
DLLEXPORT virtual AbstractQoreNode* realCopy() const = 0;
DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const = 0;
DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const = 0;
DLLLOCAL qore_type_t getType() const {
return type;
}
DLLEXPORT virtual const char* getTypeName() const = 0;
DLLEXPORT AbstractQoreNode* eval(ExceptionSink* xsink) const;
DLLEXPORT AbstractQoreNode* eval(bool& needs_deref, ExceptionSink* xsink) const;
DLLEXPORT int64 bigIntEval(ExceptionSink* xsink) const;
DLLEXPORT int integerEval(ExceptionSink* xsink) const;
DLLEXPORT bool boolEval(ExceptionSink* xsink) const;
DLLEXPORT double floatEval(ExceptionSink* xsink) const;
DLLLOCAL bool is_value() const {
return value;
}
DLLEXPORT void deref(ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* refSelf() const;
DLLEXPORT void ref() const;
DLLLOCAL bool isReferenceCounted() const { return !there_can_be_only_one; }
DLLEXPORT virtual AbstractQoreNode* parseInit(LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo);
// new eval APIs - to be virtual in bew API
DLLEXPORT QoreValue evalValue(ExceptionSink* xsink) const;
DLLEXPORT QoreValue evalValue(bool& needs_deref, ExceptionSink* xsink) const;
DLLLOCAL bool hasValueApi() const;
};
class SimpleQoreNode : public AbstractQoreNode {
private:
DLLLOCAL SimpleQoreNode& operator=(const SimpleQoreNode&);
public:
DLLLOCAL SimpleQoreNode(qore_type_t t, bool n_value, bool n_needs_eval, bool n_there_can_be_only_one = false) : AbstractQoreNode(t, n_value, n_needs_eval, n_there_can_be_only_one) { }
DLLLOCAL SimpleQoreNode(const SimpleQoreNode& v) : AbstractQoreNode(v) { }
using AbstractQoreNode::deref;
DLLEXPORT void deref();
};
class SimpleValueQoreNode : public SimpleQoreNode {
private:
protected:
DLLEXPORT virtual AbstractQoreNode* evalImpl(ExceptionSink* xsink) const;
DLLEXPORT virtual AbstractQoreNode* evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
DLLEXPORT virtual int64 bigIntEvalImpl(ExceptionSink* xsink) const;
DLLEXPORT virtual int integerEvalImpl(ExceptionSink* xsink) const;
DLLEXPORT virtual bool boolEvalImpl(ExceptionSink* xsink) const;
DLLEXPORT virtual double floatEvalImpl(ExceptionSink* xsink) const;
public:
DLLLOCAL SimpleValueQoreNode(qore_type_t t, bool n_there_can_be_only_one = false) : SimpleQoreNode(t, true, false, n_there_can_be_only_one) { }
DLLLOCAL SimpleValueQoreNode(const SimpleValueQoreNode& v) : SimpleQoreNode(v) { }
};
class UniqueValueQoreNode : public SimpleValueQoreNode {
private:
DLLLOCAL UniqueValueQoreNode& operator=(const UniqueValueQoreNode&);
DLLLOCAL void *operator new(size_t);
protected:
public:
DLLLOCAL UniqueValueQoreNode(qore_type_t t) : SimpleValueQoreNode(t, true) { }
DLLLOCAL UniqueValueQoreNode(const UniqueValueQoreNode& ) : SimpleValueQoreNode(type, true) { }
DLLEXPORT virtual AbstractQoreNode* realCopy() const;
};
#endif
AbstractQoreNode::refSelf
DLLEXPORT AbstractQoreNode * refSelf() const
returns &quot;this&quot; with an incremented reference count
AbstractQoreNode::parseInit
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
AbstractQoreNode::getAsBool
DLLEXPORT bool getAsBool() const
returns the boolean value of the object
AbstractQoreNode::getAsString
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 contai...
AbstractQoreNode::eval
DLLEXPORT AbstractQoreNode * eval(ExceptionSink *xsink) const
evaluates the object and returns a value (or 0)
AbstractQoreNode::getAsFloat
DLLEXPORT double getAsFloat() const
returns the float value of the object
SimpleValueQoreNode::bigIntEvalImpl
virtual DLLEXPORT int64 bigIntEvalImpl(ExceptionSink *xsink) const
should never be called for value types
AbstractQoreNode::bigIntEval
DLLEXPORT int64 bigIntEval(ExceptionSink *xsink) const
evaluates the object and returns a 64-bit integer value
DateTime
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
UniqueValueQoreNode::UniqueValueQoreNode
DLLLOCAL UniqueValueQoreNode(qore_type_t t)
constructor takes the type argument
Definition: AbstractQoreNode.h:491
AbstractQoreNode::integerEval
DLLEXPORT int integerEval(ExceptionSink *xsink) const
evaluates the object and returns an integer value
SimpleQoreNode::SimpleQoreNode
DLLLOCAL SimpleQoreNode(const SimpleQoreNode &v)
copy constructor
Definition: AbstractQoreNode.h:424
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
AbstractQoreNode::getStringRepresentation
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns the value of the type converted to a string, default implementation: returns the empty string...
UniqueValueQoreNode::UniqueValueQoreNode
DLLLOCAL UniqueValueQoreNode(const UniqueValueQoreNode &)
copy constructor
Definition: AbstractQoreNode.h:494
AbstractQoreNode::getDateTimeRepresentation
virtual DLLEXPORT class DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this type (default implementation: returns ZeroDate...
AbstractQoreNode::is_equal_hard
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const =0
tests for equality (&quot;deep compare&quot; including all contained values for container types) without type c...
AbstractQoreNode::boolEval
DLLEXPORT bool boolEval(ExceptionSink *xsink) const
evaluates the object and returns a boolean value
AbstractQoreNode::getAsInt
DLLEXPORT int getAsInt() const
returns the integer value of the object
AbstractQoreNode::getAsBigInt
DLLEXPORT int64 getAsBigInt() const
returns the 64-bit integer value of the object
AbstractQoreNode::getTypeName
virtual DLLEXPORT const char * getTypeName() const =0
returns the type name as a c string
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:82
SimpleValueQoreNode::evalImpl
virtual DLLEXPORT AbstractQoreNode * evalImpl(ExceptionSink *xsink) const
should never be called for value types
AbstractQoreNode::custom_reference_handlers
bool custom_reference_handlers
set to one for objects that need custom reference handlers
Definition: AbstractQoreNode.h:169
AbstractQoreNode::needs_eval_flag
bool needs_eval_flag
if this is true then the type can be evaluated
Definition: AbstractQoreNode.h:163
SimpleValueQoreNode::floatEvalImpl
virtual DLLEXPORT double floatEvalImpl(ExceptionSink *xsink) const
should never be called for value types
UniqueValueQoreNode
this class is for value types that will exists only once in the Qore library, reference counting is d...
Definition: AbstractQoreNode.h:479
QoreReferenceCounter
provides atomic reference counting to Qore objects
Definition: QoreReferenceCounter.h:42
AbstractQoreNode::is_value
DLLLOCAL bool is_value() const
returns true if the node represents a value
Definition: AbstractQoreNode.h:366
SimpleValueQoreNode::integerEvalImpl
virtual DLLEXPORT int integerEvalImpl(ExceptionSink *xsink) const
should never be called for value types
AbstractQoreNode::ref
DLLEXPORT void ref() const
increments the reference count
AbstractQoreNode::realCopy
virtual DLLEXPORT AbstractQoreNode * realCopy() const =0
returns a copy of the object; the caller owns the reference count
SimpleQoreNode
The base class for all types in Qore expression trees that cannot throw an exception when deleted...
Definition: AbstractQoreNode.h:414
SimpleValueQoreNode::boolEvalImpl
virtual DLLEXPORT bool boolEvalImpl(ExceptionSink *xsink) const
should never be called for value types
ExceptionSink
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:43
AbstractQoreNode::needs_eval
DLLLOCAL bool needs_eval() const
returns true if the object needs evaluation to return a value, false if not
Definition: AbstractQoreNode.h:267
AbstractQoreNode::has_value_api
bool has_value_api
set to flag with new QoreValue API (derived from ParseNode) - FIXME: to be removed when new ABI is im...
Definition: AbstractQoreNode.h:172
AbstractQoreNode::hasValueApi
DLLLOCAL bool hasValueApi() const
returns the &quot;has value api&quot; flags - FIXME: remove with new ABI
AbstractQoreNode::deref
DLLEXPORT void deref(ExceptionSink *xsink)
decrements the reference count and calls derefImpl() if there_can_be_only_one is false, otherwise does nothing
int64
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:228
SimpleValueQoreNode::SimpleValueQoreNode
DLLLOCAL SimpleValueQoreNode(qore_type_t t, bool n_there_can_be_only_one=false)
creates the object by assigning the type code and setting the &quot;value&quot; flag, unsetting the &quot;needs_eval...
Definition: AbstractQoreNode.h:471
AbstractQoreNode::AbstractQoreNode
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
AbstractQoreNode::getType
DLLLOCAL qore_type_t getType() const
returns the data type
Definition: AbstractQoreNode.h:297
AbstractQoreNode::there_can_be_only_one
bool there_can_be_only_one
if this is set to true, then reference counting is turned off for objects of this class ...
Definition: AbstractQoreNode.h:166
SimpleQoreNode::SimpleQoreNode
DLLLOCAL SimpleQoreNode(qore_type_t t, bool n_value, bool n_needs_eval, bool n_there_can_be_only_one=false)
constructor takes the type and value arguments
Definition: AbstractQoreNode.h:421
qore_type_t
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:68
AbstractQoreNode::value
bool value
this is true for values, if false then either the type needs evaluation to produce a value or is a pa...
Definition: AbstractQoreNode.h:160
common.h
UniqueValueQoreNode::realCopy
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns itself; objects of this type are not reference-counted and only deleted manually (by static d...
AbstractQoreNode::~AbstractQoreNode
virtual DLLEXPORT ~AbstractQoreNode()
default destructor does nothing
SimpleValueQoreNode
base class for simple value types
Definition: AbstractQoreNode.h:435
AbstractQoreNode::is_equal_soft
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const =0
tests for equality (&quot;deep compare&quot; including all contained values for container types) with possible ...
AbstractQoreNode::isReferenceCounted
DLLLOCAL bool isReferenceCounted() const
returns true if the object is reference-counted
Definition: AbstractQoreNode.h:387
AbstractQoreNode::floatEval
DLLEXPORT double floatEval(ExceptionSink *xsink) const
evaluates the object and returns a floating-point value
AbstractQoreNode::type
qore_type_t type
the type of the object
Definition: AbstractQoreNode.h:157
node_types.h