Qore Programming Language  1.12.0
QoreSquareBracketsOperatorNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreSquareBracketsOperatorNode.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_QORESQUAREBRACKETSOPERATORNODE_H
33 #define _QORE_QORESQUAREBRACKETSOPERATORNODE_H
34 
35 class QoreSquareBracketsOperatorNode : public QoreBinaryOperatorNode<>, public FunctionalOperator {
36 OP_COMMON
37 public:
38  DLLLOCAL QoreSquareBracketsOperatorNode(const QoreProgramLocation* loc, QoreValue left, QoreValue right)
39  : QoreBinaryOperatorNode<>(loc, left, right) {
40  }
41 
42  DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const {
43  return typeInfo;
44  }
45 
46  DLLLOCAL virtual QoreOperatorNode* copyBackground(ExceptionSink *xsink) const {
47  return copyBackgroundExplicit<QoreSquareBracketsOperatorNode>(xsink);
48  }
49 
50  DLLLOCAL static QoreValue doSquareBracketsListRange(const QoreValue l, const QoreParseListNode* pln,
51  ExceptionSink* xsink);
52 
53  DLLLOCAL static QoreValue doSquareBrackets(const QoreValue l, const QoreValue r, bool list_ok,
54  ExceptionSink* xsink);
55 
56 protected:
57  const QoreTypeInfo* typeInfo = nullptr;
58  // is the RHS a list with a range?
59  bool rhs_list_range = false;
60 
61  DLLLOCAL int parseCheckValueTypes(const QoreParseListNode* pln);
62  DLLLOCAL int parseCheckValueTypes(const QoreListNode* ln);
63 
64  DLLLOCAL QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
65 
66  DLLLOCAL virtual int parseInitImpl(QoreValue& val, QoreParseContext& parse_context);
67 
68  DLLLOCAL virtual FunctionalOperatorInterface* getFunctionalIteratorImpl(FunctionalValueType& value_type,
69  ExceptionSink* xsink) const;
70 
71  DLLLOCAL static int doString(SimpleRefHolder<QoreStringNode>& ret, const QoreValue l, const QoreValue r,
72  bool list_ok, ExceptionSink* xsink);
73  DLLLOCAL static int doBinary(SimpleRefHolder<BinaryNode>& ret, const QoreValue l, const QoreValue r, bool list_ok,
74  ExceptionSink* xsink);
75 };
76 
77 class QoreFunctionalSquareBracketsOperator : public FunctionalOperatorInterface {
78 public:
79  DLLLOCAL QoreFunctionalSquareBracketsOperator(ValueEvalRefHolder& lhs, ValueEvalRefHolder& rhs,
80  ExceptionSink* xsink)
81  : leftValue(*lhs, lhs.isTemp(), xsink),
82  rightList(rhs->get<const QoreListNode>()) {
83  lhs.clearTemp();
84  rhs.clearTemp();
85  }
86 
87  DLLLOCAL virtual ~QoreFunctionalSquareBracketsOperator() {}
88 
89  DLLLOCAL virtual bool getNextImpl(ValueOptionalRefHolder& val, ExceptionSink* xsink);
90 
91  DLLLOCAL virtual const QoreTypeInfo* getValueTypeImpl() const;
92 
93 protected:
94  ValueOptionalRefHolder leftValue;
95  const QoreListNode* rightList;
96  qore_offset_t offset = -1;
97 };
98 
99 class QoreFunctionalSquareBracketsComplexOperator : public FunctionalOperatorInterface {
100 public:
101  DLLLOCAL QoreFunctionalSquareBracketsComplexOperator(ValueEvalRefHolder& lhs, const QoreParseListNode* rpl,
102  ExceptionSink* xsink)
103  : leftValue(*lhs, lhs.isTemp(), xsink),
104  rightParseList(rpl) {
105  lhs.clearTemp();
106  }
107 
108  DLLLOCAL virtual ~QoreFunctionalSquareBracketsComplexOperator() {}
109 
110  DLLLOCAL virtual bool getNextImpl(ValueOptionalRefHolder& val, ExceptionSink* xsink);
111 
112  DLLLOCAL virtual const QoreTypeInfo* getValueTypeImpl() const;
113 
114 protected:
115  ValueOptionalRefHolder leftValue;
116  const QoreParseListNode* rightParseList;
117  qore_offset_t offset = -1;
118  std::unique_ptr<class QoreFunctionalRangeOperator> rangeIter;
119 };
120 
121 #endif
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
evaluates an AbstractQoreNode and dereferences the stored value in the destructor
Definition: QoreValue.h:613
allows storing a value and setting a boolean flag that indicates if the value should be dereference i...
Definition: QoreValue.h:509
DLLLOCAL void clearTemp()
sets needs_deref = false
Definition: QoreValue.h:533
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:275