Figure 2.25. Concrete Syntax for Virtual Table Declaration
|
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.
The Java AST class for virtual table declaration is the VirtualTableDefinition class.
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.