NumericInstruction.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 Numeric Parse Class */
42 /* */
43 /******************************************************************************/
44 #include <stdlib.h>
45 #include "RexxCore.h"
46 #include "StringClass.hpp"
47 #include "RexxActivation.hpp"
48 #include "NumericInstruction.hpp"
49 #include "Token.hpp"
50 
52  RexxObject *_expression, /* optional expression */
53  unsigned short type, /* type of numeric instruction */
54  size_t flags) /* processing flags */
55 /****************************************************************************/
56 /* Function: Execute a REXX NUMERIC instruction */
57 /****************************************************************************/
58 {
59  /* copy the expression */
60  OrefSet(this, this->expression, _expression);
61  instructionFlags = (uint16_t)flags;
62  switch (type)
63  {
64  case SUBKEY_DIGITS:
66  break;
67  case SUBKEY_FUZZ:
69  break;
70  case SUBKEY_FORM:
72  break;
73  }
74 }
75 
77  RexxActivation *context, /* current activation context */
78  RexxExpressionStack *stack ) /* evaluation stack */
79 /****************************************************************************/
80 /* Function: Execute a REXX LEAVE instruction */
81 /****************************************************************************/
82 {
83  RexxObject *result; /* expression evaluation result */
84  RexxString *stringResult; /* converted string */
85  stringsize_t setting; /* binary form of the setting */
86 
87  context->traceInstruction(this); /* trace if necessary */
88  /* process the different types of */
89  switch (instructionFlags & numeric_type_mask) /* numeric instruction */
90  {
91  case numeric_digits: /* NUMERIC DIGITS instruction */
92  /* resetting to default digits? */
93  if (this->expression == OREF_NULL)
94  {
95  /* just set it to the default */
96  context->setDigits();
97  }
98  else /* need to evaluate an expression */
99  {
100  /* get the expression value */
101  result = this->expression->evaluate(context, stack);
102  context->traceResult(result); /* trace if necessary */
103  /* bad value? */
104  if (!result->requestUnsignedNumber(setting, number_digits()) || setting < 1)
105  {
106  /* report an exception */
108  }
109  /* problem with the fuzz setting? */
110  if (setting <= context->fuzz())
111  {
112  /* this is an error */
114  }
115  context->setDigits(setting); /* now adjust the setting */
116  }
117  // For the moment, no default value on package (no ::OPTIONS DIGITS <digits> PROPAGATE)
119  break;
120 
121  case numeric_fuzz: /* NUMERIC FUZZ instruction */
122  /* resetting to default fuzz? */
123  if (this->expression == OREF_NULL)
124  {
125  context->setFuzz(); /* just set it to the default */
126  }
127  else /* need to evaluate an expression */
128  {
129  /* get the expression value */
130  result = this->expression->evaluate(context, stack);
131  context->traceResult(result); /* trace if necessary */
132  /* bad value? */
133  if (!result->requestUnsignedNumber(setting, number_digits()))
134  {
135  /* report an exception */
137  }
138  /* problem with the digits setting? */
139  if (setting >= context->digits())
140  {
141  /* and issue the error */
143  }
144  context->setFuzz(setting); /* set the new value */
145  }
146  break;
147 
148  case numeric_form: /* NUMERIC FORM instruction */
149  /* non-VALUE form? */
150  if (this->expression == OREF_NULL)
151  {
152  // if default form, set that
154  {
155  context->setForm();
156  }
157  else
158  {
159 
160  // set it to what was specified.
162  }
163  }
164  else /* need to evaluate an expression */
165  {
166  /* get the expression value */
167  result = this->expression->evaluate(context, stack);
168  /* get the string version */
169  stringResult = REQUEST_STRING(result);
170  /* trace if necessary */
171  context->traceResult(stringResult);
172  /* Scientific form? */
173  if (stringResult->strCompare(CHAR_SCIENTIFIC))
174  {
175  /* set the proper form */
177  }
178  /* Scientific form? */
179  else if (stringResult->strCompare(CHAR_ENGINEERING))
180  {
181  /* set the engineering form */
183  }
184  else
185  {
186  /* report an exception */
188  }
189  }
190  break;
191  }
192  context->pauseInstruction(); /* do debug pause if necessary */
193 }
void reportException(wholenumber_t error)
#define numeric_form
#define numeric_engineering
#define numeric_fuzz
#define numeric_propagate
#define numeric_type_mask
#define numeric_form_default
#define numeric_digits
size_t number_digits()
Definition: Numerics.hpp:147
#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_Expression_result_digits
#define Error_Invalid_whole_number_fuzz
#define Error_Invalid_whole_number_digits
#define Error_Invalid_subkeyword_form
#define SUBKEY_FUZZ
Definition: Token.hpp:215
#define SUBKEY_DIGITS
Definition: Token.hpp:207
#define SUBKEY_FORM
Definition: Token.hpp:214
static const bool FORM_SCIENTIFIC
Definition: Numerics.hpp:76
static const bool FORM_ENGINEERING
Definition: Numerics.hpp:77
void setDigits(size_t)
void setFuzz(size_t)
void traceResult(RexxObject *v)
void traceInstruction(RexxInstruction *v)
bool propagateNumericSettings()
uint16_t instructionFlags
void execute(RexxActivation *, RexxExpressionStack *)
RexxInstructionNumeric(RexxObject *, unsigned short, size_t)
virtual RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
bool requestUnsignedNumber(stringsize_t &, size_t)
bool strCompare(const char *s)
int type
Definition: cmdparse.cpp:1888
size_t stringsize_t
Definition: rexx.h:228
unsigned short uint16_t