Qore Programming Language 2.0.0
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 - 2024 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#include "qore/intern/WeakHashReferenceNode.h"
38#include "qore/intern/WeakListReferenceNode.h"
39
40class ParseNode : public SimpleQoreNode {
41public:
42 const QoreProgramLocation* loc;
43
44 DLLLOCAL ParseNode(const QoreProgramLocation* loc, qore_type_t t, bool n_needs_eval = true)
45 : SimpleQoreNode(t, false, n_needs_eval), loc(loc), effect(n_needs_eval), ref_rv(true),
46 parse_init(false) {
47 effect_as_root = effect;
48 }
49 DLLLOCAL ParseNode(const QoreProgramLocation* loc, qore_type_t t, bool n_needs_eval, bool n_effect)
50 : SimpleQoreNode(t, false, n_needs_eval), loc(loc), effect(n_effect), ref_rv(true), parse_init(false) {
51 effect_as_root = effect;
52 }
53 DLLLOCAL ParseNode(const ParseNode& old) : SimpleQoreNode(old.type, false, old.needs_eval_flag), loc(old.loc),
54 effect(old.effect), ref_rv(old.ref_rv), parse_init(false) {
55 effect_as_root = effect;
56 }
57 // parse types should never be copied
58 DLLLOCAL virtual AbstractQoreNode* realCopy() const {
59 assert(false);
60 return 0;
61 }
62 DLLLOCAL virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const {
63 assert(false);
64 return false;
65 }
66 DLLLOCAL virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const {
67 assert(false);
68 return false;
69 }
70 DLLLOCAL void set_effect(bool n_effect) {
71 effect = n_effect;
72 }
73 DLLLOCAL bool has_effect() const {
74 return effect;
75 }
76 DLLLOCAL void set_effect_as_root(bool n_effect) {
77 effect_as_root = n_effect;
78 }
79 DLLLOCAL bool has_effect_as_root() const {
80 return effect_as_root;
81 }
82 DLLLOCAL void ignore_rv() {
83 ref_rv = false;
84 }
85 DLLLOCAL bool need_rv() const {
86 return ref_rv;
87 }
88
89 DLLLOCAL virtual int parseInit(QoreValue& val, QoreParseContext& parse_context) {
90 if (parse_init) {
91 parse_context.typeInfo = getTypeInfo();
92 return 0;
93 }
94 parse_init = true;
95 return parseInitImpl(val, parse_context);
96 }
97
98private:
99 // not implemented
100 ParseNode& operator=(const ParseNode&) = delete;
101
102protected:
104 bool effect : 1;
105
107 bool effect_as_root : 1;
108
110 bool ref_rv : 1;
111
113 bool parse_init : 1;
114
115 DLLLOCAL virtual int parseInitImpl(QoreValue& val, QoreParseContext& parse_context) = 0;
116
117 DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const = 0;
118};
119
120// these objects will never be copied or referenced therefore they can have
121// public destructors - the deref() functions just call "delete this;"
122class ParseNoEvalNode : public ParseNode {
123private:
124 // not implemented
125 DLLLOCAL ParseNoEvalNode& operator=(const ParseNoEvalNode&);
126
127 DLLLOCAL virtual int parseInitImpl(QoreValue& val, QoreParseContext& parse_context) = 0;
128 DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const = 0;
129
130protected:
131 DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const {
132 assert(false);
133 return QoreValue();
134 }
135
136public:
137 DLLLOCAL ParseNoEvalNode(const QoreProgramLocation* loc, qore_type_t t) : ParseNode(loc, t, false) {
138 }
139
140 DLLLOCAL ParseNoEvalNode(const ParseNoEvalNode& old) : ParseNode(old) {
141 }
142};
143
144#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:76
The main value class in Qore, designed to be passed by value.
Definition QoreValue.h:279