home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / msysjour / vol04 / 02b / project / act / fix_le.act < prev    next >
Text File  |  1988-10-20  |  8KB  |  311 lines

  1. /* This file fixes all known bugs in Language Extensions I
  2.  
  3.    This updates all releases to Version 1.2
  4.  
  5.    If you are not using Object Storage, just load the first two
  6.    related to the methodBrowser.
  7.  
  8. version history:
  9.  
  10.    mas 5/27/88  -- method browser errors
  11.    mas 10/17/88 -- literal rects, polygon, struct fixes
  12.    mas 5/23/88  -- object storage class redef error on structs
  13.    cbd 7/14/88  -- object store bad ID error on recursive objects
  14.    acr 10/17/88 -- storing of strings changed to accomodate ()s
  15.                    strings are now stored as ("a string") instead of
  16.                    just (a string).  Old strings will load properly.
  17. */!!
  18.  
  19. /* This fixes a problem where the MethodBrowser could not be
  20.    recreated when the image is brought up. */!!
  21.  
  22. now(MethodBrowser)!!
  23.  
  24. /*  Recreate self according to data in instance 
  25.   variables.  A recreate message is sent to window objects 
  26.   in OpenWindows when Actor starts up. This method returns 
  27.   nil, indicating no need to show self, since the start 
  28.   method does it.  */
  29. Def  recreate(self)
  30. { loadMenu(self, loadString(324));
  31.   create(self, parent, caption, locRect, WS_POPUPWIND);
  32.   start(self, classCol, nil);
  33.   ^nil
  34. }!!
  35.  
  36. /* This fixes a problem where if you change the number of local
  37.    variables in a method in the MBrowser, the method will appear
  38.    twice in the method list box. */!!
  39.    
  40. now(MethodBrowser)!!
  41.  
  42. /* Compile the method code in the edit window. */
  43. Def accept(self | fSym, cl, oldMethod)
  44. { showWaitCurs(self);
  45.   cl :=
  46.   if mode == BR_CMETH
  47.   then class(selClass)
  48.   else selClass
  49.   endif;
  50.   oldMethod := cl.methods[selMethod];
  51.   fSym := compileText(ew, cl);
  52.   if fSym
  53.   then saveMethText(self, ew.workText, fSym);
  54.     rehash(classCol);
  55.     remove(classCol, oldMethod);
  56.     loadMethods(self);
  57.     selectString(lb1, methodName(self, fSym));
  58.   endif;
  59.   setFocus(ew);
  60.   showOldCurs(self);
  61.   invalidate(ew);
  62. }!!  
  63.  
  64. /* The next changes modify literals.act to accomodate Struct, Rect
  65.    Polygon properly.  They go in the file LITERALS.ACT.
  66. */
  67.  
  68. now(StructClass)!!
  69.  
  70. /* Create a new Struct with the contents of the elements 
  71.   array as its elements. */
  72. Def build(self, elements | coll)
  73. { coll := new(self, size(elements) * 2);
  74.   do(size(elements),
  75.   {using(idx) putLong(coll, asLong(elements[idx]), idx * 2);
  76.   });
  77.   ^coll
  78. }!!     
  79.  
  80. now(RectClass)!!
  81.  
  82. /* Create a new Rect with the contents of the elements 
  83.   array as its elements. */
  84. Def build(self, elements | coll)
  85. { coll := new(self);
  86.   do(size(elements),
  87.   {using(idx) putLong(coll, asLong(elements[idx]), idx * 2);
  88.   });
  89.   ^coll
  90. }!!     
  91.  
  92. now(PolygonClass);!!
  93.  
  94. /* Create a new Polygon with the contents of the points
  95.   array as its elements. */
  96. Def build(self, points | coll)
  97. { ^new(self, points)
  98. }!!    
  99.  
  100. /* These fixes are related to object storage.
  101.    The first five go in ACT\OBJSTORE.ACT.
  102. */
  103.  
  104. now(StructClass)!!
  105.  
  106. /* Read a stored instance of the receiver from a 
  107.   stream.   Modified for recursive objects. */
  108. Def getNew(self, reader, id | obj len )
  109. { len := getNum(reader);
  110.   obj := variableNew(self:Behavior, len);
  111.   addObject(reader, id, obj);
  112.   sync(reader);
  113.   do(overBy(0, len, 2),
  114.   {using(x) obj[x] := next(reader);
  115.   });
  116.   ^obj;
  117. }!!
  118.  
  119.  
  120. now(ObjectClass)!!
  121.  
  122. /* Read a stored instance of the receiver from a 
  123.   stream.  Modified to handle recursive objects. */
  124. Def getNew(self, reader, id | obj len )
  125. { len := getNum(reader);
  126.   if len > 0
  127.   then obj := new(self, len)
  128.   else obj := new(self)
  129.   endif;
  130.   addObject(reader, id, obj);
  131.   do(variables(self),
  132.   {using(v) setVar(obj, next(reader), v);
  133.   });
  134.   sync(reader);
  135.   do(len,
  136.   {using(x) obj:Object[x] := next(reader);
  137.   });
  138.   ^obj;
  139. }!!
  140.  
  141. now(CharClass)!!
  142. /* Modified to handle recursive objects. */
  143. Def getNew(self, reader, id | obj)
  144. { obj := defString(reader)[0];
  145.   addObject(reader, id, obj);
  146.   ^obj;
  147. }!!
  148.  
  149. now(StringClass)!!
  150. /* Modified to handle recursive objects and strings delimited
  151.    by double quotes. */
  152. Def getNew(self, reader, id | obj)
  153. { obj := defStringString(reader);
  154.   addObject(reader, id, obj);
  155.   ^obj;
  156. }!!
  157.  
  158. now(SymbolClass)!!
  159. /* Modified to handle recursive objects */
  160. Def getNew(self, reader, id | obj)
  161. { obj := asSymbol(defString(reader));
  162.   addObject(reader, id, obj);
  163.   ^obj;
  164. }!!
  165.  
  166.  
  167. /* The next five fixes go in CLASSES\STOREDOB.CLS */
  168.  
  169. now(StoredObjectReader)!!
  170. /* Add a new object to the list of objects read.
  171.    Modified to handle recursive objects. */
  172. Def addObject(self, id, obj)
  173. { add(inputTable, id, obj);
  174.   ^obj;
  175. }!!
  176.  
  177. /* Parse a global object.
  178.    Fixed to handle recursive objects. */
  179. Def global(self, id | obj sym)
  180. { sym := getSym(self);
  181.   if (obj := isMetaName(sym))
  182.   then ^addObject(self, id, obj := class(Actor[obj.key]));
  183.   endif;
  184.   if sym == #nil
  185.   then ^nil
  186.   endif;
  187.   if not(obj := Actor[sym])
  188.   then error(self, stackTop(), #undefGlobalError);
  189.   endif;
  190.   ^addObject(self, id, obj);
  191. }!!
  192.  
  193. /* Finish parsing a full stored object structure 
  194.   from the input stream.  Call readNew of the class 
  195.   to parse the private data of the object.
  196.   Fixed to handle recursive objects. */
  197. Def full(self, id | class obj)
  198. {
  199.   if not(class := getClass(self))
  200.   then error(self, stackTop(), #undefClassError);
  201.   endif;
  202.   next(inputStream);
  203.   obj := getNew(class, self, id);
  204.   if not(atEnd(inputStream))
  205.   then next(inputStream);
  206.   endif;
  207.   ^obj;
  208. }!!
  209.  
  210. /* Parse a literal number from the input stream.
  211.    Modified to handle recursive objects. */
  212. Def literal(self, id | obj)
  213. { obj := getNum(self);
  214.   addObject(self, id, obj);
  215.   ^obj;
  216. }!!
  217.  
  218. /* Return the next object that is stored on the 
  219.   input stream.  Return nil if none is available 
  220.   or end of stream.  Modified for recursive objects. */
  221. Def next(self | id type obj)
  222. { id := getNum(self);
  223.   if (type := defType(self)) ~= #alias
  224.   then obj := perform(self, id, type);
  225.     if isAncestor(class(obj), KeyedCollection) cor 
  226.       isAncestor(class(obj), Set)
  227.     then add(hashedObjects, obj);
  228.     endif;
  229.     ^obj;
  230.   else
  231.     if obj := assocAt(inputTable, id)
  232.     then ^obj.value
  233.     else if atEnd(inputStream)
  234.       then error(self, stackTop(), #eosError);
  235.       endif;
  236.       error(self, stackTop(), #badIdError);
  237.     endif;
  238.   endif;
  239. }!!
  240.  
  241. /* The next changes modify how strings are stored.  This allows strings
  242.    to contain ()s but not double quotes.  Both the old string format and
  243.    the new one will be handled properly.  These go in OBJSTORE.ACT.
  244. */!!
  245.  
  246. now(Stream)!!
  247.  
  248. /* Return the string, scanning until delim.
  249.    The starting position is the first character of the string.
  250.    Check for an error if the delim is not found.
  251. */
  252. Def copyString(self, delim | endPos, aStr)
  253. { endPos := find(collection, delim, position);
  254.   if not(endPos)
  255.        error(self, stackTop(), #eosError);
  256.   endif;
  257.   aStr := subString(collection, position, endPos);
  258.   position := endPos + 1;
  259.   ^aStr
  260. }!!
  261.  
  262. now(File)!!
  263.  
  264. /* Return the string, scanning until delim.
  265.    The starting position is the first character of the string.
  266.    Check for an error if the delim is not found.
  267. */
  268. Def copyString(self, delim | start, aStr, length, index)
  269. { start := position(self);
  270.   length := size(delim);
  271.   index := 0;
  272.   loop
  273.   while (index < length) cand not(atEnd(self))
  274.     if delim[index] == next(self)
  275.       index := index + 1
  276.     else
  277.       index := 0
  278.     endif
  279.   endLoop;
  280.   if atEnd(self) cand index == 0
  281.        error(self, stackTop(), #eosError);
  282.   endif;
  283.   aStr := copyFrom(self, start, position(self)-2);
  284.   next(self);
  285.   ^aStr
  286. }!!
  287.  
  288. now(StoredObjectReader)!!
  289.  
  290. /* Return the string from the input stream that constitutes
  291.    the definition of the current String object.  This will work
  292.    for strings delimited by quotes (e.g. ("String")) or those
  293.    stored under previous versions without quotes (e.g. (String)). */
  294. Def defStringString(self | str)
  295.   if next(inputStream) == '"'                       /* new way */
  296.     ^copyString(inputStream, asString('"') + ")");
  297.   else
  298.     putBack(inputStream);                           /* old way */
  299.     ^copyWhile(inputStream, {using(ch) ch ~= ')'}); 
  300.   endif;
  301. }!!
  302.  
  303. now(String)!!
  304.  
  305. /* Store a string within quotes */
  306. Def storeDefinitionOn(self, stream, table)
  307. { nextPutAll(stream, asString('"') + asString(self) + asString('"'));
  308. }!!
  309.  
  310.