xtending our vhdl xtext formatter with the formatter2 api
play

Xtending our VHDL Xtext formatter with the formatter2 API ir. - PowerPoint PPT Presentation

EclipseCon France 2017-06-21 Xtending our VHDL Xtext formatter with the formatter2 API ir. Titouan Vervack redefine.digital.design: Helping you deal with complexity in VHDL and Verilog. EclipseCon France, Toulouse 2017-06-21 Xtending our VHDL


  1. Alignment! 22

  2. Alignment! 22

  3. Alignment! 22

  4. Alignment! 22

  5. Alignment! start end 22

  6. Alignment! start end 22

  7. Alignment! start end Find smallest encapsulating object that formats region between start and end 22

  8. Alignment! start end Find smallest encapsulating object that formats region between start and end 22

  9. Alignment! clk : in std_logic := ‘X’; 23

  10. Alignment! clk : in std_logic := ‘X’; start end 23

  11. Alignment! clk : in std_logic := ‘X’; start end end.getSemanticElement() PortList PortDeclaration PortDeclaration name direction type value 23

  12. Alignment! x + 4 clk : in std_logic := ‘X’; start end offset x end.getSemanticElement() PortList PortDeclaration PortDeclaration name direction type value 23

  13. Alignment! Format smallest encapsulating object val rule = portDecl.getParserRule() val oldAccess = createTextRegionAccess(rule, portDecl.text) val formatted = portDecl.format() 24

  14. Alignment! Format smallest encapsulating object val rule = portDecl.getParserRule() val oldAccess = createTextRegionAccess(rule, portDecl.text) val formatted = portDecl.format() Map unformatted string to formatted string val newAccess = createTextRegionAccess(rule, formatted.text) val oldIndices = oldAccess.getIndices(start, end) val length = newAccess.countBetween(oldIndices) 24

  15. Align on first parameter? → return ( →→ foo((5, →→ ·····6), →→ ····3)); 25

  16. Align on first parameter? → return ( →→ foo((5, →→ ·····6), →→ ····3)); 25

  17. Align on first parameter? → return ( →→ foo((5, →→ ·····6), →→ ····3)); → return (5, → ········foo((5, → ·············6), → ············3)); 25

  18. Align on first parameter? → return ( →→ foo((5, →→ ·····6), →→ ····3)); → return (5, → ········foo((5, → ·············6), → ············3)); 25

  19. Align on first parameter? → return ( → return foo((5, →→ foo((5, → ············6), →→ ·····6), → ···········3)); →→ ····3)); → return (5, → ········foo((5, → ·············6), → ············3)); 25

  20. Align on first parameter? → return ( → return foo((5, →→ foo((5, → ············6), →→ ·····6), → ···········3)); →→ ····3)); → return (5, → ········foo((5, → ·············6), → ············3)); 25

  21. Align on first parameter? → return ( → return foo((5, →→ foo((5, → ············6), →→ ·····6), → ···········3)); →→ ····3)); → return foo( → return (5, →→ (5, → ········foo((5, →→ ·6), → ·············6), →→ 3)); → ············3)); 25

  22. Align on first parameter? → return ( → return foo((5, →→ foo((5, → ············6), →→ ·····6), → ···········3)); →→ ····3)); → return foo( → return (5, →→ (5, → ········foo((5, →→ ·6), → ·············6), →→ 3)); → ············3)); 25

  23. Align on first parameter? → return ( → return foo((5, →→ foo((5, → ············6), →→ ·····6), → ···········3)); →→ ····3)); Find largest encapsulating element on same line → return foo( → return (5, →→ (5, → ········foo((5, →→ ·6), → ·············6), →→ 3)); → ············3)); 25

  24. Actual timeline 6. Feature parity & extend formatter with new features Correct indentation 26

  25. Actual timeline 6. Feature parity & extend formatter with new features Correct indentation val replacements = formatter.format(request) 26

  26. Actual timeline 6. Feature parity & extend formatter with new features Correct indentation val replacements = formatter.format(request) replacements .filter[ r| ] 26

  27. Actual timeline 6. Feature parity & extend formatter with new features Correct indentation val replacements = formatter.format(request) replacements .filter[ r| r.lineCount > 1 ] 26

  28. Actual timeline 6. Feature parity & extend formatter with new features Correct indentation val replacements = formatter.format(request) replacements .filter[ r| r.lineCount > 1 && r.replacementText.newlines + 1 == r.lineCount ] 26

  29. Actual timeline 6. Feature parity & extend formatter with new features Formatter tags 27

  30. Actual timeline 6. Feature parity & extend formatter with new features Formatter tags -- @formatter:off Turns formatter off -- @formatter:on Turns formatter on 27

  31. Actual timeline 6. Feature parity & extend formatter with new features Formatter tags -- @formatter:off Turns formatter off -- @formatter:on Turns formatter on val originalRegions = request.getRegions() ?: document.region 27

  32. Actual timeline 6. Feature parity & extend formatter with new features Formatter tags -- @formatter:off Turns formatter off -- @formatter:on Turns formatter on val originalRegions = request.getRegions() ?: document.region val betweenRegions = document.findRegionsBetween(off, on) 27

  33. Actual timeline 6. Feature parity & extend formatter with new features Formatter tags -- @formatter:off Turns formatter off -- @formatter:on Turns formatter on val originalRegions = request.getRegions() ?: document.region val betweenRegions = document.findRegionsBetween(off, on) .addAll(document.findRegionsBetween(off, EOF)) 27

  34. Actual timeline 6. Feature parity & extend formatter with new features Formatter tags -- @formatter:off Turns formatter off -- @formatter:on Turns formatter on val originalRegions = request.getRegions() ?: document.region val betweenRegions = document.findRegionsBetween(off, on) .addAll(document.findRegionsBetween(off, EOF)) val newRegions = originalRegions.removeRegions(betweenRegions) 27

  35. Actual timeline 6. Feature parity & extend formatter with new features Formatter tags -- @formatter:off Turns formatter off -- @formatter:on Turns formatter on val originalRegions = request.getRegions() ?: document.region val betweenRegions = document.findRegionsBetween(off, on) .addAll(document.findRegionsBetween(off, EOF)) val newRegions = originalRegions.removeRegions(betweenRegions) request.setRegions(newRegions) 27

  36. Performance 7. Performance tweaking to same or better level than old 28

  37. Performance 7. Performance tweaking to same or better level than old ● Cache ITextRegionAccess in subformats 28

  38. Performance 7. Performance tweaking to same or better level than old ● Cache ITextRegionAccess in subformats ● Cache IParser.createAllRules(Grammar) 28

  39. Performance 7. Performance tweaking to same or better level than old ● Cache ITextRegionAccess in subformats ● Cache IParser.createAllRules(Grammar) ● Merge all replacements into one big replacement 28

  40. Performance 7. Performance tweaking to same or better level than old emacs/xtend > 25m 29

  41. Performance 7. Performance tweaking to same or better level than old emacs/xtend > 25m 30

  42. Biggest problems in hindsight 31

Recommend


More recommend