All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AbstractQoreNode.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
AbstractQoreNode.h
Qore Programming Language
Copyright 2003 - 2013 David Nichols
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _QORE_ABSTRACTQORENODE_H
#define _QORE_ABSTRACTQORENODE_H
#include <qore/common.h>
#include <qore/QoreReferenceCounter.h>
#include <qore/node_types.h>
#include <string>
#include <assert.h>
#define FMT_YAML_SHORT -2
#define FMT_NONE -1
#define FMT_NORMAL 0
class LocalVar;
class QoreTypeInfo;
class AbstractQoreNode : public QoreReferenceCounter {
private:
DLLLOCAL AbstractQoreNode& operator=(const AbstractQoreNode&);
DLLLOCAL virtual bool getAsBoolImpl() const { return false; }
DLLLOCAL virtual int getAsIntImpl() const { return 0; }
DLLLOCAL virtual int64 getAsBigIntImpl() const { return 0; }
DLLLOCAL virtual double getAsFloatImpl() const { return 0.0; }
DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const = 0;
DLLEXPORT virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const = 0;
DLLEXPORT virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
DLLEXPORT virtual int integerEvalImpl(ExceptionSink *xsink) const;
DLLEXPORT virtual bool boolEvalImpl(ExceptionSink *xsink) const;
DLLEXPORT virtual double floatEvalImpl(ExceptionSink *xsink) const;
DLLEXPORT virtual bool derefImpl(ExceptionSink *xsink);
DLLEXPORT virtual void customRef() const;
DLLEXPORT virtual void customDeref(ExceptionSink *xsink);
protected:
qore_type_t type : 11;
bool value : 1;
bool needs_eval_flag : 1;
bool there_can_be_only_one : 1;
bool custom_reference_handlers : 1;
DLLEXPORT virtual ~AbstractQoreNode();
public:
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);
DLLEXPORT AbstractQoreNode(const AbstractQoreNode& v);
DLLEXPORT bool getAsBool() const;
DLLEXPORT int getAsInt() const;
DLLEXPORT int64 getAsBigInt() const;
DLLEXPORT double getAsFloat() const;
DLLEXPORT virtual QoreString *getStringRepresentation(bool &del) const;
DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
DLLEXPORT virtual class DateTime *getDateTimeRepresentation(bool &del) const;
DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
DLLEXPORT virtual int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const = 0;
DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, ExceptionSink *xsink) const = 0;
DLLLOCAL bool needs_eval() const {
return needs_eval_flag;
}
DLLEXPORT virtual AbstractQoreNode *realCopy() const = 0;
DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const = 0;
DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const = 0;
DLLLOCAL qore_type_t getType() const {
return type;
}
DLLEXPORT virtual const char *getTypeName() const = 0;
DLLEXPORT AbstractQoreNode *eval(ExceptionSink *xsink) const;
DLLEXPORT AbstractQoreNode *eval(bool &needs_deref, ExceptionSink *xsink) const;
DLLEXPORT int64 bigIntEval(ExceptionSink *xsink) const;
DLLEXPORT int integerEval(ExceptionSink *xsink) const;
DLLEXPORT bool boolEval(ExceptionSink *xsink) const;
DLLEXPORT double floatEval(ExceptionSink *xsink) const;
DLLLOCAL bool is_value() const {
return value;
}
DLLEXPORT void deref(ExceptionSink *xsink);
DLLEXPORT AbstractQoreNode *refSelf() const;
DLLEXPORT void ref() const;
DLLLOCAL bool isReferenceCounted() const { return !there_can_be_only_one; }
DLLEXPORT virtual AbstractQoreNode *parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo);
};
class SimpleQoreNode : public AbstractQoreNode {
private:
DLLLOCAL SimpleQoreNode& operator=(const SimpleQoreNode&);
public:
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) { }
DLLLOCAL SimpleQoreNode(const SimpleQoreNode& v) : AbstractQoreNode(v) { }
using AbstractQoreNode::deref;
DLLEXPORT void deref();
};
class SimpleValueQoreNode : public SimpleQoreNode {
private:
protected:
DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const;
DLLEXPORT virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const;
DLLEXPORT virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
DLLEXPORT virtual int integerEvalImpl(ExceptionSink *xsink) const;
DLLEXPORT virtual bool boolEvalImpl(ExceptionSink *xsink) const;
DLLEXPORT virtual double floatEvalImpl(ExceptionSink *xsink) const;
public:
DLLLOCAL SimpleValueQoreNode(qore_type_t t, bool n_there_can_be_only_one = false) : SimpleQoreNode(t, true, false, n_there_can_be_only_one) { }
DLLLOCAL SimpleValueQoreNode(const SimpleValueQoreNode &v) : SimpleQoreNode(v) { }
};
class UniqueValueQoreNode : public SimpleValueQoreNode {
private:
DLLLOCAL UniqueValueQoreNode& operator=(const UniqueValueQoreNode&);
DLLLOCAL void *operator new(size_t);
protected:
public:
DLLLOCAL UniqueValueQoreNode(qore_type_t t) : SimpleValueQoreNode(t, true) { }
DLLLOCAL UniqueValueQoreNode(const UniqueValueQoreNode &) : SimpleValueQoreNode(type, true) { }
DLLEXPORT virtual AbstractQoreNode *realCopy() const;
};
#endif