TotalView Reference Guide : Part I: CLI Commands : Creating Type Transformations : Creating Structure and Class Transformations : Type Transformation Expressions
Type Transformation Expressions
The list that defines a member has a name component and sublist within the list. This sublist defines a type transformation expression. This expression tells TotalView what it needs to know to locate the member. The example in the previous section used two of the six possible expressions. The following list describes these expressions:
{member}
No transformation occurs. The structure or class member that TotalView displays is the same as it displays if you hadn’t used a transformation. This is most often used for simple data types such as ints and floats.
{* expr}
Dereferences a pointer. If the data element is a pointer to an element, this expression tells TotalView to dereference the pointer and display the dereferenced information.
{expr . expr}
Names a subelement of a structure. This is used in the same way as the dot operator that exists in C and C++. You must type a space before and after the dot operator.
{expr + offset}
Use the data whose location is an offset away from expr. This behaves just like pointer arithmetic in C and C++. The result is calculated based on the size of the type that expr points to:
result = expr + sizeof(*expr) * offset
{expr -> expr}
Names a subelement in a structure accessed using a pointer. This is used in the same way as the -> operator in C and C++. You must type a space before and after the -> operator.
{datatype cast expr}
Casts a data type. For example:
{double cast national_debt}
{N upcast expr}
Converts the current class type into one of its base classes. For example:
{base_class upcast expr }
You can nest expressions within expressions. For example, here is the list for adding an int member that is defined as int **pfoo:
{foo { * {* pfoo}}
Example
The example in this section changes the structure elements of the example in the previous section so that they are now class members. In addition, this example contains a class that is derived from a second class:
#include <stdio.h>
#include <string.h>
class xbase
{
public:
char * pName;
char * pStreet;
char CityState[30];
};
class x1 : public xbase
{
public:
int month;
int day;
int year;
void *v;
void *q;
};
class x2
{
public:
int q1;
int q2;
};
int main () {
class x1 info;
char my_name[] = “John Smith”;
char my_street[] = “24 Prime Parkway, Suite 106”;
char my_CityState[] = “Natick, MA 01760”;
info.month = 6;
info.day = 20;
info.year = 2004;
info.pName = my_name;
info.pStreet = my_street;
info.v = (void *) my_name;
strcpy(info.CityState, my_CityState);
 
class x2 x;
x.q1 = 100;
x.q2 = 200;
info.q = (void *) &x;
printf(“The year is %d\n”, info.year);
}
Figure 8 shows the Variables Windows that TotalView displays for the info class and the x struct.
 
Figure 8: Untransformed Data
The following transformation remaps this information:
::TV::TTF::RTF::build_struct_transform {
name {^(class|struct) x1$}
members {
{ pmonth { month } }
{ pName { xbase upcast { * pName } } }
{ pStreet { xbase upcast { * pStreet } } }
{ pVoid1 { “$string *” cast v } }
{ pVoid2 { * { “class x2 *” cast q } } }
}
}
After you remap the information, TotalView displays the x1 class.
 
Figure 9: Transformed Class
The members of this transformation are as follows:
*pmonth: The month member is added to the transformed structure without making any changes to the way TotalView displays its data. This member, however, changes the display name of the data element. That is, the name that TotalView uses to display a member within the remapped structure does not have to be the same as it is in the actual structure.
*pName: The pName member is added. The transformation contains two operations. The first dereferences the pointer. In addition, as x1 is derived from xbase, you need to upcast the variable when you want to include it.
Notice that one expression is nested within another.
*pStreet: The pStreet member is added. The operations that are performed are the same as for pName.
*pVoid1: The v member is added. Because the application’s definition of the data is void *, casting tells TotalView how it should interpret the information. In this example, the data is being cast into a pointer to a string.
*pVoid2: The q member is added. The transformation contains two operations. The first casts q into a pointer to the x2 class. The second dereferences the pointer.