Qore Programming Language  0.9.16
ParseNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  ParseNode.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2018 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 
38 class ParseNode : public SimpleQoreNode {
39 public:
40  const QoreProgramLocation* loc;
41 
42 private:
43  // not implemented
44  ParseNode& operator=(const ParseNode&) = delete;
45 
46 protected:
48  bool effect : 1;
49 
51  bool effect_as_root : 1;
52 
54  bool ref_rv : 1;
55 
57  bool parse_init : 1;
58 
59  DLLLOCAL virtual void parseInitImpl(QoreValue& val, LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo) = 0;
60 
61  DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const = 0;
62 
63 public:
64  DLLLOCAL ParseNode(const QoreProgramLocation* loc, qore_type_t t, bool n_needs_eval = true) : SimpleQoreNode(t, false, n_needs_eval), loc(loc), effect(n_needs_eval), ref_rv(true), parse_init(false) {
65  effect_as_root = effect;
66  }
67  DLLLOCAL ParseNode(const QoreProgramLocation* loc, qore_type_t t, bool n_needs_eval, bool n_effect) : SimpleQoreNode(t, false, n_needs_eval), loc(loc), effect(n_effect), ref_rv(true), parse_init(false) {
68  effect_as_root = effect;
69  }
70  DLLLOCAL ParseNode(const ParseNode& old) : SimpleQoreNode(old.type, false, old.needs_eval_flag), loc(old.loc), effect(old.effect), ref_rv(old.ref_rv), parse_init(false) {
71  effect_as_root = effect;
72  }
73  // parse types should never be copied
74  DLLLOCAL virtual AbstractQoreNode* realCopy() const {
75  assert(false);
76  return 0;
77  }
78  DLLLOCAL virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const {
79  assert(false);
80  return false;
81  }
82  DLLLOCAL virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const {
83  assert(false);
84  return false;
85  }
86  DLLLOCAL void set_effect(bool n_effect) {
87  effect = n_effect;
88  }
89  DLLLOCAL bool has_effect() const {
90  return effect;
91  }
92  DLLLOCAL void set_effect_as_root(bool n_effect) {
93  effect_as_root = n_effect;
94  }
95  DLLLOCAL bool has_effect_as_root() const {
96  return effect_as_root;
97  }
98  DLLLOCAL void ignore_rv() {
99  ref_rv = false;
100  }
101  DLLLOCAL bool need_rv() const {
102  return ref_rv;
103  }
104 
105  DLLLOCAL virtual void parseInit(QoreValue& val, LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo) {
106  if (parse_init) {
107  typeInfo = getTypeInfo();
108  return;
109  }
110  parse_init = true;
111  parseInitImpl(val, oflag, pflag, lvids, typeInfo);
112  }
113 };
114 
115 // these objects will never be copied or referenced therefore they can have
116 // public destructors - the deref() functions just call "delete this;"
117 class ParseNoEvalNode : public ParseNode {
118 private:
119  // not implemented
120  DLLLOCAL ParseNoEvalNode& operator=(const ParseNoEvalNode&);
121 
122  DLLLOCAL virtual void parseInitImpl(QoreValue& val, LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo) = 0;
123  DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const = 0;
124 
125 protected:
126  DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const {
127  assert(false);
128  return QoreValue();
129  }
130 
131 public:
132  DLLLOCAL ParseNoEvalNode(const QoreProgramLocation* loc, qore_type_t t) : ParseNode(loc, t, false) {
133  }
134 
135  DLLLOCAL ParseNoEvalNode(const ParseNoEvalNode& old) : ParseNode(old) {
136  }
137 };
138 
139 #endif
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
AbstractQoreNode::is_equal_hard
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const =0
tests for equality ("deep compare" including all contained values for container types) without type c...
AbstractQoreNode::realCopy
virtual DLLEXPORT AbstractQoreNode * realCopy() const =0
returns a copy of the object; the caller owns the reference count
AbstractQoreNode::needs_eval_flag
bool needs_eval_flag
if this is true then the type can be evaluated
Definition: AbstractQoreNode.h:327
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
AbstractQoreNode::is_equal_soft
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const =0
tests for equality ("deep compare" including all contained values for container types) with possible ...
AbstractQoreNode::type
qore_type_t type
the type of the object
Definition: AbstractQoreNode.h:321
SimpleQoreNode::operator=
SimpleQoreNode & operator=(const SimpleQoreNode &)=delete
this function is not implemented
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
qore_type_t
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode)
Definition: common.h:70
AbstractQoreNode::parseInit
virtual DLLLOCAL void parseInit(QoreValue &val, LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo)
for use by parse types to initialize them for execution during stage 1 parsing; not exported in the l...
SimpleQoreNode
The base class for all types in Qore expression trees that cannot throw an exception when deleted.
Definition: AbstractQoreNode.h:346