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 {
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
DLLEXPORT void ref() const
increments the reference count
DLLLOCAL AbstractQoreNode & operator=(const AbstractQoreNode &)
this function is not implemented; it is here as a private function in order to prohibit it from being...
DLLEXPORT void deref(ExceptionSink *xsink)
decrements the reference count and calls derefImpl() if there_can_be_only_one is false,...
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
the implementation of Qore's object data type, reference counted, dynamically-allocated only
Definition: QoreObject.h:60
DLLEXPORT void tRef() const
increments the existence reference count
DLLEXPORT const char * getClassName() const
returns the name of the class
DLLEXPORT QoreProgram * getProgram() const
returns the QoreProgram object associated with this object
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only
Definition: QoreProgram.h:127
DLLEXPORT void depRef()
incremements the weak reference count for the program object
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
DLLEXPORT int sprintf(const char *fmt,...)
this will concatentate a formatted string to the existing string according to the format string and t...
base class for resolved call references
Definition: CallReferenceNode.h:109
virtual DLLLOCAL QoreFunction * getFunction()=0
Returns the internal function object, if any; can return nullptr.
const qore_type_t NT_RUNTIME_CLOSURE
type value for ResolvedCallReferenceNode (QoreClosureNode, QoreObjectClosureNode)
Definition: node_types.h:71
DLLEXPORT QoreProgram * getProgram()
returns the current QoreProgram
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:275