Qore Programming Language  0.8.11.1
AbstractQoreNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  AbstractQoreNode.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2014 David Nichols
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 <assert.h>
43 
44 #define FMT_YAML_SHORT -2
45 #define FMT_NONE -1
46 #define FMT_NORMAL 0
47 
48 class LocalVar;
49 class QoreTypeInfo;
50 
52 
56 private:
58  DLLLOCAL AbstractQoreNode& operator=(const AbstractQoreNode&);
59 
61 
64  DLLLOCAL virtual bool getAsBoolImpl() const { return false; }
65 
67 
70  DLLLOCAL virtual int getAsIntImpl() const { return 0; }
71 
73 
76  DLLLOCAL virtual int64 getAsBigIntImpl() const { return 0; }
77 
79 
82  DLLLOCAL virtual double getAsFloatImpl() const { return 0.0; }
83 
85 
92  DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const = 0;
93 
95 
101  DLLEXPORT virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const = 0;
102 
104 
108  DLLEXPORT virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
109 
111 
115  DLLEXPORT virtual int integerEvalImpl(ExceptionSink *xsink) const;
116 
118 
122  DLLEXPORT virtual bool boolEvalImpl(ExceptionSink *xsink) const;
123 
125 
129  DLLEXPORT virtual double floatEvalImpl(ExceptionSink *xsink) const;
130 
132 
137  DLLEXPORT virtual bool derefImpl(ExceptionSink *xsink);
138 
140 
144  DLLEXPORT virtual void customRef() const;
145 
150  DLLEXPORT virtual void customDeref(ExceptionSink *xsink);
151 
152 protected:
154 
158 
160  bool value : 1;
161 
163  bool needs_eval_flag : 1;
164 
167 
170 
172 
175  DLLEXPORT virtual ~AbstractQoreNode();
176 
177 public:
179 
186  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);
187 
189  DLLEXPORT AbstractQoreNode(const AbstractQoreNode& v);
190 
192 
195  DLLEXPORT bool getAsBool() const;
196 
198 
201  DLLEXPORT int getAsInt() const;
202 
204 
207  DLLEXPORT int64 getAsBigInt() const;
208 
210 
213  DLLEXPORT double getAsFloat() const;
214 
216 
221  DLLEXPORT virtual QoreString *getStringRepresentation(bool &del) const;
222 
224 
227  DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
228 
230 
234  DLLEXPORT virtual class DateTime *getDateTimeRepresentation(bool &del) const;
235 
237 
240  DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
241 
243 
249  DLLEXPORT virtual int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const = 0;
250 
252 
258  DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, ExceptionSink *xsink) const = 0;
259 
261 
264  DLLLOCAL bool needs_eval() const {
265  return needs_eval_flag;
266  }
267 
269 
272  DLLEXPORT virtual AbstractQoreNode *realCopy() const = 0;
273 
275 
280  DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const = 0;
281 
283 
288  DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const = 0;
289 
291 
294  DLLLOCAL qore_type_t getType() const {
295  return type;
296  }
297 
299 
302  DLLEXPORT virtual const char *getTypeName() const = 0;
303 
305 
318  DLLEXPORT AbstractQoreNode *eval(ExceptionSink *xsink) const;
319 
321 
329  DLLEXPORT AbstractQoreNode *eval(bool &needs_deref, ExceptionSink *xsink) const;
330 
332 
336  DLLEXPORT int64 bigIntEval(ExceptionSink *xsink) const;
337 
339 
343  DLLEXPORT int integerEval(ExceptionSink *xsink) const;
344 
346 
350  DLLEXPORT bool boolEval(ExceptionSink *xsink) const;
351 
353 
357  DLLEXPORT double floatEval(ExceptionSink *xsink) const;
358 
360 
363  DLLLOCAL bool is_value() const {
364  return value;
365  }
366 
368 
372  DLLEXPORT void deref(ExceptionSink *xsink);
373 
375 
378  DLLEXPORT AbstractQoreNode *refSelf() const;
379 
381  DLLEXPORT void ref() const;
382 
384  DLLLOCAL bool isReferenceCounted() const { return !there_can_be_only_one; }
385 
387 
397  DLLEXPORT virtual AbstractQoreNode *parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo);
398 };
399 
401 
405 private:
407  DLLLOCAL SimpleQoreNode& operator=(const SimpleQoreNode&);
408 
409 public:
411  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) { }
412 
414  DLLLOCAL SimpleQoreNode(const SimpleQoreNode& v) : AbstractQoreNode(v) { }
415 
417 
421  DLLEXPORT void deref();
422 };
423 
426 private:
427 
428 protected:
430 
432  DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const;
433 
435 
437  DLLEXPORT virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const;
438 
440 
442  DLLEXPORT virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
443 
445 
447  DLLEXPORT virtual int integerEvalImpl(ExceptionSink *xsink) const;
448 
450 
452  DLLEXPORT virtual bool boolEvalImpl(ExceptionSink *xsink) const;
453 
455 
457  DLLEXPORT virtual double floatEvalImpl(ExceptionSink *xsink) const;
458 
459 public:
461  DLLLOCAL SimpleValueQoreNode(qore_type_t t, bool n_there_can_be_only_one = false) : SimpleQoreNode(t, true, false, n_there_can_be_only_one) { }
462 
463  DLLLOCAL SimpleValueQoreNode(const SimpleValueQoreNode &v) : SimpleQoreNode(v) { }
464 };
465 
467 
470 private:
472  DLLLOCAL UniqueValueQoreNode& operator=(const UniqueValueQoreNode&);
473 
475  DLLLOCAL void *operator new(size_t);
476 
477 protected:
478 
479 public:
482 
485 
487  DLLEXPORT virtual AbstractQoreNode *realCopy() const;
488 };
489 
490 #endif
DLLEXPORT AbstractQoreNode * refSelf() const
returns "this" with an incremented reference count
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
DLLEXPORT bool getAsBool() const
returns the boolean value of the object
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...
DLLEXPORT AbstractQoreNode * eval(ExceptionSink *xsink) const
evaluates the object and returns a value (or 0)
DLLEXPORT double getAsFloat() const
returns the float value of the object
virtual DLLEXPORT int64 bigIntEvalImpl(ExceptionSink *xsink) const
should never be called for value types
DLLEXPORT int64 bigIntEval(ExceptionSink *xsink) const
evaluates the object and returns a 64-bit integer value
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
DLLLOCAL UniqueValueQoreNode(qore_type_t t)
constructor takes the type argument
Definition: AbstractQoreNode.h:481
DLLEXPORT int integerEval(ExceptionSink *xsink) const
evaluates the object and returns an integer value
DLLLOCAL SimpleQoreNode(const SimpleQoreNode &v)
copy constructor
Definition: AbstractQoreNode.h:414
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns the value of the type converted to a string, default implementation: returns the empty string...
DLLLOCAL UniqueValueQoreNode(const UniqueValueQoreNode &)
copy constructor
Definition: AbstractQoreNode.h:484
virtual DLLEXPORT class DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this type (default implementation: returns ZeroDate...
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...
DLLEXPORT bool boolEval(ExceptionSink *xsink) const
evaluates the object and returns a boolean value
DLLEXPORT int getAsInt() const
returns the integer value of the object
DLLEXPORT int64 getAsBigInt() const
returns the 64-bit integer value of the object
signed short qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:67
virtual DLLEXPORT const char * getTypeName() const =0
returns the type name as a c string
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:50
virtual DLLEXPORT AbstractQoreNode * evalImpl(ExceptionSink *xsink) const
should never be called for value types
bool custom_reference_handlers
set to one for objects that need custom reference handlers
Definition: AbstractQoreNode.h:169
bool needs_eval_flag
if this is true then the type can be evaluated
Definition: AbstractQoreNode.h:163
virtual DLLEXPORT double floatEvalImpl(ExceptionSink *xsink) const
should never be called for value types
this class is for value types that will exists only once in the Qore library, reference counting is d...
Definition: AbstractQoreNode.h:469
provides atomic reference counting to Qore objects
Definition: QoreReferenceCounter.h:42
DLLLOCAL bool is_value() const
returns true if the node represents a value
Definition: AbstractQoreNode.h:363
virtual DLLEXPORT int integerEvalImpl(ExceptionSink *xsink) const
should never be called for value types
DLLEXPORT void ref() const
increments the reference count
virtual DLLEXPORT AbstractQoreNode * realCopy() const =0
returns a copy of the object; the caller owns the reference count
The base class for all types in Qore expression trees that cannot throw an exception when deleted...
Definition: AbstractQoreNode.h:404
virtual DLLEXPORT bool boolEvalImpl(ExceptionSink *xsink) const
should never be called for value types
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:43
DLLLOCAL bool needs_eval() const
returns true if the object needs evaluation to return a value, false if not
Definition: AbstractQoreNode.h:264
DLLEXPORT void deref(ExceptionSink *xsink)
decrements the reference count and calls derefImpl() if there_can_be_only_one is false, otherwise does nothing
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:461
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
DLLLOCAL qore_type_t getType() const
returns the data type
Definition: AbstractQoreNode.h:294
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
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:411
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
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns itself; objects of this type are not reference-counted and only deleted manually (by static d...
virtual DLLEXPORT ~AbstractQoreNode()
default destructor does nothing
base class for simple value types
Definition: AbstractQoreNode.h:425
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 ...
DLLLOCAL bool isReferenceCounted() const
returns true if the object is reference-counted
Definition: AbstractQoreNode.h:384
DLLEXPORT double floatEval(ExceptionSink *xsink) const
evaluates the object and returns a floating-point value
qore_type_t type
the type of the object
Definition: AbstractQoreNode.h:157