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)  

ExpressionCompoundVariable.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 Translator Expression Parsing Compound Variable Reference Class */
42 /* */
43 /******************************************************************************/
44 #include <stdlib.h>
45 #include "RexxCore.h"
46 #include "StringClass.hpp"
47 #include "QueueClass.hpp"
48 #include "StemClass.hpp"
50 #include "RexxActivation.hpp"
51 #include "RexxActivity.hpp"
53 #include "ExpressionVariable.hpp"
54 #include "RexxVariable.hpp"
55 #include "ProtectedObject.hpp"
56 #include "RexxCompoundTail.hpp"
57 
59  RexxString * _stemName, /* stem retriever */
60  size_t stemIndex, /* stem lookaside index */
61  RexxQueue * tailList, /* list of tails */
62  size_t TailCount) /* count of tails */
63 /******************************************************************************/
64 /* Function: Complete compound variable initialization */
65 /******************************************************************************/
66 {
67  this->tailCount= TailCount; /* set the count (and hash value) */
68  OrefSet(this, this->stemName, _stemName); /* save the associate value */
69  this->index = stemIndex; /* set the stem index */
70 
71  while (TailCount > 0) /* loop through the variable list */
72  {
73  /* copying each variable */
74  OrefSet(this, this->tails[--TailCount], tailList->pop());
75  }
76 }
77 
79  RexxString * variable_name, /* full variable name of compound */
80  bool direct ) /* this is direct access */
81 /******************************************************************************/
82 /* Function: Build a dynamically created compound variable */
83 /******************************************************************************/
84 {
85  RexxString * stem; /* stem part of compound variable */
86  RexxString * tail; /* tail section string value */
87  RexxQueue * tails; /* tail elements */
88  RexxObject * tailPart; /* tail element retriever */
89  size_t position; /* scan position within compound name*/
90  size_t start; /* starting scan position */
91  size_t length; /* length of tail section */
92 
93  length = variable_name->getLength(); /* get the string length */
94  position = 0; /* start scanning at first character */
95  /* scan to the first period */
96  while (variable_name->getChar(position) != '.')
97  {
98  position++; /* step to the next character */
99  length--; /* reduce the length also */
100  }
101  /* extract the stem part */
102  stem = variable_name->extract(0, position + 1);
103  ProtectedObject p1(stem);
104  /* processing to decompose the name */
105  /* into its component parts */
106 
107  tails = new_queue(); /* get a new list for the tails */
108  ProtectedObject p2(tails);
109  position++; /* step past previous period */
110  length--; /* adjust the length */
111  if (direct == true) /* direct access? */
112  {
113  /* extract the tail part */
114  tail = variable_name->extract(position, length);
115  tails->push(tail); /* add to the tail piece list */
116  }
117  else
118  {
119  while (length > 0) /* process rest of the variable */
120  {
121  start = position; /* save the start position */
122  /* scan for the next period */
123  while (length > 0 && variable_name->getChar(position) != '.')
124  {
125  position++; /* step to the next character */
126  length--; /* reduce the length also */
127  }
128  /* extract the tail part */
129  tail = variable_name->extract(start, position - start);
130  /* have a null tail piece or */
131  /* section begin with a digit? */
132  /* CHM - defect 87: change index start to 0 and compare for range */
133  /* ASCII '0' to '9' to recognize a digit */
134  if (tail->getLength() == 0 || (tail->getChar(0) >= '0' && tail->getChar(0) <= '9'))
135  {
136  tailPart = (RexxObject *)tail; /* this is a literal piece */
137  }
138  else
139  {
140  /* create a new variable retriever */
141  tailPart = (RexxObject *)new RexxParseVariable(tail, 0);
142  }
143  tails->push(tailPart); /* add to the tail piece list */
144  position++; /* step past previous period */
145  length--; /* adjust the length */
146  }
147  /* have a trailing period? */
148  if (variable_name->getChar(position - 1) == '.')
149  {
150  tails->push(OREF_NULLSTRING); /* add to the tail piece list */
151  }
152  }
153  /* create and return a new compound */
154  return(RexxObject *)new (tails->getSize()) RexxCompoundVariable(stem, 0, tails, tails->getSize());
155 }
156 
157 void RexxCompoundVariable::live(size_t liveMark)
158 /******************************************************************************/
159 /* Function: Normal garbage collection live marking */
160 /******************************************************************************/
161 {
162  size_t i; /* loop counter */
163  size_t count; /* argument count */
164 
165  for (i = 0, count = this->tailCount; i < count; i++)
166  {
167  memory_mark(this->tails[i]);
168  }
169  memory_mark(this->stemName);
170 }
171 
173 /******************************************************************************/
174 /* Function: Generalized object marking */
175 /******************************************************************************/
176 {
177  size_t i; /* loop counter */
178  size_t count; /* argument count */
179 
180  for (i = 0, count = this->tailCount; i < count; i++)
181  {
182  memory_mark_general(this->tails[i]);
183  }
185 }
186 
188 /******************************************************************************/
189 /* Function: Flatten an object */
190 /******************************************************************************/
191 {
192  size_t i; /* loop counter */
193  size_t count; /* argument count */
194 
196 
197  flatten_reference(newThis->stemName, envelope);
198  for (i = 0, count = this->tailCount; i < count; i++)
199  {
200  flatten_reference(newThis->tails[i], envelope);
201  }
202 
204 }
205 
207  RexxActivation *context, /* current activation context */
208  RexxExpressionStack *stack ) /* evaluation stack */
209 /******************************************************************************/
210 /* Function: Evaluate a REXX compound variable */
211 /******************************************************************************/
212 {
213  /* and ask it for the value */
215 
216  stack->push(value); /* place on the evaluation stack */
217  return value; /* return the located variable */
218 }
219 
221  RexxVariableDictionary *dictionary) /* current activation dictionary */
222 /******************************************************************************/
223 /* Function: Direct value retrieve of a compound variable */
224 /******************************************************************************/
225 {
226  /* resolve the tail element */
227  return dictionary->getCompoundVariableValue(stemName, &tails[0], tailCount);
228 }
229 
231  RexxActivation *context) /* current activation dictionary */
232 /******************************************************************************/
233 /* Function: Direct value retrieve of a compound variable */
234 /******************************************************************************/
235 {
236  /* resolve the tail element */
238 }
239 
250 {
251  /* resolve the tail element */
252  return dictionary->getCompoundVariableRealValue(stemName, &tails[0], tailCount);
253 }
254 
255 
267 {
268  /* resolve the tail element */
270 }
271 
272 
274  RexxActivation *context, /* current activation context */
275  RexxObject *value ) /* new value to assign */
276 /******************************************************************************/
277 /* Function: Assign a new value to a compound variable */
278 /******************************************************************************/
279 {
280  /* the dictionary manages all of these details */
281  context->setLocalCompoundVariable(stemName, index, &tails[0], tailCount, value);
282 }
283 
284 
286  RexxVariableDictionary *dictionary, /* an object variable dictionary */
287  RexxObject *value ) /* new value to assign */
288 /******************************************************************************/
289 /* Function: Assign a new value to a compound variable */
290 /******************************************************************************/
291 {
292  /* the dictionary manages all of these details */
293  dictionary->setCompoundVariable(stemName, &tails[0], tailCount, value);
294 }
295 
296 
298  RexxActivation *context) /* current execution context */
299 /******************************************************************************/
300 /* Function: Check to see if a compound variable exists in a directory */
301 /******************************************************************************/
302 {
303  /* retrieve the variable value, and */
304  /* see it really exists */
305  return context->localCompoundVariableExists(stemName, index, &tails[0], tailCount);
306 }
307 
309  RexxActivation *context, /* current activation context */
310  RexxExpressionStack *stack, /* current evaluation stack */
311  RexxObject *value ) /* new value to assign */
312 /******************************************************************************/
313 /* Function: Assign a value to a compound variable */
314 /******************************************************************************/
315 {
316  /* the context manages the assignment details */
318 }
319 
321  RexxActivation *context) /* current activation context */
322 /******************************************************************************/
323 /* Function: Drop a compound variable */
324 /******************************************************************************/
325 {
326  /* set the compound value */
328 }
329 
336 {
337  /* the dictionary manages all of these details */
338  dictionary->dropCompoundVariable(stemName, &tails[0], tailCount);
339 }
340 
341 
343  RexxActivation *context, /* current activation context */
344  RexxActivation *parent, /* the parent activation context */
345  RexxExpressionStack *stack) /* current evaluation stack */
346 /******************************************************************************/
347 /* Function: Expose a compound variable */
348 /******************************************************************************/
349 {
350  /* first get (and possible create) the compound variable in the */
351  /* parent context. */
353  /* get the stem index from the current level. This may end up */
354  /* creating the stem that holds the exposed value. */
355  RexxStem *stem_table = context->getLocalStem(stemName, index);
356  /* have the stem expose this */
357  stem_table->expose(variable);
358  /* trace resolved compound name */
359  context->traceCompoundName(stemName, (RexxObject **)&tails[0], tailCount, variable->getName());
360 }
361 
362 
364  RexxActivation *context, /* current activation context */
365  RexxExpressionStack *stack, /* current evaluation stack */
366  /* variable scope we're exposing from*/
367  RexxVariableDictionary *object_dictionary)
368 /******************************************************************************/
369 /* Function: Expose a compound variable */
370 /******************************************************************************/
371 {
372  /* get the stem in the source dictionary */
373  RexxStem *source_stem = object_dictionary->getStem(stemName);
374  /* new tail for compound */
375  RexxCompoundTail resolved_tail(context, &tails[0], tailCount);
376  /* first get (and possible create) the compound variable in the */
377  /* object context. */
378  RexxCompoundElement *variable = source_stem->exposeCompoundVariable(&resolved_tail);
379  /* get the stem index from the current level. This may end up */
380  /* creating the stem that holds the exposed value. */
381  RexxStem *stem_table = context->getLocalStem(stemName, index);
382  /* have the stem expose this */
383  stem_table->expose(variable);
384  /* tracing intermediate values? */
385  if (context->tracingIntermediates()) {
386  /* trace resolved compound name */
387  context->traceCompoundName(stemName, (RexxObject **)&tails[0], tailCount, variable->getName());
388  }
389 }
390 
391 
393  RexxActivation *context ) /* current activation context */
394 /******************************************************************************/
395 /* Function: Set a guard wait in a compound variable */
396 /******************************************************************************/
397 {
398  /* get the variable item */
400  variable->inform(ActivityManager::currentActivity); /* mark the variable entry */
401 }
402 
404  RexxActivation *context ) /* current activation context */
405 /******************************************************************************/
406 /* Function: Clear a guard wait on a compound variable */
407 /******************************************************************************/
408 {
409  /* get the variable item */
411  variable->uninform(ActivityManager::currentActivity); /* mark the variable entry */
412 }
413 
414 void * RexxCompoundVariable::operator new(size_t size,
415  size_t tailCount) /* count of tails */
416 /******************************************************************************/
417 /* Function: Create a new compound variable object */
418 /******************************************************************************/
419 {
420  if (tailCount == 0)
421  {
422  // this object is normal sized, minus the dummy tail element
423  return new_object(size - sizeof(RexxObject *), T_CompoundVariableTerm);
424  }
425  else
426  {
427  /* Get new object */
428  return new_object(size + ((tailCount - 1) * sizeof(RexxObject *)), T_CompoundVariableTerm);
429  }
430 }
431 
RexxExpressionStack
Definition: ExpressionStack.hpp:53
RexxCompoundElement
Definition: RexxCompoundElement.hpp:50
RexxCompoundVariable::getRealValue
RexxObject * getRealValue(RexxVariableDictionary *)
Definition: ExpressionCompoundVariable.cpp:249
RexxVariable.hpp
RexxActivation::getLocalCompoundVariableValue
RexxObject * getLocalCompoundVariableValue(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount)
Definition: RexxActivation.cpp:4163
RexxActivation::getLocalCompoundVariable
RexxCompoundElement * getLocalCompoundVariable(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount)
Definition: RexxActivation.cpp:4183
RexxVariableDictionary::getStem
RexxStem * getStem(RexxString *stemName)
Definition: RexxVariableDictionary.hpp:72
RexxActivation::setLocalCompoundVariable
void setLocalCompoundVariable(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount, RexxObject *value)
Definition: RexxActivation.cpp:4231
RexxCompoundVariable::procedureExpose
void procedureExpose(RexxActivation *, RexxActivation *, RexxExpressionStack *)
Definition: ExpressionCompoundVariable.cpp:342
RexxActivation::localCompoundVariableExists
bool localCompoundVariableExists(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount)
Definition: RexxActivation.cpp:4203
memory_mark_general
#define memory_mark_general(oref)
Definition: RexxMemory.hpp:437
RexxQueue
Definition: QueueClass.hpp:49
RexxActivation.hpp
OrefSet
#define OrefSet(o, r, v)
Definition: RexxCore.h:94
RexxCompoundVariable::assign
void assign(RexxActivation *, RexxExpressionStack *, RexxObject *)
Definition: ExpressionCompoundVariable.cpp:308
RexxCompoundVariable::setGuard
void setGuard(RexxActivation *)
Definition: ExpressionCompoundVariable.cpp:392
ExpressionCompoundVariable.hpp
RexxCompoundVariable::tails
RexxObject * tails[1]
Definition: ExpressionCompoundVariable.hpp:86
RexxString::getLength
size_t getLength()
Definition: StringClass.hpp:330
RexxQueue::pop
RexxObject * pop()
Definition: QueueClass.hpp:80
RexxVariableDictionary::getCompoundVariableValue
RexxObject * getCompoundVariableValue(RexxString *stemName, RexxObject **tail, size_t tailCount)
Definition: RexxVariableDictionary.cpp:166
RexxCompoundVariable::RexxCompoundVariable
RexxCompoundVariable(RexxString *, size_t, RexxQueue *, size_t)
Definition: ExpressionCompoundVariable.cpp:58
RexxStem::exposeCompoundVariable
RexxCompoundElement * exposeCompoundVariable(RexxCompoundTail *name)
Definition: StemClass.cpp:552
RexxVariableDictionary
Definition: RexxVariableDictionary.hpp:55
RexxVariable::getName
RexxString * getName()
Definition: RexxVariable.hpp:74
RexxActivation::assignLocalCompoundVariable
void assignLocalCompoundVariable(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount, RexxObject *value)
Definition: RexxActivation.cpp:4213
RexxCompoundVariable::set
void set(RexxActivation *, RexxObject *)
Definition: ExpressionCompoundVariable.cpp:273
RexxCompoundVariable::index
size_t index
Definition: ExpressionCompoundVariable.hpp:84
RexxString::getChar
char getChar(size_t p)
Definition: StringClass.hpp:338
RexxEnvelope
Definition: RexxEnvelope.hpp:53
new_queue
RexxQueue * new_queue()
Definition: QueueClass.hpp:89
RexxCompoundVariable::evaluate
RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
Definition: ExpressionCompoundVariable.cpp:206
RexxParseVariable
Definition: ExpressionVariable.hpp:49
RexxActivation::tracingIntermediates
bool tracingIntermediates()
Definition: RexxActivation.hpp:348
RexxCompoundTail.hpp
RexxStem
Definition: StemClass.hpp:70
RexxCompoundVariable::expose
void expose(RexxActivation *, RexxExpressionStack *, RexxVariableDictionary *)
Definition: ExpressionCompoundVariable.cpp:363
ProtectedObject.hpp
RexxVariableDictionary::setCompoundVariable
void setCompoundVariable(RexxString *stemName, RexxObject **tail, size_t tailCount, RexxObject *value)
Definition: RexxVariableDictionary.cpp:557
RexxCompoundVariable::getValue
RexxObject * getValue(RexxActivation *context)
Definition: ExpressionCompoundVariable.cpp:230
flatten_reference
#define flatten_reference(oref, envel)
Definition: RexxMemory.hpp:440
cleanUpFlatten
#define cleanUpFlatten
Definition: RexxMemory.hpp:432
ExpressionVariable.hpp
ProtectedObject
Definition: ProtectedObject.hpp:46
StringClass.hpp
RexxActivation::traceCompoundName
void traceCompoundName(RexxString *stemVar, RexxObject **tails, size_t tailCount, RexxCompoundTail *tail)
Definition: RexxActivation.hpp:388
RexxExpressionStack::push
void push(RexxObject *value)
Definition: ExpressionStack.hpp:77
RexxActivation::getLocalStem
RexxStem * getLocalStem(RexxString *name, size_t index)
Definition: RexxActivation.hpp:482
RexxString::extract
RexxString * extract(size_t offset, size_t sublength)
Definition: StringClass.hpp:229
build
RexxObject * build(RexxString *variable_name, bool direct)
Definition: ExpressionCompoundVariable.cpp:78
RexxQueue::push
void push(RexxObject *obj)
Definition: QueueClass.hpp:81
memory_mark
#define memory_mark(oref)
Definition: RexxMemory.hpp:436
RexxCompoundVariable::drop
void drop(RexxActivation *)
Definition: ExpressionCompoundVariable.cpp:320
RexxActivation::getLocalCompoundVariableRealValue
RexxObject * getLocalCompoundVariableRealValue(RexxString *localstem, size_t index, RexxObject **tail, size_t tailCount)
Definition: RexxActivation.cpp:4173
T_CompoundVariableTerm
Definition: ClassTypeCodes.h:129
RexxCompoundVariable::clearGuard
void clearGuard(RexxActivation *)
Definition: ExpressionCompoundVariable.cpp:403
RexxActivation
Definition: RexxActivation.hpp:156
RexxCompoundVariable::live
void live(size_t)
Definition: ExpressionCompoundVariable.cpp:157
StemClass.hpp
RexxCompoundVariable::liveGeneral
void liveGeneral(int reason)
Definition: ExpressionCompoundVariable.cpp:172
RexxCompoundVariable::stemName
RexxString * stemName
Definition: ExpressionCompoundVariable.hpp:81
QueueClass.hpp
RexxActivation::evaluateLocalCompoundVariable
RexxObject * evaluateLocalCompoundVariable(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount)
Definition: RexxActivation.cpp:4145
setUpFlatten
#define setUpFlatten(type)
Definition: RexxMemory.hpp:427
RexxCompoundVariable
Definition: ExpressionCompoundVariable.hpp:53
ActivityManager::currentActivity
static RexxActivity *volatile currentActivity
Definition: ActivityManager.hpp:95
RexxCompoundVariable::flatten
void flatten(RexxEnvelope *)
Definition: ExpressionCompoundVariable.cpp:187
RexxVariableDictionary::dropCompoundVariable
void dropCompoundVariable(RexxString *stemName, RexxObject **tail, size_t tailCount)
Definition: RexxVariableDictionary.cpp:576
RexxList::getSize
size_t getSize()
Definition: ListClass.hpp:126
RexxActivity.hpp
RexxStem::expose
void expose(RexxCompoundElement *variable)
Definition: StemClass.cpp:854
RexxActivation::dropLocalCompoundVariable
void dropLocalCompoundVariable(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount)
Definition: RexxActivation.cpp:4242
RexxVariableDictionary::getCompoundVariableRealValue
RexxObject * getCompoundVariableRealValue(RexxString *stem, RexxObject **tail, size_t tailCount)
Definition: RexxVariableDictionary.cpp:197
RexxCore.h
RexxVariable::uninform
void uninform(RexxActivity *)
Definition: RexxVariable.cpp:98
RexxCompoundTail
Definition: RexxCompoundTail.hpp:52
RexxCompoundVariable::exists
bool exists(RexxActivation *)
Definition: ExpressionCompoundVariable.cpp:297
new_object
RexxObject * new_object(size_t s)
Definition: RexxMemory.hpp:422
RexxVariable::inform
void inform(RexxActivity *)
Definition: RexxVariable.cpp:83
RexxCompoundVariable::tailCount
size_t tailCount
Definition: ExpressionCompoundVariable.hpp:85
RexxVariableDictionary.hpp
RexxActivation::exposeLocalCompoundVariable
RexxCompoundElement * exposeLocalCompoundVariable(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount)
Definition: RexxActivation.cpp:4193
RexxObject
Definition: ObjectClass.hpp:311
RexxString
Definition: StringClass.hpp:119