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 /**
59  * Base class for a code object. Code objects can be invoked as
60  * methods, or called.
61  */
63 {
64 public:
65  virtual void run(RexxActivity *, RexxMethod *, RexxObject *, RexxString *, RexxObject **, size_t, size_t, ProtectedObject &);
66  virtual void call(RexxActivity *, RoutineClass *, RexxString *, RexxObject **, size_t, size_t, RexxString *, RexxString *, int, ProtectedObject &);
67  virtual void call(RexxActivity *, RoutineClass *, RexxString *, RexxObject **, size_t, size_t, ProtectedObject &);
68  virtual RexxArray *getSource();
69  virtual RexxObject *setSecurityManager(RexxObject *manager);
70  virtual RexxSource *getSourceObject();
71  virtual RexxClass *findClass(RexxString *className);
72  virtual BaseCode *setSourceObject(RexxSource *s);
73  virtual PackageClass *getPackage();
74 };
75  /* pointer to native method function */
77  /* pointer to native function function*/
79 
80 typedef size_t (RexxEntry *PREGISTEREDROUTINE)(const char *, size_t, PCONSTRXSTRING, const char *, PRXSTRING);
81 
82 class BaseExecutable : public RexxObject
83 {
84 public:
85  inline RexxSource *getSourceObject() { return code->getSourceObject(); };
86  inline BaseCode *getCode() { return code; }
87  RexxArray *getSource() { return code->getSource(); }
89 
90  RexxArray *source();
91  RexxClass *findClass(RexxString *className);
94  void setName(RexxString *name) { executableName = name; }
95 
96 protected:
97  RexxString *executableName; // the created name of this routine
98  BaseCode *code; // the backing code object
99 };
100 
101 
102  class RexxMethod : public BaseExecutable
103  {
104  public:
105  void *operator new(size_t);
106  inline void *operator new(size_t size, void *ptr) { return ptr; };
107  RexxMethod(RexxString *name, BaseCode *_code);
109  RexxMethod(RexxString *name);
111  RexxMethod(RexxString *name, const char *data, size_t length);
113  inline RexxMethod(RESTORETYPE restoreType) { ; };
114 
116  void live(size_t);
117  void liveGeneral(int reason);
118  void flatten(RexxEnvelope*);
119 
120  void run(RexxActivity *, RexxObject *, RexxString *, RexxObject **, size_t, size_t, ProtectedObject &);
122  void setScope(RexxClass *);
129 
133 
134  inline bool isGuarded() {return (this->methodFlags & UNGUARDED_FLAG) == 0; };
135  inline bool isPrivate() {return (this->methodFlags & PRIVATE_FLAG) != 0;}
136  inline bool isProtected() {return (this->methodFlags & PROTECTED_FLAG) != 0;}
137  inline bool isSpecial() {return (this->methodFlags & (PROTECTED_FLAG | PRIVATE_FLAG)) != 0;}
138 
139  inline void setUnguarded() {this->methodFlags |= UNGUARDED_FLAG;};
140  inline void setGuarded() {this->methodFlags &= ~UNGUARDED_FLAG;};
141  // On 03/07/2014, rev 10273, setPrivate was modified to no longer apply the flag PROTECTED_FLAG
142  inline void setPrivate() {this->methodFlags |= (PRIVATE_FLAG /* | PROTECTED_FLAG */);};
143  inline void setProtected() {this->methodFlags |= PROTECTED_FLAG;};
144  void setAttributes(bool _private, bool _protected, bool _guarded);
145  inline RexxClass *getScope() {return this->scope;}
146 
147  inline BaseCode *getCode() { return this->code; }
148  RexxMethod *newRexx(RexxObject **, size_t, size_t);
150  RexxMethod *loadExternalMethod(RexxString *name, RexxString *descriptor);
151 
152  static RexxMethod *newMethodObject(RexxString *, RexxObject *, RexxObject *, RexxSource *a, bool isBlock=false);
153  static RexxMethod *restore(RexxBuffer *, char *, size_t length);
154 
155  static void createInstance();
157 
158  protected:
159  enum
160  {
161  PRIVATE_FLAG = 0x01, // private method
162  UNGUARDED_FLAG = 0x02, // Method can run with GUARD OFF
163  PROTECTED_FLAG = 0x40, // method is protected
164  };
165 
166  size_t methodFlags; // method status flags
167  RexxClass *scope; /* pointer to the method scope */
168 };
169 
170 #endif
size_t(RexxEntry * PREGISTEREDROUTINE)(const char *, size_t, PCONSTRXSTRING, const char *, PRXSTRING)
Definition: MethodClass.hpp:80
uint16_t *(RexxEntry * PNATIVEMETHOD)(RexxMethodContext *, ValueDescriptor *)
Definition: MethodClass.hpp:76
uint16_t *(RexxEntry * PNATIVEROUTINE)(RexxCallContext *, ValueDescriptor *)
Definition: MethodClass.hpp:78
RESTORETYPE
Definition: ObjectClass.hpp:80
virtual BaseCode * setSourceObject(RexxSource *s)
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()
Definition: MethodClass.hpp:86
PackageClass * getPackage()
RexxString * getName()
Definition: MethodClass.hpp:93
RexxArray * getSource()
Definition: MethodClass.hpp:87
RexxArray * source()
RexxString * executableName
Definition: MethodClass.hpp:97
void setName(RexxString *name)
Definition: MethodClass.hpp:94
RexxClass * findClass(RexxString *className)
Definition: MethodClass.cpp:87
BaseCode * code
Definition: MethodClass.hpp:98
RexxSource * getSourceObject()
Definition: MethodClass.hpp:85
BaseExecutable * setSourceObject(RexxSource *s)
RexxMethod * newRexx(RexxObject **, size_t, size_t)
bool isProtected()
static void createInstance()
Definition: MethodClass.cpp:74
void liveGeneral(int reason)
void execute(RexxObject *, RexxObject *)
RexxSmartBuffer * saveMethod()
RexxObject * isPrivateRexx()
void setGuarded()
RexxObject * setPrivateRexx()
void setPrivate()
bool isPrivate()
static RexxMethod * restore(RexxBuffer *, char *, size_t length)
RexxObject * setUnguardedRexx()
RexxObject * setProtectedRexx()
RexxObject * setSecurityManager(RexxObject *)
RexxClass * scope
void setAttributes(bool _private, bool _protected, bool _guarded)
RexxObject * isProtectedRexx()
void run(RexxActivity *, RexxObject *, RexxString *, RexxObject **, size_t, size_t, ProtectedObject &)
RexxMethod * newFileRexx(RexxString *)
bool isSpecial()
void flatten(RexxEnvelope *)
RexxObject * isGuardedRexx()
RexxMethod * loadExternalMethod(RexxString *name, RexxString *descriptor)
static RexxClass * classInstance
void setScope(RexxClass *)
RexxMethod(RESTORETYPE restoreType)
static RexxMethod * newMethodObject(RexxString *, RexxObject *, RexxObject *, RexxSource *a, bool isBlock=false)
bool isGuarded()
void setUnguarded()
RexxClass * getScope()
void live(size_t)
void setProtected()
size_t methodFlags
BaseCode * getCode()
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:412
unsigned short uint16_t