RexxNativeActivation.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 RexxNativeActivation.hpp */
40 /* */
41 /* Primitive Native Activation Class Definitions */
42 /* */
43 /******************************************************************************/
44 #ifndef Included_RexxNativeActivation
45 #define Included_RexxNativeActivation
46 
47 #include "RexxActivity.hpp"
48 class RexxNativeCode;
49 class ActivityDispatcher;
50 class CallbackDispatcher;
51 class TrappingDispatcher;
52 class RexxNativeMethod;
53 class RexxNativeRoutine;
54 class RegisteredRoutine;
55 class RexxStem;
56 class RexxSupplier;
57 class StackFrameClass;
58 class RexxIdentityTable;
59 
60 #define MAX_NATIVE_ARGUMENTS 16
61 
63 {
64  public:
65  void *operator new(size_t);
66  inline void *operator new(size_t size, void *ptr) {return ptr;};
67  inline void operator delete(void *, void *) { ; }
68  inline void operator delete(void *) { ; }
69 
70  inline RexxNativeActivation(RESTORETYPE restoreType) { ; };
72  RexxNativeActivation(RexxActivity *_activity, RexxActivation *_activation);
74  void live(size_t);
75  void liveGeneral(int reason);
76  void run(RexxMethod *_method, RexxNativeMethod *_code, RexxObject *_receiver,
77  RexxString *_msgname, RexxObject **_arglist, size_t _argcount, size_t _named_argcount, ProtectedObject &resultObj);
78  void run(ActivityDispatcher &dispatcher);
79  void run(CallbackDispatcher &dispatcher);
80  void run(TrappingDispatcher &dispatcher);
82  bool isInteger(RexxObject *);
83  wholenumber_t signedIntegerValue(RexxObject *o, size_t position, wholenumber_t maxValue, wholenumber_t minValue);
84  stringsize_t unsignedIntegerValue(RexxObject *o, size_t position, stringsize_t maxValue);
85  int64_t int64Value(RexxObject *o, size_t position);
86  uint64_t unsignedInt64Value(RexxObject *o, size_t position);
87  const char *cstring(RexxObject *);
88  double getDoubleValue(RexxObject *, size_t position);
89  bool isDouble(RexxObject *);
90  void *cself();
91  void *buffer();
92  void *pointer(RexxObject *);
93  void *pointerString(RexxObject *object, size_t position);
95  size_t digits();
96  size_t fuzz();
97  bool form();
98  void setDigits(size_t);
99  void setFuzz(size_t);
100  void setForm(bool);
101  void guardOff();
102  void guardOn();
103  void enableVariablepool();
104  void disableVariablepool();
105  bool trap (RexxString *, RexxDirectory *);
106  void resetNext();
107  bool fetchNext(RexxString **name, RexxObject **value);
108  void raiseCondition(RexxString *condition, RexxString *description, RexxObject *additional, RexxObject *result);
110  RexxObject *getPositionalArgument(size_t index);
112  RexxObject *getSuper();
113  RexxObject *getScope();
115  RexxClass *findClass(RexxString *className);
116  RexxClass *findCallerClass(RexxString *className);
117 
118  inline void termination() { this->guardOff();}
119 
120  void accessCallerContext();
121  inline bool getVpavailable() {return this->vpavailable;}
122  inline RexxString *getMessageName() {return this->msgname;}
123  inline size_t nextVariable() {return this->nextvariable;}
124  inline RexxVariable *nextStem() {return this->nextstem;}
126  RexxObject *getContextVariable(const char *name);
127  void dropContextVariable(const char *name);
128  void setContextVariable(const char *name, RexxObject *value);
129  RexxObject *getObjectVariable(const char *name);
130  void setObjectVariable(const char *name, RexxObject *value);
131  void dropObjectVariable(const char *name);
133  inline void setConditionInfo(RexxDirectory *info) { conditionObj = info; }
135  inline void clearException() { conditionObj = OREF_NULL; }
136  void checkConditions();
139  inline void setNextVariable(size_t value) {this->nextvariable = value;}
140  inline void setNextCurrent(RexxVariableDictionary *vdict) {this->nextcurrent = vdict;}
141  inline void setNextStem(RexxVariable *stemVar) {this->nextstem = stemVar;}
142  inline void setCompoundElement(RexxCompoundElement *element) {this->compoundelement = element;}
143  inline RexxObject *getSelf() { return receiver; }
144  inline RexxActivity *getActivity() { return activity; }
145  virtual bool isStackBase();
146  virtual RexxActivation *getRexxContext();
149  virtual RexxActivation *findRexxContext();
151  virtual RexxObject *getReceiver();
154  inline void setStackBase() { stackBase = true; }
155  void reportSignatureError();
156  void reportStemError(size_t position, RexxObject *object);
157  void processArguments(size_t argcount, RexxObject **arglist, uint16_t *argumentTypes, ValueDescriptor *descriptors, size_t maximumArgumentCount);
159  RexxArray *valuesToObject(ValueDescriptor *value, size_t count);
160  bool objectToValue(RexxObject *o, ValueDescriptor *value);
161  void createLocalReference(RexxObject *objr);
162  void removeLocalReference(RexxObject *objr);
163  void callNativeRoutine(RoutineClass *routine, RexxNativeRoutine *code, RexxString *functionName,
164  RexxObject **list, size_t count, size_t named_count, ProtectedObject &result);
165  void callRegisteredRoutine(RoutineClass *routine, RegisteredRoutine *code, RexxString *functionName,
166  RexxObject **list, size_t count, size_t named_count, ProtectedObject &resultObj);
167 
169  RexxVariableBase *variablePoolGetVariable(PSHVBLOCK pshvblock, bool symbolic);
170  void variablePoolFetchVariable(PSHVBLOCK pshvblock);
171  void variablePoolSetVariable(PSHVBLOCK pshvblock);
172  void variablePoolDropVariable(PSHVBLOCK pshvblock);
173  void variablePoolNextVariable(PSHVBLOCK pshvblock);
174  void variablePoolFetchPrivate(PSHVBLOCK pshvblock);
175  void variablePoolRequest(PSHVBLOCK pshvblock);
176  RexxReturnCode copyValue(RexxObject * value, RXSTRING *rxstring, size_t *length);
177  RexxReturnCode copyValue(RexxObject * value, CONSTRXSTRING *rxstring, size_t *length);
178  int stemSort(const char *stemname, int order, int type, size_t start, size_t end, size_t firstcol, size_t lastcol);
179  inline void enableConditionTrap() { trapConditions = true; }
180 
181  void forwardMessage(RexxObject *to, RexxString *msg, RexxClass *super, RexxArray *positionalArgs, RexxDirectory *namedArgs, ProtectedObject &result);
182  void enableConditionTraps() { trapErrors = true; }
183  void disableConditionTraps() { trapErrors = false; }
185 
186 protected:
187 
188  typedef enum
189  {
190  PROGRAM_ACTIVATION, // toplevel program entry
191  METHOD_ACTIVATION, // normal method call
192  FUNCTION_ACTIVATION, // function call activation
193  DISPATCHER_ACTIVATION, // running a top-level dispatcher
194  CALLBACK_ACTIVATION, // running a callback, such as an exit
195  TRAPPING_ACTIVATION, // running a protected method call, such as an uninit
196  } ActivationType;
197 
198  RexxActivity *activity; /* current activity */
199  RexxNativeCode *code; // the code object controlling the target
200  RexxObject *receiver; // the object receiving the message
201  RexxString *msgname; /* name of the message running */
202  RexxActivation *activation; /* parent activation */
203 
204  // Positional arguments from arglist[0] to arglist[argcount-1]
205  // Named arguments from arglist[argcount] to arglist[argcount + (2*namedArgcount)-1]
206  RexxObject **arglist; /* copy of the argument list */
207 
208  RexxArray *argArray; /* optionally create positional argument array */
209  RexxDirectory *argDirectory; /* optionally create named argument directory */
210 
211  RexxIdentityTable *savelist; /* list of saved objects */
212  RexxObject *result; /* result from RexxRaise call */
213  ActivationType activationType; // the type of activation
214  RexxDirectory *conditionObj; // potential condition object
215  SecurityManager *securityManager; // our active security manager
216  /* running object variable pool */
218  size_t nextvariable; /* next variable to retrieve */
219  RexxVariableDictionary *nextcurrent; /* current processed vdict */
220  RexxCompoundElement *compoundelement;/* current compound variable value */
221  RexxVariable *nextstem; /* our working stem variable */
222  size_t argcount; /* count of positional arguments */
224  bool vpavailable; /* Variable pool access flag */
225  int object_scope; /* reserve/release state of variables*/
226  bool stackBase; // this is a stack base marker
227  bool trapErrors; // we're trapping errors from external callers
228  bool trapConditions; // trap any raised conditions
229 };
230 #endif
RESTORETYPE
Definition: ObjectClass.hpp:82
#define OREF_NULL
Definition: RexxCore.h:61
RexxCompoundElement * compoundelement
int64_t int64Value(RexxObject *o, size_t position)
void setNextVariable(size_t value)
RexxReturnCode copyValue(RexxObject *value, RXSTRING *rxstring, size_t *length)
RexxReturnCode variablePoolInterface(PSHVBLOCK requests)
void variablePoolSetVariable(PSHVBLOCK pshvblock)
void dropObjectVariable(const char *name)
RexxDirectory * getNamedArguments()
RexxVariableDictionary * nextCurrent()
BaseExecutable * getRexxContextExecutable()
bool trap(RexxString *, RexxDirectory *)
void callRegisteredRoutine(RoutineClass *routine, RegisteredRoutine *code, RexxString *functionName, RexxObject **list, size_t count, size_t named_count, ProtectedObject &resultObj)
bool isInteger(RexxObject *)
void variablePoolFetchVariable(PSHVBLOCK pshvblock)
bool objectToValue(RexxObject *o, ValueDescriptor *value)
void variablePoolDropVariable(PSHVBLOCK pshvblock)
RexxObject * getContextVariable(const char *name)
void variablePoolFetchPrivate(PSHVBLOCK pshvblock)
stringsize_t unsignedIntegerValue(RexxObject *o, size_t position, stringsize_t maxValue)
RexxDirectory * getAllContextVariables()
RexxVariableDictionary * methodVariables()
virtual SecurityManager * getSecurityManager()
void dropContextVariable(const char *name)
RexxClass * findClass(RexxString *className)
void processArguments(size_t argcount, RexxObject **arglist, uint16_t *argumentTypes, ValueDescriptor *descriptors, size_t maximumArgumentCount)
void setNextCurrent(RexxVariableDictionary *vdict)
wholenumber_t signedIntegerValue(RexxObject *o, size_t position, wholenumber_t maxValue, wholenumber_t minValue)
virtual NumericSettings * getNumericSettings()
RexxVariableBase * variablePoolGetVariable(PSHVBLOCK pshvblock, bool symbolic)
RexxNativeActivation(RESTORETYPE restoreType)
void createLocalReference(RexxObject *objr)
RexxIdentityTable * savelist
void callNativeRoutine(RoutineClass *routine, RexxNativeRoutine *code, RexxString *functionName, RexxObject **list, size_t count, size_t named_count, ProtectedObject &result)
double getDoubleValue(RexxObject *, size_t position)
RexxStem * resolveStemVariable(RexxObject *s)
uint64_t unsignedInt64Value(RexxObject *o, size_t position)
RexxDirectory * getConditionInfo()
int stemSort(const char *stemname, int order, int type, size_t start, size_t end, size_t firstcol, size_t lastcol)
void setCompoundElement(RexxCompoundElement *element)
void * pointerString(RexxObject *object, size_t position)
virtual RexxActivation * getRexxContext()
void setObjectVariable(const char *name, RexxObject *value)
RexxObject * getObjectVariable(const char *name)
SecurityManager * securityManager
RexxObject * valueToObject(ValueDescriptor *value)
RexxCompoundElement * compoundElement()
void run(RexxMethod *_method, RexxNativeMethod *_code, RexxObject *_receiver, RexxString *_msgname, RexxObject **_arglist, size_t _argcount, size_t _named_argcount, ProtectedObject &resultObj)
void reportStemError(size_t position, RexxObject *object)
void * pointer(RexxObject *)
RexxVariableDictionary * nextcurrent
void removeLocalReference(RexxObject *objr)
virtual RexxObject * getReceiver()
void variablePoolNextVariable(PSHVBLOCK pshvblock)
virtual RexxActivation * findRexxContext()
void setContextVariable(const char *name, RexxObject *value)
RexxObject * getPositionalArgument(size_t index)
void raiseCondition(RexxString *condition, RexxString *description, RexxObject *additional, RexxObject *result)
RexxObject * getContextStem(RexxString *name)
void variablePoolRequest(PSHVBLOCK pshvblock)
const char * cstring(RexxObject *)
void setNextStem(RexxVariable *stemVar)
RexxVariableDictionary * objectVariables
StackFrameClass * createStackFrame()
void forwardMessage(RexxObject *to, RexxString *msg, RexxClass *super, RexxArray *positionalArgs, RexxDirectory *namedArgs, ProtectedObject &result)
void setConditionInfo(RexxDirectory *info)
bool fetchNext(RexxString **name, RexxObject **value)
RexxClass * findCallerClass(RexxString *className)
RexxArray * valuesToObject(ValueDescriptor *value, size_t count)
int type
Definition: cmdparse.cpp:1888
ssize_t wholenumber_t
Definition: rexx.h:230
int RexxReturnCode
Definition: rexx.h:73
size_t stringsize_t
Definition: rexx.h:228
unsigned short uint16_t
signed __int64 int64_t
unsigned __int64 uint64_t