Qore Programming Language  1.12.0
NewComplexTypeNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  NewComplexTypeNode.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_NEWCOMPLEXTYPENODE_H
33 
34 #define _QORE_INTERN_NEWCOMPLEXTYPENODE_H
35 
36 #include "qore/intern/FunctionCallNode.h"
37 
38 class ParseNewComplexTypeNode : public ParseNoEvalNode {
39 public:
40  DLLLOCAL ParseNewComplexTypeNode(const QoreProgramLocation* loc, QoreParseTypeInfo* pti, QoreParseListNode* a)
41  : ParseNoEvalNode(loc, NT_PARSE_NEW_COMPLEX_TYPE), pti(pti), args(a) {
42  }
43 
44  DLLLOCAL ~ParseNewComplexTypeNode() {
45  if (args)
46  args->deref(nullptr);
47  delete pti;
48  }
49 
50  // do not know type until resolution
51  DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const {
52  return anyTypeInfo;
53  }
54 
55  DLLLOCAL virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const {
56  str.sprintf("new complex type operator expression ('%s')", QoreParseTypeInfo::getName(pti));
57  return 0;
58  }
59 
60  // if del is true, then the returned QoreString * should be deleted, if false, then it must not be
61  DLLLOCAL virtual QoreString* getAsString(bool& del, int foff, ExceptionSink* xsink) const {
62  del = true;
63  QoreString* rv = new QoreString;
64  getAsString(*rv, foff, xsink);
65  return rv;
66  }
67 
68  DLLLOCAL virtual const char* getTypeName() const {
69  return "new complex type operator expression";
70  }
71 
72 protected:
73  QoreParseTypeInfo* pti;
74  QoreParseListNode* args;
75 
76  DLLLOCAL virtual int parseInitImpl(QoreValue& val, QoreParseContext& parse_context);
77 
78  DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const {
79  assert(false);
80  return QoreValue();
81  }
82 
83  DLLLOCAL QoreParseListNode* takeArgs() {
84  QoreParseListNode* rv = args;
85  args = nullptr;
86  return rv;
87  }
88 };
89 
90 class NewHashDeclNode : public ParseNode {
91 protected:
92  DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
93 
94  DLLLOCAL virtual int parseInitImpl(QoreValue& val, QoreParseContext& parse_context) {
95  return 0;
96  }
97 
98  DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const {
99  return hd ? hd->getTypeInfo() : hashTypeInfo;
100  }
101 
102 public:
103  const TypedHashDecl* hd;
104  QoreParseListNode* args;
105  bool runtime_check;
106 
107  DLLLOCAL NewHashDeclNode(const QoreProgramLocation* loc, const TypedHashDecl* hd, QoreParseListNode* a,
108  bool runtime_check) : ParseNode(loc, NT_SCOPE_REF), hd(hd), args(a), runtime_check(runtime_check) {
109  }
110 
111  DLLLOCAL virtual ~NewHashDeclNode() {
112  if (args)
113  args->deref(nullptr);
114  }
115 
116  DLLLOCAL virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const {
117  str.sprintf("new hashdecl operator expression (hashdecl '%s')", hd->getName());
118  return 0;
119  }
120 
121  // if del is true, then the returned QoreString * should be deleted, if false, then it must not be
122  DLLLOCAL virtual QoreString* getAsString(bool& del, int foff, ExceptionSink* xsink) const {
123  del = true;
124  QoreString* rv = new QoreString;
125  getAsString(*rv, foff, xsink);
126  return rv;
127  }
128 
129  DLLLOCAL virtual const char* getTypeName() const {
130  return "new hashdecl operator expression";
131  }
132 };
133 
134 class NewComplexHashNode : public ParseNode {
135 protected:
136  DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
137 
138  DLLLOCAL virtual int parseInitImpl(QoreValue& val, QoreParseContext& parse_context) {
139  return 0;
140  }
141 
142  DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const {
143  return typeInfo;
144  }
145 
146 public:
147  const QoreTypeInfo* typeInfo;
148  QoreParseListNode* args;
149 
150  DLLLOCAL NewComplexHashNode(const QoreProgramLocation* loc, const QoreTypeInfo* typeInfo, QoreParseListNode* a)
151  : ParseNode(loc, NT_SCOPE_REF), typeInfo(typeInfo), args(a) {
152  assert(QoreTypeInfo::getUniqueReturnComplexHash(typeInfo));
153  }
154 
155  DLLLOCAL virtual ~NewComplexHashNode() {
156  if (args)
157  args->deref(nullptr);
158  }
159 
160  DLLLOCAL virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const {
161  str.sprintf("new complex hash operator expression ('%s')", QoreTypeInfo::getName(typeInfo));
162  return 0;
163  }
164 
165  // if del is true, then the returned QoreString * should be deleted, if false, then it must not be
166  DLLLOCAL virtual QoreString* getAsString(bool& del, int foff, ExceptionSink* xsink) const {
167  del = true;
168  QoreString* rv = new QoreString;
169  getAsString(*rv, foff, xsink);
170  return rv;
171  }
172 
173  DLLLOCAL virtual const char* getTypeName() const {
174  return "new complex hash operator expression";
175  }
176 };
177 
178 class NewComplexListNode : public ParseNode {
179 protected:
180  DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
181 
182  DLLLOCAL virtual int parseInitImpl(QoreValue& val, QoreParseContext& parse_context) {
183  return 0;
184  }
185 
186  DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const {
187  return typeInfo;
188  }
189 
190 public:
191  const QoreTypeInfo* typeInfo;
192  QoreValue args;
193 
194  DLLLOCAL NewComplexListNode(const QoreProgramLocation* loc, const QoreTypeInfo* typeInfo, QoreValue a)
195  : ParseNode(loc, NT_SCOPE_REF), typeInfo(typeInfo), args(a) {
196  assert(QoreTypeInfo::getUniqueReturnComplexList(typeInfo));
197  }
198 
199  DLLLOCAL virtual ~NewComplexListNode() {
200  args.discard(nullptr);
201  }
202 
203  DLLLOCAL virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const {
204  str.sprintf("new complex list operator expression ('%s')", QoreTypeInfo::getName(typeInfo));
205  return 0;
206  }
207 
208  // if del is true, then the returned QoreString * should be deleted, if false, then it must not be
209  DLLLOCAL virtual QoreString* getAsString(bool& del, int foff, ExceptionSink* xsink) const {
210  del = true;
211  QoreString* rv = new QoreString;
212  getAsString(*rv, foff, xsink);
213  return rv;
214  }
215 
216  DLLLOCAL virtual const char* getTypeName() const {
217  return "new complex list operator expression";
218  }
219 };
220 
221 #endif
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
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...
typed hash declaration
Definition: TypedHashDecl.h:44
DLLEXPORT const char * getName() const
returns the name of the typed hash
const qore_type_t NT_SCOPE_REF
type value for ScopedObjectCallNode
Definition: node_types.h:61
const qore_type_t NT_PARSE_NEW_COMPLEX_TYPE
type value for ParseNewComplexTypeNode
Definition: node_types.h:85
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