![]() |
![]() |
![]() |
General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
![]() |
![]() |
Tutorial on Type AnalysisRecord Types
We now introduce record types to our language in order to
demonstrate how composed program defined types are specified.
A record type is described by a sequence of field declarations
which have the same form as The following concrete productions are added: ScopeProp.con[35]== TypeDenoter: RecordType. RecordType: 'record' ObjDecls 'end'. Variable: Variable '.' SelectIdent. SelectIdent: Ident. This macro is attached to a product file.
Here is an example program that defines and uses a record
variable begin var record int i, bool b, real r end rv; var int j, bool c, real s; j = rv.i; c = rv.b; s = rv.r; end This macro is attached to a product file.
An abstraction of a record type is the sequence of component
definitions. The selection construct needs to identify a definition
within such a sequence. Hence it is suitable to use a scope
for that abstraction. The module ScopeProp.specs[37]== $/Name/AlgScopeProp.gnrc:inst This macro is attached to a product file.
A
In a different language we could have specified that the notation
of one record type is equal or compatible to another notation
of a record type at a different place in the program, e. g.
if they have the same sequence of component (structural equality).
In that case we had to describe the rules for equality or
compatibility in the
The role ScopeProp.lido[38]== RULE: TypeDenoter ::= RecordType COMPUTE TypeDenoter.Type = RecordType.Type; END; SYMBOL RecordType INHERITS TypeDenotation, RangeScopeProp COMPUTE SYNT.ScopeKey = SYNT.Type; SYNT.GotType = ResetTypeName (SYNT.Type, "record..."); END; This macro is attached to a product file.
The last computation above set the
Type analysis for a record component selection is specified in the
following way: The Finally, the type of the whole selection is the type of the bound component: Selection.lido[39]== RULE: Variable ::= Variable '.' SelectIdent COMPUTE SelectIdent.Scope = GetScope (Variable[2].Type, NoEnv) <- INCLUDING Program.GotScopeProp; Variable[1].Type = SelectIdent.Type; IF (EQ (SelectIdent.Scope, NoEnv), message (ERROR, "selection applied to non record type", 0, COORDREF)); END; SYMBOL SelectIdent INHERITS IdUseScopeProp, ChkIdUse, IdentOcc, TypedUseId, ChkTypedUseId, PrtType END; This macro is attached to a product file.
The last symbol computation combines several roles to solve
the record selection analysis task:
A
|