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)  

ExpressionStem.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 ExpressionStem.cpp */
40 /* */
41 /* Primitive Translator Expression Parsing Stem Reference Class */
42 /* */
43 /******************************************************************************/
44 /******************************************************************************/
45 
46 #include <stdlib.h>
47 #include "RexxCore.h"
48 #include "StringClass.hpp"
49 #include "RexxActivation.hpp"
50 #include "RexxVariable.hpp"
52 #include "StemClass.hpp"
53 #include "ExpressionStem.hpp"
54 
56  RexxString * stemName, /* stem name to access */
57  size_t var_index) /* lookaside index for stem */
58 /******************************************************************************/
59 /* Function: Initialize a translator STEM object */
60 /******************************************************************************/
61 {
62  /* set the name */
63  OrefSet(this, this->stem, stemName); /* set the name */
64  this->index = var_index; /* and the index */
65 }
66 
67 void RexxStemVariable::live(size_t liveMark)
68 /******************************************************************************/
69 /* Function: Normal garbage collection live marking */
70 /******************************************************************************/
71 {
72  memory_mark(this->stem);
73 }
74 
76 /******************************************************************************/
77 /* Function: Generalized object marking */
78 /******************************************************************************/
79 {
81 }
82 
84 /******************************************************************************/
85 /* Function: Flatten an object */
86 /******************************************************************************/
87 {
89 
90  flatten_reference(newThis->stem, envelope);
91 
93 }
94 
96  RexxActivation *context, /* current activation context */
97  RexxExpressionStack *stack ) /* evaluation stack */
98 /******************************************************************************/
99 /* Function: Evaluate a REXX stem variable */
100 /******************************************************************************/
101 {
102  /* look up the name */
103  RexxObject *value = context->getLocalStem(this->stem, this->index);
104  /* NOTE: stem accesses do NOT */
105  /* report NOVALUE so that DO OVER, */
106  /* call-by-reference with a stem and */
107  /* return with a stem does not */
108  /* trigger a novalue trap */
109  /* unexpectedly */
110  stack->push(value); /* place on the evaluation stack */
111  /* trace if necessary */
112  context->traceVariable(stem, value);
113  return value; /* return the located variable */
114 }
115 
117  RexxVariableDictionary *dictionary) /* current activation dictionary */
118 /******************************************************************************/
119 /* Function: retrieve a stem variable's value (notready condition will */
120 /* not be raised) */
121 /******************************************************************************/
122 {
123  /* look up the name */
124  return dictionary->getStem(this->stem);
125 }
126 
128  RexxActivation *context) /* current activation context */
129 /******************************************************************************/
130 /* Function: retrieve a stem variable's value (notready condition will */
131 /* not be raised) */
132 /******************************************************************************/
133 {
134  /* look up the name */
135  return context->getLocalStem(stem, index);
136 }
137 
148 {
149  return dictionary->getStem(this->stem);
150 }
151 
162 {
163  return context->getLocalStem(stem, index);
164 }
165 
167  RexxActivation *context, /* current activation context */
168  RexxObject *value ) /* new value to be assigned */
169 /******************************************************************************/
170 /* Function: Fast set of a stem variable value */
171 /******************************************************************************/
172 {
173  /* look up the name */
174  RexxVariable *variable = context->getLocalStemVariable(stem, index);
175  if (isOfClass(Stem, value))
176  { /* stem to stem assignment */
177  variable->set(value); /* overlay the reference stem object */
178  }
179  else
180  {
181  /* create a new stem object as value */
182  RexxStem *stem_table = new RexxStem (this->stem);
183  variable->set(stem_table); /* overlay the reference stem object */
184  stem_table->setValue(value); /* set the default value */
185  }
186 }
187 
188 
190  RexxVariableDictionary *dictionary, /* current activation dictionary */
191  RexxObject *value ) /* new value to be assigned */
192 /******************************************************************************/
193 /* Function: Fast set of a stem variable value */
194 /******************************************************************************/
195 {
196  /* look up the name */
197  RexxVariable *variable = dictionary->getStemVariable(this->stem);
198  if (isOfClass(Stem, value))
199  { /* stem to stem assignment */
200  variable->set(value); /* overlay the reference stem object */
201  }
202  else
203  {
204  /* create a new stem object as value */
205  RexxStem *stem_table = new RexxStem (this->stem);
206  variable->set(stem_table); /* overlay the reference stem object */
207  stem_table->setValue(value); /* set the default value */
208  }
209 }
210 
211 
213  RexxActivation *context) /* current activation context */
214 /******************************************************************************/
215 /* Function: Check the existance of a REXX stem variable */
216 /******************************************************************************/
217 {
218  /* retrieve the variable value */
219  return context->localStemVariableExists(stem, index);
220 }
221 
223  RexxActivation *context, /* current activation context */
224  RexxExpressionStack *stack, /* current evaluation stack */
225  RexxObject *value ) /* new value to assign */
226 /******************************************************************************/
227 /* Function: Assign a value to a stem variable */
228 /******************************************************************************/
229 {
230  RexxVariable *variable = context->getLocalStemVariable(stem, index);
231  if (isOfClass(Stem, value))
232  { /* stem to stem assignment */
233  variable->set(value); /* overlay the reference stem object */
234  }
235  else
236  {
237  /* create a new stem object as value */
238  RexxStem *stem_table = new RexxStem (this->stem);
239  variable->set(stem_table); /* overlay the reference stem object */
240  stem_table->setValue(value); /* set the default value */
241  }
242  // trace the assignment
243  context->traceAssignment(stem, value);
244 }
245 
247  RexxActivation *context) /* target variable dictionary */
248 /******************************************************************************/
249 /* Function: Drop a variable object */
250 /******************************************************************************/
251 {
252  /* drop the stem value */
253  context->dropLocalStem(stem, index);
254 }
255 
262 {
263  // dropping the stem name is sufficient
264  dictionary->dropStemVariable(stem);
265 }
266 
268  RexxActivation *context, /* current activation context */
269  RexxActivation *parent, /* the parent activation context */
270  RexxExpressionStack *stack) /* current evaluation stack */
271 /******************************************************************************/
272 /* Function: Expose a stem variable */
273 /******************************************************************************/
274 {
275  /* get the old variable entry */
276  RexxVariable *old_variable = parent->getLocalStemVariable(stem, index);
277 
278  /* set the entry in the new table */
279  if (index == 0)
280  {
281  context->updateLocalVariable(old_variable);
282  }
283  else
284  {
285  context->putLocalVariable(old_variable, index);
286  }
287 }
288 
289 
291  RexxActivation *context, /* current activation context */
292  RexxExpressionStack *stack, /* current evaluation stack */
293  /* variable scope we're exposing from*/
294  RexxVariableDictionary *object_dictionary)
295 /******************************************************************************/
296 /* Function: Expose a stem variable */
297 /******************************************************************************/
298 {
299  /* get the old variable entry */
300  RexxVariable *old_stem = object_dictionary->getStemVariable(stem);
301  /* set the entry in the new table */
302  context->putLocalVariable(old_stem, index);
303 }
304 
305 
307  RexxActivation *context ) /* current activation context */
308 /******************************************************************************/
309 /* Set a guard variable notification on a stem variable */
310 /******************************************************************************/
311 {
312  /* look up the name */
313  RexxVariable *variable = context->getLocalStemVariable(this->stem, this->index);
314  variable->inform(ActivityManager::currentActivity); /* mark the variable entry */
315 }
316 
318  RexxActivation *context ) /* current activation context */
319 /******************************************************************************/
320 /* Remove a guard variable notification on an object variable */
321 /******************************************************************************/
322 {
323  /* look up the name */
324  RexxVariable *variable = context->getLocalStemVariable(this->stem, this->index);
325  variable->uninform(ActivityManager::currentActivity); /* mark the variable entry */
326 }
327 
328 
330  RexxActivation *context, RexxString *prefix, int order, int type, size_t start,
331  size_t end, size_t firstcol, size_t lastcol)
332 /******************************************************************************/
333 /* Sort the elements of a stem variable as if they were an array. */
334 /******************************************************************************/
335 {
336  /* get the stem object */
337  RexxStem *stem_table = context->getLocalStem(stem, index);
338  /* the stem object handles the sorting. */
339  return stem_table->sort(prefix, order, type, start, end, firstcol, lastcol);
340 }
341 
342 void *RexxStemVariable::operator new(size_t size)
343 /******************************************************************************/
344 /* Function: Create a new translator object */
345 /******************************************************************************/
346 {
347  /* Get new object */
348  return new_object(size, T_StemVariableTerm);
349 }
350 
T_StemVariableTerm
Definition: ClassTypeCodes.h:130
RexxActivation::traceAssignment
void traceAssignment(RexxString *n, RexxObject *v)
Definition: RexxActivation.hpp:386
RexxExpressionStack
Definition: ExpressionStack.hpp:53
RexxStemVariable::assign
void assign(RexxActivation *, RexxExpressionStack *, RexxObject *)
Definition: ExpressionStem.cpp:222
RexxVariable.hpp
RexxActivation::dropLocalStem
void dropLocalStem(RexxString *name, size_t index)
Definition: RexxActivation.hpp:487
RexxVariableDictionary::getStem
RexxStem * getStem(RexxString *stemName)
Definition: RexxVariableDictionary.hpp:72
memory_mark_general
#define memory_mark_general(oref)
Definition: RexxMemory.hpp:437
RexxActivation.hpp
type
int type
Definition: cmdparse.cpp:1965
OrefSet
#define OrefSet(o, r, v)
Definition: RexxCore.h:94
RexxStemVariable::clearGuard
void clearGuard(RexxActivation *)
Definition: ExpressionStem.cpp:317
RexxActivation::updateLocalVariable
void updateLocalVariable(RexxVariable *variable)
Definition: RexxActivation.hpp:515
RexxStemVariable::liveGeneral
void liveGeneral(int reason)
Definition: ExpressionStem.cpp:75
RexxStemVariable::drop
void drop(RexxActivation *)
Definition: ExpressionStem.cpp:246
RexxVariableDictionary
Definition: RexxVariableDictionary.hpp:55
RexxStemVariable::getRealValue
RexxObject * getRealValue(RexxVariableDictionary *)
Definition: ExpressionStem.cpp:147
RexxEnvelope
Definition: RexxEnvelope.hpp:53
isOfClass
#define isOfClass(t, r)
Definition: RexxCore.h:211
RexxStemVariable::getValue
RexxObject * getValue(RexxVariableDictionary *)
Definition: ExpressionStem.cpp:116
RexxStemVariable::sort
bool sort(RexxActivation *context, RexxString *prefix, int order, int type, size_t start, size_t end, size_t firstcol, size_t lastcol)
Definition: ExpressionStem.cpp:329
ExpressionStem.hpp
RexxStem
Definition: StemClass.hpp:70
RexxStemVariable::exists
bool exists(RexxActivation *)
Definition: ExpressionStem.cpp:212
RexxStemVariable::set
void set(RexxActivation *, RexxObject *)
Definition: ExpressionStem.cpp:166
RexxStemVariable::index
size_t index
Definition: ExpressionStem.hpp:80
RexxVariableDictionary::getStemVariable
RexxVariable * getStemVariable(RexxString *stemName)
Definition: RexxVariableDictionary.hpp:94
RexxStemVariable::flatten
void flatten(RexxEnvelope *)
Definition: ExpressionStem.cpp:83
RexxStemVariable::expose
void expose(RexxActivation *, RexxExpressionStack *, RexxVariableDictionary *)
Definition: ExpressionStem.cpp:290
flatten_reference
#define flatten_reference(oref, envel)
Definition: RexxMemory.hpp:440
RexxStem::sort
bool sort(RexxString *prefix, int order, int type, size_t start, size_t end, size_t firstcol, size_t lastcol)
Definition: StemClass.cpp:1416
cleanUpFlatten
#define cleanUpFlatten
Definition: RexxMemory.hpp:432
StringClass.hpp
RexxActivation::traceVariable
void traceVariable(RexxString *n, RexxObject *v)
Definition: RexxActivation.hpp:374
RexxVariable::set
void set(RexxObject *value)
Definition: RexxVariable.hpp:67
RexxExpressionStack::push
void push(RexxObject *value)
Definition: ExpressionStack.hpp:77
RexxActivation::getLocalStem
RexxStem * getLocalStem(RexxString *name, size_t index)
Definition: RexxActivation.hpp:482
memory_mark
#define memory_mark(oref)
Definition: RexxMemory.hpp:436
RexxStemVariable::live
void live(size_t)
Definition: ExpressionStem.cpp:67
RexxVariableDictionary::dropStemVariable
void dropStemVariable(RexxString *)
Definition: RexxVariableDictionary.cpp:135
RexxStemVariable::stem
RexxString * stem
Definition: ExpressionStem.hpp:77
RexxActivation
Definition: RexxActivation.hpp:156
StemClass.hpp
RexxStemVariable::setGuard
void setGuard(RexxActivation *)
Definition: ExpressionStem.cpp:306
RexxActivation::localStemVariableExists
bool localStemVariableExists(RexxString *stemName, size_t index)
Definition: RexxActivation.hpp:494
setUpFlatten
#define setUpFlatten(type)
Definition: RexxMemory.hpp:427
ActivityManager::currentActivity
static RexxActivity *volatile currentActivity
Definition: ActivityManager.hpp:95
RexxActivation::getLocalStemVariable
RexxVariable * getLocalStemVariable(RexxString *name, size_t index)
Definition: RexxActivation.hpp:473
RexxStemVariable::evaluate
RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
Definition: ExpressionStem.cpp:95
RexxStem::setValue
void setValue(RexxObject *value)
Definition: StemClass.cpp:153
RexxCore.h
RexxVariable::uninform
void uninform(RexxActivity *)
Definition: RexxVariable.cpp:98
new_object
RexxObject * new_object(size_t s)
Definition: RexxMemory.hpp:422
RexxVariable::inform
void inform(RexxActivity *)
Definition: RexxVariable.cpp:83
RexxStemVariable
Definition: ExpressionStem.hpp:49
RexxActivation::putLocalVariable
void putLocalVariable(RexxVariable *variable, size_t index)
Definition: RexxActivation.hpp:510
RexxVariableDictionary.hpp
RexxStemVariable::procedureExpose
void procedureExpose(RexxActivation *, RexxActivation *, RexxExpressionStack *)
Definition: ExpressionStem.cpp:267
RexxObject
Definition: ObjectClass.hpp:311
RexxStemVariable::RexxStemVariable
RexxStemVariable(RESTORETYPE restoreType)
Definition: ExpressionStem.hpp:56
RexxString
Definition: StringClass.hpp:119
RexxVariable
Definition: RexxVariable.hpp:49