Contents | Prev | Next | Index


Class Types

A class type is a structure consisting of a fixed number of components. The possible components of a class are fields, methods, constructors and destructors. Unlike other types, a class type can be declared only in a type declaration part in the outermost scope of a program or unit. Therefore, a class type can't be declared in a variable declaration part or within a procedure, function, or method block. This compiler always maps class types to Java classes. The components of a class are also known as members. In the following grammar syntax for class types, Java-specific language extensions are shown in red.

class_type        ::= class class_base component_seq END
class             ::= java_modifiers CLASS
                  ::= CLASS
class_base        ::= ( parent interface_list )
                  ::= <empty>
parent            ::= qualident
                  ::= <empty>
interface_list    ::= interface_list , qualident
                  ::= <empty>
component_seq     ::= component_seq visibility component_list
                  ::= component_list
visibility        ::= PUBLISHED
                  ::= PUBLIC
                  ::= PROTECTED
                  ::= PRIVATE
                  ::= AUTOMATED
component_list    ::= field_def_list method_list
                  ::= field_def_list
                  ::= method_list
                  ::= <empty>
field_def_list    ::= field_def_list field_list ;
                  ::= field_list ;
method_list       ::= method_list method_def
                  ::= method_def
method_def        ::= method_heading ; method_directives
method_heading    ::= procedure_heading
                  ::= func_heading
                  ::= class_directive procedure_heading
                  ::= class_directive func_heading
class_directive   ::= CLASS
method_directives ::= virtual param_directive abstract
virtual           ::= VIRTUAL ;
                  ::= DYNAMIC ;
                  ::= OVERRIDE ;
                  ::= <empty>
abstract          ::= ABSTRACT ;
                  ::= <empty>
param_directive   ::= REGISTER ;
                  ::= PASCAL ;
                  ::= CDECL ;
                  ::= STDCALL ;
                  ::= <empty>

A class type can be declared as a forward reference. This is done by specifying the word CLASS and nothing else in the class type declaration. Such a forward declaration must be resolved by a normal declaration of the class within the same type declaration part. Forward declarations allow mutually dependant classes to be declared.

type_decl  ::= type_id = type
           ::= type_id = CLASS

A class type can inherit components from a specified parent class. The class type itself  always is a subclass of that parent class. The parent class is also known as the superclass. The default parent class is java.lang.Object. The latter is also the ultimate parent class of the whole class hierarchy in Canterbury Pascal as well as in Java.

Notice that, unlike Borland Object Pascal, Canterbury Pascal does not implement the property component. Neither does Canterbury Pascal in its current version implement SYSTEM.TObject nor any subclasses thereof.

However, it is possible to access any existing foreign Java class in Canterbury Pascal via a direct import mechanism, and this even without writing interface units for foreign classes. Thus, all the features of existing Java class libraries become available in Canterbury Pascal, too.


Contents | Prev | Next | Index

Canterbury Pascal for JVM  (Last documentation update Sep 02, 2004)
Copyright © 1999-2004 J.Neuhoff - mhccorp.com  . All rights reserved.
Please send any comments or corrections to neuhoff@mhccorp.com