StackClass.hpp
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 Kernel StackClass.hpp */
40 /* */
41 /* Primitive Stack Class Definitions */
42 /* */
43 /******************************************************************************/
44 #ifndef Included_RexxStack
45 #define Included_RexxStack
46 
47  class RexxStack : public RexxInternalObject {
48  public:
49  inline void *operator new(size_t size, void *ptr) { return ptr; }
50  void *operator new(size_t, size_t, bool temporary);
51  inline void operator delete(void *) { }
52  inline void operator delete(void *, void *) { }
53  inline void operator delete(void *, size_t, bool temporary) { };
54 
55  inline RexxStack(RESTORETYPE restoreType) { ; };
56  RexxStack(size_t size);
57 
58  void init(size_t);
59  void live(size_t);
60  void liveGeneral(int reason);
61  void flatten(RexxEnvelope *);
62  RexxObject *get(size_t pos);
63  inline RexxObject *push(RexxObject *obj)
64  { incrementTop();
65  return *(this->stack + this->top) = obj;
66  }
67  RexxObject *pop();
68  RexxObject *fpop();
69 
70  inline void fastPush(RexxObject *element) { this->stack[++(this->top)] = element; };
71  inline bool checkRoom() { return this->top < this->size-1; }
72  inline RexxObject *fastPop() { return this->stack[(this->top)--]; };
73  inline size_t stackSize() { return this->size; };
74  inline RexxObject *stackTop() { return (*(this->stack + this->top)); };
75  inline void decrementTop() { top = (top == 0) ? size - 1 : top - 1; }
76  inline void incrementTop() { if (++top >= size) top = 0; }
77  /* (other->size + 1) was wrong !? */
78  inline void copyEntries(RexxStack *other) { memcpy((char *)this->stack, other->stack, other->size * sizeof(RexxObject *)); this->top = other->top; }
79 
80  size_t size; // the stack size
81  size_t top; /* top position on the stack */
82  RexxObject *stack[1]; /* stack entries */
83  };
84 
85  class RexxSaveStack : public RexxStack {
86  public:
87  void *operator new(size_t, size_t);
88  inline void operator delete(void *) { ; }
89  inline void operator delete(void *, size_t) { }
90 
91  RexxSaveStack(size_t, size_t);
92  void live(size_t);
93  void init(size_t, size_t);
94  void extend(size_t);
95  void remove(RexxObject *, bool search = false);
96 
97  size_t allocSize;
98  };
99 
100 #endif
RESTORETYPE
Definition: ObjectClass.hpp:82
void remove(RexxObject *, bool search=false)
Definition: StackClass.cpp:226
void extend(size_t)
Definition: StackClass.cpp:214
size_t allocSize
Definition: StackClass.hpp:97
void live(size_t)
Definition: StackClass.cpp:265
RexxSaveStack(size_t, size_t)
Definition: StackClass.cpp:179
void init(size_t, size_t)
Definition: StackClass.cpp:190
void fastPush(RexxObject *element)
Definition: StackClass.hpp:70
void init(size_t)
Definition: StackClass.cpp:60
void live(size_t)
Definition: StackClass.cpp:71
void flatten(RexxEnvelope *)
Definition: StackClass.cpp:98
RexxObject * fastPop()
Definition: StackClass.hpp:72
void copyEntries(RexxStack *other)
Definition: StackClass.hpp:78
void liveGeneral(int reason)
Definition: StackClass.cpp:84
RexxObject * fpop()
Definition: StackClass.cpp:138
void decrementTop()
Definition: StackClass.hpp:75
RexxObject * stackTop()
Definition: StackClass.hpp:74
size_t size
Definition: StackClass.hpp:80
RexxObject * stack[1]
Definition: StackClass.hpp:82
void incrementTop()
Definition: StackClass.hpp:76
size_t stackSize()
Definition: StackClass.hpp:73
RexxObject * push(RexxObject *obj)
Definition: StackClass.hpp:63
RexxObject * pop()
Definition: StackClass.cpp:126
RexxStack(RESTORETYPE restoreType)
Definition: StackClass.hpp:55
bool checkRoom()
Definition: StackClass.hpp:71
size_t top
Definition: StackClass.hpp:81
RexxObject * get(size_t pos)
Definition: StackClass.cpp:111