Qore Programming Language 2.1.1
Loading...
Searching...
No Matches
CallReferenceNode.h
1/* -*- mode: c++; indent-tabs-mode: nil -*- */
2/*
3 CallReferenceNode.h
4
5 Qore Programming Language
6
7 Copyright (C) 2003 - 2024 Qore Technologies, s.r.o.
8
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the "Software"),
11 to deal in the Software without restriction, including without limitation
12 the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26
27 Note that the Qore library is released under a choice of three open-source
28 licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29 information.
30*/
31
32#ifndef _QORE_INTERN_FUNCTIONREFERENCENODE_H
33
34#define _QORE_INTERN_FUNCTIONREFERENCENODE_H
35
36#include <string>
37
39
40hashdecl CallReferenceNodeLocation {
41 const QoreProgramLocation* loc;
42
43 DLLLOCAL CallReferenceNodeLocation(const QoreProgramLocation* loc) : loc(loc) {
44 }
45};
46
47class AbstractCallReferenceNodeIntern : public AbstractCallReferenceNode, public CallReferenceNodeLocation {
48public:
49 DLLLOCAL AbstractCallReferenceNodeIntern(const QoreProgramLocation* loc, bool n_needs_eval) :
50 AbstractCallReferenceNode(n_needs_eval), CallReferenceNodeLocation(loc) {
51 }
52};
53
54class ResolvedCallReferenceNodeIntern : public ResolvedCallReferenceNode, public CallReferenceNodeLocation {
55public:
56 DLLLOCAL ResolvedCallReferenceNodeIntern(const QoreProgramLocation* loc, bool n_needs_eval = false) :
57 ResolvedCallReferenceNode(n_needs_eval), CallReferenceNodeLocation(loc) {
58 }
59};
60
61class AbstractUnresolvedCallReferenceNode : public AbstractCallReferenceNodeIntern {
62public:
63 DLLLOCAL AbstractUnresolvedCallReferenceNode(const QoreProgramLocation* loc, bool n_needs_eval) : AbstractCallReferenceNodeIntern(loc, n_needs_eval) {
64 }
65};
66
68class UnresolvedProgramCallReferenceNode : public AbstractUnresolvedCallReferenceNode {
69public:
70 char* str;
71
72 DLLLOCAL UnresolvedProgramCallReferenceNode(const QoreProgramLocation* loc, char* n_str);
73
74 DLLLOCAL virtual ~UnresolvedProgramCallReferenceNode();
75
76 DLLLOCAL virtual int parseInit(QoreValue& val, QoreParseContext& parse_context);
77};
78
79class UnresolvedCallReferenceNode : public UnresolvedProgramCallReferenceNode {
80public:
81 DLLLOCAL UnresolvedCallReferenceNode(const QoreProgramLocation* loc, char* n_str) : UnresolvedProgramCallReferenceNode(loc, n_str) {
82 }
83
84 DLLLOCAL virtual int parseInit(QoreValue& val, QoreParseContext& parse_context);
85};
86
88class LocalStaticMethodCallReferenceNode : public ResolvedCallReferenceNodeIntern {
89public:
90 DLLLOCAL LocalStaticMethodCallReferenceNode(const QoreProgramLocation* loc, const QoreMethod* n_method)
91 : ResolvedCallReferenceNodeIntern(loc, true), method(n_method) {
92 //printd(5, "LocalStaticMethodCallReferenceNode::LocalStaticMethodCallReferenceNode() this: %p %s::%s() "
93 // "pgm: %p\n", this, method->getClass()->getName(), method->getName(), pgm);
94 }
95
96 DLLLOCAL virtual ~LocalStaticMethodCallReferenceNode() {
97 }
98
99 DLLLOCAL virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const {
101 }
102
103 DLLLOCAL virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
104
105 DLLLOCAL virtual QoreValue execValue(const QoreListNode* args, ExceptionSink* xsink) const;
106
107 DLLLOCAL virtual QoreFunction* getFunction();
108
109protected:
110 const QoreMethod* method;
111
112 // constructor for subclasses
113 DLLLOCAL LocalStaticMethodCallReferenceNode(const QoreProgramLocation* loc, const QoreMethod* n_method,
114 bool n_needs_eval) : ResolvedCallReferenceNodeIntern(loc, n_needs_eval), method(n_method) {
115 }
116
117 DLLLOCAL virtual QoreValue evalImpl(bool &needs_deref, ExceptionSink* xsink) const;
118};
119
120class StaticMethodCallReferenceNode : public LocalStaticMethodCallReferenceNode {
121protected:
122 QoreProgram* pgm;
123 const qore_class_private* class_ctx;
124
125 DLLLOCAL virtual bool derefImpl(ExceptionSink* xsink);
126
127public:
128 DLLLOCAL StaticMethodCallReferenceNode(const QoreProgramLocation* loc, const QoreMethod* n_method,
129 QoreProgram* n_pgm, const qore_class_private* n_class_ctx);
130
131 DLLLOCAL ~StaticMethodCallReferenceNode() {
132 assert(!pgm);
133 }
134
135 DLLLOCAL virtual QoreValue execValue(const QoreListNode *args, ExceptionSink *xsink) const;
136};
137
140protected:
141 DLLLOCAL virtual QoreValue evalImpl(bool &needs_deref, ExceptionSink* xsink) const;
142
143 DLLLOCAL LocalMethodCallReferenceNode(const QoreProgramLocation* loc, const QoreMethod* n_method, bool n_needs_eval) : LocalStaticMethodCallReferenceNode(loc, n_method, n_needs_eval) {
144 //printd(5, "LocalMethodCallReferenceNode::LocalStaticMethodCallReferenceNode() this: %p %s::%s() pgm: %p\n", this, method->getClass()->getName(), method->getName(), pgm);
145 }
146
147public:
148 DLLLOCAL LocalMethodCallReferenceNode(const QoreProgramLocation* loc, const QoreMethod* n_method) : LocalStaticMethodCallReferenceNode(loc, n_method) {
149 //printd(5, "LocalMethodCallReferenceNode::LocalStaticMethodCallReferenceNode() this: %p %s::%s() pgm: %p\n", this, method->getClass()->getName(), method->getName(), pgm);
150 }
151
152 DLLLOCAL virtual ~LocalMethodCallReferenceNode() {
153 }
154
155 DLLLOCAL virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const {
157 }
158
159 DLLLOCAL virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
160
161 DLLLOCAL virtual QoreValue execValue(const QoreListNode* args, ExceptionSink* xsink) const;
162};
163
164class MethodCallReferenceNode : public LocalMethodCallReferenceNode {
165protected:
166 QoreObject* obj;
167
168 DLLLOCAL virtual bool derefImpl(ExceptionSink* xsink);
169
170public:
171 DLLLOCAL MethodCallReferenceNode(const QoreProgramLocation* loc, const QoreMethod* n_method, QoreProgram* n_pgm);
172
173 DLLLOCAL virtual QoreValue execValue(const QoreListNode* args, ExceptionSink* xsink) const;
174};
175
177class LocalFunctionCallReferenceNode : public ResolvedCallReferenceNodeIntern {
178public:
179 DLLLOCAL LocalFunctionCallReferenceNode(const QoreProgramLocation* loc, const QoreFunction* n_uf);
180
181 DLLLOCAL virtual QoreValue execValue(const QoreListNode* args, ExceptionSink* xsink) const;
182
183 DLLLOCAL virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const {
185 }
186
187 DLLLOCAL virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
188
189 DLLLOCAL virtual QoreFunction* getFunction() {
190 return const_cast<QoreFunction*>(uf);
191 }
192
193protected:
194 const QoreFunction* uf;
195
196 // constructor for subclasses
197 DLLLOCAL LocalFunctionCallReferenceNode(const QoreProgramLocation* loc, const QoreFunction* n_uf,
198 bool n_needs_eval);
199
200 DLLLOCAL virtual QoreValue evalImpl(bool &needs_deref, ExceptionSink* xsink) const;
201};
202
205public:
206 DLLLOCAL FunctionCallReferenceNode(const QoreProgramLocation* loc, const QoreFunction* n_uf,
207 QoreProgram* n_pgm) : LocalFunctionCallReferenceNode(loc, n_uf, false), pgm(n_pgm) {
208 assert(pgm);
209 // make a weak reference to the Program - a strong reference (QoreProgram::ref()) could cause a recursive
210 // reference
211 pgm->depRef();
212 }
213
214 DLLLOCAL virtual QoreValue execValue(const QoreListNode* args, ExceptionSink* xsink) const;
215
216protected:
217 QoreProgram* pgm;
218
219 DLLLOCAL virtual bool derefImpl(ExceptionSink* xsink);
220};
221
223class UnresolvedStaticMethodCallReferenceNode : public AbstractUnresolvedCallReferenceNode {
224public:
225 DLLLOCAL UnresolvedStaticMethodCallReferenceNode(const QoreProgramLocation* loc, NamedScope* n_scope);
226
228
230 DLLLOCAL void deref() {
231 if (ROdereference())
232 delete this;
233 }
234
235 DLLLOCAL virtual int parseInit(QoreValue& val, QoreParseContext& parse_context);
236
237protected:
238 NamedScope* scope;
239};
240
241class ImportedFunctionEntry;
242
244class RunTimeObjectMethodReferenceNode : public ResolvedCallReferenceNodeIntern {
245public:
246 DLLLOCAL RunTimeObjectMethodReferenceNode(const QoreProgramLocation* loc, QoreObject* n_obj,
247 const char* n_method);
248
249 DLLLOCAL virtual QoreValue execValue(const QoreListNode* args, ExceptionSink* xsink) const;
250
251 DLLLOCAL virtual QoreProgram* getProgram() const;
252
253 DLLLOCAL virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const {
255 }
256
257 DLLLOCAL virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
258
259 DLLLOCAL virtual QoreFunction* getFunction() {
260 // FIXME: implement type checking and method matching in ParseObjectMethodReferenceNode::parseInit()
261 return nullptr;
262 }
263
264private:
265 QoreObject* obj;
266 std::string method;
267 const qore_class_private* qc;
268
269 DLLLOCAL virtual ~RunTimeObjectMethodReferenceNode();
270};
271
273// is known when the method reference node object is created
274class RunTimeResolvedMethodReferenceNode : public ResolvedCallReferenceNodeIntern {
275public:
276 DLLLOCAL RunTimeResolvedMethodReferenceNode(const QoreProgramLocation* loc, QoreObject* n_obj,
277 const QoreMethod* n_method, const qore_class_private* ctx = runtime_get_class());
278
279 DLLLOCAL virtual QoreValue execValue(const QoreListNode* args, ExceptionSink* xsink) const;
280
281 DLLLOCAL virtual QoreProgram* getProgram() const;
282
283 DLLLOCAL virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const {
285 }
286
287 DLLLOCAL virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
288
289 DLLLOCAL virtual QoreFunction* getFunction();
290
291private:
292 QoreObject* obj;
293 const QoreMethod* method;
294 const qore_class_private* qc;
295 QoreProgram* pgm = getProgram();
296
297 DLLLOCAL virtual ~RunTimeResolvedMethodReferenceNode();
298};
299
300#endif
base class for call references, reference-counted, dynamically allocated only
Definition CallReferenceNode.h:39
The base class for all value and parse types in Qore expression trees.
Definition AbstractQoreNode.h:57
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:50
a call reference to a user function
Definition CallReferenceNode.h:204
virtual DLLLOCAL QoreValue execValue(const QoreListNode *args, ExceptionSink *xsink) const
pure virtual function for executing the function reference
virtual DLLLOCAL bool derefImpl(ExceptionSink *xsink)
Called when the strong reference count reaches zero.
a call reference to a user function from within the same QoreProgram object
Definition CallReferenceNode.h:177
virtual DLLLOCAL bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
returns true if the other node is the same value
Definition CallReferenceNode.h:183
virtual DLLLOCAL QoreValue evalImpl(bool &needs_deref, ExceptionSink *xsink) const
this function should never be called for function references; this function should never be called di...
virtual DLLLOCAL QoreFunction * getFunction()
Returns the internal function object, if any; can return nullptr.
Definition CallReferenceNode.h:189
virtual DLLLOCAL bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
returns true if the other node is the same value
virtual DLLLOCAL QoreValue execValue(const QoreListNode *args, ExceptionSink *xsink) const
pure virtual function for executing the function reference
a call reference to a static user method
Definition CallReferenceNode.h:139
virtual DLLLOCAL bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
returns true if the other node is the same value
Definition CallReferenceNode.h:155
virtual DLLLOCAL QoreValue execValue(const QoreListNode *args, ExceptionSink *xsink) const
pure virtual function for executing the function reference
virtual DLLLOCAL bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
returns true if the other node is the same value
virtual DLLLOCAL QoreValue evalImpl(bool &needs_deref, ExceptionSink *xsink) const
this function should never be called for function references; this function should never be called di...
a call reference to a static user method
Definition CallReferenceNode.h:88
virtual DLLLOCAL QoreValue evalImpl(bool &needs_deref, ExceptionSink *xsink) const
this function should never be called for function references; this function should never be called di...
virtual DLLLOCAL bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
returns true if the other node is the same value
virtual DLLLOCAL QoreValue execValue(const QoreListNode *args, ExceptionSink *xsink) const
pure virtual function for executing the function reference
virtual DLLLOCAL bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
returns true if the other node is the same value
Definition CallReferenceNode.h:99
virtual DLLLOCAL QoreFunction * getFunction()
Returns the internal function object, if any; can return nullptr.
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition QoreListNode.h:52
a method in a QoreClass
Definition QoreClass.h:143
the implementation of Qore's object data type, reference counted, dynamically-allocated only
Definition QoreObject.h:61
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only
Definition QoreProgram.h:128
DLLEXPORT void depRef()
incremements the weak reference count for the program object
DLLEXPORT bool ROdereference() const
Atomically decrements the reference count.
base class for resolved call references
Definition CallReferenceNode.h:115
virtual DLLEXPORT bool derefImpl(ExceptionSink *xsink)
Called when the strong reference count reaches zero.
a run-time call reference to a method of a particular object
Definition CallReferenceNode.h:244
virtual DLLLOCAL QoreFunction * getFunction()
Returns the internal function object, if any; can return nullptr.
Definition CallReferenceNode.h:259
virtual DLLLOCAL bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
returns true if the other node is the same value
Definition CallReferenceNode.h:253
virtual DLLLOCAL QoreValue execValue(const QoreListNode *args, ExceptionSink *xsink) const
pure virtual function for executing the function reference
virtual DLLLOCAL QoreProgram * getProgram() const
returns a pointer to the QoreProgram object associated with this reference (can be nullptr)
virtual DLLLOCAL bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
returns true if the other node is the same value
a run-time call reference to a method of a particular object where the method's class
Definition CallReferenceNode.h:274
virtual DLLLOCAL QoreValue execValue(const QoreListNode *args, ExceptionSink *xsink) const
pure virtual function for executing the function reference
virtual DLLLOCAL QoreFunction * getFunction()
Returns the internal function object, if any; can return nullptr.
virtual DLLLOCAL bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
returns true if the other node is the same value
virtual DLLLOCAL bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
returns true if the other node is the same value
Definition CallReferenceNode.h:283
virtual DLLLOCAL QoreProgram * getProgram() const
returns a pointer to the QoreProgram object associated with this reference (can be nullptr)
an unresolved call reference, only present temporarily in the parse tree
Definition CallReferenceNode.h:68
virtual DLLLOCAL int parseInit(QoreValue &val, QoreParseContext &parse_context)
for use by parse types to initialize them for execution during stage 1 parsing
an unresolved static method call reference, only present temporarily in the parse tree
Definition CallReferenceNode.h:223
virtual DLLLOCAL int parseInit(QoreValue &val, QoreParseContext &parse_context)
for use by parse types to initialize them for execution during stage 1 parsing
The main value class in Qore, designed to be passed by value.
Definition QoreValue.h:279