DOC PREVIEW
AN IMPLEMENTATION OF OBJECT-ORIENTED PROGRAM TRANSFORMATION

This preview shows page 1-2-3-4-5-6 out of 19 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Dartmouth College Computer Science Technical Report TR2001-395An Implementation of Object-Oriented Program Transformation forThought-Guided DebuggingTiffany WongDartmouth CollegeDepartment of Computer ScienceJune 2001Advisor: Thomas H. Cormen2AbstractThis paper presents our design and implementation of program transformation for C++that will be used in the context of a thought-guided debugging system. The program usesa lexical analyzer written in Flex and a grammar written in Bison that work inconjunction to scan the inputted C++ code for function definitions and class definitions.The code is then transformed to produce trace information for each defined function,while the original functionality of the code is left untouched. We also implement twoadditional data structures that are used for information storage during the course of theprogram.31 IntroductionDespite the numerous advances that have been made in various domains of thecomputing field over the past several decades, most programmers still rely on veryrudimentary techniques to debug their software. Many programmers are unable to utilizeexisting tools such as “tracers” to their full potential because the programmers lacksufficient training and experience in debugging. One possible means of implanting theprogrammer with the necessary skills to be effective at debugging is through the use of athought-guided advice system [2]. This new methodology proposes to use the existingtechnique of algorithmic debugging [4], a process by which the debugging systemacquires information about the program’s expected behavior and then uses thisinformation to localize errors, and extend the debugging technique for object-orientedprograms.There are four useful techniques that will help increase the automation of thealgorithmic debugging process: test-case generation, side-effect removal, programtransformation, and program slicing [2]. In this paper, we will focus on the technique ofprogram transformation. This method consists of inserting trace-generating actions intothe code in order to produce a trace file of relevant information [4] that will later be usedduring algorithmic debugging to help the user of the advice system locate the source oferror. We present one implementation of program transformation that can be used in anadvice system for C++ programmers. We will first describe an overview of the structureand design of the transformation program, and then discuss the actual implementation.4Finally, we conclude with a discussion of some of the limitations existing in thisimplementation of program transformation.2 Functional OverviewIn this section we describe more specifically the function of the transformation programand how it processes its inputs. We also provide some details on the internal datastructures that have been implemented in order to hold information about the code whileit is being processed.2.1 Program Transformation DesignThe transformation program is designed to take in as input a C++ program fileand to modify it to contain numerous annotations that will be used to generate traceinformation about the program, while still preserving the original functionality of thecode and avoiding any possible side-effects of modifying the code. An example of howthe program transformation should act on a piece of C++ code is presented in Figure 1.The trace information that is returned will then be used by the advice system in order tohelp the user narrow down and locate the specific source of error in the C++ code. Inparticular, program transformation will be performed on all function definitions locatedin the code. The general form of a function definition is given below [6]:ret_type function_name (parameter list){body of function}5Figure 1. The fragment on the left is the original code and the fragment on the rightis the code after transformation.There are three specific regions of each function definition that must be recognized andused in the transformation process in order to produce the trace file: the function name,the parameter list, and any return statements contained in the function body.Upon encountering a function definition in the code, the first step the programmust take is to extract out the function name and the return type of the function beingdefined. Both of these pieces of information must be stored to an external location to beused later in the transformation process. There are no actual modifications to the codeitself that need to be made at this stage.// Math functiondouble math(int x, double y){ double z; x = x + 5; y = y * 2; z = x + y; return z;}// Math functiondouble math(int x, double y){ cout << x << endl; cout << y << endl; double z; x = x + 5; y = y * 2; z = x + y; double temp = z; cout << temp << endl; return temp;}6The program must next recognize the parameter list belonging to the function.Each parameter’s name and type must then be parsed out and also saved to an externallocation. Once the body of the function has been entered, the program shouldimmediately insert statements that would generate the current values of all of theparameters passed to the function. This should be done before any statement in thedefined function body is processed in order to avoid any changes that may be made to thevalues of the parameters.Finally, the program processes the body of the function, searching for any returnstatements with non-void values. The program then alters the code to create a temporaryvariable to hold the value of the return statement, prints out its actual value, and thenreturns the temporary variable. The creation of this temporary variable is necessary inorder to ensure that no unwanted side-effects have been generated as a result of theseadditional code fragments. Therefore, the original execution of the return statementshould only be done once to store its value in the temporary variable. The temporaryvariable should then be used for all subsequent calls.2.2 Languages and Data StructuresOur implementation of program transformation requires the use of both a grammar forC++ and a lexical analyzer in order to step through the C++ code and insert the necessarytrace statements. It was also necessary to implement several data structures to store anyinformation that needed to be maintained over the course of running the program. Asymbol table is implemented in order to hold most of the state information about function7definitions. Function names and types as


AN IMPLEMENTATION OF OBJECT-ORIENTED PROGRAM TRANSFORMATION

Download AN IMPLEMENTATION OF OBJECT-ORIENTED PROGRAM TRANSFORMATION
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view AN IMPLEMENTATION OF OBJECT-ORIENTED PROGRAM TRANSFORMATION and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view AN IMPLEMENTATION OF OBJECT-ORIENTED PROGRAM TRANSFORMATION 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?