2.15. Virtual Table Declaration

Figure 2.25. Concrete Syntax for Virtual Table Declaration

[109] <virtual-table> ::= "virtual" <vtable-id> <vtable-on-enum>? "{" <vtable-entry>+ "}"  
[110] <vtable-on-enum> ::= "on" <enum-id>  
[111] <vtable-entry> ::= <record-or-enum-id> "->" <function-id>  

Figure 2.25, “Concrete Syntax for Virtual Table Declaration” presents the concrete syntax for virtual table definitions. BIR virtual tables are used to model dynamic dispatch of methods in OOP language or type-safe function pointers. There are two kinds of virtual tables: (1) records-based and (2) enumeration-based.

Namespace. The namespace for virtual tables is the global namespace that is shared with constants, enumerations, records, extensions, type-aliases, threads and functions, and functional expressions.

Abstract Syntax Tree. 

Figure 2.26. Java AST for Virtual Table Declaration

Java AST for Virtual Table Declaration
[ .gif, .svg ]

The Java AST class for virtual table declaration is the VirtualTableDefinition class.

2.15.1. Record-based

A records-based virtual table maps the records in the virtual table to the functions that handle the call. The first parameter of a function that is mapped to handle a record type should accept the record type or one of its super-records. The non-first parameter types of all functions in the virtual table should match (equivalent). Furthermore, the records that are handled by a virtual table should be closed under the sub-records relation. That is, if a record r is mapped in a virtual table, then all sub-records of r should also be mapped.

2.15.2. Enumeration-based

An enumeration-based virtual table is similar to the records-based, except that an enumeration type is used instead of record types. The virtual table should map all elements (values) of the specified enumeration type.