next up previous contents index
Next: Graph Types and Graph Rewriting Up: User defined datatypes: Previous: Another view example

Syntax of view definitions

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:

  1. 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.
  2. All other qualifiers other than view are ignored. Thus automatic generation of pretty printers, garbage collection interface routines, etc. are disabled for views.
  3. 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.
  4. 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