📄 types.c
字号:
/*
* C compiler
* ==========
*
* Copyright 1989, 1990, 1991 Christoph van Wuellen.
* Credits to Matthew Brandt.
* All commercial rights reserved.
*
* This compiler may be redistributed as long there is no
* commercial interest. The compiler must not be redistributed
* without its full sources. This notice must stay intact.
*
* History:
*
* 1989 starting an 68000 C compiler, starting with material
* originally by M. Brandt
* 1990 68000 C compiler further bug fixes
* started i386 port (December)
* 1991 i386 port finished (January)
* further corrections in the front end and in the 68000
* code generator.
* The next port will be a SPARC port
*/
/*****************************************************************************/
#include "chdr.h"
#include "expr.h"
#include "cglbdec.h"
#include "proto.h"
/********************************************************* Macro Definitions */
#define MAXTYPEKEY ((unsigned) 256) /* hash table size */
/********************************************************** Static Variables */
static TYP *hashtable[MAXTYPEKEY]; /* hash table */
static RANGE range_schar = {
-128L, 127L
};
static RANGE range_short = {
-32768L, 32767L
};
static RANGE range_long = {
-2147483647L - 1L, 2147483647L
};
static RANGE range_bool = {
0L, (IVAL) Ox1UL
};
static RANGE range_uchar = {
0L, (IVAL) OxffUL
};
static RANGE range_ushort = {
0L, (IVAL) OxffffUL
};
static RANGE range_ulong = {
0L, (IVAL) OxffffffffUL
};
#ifdef LONGLONG_BOOTSTRAP
static RANGE range_ulonglong = { 0L, (IVAL) ~0UL
};
static RANGE range_longlong = { -2147483647L - 1L, 2147483647L
};
#else /* */
#ifdef LONGLONG
static RANGE range_ulonglong = { 0L, (IVAL) 0xffffffffffffffffUL
};
static RANGE range_longlong =
{ -9223372036854775807L - 1L, 9223372036854775807L
};
#else /* */
static RANGE range_ulonglong = { 0L, (IVAL) 0xffffffffUL
};
static RANGE range_longlong = { -2147483647L - 1L, 2147483647L
};
#endif /* LONGLONG */
#endif /* LONGLONG_BOOTSTRAP */
/*****************************************************************************/
static FUNC func_params = {
fc_normal,
&init_block,
0 /*lint !e708*/ /* union initialisation */
};
/*****************************************************************************/
static TYP stp_void = {
bt_void,
QUAL_NONE,
STATE_NONE,
UNKNOWN_SIZE,
NIL_TYP,
NIL_TYP,
(const CHAR *) "void",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_bool = {
bt_bool,
QUAL_NONE,
STATE_NONE,
1L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "_Bool",
{
&range_bool} /*lint !e708*/ /* union initialization */
};
static TYP stp_long = {
bt_long,
QUAL_NONE,
STATE_NONE,
4L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "long",
{
&range_long} /*lint !e708*/ /* union initialization */
};
static TYP stp_ulong = {
bt_ulong,
QUAL_NONE,
STATE_NONE,
4L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "unsigned long",
{
&range_ulong} /*lint !e708*/ /* union initialization */
};
static TYP stp_char = {
bt_char,
QUAL_NONE,
STATE_NONE,
1L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "char",
{
&range_schar} /*lint !e708*/ /* union initialization */
};
static TYP stp_uchar = {
bt_uchar,
QUAL_NONE,
STATE_NONE,
1L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "unsigned char",
{
&range_uchar} /*lint !e708*/ /* union initialization */
};
static TYP stp_schar = {
bt_schar,
QUAL_NONE,
STATE_NONE,
1L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "signed char",
{
&range_schar} /*lint !e708*/ /* union initialization */
};
static TYP stp_short = {
bt_short,
QUAL_NONE,
STATE_NONE,
2L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "short",
{
&range_short} /*lint !e708*/ /* union initialization */
};
static TYP stp_ushort = {
bt_ushort,
QUAL_NONE,
STATE_NONE,
2L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "unsigned short",
{
&range_ushort} /*lint !e708*/ /* union initialization */
};
static TYP stp_int = {
bt_int32,
QUAL_NONE,
STATE_NONE,
4L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "int",
{
&range_long} /*lint !e708*/ /* union initialization */
};
static TYP stp_uint = {
bt_uint32,
QUAL_NONE,
STATE_NONE,
4L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "unsigned int",
{
&range_ulong} /*lint !e708*/ /* union initialization */
};
static TYP stp_longlong = {
bt_longlong,
QUAL_NONE,
STATE_NONE,
8L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "long long",
{
&range_longlong} /*lint !e708*/ /* union initialization */
};
static TYP stp_ulonglong = {
bt_ulonglong,
QUAL_NONE,
STATE_NONE,
8L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "unsigned long long",
{
&range_ulonglong} /*lint !e708*/ /* union initialization */
};
#ifdef FLOAT_MFFP
static TYP stp_float = {
bt_float,
QUAL_NONE,
STATE_NONE,
4L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "float",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_double = {
bt_double,
QUAL_NONE,
STATE_NONE,
4L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "double",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_longdouble = {
bt_longdouble,
QUAL_NONE,
STATE_NONE,
4L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "long double",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
#else
static TYP stp_float = {
bt_float,
QUAL_NONE,
STATE_NONE,
4L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "float",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_double = {
bt_double,
QUAL_NONE,
STATE_NONE,
8L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "double",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_longdouble = {
bt_longdouble,
QUAL_NONE,
STATE_NONE,
12L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "long double",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
#endif /* FLOAT_MFFP */
static TYP stp_string = {
bt_pointer32,
QUAL_NONE,
STATE_DERIVED,
4L,
&stp_char,
NIL_TYP,
(const CHAR *) "pointer to char",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_conststring = {
bt_pointer32,
QUAL_CONST,
STATE_DERIVED,
4L,
&stp_char,
NIL_TYP,
(const CHAR *) "const pointer to char",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_func = {
bt_func,
QUAL_NONE,
STATE_DERIVED,
4L,
&stp_int,
NIL_TYP,
(const CHAR *) "function",
{
(RANGE *) &func_params} /*lint !e708*/ /* union initialization */ /*lint !e826*/
};
static TYP stp_struct = {
bt_struct,
QUAL_NONE,
STATE_NONE,
UNKNOWN_SIZE,
NIL_TYP,
NIL_TYP,
(const CHAR *) "struct",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_union = {
bt_union,
QUAL_NONE,
STATE_NONE,
UNKNOWN_SIZE,
NIL_TYP,
NIL_TYP,
(const CHAR *) "union",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_pointer = {
bt_pointer32,
QUAL_NONE,
STATE_NONE,
4L,
&stp_void,
NIL_TYP,
(const CHAR *) "pointer",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_array = {
bt_pointer32,
QUAL_NONE,
STATE_DERIVED,
UNKNOWN_SIZE,
NIL_TYP,
NIL_TYP,
(const CHAR *) "array",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_enum = {
bt_int32,
QUAL_NONE,
STATE_NONE,
UNKNOWN_SIZE,
NIL_TYP,
NIL_TYP,
(const CHAR *) "int",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_ellipsis = {
bt_ellipsis,
QUAL_NONE,
STATE_NONE,
UNKNOWN_SIZE,
NIL_TYP,
NIL_TYP,
(const CHAR *) "...",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_floatcomplex = {
bt_floatcomplex,
QUAL_NONE,
STATE_NONE,
8L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "float _Complex",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_floatimaginary = {
bt_floatimaginary,
QUAL_NONE,
STATE_NONE,
4L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "float _Imaginary",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_doublecomplex = {
bt_doublecomplex,
QUAL_NONE,
STATE_NONE,
16L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "double _Complex",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_doubleimaginary = {
bt_doubleimaginary,
QUAL_NONE,
STATE_NONE,
8L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "double _Imaginary",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_longdoublecomplex = {
bt_longdoublecomplex,
QUAL_NONE,
STATE_NONE,
24L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "long double _Complex",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
static TYP stp_longdoubleimaginary = {
bt_longdoubleimaginary,
QUAL_NONE,
STATE_NONE,
12L,
NIL_TYP,
NIL_TYP,
(const CHAR *) "long double _Imaginary",
{
NIL_RANGE} /*lint !e708*/ /* union initialization */
};
#ifndef CPU_DEFINED
/*
* The following tables specify the alignment requirements of the
* basic types depending on the processor type.
*/
static SIZE alignments[] = {
1L, /* bt_void */
1L, /* bt_bool */
1L, /* bt_char */
1L, /* bt_charu */
1L, /* bt_uchar */
1L, /* bt_schar */
2L, /* bt_short */
2L, /* bt_ushort */
2L, /* bt_int16 */
2L, /* bt_uint16 */
2L, /* bt_int32 */
2L, /* bt_uint32 */
2L, /* bt_long */
2L, /* bt_ulong */
2L, /* bt_longlong */
2L, /* bt_ulonglong */
2L, /* bt_float */
2L, /* bt_double */
2L, /* bt_longdouble */
2L, /* bt_floatcomplex */
2L, /* bt_doublecomplex */
2L, /* bt_longdoublecomplex */
2L, /* bt_floatimaginary */
2L, /* bt_doubleimaginary */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -