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)  

ExpressionVariable.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 ExpressionVariable.cpp */
40 /* */
41 /* Primitive Translator Expression Parsing Variable Reference Class */
42 /* */
43 /******************************************************************************/
44 #include <stdlib.h>
45 #include "RexxCore.h"
46 #include "StringClass.hpp"
47 #include "RexxActivation.hpp"
48 #include "RexxActivity.hpp"
50 #include "RexxVariable.hpp"
51 #include "ExpressionVariable.hpp"
52 
54  RexxString *variable_name, /* variable name to access */
55  size_t var_index) /* dictionary lookaside index */
56 /******************************************************************************/
57 /* Complete initialization of a variable object */
58 /******************************************************************************/
59 {
60  /* set the name value */
61  OrefSet(this, this->variableName, variable_name);
62  this->index = var_index; /* save the index */
63 }
64 
65 void RexxParseVariable::live(size_t liveMark)
66 /******************************************************************************/
67 /* Function: Normal garbage collection live marking */
68 /******************************************************************************/
69 {
71 }
72 
74 /******************************************************************************/
75 /* Function: Generalized object marking */
76 /******************************************************************************/
77 {
79 }
80 
82 /******************************************************************************/
83 /* Function: Flatten an object */
84 /******************************************************************************/
85 {
87 
88  flatten_reference(newThis->variableName, envelope);
89 
91 }
92 
94  RexxActivation *context, /* current activation context */
95  RexxExpressionStack *stack ) /* evaluation stack */
96 /******************************************************************************/
97 /* Function: Evaluate a REXX simple variable */
98 /******************************************************************************/
99 {
100  /* look up the name */
101  RexxVariable *variable = context->getLocalVariable(variableName, index);
102  RexxObject *value = variable->getVariableValue();/* get the value */
103  if (value == OREF_NULL) /* no value yet? */
104  {
105  // try the various novalue mechanisms
106  value = context->handleNovalueEvent(variableName, variableName, variable);
107  }
108  stack->push(value); /* place on the evaluation stack */
109  /* trace if necessary */
110  context->traceVariable(variableName, value);
111  return value; /* return the located variable */
112 }
113 
115  RexxVariableDictionary *dictionary)/* current activation dictionary */
116 /******************************************************************************/
117 /* Function: retrieve a simple variable's value (notready condition will */
118 /* not be raised) */
119 /******************************************************************************/
120 {
121  /* look up the name */
122  RexxVariable *variable = dictionary->getVariable(variableName);
123  RexxObject *value = variable->getVariableValue();/* get the value */
124  if (value == OREF_NULL) /* no value yet? */
125  {
126  value = this->variableName; /* just use the name */
127  }
128  return value; /* return the located variable */
129 }
130 
132  RexxActivation *context) /* current activation context */
133 /******************************************************************************/
134 /* Function: retrieve a simple variable's value (notready condition will */
135 /* not be raised) */
136 /******************************************************************************/
137 {
138  /* look up the name */
139  RexxVariable *variable = context->getLocalVariable(variableName, index);
140  RexxObject *value = variable->getVariableValue();/* get the value */
141  if (value == OREF_NULL) /* no value yet? */
142  {
143  value = this->variableName; /* just use the name */
144  }
145  return value; /* return the located variable */
146 }
147 
158 {
159  /* look up the name */
160  RexxVariable *variable = dictionary->getVariable(variableName);
161  return variable->getVariableValue();/* get the value */
162 }
163 
164 
176 {
177  RexxVariable *variable = context->getLocalVariable(variableName, index);
178  return variable->getVariableValue();/* get the value */
179 }
180 
182  RexxVariableDictionary *dictionary, /* current activation dictionary */
183  RexxObject *value )
184 /******************************************************************************/
185 /* Function: Fast set of a variable value */
186 /******************************************************************************/
187 {
188  /* look up the name */
189  RexxVariable *variable = dictionary->getVariable(variableName);
190  variable->set(value); /* and perform the set */
191 }
192 
194  RexxActivation *context, /* current activation context */
195  RexxObject *value )
196 /******************************************************************************/
197 /* Function: Fast set of a variable value */
198 /******************************************************************************/
199 {
200  /* The context handles the details of this */
201  context->setLocalVariable(variableName, index, value);
202 }
203 
205  RexxActivation *context) /* current activation context */
206 /******************************************************************************/
207 /* Function: Check the existance of a REXX variable */
208 /******************************************************************************/
209 {
210  return context->localVariableExists(variableName, index);
211 }
212 
214  RexxActivation *context, /* current activation context */
215  RexxExpressionStack *stack, /* current evaluation stack */
216  RexxObject *value ) /* new value to assign */
217 /******************************************************************************/
218 /* Function: Assign a value to a simple variable */
219 /******************************************************************************/
220 {
221  /* The context handles the details of this */
222  context->setLocalVariable(variableName, index, value);
223  context->traceAssignment(variableName, value);
224 }
225 
227  RexxActivation *context) /* target variable dictionary */
228 /******************************************************************************/
229 /* Function: Drop a variable object */
230 /******************************************************************************/
231 {
232  /* drop the variable value */
234 }
235 
242 {
243  /* look up the name */
244  RexxVariable *variable = dictionary->getVariable(variableName);
245  variable->drop(); /* and perform the set */
246 }
247 
249  RexxActivation *context ) /* current activation context */
250 /******************************************************************************/
251 /* Set a guard variable notification on an object variable */
252 /******************************************************************************/
253 {
254  /* look up the name */
255  RexxVariable *variable = context->getLocalVariable(variableName, index);
256  variable->inform(ActivityManager::currentActivity); /* mark the variable entry */
257 }
258 
260  RexxActivation *context ) /* current activation context */
261 /******************************************************************************/
262 /* Remove a guard variable notification on an object variable */
263 /******************************************************************************/
264 {
265  /* look up the name */
266  RexxVariable *variable = context->getLocalVariable(variableName, index);
267  variable->uninform(ActivityManager::currentActivity); /* remove the notification */
268 }
269 
271  RexxActivation *context, /* current activation context */
272  RexxActivation *parent, /* the parent activation context */
273  RexxExpressionStack *stack) /* current evaluation stack */
274 /******************************************************************************/
275 /* Function: Expose a variable */
276 /******************************************************************************/
277 {
278  /* get the old variable entry */
279  RexxVariable *old_variable = parent->getLocalVariable(variableName, index);
280  /* set the entry in the new table */
281  context->putLocalVariable(old_variable, index);
282 }
283 
284 
286  RexxActivation *context, /* current activation context */
287  RexxExpressionStack *stack, /* current evaluation stack */
288  /* variable scope we're exposing from*/
289  RexxVariableDictionary *object_dictionary)
290 /******************************************************************************/
291 /* Function: Expose a variable */
292 /******************************************************************************/
293 {
294  /* get the old variable entry */
295  RexxVariable *old_variable = object_dictionary->getVariable(variableName);
296  /* set the entry in the new table */
297  context->putLocalVariable(old_variable, index);
298 }
299 
306 {
307  return variableName;
308 }
309 
310 
311 void *RexxParseVariable::operator new(size_t size)
312 /******************************************************************************/
313 /* Function: Create a REXX variable translator object */
314 /******************************************************************************/
315 {
316  return new_object(size, T_VariableTerm); /* Get new object */
317 }
318 
RexxActivation::traceAssignment
void traceAssignment(RexxString *n, RexxObject *v)
Definition: RexxActivation.hpp:386
RexxExpressionStack
Definition: ExpressionStack.hpp:53
RexxVariable.hpp
memory_mark_general
#define memory_mark_general(oref)
Definition: RexxMemory.hpp:437
RexxActivation.hpp
OrefSet
#define OrefSet(o, r, v)
Definition: RexxCore.h:94
RexxVariableDictionary::getVariable
RexxVariable * getVariable(RexxString *name)
Definition: RexxVariableDictionary.hpp:81
RexxParseVariable::set
void set(RexxActivation *, RexxObject *)
Definition: ExpressionVariable.cpp:193
RexxVariableDictionary
Definition: RexxVariableDictionary.hpp:55
RexxParseVariable::drop
void drop(RexxActivation *)
Definition: ExpressionVariable.cpp:226
RexxParseVariable::assign
void assign(RexxActivation *, RexxExpressionStack *, RexxObject *)
Definition: ExpressionVariable.cpp:213
RexxEnvelope
Definition: RexxEnvelope.hpp:53
RexxParseVariable::getValue
RexxObject * getValue(RexxVariableDictionary *)
Definition: ExpressionVariable.cpp:114
RexxParseVariable
Definition: ExpressionVariable.hpp:49
RexxParseVariable::getRealValue
RexxObject * getRealValue(RexxVariableDictionary *)
Definition: ExpressionVariable.cpp:157
RexxParseVariable::live
void live(size_t)
Definition: ExpressionVariable.cpp:65
RexxParseVariable::RexxParseVariable
RexxParseVariable(RESTORETYPE restoreType)
Definition: ExpressionVariable.hpp:56
OREF_NULL
#define OREF_NULL
Definition: RexxCore.h:60
flatten_reference
#define flatten_reference(oref, envel)
Definition: RexxMemory.hpp:440
cleanUpFlatten
#define cleanUpFlatten
Definition: RexxMemory.hpp:432
ExpressionVariable.hpp
RexxActivation::setLocalVariable
void setLocalVariable(RexxString *name, size_t index, RexxObject *value)
Definition: RexxActivation.hpp:520
StringClass.hpp
RexxParseVariable::variableName
RexxString * variableName
Definition: ExpressionVariable.hpp:80
RexxActivation::traceVariable
void traceVariable(RexxString *n, RexxObject *v)
Definition: RexxActivation.hpp:374
RexxVariable::set
void set(RexxObject *value)
Definition: RexxVariable.hpp:67
RexxParseVariable::exists
bool exists(RexxActivation *)
Definition: ExpressionVariable.cpp:204
RexxExpressionStack::push
void push(RexxObject *value)
Definition: ExpressionStack.hpp:77
memory_mark
#define memory_mark(oref)
Definition: RexxMemory.hpp:436
RexxParseVariable::liveGeneral
void liveGeneral(int reason)
Definition: ExpressionVariable.cpp:73
RexxActivation::localVariableExists
bool localVariableExists(RexxString *name, size_t index)
Definition: RexxActivation.hpp:502
RexxActivation::dropLocalVariable
void dropLocalVariable(RexxString *name, size_t index)
Definition: RexxActivation.hpp:526
RexxActivation::handleNovalueEvent
RexxObject * handleNovalueEvent(RexxString *name, RexxObject *defaultValue, RexxVariable *variable)
Definition: RexxActivation.cpp:2250
RexxActivation
Definition: RexxActivation.hpp:156
RexxParseVariable::flatten
void flatten(RexxEnvelope *)
Definition: ExpressionVariable.cpp:81
RexxParseVariable::procedureExpose
void procedureExpose(RexxActivation *, RexxActivation *, RexxExpressionStack *)
Definition: ExpressionVariable.cpp:270
setUpFlatten
#define setUpFlatten(type)
Definition: RexxMemory.hpp:427
ActivityManager::currentActivity
static RexxActivity *volatile currentActivity
Definition: ActivityManager.hpp:95
RexxParseVariable::expose
void expose(RexxActivation *, RexxExpressionStack *, RexxVariableDictionary *)
Definition: ExpressionVariable.cpp:285
RexxParseVariable::evaluate
RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
Definition: ExpressionVariable.cpp:93
RexxParseVariable::clearGuard
void clearGuard(RexxActivation *)
Definition: ExpressionVariable.cpp:259
RexxActivity.hpp
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
RexxParseVariable::getName
RexxString * getName()
Definition: ExpressionVariable.cpp:305
RexxParseVariable::setGuard
void setGuard(RexxActivation *)
Definition: ExpressionVariable.cpp:248
T_VariableTerm
Definition: ClassTypeCodes.h:128
RexxActivation::putLocalVariable
void putLocalVariable(RexxVariable *variable, size_t index)
Definition: RexxActivation.hpp:510
RexxActivation::getLocalVariable
RexxVariable * getLocalVariable(RexxString *name, size_t index)
Definition: RexxActivation.hpp:464
RexxVariableDictionary.hpp
RexxVariable::getVariableValue
RexxObject * getVariableValue()
Definition: RexxVariable.hpp:72
RexxParseVariable::index
size_t index
Definition: ExpressionVariable.hpp:81
RexxObject
Definition: ObjectClass.hpp:311
RexxVariable::drop
void drop()
Definition: RexxVariable.cpp:113
RexxString
Definition: StringClass.hpp:119
RexxVariable
Definition: RexxVariable.hpp:49