An Investigation Into the Generality of a Graphical Representation Of
Total Page:16
File Type:pdf, Size:1020Kb
Clemson University TigerPrints All Dissertations Dissertations 5-2016 An Investigation Into the Generality of a Graphical Representation of Program Code for Source to Source Translation Stephen Schaub Clemson University, [email protected] Follow this and additional works at: https://tigerprints.clemson.edu/all_dissertations Recommended Citation Schaub, Stephen, "An Investigation Into the Generality of a Graphical Representation of Program Code for Source to Source Translation" (2016). All Dissertations. 1677. https://tigerprints.clemson.edu/all_dissertations/1677 This Dissertation is brought to you for free and open access by the Dissertations at TigerPrints. It has been accepted for inclusion in All Dissertations by an authorized administrator of TigerPrints. For more information, please contact [email protected]. An Investigation Into the Generality of a Graphical Representation of Program Code for Source to Source Translation A Dissertation Presented to the Graduate School of Clemson University In Partial Fulfillment of the Requirements for the Degree Doctor of Philosophy Computer Science by Stephen Schaub May 2016 Accepted by: Brian A. Malloy, Committee Chair Jason Hallstrom Murali Sitaraman Mark Smotherman Abstract This thesis addresses the problem of defining a source-to-source translation system for reusable software components. It describes the development of an interoperable language for writing software components, and presents a system to translate components written in the interoperable language to a set of compatible target languages. The common features in a set of popular pro- gramming languages are analyzed to inform the design of the interoperable language. An evaluation is performed by using the source-to-source translator to convert two well-known open source Java libraries to C++ and Python, and the accuracy and performance of the resulting translations are assessed. ii Dedication To my wife, Ruth, for her love and support, and to my father, Paul, for introducing me to the field of computer science. iii Acknowledgments I would like to thank my advisor, Dr. Brian Malloy, for shepherding me through the topic selection, research, and the production of this thesis. I am deeply indebted to him for his encour- agement and for the many hours he invested meeting with me, reviewing my work, coauthoring papers, and providing invaluable guidance. I am also grateful to each of my committee members for their helpful feedback on my research: thanks to Dr. Mark Smotherman for introducing me to the department and advising me on my Ph.D. program; to Dr. Murali Sitaraman and the RESOLVE Software Research Group for exposing me to a significant ongoing research project; and to Dr. Jason Hallstrom, whose stimulating classes and seminars provided early writing experience and prepared me for my own research. Finally, I would like to acknowledge the support of my colleagues in the Division of Mathematical Science at Bob Jones University, especially Dr. Gary Guthrie, Dr. Melissa Gardenghi, Dr. Jim Knisely, Mr. Alan Hughes, and Dr. Debbie Summerlin, who have provided encouragement and shouldered additional responsibilities during my leave of absence to help make this research possible. iv Table of Contents Title Page ............................................ i Abstract ............................................. ii Dedication............................................ iii Acknowledgments ....................................... iv List of Tables ..........................................vii List of Figures..........................................viii List of Listings ......................................... ix 1 Introduction......................................... 1 1.1 Problem Statement..................................... 3 1.2 Research Approach..................................... 3 1.3 Thesis Statement...................................... 4 1.4 Thesis Organization .................................... 4 2 Related Work ........................................ 5 3 Background .........................................10 3.1 Program Representation Graphs ............................. 10 3.2 Language Families ..................................... 12 3.3 Language Interoperability................................. 13 3.4 Language Features..................................... 15 4 Challenges ..........................................19 4.1 Source-to-Source Challenges................................ 19 4.2 Addressing Source-to-Source Challenges......................... 20 5 System Overview......................................22 5.1 Functional View ...................................... 22 5.2 Development View..................................... 23 6 Interoperable Language Design .............................26 6.1 Design Methodology.................................... 26 6.2 Analysis Set Selection ................................... 28 6.3 Language Analysis and Design .............................. 28 7 Translation of Language Features ............................45 v 7.1 Mapping Java to iJava................................... 45 7.2 Mapping iJava to Python and C++ ........................... 47 8 Evaluation and Testing ..................................54 8.1 Test Environment...................................... 54 8.2 Test Cases.......................................... 54 8.3 Test Case Evaluation and Preparation.......................... 56 8.4 Reliability Tests and Execution Traces.......................... 57 8.5 Quality Tests........................................ 61 8.6 Performance Tests ..................................... 62 8.7 Performance Test Methodology.............................. 63 9 Conclusions and Future Directions ...........................65 Appendices ...........................................67 A iJava Language Specification ............................... 68 B iJava Grammar....................................... 106 Bibliography...........................................112 vi List of Tables 6.1 Data Type Analysis .................................... 34 6.2 Operator and Expression Analysis ............................ 37 6.3 Statement Analysis..................................... 38 6.4 Subroutine Feature Analysis................................ 39 6.5 Object Oriented Feature Analysis............................. 42 6.6 Exception Feature Analysis ................................ 43 6.7 Miscellaneous Feature Analysis.............................. 44 8.1 Test Cases.......................................... 55 8.2 Reliability Test Results .................................. 61 8.3 Quality Test Results: PureMVC ............................. 62 8.4 Quality Test Results: Apache Math Commons ..................... 62 8.5 PureMVC and Apache Performance Test Results.................... 63 8.6 Basic Iteration Performance Test Results ........................ 64 vii List of Figures 3.1 A sample Abstract Syntax Tree.............................. 11 3.2 A sample Abstract Semantic Graph ........................... 12 3.3 Source to Source Interoperability............................. 14 3.4 Internal Organization of a Source-To-Source Translator ................ 15 5.1 System Overview...................................... 22 5.2 Expanded System Overview................................ 23 5.3 iJava ASG Organization (Partial)............................. 24 5.4 Target Code Generation Classes.............................. 25 6.1 TIOBE Index History ................................... 29 7.1 Mapping of iJava types to C++ and Python ...................... 51 8.1 Apache Commons Math Classes Translated....................... 57 viii List of Listings 3.1 Source code for class Node................................. 11 7.1 Java Do-while example................................... 46 7.2 iJava Do-while translation................................. 46 7.3 Java inner class example.................................. 47 7.4 iJava inner class translation................................ 47 7.5 Java static initialization example............................. 50 7.6 C++ mapping....................................... 50 7.7 Java dynamic cast example................................ 51 7.8 C++ cast translation.................................... 52 7.9 Java try-catch example................................... 53 7.10 Python try-except translation............................... 53 8.1 Trace of JUnit Test..................................... 59 8.2 Trace of Unit Test (Python Translation)......................... 60 8.3 Python loop iteration performance test.......................... 64 ix Chapter 1 Introduction The software development landscape has changed radically in its relatively short history. The introduction of portable high-level languages, and in particular, the ascendance of object-oriented technologies, has enabled a degree of software reuse that was unimaginable to the assembly language programmers of the 1950's. And yet, solutions to fundamental problems in software engineering reuse and reliability remain elusive and in many cases unsolved. The proliferation of high-level languages|the mechanism enabling reuse|has been a significant factor in fueling this growth but has also increased the scope of the problem, thereby retarding progress in arriving at solutions. Despite ongoing efforts, the limitations of existing language interoperability mechanisms continue to inhibit interlingual code reuse. This lack of progress in reuse, in turn, has hindered improvements in software reliability. If there were a single dominant language, or