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;
69 closure_env.del(xsink);
71 for (cvv_vec_t::iterator i = cvec->begin(), e = cvec->end(); i != e; ++i)
87 DLLLOCAL ~QoreClosureBase() {
89 const_cast<QoreClosureParseNode*
>(closure)->deref();
93 DLLLOCAL ClosureVarValue* find(
const LocalVar*
id)
const {
94 return closure_env.find(
id);
97 DLLLOCAL
bool hasVar(ClosureVarValue* cvv)
const {
98 return closure_env.hasVar(cvv);
101 DLLLOCAL
const cvar_map_t& getMap()
const {
102 return closure_env.getMap();
106 DLLLOCAL
bool needsScan()
const {
107 return closure->needsScan();
110 DLLLOCAL
static const char* getStaticTypeName() {
114 DLLLOCAL
virtual QoreFunction* getFunction() {
115 return closure->getFunction();
118 DLLLOCAL
virtual QoreObject* getObject()
const {
123 class QoreClosureNode :
public QoreClosureBase {
127 DLLLOCAL QoreClosureNode(
const QoreClosureNode&);
128 DLLLOCAL QoreClosureNode& operator=(
const QoreClosureNode&);
134 DLLLOCAL QoreClosureNode(
const QoreClosureParseNode* n_closure, cvv_vec_t* cv = 0) : QoreClosureBase(n_closure, cv), pgm(::
getProgram()) {
138 DLLLOCAL
virtual ~QoreClosureNode() {
150 DLLEXPORT
virtual bool getAsBoolImpl()
const;
153 str.
sprintf(
"function closure (%slambda, %p)", closure->isLambda() ?
"" :
"non-",
this);
160 getAsString(*rv, foff, xsink);
164 DLLLOCAL
virtual const char* getTypeName()
const {
165 return getStaticTypeName();
168 DLLLOCAL
bool isLambda()
const {
return closure->isLambda(); }
171 return QoreClosureNode::is_equal_hard(v, xsink);
179 class QoreObjectClosureNode :
public QoreClosureBase {
182 const qore_class_private* class_ctx;
184 DLLLOCAL QoreObjectClosureNode(
const QoreObjectClosureNode&);
185 DLLLOCAL QoreObjectClosureNode& operator=(
const QoreObjectClosureNode&);
191 DLLLOCAL QoreObjectClosureNode(
QoreObject* n_obj,
const qore_class_private* c_ctx,
const QoreClosureParseNode* n_closure, cvv_vec_t* cv = 0) : QoreClosureBase(n_closure, cv), obj(n_obj), class_ctx(c_ctx) {
195 DLLLOCAL ~QoreObjectClosureNode() {
206 str.
sprintf(
"function closure (%slambda, in object of class '%s', %p)", closure->isLambda() ?
"" :
"non-", obj->
getClassName(),
this);
213 getAsString(*rv, foff, xsink);
217 DLLLOCAL
virtual const char* getTypeName()
const {
218 return getStaticTypeName();
221 DLLLOCAL
bool isLambda()
const {
return closure->isLambda(); }
224 return QoreObjectClosureNode::is_equal_hard(v, xsink);
231 DLLLOCAL
virtual QoreObject* getObject()
const {
DLLEXPORT void depRef()
incremements the weak reference count for the program object
DLLEXPORT int sprintf(const char *fmt,...)
this will concatentate a formatted string to the existing string according to the format string and t...
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
DLLEXPORT void tRef() const
increments the existence reference count
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
DLLEXPORT QoreProgram * getProgram()
returns the current QoreProgram
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
const qore_type_t NT_RUNTIME_CLOSURE
type value for ResolvedCallReferenceNode (QoreClosureNode, QoreObjectClosureNode) ...
Definition: node_types.h:71
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only ...
Definition: QoreProgram.h:126
the implementation of Qore's object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:61
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46
DLLEXPORT void ref() const
increments the reference count
base class for resolved call references
Definition: CallReferenceNode.h:105
DLLEXPORT QoreProgram * getProgram() const
returns the QoreProgram object associated with this object
DLLEXPORT const char * getClassName() const
returns the name of the class