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)  

ParseInstruction.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 Parse Parse Class */
42 /* */
43 /******************************************************************************/
44 #include <stdlib.h>
45 #include "RexxCore.h"
46 #include "StringClass.hpp"
47 #include "QueueClass.hpp"
48 #include "DirectoryClass.hpp"
49 #include "RexxActivation.hpp"
50 #include "RexxActivity.hpp"
51 #include "ParseInstruction.hpp"
52 #include "ParseTrigger.hpp"
53 #include "ParseTarget.hpp"
54 #include "Token.hpp"
55 #include "Interpreter.hpp"
56 
57 
59  RexxObject *_expression, /* string expression source */
60  unsigned short string_source, /* source of the parsed string */
61  size_t flags, /* option flags */
62  size_t templateCount, /* count of template items */
63  RexxQueue *parse_template ) /* parsing template array */
64 /******************************************************************************/
65 /* Function: Complete parse instruction initialization */
66 /******************************************************************************/
67 {
68  /* save the expression */
69  OrefSet(this, this->expression, _expression);
70  instructionFlags = (uint16_t)flags; /* save the expression */
71  stringSource = string_source; // our instruction type is determined by the source
72  this->trigger_count = templateCount; /* save the size */
73  while (templateCount > 0) /* loop through the template list */
74  {
75  /* copying each trigger */
76  OrefSet(this, this->triggers[--templateCount], (RexxTrigger *)parse_template->pop());
77  }
78 }
79 
81  RexxActivation *context, /* current activation context */
82  RexxExpressionStack *stack ) /* evaluation stack */
83 /****************************************************************************/
84 /* Function: Execute a REXX PARSE instruction */
85 /****************************************************************************/
86 {
87  RexxObject *value; /* parsed value */
88  RexxObject **argList; /* current argument list */
89  size_t argCount; /* the argument list size */
90  RexxTarget target; /* created target value */
91  RexxTrigger *trigger; /* current trigger */
92  size_t size; /* size of template array */
93  bool multiple; /* processing an argument list */
94  size_t i; /* loop counter */
95 
96  context->traceInstruction(this); /* trace if necessary */
97  multiple = false; /* default to no argument list */
98  value = OREF_NULLSTRING; /* no value yet */
99  argList = OREF_NULL; /* neither is there an argument list */
100  argCount = 0;
101 
102  switch (stringSource) /* get data from variaous sources */
103  {
104 
105  case SUBKEY_PULL: /* PARSE PULL instruction */
106  /* read a line from the queue */
108  stack->push(value); /* add the value to the stack */
109  break;
110 
111  case SUBKEY_LINEIN: /* PARSE LINEIN instruction */
112  /* read a line from the stream */
113  value = ActivityManager::currentActivity->lineIn(context);
114  stack->push(value); /* add the value to the stack */
115  break;
116 
117  case SUBKEY_ARG: /* PARSE ARG instruction */
118  multiple = true; /* have an argument list */
119  /* get the current argument list */
120  argList = context->getMethodArgumentList();
121  argCount = context->getMethodArgumentCount();
122  break;
123 
124  case SUBKEY_SOURCE: /* PARSE SOURCE instruction */
125  value = context->sourceString(); /* retrieve the source string */
126  stack->push(value); /* add the value to the stack */
127  break;
128 
129  case SUBKEY_VERSION: /* PARSE VERSION instruction */
130  /* retrieve the version string */
132  break;
133 
134  case SUBKEY_VAR: /* PARSE VAR name instruction */
135  /* get the variable value */
136  value = this->expression->evaluate(context, stack);
137  stack->push(value); /* add the value to the stack */
138  break;
139 
140  case SUBKEY_VALUE: /* PARSE VALUE expr WITH instruction */
141  /* have an expression? */
142  if (this->expression != OREF_NULL)
143  {
144  /* get the expression value */
145  value = this->expression->evaluate(context, stack);
146  }
147  else
148  {
149  value = OREF_NULLSTRING; /* must have been "parse value with" */
150  }
151  stack->push(value); /* add the value to the stack */
152  break;
153  }
154  /* create the parse target */
155  target.init(value, argList, argCount, instructionFlags&parse_translate, multiple, context, stack);
156 
157  size = this->trigger_count; /* get the template size */
158  for (i = 0; i < size; i++) /* loop through the template list */
159  {
160  trigger = this->triggers[i]; /* get the next trigger value */
161  if (trigger == OREF_NULL) /* end of this template portion? */
162  {
163  target.next(context); /* reset for the next string */
164  }
165  else /* process this trigger */
166  {
167  trigger->parse(context, stack, &target);
168  }
169  }
170  context->pauseInstruction(); /* do debug pause if necessary */
171 }
172 
173 void RexxInstructionParse::live(size_t liveMark)
174 /******************************************************************************/
175 /* Function: Normal garbage collection live marking */
176 /******************************************************************************/
177 {
178  size_t i; /* loop counter */
179  size_t count; /* argument count */
180 
181  memory_mark(this->nextInstruction); /* must be first one marked */
182  for (i = 0, count = this->trigger_count; i < count; i++)
183  {
184  memory_mark(this->triggers[i]);
185  }
186  memory_mark(this->expression);
187 }
188 
190 /******************************************************************************/
191 /* Function: Generalized object marking */
192 /******************************************************************************/
193 {
194  size_t i; /* loop counter */
195  size_t count; /* argument count */
196 
197  /* must be first one marked */
199  for (i = 0, count = this->trigger_count; i < count; i++)
200  {
201  memory_mark_general(this->triggers[i]);
202  }
204 }
205 
207 /******************************************************************************/
208 /* Function: Flatten an object */
209 /******************************************************************************/
210 {
211  size_t i; /* loop counter */
212  size_t count; /* argument count */
213 
215 
216  flatten_reference(newThis->nextInstruction, envelope);
217  for (i = 0, count = this->trigger_count; i < count; i++)
218  {
219  flatten_reference(newThis->triggers[i], envelope);
220  }
221  flatten_reference(newThis->expression, envelope);
223 }
224 
parse_translate
#define parse_translate
Definition: ParseInstruction.hpp:52
RexxExpressionStack
Definition: ExpressionStack.hpp:53
SUBKEY_LINEIN
#define SUBKEY_LINEIN
Definition: Token.hpp:205
SUBKEY_PULL
#define SUBKEY_PULL
Definition: Token.hpp:214
SUBKEY_ARG
#define SUBKEY_ARG
Definition: Token.hpp:194
RexxInternalObject::evaluate
virtual RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
Definition: ObjectClass.hpp:269
RexxInstructionParse::RexxInstructionParse
RexxInstructionParse(RexxObject *, unsigned short, size_t, size_t, RexxQueue *)
Definition: ParseInstruction.cpp:58
RexxInstructionParse::flatten
void flatten(RexxEnvelope *)
Definition: ParseInstruction.cpp:206
RexxInstruction::instructionFlags
uint16_t instructionFlags
Definition: RexxInstruction.hpp:82
RexxActivation::getMethodArgumentList
RexxObject ** getMethodArgumentList()
Definition: RexxActivation.hpp:423
memory_mark_general
#define memory_mark_general(oref)
Definition: RexxMemory.hpp:437
RexxQueue
Definition: QueueClass.hpp:49
SUBKEY_VAR
#define SUBKEY_VAR
Definition: Token.hpp:222
RexxActivation.hpp
OrefSet
#define OrefSet(o, r, v)
Definition: RexxCore.h:94
SUBKEY_SOURCE
#define SUBKEY_SOURCE
Definition: Token.hpp:216
RexxInstructionParse
Definition: ParseInstruction.hpp:57
RexxInstructionParse::trigger_count
size_t trigger_count
Definition: ParseInstruction.hpp:72
RexxTrigger::parse
void parse(RexxActivation *, RexxExpressionStack *, RexxTarget *)
Definition: ParseTrigger.cpp:103
RexxQueue::pop
RexxObject * pop()
Definition: QueueClass.hpp:80
RexxInstructionParse::live
void live(size_t)
Definition: ParseInstruction.cpp:173
RexxTrigger
Definition: ParseTrigger.hpp:59
ParseInstruction.hpp
SUBKEY_VERSION
#define SUBKEY_VERSION
Definition: Token.hpp:223
RexxEnvelope
Definition: RexxEnvelope.hpp:53
ParseTrigger.hpp
Interpreter.hpp
RexxInstruction::nextInstruction
RexxInstruction * nextInstruction
Definition: RexxInstruction.hpp:85
OREF_NULL
#define OREF_NULL
Definition: RexxCore.h:60
SUBKEY_VALUE
#define SUBKEY_VALUE
Definition: Token.hpp:221
RexxActivation::pauseInstruction
void pauseInstruction()
Definition: RexxActivation.hpp:401
flatten_reference
#define flatten_reference(oref, envel)
Definition: RexxMemory.hpp:440
cleanUpFlatten
#define cleanUpFlatten
Definition: RexxMemory.hpp:432
RexxTarget
Definition: ParseTarget.hpp:51
RexxTarget::next
void next(RexxActivation *)
Definition: ParseTarget.cpp:74
StringClass.hpp
RexxActivity::pullInput
RexxString * pullInput(RexxActivation *)
Definition: RexxActivity.cpp:2893
Interpreter::getVersionNumber
static RexxString * getVersionNumber()
Definition: Version.cpp:52
RexxActivation::getMethodArgumentCount
size_t getMethodArgumentCount()
Definition: RexxActivation.hpp:424
RexxExpressionStack::push
void push(RexxObject *value)
Definition: ExpressionStack.hpp:77
memory_mark
#define memory_mark(oref)
Definition: RexxMemory.hpp:436
RexxActivation
Definition: RexxActivation.hpp:156
Token.hpp
RexxTarget::init
void init(RexxObject *, RexxObject **, size_t, size_t, bool, RexxActivation *, RexxExpressionStack *)
Definition: ParseTarget.cpp:52
RexxActivation::sourceString
RexxString * sourceString()
Definition: RexxActivation.cpp:3983
ParseTarget.hpp
QueueClass.hpp
RexxActivation::traceInstruction
void traceInstruction(RexxInstruction *v)
Definition: RexxActivation.hpp:396
setUpFlatten
#define setUpFlatten(type)
Definition: RexxMemory.hpp:427
ActivityManager::currentActivity
static RexxActivity *volatile currentActivity
Definition: ActivityManager.hpp:95
RexxInstructionParse::execute
void execute(RexxActivation *, RexxExpressionStack *)
Definition: ParseInstruction.cpp:80
RexxActivity.hpp
RexxInstructionParse::stringSource
int stringSource
Definition: ParseInstruction.hpp:70
RexxCore.h
DirectoryClass.hpp
RexxInstructionParse::liveGeneral
void liveGeneral(int reason)
Definition: ParseInstruction.cpp:189
RexxInstructionParse::triggers
RexxTrigger * triggers[1]
Definition: ParseInstruction.hpp:73
RexxActivity::lineIn
RexxString * lineIn(RexxActivation *)
Definition: RexxActivity.cpp:2936
RexxObject
Definition: ObjectClass.hpp:311
RexxInstructionParse::expression
RexxObject * expression
Definition: ParseInstruction.hpp:71