AddressInstruction.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 AddressInstruction.cpp */
40 /* */
41 /* Primitive Address Parse Class */
42 /* */
43 /******************************************************************************/
44 #include <stdlib.h>
45 #include "RexxCore.h"
46 #include "StringClass.hpp"
47 #include "RexxActivation.hpp"
48 #include "AddressInstruction.hpp"
49 #include "SystemInterpreter.hpp"
50 
52  RexxObject *_expression, /* variable address expression */
53  RexxString *_environment, /* address environment name */
54  RexxObject *_command) /* command to issue */
55 /******************************************************************************/
56 /* Function : Complete address instruction initialization */
57 /******************************************************************************/
58 {
59  /* store the instruction state */
60  OrefSet(this, this->expression, _expression);
61  OrefSet(this, this->environment, _environment);
62  OrefSet(this, this->command, _command);
63 }
64 
65 void RexxInstructionAddress::live(size_t liveMark)
66 /******************************************************************************/
67 /* Function: Normal garbage collection live marking */
68 /******************************************************************************/
69 {
70  memory_mark(this->nextInstruction); /* must be first one marked */
71  memory_mark(this->expression);
72  memory_mark(this->environment);
73  memory_mark(this->command);
74 }
75 
77 /******************************************************************************/
78 /* Function: Generalized object marking */
79 /******************************************************************************/
80 {
81  /* must be first one marked */
86 }
87 
89 /******************************************************************************/
90 /* Function: Flatten an object */
91 /******************************************************************************/
92 {
94 
95  flatten_reference(newThis->nextInstruction, envelope);
96  flatten_reference(newThis->expression, envelope);
97  flatten_reference(newThis->environment, envelope);
98  flatten_reference(newThis->command, envelope);
99 
101 }
102 
104  RexxActivation *context, /* current activation context */
105  RexxExpressionStack *stack ) /* evaluation stack */
106 /****************************************************************************/
107 /* Function: Execute a REXX LEAVE instruction */
108 /****************************************************************************/
109 {
110  context->traceInstruction(this); /* trace if necessary */
111  /* is this an address toggle? */
112  if (this->environment == OREF_NULL && this->expression == OREF_NULL)
113  {
114  context->toggleAddress(); /* toggle the address settings */
115  context->pauseInstruction(); /* do debug pause if necessary */
116  }
117  /* have a constant address name? */
118  else if (this->environment != OREF_NULL)
119  {
120  if (this->command != OREF_NULL)
121  { /* actually the command form? */
122  /* get the expression value */
123  RexxObject *result = this->command->evaluate(context, stack);
124  RexxString *_command = REQUEST_STRING(result);/* force to string form */
125  context->traceResult(_command); /* trace if necessary */
126  /* validate the address name */
128  /* go process the command */
129  context->command(this->environment, _command);
130  }
131  else
132  { /* just change the address */
133  /* validate the address name */
135  /* now perform the switch */
136  context->setAddress(this->environment);
137  context->pauseInstruction(); /* do debug pause if necessary */
138  }
139  }
140  else
141  { /* we have an ADDRESS VALUE form */
142  /* get the expression value */
143  RexxObject *result = this->expression->evaluate(context, stack);
144  RexxString *_address = REQUEST_STRING(result); /* force to string form */
145  context->traceResult(_address); /* trace if necessary */
146  SystemInterpreter::validateAddressName(_address); /* validate the address name */
147  context->setAddress(_address); /* just change the address */
148  context->pauseInstruction(); /* do debug pause if necessary */
149  }
150 }
151 
#define OREF_NULL
Definition: RexxCore.h:60
RexxString * REQUEST_STRING(RexxObject *object)
Definition: RexxCore.h:283
#define OrefSet(o, r, v)
Definition: RexxCore.h:94
#define memory_mark(oref)
Definition: RexxMemory.hpp:445
#define flatten_reference(oref, envel)
Definition: RexxMemory.hpp:493
#define memory_mark_general(oref)
Definition: RexxMemory.hpp:446
#define cleanUpFlatten
Definition: RexxMemory.hpp:479
#define setUpFlatten(type)
Definition: RexxMemory.hpp:473
void setAddress(RexxString *)
void traceResult(RexxObject *v)
void command(RexxString *, RexxString *)
void traceInstruction(RexxInstruction *v)
void execute(RexxActivation *, RexxExpressionStack *)
void liveGeneral(int reason)
void flatten(RexxEnvelope *)
RexxInstructionAddress(RexxObject *, RexxString *, RexxObject *)
RexxInstruction * nextInstruction
virtual RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
static void validateAddressName(RexxString *name)