Beyond Traditional Program Slicing - CiteSeerX

5 downloads 0 Views 77KB Size Report
James Cook University .... reusable library module for the Eli compiler generation system[21] that allows ... Using examples from the Eli system we show that.
Beyond Traditional Program Slicing Anthony M. Sloane Jason Holdsworth Department of Computer Science James Cook University Townsville, QLD, 4811 AUSTRALIA Technical Report 95/8 Abstract Traditional program slices are based on variables and statements. Slices consist of statements that potentially affect (or are affected by) the value of a particular variable at a given statement. Two assumptions are implicit in this definition: 1) that variables and statements are concepts of the programming language in which the program is written, and 2) that slices consist solely of statements. Generalised slicing is an extension of traditional slicing where variables are replaced by arbitrary named program entities and statements by arbitrary program constructs. A model of generalised slicing is presented that allows the essence of any slicing tool to be reduced to a node marking process operating on a program syntax tree. Slicing tools can thus be implemented in a straight-forward way as reusable modules using tree-based techniques such as attribute grammars. A variety of useful program decompositions are shown to be instances of generalised slicing. Examples include call graph generation and interface extraction. To show the wide applicability of generalised slicing examples are also given of how slicing can enhance understanding of formal compiler specifications and make it possible to create subset language specifications.

1

1 Introduction Program slices were originally introduced by Weiser as decompositions of programs based on data flow and control analysis[1]. We refer to this kind of slicing as traditional slicing to distinguish it from the more general variety described later. Figure 1 illustrates the idea behind traditional slicing using the first example from Weiser’s paper; the code in (b) is obtained from the code in (a) by including only those statements that could affect the value of the variable Total at line 12. The pair (Total,12) is called a slicing criterion for this slice. Many researchers have investigated program slicing based on Weiser’s definition, primarily looking at the problem of generating the smallest possible slice for a given criterion. In general this problem cannot be solved[1], but various approaches result in good approximations. Some techniques are based on data flow equations [1, 2, 3] while others use graph representations of the program [4, 5, 6, 7, 8, 9, 10]. A survey is given elsewhere[11]. Applications of program slicing are many and varied[11], including debugging[12, 13], program comparison and integration[14], parallelisation[15, 16], testing[17] and maintenance[18, 19]. The traditional definition of slicing is concerned with slicing programs written in imperative programming languages. Two assumptions are implicit in this definition: 1. programs contain variables and statements, and 2. slices consist solely of statements. If a programmer is using a language that does not have variables or statements then traditional slicing criteria do not make sense. Consider languages for expressing context-free grammars such as used by YACC[20] or similar systems. These languages contain concepts such as grammar symbols and rules, but neither variables nor statements. Even for imperative programs, basing slices on variable values and statements is limiting since other concepts such as typing are ignored.

1 2 3 4 5 6

begin

4 5 6 7

begin

Read(X; Y ); Total := 0:0; if X