ExpressionList.cpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2014 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 logical list evaluator */
42 /* */
43 /******************************************************************************/
44 #include "RexxCore.h"
45 #include "ExpressionList.hpp"
46 #include "QueueClass.hpp"
47 #include "RexxActivation.hpp"
48 #include "ArrayClass.hpp"
49 #include "RexxInstruction.hpp"
50 
51 
52 /**
53  * Create a new expression list object.
54  *
55  * @param size The size of the class object.
56  * @param count The count of logical expressions. Used to adjust the
57  * allocated size to the requirements.
58  *
59  * @return A new RexxExpressionLogical object.
60  */
61 void *RexxExpressionList::operator new(size_t size, size_t count)
62 {
63  return new_object(size + (count - 1) * sizeof(RexxObject *), T_ListTerm);
64 }
65 
66 
67 /**
68  * Constructor for a RexxExpressionList object.
69  *
70  * @param count The number of expressions in the list.
71  * @param list The accumulated list of expressions.
72  */
74 {
75  expressionCount = count;
76 
77  // now copy the expressions from the sub term stack
78  // NOTE: The expressionss are in last-to-first order on the stack.
80 }
81 
82 
83 /**
84  * The runtime, non-debug live marking routine.
85  */
86 void RexxExpressionList::live(size_t liveMark)
87 {
89 }
90 
91 
92 /**
93  * The generalized live marking routine used for non-performance
94  * critical marking operations.
95  */
97 {
99 }
100 
101 
102 /**
103  * The flattening routine, used for serializing object trees.
104  *
105  * @param envelope The envelope were's flattening into.
106  */
108 {
110 
112 
114 }
115 
116 /**
117  * Evaluate an expression list.
118  *
119  * @param context The execution context.
120  * @param stack The evaluation stack.
121  *
122  * @return An array
123  */
125 {
126  // loop through the expression list evaulating and then testing for the
127  // logical value
128  size_t count = expressionCount;
129 
130  // save the top of the stack for popping values off later.
131  size_t stacktop = stack->location();
132 
133  // create a result array with a matching size
135  ProtectedObject resultP(result);
136 
137  for (size_t i = 0; i < count; i++)
138  {
139  // evaluate and trace
140  RexxInternalObject *expr = expressions[i];
141  // if this is a real expression (omitted expressions are permitted)
142  if (expr != OREF_NULL)
143  {
144  RexxObject *value = expr->evaluate(context, stack);
145  // trace this as an argument value
146  // context->traceArgument(value);
147  context->traceIntermediate(value, TRACE_PREFIX_ARGUMENT);
148 
149  // add this to the created array
150  result->put(value, i + 1);
151  }
152  }
153 
154  // remove the arguments from the stack and push our result
155  stack->setTop(stacktop);
156  stack->push(result);
157 
158  // TODO: Need to reassess how this final result is traced.
159  // trace the array result and return it
160  context->traceResult(result);
161  return result;
162 }
163 
RexxArray * new_array(size_t s)
Definition: ArrayClass.hpp:259
@ T_ListTerm
@ TRACE_PREFIX_ARGUMENT
#define OREF_NULL
Definition: RexxCore.h:61
#define initializeObjectArray(count, array, type, queue)
RexxObject * new_object(size_t s)
Definition: RexxMemory.hpp:436
#define memory_mark_array(count, array)
Definition: RexxMemory.hpp:454
#define cleanUpFlatten
Definition: RexxMemory.hpp:484
#define memory_mark_general_array(count, array)
Definition: RexxMemory.hpp:460
#define setUpFlatten(type)
Definition: RexxMemory.hpp:478
#define flattenArrayRefs(count, array)
Definition: RexxMemory.hpp:491
void traceResult(RexxObject *v)
void traceIntermediate(RexxObject *v, int p)
void put(RexxObject *eref, size_t pos)
Definition: ArrayClass.cpp:208
virtual void live(size_t)
RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
virtual void flatten(RexxEnvelope *)
RexxExpressionList(size_t, RexxQueue *)
RexxInternalObject * expressions[1]
virtual void liveGeneral(int reason)
void push(RexxObject *value)
void setTop(size_t v)
virtual RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)