Representation of Types

TypeInfo metaobjects represent types. Because C++ deals with derived types such as pointer types and array types, Class metaobjects are not used for primary representation of types. TypeInfo metaobjects do not treat typedefed types as independent types. They are treated just as aliases of the original types.

Public Members

The followings are member functions on TypeInfo metaobjects:

The TypeInfo metaobjects also provide methods for computing the dereferenced type. For example, those methods are used to get the type of the value that a pointer points to. Suppose that the type of the pointer is int*. If the dereferenced type of that pointer type is computed, then int is obtained.

The dereferenced type of a function type is the type of the return value. For example, if the function type is void f(char), then the dereferenced type is void . If no return type is specified (e.g. constructors), the dereferenced type of the function type is ``no return type.''

The TypeInfo metaobjects also provide a method to obtain the types of function arguments.

Finally, we show a convenient method for constructing a Ptree metaobject that represents the declaration of a variable of the type.

If the type is a function type, MakePtree() returns a function prototype matching that type. The argument names in the prototype is omitted. To construct a function prototype including argument names, programmers need to write as follows. Suppose that ftype is the type of the function, atype is the type of the argument, the function name is Set, and the argument name is width:

Ptree* arg = atype.MakePtree(Ptree::Make("width"));
Ptree* func = Ptree::qMake("Set(`arg`)");
Ptree* proto = ftype.MakePtree(func);    // function prototype

[First | Prev | Next]