Qore Programming Language 0.8.8

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

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AbstractQoreNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3 AbstractQoreNode.h
4
5 Qore Programming Language
6
7 Copyright 2003 - 2013 David Nichols
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #ifndef _QORE_ABSTRACTQORENODE_H
25
26 #define _QORE_ABSTRACTQORENODE_H
27
28 #include <qore/common.h>
29 #include <qore/QoreReferenceCounter.h>
30 #include <qore/node_types.h>
31
32 #include <string>
33
34 #include <assert.h>
35
36 #define FMT_YAML_SHORT -2
37 #define FMT_NONE -1
38 #define FMT_NORMAL 0
39
40 class LocalVar;
41 class QoreTypeInfo;
42
44
47 class AbstractQoreNode : public QoreReferenceCounter {
48 private:
50 DLLLOCAL AbstractQoreNode& operator=(const AbstractQoreNode&);
51
53
56 DLLLOCAL virtual bool getAsBoolImpl() const { return false; }
57
59
62 DLLLOCAL virtual int getAsIntImpl() const { return 0; }
63
65
68 DLLLOCAL virtual int64 getAsBigIntImpl() const { return 0; }
69
71
74 DLLLOCAL virtual double getAsFloatImpl() const { return 0.0; }
75
77
84 DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const = 0;
85
87
93 DLLEXPORT virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const = 0;
94
96
100 DLLEXPORT virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
101
103
107 DLLEXPORT virtual int integerEvalImpl(ExceptionSink *xsink) const;
108
110
114 DLLEXPORT virtual bool boolEvalImpl(ExceptionSink *xsink) const;
115
117
121 DLLEXPORT virtual double floatEvalImpl(ExceptionSink *xsink) const;
122
124
129 DLLEXPORT virtual bool derefImpl(ExceptionSink *xsink);
130
132
136 DLLEXPORT virtual void customRef() const;
137
142 DLLEXPORT virtual void customDeref(ExceptionSink *xsink);
143
144 protected:
146
149 qore_type_t type : 11;
150
152 bool value : 1;
153
155 bool needs_eval_flag : 1;
156
158 bool there_can_be_only_one : 1;
159
161 bool custom_reference_handlers : 1;
162
164
167 DLLEXPORT virtual ~AbstractQoreNode();
168
169 public:
171
178 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);
179
181 DLLEXPORT AbstractQoreNode(const AbstractQoreNode& v);
182
184
187 DLLEXPORT bool getAsBool() const;
188
190
193 DLLEXPORT int getAsInt() const;
194
196
199 DLLEXPORT int64 getAsBigInt() const;
200
202
205 DLLEXPORT double getAsFloat() const;
206
208
213 DLLEXPORT virtual QoreString *getStringRepresentation(bool &del) const;
214
216
219 DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
220
222
226 DLLEXPORT virtual class DateTime *getDateTimeRepresentation(bool &del) const;
227
229
232 DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
233
235
241 DLLEXPORT virtual int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const = 0;
242
244
250 DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, ExceptionSink *xsink) const = 0;
251
253
256 DLLLOCAL bool needs_eval() const {
257 return needs_eval_flag;
258 }
259
261
264 DLLEXPORT virtual AbstractQoreNode *realCopy() const = 0;
265
267
272 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const = 0;
273
275
280 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const = 0;
281
283
286 DLLLOCAL qore_type_t getType() const {
287 return type;
288 }
289
291
294 DLLEXPORT virtual const char *getTypeName() const = 0;
295
297
310 DLLEXPORT AbstractQoreNode *eval(ExceptionSink *xsink) const;
311
313
321 DLLEXPORT AbstractQoreNode *eval(bool &needs_deref, ExceptionSink *xsink) const;
322
324
328 DLLEXPORT int64 bigIntEval(ExceptionSink *xsink) const;
329
331
335 DLLEXPORT int integerEval(ExceptionSink *xsink) const;
336
338
342 DLLEXPORT bool boolEval(ExceptionSink *xsink) const;
343
345
349 DLLEXPORT double floatEval(ExceptionSink *xsink) const;
350
352
355 DLLLOCAL bool is_value() const {
356 return value;
357 }
358
360
364 DLLEXPORT void deref(ExceptionSink *xsink);
365
367
370 DLLEXPORT AbstractQoreNode *refSelf() const;
371
373 DLLEXPORT void ref() const;
374
376 DLLLOCAL bool isReferenceCounted() const { return !there_can_be_only_one; }
377
379
389 DLLEXPORT virtual AbstractQoreNode *parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo);
390 };
391
393
396 class SimpleQoreNode : public AbstractQoreNode {
397 private:
399 DLLLOCAL SimpleQoreNode& operator=(const SimpleQoreNode&);
400
401 public:
403 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) { }
404
406 DLLLOCAL SimpleQoreNode(const SimpleQoreNode& v) : AbstractQoreNode(v) { }
407
409
412 using AbstractQoreNode::deref;
413 DLLEXPORT void deref();
414 };
415
417 class SimpleValueQoreNode : public SimpleQoreNode {
418 private:
419
420 protected:
422
424 DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const;
425
427
429 DLLEXPORT virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const;
430
432
434 DLLEXPORT virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
435
437
439 DLLEXPORT virtual int integerEvalImpl(ExceptionSink *xsink) const;
440
442
444 DLLEXPORT virtual bool boolEvalImpl(ExceptionSink *xsink) const;
445
447
449 DLLEXPORT virtual double floatEvalImpl(ExceptionSink *xsink) const;
450
451 public:
453 DLLLOCAL SimpleValueQoreNode(qore_type_t t, bool n_there_can_be_only_one = false) : SimpleQoreNode(t, true, false, n_there_can_be_only_one) { }
454
455 DLLLOCAL SimpleValueQoreNode(const SimpleValueQoreNode &v) : SimpleQoreNode(v) { }
456 };
457
459
461 class UniqueValueQoreNode : public SimpleValueQoreNode {
462 private:
464 DLLLOCAL UniqueValueQoreNode& operator=(const UniqueValueQoreNode&);
465
467 DLLLOCAL void *operator new(size_t);
468
469 protected:
470
471 public:
473 DLLLOCAL UniqueValueQoreNode(qore_type_t t) : SimpleValueQoreNode(t, true) { }
474
476 DLLLOCAL UniqueValueQoreNode(const UniqueValueQoreNode &) : SimpleValueQoreNode(type, true) { }
477
479 DLLEXPORT virtual AbstractQoreNode *realCopy() const;
480 };
481
482 #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:85
UniqueValueQoreNode::UniqueValueQoreNode
DLLLOCAL UniqueValueQoreNode(qore_type_t t)
constructor takes the type argument
Definition: AbstractQoreNode.h:473
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:406
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:47
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:476
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
qore_type_t
signed short qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:58
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:42
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:161
AbstractQoreNode::needs_eval_flag
bool needs_eval_flag
if this is true then the type can be evaluated
Definition: AbstractQoreNode.h:155
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:461
QoreReferenceCounter
provides atomic reference counting to Qore objects
Definition: QoreReferenceCounter.h:34
AbstractQoreNode::is_value
DLLLOCAL bool is_value() const
returns true if the node represents a value
Definition: AbstractQoreNode.h:355
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:396
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:35
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:256
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
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:453
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:286
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:158
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:403
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:152
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:417
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:376
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:149
node_types.h