Qore Programming Language  0.8.7
 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 
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 
150 
152  bool value : 1;
153 
155  bool needs_eval_flag : 1;
156 
159 
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 
387  DLLEXPORT virtual AbstractQoreNode *parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo);
388 };
389 
391 
395 private:
397  DLLLOCAL SimpleQoreNode& operator=(const SimpleQoreNode&);
398 
399 public:
401  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) { }
402 
404  DLLLOCAL SimpleQoreNode(const SimpleQoreNode& v) : AbstractQoreNode(v) { }
405 
407 
411  DLLEXPORT void deref();
412 };
413 
416 private:
417 
418 protected:
420 
422  DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const;
423 
425 
427  DLLEXPORT virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const;
428 
430 
432  DLLEXPORT virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
433 
435 
437  DLLEXPORT virtual int integerEvalImpl(ExceptionSink *xsink) const;
438 
440 
442  DLLEXPORT virtual bool boolEvalImpl(ExceptionSink *xsink) const;
443 
445 
447  DLLEXPORT virtual double floatEvalImpl(ExceptionSink *xsink) const;
448 
449 public:
451  DLLLOCAL SimpleValueQoreNode(qore_type_t t, bool n_there_can_be_only_one = false) : SimpleQoreNode(t, true, false, n_there_can_be_only_one) { }
452 
453  DLLLOCAL SimpleValueQoreNode(const SimpleValueQoreNode &v) : SimpleQoreNode(v) { }
454 };
455 
457 
460 private:
462  DLLLOCAL UniqueValueQoreNode& operator=(const UniqueValueQoreNode&);
463 
465  DLLLOCAL void *operator new(size_t);
466 
467 protected:
468 
469 public:
472 
475 
477  DLLEXPORT virtual AbstractQoreNode *realCopy() const;
478 };
479 
480 #endif