Peephole Pretty Printing

Copyright © 2004 Stoney Jackson, <hjackson@wnec.edu>

Distributed under the GPLv3.

Home: http://peephole.cs.ucdavis.edu/

 

Download: peephole.tar.bz2 (~4MB. Aug 7, 2007).

 

Overview

 

Peephole pretty printing is an optimization of WadlerÕs pretty print algorithm. WadlerÕs pretty printer provides a flexible high-level language for specifying the format for programming languages. His algorithm does a nice job of maximizing the use of screen space while maintaining the presentation of source codeÕs rich structure. We want to use WadlerÕs pretty printer to maintain codeÕs readability even when source code visualizations are applied that may alter the presentationÕs fonts, sizes, and styles (e.g., FurnasÕ fisheye views and fisheye menus). However, in most graphics environments, to accommodate kerning, measuring textsÕ width is typically slow. And since WadlerÕs pretty printer frequently measures textsÕ width, making use of his algorithm in an interactive visualization environment is prohibitive. Pretty printing moderate to large files often takes more than one second to format. This violates an important principle in interaction design: to avoid interrupting a userÕs flow of thought, operations must be performed in under one second.

 

Peephole pretty printing optimizes WadlerÕs algorithm for interactive environments by first formatting code immediately around a user-selected point of interest, allowing us to regularly respond to user interactions in under one second. This is the same strategy used by graphics environments to render images; they only render the visible portion of the image. While there is nothing new about this strategy, applying it to WadlerÕs algorithm is non-trivial—especially since we want to allow changes to window sizes and font attributes between formatting request (which is desirable for interactive environments and interactive visualizations), and since we want our peepholeÕs format to remain true to that which WadlerÕs algorithm would have produced by formatting the entire file (which makes it possible to format the remaining file after the peephole and for the two results to be combined without any awkward artifacts). Our peephole pretty print algorithm efficiently solves these problems.

 

Our peephole technology is distributed over several tools. This is a reflection of its evolution. The first tool written was Peep. It was developed to evaluate the performance of the peephole algorithm. Next was the Peepeye browser (original called peeper). It was developed as a proof of concept to demonstrate how our peephole algorithm can be used in source code browsers and how it can support fisheye visualizations. Last, an Eclipse plug-in (original called peepest) was developed to make our peephole technology available in EclipseÕs JDT. The plug-in does not implement fisheye views, because at the time it was developed the SWTÕs StyledText, which is used at the core of JDT, did not support multiple fonts in a single StyledText object. This limitation was recently corrected, and we have begun extending our plug-in to support fisheyes.

 

Contents of Peephole Distribution

 

Subprojects are located in subfolders within this distributionÕs main folder. The names of the subfolders are the same as the subprojectsÕ name. E.g., peephole/Peephole Framework.

 

 

Peephole Framework

 

This is a an application programmers interface (API) for developing pretty printers and visualizations that use our peephole pretty printing algorithm. The latest version is included in the Eclipse Plugin.

 

README: ./Peephole Framework/README.html

 

 

Peep

 

This is a program for comparing the layout times of global vs peephole pretty-printing strategy, and for investigating the affects of width, height, and fisheye degree on the layout time of each strategy. Its primary function is to report the time it takes for each strategy to pretty-print a window of text around a given focal point. It can also be used to visually confirm the stability of the peephole layout strategy. This product operates on abstract syntax tree files produced by JavaML.

 

README: ./Peep/README.txt

 

 

Peepeye

 

This is a source browser that allows one to browse a tree of code. It supports continuous and discrete fisheye views, and uses peephole pretty printing to maintain the format of code. This product calls JavaML to produce abstract syntax trees for source code. JavaML must be on the path.

 

README: ./Peepeye/README.html

 

 

Eclipse Plugin

 

This is a plugin for the Eclipse platform; specifically for the Java Development Toolkit (JDT) plugin for Eclipse. It adds peephole pretty printing to JDTs enriched Java editor. This plugin only requires JDT and Eclipse.

 

README: ./Eclipse Plugin/README.html

 

 

JavaML

 

This is an external project built by Greg J. Badros (http://www.badros.com/greg/JavaML/). We maintain and distribute a version of JavaML in compliance with its licensing to ensure that its output is what our peephole products expect. JavaML is a Jikes Java compiler that has been expanded to parse Java source files into XML representing the codeÕs abstract syntax tree. Peep works on the XML produced by this tool, but does not run JavaML automatically. Peeper also works on the XML produced by JavaML. However, Peeper will try to call JavaML if a file has not yet been parsed.

 

README: ./JavaML/README.html