• No results found

5.2 Type level transformations

5.2.5 User-defined data types

Within this section, the transformation of an user-defined data type will be defined. A user-defined data type in Ecore is a custom data type, of which a serialisation can be stored in the form of a string. The Ecore type model for introducing a user-defined data type is simple:

Definition 5.2.48 (Type modelT mU serT ype)

LetT mU serT ype be the type model containing a user-defined data type with identifier name. T mU serT ype is defined as:

Class={}

Enum={}

U serDataT ype={name}

F ield={} FieldSig ={} EnumV alue={} Inh={} P rop={} Constant={} ConstType ={}

Also see tmod_userdatatypein Ecore-GROOVE-Mapping-Library.UserDataTypeType

Theorem 5.2.49 (Correctness ofT mU serT ype)

Also see tmod_userdatatype_correctin Ecore-GROOVE-Mapping-Library.UserDataTypeType

A visual representation ofT mU serT ypewith identifier.Examplecan be seen in Figure 5.5a. The correctness

proof ofT mU serT ype 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 mU serT ype should be compatible with

the type model it is combined with.

Theorem 5.2.50 (Correctness ofcombine(T m, T mU serT ype))

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

• The identifier of the user-defined data type in T mU serT ype is not yet an identifier for a class, enumeration type or user-defined data type inT m;

• The identifier of the user-defined data type in T mU serT ype is not in the namespace of any class, enumeration 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 class in T mU serT ype.

Also see tmod_userdatatype_combine_correctin

Ecore-GROOVE-Mapping-Library.UserDataTypeType

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

combine(T m, T mU serT ype)is consistent in the sense of Definition 3.2.11.

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

Encoding as node type

A possible encoding for user-defined data types in Ecore is using a node type in GROOVE. This node type will get a transformed identifier as name. In order to be able to store the serialised value, an edge type is created to a string node that represents the serialised value. The encoding corresponding to

T mU serT ype can then be represented asT GU serT ype, defined in the following definition: Definition 5.2.51 (Type graphT GU serT ype)

Let T GU serT ype be the type graph containing a single node type which encodes a user-defined data type name. Furthermore, this node type has an edge type named data_edge to a string primitive to store its serialised value. T GU serT ype is defined as:

N T ={ns_to_list(name)}

ET ={(ns_to_list(name),⟨data_edge⟩,string)}

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

abs={}

mult(e) = {︂(0..∗,1..1) if e∈ETT GU serT ype contains={}

Also see tg_userdatatype_as_node_typein Ecore-GROOVE-Mapping-Library.UserDataTypeType

Theorem 5.2.52 (Correctness ofT GU serT ype)

T GU serT ype (Definition 5.2.51) is a valid type graph in the sense of Definition 3.3.5.

Also see tg_userdatatype_as_node_type_correct in

Ecore-GROOVE-Mapping-Library.UserDataTypeType

A visual representation of T GU serT ype with identifier .Example can be seen in Figure 5.5b. In this

example,valuewas chosen as edge name. The correctness proof ofT GU serT ype 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 GU serT ype should be compatible with

Theorem 5.2.53 (Correctness ofcombine(T G, T GU serT ype))

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

• The node type of the encoded class in T GU serT ype is not a node type inT G.

Also see tg_userdatatype_as_node_type_combine_correct in

Ecore-GROOVE-Mapping-Library.UserDataTypeType

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

combine(T G, T GU serT ype)is valid in the sense of Definition 3.3.5.

The next definitions define the transformation function fromT mU serT ype toT GU serT ype: Definition 5.2.54 (Transformation functionfU serT ype)

The transformation functionfU serT ype(T m) is defined as:

N T ={ns_to_list(u)|u∈U serDataT ypeT m} ∪ {string}

ET ={(ns_to_list(u),⟨data_edge⟩,string)|u∈U serDataT ypeT m}

⊑={(ns_to_list(u1),ns_to_list(u2))|u1∈U serDataT ypeT m∧u2∈U serDataT ypeT m} ∪

{(string,string)}

abs={}

mult(e) = {︂(0..∗,1..1) if e∈ {(ns_to_list(u),⟨data_edge⟩,string)|u∈U serDataT ypeT m} contains={}

Also see tmod_userdatatype_to_tg_userdatatype_as_node_type in

Ecore-GROOVE-Mapping-Library.UserDataTypeType

Theorem 5.2.55 (Correctness offU serT ype)

fU serT ype(T m) (Definition 5.2.54) is a valid transformation function in the sense of Definition 4.3.25 transforming T mU serT ype intoT GU serT ype.

Also see tmod_userdatatype_to_tg_userdatatype_as_node_type_funcin

Ecore-GROOVE-Mapping-Library.UserDataTypeType

The proof of the correctness of fU serT ype will not be included here. Instead, it can be found in the

validated Isabelle theories.

Finally, to complete the transformation, the transformation function that transforms T GU serT ype into T mU serT ype is defined:

Definition 5.2.56 (Transformation functionfU serT ype′ )

The transformation functionfU serT ype′ (T G)is defined as:

Class={}

Enum={}

U serDataT ype={list_to_ns(n)|n∈N TT G∩Labt} F ield={} FieldSig ={} EnumV alue={} Inh={} P rop={} Constant={} ConstType ={}

Also see tg_userdatatype_as_node_type_to_tmod_userdatatype in

Ecore-GROOVE-Mapping-Library.UserDataTypeType

Theorem 5.2.57 (Correctness offU serT ype′ )

fU serT ype′ (T G) (Definition 5.2.56) is a valid transformation function in the sense of Definition 4.3.30 transforming T GU serT ype intoT mU serT ype.

Example field : EString

(a)T mDataF ieldfor astringwithname=field

Example

field:string

(b)T GDataF ieldfor astringwithname=field

Figure 5.6: Visualisation of the transformation of a field typed by a data type

Also see tg_userdatatype_as_node_type_to_tmod_userdatatype_funcin

Ecore-GROOVE-Mapping-Library.UserDataTypeType

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