IndirectVariableReference.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 IndirectVariableReference.cpp */
40 /* */
41 /* Primitive Translator Expression Parsing Variable Indirect Reference Class */
42 /* */
43 /******************************************************************************/
44 #include <stdlib.h>
45 #include "RexxCore.h"
46 #include "StringClass.hpp"
47 #include "ArrayClass.hpp"
48 #include "RexxActivation.hpp"
49 #include "RexxActivity.hpp"
52 
54  RexxVariableBase *variable) /* variable retriever for reference */
55 /******************************************************************************/
56 /* Function: Complete initialization of a variable reference object */
57 /******************************************************************************/
58 {
59  /* set the name value */
60  OrefSet(this, this->variableObject, variable);
61 }
62 
63 void RexxVariableReference::live(size_t liveMark)
64 /******************************************************************************/
65 /* Function: Normal garbage collection live marking */
66 /******************************************************************************/
67 {
69 }
70 
72 /******************************************************************************/
73 /* Function: Generalized object marking */
74 /******************************************************************************/
75 {
77 }
78 
80 /******************************************************************************/
81 /* Function: Flatten an object */
82 /******************************************************************************/
83 {
85 
86  flatten_reference(newThis->variableObject, envelope);
87 
89 }
90 
92  RexxActivation *context, /* current activation context */
93  RexxExpressionStack *stack) /* evaluation stack */
94 /******************************************************************************/
95 /* Function: Parse a variables contents into an array of "good" variable */
96 /* retrievers. */
97 /******************************************************************************/
98 {
99  /* get the variable value */
100  RexxObject *value = this->variableObject->evaluate(context, stack);
101  stack->toss(); /* remove the stack item */
102  RexxString *name_string = REQUEST_STRING(value); /* force to string form */
103  stack->push(name_string); /* protect this on the stack */
104  RexxList *name_list = new_list(); /* create a new list item */
105  stack->push(name_list); /* protect this also */
106  size_t i = 1; /* start with the first word */
107  /* get the next variable */
108  RexxString *variable_name = (RexxString *)name_string->word(new_integer(i));
109  i++; /* step the index */
110  while (variable_name->getLength() != 0)
111  {
112  /* get the first character */
113  int character = (int)variable_name->getChar(0);
114  if (character == '.') /* start with a period? */
115  {
116  /* report that error */
118  }
119  /* how about a digit? */
120  else if (character >= '0' && character <= '9')
121  {
122  /* constant symbol */
124  }
125  /* convert into a variable reference */
127  if (retriever == OREF_NULL) /* not converted ok? */
128  {
130  }
131  /* add to the processing list */
132  name_list->addLast((RexxObject *)retriever);
133  /* get the next variable */
134  variable_name = (RexxString *)name_string->word(new_integer(i));
135  i++; /* and step the index */
136  }
137  return name_list; /* return the list directly */
138 }
139 
141  RexxActivation *context) /* the context we're dropping in */
142 /******************************************************************************/
143 /* Function: Drop a subsidiary list of variables */
144 /******************************************************************************/
145 {
146  RexxExpressionStack *stack = context->getStack(); /* get the stack from the context */
147  /* evaluate into a variable list */
148  RexxList *name_list = this->list(context, stack);
149  /* get the first list item */
150  RexxVariableBase *variable = (RexxVariableBase *)name_list->removeFirst();
151  /* while more list items */
152  while (variable != (RexxVariableBase *)TheNilObject)
153  {
154  variable->drop(context); /* drop the this variable */
155  /* get the next list item */
156  variable = (RexxVariableBase *)name_list->removeFirst();
157  }
158 }
159 
160 
162  RexxActivation *context, /* current activation context */
163  RexxActivation *parent, /* the parent activation context */
164  RexxExpressionStack *stack) /* current evaluation stack */
165 /******************************************************************************/
166 /* Function: Expose a subsidiary list of variables */
167 /******************************************************************************/
168 {
169  /* expose the variable first */
170  variableObject->procedureExpose(context, parent, stack);
171  /* evaluate into a variable list */
172  RexxList *name_list = this->list(context, stack);
173  /* get the first list item */
174  RexxVariableBase *variable = (RexxVariableBase *)name_list->removeFirst();
175  /* while more list items */
176  while (variable != (RexxVariableBase *)TheNilObject)
177  {
178  /* expose this variable */
179  variable->procedureExpose(context, parent, stack);
180  /* get the next list item */
181  variable = (RexxVariableBase *)name_list->removeFirst();
182  }
183 }
184 
185 
187  RexxActivation *context, /* current activation context */
188  RexxExpressionStack *stack, /* current evaluation stack */
189  /* variable scope we're exposing from*/
190  RexxVariableDictionary *object_dictionary)
191 /******************************************************************************/
192 /* Function: Expose a subsidiary list of variables */
193 /******************************************************************************/
194 {
195  /* expose the variable first */
196  variableObject->expose(context, stack, object_dictionary);
197  /* evaluate into a variable list */
198  RexxList *name_list = this->list(context, stack);
199  /* get the first list item */
200  RexxVariableBase *variable = (RexxVariableBase *)name_list->removeFirst();
201  /* while more list items */
202  while (variable != (RexxVariableBase *)TheNilObject)
203  {
204  /* expose this variable */
205  variable->expose(context, stack, object_dictionary);
206  /* get the next list item */
207  variable = (RexxVariableBase *)name_list->removeFirst();
208  }
209 }
210 
211 
212 void *RexxVariableReference::operator new(size_t size)
213 /******************************************************************************/
214 /* Function: Create a new translator object */
215 /******************************************************************************/
216 {
217  /* Get new object */
218  return new_object(size, T_IndirectVariableTerm);
219 }
220 
221 
223  RexxActivation *context) /* current activation context */
224 /******************************************************************************/
225 /* Function: Translate to upper a subsidiary list of variables */
226 /******************************************************************************/
227 {
228  RexxExpressionStack *stack = context->getStack(); /* get the stack from the context */
229  /* evaluate into a variable list */
230  RexxList *name_list = this->list(context, stack);
231  /* get the first list item */
232  RexxVariableBase *variable = (RexxVariableBase *)name_list->removeFirst();
233  /* while more list items */
234  while (variable != (RexxVariableBase *)TheNilObject)
235  {
236  variable->upper(context); /* translate to upper this variable */
237  /* get the next list item */
238  variable = (RexxVariableBase *)name_list->removeFirst();
239  }
240 }
void reportException(wholenumber_t error)
@ T_IndirectVariableTerm
RexxInteger * new_integer(wholenumber_t v)
RexxList * new_list()
Definition: ListClass.hpp:147
#define OREF_NULL
Definition: RexxCore.h:61
RexxString * REQUEST_STRING(RexxObject *object)
Definition: RexxCore.h:295
#define OrefSet(o, r, v)
Definition: RexxCore.h:101
#define TheNilObject
Definition: RexxCore.h:191
#define Error_Invalid_variable_period
#define Error_Invalid_variable_number
#define Error_Symbol_expected_expose
#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
RexxExpressionStack * getStack()
void push(RexxObject *value)
virtual RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
RexxObject * removeFirst()
Definition: ListClass.hpp:109
void addLast(RexxObject *value)
Definition: ListClass.cpp:455
size_t getLength()
RexxString * word(RexxInteger *)
char getChar(size_t p)
virtual void procedureExpose(RexxActivation *, RexxActivation *, RexxExpressionStack *)
virtual void upper(RexxActivation *)
virtual void expose(RexxActivation *, RexxExpressionStack *, RexxVariableDictionary *)
virtual void drop(RexxActivation *)
static RexxVariableBase * getVariableRetriever(RexxString *variable)
RexxList * list(RexxActivation *, RexxExpressionStack *)
void expose(RexxActivation *, RexxExpressionStack *, RexxVariableDictionary *)
RexxVariableReference(RESTORETYPE restoreType)
void procedureExpose(RexxActivation *, RexxActivation *, RexxExpressionStack *)