ooRexx  4.2.0-source
About: ooRexx (Open Object Rexx) is a free implementation of Object Rexx. Object Rexx is an enhancement of the classic Rexx interpreter; a full-featured programming language with a human-oriented syntax.
  Fossies Dox: ooRexx-4.2.0-source.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

PackageClass.cpp
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 PackageClass.cpp */
40 /* */
41 /* Primitive Package class */
42 /* */
43 /******************************************************************************/
44 #include "RexxCore.h"
45 #include "ArrayClass.hpp"
46 #include "SourceFile.hpp"
47 #include "DirectoryClass.hpp"
48 #include "ProtectedObject.hpp"
49 #include "PackageClass.hpp"
50 #include "RoutineClass.hpp"
51 #include "InterpreterInstance.hpp"
52 #include "PackageManager.hpp"
53 
54 
55 // singleton class instance
57 
58 
63 {
64  CLASS_CREATE(Package, "Package", RexxClass);
65 }
66 
67 
68 void *PackageClass::operator new (size_t size)
69 /******************************************************************************/
70 /* Function: create a new method instance */
71 /******************************************************************************/
72 {
73  /* get a new method object */
74  return new_object(size, T_Package);
75 }
76 
77 
79 /******************************************************************************/
80 /* Function: Initialize a method object */
81 /******************************************************************************/
82 {
83  OrefSet(this, this->source, s); /* store the code */
84 }
85 
86 
87 void PackageClass::live(size_t liveMark)
88 /******************************************************************************/
89 /* Function: Normal garbage collection live marking */
90 /******************************************************************************/
91 {
92  memory_mark(this->source);
93  memory_mark(this->objectVariables);
94 }
95 
96 void PackageClass::liveGeneral(int reason)
97 /******************************************************************************/
98 /* Function: Generalized object marking */
99 /******************************************************************************/
100 {
102  memory_mark_general(this->objectVariables);
103 }
104 
106 /******************************************************************************/
107 /* Function: Flatten an object */
108 /******************************************************************************/
109 {
111 
112  flatten_reference(newThis->source, envelope);
113  flatten_reference(newThis->objectVariables, envelope);
114 
116 }
117 
118 
125 {
126  return source->getProgramName();
127 }
128 
129 
136 {
137  return source->extractSource();
138 }
139 
140 
149 {
150  return source->get(n);
151 }
152 
153 
162 {
163  // the starting position isn't optional
164  size_t n = positionArgument(position, ARG_ONE);
165  return source->get(n);
166 }
167 
168 
175 {
176  return new_integer(source->sourceSize());
177 }
178 
179 
186 {
187  // we need to return a copy. The source might necessarily have any of these,
188  // so we return an empty directory if it's not there.
190  if (classes != OREF_NULL)
191  {
192  return (RexxDirectory *)classes->copy();
193  }
194  else
195  {
196  return new_directory();
197  }
198 }
199 
200 
207 {
208  // we need to return a copy. The source might necessarily have any of these,
209  // so we return an empty directory if it's not there.
211  if (classes != OREF_NULL)
212  {
213  return (RexxDirectory *)classes->copy();
214  }
215  else
216  {
217  return new_directory();
218  }
219 }
220 
221 
229 {
230  // we need to return a copy. The source might necessarily have any of these,
231  // so we return an empty directory if it's not there.
233  if (classes != OREF_NULL)
234  {
235  return (RexxDirectory *)classes->copy();
236  }
237  else
238  {
239  return new_directory();
240  }
241 }
242 
243 
250 {
251  // we need to return a copy. The source might necessarily have any of these,
252  // so we return an empty directory if it's not there.
254  if (routines != OREF_NULL)
255  {
256  return (RexxDirectory *)routines->copy();
257  }
258  else
259  {
260  return new_directory();
261  }
262 }
263 
264 
272 {
273  // we need to return a copy. The source might necessarily have any of these,
274  // so we return an empty directory if it's not there.
276  if (routines != OREF_NULL)
277  {
278  return (RexxDirectory *)routines->copy();
279  }
280  else
281  {
282  return new_directory();
283  }
284 }
285 
286 
294 {
295  // we need to return a copy. The source might necessarily have any of these,
296  // so we return an empty directory if it's not there.
298  if (routines != OREF_NULL)
299  {
300  return (RexxDirectory *)routines->copy();
301  }
302  else
303  {
304  return new_directory();
305  }
306 }
307 
308 
315 {
316  // we need to return a copy. The source might necessarily have any of these,
317  // so we return an empty directory if it's not there.
318  RexxDirectory *methods = source->getMethods();
319  if (methods != OREF_NULL)
320  {
321  return (RexxDirectory *)methods->copy();
322  }
323  else
324  {
325  return new_directory();
326  }
327 }
328 
329 
337 {
338  RexxList *packages = source->getPackages();
339  if (packages != OREF_NULL)
340  {
341  return packages->makeArray();
342  }
343  else
344  {
345  return new_array((size_t)0);
346  }
347 
348 }
349 
350 
360 {
361  // make sure we have a valid name and delegate to the source object
362  name = stringArgument(name, 1);
363  // if no source provided, this comes from a file
364  if (s == OREF_NULL)
365  {
367  }
368  else
369  {
370  s = arrayArgument(s, "source");
372  }
373 }
374 
375 
384 {
385  classArgument(package, ThePackageClass, "package");
386  source->addPackage(package);
387  return this;
388 }
389 
390 
399 {
400  name = stringArgument(name, "name");
401  classArgument(routine, TheRoutineClass, "routine");
402  source->addInstalledRoutine(name, routine, false);
403  return this;
404 }
405 
406 
415 {
416  name = stringArgument(name, "name");
417  classArgument(routine, TheRoutineClass, "routine");
418  source->addInstalledRoutine(name, routine, true);
419  return this;
420 }
421 
422 
431 {
432  name = stringArgument(name, "name");
433  classArgument(clazz, TheClassClass, "class");
434  source->addInstalledClass(name, clazz, false);
435  return this;
436 }
437 
438 
447 {
448  name = stringArgument(name, "name");
449  classArgument(clazz, TheClassClass, "class");
450  source->addInstalledClass(name, clazz, true);
451  return this;
452 }
453 
454 
463 {
464  RexxClass *classObj = source->findClass(name);
465  // we need to filter this to always return a class object
466  if (classObj != OREF_NULL && classObj->isInstanceOf(TheClassClass))
467  {
468  return classObj;
469  }
470  return OREF_NULL;
471 }
472 
473 
482 {
483  name = stringArgument(name, "name");
484  RexxClass *cls = source->findClass(name);
485  if (cls == OREF_NULL)
486  {
487  return (RexxClass *)TheNilObject;
488  }
489  return cls;
490 }
491 
492 
501 {
502  return source->findRoutine(name);
503 }
504 
505 
514 {
515  name = stringArgument(name, "name");
516  RoutineClass *routine = findRoutine(name);
517  if (routine == OREF_NULL)
518  {
519  return (RoutineClass *)TheNilObject;
520  }
521  return routine;
522 }
523 
524 
533 {
534  source->setSecurityManager(manager);
535  return TheTrueObject;
536 }
537 
538 
540  RexxObject **init_args, /* subclass init arguments */
541  size_t argCount) /* number of arguments passed */
542 /******************************************************************************/
543 /* Function: Create a new packag from REXX code contained in a file or an */
544 /* array */
545 /******************************************************************************/
546 {
547  RexxObject *pgmname; /* method name */
548  RexxObject *_source; /* Array or string object */
549  size_t initCount = 0; /* count of arguments we pass along */
551  InterpreterInstance *instance = activity->getInstance();
552 
553  /* break up the arguments */
554 
555  RexxClass::processNewArgs(init_args, argCount, &init_args, &initCount, 2, (RexxObject **)&pgmname, (RexxObject **)&_source);
556 
557  PackageClass *package = OREF_NULL;
558 
559  /* get the package name as a string */
560  RexxString *nameString = stringArgument(pgmname, "name");
561  if (_source == OREF_NULL)
562  {
563  // if no directly provided source, resolve the name in the global context and have the instance
564  // load the file.
565  RexxString *resolvedName = instance->resolveProgramName(nameString, OREF_NULL, OREF_NULL);
566  ProtectedObject n(resolvedName);
567  package = instance->loadRequires(activity, nameString, resolvedName);
568  }
569  else
570  {
571  // add this to the instance context
572  RexxArray *sourceArray = arrayArgument(_source, "source");
573  package = instance->loadRequires(activity, nameString, sourceArray);
574  }
575 
576  ProtectedObject p(package);
577 
578  /* Give new object its behaviour */
579  package->setBehaviour(((RexxClass *)this)->getInstanceBehaviour());
580  if (((RexxClass *)this)->hasUninitDefined())
581  {
582  package->hasUninit(); /* Make sure everyone is notified. */
583  }
584  /* now send an INIT message */
585  package->sendMessage(OREF_INIT, init_args, initCount);
586  return package; /* return the new method */
587 }
588 
589 
599 {
600  name = stringArgument(name, "name");
601  // have we already loaded this package?
602  // may need to bootstrap it up first.
603  LibraryPackage *package = PackageManager::loadLibrary(name);
604  return package == NULL ? TheFalseObject : TheTrueObject;
605 }
606 
607 
614 {
615  return new_integer(source->getDigits());
616 }
617 
618 
625 {
626  return new_integer(source->getFuzz());
627 }
628 
629 
636 {
637  return source->getForm() == Numerics::FORM_SCIENTIFIC ? OREF_SCIENTIFIC : OREF_ENGINEERING;
638 }
639 
640 
647 {
648  return source->getTrace();
649 }
PackageClass::flatten
void flatten(RexxEnvelope *)
Definition: PackageClass.cpp:105
PackageClass::PackageClass
PackageClass(RexxSource *source)
Definition: PackageClass.cpp:78
new_array
RexxArray * new_array(size_t s)
Definition: ArrayClass.hpp:250
RexxArray
Definition: ArrayClass.hpp:100
RexxObject::isInstanceOf
bool isInstanceOf(RexxClass *)
Definition: ObjectClass.cpp:226
PackageClass::getSourceLine
RexxString * getSourceLine(size_t)
Definition: PackageClass.cpp:148
PackageClass::newRexx
PackageClass * newRexx(RexxObject **init_args, size_t argCount)
Definition: PackageClass.cpp:539
TheRoutineClass
#define TheRoutineClass
Definition: RexxCore.h:155
RexxSource::addInstalledClass
void addInstalledClass(RexxString *name, RexxClass *classObject, bool publicClass)
Definition: SourceFile.cpp:6175
PackageClass::getClasses
RexxDirectory * getClasses()
Definition: PackageClass.cpp:185
RexxSource::getForm
bool getForm()
Definition: SourceFile.hpp:400
PackageClass.hpp
new_integer
RexxInteger * new_integer(wholenumber_t v)
Definition: IntegerClass.hpp:198
memory_mark_general
#define memory_mark_general(oref)
Definition: RexxMemory.hpp:437
OrefSet
#define OrefSet(o, r, v)
Definition: RexxCore.h:94
PackageClass::findRoutine
RoutineClass * findRoutine(RexxString *name)
Definition: PackageClass.cpp:500
RexxSource::sourceSize
size_t sourceSize()
Definition: SourceFile.cpp:762
RoutineClass.hpp
RoutineClass
Definition: RoutineClass.hpp:49
RexxDirectory::copy
RexxObject * copy()
Definition: DirectoryClass.cpp:109
PackageClass::setSecurityManager
RexxObject * setSecurityManager(RexxObject *)
Definition: PackageClass.cpp:532
RexxSource::getImportedRoutines
RexxDirectory * getImportedRoutines()
Definition: SourceFile.hpp:396
PackageClass::getSourceLineRexx
RexxString * getSourceLineRexx(RexxObject *)
Definition: PackageClass.cpp:161
RexxSource::getImportedClasses
RexxDirectory * getImportedClasses()
Definition: SourceFile.hpp:393
RexxSource::getInstalledClasses
RexxDirectory * getInstalledClasses()
Definition: SourceFile.hpp:391
TheClassClass
#define TheClassClass
Definition: RexxCore.h:149
TheTrueObject
#define TheTrueObject
Definition: RexxCore.h:185
RexxSource::get
RexxString * get(size_t)
Definition: SourceFile.cpp:794
Numerics::FORM_SCIENTIFIC
static const bool FORM_SCIENTIFIC
Definition: Numerics.hpp:76
RexxEnvelope
Definition: RexxEnvelope.hpp:53
PackageClass::loadLibrary
RexxObject * loadLibrary(RexxString *name)
Definition: PackageClass.cpp:598
PackageClass::addClass
RexxObject * addClass(RexxString *name, RexxClass *clazz)
Definition: PackageClass.cpp:430
PackageClass::getPublicClasses
RexxDirectory * getPublicClasses()
Definition: PackageClass.cpp:206
LibraryPackage
Definition: LibraryPackage.hpp:57
PackageClass::liveGeneral
void liveGeneral(int reason)
Definition: PackageClass.cpp:96
RexxSource
Definition: SourceFile.hpp:131
PackageClass::getImportedRoutines
RexxDirectory * getImportedRoutines()
Definition: PackageClass.cpp:293
PackageClass::getMethods
RexxDirectory * getMethods()
Definition: PackageClass.cpp:314
ARG_ONE
const int ARG_ONE
Definition: RexxCore.h:80
OREF_NULL
#define OREF_NULL
Definition: RexxCore.h:60
PackageClass::trace
RexxObject * trace()
Definition: PackageClass.cpp:646
ArrayClass.hpp
PackageClass::getSourceSize
RexxInteger * getSourceSize()
Definition: PackageClass.cpp:174
RexxActivity
Definition: RexxActivity.hpp:127
RexxSource::getDigits
size_t getDigits()
Definition: SourceFile.hpp:399
PackageClass::getName
RexxString * getName()
Definition: PackageClass.cpp:124
RexxDirectory
Definition: DirectoryClass.hpp:49
RexxSource::extractSource
RexxArray * extractSource(SourceLocation &)
Definition: SourceFile.cpp:1079
PackageClass::getSource
RexxArray * getSource()
Definition: PackageClass.cpp:135
arrayArgument
RexxArray * arrayArgument(RexxObject *object, size_t position)
Definition: RexxCore.h:376
RexxClass
Definition: ClassClass.hpp:49
ProtectedObject.hpp
PackageClass::addPublicRoutine
RexxObject * addPublicRoutine(RexxString *name, RoutineClass *routine)
Definition: PackageClass.cpp:414
flatten_reference
#define flatten_reference(oref, envel)
Definition: RexxMemory.hpp:440
RexxSource::findRoutine
RoutineClass * findRoutine(RexxString *)
Definition: SourceFile.cpp:1513
cleanUpFlatten
#define cleanUpFlatten
Definition: RexxMemory.hpp:432
ProtectedObject
Definition: ProtectedObject.hpp:46
classArgument
void classArgument(RexxObject *object, RexxClass *clazz, const char *name)
Definition: RexxCore.h:416
InterpreterInstance::resolveProgramName
RexxString * resolveProgramName(RexxString *name, RexxString *dir, RexxString *ext)
Definition: InterpreterInstance.hpp:106
PackageClass::getRoutines
RexxDirectory * getRoutines()
Definition: PackageClass.cpp:249
PackageClass
Definition: PackageClass.hpp:48
PackageClass::digits
RexxObject * digits()
Definition: PackageClass.cpp:613
PackageClass::loadPackage
PackageClass * loadPackage(RexxString *name, RexxArray *source)
Definition: PackageClass.cpp:359
RexxSource::getFuzz
size_t getFuzz()
Definition: SourceFile.hpp:401
PackageClass::getPublicRoutines
RexxDirectory * getPublicRoutines()
Definition: PackageClass.cpp:271
CLASS_CREATE
#define CLASS_CREATE(name, id, className)
Definition: RexxMemory.hpp:445
RexxSource::getInstalledPublicRoutines
RexxDirectory * getInstalledPublicRoutines()
Definition: SourceFile.hpp:395
RexxSource::getTrace
RexxString * getTrace()
Definition: SourceFile.hpp:404
PackageClass::findClassRexx
RexxClass * findClassRexx(RexxString *name)
Definition: PackageClass.cpp:481
memory_mark
#define memory_mark(oref)
Definition: RexxMemory.hpp:436
PackageClass::addPublicClass
RexxObject * addPublicClass(RexxString *name, RexxClass *clazz)
Definition: PackageClass.cpp:446
RexxSource::getInstalledRoutines
RexxDirectory * getInstalledRoutines()
Definition: SourceFile.hpp:394
RexxSource::getProgramName
RexxString * getProgramName()
Definition: SourceFile.hpp:290
PackageClass::findRoutineRexx
RoutineClass * findRoutineRexx(RexxString *name)
Definition: PackageClass.cpp:513
PackageClass::fuzz
RexxObject * fuzz()
Definition: PackageClass.cpp:624
PackageClass::live
void live(size_t)
Definition: PackageClass.cpp:87
PackageClass::getImportedClasses
RexxDirectory * getImportedClasses()
Definition: PackageClass.cpp:228
new_directory
RexxDirectory * new_directory()
Definition: DirectoryClass.hpp:101
PackageClass::findClass
RexxClass * findClass(RexxString *name)
Definition: PackageClass.cpp:462
InterpreterInstance
Definition: InterpreterInstance.hpp:55
T_Package
Definition: ClassTypeCodes.h:97
RexxSource::addInstalledRoutine
void addInstalledRoutine(RexxString *name, RoutineClass *routineObject, bool publicRoutine)
Definition: SourceFile.cpp:6206
PackageClass::getImportedPackages
RexxArray * getImportedPackages()
Definition: PackageClass.cpp:336
RexxSource::loadRequires
PackageClass * loadRequires(RexxActivity *activity, RexxString *target)
Definition: SourceFile.cpp:6072
setUpFlatten
#define setUpFlatten(type)
Definition: RexxMemory.hpp:427
TheNilObject
#define TheNilObject
Definition: RexxCore.h:180
ActivityManager::currentActivity
static RexxActivity *volatile currentActivity
Definition: ActivityManager.hpp:95
ThePackageClass
#define ThePackageClass
Definition: RexxCore.h:156
PackageClass::form
RexxObject * form()
Definition: PackageClass.cpp:635
positionArgument
stringsize_t positionArgument(RexxObject *argument, size_t position)
Definition: StringClassUtil.cpp:82
PackageClass::addPackage
RexxObject * addPackage(PackageClass *package)
Definition: PackageClass.cpp:383
PackageClass::createInstance
static void createInstance()
Definition: PackageClass.cpp:62
stringArgument
RexxString * stringArgument(RexxObject *object, size_t position)
Definition: RexxCore.h:296
RexxClass::processNewArgs
static void processNewArgs(RexxObject **, size_t, RexxObject ***, size_t *, size_t, RexxObject **, RexxObject **)
Definition: ClassClass.cpp:1701
InterpreterInstance.hpp
RexxSource::getMethods
RexxDirectory * getMethods()
Definition: SourceFile.hpp:294
RexxSource::addPackage
void addPackage(PackageClass *package)
Definition: SourceFile.cpp:6126
RexxSource::getInstalledPublicClasses
RexxDirectory * getInstalledPublicClasses()
Definition: SourceFile.hpp:392
RexxCore.h
RexxList
Definition: ListClass.hpp:63
RexxSource::findClass
RexxClass * findClass(RexxString *)
Definition: SourceFile.cpp:1609
DirectoryClass.hpp
PackageClass::addRoutine
RexxObject * addRoutine(RexxString *name, RoutineClass *routine)
Definition: PackageClass.cpp:398
new_object
RexxObject * new_object(size_t s)
Definition: RexxMemory.hpp:422
PackageClass::classInstance
static RexxClass * classInstance
Definition: PackageClass.hpp:61
RexxInteger
Definition: IntegerClass.hpp:56
RexxSource::setSecurityManager
void setSecurityManager(RexxObject *manager)
Definition: SourceFile.hpp:366
RexxList::makeArray
RexxArray * makeArray()
Definition: ListClass.cpp:872
RexxSource::getPackages
RexxList * getPackages()
Definition: SourceFile.hpp:398
SourceFile.hpp
RexxObject
Definition: ObjectClass.hpp:311
PackageManager.hpp
PackageClass::source
RexxSource * source
Definition: PackageClass.hpp:99
RexxString
Definition: StringClass.hpp:119
RexxActivity::getInstance
InterpreterInstance * getInstance()
Definition: RexxActivity.hpp:250