Qore Programming Language  0.9.16
ParseReferenceNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  ParseReferenceNode.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2020 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_PARSEREFERENCENODE_H
33 #define _QORE_INTERN_PARSEREFERENCENODE_H
34 
35 #include "qore/intern/ParseNode.h"
36 
37 class IntermediateParseReferenceNode;
38 
39 class ParseReferenceNode : public ParseNode {
40 protected:
42  QoreValue lvexp;
44  const QoreTypeInfo* typeInfo;
45 
47  DLLLOCAL ~ParseReferenceNode() {
48  lvexp.discard(nullptr);
49  }
50 
51  // returns a runtime reference (ReferenceNode)
52  DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const {
53  return evalToRef(xsink);
54  }
55 
56  DLLLOCAL QoreValue doPartialEval(QoreValue n, QoreObject*& self, const void*& lvalue_id, const qore_class_private*& qc, ExceptionSink* xsink) const;
57 
59  DLLLOCAL virtual void parseInitImpl(QoreValue& val, LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo);
60 
61 public:
63 
65  DLLLOCAL ParseReferenceNode(const QoreProgramLocation* loc, QoreValue exp, const QoreTypeInfo* typeInfo = referenceTypeInfo) : ParseNode(loc, NT_PARSEREFERENCE, true, false), lvexp(exp), typeInfo(typeInfo) {
66  }
67 
69 
75  DLLLOCAL virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const {
76  str.sprintf("parse reference expression (%p)", this);
77  return 0;
78  }
79 
81 
87  DLLLOCAL virtual QoreString* getAsString(bool &del, int foff, class ExceptionSink* xsink) const {
88  del = true;
89  QoreString* rv = new QoreString();
90  getAsString(*rv, foff, xsink);
91  return rv;
92  }
93 
95  DLLLOCAL virtual const char* getTypeName() const {
96  return "reference to lvalue";
97  }
98 
99  DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const {
100  return typeInfo;
101  }
102 
103  // returns an intermediate reference for use with the background operator
104  DLLLOCAL IntermediateParseReferenceNode* evalToIntermediate(ExceptionSink* xsink) const;
105 
106  // returns a runtime reference
107  DLLLOCAL virtual ReferenceNode* evalToRef(ExceptionSink* xsink) const;
108 };
109 
110 class IntermediateParseReferenceNode : public ParseReferenceNode {
111 protected:
112  QoreObject* self;
113  const void* lvalue_id;
114  const qore_class_private* cls;
115 
116  DLLLOCAL virtual bool derefImpl(ExceptionSink* xsink) {
117  lvexp.discard(xsink);
118  lvexp = QoreValue();
119  return true;
120  }
121 
122 public:
123  DLLLOCAL IntermediateParseReferenceNode(const QoreProgramLocation* loc, QoreValue exp, const QoreTypeInfo* typeInfo, QoreObject* o, const void* lvid, const qore_class_private* n_cls);
124 
125  // returns a runtime reference
126  DLLLOCAL virtual ReferenceNode* evalToRef(ExceptionSink* xsink) const {
127  return new ReferenceNode(lvexp.refSelf(), typeInfo, self, lvalue_id, cls);
128  }
129 };
130 
131 #endif // _QORE_INTERN_PARSEREFERENCENODE_H
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
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
QoreValue::refSelf
DLLEXPORT QoreValue refSelf() const
references the contained value if type == QV_Node, returns itself
NT_PARSEREFERENCE
const qore_type_t NT_PARSEREFERENCE
type value for ParseReferenceNode (private class)
Definition: node_types.h:80
QoreValue::discard
DLLEXPORT void discard(ExceptionSink *xsink)
dereferences any contained AbstractQoreNode pointer and sets to 0; does not modify other values
ReferenceNode
parse type: reference to a lvalue expression
Definition: ReferenceNode.h:45
QoreObject
the implementation of Qore's object data type, reference counted, dynamically-allocated only
Definition: QoreObject.h:61
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48