⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ccsym.h

📁 KCC , a good c compiler, write by Ken Harrenstien
💻 H
📖 第 1 页 / 共 3 页
字号:
*/

#define SPC_SMEM ('+')		/* * Structure/union members */
#define SPC_TAG  ('^')		/* T Structure/union/enum tags */
#define SPC_LABEL ('@')		/* L Statement labels */
#define SPC_MACDEF ('?')	/* Special for hiding the "defined" macro */
#define SPC_IDQUOT ('`')	/* Special for hiding quoted idents */
#define SPC_IAUTO ('<')		/* Special for hiding internal auto vars */

/* Symbol Classes and Storage Classes:
 *
 * SC_xxx are the symbol classes used internally by the compiler.
 * SCDB_xxx are the storage classes used externally by the debugger.
 * Macro scdefs and array scmap define the relation between the two.
 */

#define SCDB_TYPEDEF	1
#define SCDB_TAG	2
#define SCDB_MEMBER	3
#define SCDB_ENUM	4
#define SCDB_EXTDEF	5
#define SCDB_INTDEF	6
#define SCDB_ISTATIC	7
#define SCDB_ARG	8
#define SCDB_RARG	9
#define SCDB_AUTO	10
#define SCDB_RAUTO	11
#define SCDB_LABEL	12

#define scdefs \
	scdef(SC_MACRO, 0)\
	scdef(SC_RW,    0)\
	scdef(SC_TYPEDEF, SCDB_TYPEDEF)\
	scdef(SC_TAG,   SCDB_TAG)\
	scdef(SC_UTAG,  0)\
	scdef(SC_MEMBER,SCDB_MEMBER)\
	scdef(SC_ENUM,  SCDB_ENUM)\
	scdef(SC_XEXTREF, 0)\
	scdef(SC_EXTREF,0)\
	scdef(SC_INTREF,0)\
	scdef(SC_EXTDEF, SCDB_EXTDEF)\
	scdef(SC_INTDEF, SCDB_INTDEF)\
	scdef(SC_EXLINK,0)\
	scdef(SC_INLINK,0)\
	scdef(SC_ISTATIC,SCDB_ISTATIC)\
	scdef(SC_ARG,    SCDB_ARG)\
	scdef(SC_RARG,   SCDB_RARG)\
	scdef(SC_AUTO,   SCDB_AUTO)\
	scdef(SC_RAUTO,  SCDB_RAUTO)\
	scdef(SC_REGISTER,0)\
	scdef(SC_LABEL,  SCDB_LABEL)\
	scdef(SC_ULABEL,0)\
	scdef(SC_ILABEL,0)

/* Symbol Classes (some relationship to "storage classes") */
			/* OC-----> Overloading Class */
			/*   vf --> v=var object, f=function */
enum symbolspec {
	SC_UNDEF	/*	Undefined  - should be zero */
#define scdef(a,b) ,a
	scdefs
#undef  scdef

#if 0
	SC_MACRO,	/* -	Macro name */
	SC_RW,		/* -	Reserved Word */
	SC_TYPEDEF,	/* -	Typedef name */
	SC_TAG,		/* T	Struct/union/enum tag */
	SC_UTAG,	/* T	Undefined struct/union/enum tag */
	SC_MEMBER,	/* * v	Struct/union member */
	SC_ENUM,	/* - v	Enumeration constant "member" */

			/*	Extent	Linkage	Scope	Def/Ref	*/
	SC_XEXTREF,	/* - vf	static	extern	-	reference */
	SC_EXTREF,	/* - vf	static	extern	file	reference */
	SC_INTREF,	/* - vf	static	intern	file	reference */
	SC_EXTDEF,	/* - vf	static	extern	file	definition */
	SC_INTDEF,	/* - vf	static	intern	file	definition */
	SC_EXLINK,	/* - v	static	extern	file	tentative def */
	SC_INLINK,	/* - v	static	intern	file	tentative def */
	SC_ISTATIC,	/* - v	static	-	block	definition */
	SC_ARG,		/* - v	auto	param	block	def		*/
	SC_RARG,	/* - v	auto	param	block	def (register)	*/
	SC_AUTO,	/* - v	auto	-	block	def		*/
	SC_RAUTO,	/* - v	auto	-	block	def (register)	*/
	SC_REGISTER,	/* - v	auto	-	block	def (register)	*/

	SC_LABEL,	/* L	Goto label */
	SC_ULABEL,	/* L	Undefined goto label */
	SC_ILABEL	/* L	Internal ($xxx) label. Not used in symtab. */
#endif
};

/* Symbol flags */
#define SF_LOCAL	01	/* Local symbol (not file scope) */
#define SF_XLOCAL	02	/* Local symbol no longer active */
#define SF_PROTOTAG	04	/* SC_TAG or SC_UTAG only: prototype scope */
#define SF_PARAMDECL	010	/* SC_ARG only: parameter declaration seen */
#define SF_SIDEFF	020	/* Side-effect (tag or enum) during parsing.
				** This flag is only set by CCDECL's pbase()
				** for dummy "base" symbol structures
				** and only used to detect null declarations.
				*/
#define SF_MACEXP	0100	/* SC_MACRO only: macro being expanded.
				** This is used to detect and suppress
				** recursive expansions.
				*/
#define SF_MACSHADOW	0200	/* Any class, indicates this symbol is
				** shadowed by a macro symbol (ie has the
				** same identifier).
				*/
#define SF_MACRO	040	/* SC_MACRO only: overloading class flag */
#define SF_MEMBER	01000	/* SC_MEMBER only: overloading class flag */
#define SF_TAG		02000	/* SC_TAG/SC_UTAG only: ditto */
#define SF_LABEL	04000	/* SC_LABEL/SC_ULABEL only: ditto */
#define SF_OVCLS (SF_MACRO|SF_MEMBER|SF_TAG|SF_LABEL)	/* All ov classes */


#if 0
#define SF_REGIS	02	/* User declared this as "register" */
#endif

/*
** Global vs Local symbols
**	Local symbols are kept on the "locsymbol" list and global ones on
** the "symbol" list.  Local symbols can have the following classes:
**	SC_ARG, SC_RARG			(function parameters)
**	SC_AUTO, SC_RAUTO, SC_ISTATIC	(auto, register, static)
**	SC_TAG, SC_UTAG, SC_ENUM, SC_MEMBER (struct/union/enum tags,enums,mems)
**	SC_LABEL, SC_ULABEL, SC_ILABEL	(goto labels)
**
**	When parsing enters a scope block, "beglsym()" is called to set
** a pointer to the start of the list of symbols local to that block.
** All symbols before this pointer will belong to outer blocks; all symbols
** after this pointer will belong to this block or inner blocks.
**	When parsing leaves a block, the symbols local to that block are
** still retained so that code generation can refer to them, but they are
** rendered inactive by setting the SF_XLOCAL (ex-local) flag.  This is
** done by having "compound()" call "endlsym()".  The findsym
** routine will never return a symbol which has this flag set.
** Thus, at any time, the symbols defined within any specific block (and
** not outer or inner ones) are represented by all of the local symbols
** following this remembered "head pointer" which do NOT have SF_XLOCAL set.
**
**	All local symbols -- ie everything on the locsymbol list -- are
** flushed completely when the code generator has finished dealing with
** a function's parse tree.  "ridlsym()" is the function called to do this.
** Note that SC_ARG and SC_RARG are active over the entire body of
** a function.
**
**	Note that SC_ILABEL symbols are never found in the symbol table
** itself.  These are generated by CCLAB and kept on a separate label list.
** Certain symbols may point to these "label symbols", however.
*/

/* TYPE - Type table entry
*/

TYPE {
    char Tspec;			/* Type specifier, set to a TS_ value */
    INT Tflag;			/* Flags, plus size in bits (mask 0777) */
    union {
	unsigned INT t_int;	/* Size in words, or # elements. */
	TYPE *t_subt;		/* Ptr to parameter list, if function */
    } t_v0;
    union {
	INT t_int;
	TYPE *t_subt;		/* Subtype if not a basic type */
	SYMBOL *t_sym;		/* or tag name of struct or union */
    } t_v1;
    TYPE *Tnhash;		/* Pointer to next in hash chain */
};

/* Define generally used members for public consumption.
** Code should never refer to "t_" members directly.
*/
#define Tsize  t_v0.t_int	/* Size (in wds or elems) - all but TS_FUNCT */
#define Tsubt  t_v1.t_subt	/* Subtype - TS_FUNCT, TS_ARRAY, TS_PTR */

/* For all types:
**
** Tspec is set to a TS_ value.  These are specified by the "alltypemacro"
**	definition on the next page.
** Tflag is used to hold both TF_ flags as well as the # of bits occupied
**	by an object of scalar type.  The flags are set from:
**		(1) the flags specified in the "alltypemacro" definition, plus
**		(2) TF_CONST or TF_VOLATILE if so declared, plus
**		(3) TF_BYTE if the object is a bitfield OR is smaller than
**		 a word.  (This is the only machine-dependent flag).
**	Note that the size in bits is only meaningful for objects of
**	scalar type, and is only really used for objects of integral type.
** Tnhash serves to chain together all types which hash to the same
**	value.
**
** The other two members of a TYPE struct have varied uses which depend on
** the TS_ value in Tspec.  The most common usages are:
**
**	Tsize - normally represents the size of the object in terms of words.
**	Tsubt - holds pointer to a subtype, if any.
*/

/* Tspec == TS_VOID
**	Tflag == 0 (may be qualified)
**	Tsize == 0	(unused)
**	Tsubt == NULL	(unused)
*/

/* TS_FUNCT - Function returning Tsubt.
**	Tflag == 0 (cannot be qualified)
**	Tsubt - type of return value.
**	Tproto - if NULL, no prototype exists.  Otherwise, points to
**		the first node of a parameter list.
** Note that Tproto occupies the space normally used for Tsize; the latter
** interpretation is meaningless for a function.
** Functions without prototypes may still have a "hidden prototype" if
** an old-style definition was seen prior to any prototype declaration; this
** prototype list will be pointed to by Shproto of the identifier's symbol.
** See SC_EXTDEF.
*/
#define Tproto t_v0.t_subt	/* Ptr to prototype param list, if any */

/* TS_PARxxx - Parameter List "types"
**	The Tspec values TS_PARVOID, TS_PARINF, and TS_PARAM
** are not real types; they are used to link together parameter lists for
** function prototypes.
** 
**	Tspec - a TS_PARxxx value.
**	Tflag - 0 (unused).
**	Tproto - points to next node in parameter list. (reusing Tsize)
**	Tsubt - NULL for TS_PARVOID and TS_PARINF; otherwise (for TS_PARAM)
**		points to the unqualified type for this parameter.
**
** TS_PARVOID, if it exists, should be the only thing in a prototype list;
**	it indicates that the function takes no arguments.
** TS_PARINF, if it exists, should be the last thing in a prototype list;
**	it represents ellipsis terminator (",...")
** TS_PARAM is used for all normal parameters.
**	Note that the type pointed to is unqualified even if the parameter
**	identifier has a qualified type.  This is because all operations on
**	function prototypes (comparison, casting) use the unqualified type;
**	this does not prevent a function definition from using type
**	qualifiers on a parameter, because any reference to that parameter's
**	identifier within the function body will be given the qualified type
**	that the ident's Stype points to.
*/


/* TS_ARRAY - Array of Tsubt.
**	Tsubt - type of an array element.  This may be an array too.
**	Tsize is the # of elements (objects) in the array, each of which has
** the given subtype.  So the total size is Tsize times the size of
** the subtype.
**	If Tsize is 0, then the size of the array is unknown.  This can
** happen when the user declares something like "int foo[];"
** However, only the first dimension of a (possibly multi-dimensional)
** array can be left unspecified in this way, and obviously it will not
** work to do a sizeof on this array.
*/

/* TS_STRUCT, TS_UNION, TS_ENUM - Structure/Union/Enum of Tsmtag.
**	Tsmtag - points to the tag symbol for this type.  This re-uses the
**		space of "Tsubt".
**	Tsize is # of words in object.  If a struct/union is not yet
**		defined (i.e. Tsmtag->Sclass == SC_UTAG) then Tsize is 0
**		since the size is unknown.
** See the detailed description on the next page.
*/
#define Tsmtag t_v1.t_sym	/* TS_STRUCT or TS_UNION - tag pointer */

/* TS_PTR - Pointer to Tsubt.
**	Tsubt - type of object pointed to.
**	Tsize == 1 always (# wds in a pointer).
**
** It used to be the case that a type of TS_PTR used Tsize as an array
** indicator.  THIS IS NO LONGER TRUE, but for reference:
**	If Tsize 0, this was a normal TS_PTR to some object and the pointer
**		had the size PTRSIZE.
**	If Tsize non-zero, then this was a hybrid type that represented an
**		array name coerced into a pointer.  Tsize and Tsubt
**		were the same as the Tsize and Tsubt of the array in question.
**		The array type itself could be found by doing a findtype

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -