TraceInstruction.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 Trace Parse Class */
42 /* */
43 /******************************************************************************/
44 #include <stdlib.h>
45 #include "RexxCore.h"
46 #include "RexxActivation.hpp"
47 #include "TraceInstruction.hpp"
48 #include "SourceFile.hpp"
49 
50 
51 /**
52  * Initialize a Trace instruction.
53  *
54  * @param _expression
55  * A potential expression to evaluate.
56  * @param trace The new trace setting (can be zero if numeric or dynamic form).
57  * @param flags The translated trace flags for setting-based forms.
58  * @param debug_skip A potential debug_skip value.
59  */
60 RexxInstructionTrace::RexxInstructionTrace(RexxObject *_expression, size_t trace, size_t flags, wholenumber_t debug_skip )
61 {
62  /* process the expression */
63  OrefSet(this, this->expression, _expression);
64  this->debugskip = debug_skip; /* copy the skip value */
65  traceSetting = trace; /* and the trace setting */
66  traceFlags = flags;
67 }
68 
69 void RexxInstructionTrace::live(size_t liveMark)
70 /******************************************************************************/
71 /* Function: Normal garbage collection live marking */
72 /******************************************************************************/
73 {
74  memory_mark(this->nextInstruction); /* must be first one marked */
75  memory_mark(this->expression);
76 }
77 
79 /******************************************************************************/
80 /* Function: Generalized object marking */
81 /******************************************************************************/
82 {
83  /* 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 
99 }
100 
102  RexxActivation *context, /* current activation context */
103  RexxExpressionStack *stack) /* evaluation stack */
104 /******************************************************************************/
105 /* Function: Execute a REXX TRACE instruction */
106 /******************************************************************************/
107 {
108  RexxObject *result; /* expression result */
109  RexxString *value; /* string version of expression */
110 
111  context->traceInstruction(this); /* trace if necessary */
112  // is this a debug skip request (the setting value is zero in that case)
113  if ((traceSetting&TRACE_SETTING_MASK) == 0)
114  {
115  /* turn on the skip mode */
116  context->debugSkip(this->debugskip, (traceSetting&DEBUG_NOTRACE) != 0);
117  }
118  /* non-dynamic form? */
119  else if (this->expression == OREF_NULL)
120  {
121  if (!context->inDebug()) /* not in debug mode? */
122  {
123  /* just change the setting */
124  context->setTrace(traceSetting, traceFlags);
125  }
126  else
127  {
128  context->pauseInstruction(); /* do debug pause if necessary */
129  }
130  }
131  else /* need to evaluate an expression */
132  {
133  /* get the expression value */
134  result = this->expression->evaluate(context, stack);
135  ProtectedObject p_result(result);
136  value = REQUEST_STRING(result); /* force to string form */
137  ProtectedObject p_value(value);
138  context->traceResult(result); /* trace if necessary */
139  if (!context->inDebug()) /* not in debug mode? */
140  {
141  /* now change the setting */
142  context->setTrace(value);
143  }
144  else
145  {
146  context->pauseInstruction(); /* do debug pause if necessary */
147  }
148  }
149 }
150 
#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 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
const size_t TRACE_SETTING_MASK
Definition: SourceFile.hpp:87
const int DEBUG_NOTRACE
Definition: SourceFile.hpp:97
void debugSkip(wholenumber_t, bool)
void traceResult(RexxObject *v)
void setTrace(size_t, size_t)
void traceInstruction(RexxInstruction *v)
RexxInstruction * nextInstruction
RexxInstructionTrace(RexxObject *, size_t, size_t, wholenumber_t)
void execute(RexxActivation *, RexxExpressionStack *)
void flatten(RexxEnvelope *)
void liveGeneral(int reason)
virtual RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
ssize_t wholenumber_t
Definition: rexx.h:230