2.8. Record Declaration

Figure 2.12. Concrete Syntax for Record Declaration

[61] <record> ::= "top"? "throwable"? "record" <record-id> <super>? "{" <record-field>* "}"  
[62] <super> ::= "extends" <record-id> ("," <record-id>)*  
[63] <record-field> ::= <basic-type> <record-field-id> ";"  

Figure 2.12, “Concrete Syntax for Record Declaration” presents the concrete syntax for record declarations. A record r' can extend another record r (i.e., r!= r'). The record r is called the (direct) super record of r', and r' is called a (direct) sub-record of r. Super record and sub-record relations are transitive relations (e.g, r is a super record of r''s sub-records). The fields of r is implicitly present in r', however, the implicit fields share the namespace of the fields of r'. Furthermore, constructs that can be used for r can also be used with r', but not necessarily the other way around. A record can also extend multiple records.

The "top" modifier is used to indicate that the record is the top record. That is, all other records that do not explicitly extend another record extend the top record. In a BIR model, there can be at most one top record. The "throwable" modifier is used to indicate the record can be thrown as an exception. All sub-records of a throwable record are also throwable.

In BIR, we allow a degree of freedom of how the language is implemented. The language can be implemented in a way that is biased toward a specific domain. For example, when modeling Java, it is convenient to have each record contains an implicit lock. Thus, the lock operations (see lock action) and the lock tests (see lock test expression) can be used directly on records. Another example, it is also convenient to have arrays that can be treated as the top record because arrays are objects in Java (i.e., they can be casted to the Java top object java.lang.Object). Thus, if a top record is specified in a BIR model, then all array types "extend" the top record in a sense that it can be casted to/from. This degree of freedom, however, should be used carefully and it should be documented clearly when used.

Namespace. The namespace for records is the global namespace that is shared with constants, enumerations, extensions, type-aliases, global variables, threads and functions, virtual tables, and functional expressions. Each record type has its own namespace for its fields. Note that fields of a record are implicitly present in its sub-records. This means that the inherited fields will also use the namespace of each sub-record's field namespace.


	top throwable record A { int x; }
	throwable record B { int y; }
	record C extends A, B { int z; }

Abstract Syntax Tree. 

Figure 2.13. Java AST for Record Declaration

Java AST for Record Declaration
[ .gif, .svg ]

The Java AST class for BIR records is the RecordDefinition class. The Java AST class for BIR record field is the TypedId class.