Qore Programming Language 1.19.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ObjectMethodReferenceNode.h
1/* -*- mode: c++; indent-tabs-mode: nil -*- */
2/*
3 ObjectMethodReference.h
4
5 Qore Programming Language
6
7 Copyright (C) 2003 - 2023 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_OBJECTMETHODREFERENCE_H
33
34#define _QORE_OBJECTMETHODREFERENCE_H
35
36#include <string>
37
38class AbstractParseObjectMethodReferenceNode : public ParseNode {
39protected:
41
44 DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const = 0;
45
46public:
47 DLLLOCAL AbstractParseObjectMethodReferenceNode(const QoreProgramLocation* loc) : ParseNode(loc, NT_OBJMETHREF) {
48 }
49
50 DLLLOCAL virtual ~AbstractParseObjectMethodReferenceNode() {
51 }
52
53 DLLLOCAL virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const {
54 str.sprintf("object method reference (%p)", this);
55 return 0;
56 }
57
58 // if del is true, then the returned QoreString* should be deleted, if false, then it must not be
59 DLLLOCAL virtual QoreString* getAsString(bool& del, int foff, ExceptionSink* xsink) const {
60 del = true;
61 QoreString* rv = new QoreString;
62 getAsString(*rv, foff, xsink);
63 return rv;
64 }
65
66 // returns the type name as a c string
67 DLLLOCAL virtual const char* getTypeName() const {
68 return "object method reference";
69 }
70};
71
72class ParseObjectMethodReferenceNode : public AbstractParseObjectMethodReferenceNode {
73private:
74 QoreValue exp;
75 std::string method;
76 const QoreClass *qc;
77 mutable const QoreMethod* m;
78 mutable QoreThreadLock lck;
79
80 DLLLOCAL virtual ~ParseObjectMethodReferenceNode();
81
82 DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const {
83 return callReferenceTypeInfo;
84 }
85
86protected:
88
91 DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
92
93public:
94 DLLLOCAL ParseObjectMethodReferenceNode(const QoreProgramLocation* loc, QoreValue n_exp, char* n_method);
95 DLLLOCAL virtual int parseInitImpl(QoreValue& val, QoreParseContext& parse_context);
96};
97
98class ParseSelfMethodReferenceNode : public AbstractParseObjectMethodReferenceNode {
99private:
100 std::string method;
101 const QoreMethod* meth;
102
103 DLLLOCAL ~ParseSelfMethodReferenceNode() {
104 }
105
106 DLLLOCAL virtual int parseInitImpl(QoreValue& val, QoreParseContext& parse_context);
107
108 DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const {
109 return callReferenceTypeInfo;
110 }
111
112protected:
113 // returns a RunTimeObjectMethodReference or NULL if there's an exception
114 DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
115
116public:
117 DLLLOCAL ParseSelfMethodReferenceNode(const QoreProgramLocation* loc, char* n_method)
118 : AbstractParseObjectMethodReferenceNode(loc), method(n_method), meth(0) {
119 free(n_method);
120 }
121
122 DLLLOCAL ParseSelfMethodReferenceNode(const QoreProgramLocation* loc, const QoreMethod* m)
123 : AbstractParseObjectMethodReferenceNode(loc), meth(m) {
124 }
125};
126
127class ParseScopedSelfMethodReferenceNode : public AbstractParseObjectMethodReferenceNode {
128private:
129 NamedScope *nscope;
130 const QoreMethod* method;
131
132 DLLLOCAL virtual ~ParseScopedSelfMethodReferenceNode();
133
134protected:
135 // returns a RunTimeObjectMethodReference or NULL if there's an exception
136 DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
137
138 DLLLOCAL virtual int parseInitImpl(QoreValue& val, QoreParseContext& parse_context);
139 DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const {
140 return callReferenceTypeInfo;
141 }
142
143public:
144 DLLLOCAL ParseScopedSelfMethodReferenceNode(const QoreProgramLocation* loc, NamedScope *n_nscope);
145};
146
147#endif
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
defines a Qore-language class
Definition: QoreClass.h:253
a method in a QoreClass
Definition: QoreClass.h:139
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...
provides a mutually-exclusive thread lock
Definition: QoreThreadLock.h:49
const qore_type_t NT_OBJMETHREF
type value for AbstractParseObjectMethodReferenceNode
Definition: node_types.h:67
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:276