ooRexx  4.2.0-source
About: ooRexx (Open Object Rexx) is a free implementation of Object Rexx. Object Rexx is an enhancement of the classic Rexx interpreter; a full-featured programming language with a human-oriented syntax.
  Fossies Dox: ooRexx-4.2.0-source.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

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 
RexxExpressionOperator
Definition: ExpressionOperator.hpp:47
RexxExpressionStack
Definition: ExpressionStack.hpp:53
RexxExpressionStack::prefixResult
void prefixResult(RexxObject *value)
Definition: ExpressionStack.hpp:86
RexxInternalObject::evaluate
virtual RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
Definition: ObjectClass.hpp:269
memory_mark_general
#define memory_mark_general(oref)
Definition: RexxMemory.hpp:437
RexxActivation.hpp
OrefSet
#define OrefSet(o, r, v)
Definition: RexxCore.h:94
RexxActivation::tracePrefix
void tracePrefix(const char *n, RexxObject *v)
Definition: RexxActivation.hpp:384
RexxExpressionStack::operatorResult
void operatorResult(RexxObject *value)
Definition: ExpressionStack.hpp:85
RexxEnvelope
Definition: RexxEnvelope.hpp:53
RexxExpressionOperator::liveGeneral
void liveGeneral(int reason)
Definition: ExpressionOperator.cpp:148
RexxUnaryOperator::evaluate
RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
Definition: ExpressionOperator.cpp:122
RexxExpressionOperator::live
void live(size_t)
Definition: ExpressionOperator.cpp:139
RexxExpressionOperator::RexxExpressionOperator
RexxExpressionOperator()
Definition: ExpressionOperator.hpp:49
OREF_NULL
#define OREF_NULL
Definition: RexxCore.h:60
RexxActivation::traceOperator
void traceOperator(const char *n, RexxObject *v)
Definition: RexxActivation.hpp:382
callOperatorMethod
RexxObject * callOperatorMethod(RexxObject *object, size_t methodOffset, RexxObject *argument)
Definition: RexxCore.h:442
flatten_reference
#define flatten_reference(oref, envel)
Definition: RexxMemory.hpp:440
cleanUpFlatten
#define cleanUpFlatten
Definition: RexxMemory.hpp:432
memory_mark
#define memory_mark(oref)
Definition: RexxMemory.hpp:436
RexxExpressionOperator::left_term
RexxObject * left_term
Definition: ExpressionOperator.hpp:65
RexxActivation
Definition: RexxActivation.hpp:156
RexxExpressionOperator::operatorNames
static const char * operatorNames[]
Definition: ExpressionOperator.hpp:61
ExpressionOperator.hpp
setUpFlatten
#define setUpFlatten(type)
Definition: RexxMemory.hpp:427
T_BinaryOperatorTerm
Definition: ClassTypeCodes.h:136
RexxBinaryOperator::evaluate
RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
Definition: ExpressionOperator.cpp:102
RexxExpressionOperator::right_term
RexxObject * right_term
Definition: ExpressionOperator.hpp:64
RexxExpressionOperator::flatten
void flatten(RexxEnvelope *)
Definition: ExpressionOperator.cpp:157
RexxCore.h
RexxExpressionOperator::oper
int oper
Definition: ExpressionOperator.hpp:63
T_UnaryOperatorTerm
Definition: ClassTypeCodes.h:135
new_object
RexxObject * new_object(size_t s)
Definition: RexxMemory.hpp:422
RexxObject
Definition: ObjectClass.hpp:311
RexxExpressionOperator::operatorName
const char * operatorName()
Definition: ExpressionOperator.hpp:57