Chapter 3. Types and Classes

Table of Contents
3.1. Type specifiers
3.2. Signatures
3.3. Sather source files
3.4. Abstract classes
3.5. Concrete classes
3.6. Parameterization

Sather programs are textually made up of classes. Classes are used to define the code and storage that make up types. Each object is an instance of a type. Types can be thought of as representing sets of objects at runtime. Objects never change their type.

There are four kinds of objects in Sather: immutable (e.g. integers), reference (e.g. strings), closures, and external (used to represent entities in other languages). There are four corresponding concrete types: immutable, reference, closure, and external types. There are also abstract types, which represent sets of concrete types. Immutable, reference, external, and abstract types are defined textually by immutable, reference, external, and abstract classes. Partial classes define code that does not have corresponding objects or types, and may be included by other classes to obtain implementation.

The type graph for a program is a directed acyclic graph that is constructed from the program's source text. Its nodes are types and its edges represent the subtype relationship. If there is a path in this graph from a type t1 to a type t2, we say that t2 is a subtype of t1 and that t1 is a supertype of t2. Subtyping is reflexive; any type is a subtype of itself. Only abstract types and method closures can be supertypes (see pages See Abstract classes and See Closure creation expressions); closure types can only be supertypes of other closure types.

Every Sather variable has a declared type. The fundamental typing rule is: An object can only be held by a variable if the object's type is a subtype of the variable's type. It is not possible for a program which compiles to violate this rule (i.e. Sather is statically type-safe).

3.1. Type specifiers

Example 3-1. Examples:

type_specifier ==>
        ( uppercase_identifier | abstract_class_name ) [ { type_specifier_list } ] | method_closure_type_specifier | SAME
method_closure_type_specifier ==>
        routine_closure_type_specifier | iter_closure_type_specifier
routine_closure_type_specifier ==>
        ROUT [ {  routine_mode type_specifier { ,  routine_mode type_specifier } } ] [ : type_specifier ]
iter_closure_type_specifier ==>
        ITER [ {  iter_mode type_specifier { ,  iter_mode type_specifier } } ] [ : type_specifier ]

In source text, Sather types are specified by one of the following forms of type specifier: