32 #ifndef _QORE_QORECLOSURENODE_H
34 #define _QORE_QORECLOSURENODE_H
36 #include "qore/intern/QoreObjectIntern.h"
40 class CVecInstantiator {
46 DLLLOCAL CVecInstantiator(cvv_vec_t* cv,
ExceptionSink* xs) : cvec(cv), xsink(xs) {
49 for (cvv_vec_t::iterator i = cvec->begin(), e = cvec->end(); i != e; ++i)
50 thread_instantiate_closure_var((*i)->refSelf());
53 DLLLOCAL ~CVecInstantiator() {
57 for (cvv_vec_t::iterator i = cvec->begin(), e = cvec->end(); i != e; ++i)
58 thread_uninstantiate_closure_var(xsink);
64 const QoreClosureParseNode* closure;
65 mutable ThreadSafeLocalVarRuntimeEnvironment closure_env;
67 const qore_class_private* class_ctx;
70 closure_env.del(xsink);
72 for (cvv_vec_t::iterator i = cvec->begin(), e = cvec->end(); i != e; ++i)
83 DLLLOCAL QoreClosureBase(
const QoreClosureParseNode* n_closure, cvv_vec_t* cv,
const qore_class_private* class_ctx)
85 closure_env(n_closure->getVList()), cvec(cv), class_ctx(class_ctx) {
90 DLLLOCAL ~QoreClosureBase() {
92 const_cast<QoreClosureParseNode*
>(closure)->
deref();
96 DLLLOCAL ClosureVarValue* find(
const LocalVar*
id)
const {
97 return closure_env.find(
id);
100 DLLLOCAL
bool hasVar(ClosureVarValue* cvv)
const {
101 return closure_env.hasVar(cvv);
104 DLLLOCAL
const cvar_map_t& getMap()
const {
105 return closure_env.getMap();
109 DLLLOCAL
bool needsScan()
const {
110 return closure->needsScan();
113 DLLLOCAL
static const char* getStaticTypeName() {
118 return closure->getFunction();
121 DLLLOCAL
virtual QoreObject* getObject()
const {
126 class QoreClosureNode :
public QoreClosureBase {
130 DLLLOCAL QoreClosureNode(
const QoreClosureNode&);
131 DLLLOCAL QoreClosureNode&
operator=(
const QoreClosureNode&);
137 DLLLOCAL QoreClosureNode(
const QoreClosureParseNode* n_closure, cvv_vec_t* cv =
nullptr,
138 const qore_class_private* class_ctx =
nullptr) : QoreClosureBase(n_closure, cv, class_ctx), pgm(::
getProgram()) {
142 DLLLOCAL
virtual ~QoreClosureNode() {
154 DLLEXPORT
virtual bool getAsBoolImpl()
const;
157 str.
sprintf(
"function closure (%slambda, %p)", closure->isLambda() ?
"" :
"non-",
this);
164 getAsString(*rv, foff, xsink);
168 DLLLOCAL
virtual const char* getTypeName()
const {
169 return getStaticTypeName();
172 DLLLOCAL
bool isLambda()
const {
return closure->isLambda(); }
175 return QoreClosureNode::is_equal_hard(v, xsink);
183 class QoreObjectClosureNode :
public QoreClosureBase {
187 DLLLOCAL QoreObjectClosureNode(
const QoreObjectClosureNode&);
188 DLLLOCAL QoreObjectClosureNode&
operator=(
const QoreObjectClosureNode&);
194 DLLLOCAL QoreObjectClosureNode(
QoreObject* n_obj,
const qore_class_private* c_ctx,
195 const QoreClosureParseNode* n_closure, cvv_vec_t* cv =
nullptr)
196 : QoreClosureBase(n_closure, cv, c_ctx),
201 DLLLOCAL ~QoreObjectClosureNode() {
212 str.
sprintf(
"function closure (%slambda, in object of class '%s', %p)", closure->isLambda() ?
"" :
"non-", obj->
getClassName(),
this);
219 getAsString(*rv, foff, xsink);
223 DLLLOCAL
virtual const char* getTypeName()
const {
224 return getStaticTypeName();
227 DLLLOCAL
bool isLambda()
const {
return closure->isLambda(); }
230 return QoreObjectClosureNode::is_equal_hard(v, xsink);
237 DLLLOCAL
virtual QoreObject* getObject()
const {