32 #ifndef _QORE_QOREOPERATORNODE_H
33 #define _QORE_QOREOPERATORNODE_H
42 class QoreOperatorNode :
public ParseNode {
48 DLLLOCAL
virtual ~QoreOperatorNode() {}
50 DLLLOCAL
virtual void ignoreReturnValueImpl() {}
53 DLLLOCAL QoreOperatorNode(
const QoreProgramLocation* loc,
bool n_ref_rv =
true) : ParseNode(loc,
NT_OPERATOR),
54 in_parentheses(false), ref_rv(n_ref_rv) {
58 DLLLOCAL
virtual const char *getTypeName()
const = 0;
60 DLLLOCAL
void ignoreReturnValue() {
62 ignoreReturnValueImpl();
65 DLLLOCAL
bool getInParentheses()
const {
66 return in_parentheses;
69 DLLLOCAL
void setInParentheses() {
70 in_parentheses =
true;
73 DLLLOCAL
virtual bool hasEffect()
const = 0;
74 DLLLOCAL
virtual bool hasEffectAsRoot()
const = 0;
76 DLLLOCAL
virtual QoreOperatorNode* copyBackground(
ExceptionSink *xsink)
const = 0;
79 class LValueOperatorNode :
public QoreOperatorNode {
81 DLLLOCAL LValueOperatorNode(
const QoreProgramLocation* loc) : QoreOperatorNode(loc) {
84 DLLLOCAL
virtual bool hasEffect()
const {
88 DLLLOCAL
virtual bool hasEffectAsRoot()
const {
92 DLLLOCAL
int checkLValue(
QoreValue exp,
int pflag,
bool assignment =
true) {
94 if (check_lvalue(exp, assignment)) {
95 parse_error(*loc,
"expecting lvalue for %s, got '%s' instead", getTypeName(), exp.getTypeName());
97 }
else if ((pflag & PF_BACKGROUND) && exp.getType() ==
NT_VARREF
98 && exp.get<
const VarRefNode>()->getType() == VT_LOCAL) {
99 parse_error(*loc,
"illegal local variable modification with the background operator in %s",
108 template <
class T = QoreOperatorNode>
109 class QoreSingleExpressionOperatorNode :
public T {
113 DLLLOCAL ~QoreSingleExpressionOperatorNode() {
118 DLLLOCAL QoreSingleExpressionOperatorNode(
const QoreProgramLocation* loc,
QoreValue exp) : T(loc), exp(exp) {
132 DLLLOCAL QoreSingleExpressionOperatorNode* makeSpecialization() {
136 O* rv =
new O(this->loc, e);
138 rv->ignoreReturnValue();
142 DLLLOCAL
virtual bool hasEffect()
const {
143 return exp.hasEffect();
146 DLLLOCAL
virtual bool hasEffectAsRoot()
const {
147 return dynamic_cast<const LValueOperatorNode*
>(
this);
151 DLLLOCAL O* copyBackgroundExplicit(
ExceptionSink* xsink)
const {
152 ValueHolder n_exp(copy_value_and_resolve_lvar_refs(exp, xsink), xsink);
155 return new O(this->loc, n_exp.release());
159 template <
class T = QoreOperatorNode>
160 class QoreSingleValueExpressionOperatorNode :
public T {
164 DLLLOCAL ~QoreSingleValueExpressionOperatorNode() {
169 DLLLOCAL QoreSingleValueExpressionOperatorNode(
const QoreProgramLocation* loc,
QoreValue exp) : T(loc), exp(exp) {
183 DLLLOCAL QoreSingleValueExpressionOperatorNode* makeSpecialization() {
187 O* rv =
new O(this->loc, e);
189 rv->ignoreReturnValue();
193 DLLLOCAL
virtual bool hasEffect()
const {
194 return exp.hasEffect();
197 DLLLOCAL
virtual bool hasEffectAsRoot()
const {
198 return dynamic_cast<const LValueOperatorNode*
>(
this);
202 DLLLOCAL O* copyBackgroundExplicit(
ExceptionSink* xsink)
const {
203 ValueHolder n_exp(copy_value_and_resolve_lvar_refs(exp, xsink), xsink);
206 return new O(this->loc, n_exp.release());
210 template <
class T = QoreOperatorNode>
211 class QoreBinaryOperatorNode :
public T {
216 DLLLOCAL QoreBinaryOperatorNode(
const QoreProgramLocation* loc,
QoreValue left,
QoreValue right) : T(loc), left(left), right(right) {
219 DLLLOCAL ~QoreBinaryOperatorNode() {
225 DLLLOCAL QoreBinaryOperatorNode* makeSpecialization() {
229 U* rv =
new U(this->loc, l, r);
231 rv->ignoreReturnValue();
255 DLLLOCAL
virtual bool hasEffect()
const {
256 return left.hasEffect() || right.hasEffect();
259 DLLLOCAL
virtual bool hasEffectAsRoot()
const {
260 return dynamic_cast<const LValueOperatorNode*
>(
this);
264 DLLLOCAL O* copyBackgroundExplicit(
ExceptionSink* xsink)
const {
265 ValueHolder n_left(copy_value_and_resolve_lvar_refs(left, xsink), xsink);
268 ValueHolder n_right(copy_value_and_resolve_lvar_refs(right, xsink), xsink);
271 return new O(this->loc, n_left.release(), n_right.release());
275 class QoreBoolBinaryOperatorNode :
public QoreBinaryOperatorNode<> {
277 DLLLOCAL QoreBoolBinaryOperatorNode(
const QoreProgramLocation* loc,
QoreValue left,
QoreValue right) : QoreBinaryOperatorNode<>(loc, left, right) {
280 DLLLOCAL
virtual const QoreTypeInfo* getTypeInfo()
const {
285 class QoreIntBinaryOperatorNode :
public QoreBinaryOperatorNode<> {
287 DLLLOCAL QoreIntBinaryOperatorNode(
const QoreProgramLocation* loc,
QoreValue left,
QoreValue right) : QoreBinaryOperatorNode<>(loc, left, right) {
290 DLLLOCAL
virtual const QoreTypeInfo* getTypeInfo()
const {
291 return bigIntTypeInfo;
295 #define OP_COMMON protected:\
296 DLLLOCAL static QoreString op_str;\
298 DLLLOCAL virtual QoreString* getAsString(bool& del, int foff, ExceptionSink* xsink) const {del = false;return &op_str;}\
299 DLLLOCAL virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const {str.concat(&op_str);return 0;}\
300 DLLLOCAL virtual const char* getTypeName() const {return op_str.getBuffer();}
302 template <
unsigned int N,
class T = QoreOperatorNode>
303 class QoreNOperatorNodeBase :
public T {
307 DLLLOCAL
virtual ~QoreNOperatorNodeBase() {
308 for (
unsigned i = 0; i < N; ++i) {
314 DLLLOCAL QoreNOperatorNodeBase(
const QoreProgramLocation* loc,
QoreValue a0, ...) : T(loc) {
318 for (
unsigned int i = 1; i < N; ++i)
319 e[i] = va_arg(ap, QoreSimpleValue);
323 DLLLOCAL
QoreValue get(
unsigned i)
const {
328 DLLLOCAL
virtual bool hasEffect()
const {
329 for (
unsigned int i = 0; i < N; ++i)
330 if (e[i].hasEffect())
335 DLLLOCAL
virtual bool hasEffectAsRoot()
const {
336 return dynamic_cast<const LValueOperatorNode*
>(
this);
341 #include "qore/intern/QoreDeleteOperatorNode.h"
342 #include "qore/intern/QoreRemoveOperatorNode.h"
343 #include "qore/intern/QoreSpliceOperatorNode.h"
344 #include "qore/intern/QoreExtractOperatorNode.h"
345 #include "qore/intern/QoreCastOperatorNode.h"
346 #include "qore/intern/QoreKeysOperatorNode.h"
347 #include "qore/intern/QoreUnaryMinusOperatorNode.h"
348 #include "qore/intern/QoreUnaryPlusOperatorNode.h"
349 #include "qore/intern/QoreLogicalNotOperatorNode.h"
350 #include "qore/intern/QoreDotEvalOperatorNode.h"
351 #include "qore/intern/QoreLogicalEqualsOperatorNode.h"
352 #include "qore/intern/QoreLogicalAbsoluteEqualsOperatorNode.h"
353 #include "qore/intern/QoreLogicalNotEqualsOperatorNode.h"
354 #include "qore/intern/QoreLogicalAbsoluteNotEqualsOperatorNode.h"
355 #include "qore/intern/QoreModuloOperatorNode.h"
356 #include "qore/intern/QoreBinaryAndOperatorNode.h"
357 #include "qore/intern/QoreBinaryOrOperatorNode.h"
358 #include "qore/intern/QoreBinaryXorOperatorNode.h"
359 #include "qore/intern/QoreBinaryNotOperatorNode.h"
360 #include "qore/intern/QoreShiftLeftOperatorNode.h"
361 #include "qore/intern/QoreShiftRightOperatorNode.h"
362 #include "qore/intern/QoreExistsOperatorNode.h"
363 #include "qore/intern/QoreElementsOperatorNode.h"
364 #include "qore/intern/QoreInstanceOfOperatorNode.h"
365 #include "qore/intern/QoreHashObjectDereferenceOperatorNode.h"
366 #include "qore/intern/QoreRegexMatchOperatorNode.h"
367 #include "qore/intern/QoreRegexNMatchOperatorNode.h"
368 #include "qore/intern/QoreRegexExtractOperatorNode.h"
369 #include "qore/intern/QoreRegexSubstOperatorNode.h"
370 #include "qore/intern/QoreTransliterationOperatorNode.h"
371 #include "qore/intern/QoreBinaryLValueOperatorNode.h"
372 #include "qore/intern/QoreAssignmentOperatorNode.h"
373 #include "qore/intern/QoreListAssignmentOperatorNode.h"
374 #include "qore/intern/QorePlusEqualsOperatorNode.h"
375 #include "qore/intern/QoreIntPlusEqualsOperatorNode.h"
376 #include "qore/intern/QoreMinusEqualsOperatorNode.h"
377 #include "qore/intern/QoreIntMinusEqualsOperatorNode.h"
378 #include "qore/intern/QoreOrEqualsOperatorNode.h"
379 #include "qore/intern/QoreAndEqualsOperatorNode.h"
380 #include "qore/intern/QoreModuloEqualsOperatorNode.h"
381 #include "qore/intern/QoreMultiplyEqualsOperatorNode.h"
382 #include "qore/intern/QoreDivideEqualsOperatorNode.h"
383 #include "qore/intern/QoreXorEqualsOperatorNode.h"
384 #include "qore/intern/QoreShiftLeftEqualsOperatorNode.h"
385 #include "qore/intern/QoreShiftRightEqualsOperatorNode.h"
386 #include "qore/intern/QorePostIncrementOperatorNode.h"
387 #include "qore/intern/QoreIntPostIncrementOperatorNode.h"
388 #include "qore/intern/QorePostDecrementOperatorNode.h"
389 #include "qore/intern/QoreIntPostDecrementOperatorNode.h"
390 #include "qore/intern/QorePreIncrementOperatorNode.h"
391 #include "qore/intern/QoreIntPreIncrementOperatorNode.h"
392 #include "qore/intern/QorePreDecrementOperatorNode.h"
393 #include "qore/intern/QoreIntPreDecrementOperatorNode.h"
394 #include "qore/intern/QoreLogicalLessThanOperatorNode.h"
395 #include "qore/intern/QoreLogicalGreaterThanOrEqualsOperatorNode.h"
396 #include "qore/intern/QoreLogicalGreaterThanOperatorNode.h"
397 #include "qore/intern/QoreLogicalLessThanOrEqualsOperatorNode.h"
398 #include "qore/intern/QoreDivisionOperatorNode.h"
399 #include "qore/intern/QoreQuestionMarkOperatorNode.h"
400 #include "qore/intern/QoreMapOperatorNode.h"
401 #include "qore/intern/QoreMapSelectOperatorNode.h"
402 #include "qore/intern/QoreHashMapOperatorNode.h"
403 #include "qore/intern/QoreHashMapSelectOperatorNode.h"
404 #include "qore/intern/QoreFoldlOperatorNode.h"
405 #include "qore/intern/QoreSelectOperatorNode.h"
406 #include "qore/intern/QoreNullCoalescingOperatorNode.h"
407 #include "qore/intern/QoreValueCoalescingOperatorNode.h"
408 #include "qore/intern/QoreChompOperatorNode.h"
409 #include "qore/intern/QoreTrimOperatorNode.h"
410 #include "qore/intern/QoreSquareBracketsOperatorNode.h"
411 #include "qore/intern/QoreShiftOperatorNode.h"
412 #include "qore/intern/QoreUnshiftOperatorNode.h"
413 #include "qore/intern/QorePopOperatorNode.h"
414 #include "qore/intern/QorePushOperatorNode.h"
415 #include "qore/intern/QoreLogicalAndOperatorNode.h"
416 #include "qore/intern/QoreLogicalOrOperatorNode.h"
417 #include "qore/intern/QoreLogicalComparisonOperatorNode.h"
418 #include "qore/intern/QorePlusOperatorNode.h"
419 #include "qore/intern/QoreMinusOperatorNode.h"
420 #include "qore/intern/QoreMultiplicationOperatorNode.h"
421 #include "qore/intern/QoreBackgroundOperatorNode.h"
422 #include "qore/intern/QoreRangeOperatorNode.h"
423 #include "qore/intern/QoreSquareBracketsRangeOperatorNode.h"
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
manages a reference count of a pointer to a class that takes a simple "deref()" call with no argument...
Definition: ReferenceHolder.h:118
holds an object and dereferences it in the destructor
Definition: QoreValue.h:476
const qore_type_t NT_OPERATOR
type value for QoreOperatorNode (private class)
Definition: node_types.h:76
const qore_type_t NT_VARREF
type value for VarRefNode
Definition: node_types.h:56
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