📄 ccsym.h
字号:
** of TS_ARRAY with the given Tsize and Tsubt.
** To repeat: TS_PTR is now just a normal type, and its Tsize always
** represents the pointer size (1 word).
*/
/* All arithmetic types (floating point and integral):
** Tflag == Low-order bits have size in bits. Many TF_ flags.
** Tsize == size in words (if less than 1, is 1).
** Tsubt == NULL (unused).
*/
/* Structure/Union/Enum tags and members
**
** If a type has Tspec TS_STRUCT, TS_UNION, or TS_ENUM, then it has no subtype
** pointer. Instead, t_var is interpreted as "Tsmtag" - that is, a pointer
** to a tag symbol (Sclass SC_TAG). In the following discussion, the word
** "structure" is understood to mean both "struct" and "union".
**
** Struct/Union/Enum types:
** Tspec - TS_STRUCT, TS_UNION, or TS_ENUM.
** Tsize - size of the structure, in words. 0 if structure not yet
** defined. INTSIZE if an enum type.
** Tsmtag - pointer to the tag symbol for this type.
**
** Tag symbols:
** Sclass - SC_TAG (or SC_UTAG if not yet defined).
** Sname - the tag name, prefixed with SPC_TAG. This will be
** a unique internal name if the structure or enum list was
** not named with a tag at definition time.
** Stype - pointer to the C type. This is in effect a backpointer
** to the type specification described above.
** Ssmnext - pointer to the first component symbol of this object.
** This will be NULL if the tag is still undefined (SC_UTAG).
** For a structure, the components are structure members
** with Sclass SC_MEMBER. For an enum, the components are
** enum constants with Sclass SC_ENUM.
**
** Structure member symbols:
** Each component of a structure is represented by an unique
** symbol table entry. The members are linked together in order of
** definition.
** Sclass - SC_MEMBER
** Stype - C type of this member.
** Ssmoff - offset from beginning of structure.
** If positive, it is a word offset from start of struct.
** If negative, it is a bitfield. After making it positive again,
** the low 12 bits are the P+S fields of a byte pointer,
** and the remaining high bits are the word offset.
** Ssmnext - pointer to next member (NULL if this is last one).
** Ssmtag - pointer back to "parent" structure tag symbol.
** The sole reason for the existence of Ssmtag is so that
** it is possible to find out very quickly whether an
** arbitrarily selected SC_MEMBER symbol does in fact
** belong to a specific structure.
**
** Enum constant symbols:
** Each component of an enum list is represented by an unique
** symbol table entry, linked together in order of definition.
** These are almost the same as SC_MEMBERs except that Svalue is used
** instead of Ssmoff.
** Sclass - SC_ENUM
** Stype - C type (always "int" for now).
** Svalue - integer value of this enum constant.
** Ssmnext - pointer to next component (NULL if this is last one).
** Ssmtag - pointer back to "parent" tag symbol.
** This is not really used at the moment but is kept for
** consistency with SC_MEMBER and (someday) error messages.
**
** Tag, enum constant, and structure member symbols are treated just as
** regular variable symbols are. They can be made global or local, and in
** particular can be "shadowed" by structure definitions in inner blocks,
** through use of the global/local symbol lists and the SF_XLOCAL flag.
** Note that each structure member always has its own symbol cell, even
** though the identifier may duplicate that of a another structure's
** member. They are distinguished by checking the "Ssmtag" pointer,
** which indicates the structure enclosing any particular member.
** Enum constant symbols likewise are all unique to a particular tag,
** even though the language does not require this (in fact it requires
** that enum constant identifiers be treated in the same overloading class
** as regular variable identifiers!) This is so the list structure won't
** be screwed up by redefinitions. However, error messages will be
** generated whenever a duplicate enum constant definition is seen.
**
** There is a special situation where a struct/union definition might still
** be needed even after the tag (explicit or internal) would ordinarily
** have been flushed from the symbol table. This is for a def within a
** function prototype (either def or ref), which
** results in a parameter "type" that cannot ever match another type in
** any function call or prototype comparison once the prototype scope is left.
** In order to do this, tags defined within prototype scope are flagged
** with SF_PROTOTAG, and ridlsym() avoids flushing those symbols; instead
** it hides them with SF_XLOCAL and moves them to the global list, there to
** reside forever (until a new file compilation is started). It does not
** bother preserving the members of such tags, however, and sets Ssmnext
** to NULL. This ensures that the TYPE node's Tsmtag reference will remain
** valid and unique for the rest of the file.
**
** K&R "global" structure members are no longer allowed, as per H&S
** and ANSI.
*/
/* Type Specifiers */
/* Define moby macro defining all type specs.
** typespec(enum_name, string, size_in_bits, flags)
**
** The size_in_bits for TS_BITF (bitfields) is 1 here only so that
** the tables will be initialized properly and the TF_BYTE flag set
** for them. In actuality their size varies (and the same is possible
** for char).
** The TF_BYTE flag is automatically set on startup for all types
** that are valid objects smaller than a word. It is also set
** specially for TS_VOID, so that (void *) will be recognized as having
** a byte-pointer representation even tho it has a zero size!
**
** WARNING!!! If the ordering of this macro is changed, the values in
** the CONVTAB table in CCTYPE must also be changed!!!
*/
#define alltypemacro \
/* Misc types (keep TS_VOID as zero for elegance) */\
typespec(TS_VOID, "void", 0,TF_BYTE) /* (void) */\
typespec(TS_FUNCT,"function",0,0) /* Function (rets subtype) */\
/* Aggregate types */\
typespec(TS_ARRAY, "array", 0,0) /* Array (of a subtype) */\
typespec(TS_STRUCT,"struct", 0,TF_STRUCT) /* Structure */\
typespec(TS_UNION, "union", 0,TF_STRUCT) /* Union */\
/* Scalar misc types */\
typespec(TS_PTR, "pointer",TGSIZ_PTR, TF_SCALAR) /* Ptr (to subtype) */\
typespec(TS_ENUM,"enum", TGSIZ_ENUM,TF_SCALAR) /* Enum */\
/* Scalar Arithmetic types - Floating-point */\
typespec(TS_FLOAT, "float", TGSIZ_FLOAT, TF_FLOAT) /* (float) */\
typespec(TS_DOUBLE,"double",TGSIZ_DOUBLE,TF_FLOAT) /* (double) */\
typespec(TS_LNGDBL,"lngdbl",TGSIZ_LNGDBL,TF_FLOAT) /* (long double) */\
/* Scalar Arithmetic types - Integral */\
typespec(TS_BITF, "bitf", 1, TF_INTEG+TF_BITF) /* bitfield */\
typespec(TS_CHAR, "char", TGSIZ_CHAR, TF_INTEG+TF_CHAR) /* char */\
typespec(TS_SHORT,"short", TGSIZ_SHORT,TF_INTEG) /* short */\
typespec(TS_INT, "int", TGSIZ_INT, TF_INTEG) /* int */\
typespec(TS_LONG, "long", TGSIZ_LONG, TF_INTEG) /* long */\
typespec(TS_UBITF,"u_bitf", 1, TF_UINTEG+TF_BITF) \
typespec(TS_UCHAR,"u_char", TGSIZ_CHAR, TF_UINTEG+TF_CHAR) \
typespec(TS_USHORT,"u_short",TGSIZ_SHORT,TF_UINTEG) \
typespec(TS_UINT, "u_int", TGSIZ_INT, TF_UINTEG) \
typespec(TS_ULONG,"u_long", TGSIZ_LONG, TF_UINTEG)
/* Define values for Tspec */
enum typespecs {
#define typespec(ts,str,bsiz,fl) ts,
alltypemacro /* Expand */
#undef typespec
TS_MAX, /* # types; 1st non-existent typespec index */
/* Additional Tspec vals for fn prototypes */
TS_PARVOID=TS_MAX, /* fn(void) - only at beg of proto list */
TS_PARINF, /* ", ..." - only at end of proto list */
TS_PARAM /* Normal parameter */
};
/* Definitions for Tflag - note that bitsize and flags must not overlap. */
#define tbitsize(t) ((t)->Tflag&0777) /* Get size in bits for a type */
#define TF_CONST 01000 /* Type is a "const" object */
#define TF_VOLATILE 02000 /* Type is a "volatile" object */
#define TF_INTEG 010000L /* Integral type */
#define TF_FLOAT 020000L /* Floating-point type */
#define TF_SCALAR 040000L /* Scalar type */
#define TF_UNSIGN 0100000L /* Unsigned type */
#define TF_CHAR 0200000L /* Char type */
#define TF_BITF 0400000L /* Bitfield type */
#define TF_STRUCT 01000000L /* Struct or Union type */
#define TF_BYTE 02000000L /* Byte (non-word) type (MACH DEPENDENT) */
#define TF_SICONST 04000000L /* Struct/union with inner "const" */
#define TF_SIVOLAT 010000000L /* Struct/union with inner "volatile" */
#if SYS_CSI
#define TF_FORTRAN 0100000000L /* fortran attribute for functions */
#define TF_BLISS 0200000000L /* bliss attribute for functions */
#define TF_INTERRUPT 0400000000L /* FW 2A(52) interrupt fn qualifier */
#endif
/* Combos */
#define TF_QUALS (TF_CONST|TF_VOLATILE) /* Type qualifiers */
#define TF_SIQUALS (TF_SICONST|TF_SIVOLAT) /* Type qualifiers in struct */
#define TF_UINTEG (TF_INTEG+TF_UNSIGN) /* to save space in alltypemacro */
/* Quick-check macros. Try to avoid directly using the TF_ macros. */
#define tisqualif(t) (((t)->Tflag&TF_QUALS)!=0)
#define tisconst(t) (((t)->Tflag&TF_CONST)!=0)
#define tisvolatile(t) (((t)->Tflag&TF_VOLATILE)!=0)
#define tisstructiconst(t) (((t)->Tflag&TF_SICONST)!=0)
#define tisstructivolat(t) (((t)->Tflag&TF_SIVOLAT)!=0)
#define tisanyvolat(t) (((t)->Tflag&(TF_VOLATILE|TF_SIVOLAT))!=0)
#define tisinteg(t) (((t)->Tflag&TF_INTEG)!=0)
#define tisfloat(t) (((t)->Tflag&TF_FLOAT)!=0)
#define tisarith(t) (((t)->Tflag&(TF_INTEG+TF_FLOAT))!=0)
#define tisscalar(t) (((t)->Tflag&(TF_INTEG+TF_FLOAT+TF_SCALAR))!=0)
#define tischar(t) (((t)->Tflag&TF_CHAR)!=0) /* char type */
#define tisbitf(t) (((t)->Tflag&TF_BITF)!=0) /* bit field */
#define tisunsign(t) (((t)->Tflag&TF_UNSIGN)!=0) /* unsigned */
#define tissigned(t) (!tisunsign(t)) /* signed */
#define tisstruct(t) (((t)->Tflag&TF_STRUCT)!=0) /* struct or union */
#define tisbyte(t) (((t)->Tflag&TF_BYTE)!=0) /* Byte (non-word) object */
/* Similar functions too complex for macros */
#define tischarpointer tischp /* External name disambiguation */
#define tisbytepointer tisbyp
#define tischararray tischa
#define tisbytearray tisbya
extern int tischarpointer(TYPE *), tischararray(TYPE *);
extern int tisbytepointer(TYPE *), tisbytearray(TYPE *);
#if 0
extern int tischarpointer(), tisbytepointer(),
tischararray(), tisbytearray();
#endif
/* Same macros, but with a Tspec argument. */
#define tspisinteg(ts) (tfltab[ts]&TF_INTEG)
#define tspisfloat(ts) (tfltab[ts]&TF_FLOAT)
#define tspisarith(ts) (tfltab[ts]&(TF_INTEG+TF_FLOAT))
#define tspisscalar(ts) (tfltab[ts]&(TF_INTEG+TF_FLOAT+TF_SCALAR))
#define tspischar(ts) (tfltab[ts]&TF_CHAR)
#define tspisunsigned(ts) (tfltab[ts]&TF_UNSIGN)
extern INT tfltab[]; /* Flag table, kept in CCDATA */
/* Cast (Type Conversion) types (NODE.Ncast) */
#define allcastmacro \
/* General-purpose cast types */\
castspec(CAST_ILL,"ill") /* convtab[] only: Illegal cast */\
castspec(CAST_TRIV,"triv") /* convtab[] only: types must be == */\
castspec(CAST_NONE,"none") /* No actual conversion needed */\
/* Casts to Integer Type */\
castspec(CAST_IT_IT,"it_it") /* from Integer Type */\
castspec(CAST_FP_IT,"fp_it") /* from Floating-Point type */\
castspec(CAST_EN_IT,"en_it") /* from ENumeration type */\
castspec(CAST_PT_IT,"pt_it") /* from Pointer Type */\
/* Casts to Floating-Point type */\
castspec(CAST_FP_FP,"fp_fp") /* from Floating-Point type */\
castspec(CAST_IT_FP,"it_fp") /* from Integer Type */\
/* Casts to ENum type */\
castspec(CAST_EN_EN,"en_en") /* from ENumeration type */\
castspec(CAST_IT_EN,"it_en") /* from Integer Type */\
/* Casts to Pointer Type */\
castspec(CAST_PT_PT,"pt_pt") /* from Pointer Type */\
castspec(CAST_IT_PT,"it_pt") /* from Integer Type */\
/* Misc casts */\
castspec(CAST_AR_PA,"ar_pa") /* Array -> Ptr to 1st element */\
castspec(CAST_FN_PF,"fn_pf") /* Function -> Pointer to Function */\
castspec(CAST_VOID,"void") /* Any type to void type (discard) */
enum castspecs {
#define castspec(op,str) op,
allcastmacro /* Expand */
#undef castspec
CAST_MAX /* # of cast types */
};
/* Macro to generate a unique index for every possible type cast combo */
#define castidx(from,to) (((to)*TS_MAX)+(from))
/*
** Misc shared storage
*/
EXT SYMBOL
*symbol, /* Global symbol table head ptr */
*csymbol, /* Current symbol */
*minsym; /* minimum variable ptr (CC, CCSYM) */
EXT SYMBOL bytsym; /* Symbol for $BYTE */
extern SYMBOL *htable[]; /* Symbol hash table (CCSYM, CCDATA) */
extern TYPE *ttable[]; /* Type hash table (CCSYM, CCDATA) */
extern TYPE *types; /* Table of type structs (CCDUMP, CCSYM, CCDATA) */
/* Eventually make this dynamic */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -