00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _QORE_ABSTRACTQORENODE_H
00024
00025 #define _QORE_ABSTRACTQORENODE_H
00026
00027 #include <qore/common.h>
00028 #include <qore/QoreReferenceCounter.h>
00029 #include <qore/node_types.h>
00030
00031 #include <string>
00032
00033 #include <assert.h>
00034
00035 #define FMT_NONE -1
00036 #define FMT_NORMAL 0
00037
00038 class LocalVar;
00039
00041
00044 class AbstractQoreNode : public QoreReferenceCounter {
00045 private:
00047 DLLLOCAL AbstractQoreNode(const AbstractQoreNode&);
00048
00050 DLLLOCAL AbstractQoreNode& operator=(const AbstractQoreNode&);
00051
00053
00056 DLLEXPORT virtual bool getAsBoolImpl() const { return false; }
00057
00059
00062 DLLEXPORT virtual int getAsIntImpl() const { return 0; }
00063
00065
00068 DLLEXPORT virtual int64 getAsBigIntImpl() const { return 0; }
00069
00071
00074 DLLEXPORT virtual double getAsFloatImpl() const { return 0.0; }
00075
00077
00084 DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const = 0;
00085
00087
00093 DLLEXPORT virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const = 0;
00094
00096
00100 DLLEXPORT virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const = 0;
00101
00103
00107 DLLEXPORT virtual int integerEvalImpl(ExceptionSink *xsink) const = 0;
00108
00110
00114 DLLEXPORT virtual bool boolEvalImpl(ExceptionSink *xsink) const = 0;
00115
00117
00121 DLLEXPORT virtual double floatEvalImpl(ExceptionSink *xsink) const = 0;
00122
00124
00129 DLLEXPORT virtual bool derefImpl(ExceptionSink *xsink);
00130
00132
00136 DLLEXPORT virtual void customRef() const;
00137
00142 DLLEXPORT virtual void customDeref(ExceptionSink *xsink);
00143
00144 protected:
00146
00149 qore_type_t type : 11;
00150
00152 bool value : 1;
00153
00155 bool needs_eval_flag : 1;
00156
00158 bool there_can_be_only_one : 1;
00159
00161 bool custom_reference_handlers : 1;
00162
00164
00167 DLLEXPORT virtual ~AbstractQoreNode();
00168
00169 public:
00171
00178 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);
00179
00181
00184 DLLEXPORT bool getAsBool() const;
00185
00187
00190 DLLEXPORT int getAsInt() const;
00191
00193
00196 DLLEXPORT int64 getAsBigInt() const;
00197
00199
00202 DLLEXPORT double getAsFloat() const;
00203
00205
00210 DLLEXPORT virtual QoreString *getStringRepresentation(bool &del) const;
00211
00213
00216 DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
00217
00219
00223 DLLEXPORT virtual class DateTime *getDateTimeRepresentation(bool &del) const;
00224
00226
00229 DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
00230
00232
00238 DLLEXPORT virtual int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const = 0;
00239
00241
00247 DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, ExceptionSink *xsink) const = 0;
00248
00250
00253 DLLLOCAL bool needs_eval() const {
00254 return needs_eval_flag;
00255 }
00256
00258
00261 DLLEXPORT virtual AbstractQoreNode *realCopy() const = 0;
00262
00264
00269 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const = 0;
00270
00272
00277 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const = 0;
00278
00280
00283 DLLLOCAL qore_type_t getType() const {
00284 return type;
00285 }
00286
00288
00291 DLLEXPORT virtual const char *getTypeName() const = 0;
00292
00294
00302 DLLEXPORT virtual AbstractQoreNode *parseInit(LocalVar *oflag, int pflag, int &lvids) { return this; }
00303
00305
00318 DLLEXPORT AbstractQoreNode *eval(ExceptionSink *xsink) const;
00319
00321
00329 DLLEXPORT AbstractQoreNode *eval(bool &needs_deref, ExceptionSink *xsink) const;
00330
00332
00336 DLLEXPORT int64 bigIntEval(ExceptionSink *xsink) const;
00337
00339
00343 DLLEXPORT int integerEval(ExceptionSink *xsink) const;
00344
00346
00350 DLLEXPORT bool boolEval(ExceptionSink *xsink) const;
00351
00353
00357 DLLEXPORT double floatEval(ExceptionSink *xsink) const;
00358
00360
00363 DLLLOCAL bool is_value() const {
00364 return value;
00365 }
00366
00368
00372 DLLEXPORT void deref(ExceptionSink *xsink);
00373
00375
00378 DLLEXPORT AbstractQoreNode *refSelf() const;
00379
00381 DLLEXPORT void ref() const;
00382
00384 DLLEXPORT bool isReferenceCounted() const { return there_can_be_only_one; }
00385 };
00386
00388
00391 class SimpleQoreNode : public AbstractQoreNode {
00392 private:
00394 DLLLOCAL SimpleQoreNode& operator=(const SimpleQoreNode&);
00395
00396 public:
00398 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) { }
00399
00401 DLLEXPORT SimpleQoreNode(const SimpleQoreNode &) : AbstractQoreNode(type, value, needs_eval_flag, there_can_be_only_one) { }
00402
00404
00407 DLLEXPORT void deref();
00408 };
00409
00411 class SimpleValueQoreNode : public SimpleQoreNode {
00412 private:
00413
00414 protected:
00416
00418 DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const;
00419
00421
00423 DLLEXPORT virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const;
00424
00426
00428 DLLEXPORT virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
00429
00431
00433 DLLEXPORT virtual int integerEvalImpl(ExceptionSink *xsink) const;
00434
00436
00438 DLLEXPORT virtual bool boolEvalImpl(ExceptionSink *xsink) const;
00439
00441
00443 DLLEXPORT virtual double floatEvalImpl(ExceptionSink *xsink) const;
00444
00445 public:
00447 DLLLOCAL SimpleValueQoreNode(qore_type_t t, bool n_there_can_be_only_one = false) : SimpleQoreNode(t, true, false, n_there_can_be_only_one) { }
00448
00449 DLLLOCAL SimpleValueQoreNode(const SimpleValueQoreNode &v) : SimpleQoreNode(type, true, false, there_can_be_only_one) { }
00450 };
00451
00453
00455 class UniqueValueQoreNode : public SimpleValueQoreNode {
00456 private:
00458 DLLLOCAL UniqueValueQoreNode& operator=(const UniqueValueQoreNode&);
00459
00461 DLLLOCAL void *operator new(size_t);
00462
00463 protected:
00464
00465 public:
00467 DLLLOCAL UniqueValueQoreNode(qore_type_t t) : SimpleValueQoreNode(t, true) { }
00468
00470 DLLLOCAL UniqueValueQoreNode(const UniqueValueQoreNode &) : SimpleValueQoreNode(type, true) { }
00471
00473 DLLEXPORT virtual AbstractQoreNode *realCopy() const;
00474 };
00475
00476 #endif