• No results found

5.2 Type level transformations

5.2.4 Enumeration types

Example OPTION_A OPTION_B OPTION_C

(a)T mEnumwith name=.Exampleand values={OPTION_A, OPTION_B,OPTION_C} Example

Example$OPTION_A Example$OPTION_B Example$OPTION_C

(b)T GEnumN odes withname=.Exampleand values={OPTION_A,OPTION_B,OPTION_C}

Example

OPTION_A OPTION_B OPTION_C (c)T GEnumF lagswith name=.Exampleand values={OPTION_A, OPTION_B,OPTION_C}

Figure 5.4: Visualisations of the transformations of enumeration types

This section will define the transformation of an enumeration type. Within this transformation, a new enumeration type is introduced, including its possible values. The Ecore type model that introduces such a subclass is defined as follows:

Definition 5.2.31 (Type modelT mEnum)

Let T mEnum be the type model containing a enumeration type with identifier name. The values of this enumeration type are defined as part of sequencevalues. T mEnum is defined as:

Class={}

Enum={name}

U serDataT ype={}

F ield={}

FieldSig ={}

EnumV alue={(name, v)|v∈values}

Inh={}

P rop={}

Constant={}

ConstType ={}

Also see tmod_enumin Ecore-GROOVE-Mapping-Library.EnumType

Theorem 5.2.32 (Correctness ofT mEnum)

T mSubclass (Definition 5.2.31) is a consistent type model in the sense of Definition 3.2.11.

Also see tmod_enum_correctin Ecore-GROOVE-Mapping-Library.EnumType

A visual representation of T mEnum with .Example as identifier for the new enumeration type and OPTION_A, OPTION_B and OPTION_C as its values can be seen in Figure 5.4a. The correctness proof of T mEnum is trivial, and therefore not included here. The proof can be found as part of the

Isabelle validated proofs.

In order to make composing transformation functions possible,T mEnum should be compatible with the

type model it is combined with.

Theorem 5.2.33 (Correctness ofcombine(T m, T mEnum))

Assume a type model T m that is consistent in the sense of Definition 3.2.11. Then T m is compatible withT mEnum (in the sense of Definition 4.3.13) if:

• The identifier of the enumeration type in T mEnumis not yet an identifier for a class, enumeration type or user-defined data type in T m;

• The identifier of the enumeration type in T mEnum is not in the namespace of any class, enumer- ation type or user-defined data type inT m;

• None of the identifiers in any class, enumeration type or user-defined data type in T m is in the namespace of the enumeration type in T mEnum.

Also see tmod_enum_combine_correctin Ecore-GROOVE-Mapping-Library.EnumType

Proof. Use Lemma 4.3.12. It is possible to show that all assumptions hold. Now we have shown that

combine(T m, T mEnum)is consistent in the sense of Definition 3.2.11.

The definitions and theorems for a regular subclass within Ecore are now complete.

Encoding as node type

A possible encoding for enumeration types in Ecore is using node types in GROOVE. In this case, the enumeration type itself is transformed into an abstract node type. Each value of the enumeration type is converted to its own node type, extending the abstract node type. The encoding corresponding to

T mEnum can then be represented asT GEnumN odes, defined in the following definition: Definition 5.2.34 (Type graphT GEnumN odes)

Let T GEnumN odes be a type graph containing multiple node types. The first node type encodes the enu- meration typename. The other node types encode thevaluesof enumeration typename. T GEnumN odes is defined as:

N T ={ns_to_list(name)} ∪ {ns_to_list(name) @⟨v⟩ |v∈values}

ET ={}

⊑={(ns_to_list(name),ns_to_list(name))} ∪

{(ns_to_list(name) @⟨v⟩,ns_to_list(name) @⟨v⟩)|v∈values} ∪ {(ns_to_list(name) @⟨v⟩,ns_to_list(name))|v∈values}

abs={ns_to_list(name)}

mult = {}

contains={}

Also see tg_enum_as_node_typesin Ecore-GROOVE-Mapping-Library.EnumType

Theorem 5.2.35 (Correctness ofT GEnumN odes)

T GEnumN odes (Definition 5.2.34) is a valid type graph in the sense of Definition 3.3.5.

Also see tg_enum_as_node_types_correct in Ecore-GROOVE-Mapping-Library.EnumType

A visual representation ofT GEnumN odes with.Exampleas identifier for the encoded enumeration type

andOPTION_A,OPTION_BandOPTION_Cas its values can be seen in Figure 5.4b. Please note that in this visualisation, the sequences are concatenated using the dollar sign $. The correctness proof of

T GEnumN odes is trivial, and therefore not included here. The proof can be found as part of the Isabelle

validated proofs.

In order to make composing transformation functions possible,T GEnumN odes should be compatible with

the type graph it is combined with.

Theorem 5.2.36 (Correctness ofcombine(T G, T GEnumN odes))

Assume a type graph T G that is valid in the sense of Definition 3.3.5. Then T G is compatible with T GEnumN odes (in the sense of Definition 4.3.24) if:

• There are no shared node types betweenT GEnumN odes andT G.

Also see tg_enum_as_node_types_combine_correct in

Ecore-GROOVE-Mapping-Library.EnumType

Proof. Use Lemma 4.3.23. It is possible to show that all assumptions hold. Now we have shown that

The next definitions define the transformation function fromT mEnum to T GEnumN odes: Definition 5.2.37 (Transformation functionfEnumN odes)

The transformation functionfEnumN odes(T m)is defined as:

N T ={ns_to_list(e)|e∈EnumT m} ∪ {ns_to_list(e) @⟨v⟩ |(e, v)∈EnumV alueT m} ET ={}

⊑={(ns_to_list(e1),ns_to_list(e2))|e1∈EnumT m∧e2∈EnumT m} ∪

{(ns_to_list(i) @⟨j⟩,ns_to_list(i) @⟨j⟩)|(i, j)∈EnumV alueT m} ∪

{(ns_to_list(i) @⟨j⟩,ns_to_list(e))|(i, j)∈EnumV alueT m∧e∈EnumT m} abs={}

mult = {}

contains={}

Also see tmod_enum_to_tg_enum_as_node_typesin Ecore-GROOVE-Mapping-Library.EnumType

Theorem 5.2.38 (Correctness offEnumN odes)

fEnumN odes(T m)(Definition 5.2.37) is a valid transformation function in the sense of Definition 4.3.25 transforming T mEnum intoT GEnumN odes.

Also see tmod_enum_to_tg_enum_as_node_types_funcin

Ecore-GROOVE-Mapping-Library.EnumType

The proof of the correctness of fEnumN odes will not be included here. Instead, it can be found in the

validated Isabelle theories.

Finally, to complete the transformation, the transformation function that transformsT GEnumN odes into T mEnum is defined:

Definition 5.2.39 (Transformation functionfEnumN odes′ )

The transformation functionfEnumN odes′ (T G, name)is defined as:

Class={}

Enum={list_to_ns(n)|n∈N TT G∧n= id_to_name(name)} U serDataT ype={}

F ield={}

FieldSig ={}

EnumV alue={(list_to_ns(e), v)|e@⟨v⟩ ∈N TT G∧e@⟨v⟩ ̸= id_to_name(name)} Inh={}

P rop={}

Constant={}

ConstType ={}

Also see tg_enum_as_node_types_to_tmod_enumin Ecore-GROOVE-Mapping-Library.EnumType

Theorem 5.2.40 (Correctness offEnumN odes′ )

fEnumN odes′ (T G, name) (Definition 5.2.39) is a valid transformation function in the sense of Defini- tion 4.3.30 transforming T GEnumN odes intoT mEnum.

Also see tg_enum_as_node_types_to_tmod_enum_funcin

Ecore-GROOVE-Mapping-Library.EnumType

Once more, the correctness proof is not included here but can be found in the validated Isabelle proofs of this thesis.

Encoding as flags

Another possible encoding for enumeration types in Ecore is using flags in GROOVE. In this case, the enumeration type itself is transformed into a regular node type. Each value of the enumeration type is converted to a flag on this node type. The encoding corresponding toT mEnum can then be represented

Definition 5.2.41 (Type graphT GEnumF lags)

Let T GEnumF lags be a type graph containing a single node type which encodes the enumeration type name. The flags on the node type ofnameencode the differentvalues. T GEnumF lags is defined as:

N T ={ns_to_list(name)}

ET ={(ns_to_list(name),⟨v⟩,ns_to_list(name))|v∈values} ⊑={(ns_to_list(name),ns_to_list(name))}

abs={}

mult(e) = {︂(0..1,0..1) if e∈ETT GEnumF lags contains={}

Also see tg_enum_as_flagsin Ecore-GROOVE-Mapping-Library.EnumType

Theorem 5.2.42 (Correctness ofT GEnumF lags)

T GEnumF lags(Definition 5.2.41) is a valid type graph in the sense of Definition 3.3.5.

Also see tg_enum_as_flags_correctin Ecore-GROOVE-Mapping-Library.EnumType

A visual representation of T GEnumF lags with .Example as identifier for the encoded enumeration type

andOPTION_A,OPTION_BandOPTION_Cas its values can be seen in Figure 5.4c. The correctness proof ofT GEnumF lags is trivial, and therefore not included here. The proof can be found as part of the

Isabelle validated proofs.

In order to make composing transformation functions possible,T GEnumF lagsshould be compatible with

the type graph it is combined with.

Theorem 5.2.43 (Correctness ofcombine(T G, T GEnumF lags))

Assume a type graph T G that is valid in the sense of Definition 3.3.5. Then T G is compatible with T GEnumF lags(in the sense of Definition 4.3.24) if:

• There are no shared node types betweenT GEnumF lags andT G.

Also see tg_enum_as_flags_combine_correctin Ecore-GROOVE-Mapping-Library.EnumType

Proof. Use Lemma 4.3.23. It is possible to show that all assumptions hold. Now we have shown that

combine(T G, T GEnumF lags)is valid in the sense of Definition 3.3.5.

The next definitions define the transformation function fromT mEnum to T GEnumF lags: Definition 5.2.44 (Transformation functionfEnumF lags)

The transformation functionfEnumF lags(T m)is defined as:

N T ={ns_to_list(e)|e∈EnumT m}

ET ={(ns_to_list(e), v,ns_to_list(e))|(e, v)∈EnumV alueT m}

⊑={(ns_to_list(e1),ns_to_list(e2))|e1∈EnumT m∧e2∈EnumT m} abs={}

mult(e) = {︂(0..1,0..1) if e∈ {(ns_to_list(n), v,ns_to_list(n))|(n, v)∈EnumV alueT m} contains={}

Also see tmod_enum_to_tg_enum_as_flags in Ecore-GROOVE-Mapping-Library.EnumType

Theorem 5.2.45 (Correctness offEnumF lags)

fEnumF lags(T m)(Definition 5.2.44) is a valid transformation function in the sense of Definition 4.3.25 transforming T mEnum intoT GEnumF lags.

Also see tmod_enum_to_tg_enum_as_flags_funcin Ecore-GROOVE-Mapping-Library.EnumType

The proof of the correctness of fEnumF lags will not be included here. Instead, it can be found in the

validated Isabelle theories.

Finally, to complete the transformation, the transformation function that transformsT GEnumF lags into T mEnum is defined:

Example

(a)T mU serT ypewithname=.Example

Example

value:string

(b)T GU serT ypewithname=.Example anddata_edge=value

Figure 5.5: Visualisation of the transformation of user-defined data types

Definition 5.2.46 (Transformation functionf′

EnumF lags) The transformation functionf′

EnumF lags(T G) is defined as:

Class={}

Enum={list_to_ns(n)|n∈N TT G} U serDataT ype={}

F ield={}

FieldSig ={}

EnumV alue={(list_to_ns(e), v)|(e, v, e)∈ETT G} Inh={}

P rop={}

Constant={}

ConstType ={}

Also see tg_enum_as_flags_to_tmod_enum in Ecore-GROOVE-Mapping-Library.EnumType

Theorem 5.2.47 (Correctness offEnumN odes′ )

f′

EnumF lags(T G)(Definition 5.2.46) is a valid transformation function in the sense of Definition 4.3.30 transforming T GEnumF lags intoT mEnum.

Also see tg_enum_as_flags_to_tmod_enum_funcin Ecore-GROOVE-Mapping-Library.EnumType

Once more, the correctness proof is not included here but can be found in the validated Isabelle proofs of this thesis.