Qore Programming Language  0.9.16
ObjectMethodReferenceNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  ObjectMethodReference.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2018 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 
38 class AbstractParseObjectMethodReferenceNode : public ParseNode {
39 protected:
41 
44  DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const = 0;
45 
46 public:
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 
72 class ParseObjectMethodReferenceNode : public AbstractParseObjectMethodReferenceNode {
73 private:
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 
86 protected:
88 
91  DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
92 
93 public:
94  DLLLOCAL ParseObjectMethodReferenceNode(const QoreProgramLocation* loc, QoreValue n_exp, char* n_method);
95  DLLLOCAL virtual void parseInitImpl(QoreValue& val, LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo);
96 };
97 
98 class ParseSelfMethodReferenceNode : public AbstractParseObjectMethodReferenceNode {
99 private:
100  std::string method;
101  const QoreMethod* meth;
102 
103  DLLLOCAL ~ParseSelfMethodReferenceNode() {
104  }
105 
106  DLLLOCAL virtual void parseInitImpl(QoreValue& val, LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo);
107 
108  DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const {
109  return callReferenceTypeInfo;
110  }
111 
112 protected:
113  // returns a RunTimeObjectMethodReference or NULL if there's an exception
114  DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
115 
116 public:
117  DLLLOCAL ParseSelfMethodReferenceNode(const QoreProgramLocation* loc, char* n_method) : AbstractParseObjectMethodReferenceNode(loc), method(n_method), meth(0) {
118  free(n_method);
119  }
120 
121  DLLLOCAL ParseSelfMethodReferenceNode(const QoreProgramLocation* loc, const QoreMethod* m) : AbstractParseObjectMethodReferenceNode(loc), meth(m) {
122  }
123 };
124 
125 class ParseScopedSelfMethodReferenceNode : public AbstractParseObjectMethodReferenceNode {
126 private:
127  NamedScope *nscope;
128  const QoreMethod* method;
129 
130  DLLLOCAL virtual ~ParseScopedSelfMethodReferenceNode();
131 
132 protected:
133  // returns a RunTimeObjectMethodReference or NULL if there's an exception
134  DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
135 
136  DLLLOCAL virtual void parseInitImpl(QoreValue& val, LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo);
137  DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const {
138  return callReferenceTypeInfo;
139  }
140 
141 public:
142  DLLLOCAL ParseScopedSelfMethodReferenceNode(const QoreProgramLocation* loc, NamedScope *n_nscope);
143 };
144 
145 #endif
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
QoreClass
defines a Qore-language class
Definition: QoreClass.h:239
NT_OBJMETHREF
const qore_type_t NT_OBJMETHREF
type value for AbstractParseObjectMethodReferenceNode
Definition: node_types.h:67
QoreString::sprintf
DLLEXPORT int sprintf(const char *fmt,...)
this will concatentate a formatted string to the existing string according to the format string and t...
QoreString
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
QoreThreadLock
provides a mutually-exclusive thread lock
Definition: QoreThreadLock.h:49
QoreMethod
a method in a QoreClass
Definition: QoreClass.h:125