- live browsing of Self object memory -

lobby traitsactivationText

CopyDowns: vector

CreatorPath: traits activationText

Module: activationText

parent* = traits selectionText
copyForActivation: = ( copyForActivation: activation Width: width)
copyForActivation:Width: =
( | new <- activationText |
    new: clone.
    new lines: new lines copyRemoveAll.
    new selection: new selection copy.
    new selection start: 0@0.
    new selection end:   0@0.
    new activation: activation.
    new width: width.
    new formatActivation)
do:AtSelectionStart:AtSelectionEnd: =
( | lineNo <- 0 |

     hasSelection ifTrue: [
         lines do: [|:line|
            line do:[| :c. :i |
                (selection start y = lineNo)
            && [ selection start x = i      ] ifTrue: [ startBlk value: c ].
            blk value: c.
                (selection end   y = lineNo)
            && [ selection end   x = i succ ] ifTrue: [ endBlk   value: c ]].
            lineNo = lines size ifFalse: [ blk value: '\n' ].
            lineNo: lineNo succ.]
    ] False: [
     lines do: [|:line|
        line do:[| :c. :i | blk value: c].
        lineNo = lines size ifFalse: [ blk value: '\n' ].
        lineNo: lineNo succ.]
    ])
hasSelection = ( selection start != selection end)
positionTableFor:IfFail: =
( 
     source parseObjectIntoPositionTableIfFail: [|:e|
        ('badTypeError' isPrefixOf: e) ifTrue: [
            ^ error: e. "a real error"
        ].
        "If The parser fails to parse the string, assume
         the source is VM-generated, e.g. an error method"
        ^ fb value.
    ])
sourceText =
( | lines |
    lines: selfMethodText copyForMethod: activation.
    lines height <= 1 ifTrue: [^ activation source ].
    (
        lines indentation: indentation
    ) asCode asString)
This method should probably be modified to disassble when needed, but since it is not used, and is uncommented, it is not clear what it should do. -- dmu 10/12/96
add: =
( 
    lines isEmpty ifTrue: [ lines add: str ]
                   False: [ lines last: lines last, str].
    pos: pos + str size)
addLine = ( lines add: ''. pos: 0)
addWithSelection:Line: =
( | offsetLineNo |
    offsetLineNo: lines size pred + lineNo.
    string do: [ | :c. :i |
      '\n' = c    ifTrue: [ addLine ] False: [ add: c ].
    ].
    selection start: 0 @ offsetLineNo.
    selection end:   (lines at: offsetLineNo) size @ offsetLineNo.
    self)
addWithSelection:Start:End: =
( | line <- ''. startLine <- 0 |
    startLine: lines size.
    string do: [ | :c. :i |
        i      = start ifTrue: [ selection start: pos@(lines size- 1)].
        '\n'   = c     ifTrue: [ addLine ] False: [ add: c ].
        i succ = end   ifTrue: [ selection end:   pos@(lines size- 1)]])
formatActivation =
( 
    formatReceiver. add: pad.
    formatSelector.
    formatSlots.
    formatSource.
    add: rightParen.
    self)
formatArgument: = ( slot key, ' ', (slot contents safeNameSize: 0))
formatArguments =
( | values <- list |
    values: values copyRemoveAll.
    activation do: [|:slot|
        slot isArgument ifTrue: [ values add: formatArgument: slot]].
    values)
formatReceiver = ( add: activation receiver safeNameAndIDSize: 20)
formatSelector =
( | arguments <- list. keywords <- list |
    (reflect: activation selector) isReflecteeString ifFalse: [
        ^add: activation selector printString, afterSelector].
    keywords:  activation selector asSelector keywords.
    arguments: formatArguments.
    arguments isEmpty
       ifTrue: [ add: activation selector, pad, afterSelector]
        False: [| selWidth <- 0 |
           keywords  do: [|:str| selWidth: selWidth + str size].
           arguments do: [|:str| selWidth: selWidth + str size].
           selWidth: selWidth + (keywords size * 2 * pad size) +
                     afterSelector size.
           restOnLine >= selWidth ifTrue: [
                 keywords with: arguments Do: [ | :keyword. :argument |
                     add: keyword, pad, argument, pad ].
                  add: afterSelector
               ] False: [| keyW <- 0. isFirst <- true |
                 "Align colons of keywords vertical"
                 keywords doFirst: [| :keyword |
                     keyW:  keyW max: keyword size + pos
                 ] MiddleLast: [| :keyword |
                     keyW:  keyW max: keyword size
                 ] IfEmpty: [].
                 keywords with: arguments Do: [| :keyword. :argument |
                     isFirst ifTrue: [ isFirst: false ]
                              False: [ addLine ].
                     add: (keyword padOnLeft: (keyW - pos)),pad,argument].
                     add: pad, afterSelector]])
formatSlot: =
( 
    slot key, pad,
    (slot isAssignable ifTrue: arrow False: equal), pad,
    (slot contents safeNameSize: 0))
formatSlots =
( | slots <- list |
    slots: slots copyRemoveAll.
    activation do: [|:slot|
           slot isArgument not
         && [ slot value isReflecteeAssignment not ]
         ifTrue: [ slots add: formatSlot: slot]].
    slots isEmpty ifFalse: [
        | isLineBroken <- false. localIndent <- 0. slotsWidth <- 0 |
        slots do: [|:str|  slotsWidth: slotsWidth + str size ].
        slotsWidth: slotsWidth + 
                    ((slots size) * ( pad size + dot size )) +
                    bar size double + pad size.
        restOnLine > slotsWidth ifFalse: [
            addLine. add: '' padOnLeft: indentation ].
        add: bar, pad.
        localIndent: pos.
        slots do:[| :str |
           restOnLine > str size
               ifTrue: [ add: str,dot,pad ]
                False: [ addLine. add: '' padOnLeft: localIndent.
                         add: str,dot,pad. isLineBroken: true]].
        add: bar.
        isLineBroken ifTrue: [ addLine ] False: [ add: pad ].
    ])
formatSource =
( | csp. mt |

    mt: selfMethodTextWithPositionConversion copyForMethod: activation.
    mt height > 1  ifTrue: [  mt indentation: indentation.  mt asCode].

    mt isDisassembled  ifTrue: [ | p. lineNo |
      p: activation position.
      lineNo: mt convertBCIToLine: p.
      addWithSelection: mt asString Line: lineNo.
    ] 
    False: [ | csp |
      csp: mt convertPosition: activation sourcePosition
                FormatBlock: [|:t|
                  t height > 1  ifTrue: [ t indentation: indentation. t asCode].
      ].
      addWithSelection: mt asString  Start: csp x  End: csp y.
    ])
indentPosition: =
( | whiteSpace = ' ' |
    string findFirst: [ | :v | (whiteSpace includes: v) not ]
                  IfPresent: [ | :v. :i. | i ]
                   IfAbsent: [ string size ])
restOnLine = ( width - pos)

printing

storeStringWorks = falseno asActivationText

tokens

afterSelector = ( equal, pad, leftParen)
arrow = '<-'
bar = '|'
colon = ':'
dot = '.'
equal = '='
leftParen = '('
pad = ' '
rightParen = ')'
tilde = '~'