ADA Types:
ADA – Basic Types – Objects:
— Type declarations
type MY_T is …; — user defined type
type YOUR_T is …; — another user defined type
— Object declarations
MY_VAR : MY_T; — variable declaration
II_VAR : MY_T; — another object of MY_T
YOUR_VAR : YOUR_T; — another variable declaration
“””
— Assignment statements
MY_VAR := II_VAR; — legal assignment
MY_VAR := YOUR_VAR; — compilation error
ADA – Basic Types – Integer:
— User defined integer types
type I_INT_T is new INTEGER;
type II_INT_T is new INTEGER range 1 .. 100;
— Object declarations
I_INT : I_INT_T;
II_INT : II_INT_T;
III_INT : INTEGER; — INTEGER object
IV_INT : INTEGER range 20 .. 30; — INTEGER constrained
I_INT := II_INT; — Illegal !!
I_INT := I_INT_T (II_INT); — Limited type casting
ADA – Basic Types – Integer Subtype:
— Type declaration
subtype I_SI is INTEGER;
subtype II_SI is I_SI range 5 .. 10;
type III_INT is new II_SI range 1 .. 5; — compilation error
- Attributes imported from base type
- Attributes:
- first, last, range, succ, pred, pos, val
- Predefined operators
- +, -, *, /, mod, rem, abs, **, <, >, =
ADA – Basic Types – Enumeration:
— Type declarations
type WEEK_T is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
subtype WORK_WEEK_T is WEEK_T range Mon .. Fri;
— Interesting declaration
type NULL_T is new WEEK_T range Sun .. Sat; — null range
— Variable declarations
I : WEEK_T := Mon;
II : WORK_WEEK_T := Sat; — Constraint error
- Attributes
- succ, pred, first, last, range, pos, val
- Predefined operators
- <, >, =
- Internal representation of literals
- BOOLEAN – Predefined type
type BOOLEAN is (FALSE, TRUE);
- Predefined Operators
- and, not, or, xor
ADA – Control Structures:
if <expression> then
…statements…
[elsif <expression> then]
…statements…
[else]
…statements…
end if;
case VAR is
when <discrete value> =>
…statements…
[when <discrete value> =>]
…statements…
[when others =>]
…statements…
end case;
while <expression> loop
…statements…
[exit [when <expression>]]
end loop;
for <expression> loop
…statements…
[exit [when <expression>]]
end loop;
loop
…statements…
[exit [when <expression>]]
end loop;
<<BAD_PRACTICE>> — A label can be placed anywhere
— in a program’s execution section
goto BAD_PRACTICE — Transfers control to the label
- Cannot transfer control to an ‘if’, ‘case’ or ‘loop’ statement
- Cannot transfer control within these blocks either
- Generally used during auto-generation of code