Qore Programming Language  0.9.16
AbstractQoreNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  AbstractQoreNode.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2018 Qore Technologies, s.r.o.
8 
9  Permission is hereby granted, free of charge, to any person obtaining a
10  copy of this software and associated documentation files (the "Software"),
11  to deal in the Software without restriction, including without limitation
12  the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  and/or sell copies of the Software, and to permit persons to whom the
14  Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  DEALINGS IN THE SOFTWARE.
26 
27  Note that the Qore library is released under a choice of three open-source
28  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29  information.
30 */
31 
32 #ifndef _QORE_ABSTRACTQORENODE_H
33 
34 #define _QORE_ABSTRACTQORENODE_H
35 
36 #include <qore/common.h>
37 #include <qore/QoreReferenceCounter.h>
38 #include <qore/node_types.h>
39 
40 #include <string>
41 
42 #include <cassert>
43 
44 #define FMT_YAML_SHORT -2
45 #define FMT_NONE -1
46 #define FMT_NORMAL 0
47 
48 class LocalVar;
49 
51 
55 public:
57 
64  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);
65 
67  DLLEXPORT AbstractQoreNode(const AbstractQoreNode& v);
68 
70 
73  DLLEXPORT bool getAsBool() const;
74 
76 
79  DLLEXPORT int getAsInt() const;
80 
82 
85  DLLEXPORT int64 getAsBigInt() const;
86 
88 
91  DLLEXPORT double getAsFloat() const;
92 
94 
99  DLLEXPORT virtual QoreString* getStringRepresentation(bool& del) const;
100 
102 
105  DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
106 
108 
112  DLLEXPORT virtual class DateTime* getDateTimeRepresentation(bool& del) const;
113 
115 
118  DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
119 
121 
127  DLLEXPORT virtual int getAsString(QoreString &str, int foff, ExceptionSink* xsink) const = 0;
128 
130 
136  DLLEXPORT virtual QoreString *getAsString(bool& del, int foff, ExceptionSink* xsink) const = 0;
137 
139 
142  DLLLOCAL bool needs_eval() const {
143  return needs_eval_flag;
144  }
145 
147 
150  DLLEXPORT virtual AbstractQoreNode* realCopy() const = 0;
151 
153 
158  DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const = 0;
159 
161 
166  DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const = 0;
167 
169 
172  DLLLOCAL qore_type_t getType() const {
173  return type;
174  }
175 
177 
180  DLLEXPORT virtual const char* getTypeName() const = 0;
181 
183 
199  DLLEXPORT QoreValue eval(ExceptionSink* xsink) const;
200 
202 
214  DLLEXPORT QoreValue eval(bool& needs_deref, ExceptionSink* xsink) const;
215 
217 
220  DLLLOCAL bool is_value() const {
221  return value;
222  }
223 
225 
229  DLLEXPORT void deref(ExceptionSink* xsink);
230 
232 
235  DLLEXPORT AbstractQoreNode* refSelf() const;
236 
238  DLLEXPORT void ref() const;
239 
241  DLLLOCAL bool isReferenceCounted() const { return !there_can_be_only_one; }
242 
244 
251  DLLLOCAL virtual void parseInit(QoreValue& val, LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo);
252 
254  DLLLOCAL AbstractQoreNode& operator=(const AbstractQoreNode&);
255 
257 
260  DLLLOCAL virtual bool getAsBoolImpl() const { return false; }
261 
263 
266  DLLLOCAL virtual int getAsIntImpl() const { return 0; }
267 
269 
272  DLLLOCAL virtual int64 getAsBigIntImpl() const { return 0; }
273 
275 
278  DLLLOCAL virtual double getAsFloatImpl() const { return 0.0; }
279 
281 
293  DLLEXPORT virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const = 0;
294 
296 
301  DLLEXPORT virtual bool derefImpl(ExceptionSink* xsink);
302 
304 
308  DLLEXPORT virtual void customRef() const;
309 
314  DLLEXPORT virtual void customDeref(ExceptionSink* xsink);
315 
316 protected:
318 
322 
324  bool value : 1;
325 
327  bool needs_eval_flag : 1;
328 
331 
334 
336 
339  DLLEXPORT virtual ~AbstractQoreNode();
340 };
341 
343 
347 public:
349  SimpleQoreNode& operator=(const SimpleQoreNode&) = delete;
350 
352  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) { }
353 
355  DLLLOCAL SimpleQoreNode(const SimpleQoreNode& v) : AbstractQoreNode(v) { }
356 
358 
362  DLLEXPORT void deref();
363 };
364 
367 public:
369  DLLLOCAL SimpleValueQoreNode(qore_type_t t, bool n_there_can_be_only_one = false) : SimpleQoreNode(t, true, false, n_there_can_be_only_one) { }
370 
371  DLLLOCAL SimpleValueQoreNode(const SimpleValueQoreNode& v) : SimpleQoreNode(v) { }
372 
373 protected:
375 
377  DLLEXPORT virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
378 };
379 
381 
384 public:
386  DLLLOCAL UniqueValueQoreNode& operator=(const UniqueValueQoreNode&) = delete;
387 
389  DLLLOCAL void *operator new(size_t) = delete;
390 
393 
396 
398  DLLEXPORT virtual AbstractQoreNode* realCopy() const;
399 };
400 
401 #endif
node_types.h
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:352
AbstractQoreNode::isReferenceCounted
DLLLOCAL bool isReferenceCounted() const
returns true if the object is reference-counted
Definition: AbstractQoreNode.h:241
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:142
AbstractQoreNode::getAsBoolImpl
virtual DLLLOCAL bool getAsBoolImpl() const
default implementation, returns false
Definition: AbstractQoreNode.h:260
AbstractQoreNode::getAsFloatImpl
virtual DLLLOCAL double getAsFloatImpl() const
default implementation, returns 0.0
Definition: AbstractQoreNode.h:278
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:324
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
AbstractQoreNode::getTypeName
virtual const DLLEXPORT char * getTypeName() const =0
returns the type name as a c string
AbstractQoreNode::refSelf
DLLEXPORT AbstractQoreNode * refSelf() const
returns "this" with an incremented reference count
AbstractQoreNode::getDateTimeRepresentation
virtual DLLEXPORT class DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this type (default implementation: returns ZeroDate,...
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:330
AbstractQoreNode::customDeref
virtual DLLEXPORT void customDeref(ExceptionSink *xsink)
AbstractQoreNode::getAsBool
DLLEXPORT bool getAsBool() const
returns the boolean value of the object
AbstractQoreNode::derefImpl
virtual DLLEXPORT bool derefImpl(ExceptionSink *xsink)
decrements the reference count
UniqueValueQoreNode::UniqueValueQoreNode
DLLLOCAL UniqueValueQoreNode(qore_type_t t)
constructor takes the type argument
Definition: AbstractQoreNode.h:392
AbstractQoreNode::custom_reference_handlers
bool custom_reference_handlers
set to one for objects that need custom reference handlers
Definition: AbstractQoreNode.h:333
AbstractQoreNode::getType
DLLLOCAL qore_type_t getType() const
returns the data type
Definition: AbstractQoreNode.h:172
AbstractQoreNode::is_equal_hard
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 c...
AbstractQoreNode::~AbstractQoreNode
virtual DLLEXPORT ~AbstractQoreNode()
default destructor 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:260
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::getAsBigIntImpl
virtual DLLLOCAL int64 getAsBigIntImpl() const
default implementation, returns 0
Definition: AbstractQoreNode.h:272
AbstractQoreNode::is_value
DLLLOCAL bool is_value() const
returns true if the node represents a value
Definition: AbstractQoreNode.h:220
QoreString
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
AbstractQoreNode::realCopy
virtual DLLEXPORT AbstractQoreNode * realCopy() const =0
returns a copy of the object; the caller owns the reference count
AbstractQoreNode::customRef
virtual DLLEXPORT void customRef() const
special processing when the object's reference count transitions from 0-1
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::needs_eval_flag
bool needs_eval_flag
if this is true then the type can be evaluated
Definition: AbstractQoreNode.h:327
SimpleValueQoreNode
base class for simple value types
Definition: AbstractQoreNode.h:366
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 "value" flag, unsetting the "needs_eval...
Definition: AbstractQoreNode.h:369
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
AbstractQoreNode::eval
DLLEXPORT QoreValue eval(ExceptionSink *xsink) const
evaluates the object and returns a value (or 0)
QoreReferenceCounter
provides atomic reference counting to Qore objects
Definition: QoreReferenceCounter.h:44
UniqueValueQoreNode
this class is for value types that will exists only once in the Qore library, reference counting is d...
Definition: AbstractQoreNode.h:383
AbstractQoreNode::getAsIntImpl
virtual DLLLOCAL int getAsIntImpl() const
default implementation, returns 0
Definition: AbstractQoreNode.h:266
AbstractQoreNode::evalImpl
virtual DLLEXPORT QoreValue evalImpl(bool &needs_deref, ExceptionSink *xsink) const =0
optionally evaluates the argument
AbstractQoreNode::ref
DLLEXPORT void ref() const
increments the reference count
common.h
UniqueValueQoreNode::operator=
DLLLOCAL UniqueValueQoreNode & operator=(const UniqueValueQoreNode &)=delete
this function is not implemented
DateTime
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
AbstractQoreNode::getAsFloat
DLLEXPORT double getAsFloat() const
returns the float value of the object
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
AbstractQoreNode::deref
DLLEXPORT void deref(ExceptionSink *xsink)
decrements the reference count and calls derefImpl() if there_can_be_only_one is false,...
AbstractQoreNode::getAsInt
DLLEXPORT int getAsInt() const
returns the integer value of the object
AbstractQoreNode::is_equal_soft
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 ...
AbstractQoreNode::type
qore_type_t type
the type of the object
Definition: AbstractQoreNode.h:321
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
SimpleQoreNode::operator=
SimpleQoreNode & operator=(const SimpleQoreNode &)=delete
this function is not implemented
SimpleValueQoreNode::evalImpl
virtual DLLEXPORT QoreValue evalImpl(bool &needs_deref, ExceptionSink *xsink) const
should never be called for value types
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
qore_type_t
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode)
Definition: common.h:70
AbstractQoreNode::getAsBigInt
DLLEXPORT int64 getAsBigInt() const
returns the 64-bit integer value of the object
AbstractQoreNode::operator=
DLLLOCAL AbstractQoreNode & operator=(const AbstractQoreNode &)
this function is not implemented; it is here as a private function in order to prohibit it from being...
AbstractQoreNode::parseInit
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 l...
SimpleQoreNode
The base class for all types in Qore expression trees that cannot throw an exception when deleted.
Definition: AbstractQoreNode.h:346