
C# COMPILER EXTENSION TO SUPPORT THE OBJECT CONSTRAINT LANGUAGE VERSION 2.0 by David Arnold A thesis submitted to the Faculty of Graduate Studies and Research in partial fulfillment of the requirements for the degree of Masters of Computer Science Ottawa-Carleton Insititute for Computer Science School of Computer Science Carleton University Ottawa, Ontario 2004 Copyright c 2004 by David Arnold The undersigned hereby recommend to the Faculty of Graduate Studies and Research acceptance of the thesis, C# Compiler Extension to Support the Object Constraint Language Version 2.0 submitted by David Arnold Dr. Douglas Howe (Director, School of Computer Science) Dr. Francis Bordeleau (Thesis Supervisor) Dr. Jean-Pierre Corriveau (Thesis Supervisor) Carleton University 2004 Abstract The Object Management Group’s Object Constraint Language (OCL), is part of the Unified Model- ing Language (UML). The OCL is a formal language for the specification of behavioral constraints in software models. When models are transformed into executable code, such constraints are often lost or converted into non-executable comments. This research examines the integration of the OCL at the code level. Microsoft’s .NET initiative introduces a new high-level language: C#. The C# language introduces several new concepts; including properties, delegates and events. The integration of the OCL into C# consists of creating not only a syntactical integration but, also a semantic one. Such integration will contribute to the verification of the OCL specification, as well as to provide a mechanism for the transformation of OCL expressions across the modeling levels defined under Model Driven Architecture (MDA). i Acknowledgements Acknowledgements I am grateful for the encouragement and feedback provided by my thesis supervisors: Jean-Pierre Cor- riveau and Francis Bordeleau. Without their help and support the thesis and implementation would not be what it is today. A special thanks to Toby McClean and Juan Pablo Zamora Zapata. Toby pointed out errors and provided invaluable critiques of the implementation at various stages of its development. Juan Pablo showed me that Fritos and hot sauce are in fact breakfast foods. Kevin Parker, my best friend, helped me to procrastinate at all hours of the day, with countless Halo games and movies. Thanks guy!! I am indebted to Tony D’Ambrogio and Carleton University for the monetary support that was provided during the course of my research. I definitely would not have been able to focus on my research without their contributions. Finally, my mother, my father and my sister have always been a source of encouragement, even when they had no idea what I was talking about. Thank you all. ii Contents 1 Introduction 1 1.1 Context and Motivation . 1 1.1.1 Models . 1 1.1.2 Design by Contract . 2 1.2 Problem . 3 1.3 Objectives . 4 1.4 Contributions . 4 1.4.1 MDA . 4 1.4.2 OCL 2.0 . 5 1.4.3 Design by Contract . 5 1.5 Thesis Structure . 6 2 Background 8 2.1 Design by Contract . 8 iii 2.1.1 Elements of Design by Contract . 8 2.1.2 Benefits of Design by Contract . 13 2.1.3 Issues of Design by Contract . 15 2.1.4 Summary of Design by Contract . 19 2.2 The Object Constraint Language . 19 2.2.1 OCL, UML, and MDA . 20 2.2.2 PIMs and PSMs . 20 2.2.3 Benefits of MDA . 22 2.2.4 The UML and MDA . 23 2.2.5 The OCL and the UML . 23 2.2.6 Summary of the OCL, the UML, and MDA . 32 2.3 Introduction to .NET . 33 2.3.1 What is .NET? . 33 2.3.2 The Common Language Runtime . 34 2.3.3 Framework Class Library . 37 2.3.4 Hands On .NET . 38 2.3.5 Shared Source Common Language Infrastructure . 41 2.3.6 The Mono Project . 42 2.3.7 .NET Summary . 42 2.4 C#............................................. 43 iv 2.4.1 C# Overview . 43 2.4.2 Types . 44 2.4.3 Classes . 46 2.4.4 Properties . 47 2.4.5 Delegates . 48 2.4.6 Events . 50 2.4.7 Indexers . 51 2.4.8 Operators . 52 2.4.9 The new Modifier . 53 2.4.10 Interfaces . 54 2.4.11 Structures . 55 2.4.12 Parameters . 56 2.4.13 Attributes . 58 2.4.14 C# and .NET . 61 2.4.15 Summary . 61 2.5 Existing Tools and Technologies . 61 2.5.1 The Octopus Tool . 62 2.5.2 The Object Constraint Language Environment . 62 2.5.3 Spec# . 63 2.5.4 Jcontract . 64 v 2.5.5 iContract . 64 2.5.6 Eiffel . 65 2.5.7 Alloy . 66 2.5.8 Summary . 68 2.6 Summary . 68 3 Syntax 70 3.1 OCL Blocks . 70 3.2 C# Grammar Changes . 71 3.3 Parsing OCL Expressions . 74 3.4 The OCL Grammar . 75 3.4.1 Variable Expressions . 75 3.4.2 Iterator Variable Lists . 77 3.4.3 Iterators as Methods . 77 3.4.4 Properties . 78 3.4.5 Indexers . 78 3.4.6 Summary . 80 3.5 The Assignment of OCL Expressions . 80 3.5.1 Association Context Declarations . 80 3.5.2 Classifier Context Declarations . 82 3.5.3 Operation Context Declarations . 83 3.6 Summary . 84 vi 4 Semantics 86 4.1 Preconditions and Postconditions . 86 4.2 Class Invariants . 87 4.3 Constraints on Properties . 89 4.4 Constraints on Indexers . 89 4.5 Constraints and Delegates . 89 4.6 Constraints and Events . 91 4.7 Constraints and Inheritance . 92 4.7.1 Class Invariants . 92 4.7.2 Preconditions . 94 4.7.3 Postconditions . 95 4.7.4 Summary of Findler’s Method . 96 4.8 Constraints on Interfaces . 98 4.9 Constraints on Structures . 98 4.10 Constraints on Abstract Classes . ..
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages312 Page
-
File Size-