The discussion of the type system to this point has described the type system used for design vocabulary elements. Properties of these design elements can also be typed. The type system used for element properties uses a syntax and semantics similar to the design element type system’s, but the constraints that can be imposed on properties are much simpler than those that can be imposed on design elements.
A property of a design element is simply a scoped name with which a value and a type can be associated. The purpose of a property type is to define the range and structure of values that can be applied to the named property.
A property type can be either an atomic type, an enumerated type, a compound type (set, sequence or record), or a type renaming.
Atomic property types. An atomic property type is one of Acme’s basic built in type primitives – int, float, boolean, or string. Atomic types do not need to be defined by the user, as they are built into the Acme language. An example of two properties declared to have atomic types follows:
Property rate : float = 7.5;
Property purpose-description : string = “This component...”;
The declaration of a type can, but does not need to, be separated from the use of that type in specific properties. Explicitly named types are declared with the following (informal) syntax:
Property Type <TypeName> = <TypeStructure>;
where <TypeName> is an identifier to be associated with <TypeStructure>. <TypeStructure> can define an enumerated type, a compound type, or rename a previously defined type. Semantically, <TypeStructure> specifies a predicate that defines the set of valid values for the type and in doing so defines the structure that values of the type must posses. A more detailed discussion of the semantics of property types is included at the end of this section.
Instances of properties are declared using the following syntax.
Property <PropertyName> : <TypeName> = <PropertyValue>;
The property named <PropertyName> is associated with the element in which it is declared. The type of <PropertyName> is explicitly specified using the “: <Typename>” notation.
Enumerated property types. An enumerated type defines a set of valid values that a property of that type may hold. The following example defines a type “color” that can have any of the values white, red, blue, green, or black.
Property Type color = enum {white, red, blue, green, black};
A compound property type is a type that provides a property with structure to store multiple values. Compound types are either sets, sequences, or records of other types. Compound typed properties may either use named compound types or explicitly create a new type in the type signature of the property. Alternatively, if a property does not declare a type but uses the syntax for specifying the value as a record, set, or sequence, then Acme will use simple type inferencing to store the value appropriately.
Examples of compound type declarations and usage follow:
Records. A record type contains multiple typed fields that store distinct but related values. Values of the fields of a record property can be referenced by the name of the field.
The syntax for record type declarations is:
Property Type <TypeName> = Record “[” <FieldDefs>* “]”;
where <FieldDefs> is a sequence of (name, type) pairs. Examples of record type declarations and the use of record types in property declarations follow:
Property Type visualization = Record [ x,y : int; fill-color : color];
Property point : Record [x,y : int] = [x = 4; y = 10];
Property vis : visualization = [x = 10; y = 20; fill-color = blue];
Sequences. A sequence type is an ordered list of elements, separated by commas. A sequence instance may have repeated values. The items stored in a sequence must be of a single homogeneous type. The following syntax is used for specifying a type that stores a sequence of <TypeName>'s :
Property Type <TypeName> = Sequence < <TypeName> > ;
Examples of sequence property type and sequence property instance declarations follow:
Property Type string-list = Sequence<string>;
Property Type vis-list = Sequence <visualization>;
Property int-seq : Sequence<int> = <1, 2, 3, 4, 2, 3, 4>;
Property string-seq : string-list = <"one", "two", "three", "one">;
Property comp-vis :
vis-list = < [x = 10; y = 20; fill-color = black ],
[x = 50; y = 300; fill-color =
white ] >;
Sets. A set type defines an unordered set of elements, separated by commas, with no duplicate values. Like a sequence type, a set type must be homogeneous. That is, all of its elements must be of a specific type. The following syntax is used for specifying a set type:
Property Type <TypeName> = Set { <TypeName> } ;
The following examples illustrate the declaration of set property types and their use:
Property Type int-set = Set{int};
Property Type color-set = Set {color};
Property set-of-floats : Set{float} = {1.2, 3.4, 5.6, 7.8, 9.0};
Property set-of-ints : int-set = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
Property set-of-colors : color-set = {blue, red, green, white};
Type renaming. A renamed property type allows users to separate the logical meaning of a type from its underlying storage structure. A renamed type is comparable to a “typedef” in the C language. For example, both a URL and a Java method declaration can be specified as properties of a component using a string. The semantics that tools should use to interpret the content of those two strings, however, are significantly different. The following example shows how these types could be renamed to be more descriptive:
Property Type java-method = string;
Property Type url = string;
Property some-java-method : java-method = “foo(x,y:int){...}”;
Property some-url : url = “http://www.codeland.com”;