00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _QORE_ABSTRACTQORENODE_H
00025
00026 #define _QORE_ABSTRACTQORENODE_H
00027
00028 #include <qore/common.h>
00029 #include <qore/QoreReferenceCounter.h>
00030 #include <qore/node_types.h>
00031
00032 #include <string>
00033
00034 #include <assert.h>
00035
00036 #define FMT_NONE -1
00037 #define FMT_NORMAL 0
00038
00039 class LocalVar;
00040 class QoreTypeInfo;
00041
00043
00046 class AbstractQoreNode : public QoreReferenceCounter {
00047 private:
00049 DLLLOCAL AbstractQoreNode(const AbstractQoreNode&);
00050
00052 DLLLOCAL AbstractQoreNode& operator=(const AbstractQoreNode&);
00053
00055
00058 DLLEXPORT virtual bool getAsBoolImpl() const { return false; }
00059
00061
00064 DLLEXPORT virtual int getAsIntImpl() const { return 0; }
00065
00067
00070 DLLEXPORT virtual int64 getAsBigIntImpl() const { return 0; }
00071
00073
00076 DLLEXPORT virtual double getAsFloatImpl() const { return 0.0; }
00077
00079
00086 DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const = 0;
00087
00089
00095 DLLEXPORT virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const = 0;
00096
00098
00102 DLLEXPORT virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
00103
00105
00109 DLLEXPORT virtual int integerEvalImpl(ExceptionSink *xsink) const;
00110
00112
00116 DLLEXPORT virtual bool boolEvalImpl(ExceptionSink *xsink) const;
00117
00119
00123 DLLEXPORT virtual double floatEvalImpl(ExceptionSink *xsink) const;
00124
00126
00131 DLLEXPORT virtual bool derefImpl(ExceptionSink *xsink);
00132
00134
00138 DLLEXPORT virtual void customRef() const;
00139
00144 DLLEXPORT virtual void customDeref(ExceptionSink *xsink);
00145
00146 protected:
00148
00151 qore_type_t type : 11;
00152
00154 bool value : 1;
00155
00157 bool needs_eval_flag : 1;
00158
00160 bool there_can_be_only_one : 1;
00161
00163 bool custom_reference_handlers : 1;
00164
00166
00169 DLLEXPORT virtual ~AbstractQoreNode();
00170
00171 public:
00173
00180 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);
00181
00183
00186 DLLEXPORT bool getAsBool() const;
00187
00189
00192 DLLEXPORT int getAsInt() const;
00193
00195
00198 DLLEXPORT int64 getAsBigInt() const;
00199
00201
00204 DLLEXPORT double getAsFloat() const;
00205
00207
00212 DLLEXPORT virtual QoreString *getStringRepresentation(bool &del) const;
00213
00215
00218 DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
00219
00221
00225 DLLEXPORT virtual class DateTime *getDateTimeRepresentation(bool &del) const;
00226
00228
00231 DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
00232
00234
00240 DLLEXPORT virtual int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const = 0;
00241
00243
00249 DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, ExceptionSink *xsink) const = 0;
00250
00252
00255 DLLLOCAL bool needs_eval() const {
00256 return needs_eval_flag;
00257 }
00258
00260
00263 DLLEXPORT virtual AbstractQoreNode *realCopy() const = 0;
00264
00266
00271 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const = 0;
00272
00274
00279 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const = 0;
00280
00282
00285 DLLLOCAL qore_type_t getType() const {
00286 return type;
00287 }
00288
00290
00293 DLLEXPORT virtual const char *getTypeName() const = 0;
00294
00296
00309 DLLEXPORT AbstractQoreNode *eval(ExceptionSink *xsink) const;
00310
00312
00320 DLLEXPORT AbstractQoreNode *eval(bool &needs_deref, ExceptionSink *xsink) const;
00321
00323
00327 DLLEXPORT int64 bigIntEval(ExceptionSink *xsink) const;
00328
00330
00334 DLLEXPORT int integerEval(ExceptionSink *xsink) const;
00335
00337
00341 DLLEXPORT bool boolEval(ExceptionSink *xsink) const;
00342
00344
00348 DLLEXPORT double floatEval(ExceptionSink *xsink) const;
00349
00351
00354 DLLLOCAL bool is_value() const {
00355 return value;
00356 }
00357
00359
00363 DLLEXPORT void deref(ExceptionSink *xsink);
00364
00366
00369 DLLEXPORT AbstractQoreNode *refSelf() const;
00370
00372 DLLEXPORT void ref() const;
00373
00375 DLLEXPORT bool isReferenceCounted() const { return there_can_be_only_one; }
00376
00378
00386 DLLEXPORT virtual AbstractQoreNode *parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo);
00387 };
00388
00390
00393 class SimpleQoreNode : public AbstractQoreNode {
00394 private:
00396 DLLLOCAL SimpleQoreNode& operator=(const SimpleQoreNode&);
00397
00398 public:
00400 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) { }
00401
00403 DLLEXPORT SimpleQoreNode(const SimpleQoreNode &) : AbstractQoreNode(type, value, needs_eval_flag, there_can_be_only_one) { }
00404
00406
00409 using AbstractQoreNode::deref;
00410 DLLEXPORT void deref();
00411 };
00412
00414 class SimpleValueQoreNode : public SimpleQoreNode {
00415 private:
00416
00417 protected:
00419
00421 DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const;
00422
00424
00426 DLLEXPORT virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const;
00427
00429
00431 DLLEXPORT virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
00432
00434
00436 DLLEXPORT virtual int integerEvalImpl(ExceptionSink *xsink) const;
00437
00439
00441 DLLEXPORT virtual bool boolEvalImpl(ExceptionSink *xsink) const;
00442
00444
00446 DLLEXPORT virtual double floatEvalImpl(ExceptionSink *xsink) const;
00447
00448 public:
00450 DLLLOCAL SimpleValueQoreNode(qore_type_t t, bool n_there_can_be_only_one = false) : SimpleQoreNode(t, true, false, n_there_can_be_only_one) { }
00451
00452 DLLLOCAL SimpleValueQoreNode(const SimpleValueQoreNode &v) : SimpleQoreNode(type, true, false, there_can_be_only_one) { }
00453 };
00454
00456
00458 class UniqueValueQoreNode : public SimpleValueQoreNode {
00459 private:
00461 DLLLOCAL UniqueValueQoreNode& operator=(const UniqueValueQoreNode&);
00462
00464 DLLLOCAL void *operator new(size_t);
00465
00466 protected:
00467
00468 public:
00470 DLLLOCAL UniqueValueQoreNode(qore_type_t t) : SimpleValueQoreNode(t, true) { }
00471
00473 DLLLOCAL UniqueValueQoreNode(const UniqueValueQoreNode &) : SimpleValueQoreNode(type, true) { }
00474
00476 DLLEXPORT virtual AbstractQoreNode *realCopy() const;
00477 };
00478
00479 #endif