• No results found

Plain objects typed by a subclass

5.3 Instance level transformations

5.3.3 Plain objects typed by a subclass

In this section, the transformation of plain objects typed by a regular subclass is discussed. The corre- sponding type level transformation can be found in Section 5.2.3. This transformation is very similar to the the transformation of plain objects discussed in Section 5.3.1. Like that transformation, it is possible to introduce an arbitrary amount of instances of the subclass introduced on the type level. First, the definition of the corresponding instance model is given.

Definition 5.3.21 (Instance modelImSubclass)

Let ImSubclass be the instance model containing a set of objects objects which are all typed by subclass name, which extends classsupertype. Furthermore, an injective functionf idis defined which maps every object in the set to its corresponding identifier. ImSubclass is typed by T mSubclass (Definition 5.2.21) and is defined as:

Object=objects

ObjectClass = {︂(ob, name) if ob∈objects

ObjectId = {︂(ob, f id(ob)) if ob∈objects

FieldValue ={}

DefaultValue ={}

Also see imod_subclassin Ecore-GROOVE-Mapping-Library.SubclassInstance

Theorem 5.3.22 (Correctness ofImSubclass)

ImSubclass (Definition 5.3.21) is a valid instance model in the sense of Definition 3.2.19.

Also see imod_subclass_correctin Ecore-GROOVE-Mapping-Library.SubclassInstance

A visual representation ofImSubclass withobjects={ob} andf id(ob) =xcan be seen in Figure 5.11a.

Although this visualisation only shows one object, it is possible to have an arbitrary amount of objects in ImSubclass, as long as they are all typed by the corresponding class introduced on the type level. In

the visualisation, the identifier .NewTypeis used for the class, in correspondence with Figure 5.3a The correctness proof of ImSubclass 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, ImSubclass should be compatible with

the instance model it is combined with.

Theorem 5.3.23 (Correctness ofcombine(Im, ImSubclass))

Assume an instance model Im that is valid in the sense of Definition 3.2.19. Then Im is compatible withImSubclass (in the sense of Definition 4.4.14) if:

• All requirements of Theorem 5.2.23 are met, to ensure the combination of the corresponding type models is valid;

• All the objects inImSubclass have an (internal and explicit) identity that is not yet used inIm;

• Im is not typed by a type model that defines any fields for thesupertype class.

Also see imod_subclass_combine_correct in

Ecore-GROOVE-Mapping-Library.SubclassInstance

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

combine(Im, ImSubclass)is consistent in the sense of Definition 3.2.19.

Please note that in this case, it has been made explicit that the new objects introduced do not have any fields defined. This is by ensuring the supertype does not define any fields. The new subclass does not have fields itself, as it cannot have existed in the combined type model.

The definitions and theorems for introducing plain objects of regular subclasses within Ecore are now complete.

Encoding as nodes

As was the case with plain objects of regular classes, a possible encoding for plain objects of subclasses in Ecore is using nodes in GROOVE. Each node is typed by the node type that was introduced inT GSubclass,

and copies the identifiers set of the objects to the corresponding nodes. The encoding corresponding to

ImSubclass can then be represented asIGSubclass, defined in the following definition: Definition 5.3.24 (Instance graphIGSubclass)

LetIGSubclassbe the instance graph with as nodes the convertedobjectsofImSubclass(Definition 5.3.21). Furthermore, reuse the injective function f id that maps every object to its identifier. Finally, use the

node type name introduced in T GSubclass, that extends the supertype node type. (Definition 5.2.4). IGSubclass is defined typed byT GSubclass and is defined as:

N=objects E={} ident = {︂(f id(ob), ob) if ob∈objects with typen= {︂

(ob,ns_to_list(name)) if ob∈objects

Also see ig_subclass_as_node_typein Ecore-GROOVE-Mapping-Library.SubclassInstance

Theorem 5.3.25 (Correctness ofIGSubclass)

IGSubclass (Definition 5.3.24) is a valid instance graph in the sense of Definition 3.3.10.

Also see ig_subclass_as_node_type_correctin

Ecore-GROOVE-Mapping-Library.SubclassInstance

A visual representation ofIGSubclass withobjects={ob} andf id(ob) =xcan be seen in Figure 5.11b.

Like the previous example for the Ecore instance model, only one node is shown here, but multiple nodes can be introduced at once if there are more objects in the objects set. As shown in the definition, the node type identified byNewTypeis used to type all the nodes, in correspondence with Figure 5.3b. The correctness proof of IGSubclass 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,IGSubclassshould be compatible with the

instance graph it is combined with.

Theorem 5.3.26 (Correctness ofcombine(IG, IGSubclass))

Assume an instance graphIG that is valid in the sense of Definition 3.3.10. ThenIG is compatible with IGSubclass (in the sense of Definition 4.4.25) if:

• All requirements of Theorem 5.2.26 are met, to ensure the combination of the corresponding type graphs is valid;

• All the nodes in IGSubclass have an (internal and explicit) identity that is not yet used inIG;

• There are no edge types from or to thesupertype node type, this includes edges from and to types that supertypeinherits from.

Also see ig_subclass_as_node_type_combine_correctin

Ecore-GROOVE-Mapping-Library.SubclassInstance

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

combine(IG, IGSubclass)is valid in the sense of Definition 3.3.10.

Like the correctness for the Ecore instance model, validity is guaranteed here by assuming there exist no edge types from and to thesupertypenode type.

The next definitions define the transformation function fromImSubclass toIGSubclass: Definition 5.3.27 (Transformation functionfSubclass)

The transformation functionfSubclass(Im)is defined as:

N =ObjectIm E={} ident = {︂(f id(ob), ob) if ob∈ObjectIm with typen= {︂

(ob,ns_to_list(name)) if ob∈ObjectIm

Also see imod_subclass_to_ig_subclass_as_node_typein

ExampleOptionA:Example$OPTION_A

ExampleOptionB:Example$OPTION_B

ExampleOptionC :Example$OPTION_C

(a)IGEnumN odes corresponding toT GEnumN odes

ExampleOptionA:Example OPTION_A ExampleOptionB:Example OPTION_B ExampleOptionC :Example OPTION_C

(b)IGEnumF lags corresponding toT GEnumF lags

Figure 5.12: Visualisation of the transformation of enumeration values corresponding to an enumeration type

Theorem 5.3.28 (Correctness offSubclass)

fSubclass(Im) (Definition 5.3.27) is a valid transformation function in the sense of Definition 4.4.26 transforming ImSubclass intoIGSubclass.

Also see imod_subclass_to_ig_subclass_as_node_type_funcin

Ecore-GROOVE-Mapping-Library.SubclassInstance

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

validated Isabelle theories. The proof is quite trivial, as extendingImcan only add extra objects, but not remove the existing ones.

Finally, to complete the transformation, the transformation function that transforms IGSubclass into ImSubclass is defined:

Definition 5.3.29 (Transformation functionfSubclass′ )

The transformation functionfSubclass′ (IG)is defined as:

Object=NIG

ObjectClass = {︂(ob, name) if ob∈NIG

ObjectId = {︂(ob, f id(ob)) if ob∈NIG

FieldValue = {}

DefaultValue ={}

Also see ig_subclass_as_node_type_to_imod_subclassin

Ecore-GROOVE-Mapping-Library.SubclassInstance

Theorem 5.3.30 (Correctness offSubclass′ )

f′

Subclass(IG) (Definition 5.3.29) is a valid transformation function in the sense of Definition 4.4.31 transforming IGSubclass intoImSubclass.

Also see ig_subclass_as_node_type_to_imod_subclass_funcin

Ecore-GROOVE-Mapping-Library.SubclassInstance

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