Qore Programming Language  1.12.0
ParseReferenceNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  ParseReferenceNode.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2022 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 public:
42 
44  DLLLOCAL ParseReferenceNode(const QoreProgramLocation* loc, QoreValue exp,
45  const QoreTypeInfo* typeInfo = referenceTypeInfo) : ParseNode(loc, NT_PARSEREFERENCE, true, false),
46  lvexp(exp), typeInfo(typeInfo) {
47  }
48 
50 
56  DLLLOCAL virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const {
57  str.sprintf("parse reference expression (%p)", this);
58  return 0;
59  }
60 
62 
70  DLLLOCAL virtual QoreString* getAsString(bool &del, int foff, class ExceptionSink* xsink) const {
71  del = true;
72  QoreString* rv = new QoreString();
73  getAsString(*rv, foff, xsink);
74  return rv;
75  }
76 
78  DLLLOCAL virtual const char* getTypeName() const {
79  return "reference to lvalue";
80  }
81 
82  DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const {
83  return typeInfo;
84  }
85 
86  // returns an intermediate reference for use with the background operator
87  DLLLOCAL IntermediateParseReferenceNode* evalToIntermediate(ExceptionSink* xsink) const;
88 
89  // returns a runtime reference
90  DLLLOCAL virtual ReferenceNode* evalToRef(ExceptionSink* xsink) const;
91 
92 protected:
94  QoreValue lvexp;
96  const QoreTypeInfo* typeInfo;
97 
99  DLLLOCAL ~ParseReferenceNode() {
100  lvexp.discard(nullptr);
101  }
102 
103  // returns a runtime reference (ReferenceNode)
104  DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const {
105  return evalToRef(xsink);
106  }
107 
108  DLLLOCAL QoreValue doPartialEval(QoreValue n, QoreObject*& self, const void*& lvalue_id,
109  const qore_class_private*& qc, ExceptionSink* xsink) const;
110 
112  DLLLOCAL virtual int parseInitImpl(QoreValue& val, QoreParseContext& parse_context);
113 };
114 
115 class IntermediateParseReferenceNode : public ParseReferenceNode {
116 protected:
117  QoreObject* self;
118  const void* lvalue_id;
119  const qore_class_private* cls;
120 
121  DLLLOCAL virtual bool derefImpl(ExceptionSink* xsink) {
122  lvexp.discard(xsink);
123  lvexp = QoreValue();
124  return true;
125  }
126 
127 public:
128  DLLLOCAL IntermediateParseReferenceNode(const QoreProgramLocation* loc, QoreValue exp,
129  const QoreTypeInfo* typeInfo, QoreObject* o, const void* lvid, const qore_class_private* n_cls);
130 
131  // returns a runtime reference
132  DLLLOCAL virtual ReferenceNode* evalToRef(ExceptionSink* xsink) const {
133  return new ReferenceNode(lvexp.refSelf(), typeInfo, self, lvalue_id, cls);
134  }
135 };
136 
137 #endif // _QORE_INTERN_PARSEREFERENCENODE_H
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
the implementation of Qore's object data type, reference counted, dynamically-allocated only
Definition: QoreObject.h:60
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...
parse type: reference to a lvalue expression
Definition: ReferenceNode.h:45
const qore_type_t NT_PARSEREFERENCE
type value for ParseReferenceNode (private class)
Definition: node_types.h:80
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:275
DLLEXPORT void discard(ExceptionSink *xsink)
dereferences any contained AbstractQoreNode pointer and sets to 0; does not modify other values
DLLEXPORT QoreValue refSelf() const
references the contained value if type == QV_Node, returns itself