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)  

ParseTrigger.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 ParseTrigger.cpp */
40 /* */
41 /* Primitive Procedure Parse Trigger Class */
42 /* */
43 /******************************************************************************/
44 #include <stdlib.h>
45 #include "RexxCore.h"
46 #include "StringClass.hpp"
47 #include "QueueClass.hpp"
48 #include "RexxActivation.hpp"
49 #include "ParseTrigger.hpp"
50 #include "ParseTarget.hpp"
52 
54  int type, /* type of trigger */
55  RexxObject *_value, /* value to evaluatate */
56  size_t _variableCount, /* count of variables */
57  RexxQueue *_variables) /* array of trigger variables */
58 /******************************************************************************/
59 /* Function: Initialize a parse trigger translator object */
60 /******************************************************************************/
61 {
62  this->setType(type); /* set the type (and hashvalue) */
63  this->variableCount = _variableCount; /* set the number of variables also */
64  OrefSet(this, this->value, _value); /* save the associated value */
65  /* loop through the variable list */
66  while (_variableCount > 0) /* copying each variable */
67  {
68  OrefSet(this, this->variables[--_variableCount], (RexxVariableBase *)_variables->pop());
69  }
70 }
71 
72 
74  RexxObject *trigger) /* value to be converted */
75 /******************************************************************************/
76 /* Function: Convert a trigger value to an integer, with appopriate error */
77 /* reporting. */
78 /******************************************************************************/
79 {
80  stringsize_t result; /* converted result */
81  /* convert the value */
82  if (!trigger->requestUnsignedNumber(result, number_digits()))
83  {
84  /* report an exception */
86  }
87  return result; /* finished */
88 }
89 
90 
92  RexxObject *trigger) /* value to be converted */
93 /******************************************************************************/
94 /* Function: Convert a trigger expression to a String, with appopriate error */
95 /* reporting. */
96 /******************************************************************************/
97 {
98  /* force to string form */
99  return REQUEST_STRING(trigger);
100 }
101 
102 
104  RexxActivation *context, /* current execution context */
105  RexxExpressionStack *stack, /* current expression stack */
106  RexxTarget *target ) /* current parsing target string */
107 /******************************************************************************/
108 /* Function: Apply a parsing trigger against a parsing target */
109 /******************************************************************************/
110 {
111  RexxObject *_value = OREF_NULL;/* evaluated trigger part */
112  RexxString *stringvalue; /* new string value */
113  stringsize_t integer; /* target integer value */
114  size_t i; /* loop counter */
115  size_t size; /* size of variables array */
116  RexxVariableBase *variable; /* current variable processing */
117 
118  if (this->value != OREF_NULL)
119  { /* need a value processed? */
120  /* evaluate the expression part */
121  _value = this->value->evaluate(context, stack);
122  context->traceResult(_value); /* trace if necessary */
123  stack->pop(); /* Get rid of the value off the stack*/
124  }
125  switch (this->getType())
126  { /* perform the trigger operations */
127 
128  case TRIGGER_END: /* just match to the end */
129  target->moveToEnd(); /* move the pointers */
130  break;
131 
132  case TRIGGER_PLUS: /* positive relative target */
133  integer = this->integerTrigger(_value); /* get binary version of trigger */
134  target->forward(integer); /* move the position */
135  break;
136 
137  case TRIGGER_MINUS: /* negative relative target */
138  integer = this->integerTrigger(_value); /* get binary version of trigger */
139  target->backward(integer); /* move the position */
140  break;
141 
142  case TRIGGER_PLUS_LENGTH: /* positive length */
143  integer = this->integerTrigger(_value); /* get binary version of trigger */
144  target->forwardLength(integer); /* move the position */
145  break;
146 
147  case TRIGGER_MINUS_LENGTH: /* negative relative target */
148  integer = this->integerTrigger(_value); /* get binary version of trigger */
149  target->backwardLength(integer); /* move the position */
150  break;
151 
152  case TRIGGER_ABSOLUTE: /* absolute column position */
153  integer = this->integerTrigger(_value); /* get binary version of trigger */
154  target->absolute(integer); /* move the position */
155  break;
156 
157  case TRIGGER_STRING: /* string search */
158  /* force to string form */
159  stringvalue = this->stringTrigger(_value);
160  target->search(stringvalue); /* perform the search */
161  break;
162 
163  case TRIGGER_MIXED: /* string search */
164  /* force to string form */
165  stringvalue = this->stringTrigger(_value);
166  /* and go search */
167  target->caselessSearch(stringvalue);
168  break;
169  }
170  if (context->tracingResults())
171  { /* are we tracing? */
172  /* loop through the entire list */
173  for (i = 0, size = this->variableCount; i < size; i++)
174  {
175  if (i + 1 == size) /* last variable? */
176  {
177  _value = target->remainder(); /* extract the remainder */
178  }
179  else
180  {
181  _value = target->getWord(); /* just get the next word */
182  }
183  ProtectedObject p(_value); // needs protecting if the assignment is a compound var.
184  variable = this->variables[i]; /* get the next variable retriever */
185  if (variable != OREF_NULL)
186  { /* not a place holder dummy? */
187  /* set the value */
188  // NOTE: The different variable tpes handle their own assignment tracing
189 
190  variable->assign(context, stack, _value);
191  // if only tracing results and not intermediates, then we need to
192  // trace this value explicitly.
193  if (!context->tracingIntermediates())
194  {
195  context->traceResult(_value); /* trace if necessary */
196  }
197  }
198  else /* dummy variable, just trace it */
199  {
200  /* trace if necessary */
201  context->traceIntermediate(_value, TRACE_PREFIX_DUMMY);
202  }
203  }
204  }
205  else
206  { /* not tracing, can optimize */
207  /* loop through the entire list */
208  for (i = 0, size = this->variableCount; i < size; i++)
209  {
210  variable = this->variables[i]; /* get the next variable retriever */
211  if (variable != OREF_NULL)
212  { /* not a place holder dummy? */
213  if (i + 1 == size) /* last variable? */
214  {
215  _value = target->remainder(); /* extract the remainder */
216  }
217  else
218  {
219  _value = target->getWord(); /* just get the next word */
220  }
221  ProtectedObject p(_value); // needs protecting if the assignment is a compound var.
222  /* set the value */
223  variable->assign(context, stack, _value);
224  }
225  else
226  { /* dummy variable, just skip it */
227  if (i + 1 == size) /* last variable? */
228  {
229  target->skipRemainder(); /* skip the remainder */
230  }
231  else
232  {
233  target->skipWord(); /* just skip the next word */
234  }
235  }
236  }
237  }
238 }
239 
240 void RexxTrigger::live(size_t liveMark)
241 /******************************************************************************/
242 /* Function: Normal garbage collection live marking */
243 /******************************************************************************/
244 {
245  size_t i; /* loop counter */
246  size_t count; /* argument count */
247 
248  for (i = 0, count = this->variableCount; i < count; i++)
249  {
250  memory_mark(this->variables[i]);
251  }
252  memory_mark(this->value);
253 }
254 
255 void RexxTrigger::liveGeneral(int reason)
256 /******************************************************************************/
257 /* Function: Generalized object marking */
258 /******************************************************************************/
259 {
260  size_t i; /* loop counter */
261  size_t count; /* argument count */
262 
263  for (i = 0, count = this->variableCount; i < count; i++)
264  {
265  memory_mark_general(this->variables[i]);
266  }
267  memory_mark_general(this->value);
268 }
269 
271 /******************************************************************************/
272 /* Function: Flatten an object */
273 /******************************************************************************/
274 {
275  size_t i; /* loop counter */
276  size_t count; /* argument count */
277 
278  setUpFlatten(RexxTrigger) /* set up for the flatten */
279 
280  flatten_reference(newThis->value, envelope);
281  for (i = 0, count = this->variableCount; i < count; i++)
282  {
283  flatten_reference(newThis->variables[i], envelope);
284  }
285 
287 }
288 
289 void *RexxTrigger::operator new(size_t size,
290  int variableCount) /* list of variables */
291 /******************************************************************************/
292 /* Function: Create a new parsing trigger object */
293 /******************************************************************************/
294 {
295  /* Get new object */
296  return new_object(size + (variableCount - 1) * sizeof(RexxObject *), T_ParseTrigger);
297 }
298 
RexxExpressionStack
Definition: ExpressionStack.hpp:53
RexxActivation::tracingResults
bool tracingResults()
Definition: RexxActivation.hpp:350
RexxInternalObject::evaluate
virtual RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
Definition: ObjectClass.hpp:269
RexxTrigger::variableCount
size_t variableCount
Definition: ParseTrigger.hpp:81
RexxTrigger::liveGeneral
void liveGeneral(int reason)
Definition: ParseTrigger.cpp:255
TRIGGER_ABSOLUTE
#define TRIGGER_ABSOLUTE
Definition: ParseTrigger.hpp:50
memory_mark_general
#define memory_mark_general(oref)
Definition: RexxMemory.hpp:437
RexxQueue
Definition: QueueClass.hpp:49
RexxActivation.hpp
type
int type
Definition: cmdparse.cpp:1965
OrefSet
#define OrefSet(o, r, v)
Definition: RexxCore.h:94
RexxTrigger::setType
void setType(int v)
Definition: ParseTrigger.hpp:76
RexxTrigger::parse
void parse(RexxActivation *, RexxExpressionStack *, RexxTarget *)
Definition: ParseTrigger.cpp:103
RexxQueue::pop
RexxObject * pop()
Definition: QueueClass.hpp:80
RexxActivation::traceResult
void traceResult(RexxObject *v)
Definition: RexxActivation.hpp:392
RexxTrigger
Definition: ParseTrigger.hpp:59
RexxVariableBase
Definition: ExpressionBaseVariable.hpp:47
reportException
void reportException(wholenumber_t error)
Definition: ActivityManager.hpp:136
RexxActivation::traceIntermediate
void traceIntermediate(RexxObject *v, int p)
Definition: RexxActivation.hpp:373
RexxEnvelope
Definition: RexxEnvelope.hpp:53
RexxTarget::search
void search(RexxString *)
Definition: ParseTarget.cpp:271
RexxTrigger::getType
int getType()
Definition: ParseTrigger.hpp:75
RexxTarget::backwardLength
void backwardLength(stringsize_t)
Definition: ParseTarget.cpp:247
ParseTrigger.hpp
RexxExpressionStack::pop
RexxObject * pop()
Definition: ExpressionStack.hpp:78
RexxTarget::caselessSearch
void caselessSearch(RexxString *)
Definition: ParseTarget.cpp:299
RexxActivation::tracingIntermediates
bool tracingIntermediates()
Definition: RexxActivation.hpp:348
TRIGGER_MIXED
#define TRIGGER_MIXED
Definition: ParseTrigger.hpp:52
RexxTarget::forward
void forward(stringsize_t)
Definition: ParseTarget.cpp:147
OREF_NULL
#define OREF_NULL
Definition: RexxCore.h:60
TRACE_PREFIX_DUMMY
Definition: RexxActivity.hpp:83
TRIGGER_STRING
#define TRIGGER_STRING
Definition: ParseTrigger.hpp:51
TRIGGER_MINUS_LENGTH
#define TRIGGER_MINUS_LENGTH
Definition: ParseTrigger.hpp:54
TRIGGER_MINUS
#define TRIGGER_MINUS
Definition: ParseTrigger.hpp:49
ExpressionBaseVariable.hpp
RexxTarget::skipWord
void skipWord()
Definition: ParseTarget.cpp:408
RexxObject::requestUnsignedNumber
bool requestUnsignedNumber(stringsize_t &, size_t)
Definition: ObjectClass.cpp:1376
TRIGGER_PLUS_LENGTH
#define TRIGGER_PLUS_LENGTH
Definition: ParseTrigger.hpp:53
flatten_reference
#define flatten_reference(oref, envel)
Definition: RexxMemory.hpp:440
RexxTrigger::value
RexxObject * value
Definition: ParseTrigger.hpp:82
cleanUpFlatten
#define cleanUpFlatten
Definition: RexxMemory.hpp:432
RexxTarget
Definition: ParseTarget.hpp:51
ProtectedObject
Definition: ProtectedObject.hpp:46
StringClass.hpp
RexxTrigger::live
void live(size_t)
Definition: ParseTrigger.cpp:240
RexxTrigger::variables
RexxVariableBase * variables[1]
Definition: ParseTrigger.hpp:83
RexxVariableBase::assign
virtual void assign(RexxActivation *, RexxExpressionStack *, RexxObject *)
Definition: ExpressionBaseVariable.hpp:53
Error_Invalid_whole_number_parse
#define Error_Invalid_whole_number_parse
Definition: RexxErrorCodes.h:224
RexxTarget::skipRemainder
void skipRemainder()
Definition: ParseTarget.hpp:68
memory_mark
#define memory_mark(oref)
Definition: RexxMemory.hpp:436
RexxTarget::remainder
RexxString * remainder()
Definition: ParseTarget.cpp:465
REQUEST_STRING
RexxString * REQUEST_STRING(RexxObject *object)
Definition: RexxCore.h:276
RexxActivation
Definition: RexxActivation.hpp:156
T_ParseTrigger
Definition: ClassTypeCodes.h:177
RexxTrigger::stringTrigger
RexxString * stringTrigger(RexxObject *)
Definition: ParseTrigger.cpp:91
stringsize_t
size_t stringsize_t
Definition: rexx.h:228
number_digits
size_t number_digits()
Definition: Numerics.hpp:147
RexxTrigger::RexxTrigger
RexxTrigger(int, RexxObject *, size_t, RexxQueue *)
Definition: ParseTrigger.cpp:53
ParseTarget.hpp
QueueClass.hpp
RexxTrigger::flatten
void flatten(RexxEnvelope *)
Definition: ParseTrigger.cpp:270
RexxTrigger::integerTrigger
stringsize_t integerTrigger(RexxObject *)
Definition: ParseTrigger.cpp:73
RexxTarget::absolute
void absolute(stringsize_t)
Definition: ParseTarget.cpp:192
setUpFlatten
#define setUpFlatten(type)
Definition: RexxMemory.hpp:427
RexxTarget::backward
void backward(stringsize_t)
Definition: ParseTarget.cpp:224
RexxCore.h
RexxTarget::moveToEnd
void moveToEnd()
Definition: ParseTarget.cpp:131
TRIGGER_PLUS
#define TRIGGER_PLUS
Definition: ParseTrigger.hpp:48
TRIGGER_END
#define TRIGGER_END
Definition: ParseTrigger.hpp:47
new_object
RexxObject * new_object(size_t s)
Definition: RexxMemory.hpp:422
RexxTarget::forwardLength
void forwardLength(stringsize_t)
Definition: ParseTarget.cpp:173
RexxTarget::getWord
RexxString * getWord()
Definition: ParseTarget.cpp:327
RexxObject
Definition: ObjectClass.hpp:311
RexxString
Definition: StringClass.hpp:119