
Universidad Carlos III de Madrid Escuela Politécnica Superior Bachelor Degree in Computer Engineering Bachelor Thesis Contract-Based Programming on Modern C++ Author: José Cabrero Holgueras Supervisor: José Daniel García Sánchez Leganés, Madrid, Spain July 2018 “Mentors are there in the moments of truth” Anonymous iv Contract-Based Programming on the Modern C++ Acknowledgements There are so many people who have been involved in the development of this project. First of all, I would like to thank all my family for all their support and unconditional help, especially over this last year. I could not have borne the load if you would not have been present with all this help. There are not enough lines in this document to thank what you have given me. I want to especially thank Javier López. I did not think I would live to know a genius, but I did. He has computer science in his veins and transmits his passion to anyone close to him. It is astonishing what he can do with a computer. He has taught me everything he knew when I needed and helped me like no one has in this work. A real mentor is the one that sits next to you and guides you in solving your problems, and Javier has been mine. There is probably no one in the group as dedicated to its task as Javier is. I wish I had had more time to share with him since it has been a real inspiration for this work. If someone deserves credit in the ideas of this project, it is Javier who does. I would also like to give a huge thank to Manuel F. Dolz. You also contributed to this project offering me to work with you. When I received the offer, I did not think I would earn what I have. It has been an incredible experience. If I look back to September, I was a completely different person, and things that change you, are what define who you are. I am specially thankful to David del Rio, to Javier Fernandez and to Mario Vasile, because they were present on the last days of this project. Each of them has given something to this project that makes it unique and without their collaboration, this project would not have been what it is. I do not really imagine how this would have ended up without your collaboration. Thank you. My labmates also deserve some words here. They have been my classmates, my friends and my partners during this journey that has been the degree. Thanks to Laura Martín for helping me in those desperation moments in the lab, you really helped me out. And thanks to Nerea Luna for all those train travels back and forth, your support during all these years is immeasurable. Thanks for talking to me on stress moments and for always believing in me. v Thanks to Saúl Alonso, because he has always guided me and telling me about any opportunities that there are out there; to Javier Prieto, who has cared of me from the very first moment that I joined the group. He has always been there and it has been an inspiration to follow what I really liked to do, and his support at all points. And to Guillermo Izquierdo, who helped me a lot on the decision of the Master Course and I really believe that thanks to that, I will follow my dream. Thanks to you all, you have all given me something that I will always keep, and you have all been an inspiration for me to be better. Thanks to Ignacio Guillermo Martínez and to Alejandro Rey. They have been my classmates and I could not imagine a better group of friends. Thanks to all the work you put up to help me with practices and for those good moments we spent. Finally, thanks José Daniel García and the ARCOS group for offering me a job in the department and lending me all the equipment and tools that I needed. This project has been more than a learning process, it has been a personal growth. Thanks to all of you. Contract-Based Programming on Modern C++ Bachelor Thesis José Cabrero Holgueras Abstract Contract-based Programming or Design By Contract (DBC) is a discipline for system construction that in recent years has postulated to be one of the most solid and reliable models for software creation. It is well known that in the software industry the number of projects not being successfully developed is huge. The main cause of the failure is that projects do not meet user expectations. In this context, Design By Contract seems to emerge as a solution to decrease this failure rate. This philosophy provides a set of mechanisms for the validation of part of the requirements specification. In recent years, several programming languages started to implement DBC, either as part of the lan- guage or an external library. The main programming languages that support contract-based program- ming are Ada 2012, Spark, Eiffel, D, C# CodeContracts or Microsoft Source-Code Annotation Language (Microsoft SAL). Traditionally, C++ has been a programming language focused on flexibility, perfor- mance and efficiency. This has attracted many people to carry out projects using this programming language. However, trends make programming languages change, and the interests of the industry are leaning towards solid solutions. Those solutions shall include frameworks that are reliable. With this same purpose, C++ has designed a specification for the implementation of Design By Contract in the programming language. This new specification has been accepted by the ISO C++ committee to be included in C++20. The specification includes several clauses that allow the user to write pre/post- conditions on the code. This allows part of the requirement specification to be merged into the code, enabling traceability between the phases of the software project. The specification of a new feature in a programming language implies changes in how the language is understood by a compiler. For the implementation of a new specification, several changes are required at different levels. This document describes these changes. Additionally, it provides an overview of the structure of a compiler, and a brief description of all the parts of the Clang C++ compiler. Keywords: · Contract Based Programming · Contract · C++ · Clang · Compiler vii Programación basada en Contratos en el C++ moderno Trabajo Fin de Grado José Cabrero Holgueras Resumen La programación por contratos es una disciplina de construcción de sistemas que recientemente se ha postulado como una de las más solidas y fiables para la creación de sistemas software. Se sabe que la industria de desarrollo de software no está siendo exitosa debido en parte a la tasa de fallos que hay en éstos. En este contexto, la programación por contratos emerge como una solución para reducir esta tasa de fracaso en la industria. Esta tendencia de desarrollo provee a los usuarios con mecanismos para la validación de los requisitos. En los últimos años, varios lenguajes de programación han comenzado a implementar la programación por contratos, bien como parte del lenguaje o como una biblioteca externa. Los principales lenguajes de programación que a día de hoy soportan programación por contratos son Ada 2012, Spark, Eiffel, D, C# CodeContracts or Microsoft Source-Code Annotation Language (Microsoft SAL). Tradicionalmente, C++ ha sido un lenguage de programación centrado en proveer al usuario con flexibilidad, rendimiento y eficiencia. Estas características han atraido a muchos clientes de cara a utilizar este lenguaje de progra- mación en proyectos. Sin embargo, las tendencías fuerzan cambios en los lenguajes de programación, y los intereses de las empresas actualmente se están inclinando hacia soluciones robustas. Estas soluciones, deben incluir marcos de trabajo que sean fiables. Con esto en mente, se ha diseñado una especificación para la programación por contratos en el lenguaje de programación. Esta nueva especificación, ha sido aceptada para por el Comite ISO C++ para ser incluida en C++20. Esta especificación provee al usuario con varios mecanismos que permiten verificar condiciones en el código. Esto permite directamente en- lazar la especificación de requisitos con la implementación de los mismos. La especificación de una nueva característica dentro de un lenguaje de programación implica cambios en como el lenguaje es entendido por un compilador. Para la implementación de estos nuevos requi- sitos se requiere de realizar modificaciones en el compilador en distintos niveles de análisis. En este proyecto, se describe un resumen de los cambios que son necesarios dentro de un compilador. Estos cambios incluyen un resumen de la estructura del compilador, posteriormente se desglosa la estructura del compilador de C++ Clang y por último se describen las modificaciones en cada una de las partes involucradas. Keywords: · Programación Basada en Contratos · Contratos · C++ · Clang · Compilador ix Contents Acknowledgments v Abstract vii Resumen ix List of Figures xviii List of Tables xxii 1 Introduction 1 1.1 Background . .1 1.2 Objectives . .2 1.3 Document Structure . .2 2 State of the Art 5 2.1 Eiffel . .5 2.1.1 Design By Contract in Eiffel . .7 2.1.2 Advantages and Disadvantages of Eiffel . .8 2.2 Ada 2012 . 10 2.2.1 Design By Contract in Ada 2012 . 11 2.2.2 Advantages and Disadvantages of Ada 2012 . 13 2.3 Spark . 15 2.3.1 Design By Contract in Spark . 16 2.3.2 Advantages and Disadvantages of Spark . 18 2.4 C# - CodeContracts . 19 2.4.1 Design By Contract in C# - Code Contracts . 20 2.4.2 Advantages and Disadvantages of C# - Code Contracts . 21 2.5 D Programming Language . 22 2.5.1 Design by Contract in D .
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages230 Page
-
File Size-