Qore Programming Language  0.8.3
include/qore/AbstractQoreNode.h (4311)
00001 /* -*- mode: c++; indent-tabs-mode: nil -*- */
00002 /*
00003   AbstractQoreNode.h
00004   
00005   Qore Programming Language
00006 
00007   Copyright 2003 - 2011 David Nichols
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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_YAML_SHORT -2
00037 #define FMT_NONE       -1
00038 #define FMT_NORMAL      0
00039 
00040 class LocalVar;
00041 class QoreTypeInfo;
00042 
00044 
00047 class AbstractQoreNode : public QoreReferenceCounter {
00048 private:
00050    DLLLOCAL AbstractQoreNode(const AbstractQoreNode&);
00051 
00053    DLLLOCAL AbstractQoreNode& operator=(const AbstractQoreNode&);
00054 
00056 
00059    DLLLOCAL virtual bool getAsBoolImpl() const { return false; }
00060 
00062 
00065    DLLLOCAL virtual int getAsIntImpl() const { return 0; }
00066 
00068 
00071    DLLLOCAL virtual int64 getAsBigIntImpl() const { return 0; }
00072 
00074 
00077    DLLLOCAL virtual double getAsFloatImpl() const { return 0.0; }
00078 
00080 
00087    DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const = 0;
00088 
00090 
00096    DLLEXPORT virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const = 0;
00097 
00099 
00103    DLLEXPORT virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
00104 
00106 
00110    DLLEXPORT virtual int integerEvalImpl(ExceptionSink *xsink) const;
00111 
00113 
00117    DLLEXPORT virtual bool boolEvalImpl(ExceptionSink *xsink) const;
00118 
00120 
00124    DLLEXPORT virtual double floatEvalImpl(ExceptionSink *xsink) const;
00125 
00127 
00132    DLLEXPORT virtual bool derefImpl(ExceptionSink *xsink);
00133 
00135 
00139    DLLEXPORT virtual void customRef() const;
00140 
00145    DLLEXPORT virtual void customDeref(ExceptionSink *xsink);
00146 
00147 protected:
00149 
00152    qore_type_t type : 11;
00153 
00155    bool value : 1;
00156 
00158    bool needs_eval_flag : 1;
00159 
00161    bool there_can_be_only_one : 1;
00162 
00164    bool custom_reference_handlers : 1;
00165 
00167 
00170    DLLEXPORT virtual ~AbstractQoreNode();
00171 
00172 public:
00174 
00181    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);
00182 
00184 
00187    DLLEXPORT bool getAsBool() const;
00188 
00190 
00193    DLLEXPORT int getAsInt() const;
00194 
00196 
00199    DLLEXPORT int64 getAsBigInt() const;
00200 
00202 
00205    DLLEXPORT double getAsFloat() const;
00206 
00208 
00213    DLLEXPORT virtual QoreString *getStringRepresentation(bool &del) const;
00214 
00216 
00219    DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
00220 
00222 
00226    DLLEXPORT virtual class DateTime *getDateTimeRepresentation(bool &del) const;
00227 
00229 
00232    DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
00233 
00235 
00241    DLLEXPORT virtual int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const = 0;
00242 
00244 
00250    DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, ExceptionSink *xsink) const = 0;
00251 
00253 
00256    DLLLOCAL bool needs_eval() const {
00257       return needs_eval_flag;
00258    }
00259 
00261 
00264    DLLEXPORT virtual AbstractQoreNode *realCopy() const = 0;
00265 
00267 
00272    DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const = 0;
00273 
00275 
00280    DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const = 0;
00281 
00283 
00286    DLLLOCAL qore_type_t getType() const {
00287       return type;
00288    }
00289 
00291 
00294    DLLEXPORT virtual const char *getTypeName() const = 0;
00295 
00297 
00310    DLLEXPORT AbstractQoreNode *eval(ExceptionSink *xsink) const;
00311 
00313 
00321    DLLEXPORT AbstractQoreNode *eval(bool &needs_deref, ExceptionSink *xsink) const;
00322 
00324 
00328    DLLEXPORT int64 bigIntEval(ExceptionSink *xsink) const;
00329 
00331 
00335    DLLEXPORT int integerEval(ExceptionSink *xsink) const;
00336 
00338 
00342    DLLEXPORT bool boolEval(ExceptionSink *xsink) const;
00343 
00345 
00349    DLLEXPORT double floatEval(ExceptionSink *xsink) const;
00350 
00352 
00355    DLLLOCAL bool is_value() const {
00356       return value;
00357    }
00358 
00360 
00364    DLLEXPORT void deref(ExceptionSink *xsink);
00365 
00367 
00370    DLLEXPORT AbstractQoreNode *refSelf() const;
00371 
00373    DLLEXPORT void ref() const;
00374 
00376    DLLLOCAL bool isReferenceCounted() const { return !there_can_be_only_one; }
00377 
00379 
00387    DLLEXPORT virtual AbstractQoreNode *parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo);
00388 };
00389 
00391 
00394 class SimpleQoreNode : public AbstractQoreNode {
00395 private:
00397    DLLLOCAL SimpleQoreNode& operator=(const SimpleQoreNode&);
00398 
00399 public:
00401    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) { }
00402 
00404    DLLLOCAL SimpleQoreNode(const SimpleQoreNode &) : AbstractQoreNode(type, value, needs_eval_flag, there_can_be_only_one) { }
00405 
00407 
00410    using AbstractQoreNode::deref;
00411    DLLEXPORT void deref();
00412 };
00413 
00415 class SimpleValueQoreNode : public SimpleQoreNode {
00416 private:
00417 
00418 protected:
00420 
00422    DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const;
00423 
00425 
00427    DLLEXPORT virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const;
00428 
00430 
00432    DLLEXPORT virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
00433 
00435 
00437    DLLEXPORT virtual int integerEvalImpl(ExceptionSink *xsink) const;
00438 
00440 
00442    DLLEXPORT virtual bool boolEvalImpl(ExceptionSink *xsink) const;
00443 
00445 
00447    DLLEXPORT virtual double floatEvalImpl(ExceptionSink *xsink) const;
00448 
00449 public:
00451    DLLLOCAL SimpleValueQoreNode(qore_type_t t, bool n_there_can_be_only_one = false) : SimpleQoreNode(t, true, false, n_there_can_be_only_one) { }
00452 
00453    DLLLOCAL SimpleValueQoreNode(const SimpleValueQoreNode &v) : SimpleQoreNode(type, true, false, there_can_be_only_one) { }
00454 };
00455 
00457 
00459 class UniqueValueQoreNode : public SimpleValueQoreNode {
00460 private:
00462    DLLLOCAL UniqueValueQoreNode& operator=(const UniqueValueQoreNode&);
00463 
00465    DLLLOCAL void *operator new(size_t);
00466 
00467 protected:
00468 
00469 public:
00471    DLLLOCAL UniqueValueQoreNode(qore_type_t t) : SimpleValueQoreNode(t, true) { }
00472 
00474    DLLLOCAL UniqueValueQoreNode(const UniqueValueQoreNode &) : SimpleValueQoreNode(type, true) { }
00475 
00477    DLLEXPORT virtual AbstractQoreNode *realCopy() const;
00478 };
00479 
00480 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines