Skip to content

Commit

Permalink
Better aproximate lenght of line-labels #107
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaumgarten committed Sep 19, 2021
1 parent 512d87d commit 477dc17
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions pkg/nolol/converter_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,25 +164,14 @@ func (c *Converter) getLengthOfLine(line ast.Node) int {
ygen := parser.Printer{}
ygen.Mode = parser.PrintermodeCompact

silenceGotoExpression := false
ygen.PrinterExtensionFunc = func(node ast.Node, visitType int, p *parser.Printer) (bool, error) {
if gotostmt, is := node.(*ast.GoToStatement); is {
if c.getGotoDestinationLabel(gotostmt) != "" {
if visitType == ast.PreVisit {
silenceGotoExpression = true
p.Write("gotoXX")
if visitType == ast.PreVisit || visitType == ast.SingleVisit {
if deref, is := node.(*ast.Dereference); is {
if _, exists := c.getLineLabel(deref.Variable); exists {
// This is a dereference for a jump-label.
p.Write("XX")
return true, nil
}
if visitType == ast.PostVisit {
silenceGotoExpression = false
}
return true, nil
}
}
if silenceGotoExpression {
if _, is := node.(ast.Expression); is {
// The current expression is inside a goto.
// DO NOT PRINT IT
return true, nil
}
}
return false, nil
Expand Down

0 comments on commit 477dc17

Please sign in to comment.