[squeak-dev] The Inbox: Compiler-cmm.185.mcz

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Thu Jan 13 07:57:58 UTC 2011


Without reading any code, I would say the Parser currentComment should
be nilled out as soon as transferred to the ParseNode.
But the compiler stuff often offer some surprises...

Nicolas

2011/1/13 Chris Muller <asqueaker at gmail.com>:
> Dear wizards, would you please double-check this change, which I made
> without fully understanding what I am doing, but which fixes a painful
> bug for me?  Life is too short to spend manually formatting code, so I
> use pretty print.  I really need it, but the formatter has been making
> multiple copies of comments, which I have to manually delete.  This of
> course defeats the benefit of automatic code-formatting..
>
> It's easy to reproduce:
>
>  - pull up any method with a comment inside a block, i.e..,
> WeakKeyDictionary>>#finalizeValues,
>  - Shift + yellow-click in the code-pane to bring up the alternate code-menu
>  - select 'pretty print'
>
> Observe the comment inside the "ifTrue:" expression at the bottom has
> been duplicated.
>
> This does not fix all cases, but it seems to at least alleviate these
> boolean-expression cases.  The comment is still duplicated inside and:
> / or: blocks, like in BlockNode>>#printStatementsOn:indent:.
>
> Thanks,
>  Chris
>
>
> On Wed, Jan 12, 2011 at 8:48 PM,  <commits at source.squeak.org> wrote:
>> A new version of Compiler was added to project The Inbox:
>> http://source.squeak.org/inbox/Compiler-cmm.185.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Compiler-cmm.185
>> Author: cmm
>> Time: 12 January 2011, 8:48:16.196 pm
>> UUID: 8aa7ae35-517f-4922-950c-0b88c9a33ec7
>> Ancestors: Compiler-nice.184
>>
>> Fix multiplying comments on pretty-print.
>>
>> =============== Diff against Compiler-nice.184 ===============
>>
>> Item was changed:
>>  ----- Method: Parser>>statements:innerBlock:blockNode: (in category 'expression types') -----
>>  statements: argNodes innerBlock: inner blockNode: theBlockNode
>>
>>        | stmts returns start |
>>        "give initial comment to block, since others trail statements"
>>        theBlockNode comment: currentComment.
>>        stmts := OrderedCollection new.
>>        returns := false.
>>        hereType ~~ #rightBracket ifTrue:
>>                [[theBlockNode startOfLastStatement: (start := self startOfNextToken).
>>                  (returns := self matchReturn)
>>                        ifTrue:
>>                                [self expression ifFalse:
>>                                        [^self expected: 'Expression to return'].
>>                                 self addComment.
>>                                 stmts addLast: (parseNode isReturningIf
>>                                                                ifTrue: [parseNode]
>>                                                                ifFalse: [ReturnNode new
>>                                                                                        expr: parseNode
>>                                                                                        encoder: encoder
>>                                                                                        sourceRange: (start to: self endOfLastToken)])]
>>                        ifFalse:
>>                                [self expression
>>                                        ifTrue:
>> +                                               [currentComment := nil..
>> -                                               [self addComment.
>>                                                 stmts addLast: parseNode]
>>                                        ifFalse:
>>                                                [self addComment.
>>                                                 stmts size = 0 ifTrue:
>>                                                        [stmts addLast:
>>                                                                (encoder encodeVariable:
>>                                                                        (inner ifTrue: ['nil'] ifFalse: ['self']))]]].
>>                  returns ifTrue:
>>                        [self match: #period.
>>                         (hereType == #rightBracket or: [hereType == #doIt]) ifFalse:
>>                                [^self expected: 'End of block']].
>>                  returns not and: [self match: #period]] whileTrue].
>>        theBlockNode
>>                arguments: argNodes
>>                statements: stmts
>>                returns: returns
>>                from: encoder.
>>        parseNode := theBlockNode.
>>        ^true!
>>
>>
>>
>
>
>
>



More information about the Squeak-dev mailing list