MethodClass.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 MethodClass.hpp */
40 /* */
41 /* Primitive Kernel Method Class Definitions */
42 /* */
43 /******************************************************************************/
44 #ifndef Included_RexxMethod
45 #define Included_RexxMethod
46 
47 #include "RexxCore.h"
48 
49 class RexxSource;
50 class RexxActivity;
51 class RexxMethod;
52 class ProtectedObject;
53 class RexxArray;
54 class RexxClass;
55 class PackageClass;
56 
57 
58 typedef enum
59 {
60  DEFAULT_GUARD, // default guard
61  GUARDED_METHOD, // guard specified
62  UNGUARDED_METHOD, // unguarded specified
63 } GuardFlag; // ooRexx5
64 
65 typedef enum
66 {
67  DEFAULT_PROTECTION, // using defualt protection
68  PROTECTED_METHOD, // security manager permission needed
69  UNPROTECTED_METHOD, // no protection.
70 } ProtectedFlag; // ooRexx5
71 
72 typedef enum
73 {
74  DEFAULT_ACCESS_SCOPE, // using defualt scope
75  PUBLIC_SCOPE, // publicly accessible
76  PRIVATE_SCOPE, // private scope
77  PACKAGE_SCOPE, // package scope
78 } AccessFlag; // ooRexx5
79 
80 /**
81  * Base class for a code object. Code objects can be invoked as
82  * methods, or called.
83  */
85 {
86 public:
87  virtual void run(RexxActivity *, RexxMethod *, RexxObject *, RexxString *, RexxObject **, size_t, size_t, ProtectedObject &);
88  virtual void call(RexxActivity *, RoutineClass *, RexxString *, RexxObject **, size_t, size_t, RexxString *, RexxString *, int, ProtectedObject &);
89  virtual void call(RexxActivity *, RoutineClass *, RexxString *, RexxObject **, size_t, size_t, ProtectedObject &);
90  virtual RexxArray *getSource();
91  virtual RexxObject *setSecurityManager(RexxObject *manager);
92  virtual RexxSource *getSourceObject();
93  virtual RexxClass *findClass(RexxString *className);
94  virtual BaseCode *setSourceObject(RexxSource *s); // ooRexx5 uses setPackageObject
95  virtual PackageClass *getPackage();
96 
97  inline bool isSamePackage(PackageClass *p) { return p == getPackage(); } // ooRexx5
98 };
99  /* pointer to native method function */
101  /* pointer to native function function*/
103 
104 typedef size_t (RexxEntry *PREGISTEREDROUTINE)(const char *, size_t, PCONSTRXSTRING, const char *, PRXSTRING);
105 
107 {
108 public:
109  inline RexxSource *getSourceObject() { return code->getSourceObject(); };
110  inline BaseCode *getCode() { return code; }
111  RexxArray *getSource() { return code->getSource(); }
113 
114  RexxArray *source();
115  RexxClass *findClass(RexxString *className);
116  BaseExecutable *setSourceObject(RexxSource *s); // ooRexx5 uses setPackageObject
118  void setName(RexxString *name) { executableName = name; }
119 
120 protected:
121  RexxString *executableName; // the created name of this routine
122  BaseCode *code; // the backing code object
123 };
124 
125 
126  class RexxMethod : public BaseExecutable
127  {
128  public:
129  void *operator new(size_t);
130  inline void *operator new(size_t size, void *ptr) { return ptr; };
131  RexxMethod(RexxString *name, BaseCode *_code);
133  RexxMethod(RexxString *name);
135  RexxMethod(RexxString *name, const char *data, size_t length);
137  inline RexxMethod(RESTORETYPE restoreType) { ; };
138 
140  void live(size_t);
141  void liveGeneral(int reason);
142  void flatten(RexxEnvelope*);
143 
144  void run(RexxActivity *, RexxObject *, RexxString *, RexxObject **, size_t, size_t, ProtectedObject &);
146  void setScope(RexxClass *);
153 
156  RexxObject *isPackageRexx(); // ooRexx5
158  RexxObject *isAbstractRexx(); // ooRexx5
159  RexxObject *isConstantRexx(); // ooRexx5
160  RexxObject *isAttributeRexx(); // ooRexx5
161 
162  inline bool isGuarded() {return (this->methodFlags & UNGUARDED_FLAG) == 0; };
163  inline bool isPrivate() {return (this->methodFlags & PRIVATE_FLAG) != 0;}
164  inline bool isProtected() {return (this->methodFlags & PROTECTED_FLAG) != 0;}
165  inline bool isPackageScope() {return (this->methodFlags & PACKAGE_FLAG) != 0;} // ooRexx5
166  inline bool isSpecial() {return (this->methodFlags & (PROTECTED_FLAG | PRIVATE_FLAG | PACKAGE_FLAG)) != 0;}
167  inline bool isConstant() {return (this->methodFlags & CONSTANT_METHOD) != 0;} // ooRexx5
168  inline bool isAttribute() {return (this->methodFlags & ATTRIBUTE_METHOD) != 0;} // ooRexx5
169  inline bool isAbstract() {return (this->methodFlags & ABSTRACT_METHOD) != 0;} // ooRexx5
170 
171  inline void setUnguarded() {this->methodFlags |= UNGUARDED_FLAG;};
172  inline void setGuarded() {this->methodFlags &= ~UNGUARDED_FLAG;};
173  // On 03/07/2014, rev 10273, setPrivate was modified to no longer apply the flag PROTECTED_FLAG
174  inline void setPrivate() {this->methodFlags |= (PRIVATE_FLAG /* | PROTECTED_FLAG */);};
175  inline void setPackageScope() {this->methodFlags |= PACKAGE_FLAG;} // ooRexx5
176  inline void setProtected() {this->methodFlags |= PROTECTED_FLAG;};
177  inline void setConstant() {this->methodFlags |= CONSTANT_METHOD;} // ooRexx5
178  inline void setAttribute() {this->methodFlags |= ATTRIBUTE_METHOD;} // ooRexx5
179  inline void clearAttribute() {this->methodFlags &= ~ATTRIBUTE_METHOD;} // ooRexx5
180  inline void setAbstract() {this->methodFlags |= ABSTRACT_METHOD;} // ooRexx5
181  inline void setAttribute(bool v) {v ? setAttribute() : clearAttribute();} // ooRexx5
182  void setAttributes(AccessFlag access, ProtectedFlag _protected, GuardFlag _guarded);
183  inline RexxClass *getScope() {return this->scope;}
184  RexxString *getScopeName(); // ooRexx5
185  RexxObject *getScopeRexx(); // ooRexx5
186 
187  inline BaseCode *getCode() { return this->code; }
188  RexxMethod *newRexx(RexxObject **, size_t, size_t);
190  RexxMethod *loadExternalMethod(RexxString *name, RexxString *descriptor);
191  inline bool isSamePackage(PackageClass *p) { return code->isSamePackage(p); } // ooRexx5
192 
193  static RexxMethod *newMethodObject(RexxString *, RexxObject *, RexxObject *, RexxSource *a, bool isBlock=false);
194  static RexxMethod *restore(RexxBuffer *, char *, size_t length);
195 
196  static void createInstance();
198 
199  protected:
200  enum
201  {
202  PRIVATE_FLAG = 0x01, // private method
203  UNGUARDED_FLAG = 0x02, // Method can run with GUARD OFF
204  PROTECTED_FLAG = 0x04, // method is protected
205  ATTRIBUTE_METHOD = 0x08, // defined as an attribute method
206  CONSTANT_METHOD = 0x10, // defined as a constant method
207  ABSTRACT_METHOD = 0x20, // defined as an abstract method
208  PACKAGE_FLAG = 0x40 // defined as a package scope method // ooRexx5
209  };
210 
211  size_t methodFlags; // method status flags
212  RexxClass *scope; /* pointer to the method scope */
213 };
214 
215 #endif
AccessFlag
Definition: MethodClass.hpp:73
@ PUBLIC_SCOPE
Definition: MethodClass.hpp:75
@ PRIVATE_SCOPE
Definition: MethodClass.hpp:76
@ PACKAGE_SCOPE
Definition: MethodClass.hpp:77
@ DEFAULT_ACCESS_SCOPE
Definition: MethodClass.hpp:74
size_t(RexxEntry * PREGISTEREDROUTINE)(const char *, size_t, PCONSTRXSTRING, const char *, PRXSTRING)
GuardFlag
Definition: MethodClass.hpp:59
@ GUARDED_METHOD
Definition: MethodClass.hpp:61
@ UNGUARDED_METHOD
Definition: MethodClass.hpp:62
@ DEFAULT_GUARD
Definition: MethodClass.hpp:60
uint16_t *(RexxEntry * PNATIVEMETHOD)(RexxMethodContext *, ValueDescriptor *)
uint16_t *(RexxEntry * PNATIVEROUTINE)(RexxCallContext *, ValueDescriptor *)
ProtectedFlag
Definition: MethodClass.hpp:66
@ UNPROTECTED_METHOD
Definition: MethodClass.hpp:69
@ PROTECTED_METHOD
Definition: MethodClass.hpp:68
@ DEFAULT_PROTECTION
Definition: MethodClass.hpp:67
RESTORETYPE
Definition: ObjectClass.hpp:82
virtual BaseCode * setSourceObject(RexxSource *s)
bool isSamePackage(PackageClass *p)
Definition: MethodClass.hpp:97
virtual RexxArray * getSource()
virtual void run(RexxActivity *, RexxMethod *, RexxObject *, RexxString *, RexxObject **, size_t, size_t, ProtectedObject &)
virtual RexxSource * getSourceObject()
virtual PackageClass * getPackage()
virtual RexxObject * setSecurityManager(RexxObject *manager)
virtual RexxClass * findClass(RexxString *className)
virtual void call(RexxActivity *, RoutineClass *, RexxString *, RexxObject **, size_t, size_t, RexxString *, RexxString *, int, ProtectedObject &)
BaseCode * getCode()
PackageClass * getPackage()
RexxString * getName()
RexxArray * getSource()
RexxArray * source()
RexxString * executableName
void setName(RexxString *name)
RexxClass * findClass(RexxString *className)
Definition: MethodClass.cpp:87
BaseCode * code
RexxSource * getSourceObject()
BaseExecutable * setSourceObject(RexxSource *s)
RexxMethod * newRexx(RexxObject **, size_t, size_t)
bool isProtected()
static void createInstance()
Definition: MethodClass.cpp:74
void setConstant()
void setAbstract()
void liveGeneral(int reason)
void execute(RexxObject *, RexxObject *)
RexxSmartBuffer * saveMethod()
RexxObject * isPrivateRexx()
void clearAttribute()
void setGuarded()
bool isPackageScope()
RexxObject * setPrivateRexx()
void setPrivate()
bool isPrivate()
RexxObject * isAttributeRexx()
static RexxMethod * restore(RexxBuffer *, char *, size_t length)
RexxObject * setUnguardedRexx()
void setAttribute()
RexxObject * setProtectedRexx()
RexxObject * setSecurityManager(RexxObject *)
bool isAbstract()
RexxClass * scope
void setPackageScope()
void setAttribute(bool v)
RexxObject * isProtectedRexx()
RexxObject * isAbstractRexx()
void run(RexxActivity *, RexxObject *, RexxString *, RexxObject **, size_t, size_t, ProtectedObject &)
RexxMethod * newFileRexx(RexxString *)
RexxObject * getScopeRexx()
bool isSpecial()
void flatten(RexxEnvelope *)
RexxObject * isGuardedRexx()
RexxMethod * loadExternalMethod(RexxString *name, RexxString *descriptor)
bool isSamePackage(PackageClass *p)
static RexxClass * classInstance
void setScope(RexxClass *)
RexxObject * isPackageRexx()
RexxMethod(RESTORETYPE restoreType)
bool isConstant()
static RexxMethod * newMethodObject(RexxString *, RexxObject *, RexxObject *, RexxSource *a, bool isBlock=false)
void setAttributes(AccessFlag access, ProtectedFlag _protected, GuardFlag _guarded)
bool isGuarded()
RexxString * getScopeName()
void setUnguarded()
RexxObject * isConstantRexx()
RexxClass * getScope()
void live(size_t)
void setProtected()
size_t methodFlags
BaseCode * getCode()
bool isAttribute()
RexxObject * setGuardedRexx()
RexxMethod * newScope(RexxClass *)
RexxMethod(RexxString *name, BaseCode *_code)
RXSTRING * PRXSTRING
Definition: rexx.h:185
CONSTANT_RXSTRING * PCONSTRXSTRING
Definition: rexx.h:186
#define RexxEntry
Definition: rexx.h:235
unsigned short uint16_t