📄 trans.h
字号:
# define FSPCARG3 0x4000 /* First three arguments are special */#define WARNLIBR 0x8000 /* Warn for all uses of this library function */#define FWDPARAM 0x10000 /* Was a param name for forward-declared func */#define SSYNONYM 0x20000 /* Symbol is a synonym for another */typedef struct S_symbol { struct S_symbol *left; /* Left pointer in binary tree */ struct S_symbol *right; /* Right pointer in binary tree */ struct S_meaning *mbase; /* First normal meaning for this symbol */ struct S_meaning *fbase; /* First record-field meaning for this symbol */ Strlist *symbolnames; /* List of NameOf's for this name */ long flags; /* (above) */ Token kwtok; /* Token, if symbol is a keyword */ char name[1]; /* Pascal name (actually variable-sized) */} Symbol;/* "Meaning" notes: * * This represents one meaning of a symbol (see below). Meanings are * organized in a tree of contexts (i.e., scopes), and also in linked * lists of meanings per symbol. Fields described in the following are * undefined for kinds where they are not listed. Other fields are * defined in all kinds of meanings. * * MK_MODULE: Program, module, or unit. * mp->anyvarflag = 1 if main program, 0 if module. * mp->cbase => First meaning in module's context. * * MK_CONST: Pascal CONST. * mp->type => Type of constant, same as mp->constdefn->type & mp->val.type. * mp->anyvarflag = 1 if FoldConstants was true when defined. * mp->constdefn => Expression for the value of the constant. * mp->val = Value of the const, if can be evaluated, else val.type is NULL. * mp->xnext => Next constant in enumeration, else NULL. * mp->isreturn = 1 if constant was declared as a macro (with #define). * * MK_TYPE: Pascal type name. * mp->type => Type which name represents. * * MK_VAR: Normal variable. * mp->type => Type of variable. * mp->constdefn => Initializer for variable, else NULL. * mp->varstructflag = 1 if variable is in parent function's varstruct. * mp->isforward = 1 if should be declared static. * mp->isfunction = 1 if should be declared extern. * mp->namedfile = 1 if this file variable has a shadow file-name variable. * mp->bufferedfile = 1 if this file variable has a shadow buffer variable. * mp->anyvarflag = 1 if this is an implicit-declared FOR loop variable. * mp->fakeparam = 1 if this has already been seen by findinits. * mp->val.s => name format string if temporary var, else NULL. * * MK_VARREF: Variable always referenced through a pointer. * mp->type => Type "pointer to T" where T is type of variable. * mp->constdefn => Initializer for the pointer, else NULL. * (Others same as for MK_VAR.) * * MK_VARMAC: Variable which has a VarMacro. * mp->type => Type of variable. * mp->constdefn => Expression for VarMacro definition. * (Others same as for MK_VAR.) * * MK_SPVAR: Special variable. * mp->handler => C function to parse and translate the special variable. * * MK_FIELD: Record/struct field name. * mp->ctx, cbase = unused (unlike other meanings). * mp->cnext => Next field in record or variant. * mp->type => Type of field (base type if a bit-field). * mp->rectype => Type of containing record. * mp->constdefn => Expression for definition if FieldMacro, else NULL. * mp->val.i = Number of bits if bit-field, or 0 if normal field. * mp->val.type => True type of bit-field, else same as mp->type. * mp->isforward = 1 if tag field for following variant, else 0. * mp->namedfile = 1 if this file field has a shadow file-name field. * mp->bufferedfile = 1 if this file field has a shadow buffer field. * mp->isreturn = 1 if this is a private field in an object. * mp->fakeparam = 1 if this is a Turbo private field in an object. * * MK_VARIANT: Header for variant record case. * mp->ctx => First field in variant (unlike other meanings). * mp->cbase = unused (unlike other meanings). * mp->cnext => Next variant in record (or next sub-variant in variant). * mp->rectype => Type of containing record. * mp->val = Tag value of variant. * * MK_LABEL: Statement label. * mp->val.i => Case number if used by non-local gotos, else -1. * mp->xnext => MK_VAR representing associated jmp_buf variable. * mp->isreturn = 1 if a TIP "escape" label. * * MK_FUNCTION: Procedure or function. * mp->type => TK_FUNCTION type. * mp->cbase => First meaning in procedure's context (when isfunction is 1, * this will always be the return-value meaning.) * mp->val.i => Body of the function (cast to Stmt *). * mp->constdefn => Expression for definition if FuncMacro, else NULL. * mp->handler => C function to adjust parse tree if predefined, else NULL. * mp->isfunction = 1 if function, 0 if procedure. * mp->isforward = 1 if function has been declared forward. * mp->varstructflag = 1 if function has a varstruct. * mp->needvarstruct = 1 if no varstruct yet but may need one. * mp->namedfile = 1 if function should be declared "inline". * mp->bufferedfile = 1 if function should be declared "virtual". * mp->rectype => Object type for member, NULL for regular function. * mp->xnext => True function object for member field, NULL otherwise. * mp->isreturn = 1 if this is a private member of an object. * mp->fakeparam = 1 if this is a Turbo private member of an object. * mp->val.s => "C" for constructors, "D" for destructors, else NULL. * * MK_SPECIAL: Special, irregular built-in function. * mp->handler => C function to parse and translate the special function. * mp->constdefn => Expression for definition if FuncMacro, else NULL. * mp->isfunction = 1 if function, 0 if procedure. * * MK_PARAM: Procedure or function parameter, or function return value. * mp->type => Type of parameter. * mp->isreturn = 1 if a function return value (not on parameter list). * mp->xnext => Next parameter of function. * mp->fakeparam = 1 if a fake parameter (e.g., conformant array size). * mp->othername => Name of true param if this one is a local copy. * mp->rectype => Type of true param if this one is a local copy. * If a normal copy param, will be "pointer to" mp->type. * If copied for varstruct reasons, will be same as mp->type. * mp->varstructflag = 1 if variable is in parent function's varstruct. * * MK_VARPARAM: VAR parameter, or StructFunction return value. * mp->type => Type "pointer to T" where T is type of parameter. * mp->anyvarflag = 1 if no type checking is to be applied to parameter. * mp->isreturn = 1 if a StructFunction return value (will be first param). * (Others same as for MK_PARAM.) * * MK_VARPARAM with mp->type == tp_anyptr: Turbo "typeless var" parameter. * mp->type = tp_anyptr. * mp->anyvarflag = 1. * (Others same as for MK_PARAM.) * * MK_VARPARAM with mp->type == tp_strptr: HP Pascal "var s:string" parameter. * mp->type = tp_strptr. * mp->anyvarflag = 1 if a separate "strmax" parameter is passed. * (Others same as for MK_PARAM.) * * MK_SYNONYM: Meaning which should be treated as identical to another. * mp->xnext => Actual meaning to be used. * */enum meaningkind { MK_NONE, MK_SPECIAL, MK_MODULE, MK_FUNCTION, MK_CONST, MK_VAR, MK_TYPE, MK_FIELD, MK_LABEL, MK_VARIANT, MK_PARAM, MK_VARPARAM, MK_VARREF, MK_VARMAC, MK_SPVAR, MK_SYNONYM, MK_LAST} ;#ifdef DEFDUMPSchar *meaningkindnames[(int)MK_LAST] = { "MK_NONE", "MK_SPECIAL", "MK_MODULE", "MK_FUNCTION", "MK_CONST", "MK_VAR", "MK_TYPE", "MK_FIELD", "MK_LABEL", "MK_VARIANT", "MK_PARAM", "MK_VARPARAM", "MK_VARREF", "MK_VARMAC", "MK_SPVAR", "MK_SYNONYM"} ;#endif /*DEFDUMPS*/typedef struct S_meaning { struct S_meaning *snext; /* Next meaning for this symbol */ struct S_meaning *cnext; /* Next meaning in this meaning's context */ struct S_meaning *cbase; /* First meaning in this context */ struct S_meaning *ctx; /* Context of this meaning */ struct S_meaning *xnext; /* (above) */ struct S_meaning *dtype; /* Declared type name, if any */ struct S_symbol *sym; /* Symbol of which this is a meaning */ struct S_type *type; /* (above) */ struct S_type *rectype; /* (above) */ struct S_expr *constdefn; /* (above) */ enum meaningkind kind; /* Kind of meaning */ unsigned needvarstruct:1, /* (above) */ varstructflag:1, /* (above) */ wasdeclared:1, /* Declaration has been written for meaning */ istemporary:1, /* Is a temporary variable */ isforward:1, /* (above) */ isfunction:1, /* (above) */ anyvarflag:1, /* (above) */ isactive:1, /* Meaning is currently in scope */ exported:1, /* Meaning is visible outside this module */ warnifused:1, /* WarnNames was 1 when meaning was declared */ dumped:1, /* Has been dumped (for debugging) */ isreturn:1, /* (above) */ fakeparam:1, /* (above) */ namedfile:1, /* (above) */ bufferedfile:1, /* (above) */ volatilequal:1, /* Object has C "volatile" qualifier */ constqual:1, /* Object has C "const" qualifier */ isref:1, /* Is a C++ reference variable */ dummy18:1, dummy19:1, dummy20:1, dummy21:1, dummy22:1, dummy23:1, dummy24:1, dummy25:1, dummy26:1, dummy27:1, dummy28:1, dummy29:1, dummy30:1, dummy31:1; Value val; /* (above) */ int refcount; /* Number of references to meaning in program */ char *name; /* Print name (i.e., C name) of the meaning */ char *othername; /* (above) */ struct S_expr *(*handler)(); /* Custom translator for procedure */ Strlist *comments; /* Comments associated with meaning */} Meaning;/* "Type" notes: * * This struct represents a data type. Types are stored in a strange * cross between Pascal and C semantics. (This usually works out okay.) * * TK_INTEGER: Base integer type. * The following types are TK_INTEGER: * tp_integer, tp_unsigned, tp_int, tp_uint, tp_sint. * All other integer types are represented by subranges. * tp->smin => Minimum value for integer. * tp->smax => Maximum value for integer. * * TK_CHAR: Base character type. * The following types are TK_CHAR: tp_char, tp_schar, tp_uchar. * All other character types are represented by subranges. * tp->smin => Minimum value for character. * tp->smax => Maximum value for character. * * TK_BOOLEAN: Boolean type. * The only TK_BOOLEAN type is tp_boolean. * tp->smin => "False" expression. * tp->smax => "True" expression. * * TK_REAL: Real types. * The only TK_REAL types are tp_real, tp_longreal, and/or the SINGLE type. * * TK_VOID: C "void" type. * The only TK_VOID type is tp_void. * * TK_SUBR: Subrange of ordinal type. * tp->basetype => a TK_INTEGER, TK_CHAR, TK_BOOLEAN, or TK_ENUM type. * tp->smin => Minimum ordinal value for subrange. * tp->smax => Maximum ordinal value for subrange. * * TK_ENUM: Enumerated type. * tp->fbase => First enumeration constant. * tp->smin => Minimum value (zero). * tp->smax => Maximum value (number of choices minus 1). * * TK_POINTER: Pointer type. * tp->basetype => Base type of pointer. * tp->smin => EK_NAME for type if not-yet-resolved forward; else NULL. * tp->fbase => Actual type name for tp->basetype, or NULL. * Only one pointer type is ever generated for a given other type; * each tp->pointertype points back to that type if it has been generated. * * TK_STRING: Pascal string or VARYING OF CHAR type. * tp->basetype => tp_char. * tp->indextype => TK_SUBR from 0 to maximum string length. * tp->structdefd = 1 if type is for a conformant VARYING OF CHAR parameter. * * TK_RECORD: Pascal record/C struct type. * tp->fbase => First field in record. * tp->structdefd = 1 if struct type has been declared in output. * tp->issigned = 1 for Turbo Pascal object types, 0 for plain records. * tp->basetype = Base type of object, NULL for records and base objects. * tp->smin => EK_NAME for tag (used if tagged but tp->meaning == NULL). * * TK_ARRAY with smax == NULL: Normal array type. * tp->basetype => Element type of array. * tp->indextype => Index type (usually a TK_SUBR). * tp->smin => Integer constant if SkipIndices was used, else NULL. * tp->smax = NULL. * tp->structdefd = 1 if type is for a conformant array parameter. * tp->fbase => Actual type name for tp->basetype, or NULL. * * TK_ARRAY with smax != NULL: Large packed array type. * tp->basetype => Element type of C array (tp_ubyte/tp_sbyte/tp_sshort). * tp->indextype => Index type (usually a TK_SUBR). * tp->smin => Integer constant if SkipIndices was used, else NULL. * tp->smax => EK_TYPENAME for element type of Pascal array. * tp->escale = log-base-two of number of bits per packed element, else 0. * tp->issigned = 1 if packed array elements are signed, 0 if unsigned. * tp->structdefd = 1 if type is for a conformant array parameter. * tp->fbase => Actual type name for tp->basetype, or NULL. * * TK_SMALLARRAY: Packed array fitting within a single integer. * (Same as for packed TK_ARRAY.) * * TK_SET: Normal set type. * tp->basetype => tp_integer. * tp->indextype => Element type of the set. * * TK_SMALLSET: Set fitting within a single integer. * (Same as for TK_SET.) * * TK_FILE: File type (corresponds to C "FILE" type). * tp->basetype => Type of file elements, or tp_abyte if UCSD untyped file. * tp->issigned = 1 if RANDOM file. * A Pascal "file" variable is represented as a TK_POINTER to a TK_FILE. * * TK_BIGFILE: File type with attached buffers and name. * tp->basetype => Type of file elements, or tp_abyte if UCSD untyped file. * tp->issigned = 1 if RANDOM file. * A Pascal "file" variable is represented directly as a TK_BIGFILE. * * TK_FUNCTION: Procedure or procedure-pointer type. * tp->basetype => Return type of function, or tp_void if procedure. * tp->issigned = 1 if type has a generic static link. * tp->fbase => First argument (or StructFunction return buffer pointer).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -