Next: , Previous: , Up: lib-structs   [Contents][Index]


10.39.8 Examining Type Definitions at Runtime

The above described procedures should be sufficient for most needs. This module does, however, provide a few procedures to allow programmers to access type definitions. These may be a convenience for debugging, or in writing tools to manipulate type definitions.

The following procedures allow programmers to find the definition of a given type:

type_definition(?Type, ?Definition)
type_definition(?Type, ?Definition, ?Size)

where Type is an atom naming a type, Definition is the definition of that type, and Size is the number of bytes occupied by a foreign term of this type. Size will be the atom unknown if the size of an object of that type is not known. Such types may not be used as fields in structs or unions, or in arrays. However, pointers to them may be created. If Type is not bound at call time, then these procedures will backtrack through all current type definitions.

A definition looks much like the definition given when the type was defined with type/1, except that it has been simplified. Firstly, intermediate type names have been elided. For example, if foo is defined as foo=integer, and bar as bar=foo, then type_definition(bar, integer) would hold. Also, in the definition of a compound type, types of parts are always defined by type names, rather than complex specifications. So if the type of a field in a struct was defined as pointer(fred), then it will show up in the definition as '$fred'. Of course, type_definition('$fred', pointer(fred)) would hold, also.

The following predicates allow the programmer to determine whether or not a given type is atomic:

atomic_type(?Type)

atomic_type(?Type, ?Primitive_type)

atomic_type(?Type, ?Primitive_type, ?Size)

where Type is an atomic type. See str-fty for the definition of an atomic type. Primitive_type is the primitive type that Type is defined in terms of. Size is the number of bytes occupied by an object of type Type, or the atom unknown, as above. If Type is unbound at call time, then these predicates will backtrack through all the currently defined atomic types.



Send feedback on this subject.