Ada for Software Engineers
Total Page:16
File Type:pdf, Size:1020Kb
Ada for Software Engineers M. Ben-Ari Weizmann Institute of Science Originally published by John Wiley & Sons, Chichester, 1998. Copyright c 2005 by M. Ben-Ari. You may download, display and print one copy for your personal use in non-commercial academic research and teaching. Instructors in non-commerical academic institutions may make one copy for each student in his/her class. All other rights reserved. In particular, posting this document on web sites is prohibited without the express permission of the author. Contents Preface x 1 The Language for a Complex World 1 1.1 Programming or software engineering? . 1 1.2 Reliable software engineering . 1 1.3 Language in software engineering . 2 1.4 Ada for software engineering . 2 1.5 The development of Ada . 3 1.6 From Ada 83 to Ada 95 . 4 1.7 The Ada Reference Manual . 5 2 A Simple Ada Program 8 2.1 Case study: country of origin . 8 2.2 Structure of a program . 9 2.3 Statements . 10 2.4 Predefined exceptions . 10 2.5 Types . 11 2.6 Subtypes . 16 2.7 Lexical elements . 18 3 Arrays 20 3.1 Case study: fill and justify text . 20 3.2 Array types . 24 3.3 Constrained array subtypes and objects* . 29 3.4 Type conversion* . 30 3.5 Operations on one-dimensional arrays* . 30 3.6 The context of array aggregates** . 31 v Contents vi 3.7 Parameter modes . 32 4 Elementary Data Structures 34 4.1 Case study: array priority queue . 34 4.2 Records . 36 4.3 Parameter associations and overloading . 37 4.4 Declaring and raising exceptions . 39 4.5 Case study: tree priority queue . 42 4.6 Access types . 45 5 Packages and Abstract Data Types 48 5.1 Modularization . 48 5.2 Case study: priority queue package . 49 5.3 Private types . 58 5.4 Limited types . 61 6 Type Extension and Inheritance 66 6.1 Case study: discrete event simulation . 66 6.2 Tagged types . 67 6.3 Primitive operations . 71 6.4 Overriding an operation . 73 6.5 Class-wide types . 77 6.6 Dynamic dispatching . 81 6.7 Encapsulation and child packages . 84 6.8 Type conversion* . 89 6.9 Objects of class-wide type* . 92 6.10 Abstract types* . 94 6.11 Implementation of dispatching** . 95 6.12 Multiple controlling operands** . 97 6.13 Dispatching on the function result** . 98 7 Generics 100 7.1 Generic declaration and instantiation . 100 7.2 The contract model . 104 7.3 Generic formal subprograms . 106 7.4 Dependence of generic formal parameters . 107 Contents vii 7.5 Generic formal tagged private types* . 109 7.6 Generic formal derived types* . 112 7.7 Generic formal objects* . 116 7.8 Indefinite and abstract parameters** . 117 7.9 Formal package parameters** . 118 7.10 Generic children* . 122 7.11 Limitations of the contract model** . 123 8 Types Revisited 126 8.1 Characters and strings . 126 8.2 Discriminants . 134 8.3 Variant records . 135 8.4 Representation items . 138 8.5 Deeper into discriminants . 139 8.6 Untagged derived types* . 142 9 Access Types 145 9.1 General access types . 145 9.2 Access-to-subprogram types . 146 9.3 Case study: callback . 146 9.4 Accessibility rules . 148 9.5 Access parameters* . 150 9.6 Storage pools* . 152 9.7 Controlled types* . 152 9.8 Access discriminants** . 157 10 Numeric Types 160 10.1 Principles of numeric types . 160 10.2 Integer types . 162 10.3 Types versus subtypes . 163 10.4 Modular types . 163 10.5 Real types . 165 10.6 Floating point types . 166 10.7 Fixed point types . 168 10.8 Advanced concepts* . 174 Contents viii 11 Input–output 179 11.1 Libraries for input–output . 179 11.2 Package Exceptions* . 180 11.3 Streams** . 182 12 Program Structure 186 12.1 Compilation and execution . 186 12.2 Subunits . 187 12.3 Pragmas* . 189 12.4 Elaboration* . 189 12.5 Renamings . 191 12.6 Use type clause . 193 12.7 Visibility rules** . 193 12.8 Overloading** . 195 13 Concurrency 197 13.1 Concepts . 197 13.2 Tasks and protected objects . 199 13.3 Rendezvous . 204 13.4 Case study: the CEO problem . 210 13.5 Entry families . 217 13.6 Protected subprograms . 217 13.7 The requeue statement . 218 13.8 Rules for entries of protected types* . ..