SignalInstruction.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 Signal Parse Class */
42 /* */
43 /******************************************************************************/
44 #include <stdlib.h>
45 #include "RexxCore.h"
46 #include "StringClass.hpp"
47 #include "RexxActivation.hpp"
48 #include "DirectoryClass.hpp"
49 #include "SignalInstruction.hpp"
50 
52  RexxObject *_expression, /* expression for signal value */
53  RexxString *_condition, /* signalled condition */
54  RexxString *_name, /* signal target name */
55  size_t flags ) /* option flags */
56 /******************************************************************************/
57 /* Initialize a SIGNAL instruction */
58 /******************************************************************************/
59 {
60  /* save all appropriate info */
61  OrefSet(this, this->expression, _expression);
62  OrefSet(this, this->condition, _condition);
63  OrefSet(this, this->name, _name);
64  instructionFlags = (uint16_t)flags;
65 }
66 
67 void RexxInstructionSignal::live(size_t liveMark)
68 /******************************************************************************/
69 /* Function: Normal garbage collection live marking */
70 /******************************************************************************/
71 {
72  memory_mark(this->nextInstruction); /* must be first one marked */
73  memory_mark(this->target);
74  memory_mark(this->name);
75  memory_mark(this->condition);
76  memory_mark(this->expression);
77 }
78 
80 /******************************************************************************/
81 /* Function: Generalized object marking */
82 /******************************************************************************/
83 {
84  /* must be first one marked */
90 }
91 
93 /******************************************************************************/
94 /* Function: Flatten an object */
95 /******************************************************************************/
96 {
98 
99  flatten_reference(newThis->nextInstruction, envelope);
100  flatten_reference(newThis->target, envelope);
101  flatten_reference(newThis->name, envelope);
102  flatten_reference(newThis->condition, envelope);
103  flatten_reference(newThis->expression, envelope);
104 
106 }
107 
109  RexxDirectory *labels) /* table of program labels */
110 /******************************************************************************/
111 /* Function: Resolve a SIGNAL instruction label target */
112 /******************************************************************************/
113 {
114  if (this->name == OREF_NULL) /* not a name target form? */
115  {
116  return; /* just return */
117  }
118  /* have a labels table? */
119  if (labels != OREF_NULL && this->name != OREF_NULL)
120  {
121  /* just get this from the table */
122  OrefSet(this, this->target, (RexxInstruction *)labels->at(this->name));
123  }
124 }
125 
127  RexxActivation *context, /* current activation context */
128  RexxExpressionStack *stack) /* evaluation stack */
129 /******************************************************************************/
130 /* Function: Execute a REXX SIGNAL instruction */
131 /******************************************************************************/
132 {
133  RexxObject *result; /* evaluated expression */
134  RexxString *stringResult; /* string version of the result */
135 
136  context->traceInstruction(this); /* trace if necessary */
137  if (this->condition != OREF_NULL) /* is this the ON/OFF form? */
138  {
139  if (instructionFlags&signal_on) /* ON form? */
140  {
141  /* turn on the trap */
142  context->trapOn(this->condition, (RexxInstructionCallBase *)this);
143  }
144  else
145  {
146  /* turn off the trap */
147  context->trapOff(this->condition);
148  }
149  context->pauseInstruction(); /* do debug pause if necessary */
150  }
151  else /* a normal signal? */
152  {
153  if (this->expression == OREF_NULL)/* already have the target? */
154  {
155  if (this->target == OREF_NULL) /* unknown target? */
156  {
158  }
159  /* tell the activation to perform */
160  context->signalTo(this->target); /* the signal */
161  }
162  else /* need to evaluate an expression */
163  {
164  /* get the expression value */
165  result = this->expression->evaluate(context, stack);
166  /* force to a string value */
167  stringResult = REQUEST_STRING(result);
168  ProtectedObject p(stringResult);
169  context->traceResult(result); /* trace if necessary */
170  /* tell the activation to perform */
171  /* the signal */
172  context->signalValue(stringResult);
173  }
174  }
175 }
176 
178  RexxActivation *context, /* current execution context */
179  RexxDirectory *conditionObj) /* associated condition object */
180 /******************************************************************************/
181 /* Function: Process a SIGNAL ON trap */
182 /******************************************************************************/
183 {
184  context->trapOff(this->condition); /* turn off the trap */
185  if (this->target == OREF_NULL) /* unknown target? */
186  {
188  }
189  /* set the new condition object */
190  context->setConditionObj(conditionObj);
191  /* tell the activation to perform */
192  context->signalTo(this->target); /* the signal */
193 }
194 
void reportException(wholenumber_t error)
#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 Error_Label_not_found_name
#define memory_mark(oref)
Definition: RexxMemory.hpp:450
#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
#define signal_on
void signalTo(RexxInstruction *)
void trapOn(RexxString *, RexxInstructionCallBase *)
void signalValue(RexxString *)
void traceResult(RexxObject *v)
void traceInstruction(RexxInstruction *v)
void trapOff(RexxString *)
void setConditionObj(RexxDirectory *condition)
RexxObject * at(RexxString *)
uint16_t instructionFlags
RexxInstruction * nextInstruction
void trap(RexxActivation *, RexxDirectory *)
void flatten(RexxEnvelope *)
void liveGeneral(int reason)
RexxInstruction * target
void execute(RexxActivation *, RexxExpressionStack *)
RexxInstructionSignal(RexxObject *, RexxString *, RexxString *, size_t)
void resolve(RexxDirectory *)
virtual RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
unsigned short uint16_t