Qore Programming Language 2.0.0
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_FUNCTIONREFERENCENODE_H
33
34#define _QORE_FUNCTIONREFERENCENODE_H
35
37
40public:
41 DLLEXPORT AbstractCallReferenceNode(bool n_needs_eval = false, qore_type_t n_type = NT_FUNCREF);
42
43 DLLEXPORT virtual ~AbstractCallReferenceNode();
44
46
48 DLLEXPORT virtual bool getAsBoolImpl() const;
49
51
57 DLLEXPORT virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const;
58
60
70 DLLEXPORT virtual QoreString* getAsString(bool& del, int foff, ExceptionSink* xsink) const;
71
73 DLLEXPORT virtual const char* getTypeName() const;
74
77 ref();
78 return const_cast<AbstractCallReferenceNode*>(this);
79 }
80
81 DLLLOCAL static const char* getStaticTypeName() {
82 return "call reference";
83 }
84
85protected:
87
89 DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
90
92 DLLLOCAL AbstractCallReferenceNode(bool n_needs_eval, bool n_there_can_be_only_one,
93 qore_type_t n_type = NT_FUNCREF);
94
95private:
97
99 DLLLOCAL virtual AbstractQoreNode* realCopy() const;
100
102
104 DLLLOCAL virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
105
107
109 DLLLOCAL virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
110};
111
112class QoreFunction;
113
116public:
119
121 DLLEXPORT virtual ~ResolvedCallReferenceNode();
122
124 DLLLOCAL ResolvedCallReferenceNode(bool n_needs_eval, qore_type_t n_type = NT_FUNCREF);
125
127
134 DLLLOCAL virtual QoreValue execValue(const QoreListNode* args, ExceptionSink* xsink) const = 0;
135
137
140 DLLEXPORT virtual QoreProgram* getProgram() const;
141
143 DLLLOCAL virtual QoreFunction* getFunction() = 0;
144
147 ref();
148 return const_cast<ResolvedCallReferenceNode*>(this);
149 }
150
152 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
153
155 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
156
158 DLLEXPORT virtual AbstractQoreNode* realCopy() const;
159
160 // must be defined but performs no action
161 DLLEXPORT virtual int parseInit(QoreValue& val, QoreParseContext& parse_context);
162
163 // the following function must be defined, but is never called
164 DLLEXPORT virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
165
167 DLLLOCAL void weakRef() {
169 }
170
172 DLLLOCAL void weakDeref() {
173 if (weak_refs.ROdereference()) {
174 delete this;
175 }
176 }
177
178protected:
181
183
190 DLLEXPORT virtual bool derefImpl(ExceptionSink* xsink);
191};
192
193class OptionalCallReferenceAccessHelper {
194public:
195 DLLEXPORT OptionalCallReferenceAccessHelper(ExceptionSink* xsink, ResolvedCallReferenceNode* ref);
196
197 DLLLOCAL ~OptionalCallReferenceAccessHelper() {
198 if (ref) {
199 ref->deref(xsink);
200 }
201 }
202
203 DLLLOCAL operator bool() const {
204 return ref ? true : false;
205 }
206
207 DLLLOCAL const AbstractCallReferenceNode* operator*() const {
208 return ref;
209 }
210
211 DLLLOCAL AbstractCallReferenceNode* operator*() {
212 return ref;
213 }
214
215protected:
216 ExceptionSink* xsink;
218};
219
220#endif
base class for call references, reference-counted, dynamically allocated only
Definition CallReferenceNode.h:39
virtual DLLEXPORT int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const
concatenate the verbose string representation of the value to an existing QoreString
DLLLOCAL AbstractCallReferenceNode * refSelf() const
Returns a non-const ptr to the same object after increasing the reference count.
Definition CallReferenceNode.h:76
virtual DLLEXPORT bool getAsBoolImpl() const
returns false unless perl-boolean-evaluation is enabled, in which case it returns true
virtual DLLEXPORT QoreString * getAsString(bool &del, int foff, ExceptionSink *xsink) const
returns a QoreString giving the verbose string representation of the 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...
DLLLOCAL AbstractCallReferenceNode(bool n_needs_eval, bool n_there_can_be_only_one, qore_type_t n_type=NT_FUNCREF)
protected constructor for subclasses that are not reference-counted
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
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
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition ExceptionSink.h:50
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition QoreListNode.h:52
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only
Definition QoreProgram.h:128
Provides atomic reference counting to Qore objects.
Definition QoreReferenceCounter.h:44
DLLEXPORT void ROreference() const
Atomically increments the reference count.
DLLEXPORT bool ROdereference() const
Atomically decrements the reference count.
Qore's string type supported by the QoreEncoding class.
Definition QoreString.h:93
base class for resolved call references
Definition CallReferenceNode.h:115
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
returns true if the other node is the same value
DLLLOCAL ResolvedCallReferenceNode * refRefSelf() const
references itself and returns this
Definition CallReferenceNode.h:146
DLLLOCAL void weakRef()
Increments the weak reference count.
Definition CallReferenceNode.h:167
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
returns true if the other node is the same value
virtual DLLEXPORT QoreProgram * getProgram() const
returns a pointer to the QoreProgram object associated with this reference (can be nullptr)
QoreReferenceCounter weak_refs
weak references
Definition CallReferenceNode.h:180
virtual DLLEXPORT bool derefImpl(ExceptionSink *xsink)
Called when the strong reference count reaches zero.
virtual DLLEXPORT ~ResolvedCallReferenceNode()
public destructor function
DLLLOCAL void weakDeref()
Decrements the weak reference count.
Definition CallReferenceNode.h:172
virtual DLLLOCAL QoreValue execValue(const QoreListNode *args, ExceptionSink *xsink) const =0
pure virtual function for executing the function reference
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns this with the ref count inmcremented; not a real copy
DLLLOCAL ResolvedCallReferenceNode(bool n_needs_eval, qore_type_t n_type=NT_FUNCREF)
constructor is not exported outside the library
virtual DLLLOCAL QoreFunction * getFunction()=0
Returns the internal function object, if any; can return nullptr.
virtual DLLEXPORT QoreValue evalImpl(bool &needs_deref, ExceptionSink *xsink) const
this function should never be called for function references; this function should never be called di...
DLLEXPORT ResolvedCallReferenceNode()
public exported constructor function
virtual DLLEXPORT int parseInit(QoreValue &val, QoreParseContext &parse_context)
for use by parse types to initialize them for execution during stage 1 parsing
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode)
Definition common.h:76
const qore_type_t NT_FUNCREF
type value for ResolvedCallReferenceNode
Definition node_types.h:68
The main value class in Qore, designed to be passed by value.
Definition QoreValue.h:279