Qore Programming Language 1.19.1
Loading...
Searching...
No Matches
ParseNode.h
1/* -*- mode: c++; indent-tabs-mode: nil -*- */
2/*
3 ParseNode.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_PARSENODE_H
33
34#define _QORE_PARSENODE_H
35
36#include "qore/intern/WeakReferenceNode.h"
37
38class ParseNode : public SimpleQoreNode {
39public:
40 const QoreProgramLocation* loc;
41
42 DLLLOCAL ParseNode(const QoreProgramLocation* loc, qore_type_t t, bool n_needs_eval = true)
43 : SimpleQoreNode(t, false, n_needs_eval), loc(loc), effect(n_needs_eval), ref_rv(true),
44 parse_init(false) {
45 effect_as_root = effect;
46 }
47 DLLLOCAL ParseNode(const QoreProgramLocation* loc, qore_type_t t, bool n_needs_eval, bool n_effect)
48 : SimpleQoreNode(t, false, n_needs_eval), loc(loc), effect(n_effect), ref_rv(true), parse_init(false) {
49 effect_as_root = effect;
50 }
51 DLLLOCAL ParseNode(const ParseNode& old) : SimpleQoreNode(old.type, false, old.needs_eval_flag), loc(old.loc),
52 effect(old.effect), ref_rv(old.ref_rv), parse_init(false) {
53 effect_as_root = effect;
54 }
55 // parse types should never be copied
56 DLLLOCAL virtual AbstractQoreNode* realCopy() const {
57 assert(false);
58 return 0;
59 }
60 DLLLOCAL virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const {
61 assert(false);
62 return false;
63 }
64 DLLLOCAL virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const {
65 assert(false);
66 return false;
67 }
68 DLLLOCAL void set_effect(bool n_effect) {
69 effect = n_effect;
70 }
71 DLLLOCAL bool has_effect() const {
72 return effect;
73 }
74 DLLLOCAL void set_effect_as_root(bool n_effect) {
75 effect_as_root = n_effect;
76 }
77 DLLLOCAL bool has_effect_as_root() const {
78 return effect_as_root;
79 }
80 DLLLOCAL void ignore_rv() {
81 ref_rv = false;
82 }
83 DLLLOCAL bool need_rv() const {
84 return ref_rv;
85 }
86
87 DLLLOCAL virtual int parseInit(QoreValue& val, QoreParseContext& parse_context) {
88 if (parse_init) {
89 parse_context.typeInfo = getTypeInfo();
90 return 0;
91 }
92 parse_init = true;
93 return parseInitImpl(val, parse_context);
94 }
95
96private:
97 // not implemented
98 ParseNode& operator=(const ParseNode&) = delete;
99
100protected:
102 bool effect : 1;
103
105 bool effect_as_root : 1;
106
108 bool ref_rv : 1;
109
111 bool parse_init : 1;
112
113 DLLLOCAL virtual int parseInitImpl(QoreValue& val, QoreParseContext& parse_context) = 0;
114
115 DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const = 0;
116};
117
118// these objects will never be copied or referenced therefore they can have
119// public destructors - the deref() functions just call "delete this;"
120class ParseNoEvalNode : public ParseNode {
121private:
122 // not implemented
123 DLLLOCAL ParseNoEvalNode& operator=(const ParseNoEvalNode&);
124
125 DLLLOCAL virtual int parseInitImpl(QoreValue& val, QoreParseContext& parse_context) = 0;
126 DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const = 0;
127
128protected:
129 DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const {
130 assert(false);
131 return QoreValue();
132 }
133
134public:
135 DLLLOCAL ParseNoEvalNode(const QoreProgramLocation* loc, qore_type_t t) : ParseNode(loc, t, false) {
136 }
137
138 DLLLOCAL ParseNoEvalNode(const ParseNoEvalNode& old) : ParseNode(old) {
139 }
140};
141
142#endif
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
bool needs_eval_flag
if this is true then the type can be evaluated
Definition: AbstractQoreNode.h:333
qore_type_t type
the type of the object
Definition: AbstractQoreNode.h:327
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
The base class for all types in Qore expression trees that cannot throw an exception when deleted.
Definition: AbstractQoreNode.h:352
SimpleQoreNode & operator=(const SimpleQoreNode &)=delete
this function is not implemented
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode)
Definition: common.h:70
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:276