Context.st
changeset 15644 6302ce0150b4
parent 15388 1b0f7426a7bb
child 15650 6fb6c451391f
equal deleted inserted replaced
15643:8ca343d37d39 15644:6302ce0150b4
   273 ! !
   273 ! !
   274 
   274 
   275 !Context methodsFor:'Compatibility-Squeak'!
   275 !Context methodsFor:'Compatibility-Squeak'!
   276 
   276 
   277 longStack
   277 longStack
   278     ^ String streamContents:[:s |
   278     ^ self fullPrintAllString
   279             self fullPrintAllOn:s
       
   280     ]
       
   281 ! !
   279 ! !
   282 
   280 
   283 !Context methodsFor:'Compatibility-VW'!
   281 !Context methodsFor:'Compatibility-VW'!
   284 
   282 
   285 resumeWith:value
   283 resumeWith:value
  1498 ! !
  1496 ! !
  1499 
  1497 
  1500 !Context methodsFor:'printing & storing'!
  1498 !Context methodsFor:'printing & storing'!
  1501 
  1499 
  1502 argStringFor:someObject
  1500 argStringFor:someObject
  1503     |name s|
  1501     |s|
  1504 %{
  1502 %{
  1505     /*
  1503     /*
  1506      * special handling for (invalid) free objects.
  1504      * special handling for (invalid) free objects.
  1507      * these only appear if some primitiveCode does not correctly use SEND macros,
  1505      * these only appear if some primitiveCode does not correctly use SEND macros,
  1508      * which may lead to sends to free objects. In normal operation, this 'cannot' happen.
  1506      * which may lead to sends to free objects. In normal operation, this 'cannot' happen.
  1509      * However, these print methods are also invoked for low-level pointer errors, so better be prepared...
  1507      * However, these print methods are also invoked for low-level pointer errors, so better be prepared...
  1510      */
  1508      */
  1511     if (__isNonNilObject(someObject) && (__qClass(someObject)==nil)) {
  1509     if (__isNonNilObject(someObject) && (__qClass(someObject)==nil)) {
  1512         name = __MKSTRING("FreeObject");
  1510         s = __MKSTRING("FreeObject");
  1513     }
  1511     }
  1514 %}.
  1512 %}.
  1515     name notNil ifTrue:[^ name].
       
  1516     s := someObject displayString.
       
  1517     s isNil ifTrue:[
  1513     s isNil ifTrue:[
  1518         ^ '**************** nil displayString of ',(someObject class name ? '??')
  1514         s := someObject displayString.
  1519     ].
  1515         s isNil ifTrue:[
  1520     s isWideString ifTrue:[
  1516             ^ '**************** nil displayString of ',(someObject class name ? '??')
  1521         "make sure that the object really returns something we can stream into a string"
  1517         ].
  1522         s := someObject storeString.
  1518     ].
  1523     ].
  1519 "/    JV@2013-04-26: Following is rubbish, the callers must handle string output correctly. 
       
  1520 "/    moreover storeString does not work on self-referencing structures, but that doesn't matter
       
  1521 "/    for wide strings.
       
  1522 "/    SV@2013-08-19: I checked/fixed the callers to use CharacterWriteStreams.
       
  1523 "/    s isWideString ifTrue:[
       
  1524 "/        "make sure that the object really returns something we can stream into a string"
       
  1525 "/        s := someObject storeString.
       
  1526 "/    ].
  1524     ^ s
  1527     ^ s
  1525 
       
  1526     "Modified: / 07-03-2012 / 13:14:17 / cg"
       
  1527 !
  1528 !
  1528 
  1529 
  1529 argsDisplayString
  1530 argsDisplayString
  1530     ^ String streamContents:[:s | self displayArgsOn:s ].
  1531     ^ String streamContents:[:s | self displayArgsOn:s ].
  1531 
  1532 
  1539     n := self numArgs.
  1540     n := self numArgs.
  1540     1 to:n do:[:index |
  1541     1 to:n do:[:index |
  1541         Error handle:[:ex |
  1542         Error handle:[:ex |
  1542             s := 'Error in argString'.
  1543             s := 'Error in argString'.
  1543         ] do:[
  1544         ] do:[
  1544             s := (self argStringFor:(self at:index)).
  1545             s := self argStringFor:(self at:index).
  1545         ].
  1546         ].
  1546 
  1547 
  1547         aStream nextPutAll:(s contractTo:100).
  1548         aStream nextPutAll:(s contractTo:100).
  1548         index ~~ n ifTrue:[ aStream space ].
  1549         index ~~ n ifTrue:[ aStream space ].
  1549     ].
  1550     ].
  1580 !
  1581 !
  1581 
  1582 
  1582 fullPrintAllString
  1583 fullPrintAllString
  1583     "return a string containing the full walkback (incl. arguments)"
  1584     "return a string containing the full walkback (incl. arguments)"
  1584 
  1585 
  1585     |s|
  1586     ^ String streamContents:[:s | self fullPrintAllOn:s]
  1586 
       
  1587     s := WriteStream on:''.
       
  1588     self fullPrintAllOn:s.
       
  1589     ^ s contents
       
  1590 
  1587 
  1591     "
  1588     "
  1592      thisContext fullPrintAllString
  1589      thisContext fullPrintAllString
  1593     "
  1590     "
  1594 
  1591 
  1625 
  1622 
  1626 fullPrintString
  1623 fullPrintString
  1627     "return a string describing the context - this includes the linenumber,
  1624     "return a string describing the context - this includes the linenumber,
  1628      receiver printString and argument printString"
  1625      receiver printString and argument printString"
  1629 
  1626 
  1630     |s|
  1627     ^ String streamContents:[:s | self fullPrintOn:s]
  1631 
       
  1632     s := WriteStream on:''.
       
  1633     self fullPrintOn:s.
       
  1634     ^ s contents
       
  1635 
  1628 
  1636     "
  1629     "
  1637      thisContext fullPrintString
  1630      thisContext fullPrintString
  1638     "
  1631     "
  1639 !
  1632 !
  2186 !Context methodsFor:'special accessing'!
  2179 !Context methodsFor:'special accessing'!
  2187 
  2180 
  2188 argAndVarNames
  2181 argAndVarNames
  2189     "helper: given a context, return a collection of arg&var names"
  2182     "helper: given a context, return a collection of arg&var names"
  2190 
  2183 
  2191     |homeContext method block numArgs numVars m src
  2184     |homeContext homeMethod block numArgs numVars m src
  2192      sel isDoIt blocksLineNr extractFromBlock sender|
  2185      sel isDoIt blocksLineNr extractFromBlock sender|
  2193 
  2186 
  2194     numArgs := self numArgs.
  2187     numArgs := self numArgs.
  2195     numVars := self numVars.
  2188     numVars := self numVars.
  2196     (numArgs == 0 and:[numVars == 0]) ifTrue:[^ #()].
  2189     (numArgs == 0 and:[numVars == 0]) ifTrue:[^ #()].
  2197 
  2190 
  2198     homeContext := self methodHome.
  2191     homeContext := self methodHome.
  2199     homeContext notNil ifTrue:[
  2192     homeContext notNil ifTrue:[
  2200         sel := homeContext selector.
  2193         sel := homeContext selector.
  2201         method := homeContext method.
  2194         homeMethod := homeContext method.
  2202     ].
  2195     ].
  2203 
  2196 
  2204     extractFromBlock :=
  2197     extractFromBlock :=
  2205         [
  2198         [
  2206             |blockNode argNames varNames vars args blocksHome|
  2199             |blockNode argNames varNames vars args blocksHome|
  2227                 argNames := #().
  2220                 argNames := #().
  2228                 varNames := #().
  2221                 varNames := #().
  2229 
  2222 
  2230                 numArgs > 0 ifTrue:[
  2223                 numArgs > 0 ifTrue:[
  2231                     vars := blockNode arguments.
  2224                     vars := blockNode arguments.
  2232                     vars size > 0 ifTrue:[
  2225                     vars notEmptyOrNil ifTrue:[
  2233                         argNames := vars collect:[:var | var name]
  2226                         argNames := vars collect:[:var | var name]
  2234                     ]
  2227                     ]
  2235                 ].
  2228                 ].
  2236                 numVars > 0 ifTrue:[
  2229                 numVars > 0 ifTrue:[
  2237                     vars := blockNode variables.
  2230                     vars := blockNode variablesIncludingInlined: (homeMethod code notNil and:[homeMethod byteCode isNil]).
  2238                     vars size > 0 ifTrue:[
  2231                     vars notEmptyOrNil ifTrue:[
  2239                         varNames := vars collect:[:var | var name].
  2232                         varNames := vars collect:[:var | var name].
  2240                     ]
  2233                     ]
  2241                 ].
  2234                 ].
  2242                 ^ argNames , varNames
  2235                 ^ argNames , varNames
  2243             ].
  2236             ].
  2245 
  2238 
  2246     "/ #doIt needs special handling below
  2239     "/ #doIt needs special handling below
  2247     isDoIt := (sel == #'doIt') or:[sel == #'doIt:'].
  2240     isDoIt := (sel == #'doIt') or:[sel == #'doIt:'].
  2248     self isBlockContext ifFalse:[
  2241     self isBlockContext ifFalse:[
  2249         isDoIt ifTrue:[
  2242         isDoIt ifTrue:[
  2250             method notNil ifTrue:[
  2243             homeMethod notNil ifTrue:[
  2251                 "/ special for #doIt
  2244                 "/ special for #doIt
  2252                 m := nil.
  2245                 m := nil.
  2253                 src := ('[' , method source , '\]') withCRs.
  2246                 src := ('[' , homeMethod source , '\]') withCRs.
  2254                 "/ blocksLineNr := self lineNumber.
  2247                 "/ blocksLineNr := self lineNumber.
  2255                 blocksLineNr := (self home ? self) lineNumber.
  2248                 blocksLineNr := (self home ? self) lineNumber.
  2256                 extractFromBlock value.
  2249                 extractFromBlock value.
  2257             ]
  2250             ]
  2258         ].
  2251         ].
  2259 
  2252 
  2260         method notNil ifTrue:[
  2253         homeMethod notNil ifTrue:[
  2261             ^ method methodArgAndVarNames.
  2254             ^ homeMethod methodArgAndVarNamesInContext: self.
  2262         ].
  2255         ].
  2263         ^ #()
  2256         ^ #()
  2264     ].
  2257     ].
  2265 
  2258 
  2266     method notNil ifTrue:[
  2259     homeMethod notNil ifTrue:[
  2267         isDoIt ifTrue:[
  2260         isDoIt ifTrue:[
  2268             "/ special for #doIt
  2261             "/ special for #doIt
  2269             "/ my source is found in the method.
  2262             "/ my source is found in the method.
  2270             m := nil.
  2263             m := nil.
  2271             src := ('[' , method source , '\]') withCRs.
  2264             src := ('[' , homeMethod source , '\]') withCRs.
  2272         ] ifFalse:[
  2265         ] ifFalse:[
  2273             m := method.
  2266             m := homeMethod.
  2274             src := nil.
  2267             src := nil.
  2275         ].
  2268         ].
  2276         blocksLineNr := self lineNumber.
  2269         blocksLineNr := self lineNumber.
  2277         extractFromBlock value.
  2270         extractFromBlock value.
  2278         blocksLineNr := self home lineNumber.
  2271         blocksLineNr := self home lineNumber.
  2297             sender := nil.
  2290             sender := nil.
  2298         ].
  2291         ].
  2299     ].
  2292     ].
  2300 
  2293 
  2301     ^ #()
  2294     ^ #()
       
  2295 
       
  2296     "Modified: / 19-08-2013 / 12:13:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  2302 !
  2297 !
  2303 
  2298 
  2304 canResume
  2299 canResume
  2305     "return true, if the receiver allows to be resumed.
  2300     "return true, if the receiver allows to be resumed.
  2306      Due to the implementation, this requires that the context which
  2301      Due to the implementation, this requires that the context which
  2498 ! !
  2493 ! !
  2499 
  2494 
  2500 !Context class methodsFor:'documentation'!
  2495 !Context class methodsFor:'documentation'!
  2501 
  2496 
  2502 version
  2497 version
  2503     ^ '$Header: /cvs/stx/stx/libbasic/Context.st,v 1.186 2013-06-09 20:40:08 cg Exp $'
  2498     ^ '$Header: /cvs/stx/stx/libbasic/Context.st,v 1.187 2013-08-19 15:56:31 stefan Exp $'
  2504 !
  2499 !
  2505 
  2500 
  2506 version_CVS
  2501 version_CVS
  2507     ^ '$Header: /cvs/stx/stx/libbasic/Context.st,v 1.186 2013-06-09 20:40:08 cg Exp $'
  2502     ^ '$Header: /cvs/stx/stx/libbasic/Context.st,v 1.187 2013-08-19 15:56:31 stefan Exp $'
       
  2503 !
       
  2504 
       
  2505 version_HG
       
  2506 
       
  2507     ^ '$Changeset: <not expanded> $'
  2508 !
  2508 !
  2509 
  2509 
  2510 version_SVN
  2510 version_SVN
  2511     ^ '$ Id: Context.st 10643 2011-06-08 21:53:07Z vranyj1  $'
  2511     ^ '$ Id: Context.st 10643 2011-06-08 21:53:07Z vranyj1  $'
  2512 ! !
  2512 ! !