ExpressionOperator.cpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.oorexx.org/license.html */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /******************************************************************************/
39 /* REXX Translator */
40 /* */
41 /* Primitive Operator Parse Class */
42 /* */
43 /******************************************************************************/
44 #include <stdlib.h>
45 #include "RexxCore.h"
46 #include "RexxActivation.hpp"
47 #include "ExpressionOperator.hpp"
48 
50 {
51  "+",
52  "-",
53  "*",
54  "/",
55  "%",
56  "//",
57  "**",
58  "",
59  "||",
60  " ",
61  "=",
62  "\\=",
63  ">",
64  "\\>",
65  "<",
66  "\\<",
67  ">=",
68  "<=",
69  "==",
70  "\\==",
71  ">>",
72  "\\>>",
73  "<<",
74  "\\<<",
75  ">>=",
76  "<<=",
77  "<>",
78  "><",
79  "&",
80  "|",
81  "&&",
82  "\\",
83 };
84 
85 
86 
88  int op, /* operator index */
89  RexxObject *left, /* left expression objects */
90  RexxObject *right) /* right expression objects */
91 /******************************************************************************/
92 /* Function: Initialize a translator operator object */
93 /******************************************************************************/
94 {
95  /* just fill in the three terms */
96  this->oper = op;
97  OrefSet(this, this->left_term, left);
98  OrefSet(this, this->right_term, right);
99 }
100 
101 
103  RexxActivation *context, /* current activation context */
104  RexxExpressionStack *stack ) /* evaluation stack */
105 /******************************************************************************/
106 /* Function: Execute a REXX binary operator */
107 /******************************************************************************/
108 {
109  /* evaluate the target */
110  RexxObject *left = this->left_term->evaluate(context, stack);
111  /* evaluate the right term */
112  RexxObject *right = this->right_term->evaluate(context, stack);
113  /* evaluate the message */
114  RexxObject *result = callOperatorMethod(left, this->oper, right);
115  /* replace top two stack elements */
116  stack->operatorResult(result); /* with this one */
117  /* trace if necessary */
118  context->traceOperator(operatorName(), result);
119  return result; /* return the result */
120 }
121 
123  RexxActivation *context, /* current activation context */
124  RexxExpressionStack *stack ) /* evaluation stack */
125 /******************************************************************************/
126 /* Function: Execute a REXX prefix operator */
127 /******************************************************************************/
128 {
129  /* evaluate the target */
130  RexxObject *term = this->left_term->evaluate(context, stack);
131  /* process this directly */
132  RexxObject *result = callOperatorMethod(term, this->oper, OREF_NULL);
133  stack->prefixResult(result); /* replace the top element */
134  /* trace if necessary */
135  context->tracePrefix(operatorName(), result);
136  return result; /* return the result */
137 }
138 
139 void RexxExpressionOperator::live(size_t liveMark)
140 /******************************************************************************/
141 /* Function: Normal garbage collection live marking */
142 /******************************************************************************/
143 {
144  memory_mark(this->left_term);
145  memory_mark(this->right_term);
146 }
147 
149 /******************************************************************************/
150 /* Function: Generalized object marking */
151 /******************************************************************************/
152 {
155 }
156 
158 /******************************************************************************/
159 /* Function: Flatten an object */
160 /******************************************************************************/
161 {
163 
164  flatten_reference(newThis->left_term, envelope);
165  flatten_reference(newThis->right_term, envelope);
166 
168 }
169 
170 
171 void *RexxUnaryOperator::operator new(size_t size)
172 /******************************************************************************/
173 /* Function: Create a new translator object */
174 /******************************************************************************/
175 {
176  /* Get new object */
177  return new_object(size, T_UnaryOperatorTerm);
178 }
179 
180 void *RexxBinaryOperator::operator new(size_t size)
181 /******************************************************************************/
182 /* Function: Create a new translator object */
183 /******************************************************************************/
184 {
185  /* Get new object */
186  return new_object(size, T_BinaryOperatorTerm);
187 }
188 
@ T_UnaryOperatorTerm
@ T_BinaryOperatorTerm
#define OREF_NULL
Definition: RexxCore.h:61
#define OrefSet(o, r, v)
Definition: RexxCore.h:101
RexxObject * callOperatorMethod(RexxObject *object, size_t methodOffset, RexxObject *argument)
Definition: RexxCore.h:565
#define memory_mark(oref)
Definition: RexxMemory.hpp:450
RexxObject * new_object(size_t s)
Definition: RexxMemory.hpp:436
#define flatten_reference(oref, envel)
Definition: RexxMemory.hpp:498
#define memory_mark_general(oref)
Definition: RexxMemory.hpp:451
#define cleanUpFlatten
Definition: RexxMemory.hpp:484
#define setUpFlatten(type)
Definition: RexxMemory.hpp:478
void tracePrefix(const char *n, RexxObject *v)
void traceOperator(const char *n, RexxObject *v)
RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
void flatten(RexxEnvelope *)
static const char * operatorNames[]
void operatorResult(RexxObject *value)
void prefixResult(RexxObject *value)
virtual RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)