Next: Conversions
Up: The C type system
Previous: The C type system
Types
Section 6.1.2.5 of the standard describes all of the C types.
This section introduces the OIL identifiers corresponding to the standard's
names for basic C types, sets of types, and user-defined types.
All of these identifiers begin with TypeIs_.
Identifiers representing the basic types of C continue with one or more C
keywords, all lower case, giving the canonic name of the type in the standard
(e.g. TypeIs_char).
Identifiers representing sets of types and user-defined types continue with a
capitalized name.
That name is the one used by the standard to describe the set of types or
the derivation of the user-defined type wherever possible
(e.g. TypeIs_Integral, TypeIs_Pointer).
Sets of types are specified in this section by OIL SET directives.
SET TypeIs_Signed_Integer=
[TypeIs_signed_char, TypeIs_short, TypeIs_int, TypeIs_long];
SET TypeIs_Unsigned_Integer=
[TypeIs_unsigned_char, TypeIs_unsigned_short, TypeIs_unsigned_int,
TypeIs_unsigned_long];
SET TypeIs_Floating=
[TypeIs_float, TypeIs_double, TypeIs_long_double];
This macro is defined in definitions 5, 10, 11, 12, and 15.
This macro is invoked in definition 4.
Each standard type has an associated pointer type, which may or may not be
declared by the programmer.
The pointer types must be defined, however, in order to be available as the
result of an & operator applied to a standard type:
Create standard pointer types[6]
:
SYMBOL Source COMPUTE
SYNT.GotType=BasicPointerTypes();
SYNT.GotOper=BasicPointerRefs() <- THIS.GotAllTypes;
END;
This macro is invoked in definition 1.
void BasicPointerTypes(void)[7]
:
{ int i;
for (i = 0; i < COUNT; i++) {
Pointer[i] = NewType();
ResetTypeName(Pointer[i], Name[i]);
AddTypeToBlock(
Pointer[i],
PointerTypes,
SingleDefTableKeyList(Type[i]));
}
}
This macro is invoked in definition 55.
void BasicPointerRefs(void)[8]
:
{ int i;
for (i = 0; Type[i] != NoKey; i++) {
InstClass1(TypeIs_Pointer,FinalType(Pointer[i]),Type[i]);
}
}
This macro is invoked in definition 55.
Two arrays of the same length are common to the two routines:
#define COUNT 12
static DefTableKey Pointer[COUNT], Type[] = {
TypeIs_signed_char,
TypeIs_short,
TypeIs_int,
TypeIs_long,
TypeIs_unsigned_char,
TypeIs_unsigned_short,
TypeIs_unsigned_int,
TypeIs_unsigned_long ,
TypeIs_float,
TypeIs_double,
TypeIs_long_double };
static char *Name[] = {
"signed_char*",
"short*",
"int*",
"long*",
"unsigned_char*",
"unsigned_short*",
"unsigned_int*",
"unsigned_long*",
"float*",
"double*",
"long_double*" };
This macro is invoked in definition 55.
Section 6.1.2.5 of the standard provides constructors enabling a user to define
additional types, called derived types.
It gives a short description of each constructor, explaining the relationship
(if any) between the type derived and other types.
Each of these constructors is specified in this section by an OIL CLASS.
An Oil CLASS is a parameterized template for construction of a new type
and all of the related operators.
The standard gives no information about the operators related to a type in
Section 6.1.2.5.
This specification follows the standard, using brief descriptions of the
operators here and actually defining them in other sections.
For each kind of operator, the description can be found via the cross
reference on the brief description.
CLASS TypeIs_Enum() BEGIN
COERCION
(TypeIs_Enum): TypeIs_int;
OPER
Enum_Assign_Op(TypeIs_Enum, TypeIs_int): TypeIs_Enum;
END;
CLASS TypeIs_Array(elementType, pointerType) BEGIN
COERCION
(TypeIs_Array): pointerType;
(TypeIs_Array): TypeIs_void;
OPER
Array_Subscript_Op(TypeIs_Array, TypeIs_unsigned_long): elementType;
END;
CLASS TypeIs_Struct() BEGIN
COERCION
(TypeIs_Struct): TypeIs_void;
OPER
Struct_Assign_Op(TypeIs_Struct, TypeIs_Struct): TypeIs_Struct;
END;
CLASS TypeIs_Union() BEGIN
COERCION
(TypeIs_Union): TypeIs_void;
OPER
Union_Assign_Op(TypeIs_Union, TypeIs_Union): TypeIs_Union;
END;
CLASS TypeIs_Function(fnptrType) BEGIN
COERCION
(TypeIs_Function): fnptrType;
(TypeIs_Function): TypeIs_void;
END;
CLASS TypeIs_Pointer(referencedType) BEGIN
COERCION
(TypeIs_Pointer): TypeIs_void;
(TypeIs_Pointer): TypeIs_VoidPointer;
(TypeIs_NULL): TypeIs_Pointer;
OPER
Subscript_Op(TypeIs_Pointer, TypeIs_unsigned_long): referencedType;
Ptr_Inc_Op, Ptr_Dec_Op(TypeIs_Pointer): TypeIs_Pointer;
Ptr_Deref_Op(TypeIs_Pointer): referencedType;
Ptr_Ref_Op (referencedType): TypeIs_Pointer;
Cast_IntegraltoPtr(TypeIs_unsigned_long): TypeIs_Pointer;
Cast_VoidPtrtoPtr (TypeIs_VoidPointer): TypeIs_Pointer;
Ptr_Add_Op, Ptr_Sub_Op(TypeIs_Pointer, TypeIs_unsigned_long): TypeIs_Pointer;
Ptr_Rev_Add_Op (TypeIs_unsigned_long, TypeIs_Pointer): TypeIs_Pointer;
Ptr_Ptr_Sub_Op (TypeIs_Pointer, TypeIs_Pointer): TypeIs_unsigned_long;
Ptr_LT_Op, Ptr_GT_Op, Ptr_LTE_Op,
Ptr_GTE_Op(TypeIs_Pointer, TypeIs_Pointer): TypeIs_int;
Ptr_Eq_Op, Ptr_NEq_Op(TypeIs_Pointer, TypeIs_Pointer): TypeIs_int;
Ptr_Cond_Op(TypeIs_Scalar,TypeIs_Pointer,TypeIs_Pointer): TypeIs_Pointer;
Ptr_Assign_Op (TypeIs_Pointer, TypeIs_Pointer): TypeIs_Pointer;
Ptr_Void_Assign_Op(TypeIs_Pointer, TypeIs_VoidPointer): TypeIs_Pointer;
Ptr_Plus_Eq_Op (TypeIs_Pointer, TypeIs_unsigned_long): TypeIs_Pointer;
Ptr_Minus_Eq_Op(TypeIs_Pointer, TypeIs_unsigned_long): TypeIs_Pointer;
END;
This macro is defined in definitions 5, 10, 11, 12, and 15.
This macro is invoked in definition 4.
Section 6.1.2.5 of the standard says that char, the signed and unsigned
integer types, and the enumerated types are called integral types.
Integral and floating types are collectively called arithmetic types.
Arithmetic and pointer types are collectively called scalar types.
Unfortunately, an OIL set is a static object and therefore cannot contain a
class as a member.
SET TypeIs_Integral =
[TypeIs_char] + TypeIs_Signed_Integer + TypeIs_Unsigned_Integer;
SET TypeIs_Arithmetic = TypeIs_Integral + TypeIs_Floating;
SET TypeIs_Scalar = TypeIs_Arithmetic + [TypeIs_VoidPointer];
This macro is defined in definitions 5, 10, 11, 12, and 15.
This macro is invoked in definition 4.
Section 6.1.4 of the standard describes string literals.
The semantics of a string literal are exactly those of a pointer to a
character sequence that is terminated by a zero byte:
COERCION
(TypeIs_string): TypeIs_void;
(TypeIs_string): TypeIs_VoidPointer;
OPER
IndexString(TypeIs_string, TypeIs_unsigned_long): TypeIs_char;
DerefString(TypeIs_string): TypeIs_char;
This macro is defined in definitions 5, 10, 11, 12, and 15.
This macro is invoked in definition 4.
Next: Conversions
Up: The C type system
Previous: The C type system
2008-08-30