RexxBehaviour.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 RexxBehaviour.hpp */
40 /* */
41 /* Primitive Behaviour Class Definitions */
42 /* */
43 /*******************************************************************************/
44 #ifndef Included_RexxBehaviour
45 #define Included_RexxBehaviour
46 
47 #define INTERNALCLASS (((uintptr_t)1) << ((sizeof(uintptr_t) * 8) - 1))
48 
50  {
51  public:
52  void *operator new(size_t, size_t);
53  inline void *operator new(size_t size, void *ptr) {return ptr;};
54  inline void operator delete(void *) { ; }
55  inline void operator delete(void *, size_t) { }
56  inline void operator delete(void *, void *) { ; }
57 
58  RexxBehaviour(size_t, PCPPM *);
59  inline RexxBehaviour() {;};
60  inline RexxBehaviour(RESTORETYPE restoreType) { ; };
61  void live(size_t);
62  void liveGeneral(int reason);
63  void flatten(RexxEnvelope*);
64  RexxObject *copy();
65  void copyBehaviour(RexxBehaviour *source);
67  RexxMethod *define(const char *, PCPPM, size_t, bool);
68  void addMethod(RexxString *, RexxMethod *);
69  void removeMethod(RexxString *);
74  void restore(RexxBehaviour *);
82  bool checkScope( RexxObject *);
83  void subclass(RexxBehaviour *);
85 
87 
88  void merge( RexxBehaviour *);
90 
91 
92  inline RexxIdentityTable *getScopes() { return this->scopes; };
93  inline RexxTable *getMethodDictionary() { return this->methodDictionary; };
94  inline void setMethodDictionary(RexxTable * m) { OrefSet(this, this->methodDictionary, m); };
97  inline RexxClass *getOwningClass() { return this->owningClass;};
98  inline void setOwningClass(RexxClass *c) { OrefSet(this, this->owningClass, c); };
99 
100  inline void setClassType(size_t n) { classType = (uint16_t)n; }
101  inline size_t getClassType() { return (size_t)classType; }
102  inline bool isPrimitive() { return (behaviourFlags & NON_PRIMITIVE_BEHAVIOUR) == 0; };
103  inline bool isNonPrimitive() { return (behaviourFlags & NON_PRIMITIVE_BEHAVIOUR) != 0; };
104  inline bool isNotResolved() { return (behaviourFlags & BEHAVIOUR_NOT_RESOLVED) != 0; };
105  inline bool isResolved() { return (behaviourFlags & BEHAVIOUR_NOT_RESOLVED) == 0; };
106  inline bool isEnhanced() { return (behaviourFlags & ENHANCED_OBJECT) != 0; };
107  inline bool isInternalClass() { return (behaviourFlags & INTERNAL_CLASS) != 0; };
108  inline bool isTransientClass() { return (behaviourFlags & TRANSIENT_CLASS) != 0; };
115 
117  {
118  uintptr_t behaviourID = (uintptr_t)this->getClassType();
119  // if this is an internal class, normalize this so we can
120  // restore this to the correct value if we add additional internal classes.
121  if (isInternalClass())
122  {
123  behaviourID -= T_Last_Exported_Class;
124  behaviourID |= INTERNALCLASS;
125  }
126  return (RexxBehaviour *)behaviourID;
127  }
128 
130  {
131  uintptr_t behaviourID = (uintptr_t)b;
132  // if this is an internal class, we need to convert back to
133  // the relative internal class id
134  if ((behaviourID & INTERNALCLASS) != 0)
135  {
136  behaviourID &= ~INTERNALCLASS; // turn off the internal marker
137  behaviourID += T_Last_Exported_Class; // turn back into an internal class
138  }
139  return &primitiveBehaviours[behaviourID]; // translate back into proper behaviour
140  }
141 
142  inline PCPPM getOperatorMethod(size_t index) { return operatorMethods[index]; }
143  static inline RexxBehaviour *getPrimitiveBehaviour(size_t index) { return &primitiveBehaviours[index]; }
144  static inline PCPPM *getOperatorMethods(size_t index) { return getPrimitiveBehaviour(index)->operatorMethods; }
145  // table of primitive behaviour objects
147 
148  protected:
149 
150  enum
151  {
153  ENHANCED_OBJECT = 0x0002,
154  INTERNAL_CLASS = 0x0004,
155  TRANSIENT_CLASS = 0x0008,
156  BEHAVIOUR_NOT_RESOLVED = 0x0010
157  };
158 
159 
160  uint16_t classType; // primitive class identifier
161  uint16_t behaviourFlags; // various behaviour flag types
162  RexxIdentityTable *scopes; /* scopes table */
163  RexxTable *methodDictionary; /* method dictionary */
164  PCPPM *operatorMethods; /* operator look-a-side table */
165  RexxClass *owningClass; /* class that created this object */
166  /* methods added via SETMETHOD */
168 
169  };
170 
171 
172 /******************************************************************************/
173 /* Global Objects - Primitive Behaviour */
174 /******************************************************************************/
175 
176 #include "PrimitiveBehaviourNames.h"
177 
178 #endif
@ T_Last_Exported_Class
RESTORETYPE
Definition: ObjectClass.hpp:80
RexxObject *(RexxObject::* PCPPM)()
#define INTERNALCLASS
#define OrefSet(o, r, v)
Definition: RexxCore.h:94
uint16_t behaviourFlags
RexxMethod * methodLookup(RexxString *)
RexxTable * getMethodDictionary()
static RexxBehaviour * restoreSavedPrimitiveBehaviour(RexxBehaviour *b)
void merge(RexxBehaviour *)
void setMethodDictionaryScope(RexxObject *)
RexxMethod * getMethod(RexxString *)
RexxObject * mergeScope(RexxObject *)
RexxObject * addScope(RexxObject *)
void methodDictionaryMerge(RexxTable *)
RexxTable * methodDictionary
void restore(RexxBehaviour *)
void setNonPrimitive()
RexxObject * define(RexxString *, RexxMethod *)
RexxObject * copy()
void removeMethod(RexxString *)
void live(size_t)
RexxClass * getOwningClass()
void setMethodDictionary(RexxTable *m)
RexxMethod * methodObject(RexxString *)
RexxSupplier * getMethods(RexxObject *scope)
RexxClass * restoreClass()
RexxObject * deleteMethod(RexxString *)
RexxTable * instanceMethodDictionary
void flatten(RexxEnvelope *)
uint16_t classType
PCPPM getOperatorMethod(size_t index)
RexxObject * setScopes(RexxIdentityTable *)
RexxBehaviour * getSavedPrimitiveBehaviour()
bool checkScope(RexxObject *)
static RexxBehaviour * getPrimitiveBehaviour(size_t index)
RexxIdentityTable * getScopes()
RexxTable * getInstanceMethodDictionary()
RexxBehaviour(RESTORETYPE restoreType)
RexxIdentityTable * scopes
void setClassType(size_t n)
RexxMethod * superMethod(RexxString *, RexxObject *)
void subclass(RexxBehaviour *)
void copyBehaviour(RexxBehaviour *source)
bool isTransientClass()
static RexxBehaviour primitiveBehaviours[]
void liveGeneral(int reason)
void resolveNonPrimitiveBehaviour()
void setInternalClass()
RexxObject * superScope(RexxObject *)
void setInstanceMethodDictionary(RexxTable *m)
RexxClass * owningClass
static PCPPM * getOperatorMethods(size_t index)
bool isInternalClass()
void addMethod(RexxString *, RexxMethod *)
size_t getClassType()
void setTransientClass()
PCPPM * operatorMethods
void setOwningClass(RexxClass *c)
unsigned short uint16_t
UINT_PTR uintptr_t