ClassClass.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 ClassClass.hpp */
40 /* */
41 /* Primitive Class Class Definitions */
42 /* */
43 /******************************************************************************/
44 #ifndef Included_RexxClass
45 #define Included_RexxClass
46 
47 
48 
49  class RexxClass : public RexxObject {
50  public:
51  void *operator new(size_t, size_t, const char *, RexxBehaviour *, RexxBehaviour *);
52  inline void *operator new(size_t size, void *ptr) {return ptr;};
53  inline void operator delete(void *) { }
54  inline void operator delete(void *, void *) { }
55  inline void operator delete(void *, size_t, const char *, RexxBehaviour *, RexxBehaviour *) { }
56 
57  inline RexxClass(){;};
58  inline RexxClass(RESTORETYPE restoreType) { ; };
59 
60  void live(size_t);
61  void liveGeneral(int reason);
62  void flatten(RexxEnvelope*);
65  bool isEqual(RexxObject *);
66 
67  HashCode hash();
74  RexxObject *isMetaClassRexx(); // ooRexx5
75  RexxObject *isAbstractRexx(); // ooRexx5
76  RexxString *getId();
83  void defmeths(RexxTable *);
88  void subClassable(bool);
89  void subClassable(RexxClass *superClass, bool restricted);
90  void mergeSuperClassScopes(RexxBehaviour *target_instance_behaviour);
94  RexxObject *defineClassMethod(RexxString *method_name, RexxMethod *newMethod);
95  void removeClassMethod(RexxString *method_name);
98  void updateSubClasses();
106  RexxObject *enhanced(RexxObject **, size_t, size_t);
109  RexxClass *mixinClassRexx(RexxString *, RexxClass *, RexxObject *); // ooRexx5 because the C++ mixinclass method takes a new argument 'package'
110  RexxClass *subclassRexx(RexxString *, RexxClass *, RexxObject *); // ooRexx5 because the C++ subclass method takes a new argument 'package'
111  RexxClass *newRexx(RexxObject **args, size_t argCount, size_t named_argCount);
112  void setMetaClass(RexxClass *);
113  bool isCompatibleWith(RexxClass *other);
116  void setPackage(PackageClass *s); // ooRexx5
117  PackageClass *getPackage(); // ooRexx5
118  void completeNewObject(RexxObject *obj, RexxObject **initArgs = OREF_NULL, size_t argCount = 0); // ooRexx5
119 
120 
121  inline bool isRexxDefined() { return (classFlags & REXX_DEFINED) != 0; };
122  inline bool isMixinClass() { return (classFlags & MIXIN) != 0; };
123  inline bool isMetaClass() { return (classFlags & META_CLASS) != 0; };
124  inline bool isAbstract() { return (classFlags & ABSTRACT) != 0; } // ooRexx5
125  inline bool hasUninitDefined() { return (classFlags & HAS_UNINIT) != 0; };
128  // NB: This clears every flag BUT the UNINIT flag
130  inline bool parentHasUninitDefined() { return (classFlags & PARENT_HAS_UNINIT) != 0; };
132  inline bool isPrimitiveClass() { return (classFlags & PRIMITIVE_CLASS) != 0; }
133  inline void setMixinClass() { classFlags |= MIXIN; }
136  inline void setMetaClass() { classFlags |= META_CLASS; }
137  inline void setAbstract() { classFlags |= ABSTRACT; } // ooRexx5
138  inline void clearAbstract() { classFlags &= ~ABSTRACT; } // ooRex5
139  void addSubClass(RexxClass *);
140  void removeSubclass(RexxClass *c);
141  void checkAbstract(); // ooRexx5
142  void makeAbstract(); // ooRexx5
143 
144  static void processNewArgs(RexxObject **, size_t, RexxObject ***, size_t *, size_t, RexxObject **, RexxObject **);
145 
146  static void createInstance();
147  // singleton class instance;
149 
150  protected:
151  enum
152  {
153  REXX_DEFINED = 0x00000001, // this class is a native rexx class
154  MIXIN = 0x00000004, // this is a mixin class
155  HAS_UNINIT = 0x00000008, // this class has an uninit method
156  META_CLASS = 0x00000010, // this class is a meta class
157  PRIMITIVE_CLASS = 0x00000020, // this is a primitive class
158  PARENT_HAS_UNINIT = 0x00000040,
159  ABSTRACT = 0x00000080 // the class is abstract
160  };
161 
162  /* Subclassable and subclassed */
163  RexxString *id; /* classes will have a name string */
164  /* class methods specific to this */
165  /* class */
167  /* instances of this class inherit */
168  RexxBehaviour *instanceBehaviour; /* this behaviour */
169  /* methods added to this class */
171  RexxClass *baseClass; /* Baseclass of this class */
172  RexxArray *metaClass; /* Metaclass of this class */
173  /* Metaclass mdict */
175  RexxIdentityTable *metaClassScopes; /* Metaclass scopes */
176  /* The superclass and any inherited */
177  RexxArray *classSuperClasses; /* mixins for class behaviour */
178  /* The superclass and any inherited */
179  /* mixins for instance behaviour */
181  /* class specific information */
182  /* defines for this field are at the */
183  uint32_t classFlags; /* top of this header file */
184 
185  RexxList *subClasses; // our list of weak referenced subclasses
186  PackageClass *package; // source we're defined in (if any)
187  };
188  #endif
RESTORETYPE
Definition: ObjectClass.hpp:82
size_t HashCode
Definition: ObjectClass.hpp:79
#define OREF_NULL
Definition: RexxCore.h:61
void removeSubclass(RexxClass *c)
void createClassBehaviour(RexxBehaviour *)
Definition: ClassClass.cpp:969
void setHasUninitDefined()
Definition: ClassClass.hpp:126
RexxClass * newRexx(RexxObject **args, size_t argCount, size_t named_argCount)
void setInstanceBehaviour(RexxBehaviour *)
Definition: ClassClass.cpp:324
PackageClass * package
Definition: ClassClass.hpp:186
RexxObject * deleteMethod(RexxString *)
Definition: ClassClass.cpp:821
RexxClass * getSuperClass()
Definition: ClassClass.cpp:333
uint32_t classFlags
Definition: ClassClass.hpp:183
RexxClass * subclassRexx(RexxString *, RexxClass *, RexxObject *)
RexxTable * methodDictionaryCreate(RexxTable *, RexxClass *)
static void createInstance()
void mergeSuperClassScopes(RexxBehaviour *target_instance_behaviour)
void addSubClass(RexxClass *)
Definition: ClassClass.cpp:367
static RexxClass * classInstance
Definition: ClassClass.hpp:148
PackageClass * getPackage()
bool isRexxDefined()
Definition: ClassClass.hpp:121
RexxClass(RESTORETYPE restoreType)
Definition: ClassClass.hpp:58
bool isAbstract()
Definition: ClassClass.hpp:124
void updateInstanceSubClasses()
Definition: ClassClass.cpp:944
void methodDictionaryMerge(RexxTable *, RexxTable *)
RexxClass * baseClass
Definition: ClassClass.hpp:171
void setInitialFlagState()
Definition: ClassClass.hpp:129
RexxTable * instanceMethodDictionary
Definition: ClassClass.hpp:170
RexxMethod * method(RexxString *)
Definition: ClassClass.cpp:850
RexxClass * getMetaClass()
Definition: ClassClass.cpp:309
RexxArray * instanceSuperClasses
Definition: ClassClass.hpp:180
RexxTable * getInstanceBehaviourDictionary()
Definition: ClassClass.cpp:417
bool isPrimitiveClass()
Definition: ClassClass.hpp:132
static void processNewArgs(RexxObject **, size_t, RexxObject ***, size_t *, size_t, RexxObject **, RexxObject **)
RexxObject * inherit(RexxClass *, RexxClass *)
void defmeths(RexxTable *)
Definition: ClassClass.cpp:378
void checkAbstract()
RexxString * defaultNameRexx()
RexxObject * isMetaClassRexx()
Definition: ClassClass.cpp:267
RexxObject * notEqual(RexxObject *)
Definition: ClassClass.cpp:231
RexxArray * getSubClasses()
Definition: ClassClass.cpp:358
void liveGeneral(int reason)
Definition: ClassClass.cpp:87
RexxIdentityTable * metaClassScopes
Definition: ClassClass.hpp:175
void removeClassMethod(RexxString *method_name)
Definition: ClassClass.cpp:803
RexxClass * getBaseClass()
Definition: ClassClass.cpp:301
RexxTable * classMethodDictionary
Definition: ClassClass.hpp:166
RexxObject * defineMethod(RexxString *, RexxMethod *)
Definition: ClassClass.cpp:653
RexxArray * getSuperClasses()
Definition: ClassClass.cpp:348
RexxObject * isAbstractRexx()
Definition: ClassClass.cpp:278
void setPackage(PackageClass *s)
RexxObject * isSubclassOf(RexxClass *other)
RexxObject * enhanced(RexxObject **, size_t, size_t)
RexxObject * unflatten(RexxEnvelope *)
Definition: ClassClass.cpp:120
void updateSubClasses()
Definition: ClassClass.cpp:909
RexxInteger * queryMixinClass()
Definition: ClassClass.cpp:253
RexxBehaviour * getInstanceBehaviour()
Definition: ClassClass.hpp:135
RexxTable * getBehaviourDictionary()
Definition: ClassClass.cpp:435
RexxObject * equal(RexxObject *)
Definition: ClassClass.cpp:209
void setParentHasUninitDefined()
Definition: ClassClass.hpp:131
bool parentHasUninitDefined()
Definition: ClassClass.hpp:130
RexxObject * defineMethods(RexxTable *)
Definition: ClassClass.cpp:725
void clearAbstract()
Definition: ClassClass.hpp:138
RexxObject * setRexxDefined()
Definition: ClassClass.cpp:292
bool isCompatibleWith(RexxClass *other)
void completeNewObject(RexxObject *obj, RexxObject **initArgs=OREF_NULL, size_t argCount=0)
RexxObject * defineClassMethod(RexxString *method_name, RexxMethod *newMethod)
Definition: ClassClass.cpp:772
void setAbstract()
Definition: ClassClass.hpp:137
RexxSupplier * methods(RexxClass *)
Definition: ClassClass.cpp:869
RexxArray * metaClass
Definition: ClassClass.hpp:172
void flatten(RexxEnvelope *)
Definition: ClassClass.cpp:112
RexxClass * mixinClassRexx(RexxString *, RexxClass *, RexxObject *)
RexxBehaviour * instanceBehaviour
Definition: ClassClass.hpp:168
RexxArray * getClassSuperClasses()
Definition: ClassClass.hpp:81
bool hasUninitDefined()
Definition: ClassClass.hpp:125
RexxObject * strictEqual(RexxObject *)
Definition: ClassClass.cpp:172
RexxList * subClasses
Definition: ClassClass.hpp:185
bool isEqual(RexxObject *)
Definition: ClassClass.cpp:181
RexxObject * uninherit(RexxClass *)
void setMetaClass()
Definition: ClassClass.hpp:136
RexxArray * classSuperClasses
Definition: ClassClass.hpp:177
void clearHasUninitDefined()
Definition: ClassClass.hpp:127
void makeAbstract()
void setNonPrimitive()
Definition: ClassClass.hpp:134
RexxString * id
Definition: ClassClass.hpp:163
RexxString * getId()
Definition: ClassClass.cpp:284
bool isMixinClass()
Definition: ClassClass.hpp:122
@ PARENT_HAS_UNINIT
Definition: ClassClass.hpp:158
HashCode getHashValue()
Definition: ClassClass.cpp:163
RexxString * defaultName()
Definition: ClassClass.cpp:403
HashCode hash()
Definition: ClassClass.cpp:149
void live(size_t)
Definition: ClassClass.cpp:67
void createInstanceBehaviour(RexxBehaviour *)
RexxObject * makeProxy(RexxEnvelope *)
Definition: ClassClass.cpp:128
RexxArray * metaClassMethodDictionary
Definition: ClassClass.hpp:174
void subClassable(bool)
Definition: ClassClass.cpp:462
void setMixinClass()
Definition: ClassClass.hpp:133
bool isMetaClass()
Definition: ClassClass.hpp:123
RexxClass * subclass(PackageClass *, RexxString *, RexxClass *, RexxTable *)
RexxClass * mixinclass(PackageClass *, RexxString *, RexxClass *, RexxTable *)
unsigned int uint32_t