Next: Graph Types and Graph Rewriting
Up: User defined datatypes:
Previous: Another view example
The general syntax of a view definition resembles that of a
datatype definition:
Datatype_Spec
| ::= | Datatype_View_Spec |
Datatype_View_Spec
| ::= | Id :: view = |
| | match ( Exp ) |
| | View_Cons_Specs |
View_Cons_Specs
| ::= | view Exp => Cons_Spec - ¼ - view Exp => Cons_Spec |
|
Default arguments in a Cons_Spec are interpreted as view accessors.
There are a few general rules to observe when defining a view:
- A datatype view definition only defines the interface
to an external data structure and no code is generated. In particular,
the defined view name is not an actual C++ type.
Thus the user is responsible for defining all appropriate type definitions.
- All other qualifiers other than view are ignored. Thus
automatic generation of pretty printers, garbage collection interface
routines, etc. are disabled for views.
- In general, the view accessors must be usable as lvalues
if the user wants to modify a view datatype. This includes the
situation when in-place rewriting is used.
- Finally, the user are responsible for generating the
constructor functions. In the two examples given above, the user
should implement the functions INT, ID, etc.
Allen Leung
Mon Apr 7 14:33:55 EDT 1997