SDA SE Wiki

Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools


New type system in AST Version 3.0

Motivation

Up to now we used type terms to represent information about types. This was an easy way for basic types (int, boolean …), references to simple types (String, Object …) and arrays. In JTransformer 3.0 we added support for generics, so there are types which are way more complex:

HashMap<? extends A<ArrayList<String>>, HashMap<Integer, ? super X<A<String>>>>

With type terms we could not represent this type information. Extending the type terms would have resulted in big, nested, unreadable terms, so we decided to represent this information as a subtree.

Type Representation since JT 3.0

Replace type terms with type references

In every PEF where a type term was used, it is replaced with a type reference.

Example 1: Basic Type
java code:
int count;
type terms:
localT(#id, #parent, #enclMethod, type(basic, 'int', 0), 'count', #init).
type references:
localT(#id, #parent, #enclMethod, #typeRef, 'count', #init).
typeRefT(#typeRef, #id, #id, #int).
basicTypeT(#int, 'int').
Example 2: Simple Type
java code:
String name;
type terms:
localT(#id, #parent, #enclMethod, type(class, 10005, 0), 'name', #init).
type references:
localT(#id, #parent, #enclMethod, #arrayRef, 'name', #init).
typeRefT(#typeRef, #id, #id, 10005).
Example 3: Array Type
java code:
Object[] objectArray;
type terms:
localT(#id, #parent, #enclMethod, type(class, 10001, 1), 'objectArray', #init).
type references:
localT(#id, #parent, #enclMethod, #arrayRef, 'objectArray', #init).
arrayTypeT(#arrayRef, #id, #typeRef, 1).
typeRefT(#typeRef, #arrayRef, #id, 10001).
Example 4: Parameterized Type
java code:
ArrayList<Integer> intList;
type terms:
localT(#id, #parent, #enclMethod, type(class, #id_of_array_list, 0), 'intList', #init).

Here we are losing the information for the Integer type parameter :-?

type references:
localT(#id, #parent, #enclMethod, #paramRef, 'intList', #init).
parameterizedTypeT(#paramRef, #id_of_array_list, #typeRef).
typeRefT(#typeRef, #paramRef, #id, #id_of_integer).
Example 5: Nested Parameterized Type
java code:
HashMap<? extends A<ArrayList<String>>, HashMap<Integer, ? super X<A<String>>>> whatAType;
type terms:
localT(#id, #parent, #enclMethod, type(class, #id_of_hash_map, 0), 'intList', #init).

Again … we are losing the type information :-?

type references:
localT(#id,#parent,#enclosing,#type,t,null).
parameterizedTypeT(#type,#id,#ref_to_hashmap,[#wildcard,#nested_type_4]).
  wildCardT(#wildcard,#type,extends,#nested_type_1).
    parameterizedTypeT(#nested_type_1,#wildcard,#ref_to_a,[#nested_type_2]).
      parameterizedTypeT(#nested_type_2,#nested_type_1,#ref_to_array_list,[#nested_type_3]).
        typeRefT(#nested_type_3,#nested_type_2,#enclosing,#ref_to_string).
  parameterizedTypeT(#nested_type_4,#type,#ref_to_hashmap,[#nested_type_5,#another_wildcard]).
    typeRefT(#nested_type_5,#nested_type_4,#enclosing,#ref_to_integer).
    wildCardT(#another_wildcard,#nested_type_4,super,#nested_type_6).
      parameterizedTypeT(#nested_type_6,#another_wildcard,#ref_to_x,[#nested_type_7]).
        parameterizedTypeT(#nested_type_7,#nested_type_6,#ref_to_a,[#nested_type_8]).
          typeRefT(#nested_type_8,#nested_type_7,#enclosing,#ref_to_string).

Transformations with new type system

Transformations with the new type system are not so easy. There are some helper predicates, see: Using the new type system in CTs.

research/jtransformer/api/java/migration/3.0.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2019