| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608 |
- DEFINITION MODULE SymTab;
- (* Symbol table with static type checking for SimpleMod2
- (simplified Modula-2 without procedures).
- - flat scopes with levels: globals at level 0, WITH statement
- bodies push the record's fields as an inner scope (shadowing
- allowed, duplicates within one level rejected)
- - every symbol carries a type descriptor index (InvalidType if
- unknown, e.g. imported names); unknown types suppress follow-on
- errors to avoid cascades
- - type descriptors: aliases (one per TYPE declaration, so
- self-references such as POINTER TO Person resolve), subranges,
- enumerations, arrays, records (with field lists), sets,
- pointers, predefined types, string literals
- - INTEGER, CARDINAL and subranges thereof form one lenient
- "integer family"; mixed INTEGER/REAL arithmetic is rejected *)
- CONST
- InvalidType = -1;
- (* symbol kinds *)
- KindConst = 0;
- KindType = 1;
- KindVar = 2;
- KindImport = 3;
- KindModule = 4;
- KindPredef = 5;
- KindField = 6;
- KindProc = 7;
- KindParam = 8;
- (* type classes returned by ClassOf *)
- ClInvalid = 0;
- ClInt = 1;
- ClReal = 2;
- ClChar = 3;
- ClBool = 4;
- ClEnum = 5;
- ClArray = 6;
- ClRecord = 7;
- ClSet = 8;
- ClPtr = 9;
- ClStr = 10;
- ClClass = 11;
- ClNil = 12;
- ClLong = 13;
- ClProc = 14;
- ClUChar = 15;
- ClUStr = 16;
- (* operator codes for RelCheck *)
- OpEq = 0; OpNeq1 = 1; OpNeq2 = 2;
- OpLt = 3; OpLe = 4; OpGt = 5; OpGe = 6;
- OpIn = 7;
- (* operator codes for AddOp / MulOp *)
- OpAdd = 0; OpSub = 1; OpOr = 2;
- OpTimes = 0; OpSlash = 1; OpDiv = 2; OpMod = 3; OpAnd = 4;
- TYPE
- Name = ARRAY [0 .. 63] OF CHAR;
- TypeIndex = INTEGER;
- BoundsArr = ARRAY [0 .. 7] OF INTEGER;
- (* Per-dimension bounds for array index lists (grammar locals). *)
- (* ---------------- symbols and scopes ---------------- *)
- PROCEDURE Init;
- (* Clears the table and enters predefined identifiers
- (INTEGER, CARDINAL, SHORTINT, LONGINT, SHORTCARD, REAL, LONGREAL,
- CHAR, BOOLEAN, TRUE, FALSE, NIL). *)
- PROCEDURE Enter (name: ARRAY OF CHAR; kind: INTEGER): BOOLEAN;
- (* Enters name at the current scope level (type InvalidType).
- Returns FALSE on duplicate within the same level. *)
- PROCEDURE EnterPending (name: ARRAY OF CHAR; kind: INTEGER): BOOLEAN;
- (* Like Enter, but remembers the entry for a later FixPending call
- (used for VAR identifier lists whose type is parsed afterwards).
- Returns FALSE on duplicate (entry not recorded). *)
- PROCEDURE FixPending (t: TypeIndex) : BOOLEAN;
- (* Assigns type t to all pending entries, clears the buffer, and
- returns TRUE. When the current heading resumed a DEFINITION, the
- just-typed formals are compared against the snapshot (strict 231):
- FALSE = mismatch. *)
- PROCEDURE PendCount (): CARDINAL;
- (* Number of entries currently waiting for FixPending. *)
- PROCEDURE PendName (i: CARDINAL; VAR n: Name);
- (* Name of the i-th pending entry (empty string if out of range).
- Used by the QBE backend to emit storage for VAR lists whose
- type is parsed after the identifiers. *)
- PROCEDURE FieldPending (rec: TypeIndex; name: ARRAY OF CHAR): BOOLEAN;
- (* Records a field name for record descriptor rec (type fixed later
- with FixPendingF). Returns FALSE on duplicate field. *)
- PROCEDURE FixPendingF (rec: TypeIndex; t: TypeIndex);
- (* Assigns type t to pending fields owned by rec. *)
- PROCEDURE Lookup (name: ARRAY OF CHAR): BOOLEAN;
- (* TRUE if name is visible (innermost scope wins). *)
- PROCEDURE SymType (name: ARRAY OF CHAR): TypeIndex;
- (* Type of innermost visible entry, InvalidType if absent. *)
- PROCEDURE SetSymType (name: ARRAY OF CHAR; t: TypeIndex);
- (* Sets type of innermost visible entry. *)
- PROCEDURE SymKind (name: ARRAY OF CHAR): INTEGER;
- (* Kind of innermost visible entry, -1 if absent. *)
- PROCEDURE SetSymVal (name: ARRAY OF CHAR; v: ARRAY OF CHAR);
- (* Stores the literal value text of a CONST for constant folding. *)
- PROCEDURE GetSymVal (name: ARRAY OF CHAR; VAR v: ARRAY OF CHAR): BOOLEAN;
- (* v := stored literal value text of CONST name; FALSE if none. *)
- PROCEDURE Equal (a, b: ARRAY OF CHAR): BOOLEAN;
- PROCEDURE PushScope;
- PROCEDURE PopScope;
- (* WITH statement support: PushRecord pushes a record's fields. *)
- PROCEDURE PushRecord (t: TypeIndex): BOOLEAN;
- (* Pushes a scope containing t's fields (as KindField). FALSE if t
- is not a record type (or invalid). Caller must PopScope after. *)
- PROCEDURE PrintTable;
- (* ---------------- procedures (headings now, bodies step 4) ---------------- *)
- PROCEDURE EnterProc (name: ARRAY OF CHAR): BOOLEAN;
- (* Enters a KindProc heading and pushes its parameter scope.
- FALSE on duplicate (no scope pushed). Resets result to
- InvalidType (proper procedure), clears fwd, empties param chain. *)
- PROCEDURE ResumeProc (name: ARRAY OF CHAR): BOOLEAN;
- (* Resumes a DEFINITION's procedure heading for its
- IMPLEMENTATION body: pushes a fresh body scope, clears the
- formal chain (the implementation re-enters its own). Only valid
- while an IMPLEMENTATION unit is open. *)
- PROCEDURE ReenterProc (name: ARRAY OF CHAR): BOOLEAN;
- (* Resumes a FORWARD-marked procedure of this scope for its body
- heading: clears fwd, pushes a fresh parameter scope. FALSE
- when no such forward heading exists (then 200 applies). *)
- PROCEDURE EnterParam (name: ARRAY OF CHAR; isVar: BOOLEAN): BOOLEAN;
- (* Enters a KindParam in the heading scope and chains it into the
- current procedure's positional param list. FALSE on duplicate. *)
- PROCEDURE SetProcRes (t: TypeIndex) : BOOLEAN;
- (* Sets the current procedure's result type (InvalidType = none) and
- returns TRUE. When the heading resumed a DEFINITION
- (ResumeProc), it also performs the strict-231 signature check
- (result, formal count, formal types, VAR-ness) and returns the
- outcome; FALSE means the implementation does not match. *)
- PROCEDURE ProcRes (name: ARRAY OF CHAR): TypeIndex;
- (* Result type of the named procedure, InvalidType if absent/none. *)
- PROCEDURE MarkFwd;
- (* Marks the current procedure FORWARD (body must follow). *)
- PROCEDURE MarkVirtual;
- (* Marks the current procedure VIRTUAL (dynamically dispatched;
- dispatch tables arrive with class lowering). *)
- PROCEDURE MarkExternal (link: ARRAY OF CHAR);
- (* Marks the current procedure EXTERNAL (no body emitted; calls bind
- to the C symbol `link`, or to the procedure's own name if ''). *)
- PROCEDURE IsExternal (name: ARRAY OF CHAR): BOOLEAN;
- (* TRUE for an EXTERNAL procedure. *)
- PROCEDURE DeclareCProc (name: ARRAY OF CHAR): BOOLEAN;
- (* Enter name as an intrinsic external C procedure (varargs, no
- result): FROM libc IMPORT. *)
- PROCEDURE Varargs (name: ARRAY OF CHAR): BOOLEAN;
- (* TRUE when the named procedure is a C-varargs intrinsic. *)
- PROCEDURE ProcLink (name: ARRAY OF CHAR; VAR link: Name): BOOLEAN;
- (* External-procedure query/link lookup (link name of the named
- visible procedure). *)
- PROCEDURE CloseProc;
- (* Pops the current procedure's scope and its proc-stack entry.
- Replaces bare PopScope at the end of headings (DefUnit),
- FORWARD clauses and bodies. *)
- PROCEDURE InProc (): BOOLEAN;
- (* TRUE inside a procedure heading/body (RETURN legal). *)
- PROCEDURE CurRes (): TypeIndex;
- (* Result type of the innermost open procedure,
- InvalidType outside procedures or for proper procedures. *)
- PROCEDURE ProcDepth (): CARDINAL;
- (* Number of open procedure headings/bodies (nesting depth). *)
- PROCEDURE ProcDepthOf (name: ARRAY OF CHAR): CARDINAL;
- (* Lexical function-nesting depth of the named procedure
- (enclosing procedures; 0 = module level). Drives the static-
- link walk count at call sites. *)
- PROCEDURE ProcUid (name: ARRAY OF CHAR): CARDINAL;
- (* Unique id of the named procedure (0 if absent); drives QBE
- name mangling so same-named methods never collide. *)
- PROCEDURE ProcNPar (name: ARRAY OF CHAR): CARDINAL;
- PROCEDURE ParamType (name: ARRAY OF CHAR; i: CARDINAL): TypeIndex;
- PROCEDURE ParamIsVar (name: ARRAY OF CHAR; i: CARDINAL): BOOLEAN;
- (* Positional formal access for call checking (233 on mismatch). *)
- PROCEDURE VarParamOk (actual, formal: TypeIndex): BOOLEAN;
- (* VAR-formal compatibility: same type, fixed array into open
- array with same element, or string literal into open CHAR. *)
- (* ---------------- modules / separate compilation (step 4.3) ---------------- *)
- (* One compiler session compiles several units into one image:
- DEFINITION, its IMPLEMENTATION, and one program (last). Each
- unit gets its own scope; imports materialize names. *)
- CONST
- UnitProg = 0; UnitDef = 1; UnitImpl = 2;
- PROCEDURE BeginDef (name: ARRAY OF CHAR): BOOLEAN;
- (* Opens a DEFINITION module scope. FALSE on duplicate module. *)
- PROCEDURE BeginImpl (name: ARRAY OF CHAR): BOOLEAN;
- (* Resumes a DEFINITION's scope for its IMPLEMENTATION.
- FALSE when the module is undefined or already implemented. *)
- PROCEDURE BeginProg (name: ARRAY OF CHAR): BOOLEAN;
- (* Opens the program module's scope. *)
- PROCEDURE EndUnit;
- (* Returns to the global scope. *)
- PROCEDURE CurUnit (): INTEGER;
- (* Unit kind currently open (UnitProg/Def/Impl); -1 between units. *)
- PROCEDURE CurModule (VAR name: Name);
- (* Name of the module currently open ('' between units). *)
- PROCEDURE HaveProgram (): BOOLEAN;
- (* TRUE once a program module has been opened (a session without
- one is an error: nothing to link). *)
- PROCEDURE ModKnown (name: ARRAY OF CHAR): BOOLEAN;
- PROCEDURE ModDefined (name: ARRAY OF CHAR): BOOLEAN;
- PROCEDURE ModImplemented (name: ARRAY OF CHAR): BOOLEAN;
- PROCEDURE ImportFrom (mod, name: ARRAY OF CHAR): BOOLEAN;
- (* Materializes an exported name from mod into the current scope
- (FROM mod IMPORT name). FALSE when mod/name is unknown. *)
- PROCEDURE OpaqueBase (name: ARRAY OF CHAR): TypeIndex;
- (* If name is an opaque alias (its target still InvalidType),
- returns that alias descriptor so the implementation can complete
- it via SetTarget; InvalidType otherwise. *)
- PROCEDURE QualFind (mod, name: ARRAY OF CHAR): BOOLEAN;
- (* TRUE when mod exports name. *)
- PROCEDURE QualKind (mod, name: ARRAY OF CHAR): INTEGER;
- PROCEDURE QualType (mod, name: ARRAY OF CHAR): TypeIndex;
- PROCEDURE QualProcUid (mod, name: ARRAY OF CHAR): CARDINAL;
- PROCEDURE QualProcNPar (mod, name: ARRAY OF CHAR): CARDINAL;
- PROCEDURE QualParamType (mod, name: ARRAY OF CHAR; i: CARDINAL): TypeIndex;
- PROCEDURE QualParamIsVar (mod, name: ARRAY OF CHAR; i: CARDINAL): BOOLEAN;
- PROCEDURE QualProcRes (mod, name: ARRAY OF CHAR): TypeIndex;
- PROCEDURE ExportUp (name: ARRAY OF CHAR);
- (* Nested-module END: clones the entry `name` from the just-finished
- nested scope into the enclosing scope, so a local module's EXPORT
- list becomes visible outside it. Must be called before PopScope. *)
- PROCEDURE Materialize (mod, name: ARRAY OF CHAR): BOOLEAN;
- (* FROM-import: clones mod's export into the current scope under
- its plain name. FALSE when mod/name is unknown. *)
- PROCEDURE MaterializeAlias (mod, name: ARRAY OF CHAR;
- VAR alias: Name): BOOLEAN;
- (* Qualified access: clones mod's export under a per-module alias
- key, so same-named exports of different modules never collide.
- The alias key is used for all subsequent lookups (types, uids,
- params); the node remembers its base name and module for QBE
- symbol emission. *)
- PROCEDURE SymBase (name: ARRAY OF CHAR; VAR base: Name): BOOLEAN;
- (* Base symbol name of the visible entry (drops any alias prefix). *)
- PROCEDURE GlobalRef (name: ARRAY OF CHAR; VAR g: Name): BOOLEAN;
- (* "<mod>_<sym>" QBE global-symbol name for a module-level entry;
- FALSE when name is not a module-level symbol. *)
- (* ---------------- classes (Clarion form, lowering deferred) ---------------- *)
- PROCEDURE EnterThisParam (cls: TypeIndex): BOOLEAN;
- (* Enters a method's hidden THIS VAR parameter. *)
- PROCEDURE LayoutClass (t: TypeIndex);
- (* Computes a class's field offsets / size. *)
- PROCEDURE ParentOf (t: TypeIndex): TypeIndex;
- (* The single parent class of t (InvalidType when none). *)
- PROCEDURE SetParent (t, p: TypeIndex);
- (* Records p as the (single) parent class of t. Multiple parents
- are rejected in the grammar with 230. *)
- PROCEDURE PushClassScope (t: TypeIndex);
- (* Pushes the body scope of class t and records it on t. *)
- PROCEDURE MethodExists (t: TypeIndex; name: ARRAY OF CHAR): BOOLEAN;
- (* TRUE if the class scope of t declares name as a procedure. *)
- PROCEDURE ResumeMethod (ct: TypeIndex; name: ARRAY OF CHAR): BOOLEAN;
- (* Resumes a declared class method for its CLASS IMPLEMENTATION body. *)
- PROCEDURE HasVTable (ct: TypeIndex): BOOLEAN;
- (* TRUE when the class (or an ancestor) has virtual methods. *)
- PROCEDURE VirtSlot (ct: TypeIndex; name: ARRAY OF CHAR): INTEGER;
- (* Vtable slot of the method, or -1 when it is not virtual. *)
- PROCEDURE IsSubclass (sub, sup: TypeIndex): BOOLEAN;
- (* TRUE when sub is sup or inherits (transitively) from sup. *)
- PROCEDURE VptrOffset (ct: TypeIndex): INTEGER;
- (* Byte offset of the class's vptr field (-1 when it has none). *)
- PROCEDURE PushImplClass (ct: TypeIndex);
- PROCEDURE PopImplClass;
- PROCEDURE CurImplClass (): TypeIndex;
- (* The innermost open CLASS IMPLEMENTATION's class (InvalidType none). *)
- PROCEDURE VtClassCount (): CARDINAL;
- PROCEDURE VtClassAt (k: CARDINAL): TypeIndex;
- (* Classes that have a vtable, in build order. *)
- PROCEDURE VtCount (ct: TypeIndex): CARDINAL;
- PROCEDURE VtName (ct: TypeIndex; k: CARDINAL; VAR name: Name): BOOLEAN;
- PROCEDURE VtHasBody (ct: TypeIndex; k: CARDINAL): BOOLEAN;
- (* TRUE when slot k's method has an emitted body. *)
- PROCEDURE VtUid (ct: TypeIndex; k: CARDINAL): CARDINAL;
- (* Virtual-method slot k of ct (inherited slots first). *)
- PROCEDURE MethUid (): CARDINAL;
- (* uid of the procedure currently being headed (0 when none). *)
- PROCEDURE ClassMethodUid (t: TypeIndex; name: ARRAY OF CHAR): CARDINAL;
- (* Unique id of method name in class t or an ancestor (0 if none). *)
- PROCEDURE ClassMethodNPar (t: TypeIndex; name: ARRAY OF CHAR): CARDINAL;
- (* User formal count of the method (the hidden THIS excluded). *)
- PROCEDURE ClassMethodRes (t: TypeIndex; name: ARRAY OF CHAR): TypeIndex;
- (* Result type of the method (InvalidType if none/absent). *)
- PROCEDURE ClassMethodParamType (t: TypeIndex; name: ARRAY OF CHAR;
- i: CARDINAL): TypeIndex;
- PROCEDURE ClassMethodParamIsVar (t: TypeIndex; name: ARRAY OF CHAR;
- i: CARDINAL): BOOLEAN;
- (* User formal i of the method (index 0 skips the hidden THIS). *)
- PROCEDURE PushClassMembers (t: TypeIndex): BOOLEAN;
- (* Pushes a scope with t's fields (KindField) for method bodies in
- CLASS IMPLEMENTATION. FALSE if t is not a class. Method names
- are re-entered fresh by each body (copying them would collide);
- sibling-method references report 201 until step 4 calls. *)
- (* ---------------- type descriptors ---------------- *)
- PROCEDURE NewAlias (): TypeIndex;
- PROCEDURE NewSub (base: TypeIndex): TypeIndex;
- PROCEDURE NewSubR (lo, hi: INTEGER): TypeIndex;
- (* Integer subrange [lo..hi] (no base descriptor needed). Bounds
- accessors arrive with step 3; the backend cannot lower them yet. *)
- PROCEDURE NewEnum (): TypeIndex;
- PROCEDURE NewArrayB (elem: TypeIndex; lo, hi: INTEGER): TypeIndex;
- (* Bounded array (one dimension; nest for multi-dim). InvalidType
- when the table is full. *)
- PROCEDURE NewOpenArray (elem: TypeIndex): TypeIndex;
- (* Open ARRAY OF formal: 0-based, runtime count in the header.
- Only legal for formal parameters (grammar enforces). *)
- PROCEDURE BoundBegin;
- PROCEDURE BoundAdd (lo, hi: INTEGER): BOOLEAN;
- (* Accumulates one index bound pair for the enclosing ArrayType
- (max 8 dimensions, FALSE past that). *)
- PROCEDURE BoundCount (): CARDINAL;
- PROCEDURE BoundLo (i: CARDINAL): INTEGER;
- PROCEDURE BoundHi (i: CARDINAL): INTEGER;
- (* Read back the accumulated bounds (so a caller can snapshot them
- before parsing a nested element type that reuses the buffer). *)
- PROCEDURE NestArray (elem: TypeIndex): TypeIndex;
- (* Nests the accumulated bounds inside-out around elem. *)
- PROCEDURE NewRecord (): TypeIndex;
- PROCEDURE IsOrdinal (t: TypeIndex): BOOLEAN;
- (* integer family / CHAR / UCHAR / BOOLEAN / enumeration. *)
- PROCEDURE ResetFields (rec: TypeIndex);
- (* Starts a fresh variant branch (drops pending fields, clears layout). *)
- PROCEDURE SetVariantTag (rec: TypeIndex; name : ARRAY OF CHAR);
- (* Records the variant CASE selector field (by name). *)
- PROCEDURE MarkVariant (rec: TypeIndex);
- (* Marks rec as having a variant part (overlapping fields). *)
- PROCEDURE IsVariant (rec: TypeIndex): BOOLEAN;
- (* TRUE when rec has a variant part. *)
- PROCEDURE NewSet (base: TypeIndex): TypeIndex;
- PROCEDURE NewPtr (base: TypeIndex): TypeIndex;
- PROCEDURE NewStr (): TypeIndex;
- PROCEDURE NewUStr (): TypeIndex;
- (* UString literal type: LONGCARD count + count x UCHAR codepoints. *)
- PROCEDURE NewClass (): TypeIndex;
- (* Fresh class descriptor (holds fields like a record; methods live
- in the class scope). Parent and scope via SetParent/PushClassScope. *)
- (* Fresh descriptors; base/elem may be InvalidType. InvalidType is
- returned when the table is full. *)
- PROCEDURE SetTarget (t, base: TypeIndex);
- (* Sets an alias target (TYPE declaration completion). *)
- PROCEDURE BeginTypeBlock;
- PROCEDURE EndTypeBlock;
- (* Delimit a TYPE block so ForwardType is only active inside one. *)
- PROCEDURE ForwardType (name: ARRAY OF CHAR): TypeIndex;
- (* Inside a TYPE block: if name is not yet declared, enters it as an
- unresolved forward alias and returns its type index (completed by
- the later TypeItem via SetTarget). InvalidType when the name is
- already known or forward references are not permitted. *)
- PROCEDURE IsUnresolved (t: TypeIndex): BOOLEAN;
- (* TRUE for a forward placeholder whose target is not yet declared. *)
- PROCEDURE FwdPending (): CARDINAL;
- PROCEDURE FwdInfo (i: CARDINAL; VAR name: Name; VAR unresolved: BOOLEAN);
- (* Module-level forward type references: enumerate them at module end
- and flag those never completed (undeclared type). *)
- PROCEDURE FwdClear;
- PROCEDURE FwdVarRef (name: ARRAY OF CHAR; kind: INTEGER;
- VAR id: INTEGER; VAR t: TypeIndex): BOOLEAN;
- (* Registers a reference to a module-level name used inside a procedure
- body before its declaration (forward variable). kind is KindVar
- (variable) or KindProc (procedure); id/t identify the placeholder. *)
- PROCEDURE FwdVarType (id: INTEGER): TypeIndex;
- PROCEDURE FwdVarKind (id: INTEGER): INTEGER;
- PROCEDURE IsFwdVar (t: TypeIndex): BOOLEAN;
- (* TRUE for a forward-variable placeholder: type checks are lenient. *)
- PROCEDURE FwdVarName (id: INTEGER; VAR name: Name);
- (* The identifier behind forward reference id (1-based). *)
- PROCEDURE FwdVarResolve (id: INTEGER): BOOLEAN;
- (* Resolves forward reference id against the module's declarations:
- TRUE when the name now exists with the expected kind. *)
- PROCEDURE IntType (): TypeIndex;
- PROCEDURE UCharType (): TypeIndex;
- (* UCHAR: 32-bit Unicode codepoint (QBE w). *)
- PROCEDURE RealType (): TypeIndex;
- PROCEDURE CharType (): TypeIndex;
- PROCEDURE BoolType (): TypeIndex;
- PROCEDURE LongType (): TypeIndex;
- (* LONGINT/LONGCARD: 64-bit integer (QBE l). *)
- PROCEDURE AddrType (): TypeIndex;
- (* ADDRESS: the pointer-sized opaque type (interchangeable with any
- pointer for assignment and VAR parameters). *)
- PROCEDURE ObjectSize (t: TypeIndex): CARDINAL;
- (* Full allocation footprint (arrays 8 + count*element); drives
- SYSTEM.SIZE/TSIZE. *)
- PROCEDURE ClassOf (t: TypeIndex): INTEGER;
- (* Resolves aliases; InvalidType maps to ClInvalid. *)
- PROCEDURE IsIntFamily (t: TypeIndex): BOOLEAN;
- (* INTEGER, CARDINAL or subrange thereof (Invalid suppresses). *)
- PROCEDURE IsLongFamily (t: TypeIndex): BOOLEAN;
- (* LONGINT/LONGCARD (QBE l). *)
- PROCEDURE SameType (a, b: TypeIndex): BOOLEAN;
- (* Same resolved descriptor (Invalid suppresses). *)
- PROCEDURE FieldExists (rec: TypeIndex; name: ARRAY OF CHAR): BOOLEAN;
- PROCEDURE FieldType (rec: TypeIndex; name: ARRAY OF CHAR): TypeIndex;
- PROCEDURE ArrayElem (t: TypeIndex): TypeIndex;
- PROCEDURE IsCharArray (t: TypeIndex): BOOLEAN;
- (* TRUE for arrays whose elements are CHAR: such arrays reserve one
- extra zero byte (index = count) so NUL-scanning works, matching
- gm2's NUL-terminated strings. *)
- PROCEDURE IsOpenArray (t: TypeIndex): BOOLEAN;
- PROCEDURE ArrayLo (t: TypeIndex): INTEGER;
- PROCEDURE ArrayHi (t: TypeIndex): INTEGER;
- (* Static bounds (open arrays: lo 0, hi undefined — backend reads
- the header instead). InvalidType maps to 0. *)
- PROCEDURE ArrayLen (t: TypeIndex): CARDINAL;
- (* Static element count, 0 for open/invalid. *)
- PROCEDURE ArrayDepth (t: TypeIndex): CARDINAL;
- (* Nesting depth (open/fixed levels); 0 for non-arrays. *)
- PROCEDURE TypeSize (t: TypeIndex): CARDINAL;
- (* Inline footprint in bytes: scalars 4/8, sets words*4, pointers,
- open and fixed arrays 8 (descriptor address), records sum of
- members. *)
- PROCEDURE FieldOffset (rec: TypeIndex; name: ARRAY OF CHAR): INTEGER;
- (* Declaration-order byte offset (-1 if absent). Computed lazily. *)
- PROCEDURE FieldOwner (name: ARRAY OF CHAR): TypeIndex;
- (* Owning record/class of the visible field (InvalidType if none). *)
- PROCEDURE FieldCount (rec: TypeIndex): CARDINAL;
- PROCEDURE FieldName (rec: TypeIndex; i: CARDINAL; VAR name: Name);
- (* Field enumeration for whole-record lowering (order irrelevant). *)
- PROCEDURE SubBounds (t: TypeIndex; VAR lo, hi: INTEGER): BOOLEAN;
- (* TRUE with the bounds when t resolves to a subrange. *)
- PROCEDURE SetBase (t: TypeIndex): TypeIndex;
- (* Base type of a set descriptor (InvalidType if none). *)
- PROCEDURE SetWords (t: TypeIndex): CARDINAL;
- (* Mask words for a set type from its base span (bool 1, char 8,
- subrange by bounds); 0 when the base is unsuitable. *)
- PROCEDURE SetBaseLo (t: TypeIndex): INTEGER;
- (* Base minimum (bool/char 0, subrange lo); 0 when unsuitable. *)
- PROCEDURE SetCount (t: TypeIndex): CARDINAL;
- (* Base span in values (0 when unsuitable). *)
- PROCEDURE TypeBounds (t: TypeIndex; VAR lo, hi: INTEGER): BOOLEAN;
- (* Ordinal bounds of a type (MIN/MAX): subrange/array, CHAR/UCHAR,
- BOOLEAN, enumeration, set base, or the integer family. *)
- PROCEDURE SetEnumCount (t: TypeIndex; n: CARDINAL);
- (* Records the number of literals of an enumeration type. *)
- PROCEDURE EnumCount (t: TypeIndex): CARDINAL;
- (* Literal count of an enumeration type (0 when not an enum). *)
- PROCEDURE PtrBase (t: TypeIndex): TypeIndex;
- (* ---------------- procedure types (step 8.5) ---------------- *)
- (* PROCEDURE (params): result as a value type. Values are code
- pointers (pointer-sized); calls through them are indirect. Param
- lists are collected with ProcTypeBegin/ProcTypeAdd and finalised
- by NewProcType (same pattern as array bounds). *)
- PROCEDURE NewProcType (res: TypeIndex): TypeIndex;
- (* Fresh procedure type (result may be InvalidType, set later). Its
- parameters are appended in order with ProcTypeAdd. *)
- PROCEDURE ProcTypeAdd (t: TypeIndex; isVar: BOOLEAN; pt: TypeIndex);
- PROCEDURE SetProcTypeRes (t: TypeIndex; res: TypeIndex);
- PROCEDURE ProcTypeNPar (t: TypeIndex): CARDINAL;
- PROCEDURE ProcTypeParamType (t: TypeIndex; i: CARDINAL): TypeIndex;
- PROCEDURE ProcTypeParamIsVar (t: TypeIndex; i: CARDINAL): BOOLEAN;
- PROCEDURE ProcTypeRes (t: TypeIndex): TypeIndex;
- (* Accessors for a procedure type (0/InvalidType when not one). *)
- PROCEDURE ProcTypeOf (name: ARRAY OF CHAR): TypeIndex;
- (* Builds the procedure type descriptor for procedure name (for using
- a procedure as a value). InvalidType if name is not a procedure. *)
- (* ---------------- predicates used by grammar checks ---------------- *)
- (* All return TRUE if either operand is InvalidType (no cascades). *)
- PROCEDURE Assignable (src, dst: TypeIndex): BOOLEAN;
- (* Assignment compatibility (210). *)
- PROCEDURE ArithCheck (l, r: TypeIndex; divmod: BOOLEAN;
- VAR res: TypeIndex): BOOLEAN;
- (* + - * / (divmod FALSE) or DIV MOD (TRUE); res is result type (211). *)
- PROCEDURE UnaryCheck (t: TypeIndex; VAR res: TypeIndex): BOOLEAN;
- (* Unary + - (part of 211). *)
- PROCEDURE BoolCheck (t: TypeIndex): BOOLEAN;
- (* BOOLEAN required: NOT/AND/OR operands (212), conditions (214). *)
- PROCEDURE RelCheck (l, r: TypeIndex; op: INTEGER): BOOLEAN;
- (* = # <> < <= > >= IN (213/222 chosen by caller via op). *)
- PROCEDURE IsStrType (t: TypeIndex): BOOLEAN;
- (* A string literal (ClStr) or a 1-D ARRAY OF CHAR. *)
- PROCEDURE UStrCompat (l, r: TypeIndex): BOOLEAN;
- (* Both operands are UString literals (U"..."): `+` concatenates. *)
- PROCEDURE IsUCharArray (t: TypeIndex): BOOLEAN;
- (* A 1-D ARRAY OF UCHAR (a U"..." content-copy destination). *)
- PROCEDURE StrCompat (l, r: TypeIndex): BOOLEAN;
- (* Both operands are string-compatible (ClStr / 1-D ARRAY OF CHAR):
- `=`/`#` compare content via the shim. *)
- PROCEDURE EqCheck (l, r: TypeIndex): BOOLEAN;
- (* = # compatibility, also reused for CASE label matching. *)
- PROCEDURE InCheck (l, set: TypeIndex): BOOLEAN;
- (* Membership `l IN set`. *)
- PROCEDURE SetElemClassOk (c: INTEGER): BOOLEAN;
- (* TRUE for an element class acceptable in a set constructor. *)
- PROCEDURE SetElemCheck (first, elem: TypeIndex): BOOLEAN;
- PROCEDURE SetFor (elem: TypeIndex): TypeIndex;
- (* Fresh SET OF elem descriptor for set literals. *)
- PROCEDURE StrLen (s: ARRAY OF CHAR): CARDINAL;
- PROCEDURE ConstInt (q: ARRAY OF CHAR; VAR v: INTEGER): BOOLEAN;
- (* Parses a folded integer immediate ("42", "-5", "16") as produced
- by NormInt/NegFold. FALSE for temporaries and non-numerics. *)
- END SymTab.
|