📄 ccsym.h
字号:
/* CCSYM.H - Declarations for KCC type and symbol table structures
**
** (c) Copyright Ken Harrenstien 1989
** All changes after v.126, 24-Sep-1987
** (c) Copyright Ken Harrenstien, SRI International 1985, 1986
** All changes after v.8, 8-Aug-1985
**
** Original version split from cc.h / David Eppstein / 23 May 85
*/
#ifndef EXT
#define EXT extern
#endif
/* Must define these together here since they need each other */
#define SYMBOL struct symbol
#define TYPE struct type
/* Constant - # words in a symbol identifier */
#define IDENTWDS ((IDENTSIZE+sizeof(INT)-1)/sizeof(INT))
/*
* Character to which '_' gets mapped in identifier names, and
* character to use as prefix in static identifiers (interdependent).
*/
#define UNDERSCORE_MAPCHR '%'
#define STATIC_PREFIXCHAR '$'
/* SYMBOL - Symbol table entry
** All symbols have a name (Sname) and a "symbol class" (Sclass) which
** determines the meaning of the rest of the structure.
*/
SYMBOL {
struct {
#if SYS_CSI
char s_reg; /* value 6 thru 15, for register vars */
#endif
char s_class; /* Symbol class - a SC_ value */
INT s_flags; /* Symbol flags (SF_) */
union {
char s_ch[IDENTSIZE]; /* Symbol identifier string */
INT s_int[IDENTWDS];
} Sid; /* Copyable contents */
union { /* Use depends on Sclass */
INT s_int; /* symbol value, misc uses */
SYMBOL *s_sym; /* symbol for label,static */
struct { /* Handy values for macro defs (SC_MACRO) */
#if 0 /* ! */
signed char svm_npar; /* # params (< 0 for special macs) */
unsigned char svm_parl; /* # chars of param names in body */
unsigned short svm_len; /* # total chars in body string */
#else
int svm_npar : 8;
unsigned int svm_parl : 8;
unsigned int svm_len : 16;
#endif
} sv_mac;
} s_val;
union { /* Use depends on Sclass */
TYPE *s_type; /* C type pointer */
int s_rwkey; /* reserved word key */
char *s_macptr; /* macro pointer */
} s_var;
} Scontents; /* Copyable contents (for struct assigns) */
/* Primarily used for SC_TAG/SC_UTAG and SC_MEMBER/SC_ENUM;
** also used for linking SC_ARG/SC_RARG parameter lists.
*/
SYMBOL *Ssmnext; /* next structure member */
union {
SYMBOL *s_sym; /* tag of structure that member belongs to */
TYPE *s_typ; /* Hidden prototype list */
} s_tag;
SYMBOL *Sprev; /* ptr to prev symbol on glob/local list */
SYMBOL *Snext; /* ptr to next symbol on ditto */
int Srefs; /* # times referenced since created */
/* KAR-11/91, usage before initialization */
/* KAR-9/92, added Sused for detecting auto value set but not used */
char Sinit; /* binary flag to signal initialization */
char Sused; /* binary flag to signal usage */
SYMBOL *Snhash; /* ptr to next sym on this hash chain */
};
/* Defs providing external access to structure fields, depending on
* the kind of symbol. No "s_" member should ever be referenced directly.
*/
/* Every symbol class uses these fields */
#if SYS_CSI
#define Sreg Scontents.s_reg /* value 6 thru 15, for register vars */
#endif
#define Sclass Scontents.s_class /* Symbol class */
#define Sflags Scontents.s_flags /* Symbol flags */
#define Sname Scontents.Sid.s_ch /* Symbol name string */
#define Sidwds Scontents.Sid.s_int /* name in wds for speed */
/* Many (but not all) symbol classes use these fields */
#define Stype Scontents.s_var.s_type /* C type of symbol */
#define Svalue Scontents.s_val.s_int /* Misc uses */
/* Sclass == SC_UNDEF
** When the lexer returns an identifier, it also points "csymbol"
** to an entry in the symtab. If the symbol did not already exist, it is
** created with class SC_UNDEF.
** Only Sname and Sclass will be set.
** Stype will be NULL and Svalue zero.
** Normally the parser changes this quickly to something else, or gets
** rid of the symbol. The only known usages which keep SC_UNDEF symbols
** around are:
** - A pair of dummy symbols at the start of the global & local sym lists.
** - References to structures/unions that have not yet been defined.
** Stype should indicate either TS_STRUCT or TS_UNION.
*/
/* Sclass == SC_RW (reserved word)
** Stoken holds the token code to return when the lexer finds this word.
** Skey contains a reserved-word token type key, one of the TKTY_ values.
*/
#define Stoken Scontents.s_val.s_int
#define Skey Scontents.s_var.s_rwkey
/* Sclass == SC_MACRO (preprocessor macro definition)
** Smacptr points to the macro body (a dynamically allocated string).
** This may be NULL for special types of macros.
** Smacnpar says how many arguments it takes, or (if < 0) indicates
** a special built-in macro. See CCPP for details.
** Smacparlen is the # chars of param-names at start of body, if any.
** Smaclen is the total # chars in the macro body string.
** Smacparlen and Smaclen are 0 if Smacptr is NULL.
*/
#define Smacptr Scontents.s_var.s_macptr
#define Smacnpar Scontents.s_val.sv_mac.svm_npar
#define Smacparlen Scontents.s_val.sv_mac.svm_parl
#define Smaclen Scontents.s_val.sv_mac.svm_len
/* Sclass == SC_TAG, SC_UTAG - Structure, union, or enum tag
** Sclass == SC_MEMBER - Structure or union member (component)
** Sclass == SC_ENUM - Enum list member
** See the discussion of structure tags and members farther on
** for a thorough explanation.
*/
#define Ssmoff Svalue /* Offset of member in struct/union */
#define Ssmtag s_tag.s_sym /* Tag of entity that member belongs to */
/* Sclass == SC_TYPEDEF
** This symbol is a "typedef name" and is lexically considered a
** type-specifier keyword.
** Stype points to the C type which this symbol represents.
*/
/* Sclass == SC_EXTDEF, SC_EXTREF, SC_XEXTREF, SC_EXLINK
** All of these classes refer to objects or functions with external
** linkage.
** SC_EXTDEF - the obj or fun has been defined (file-scope only)
** SC_EXTREF - the obj or fun has been declared (file or block scope).
** SC_XEXTREF - same, but declaration has gone out of scope.
** SC_EXLINK - this file-scope object (never function) has been
** declared with a "tentative definition". If no definition
** has been seen by end of the file, a zero initializer def is
** generated for it.
**
** Stype specifies the symbol's C type.
** Smaplab specifies the actual label to use for this object/function
** when emitting code. Currently this is a SIXBIT value.
** Shproto (SC_EXTDEF functions only) points to a hidden funct prototype.
**
** When parsing top-level declarations, SC_EXLINK is the default storage class
** when no explicit storage class is specified, as opposed to SC_EXTREF
** which indicates that "extern" was seen. This allows KCC
** to distinguish between "extern" that is assumed, and "extern" that
** is stated. See H&S 4.3.1 and 4.8.
** In the assembler output file, SC_EXTDEF causes the generation
** of an INTERN, and SC_(X)EXTREF an EXTERN. (SC_EXLINK should never be
** seen by that point).
**
** If the function was defined with an old-style declaration and no
** prototype already existed, then "Shproto" will be set to point to a
** "hidden" prototype constructed from the parameter declarations for the
** function. This is used for comparison if a later prototype declaration
** for the function is seen, and for optional validity checking on calls.
*/
#define Smaplab Svalue /* Mapped label name for assembler output */
#define Shproto s_tag.s_typ /* "Hidden" prototype for old-style fn def */
/* Sclass == SC_INTDEF, SC_INTREF, SC_INLINK
** All of these classes refer to file-scope objects or functions
** with internal linkage.
** SC_INTDEF - the obj or fun has been defined (file-scope "static").
** SC_INTREF - the funct (never obj) has been declared (file-scope "static").
** SC_INLINK - the object (never funct) is a tentative definition, just
** as for SC_EXLINK.
**
** The object (var or fun) has static extent and the symbol is not
** exported to the linker. This can only happen if "static" is explicitly
** stated, and only at top-level (file scope).
** Stype specifies the symbol's C type.
** Smaplab is used for object/function labels just as for SC_EX*.
** Shproto is used for functions just as for SC_EXTDEF.
*/
/* Sclass == SC_ISTATIC
** This class is used for objects (never functions) that have
** static extent, block scope and no linkage.
** Stype specifies the symbol's C type.
** Smaplab someday will be used as for SC_IN* and SC_EX*.
** Ssym points to a uniquely generated internal label symbol.
*/
#define Ssym Scontents.s_val.s_sym
/* Sclass == SC_ARG, SC_RARG - Function parameters
** Stype specifies the parameter's C type.
** Spmnext is a symbol pointer to the next parameter (or null if last one)
** Svalue contains stack offset, similar to SC_AUTO except that it is
** a positive number (if all args are 1 word, this is same as
** argument number) and thus needs to be inverted for an actual
** stack reference.
** The use of Spmnext overlays that of Ssmnext, but there is no conflict
** since tag and member idents can never be parameters.
** Note that Spmhead is not used in the symbol table, only in the temporary
** syms that CCDECL uses to parse declarators, and only for function type
** declarators in order to properly manage the scope of prototypes.
*/
#define Spmnext Ssmnext /* Pointer to next parameter */
#define Spmhead Ssmtag /* Saved start of local sym block for params */
/* Sclass == SC_REGISTER
** This isn't really used anywhere. For the time being,
** the classes SC_RAUTO and SC_RARG remember whether the "register" keyword
** was specified with auto vars or function parameters. This could be used
** to help the optimizer.
** Someday this may be changed to use a SF_REGISTER flag and flush
** the use of SC_RARG and SC_RAUTO as distinct classes.
*/
/* Sclass == SC_AUTO, SC_RAUTO, SC_XAUTO, SC_XRAUTO
** SC_AUTO describes an "auto" variable, within a block. This is the
** default storage class when parsing declarations within a block.
** SC_RAUTO is the same but indicates that the "register" storage class
** was given in the declaration.
** SC_XAUTO and SC_XRAUTO are what SC_AUTO and SC_RAUTO are turned
** into when parsing has left the block within which the variable
** was declared. That is, the declaration is no longer active.
**
** Stype specifies the symbol's C type.
** Svalue holds the stack offset value, in words.
*/
/* Sclass == SC_LABEL, SC_ULABEL (goto labels)
**
** Ssym is used just as for SC_ISTATIC; it points to a label symbol
** generated for use by goto statements.
*/
#define Ssym Scontents.s_val.s_sym
/* OVERLOADING CLASSES or NAME SPACES
**
** Certain types of symbols have a prefix character in their names
** as a hack to provide for "overloading classes" or "name spaces"
** [Ref H&S 4.2.4] [dpANS 3.1.2.3]
** These prefixes (none of which are legal as part of an input
** identifier) are:
** + - Structure member symbols ("component names")
** ^ - Structure/enum tag symbols ("struct, union, and enum tags")
** @ - Goto label symbols ("statement labels")
** The other two name classes ("preprocessor macro names" and "other names")
** do not need a prefix, because the former are handled during preprocessing
** prior to compilation, and the latter are normal. For reference, here
** is a list of the overloading classes as defined in H&S, with a code:
** OC= Overloading Class
** M Preprocessor macro names
** L Statement labels
** T Struct/union/enum tags
** * Structure component names (unique class for each structure)
** - Normal
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -