
    <<P3.mesa>>
        <<Copyright © 1985 by Xerox Corporation.  All rights reserved.>>
        <<Satterthwaite, June 17, 1986 2:44:31 pm PDT>>
        <<Paul Rovner, September 7, 1983 4:09 pm>>
        <<Russ Atkinson (RRA) March 6, 1985 10:14:58 pm PST>>

    DIRECTORY
        Alloc: TYPE USING [Notifier],
        Copier: TYPE USING [SEToken],
        PrincOpsUtils: TYPE USING [BITAND],
        Symbols: TYPE USING [HTIndex, Type, ISEIndex, CSEIndex, RecordSEIndex, RefSEIndex, CTXIndex, IncludedCTXIndex, MDIndex, BTIndex, 
        Closure],
        Tree: TYPE USING [Index, Link, Map, Scan];

    P3: DEFINITIONS IMPORTS PrincOpsUtils = {
        OPEN Symbols;

        mark: BOOL = TRUE; -- mark in tree as set by pass 3

    <<text literals>>

        TextForm: TYPE = {text, rope, ropeText};

    <<attributes>>

        Attr: TYPE = RECORD[
            noAssign: BOOL,
            noXfer: BOOL,
            const: BOOL];

        emptyAttr: Attr = [noAssign:FALSE, noXfer:FALSE, const:FALSE];
        fullAttr: Attr = [noAssign:TRUE, noXfer:TRUE, const:TRUE];
        voidAttr: Attr = [noAssign:TRUE, noXfer:TRUE, const:FALSE];

        And: PROC[Attr, Attr] RETURNS[Attr] = LOOPHOLE[PrincOpsUtils.BITAND];

    <<safety (Cedar)>>

        Safety: TYPE = {none, asserted, checked};

    <<narrowing operations>>

        NarrowOp: TYPE = RECORD[
            error, indirect, rtTest, tagTest, computed, unImpl: BOOL_FALSE];


    <<parameter use bookkeeping (for subst by name)>>

        NPUse: TYPE = {none, ref, set, refset, unsafe};    -- (name) param use
        NPMap: TYPE = ARRAY NPUse OF ARRAY NPUse OF NPUse;

        SetNP: ARRAY NPUse OF NPUse = [set, refset, set, refset, unsafe];

        MergeNP: NPMap =
            [[  none,    ref,    set, refset, unsafe],
                [   ref,    ref, unsafe, unsafe, unsafe],
                [   set, unsafe,    set, unsafe, unsafe],
                [refset, unsafe, unsafe, unsafe, unsafe],
                [unsafe, unsafe, unsafe, unsafe, unsafe]];

        SequenceNP: NPMap =
            [[  none,    ref,    set, refset, unsafe],
                [   ref,    ref, refset, refset, unsafe],
                [   set, unsafe,    set, unsafe, unsafe],
                [refset, unsafe, refset, unsafe, unsafe],
                [unsafe, unsafe, unsafe, unsafe, unsafe]];

        BoundNP: NPMap =
            [[  none,    ref,    set, refset, unsafe],
                [   ref,    ref, unsafe, refset, unsafe],
                [   set, unsafe,    set, refset, unsafe],
                [refset, refset, refset, refset, unsafe],
                [unsafe, unsafe, unsafe, unsafe, unsafe]];


    <<notifiers>>

        DeclNotify, MiscNotify, StmtNotify, VRNotify: Alloc.Notifier;
        ExpANotify, ExpBNotify, ExpCNotify: Alloc.Notifier;

    <<exported by Pass3B>>

        Header: PROC[node: Tree.Index];
        SetDefaultImport: PROC[iCtx: IncludedCTXIndex, implicitOK: BOOL_FALSE];

    <<exported by Pass3D>>

        DeclList: Tree.Scan;
        FirstId: PROC[Tree.Index] RETURNS[ISEIndex];
        InitialExp: PROC[Tree.Link, Type] RETURNS[v: Tree.Link, extended: BOOL];
        MakeLongType: PROC[Type, Type] RETURNS[Type];
        MakeRefType: PROC[cType, hint: Type, readOnly, counted, var: BOOL_FALSE]
            RETURNS[RefSEIndex];
        ResolveType: PROC[ISEIndex];
        ResolveValue: PROC[ISEIndex];
        TypeAppl: Tree.Map;
        TypeExp: Tree.Map;

    <<exported by Pass3I>>

        IdInit: PROC;
        IdReset: Tree.Scan;

        ArrangeKeys: PROC[
            expList: Tree.Link,
            nextKey: PROC RETURNS[HTIndex],
            omittedValue: PROC RETURNS[Tree.Link]]
            RETURNS[CARDINAL];
        BaseTree: PROC[Tree.Link, Type] RETURNS[Tree.Link];
        BindTree: PROC[Tree.Link, PROC[ISEIndex] RETURNS[Tree.Link]] RETURNS[Tree.Link];
        BumpCount: PROC[ISEIndex];
        CheckDisjoint: PROC[ctx1, ctx2: CTXIndex];
        ClearRefStack: PROC;
        CloseBase: PROC[Tree.Link, HTIndex];
        ClusterId: PROC[HTIndex, CTXIndex] RETURNS[found: BOOL, sei: ISEIndex];
        CompleteRecord: PROC[rSei: RecordSEIndex, depth: Closure_$unit];
        CopyTree: Tree.Map;
        EnterIdList: PROC[IncludedCTXIndex, Tree.Link];
        EnterComposite: PROC[type: Type, t: Tree.Link, init: BOOL];
        EnterType: PROC[type: Type, canonical: BOOL_TRUE];
        FieldId: PROC[HTIndex, RecordSEIndex] RETURNS[NAT, ISEIndex];
        FindSe: PROC[HTIndex] RETURNS[symbol: ISEIndex, base: Tree.Link, indirect: BOOL];
        Id: PROC[HTIndex] RETURNS[Tree.Link];
        InterfaceId: PROC[HTIndex, CTXIndex] RETURNS[found: BOOL, sei: ISEIndex];
        MainIncludedCtx: PROC[MDIndex] RETURNS[IncludedCTXIndex];
        MakeIdTable: PROC[CARDINAL];
        OpenBase: PROC[Tree.Link, HTIndex] RETURNS[Tree.Link];
        OpenPointer: PROC[Tree.Link, Type] RETURNS[Tree.Link, CSEIndex];
        PopCtx: PROC;
        PushCtx: PROC[CTXIndex];
        PushHtCtx: PROC[HTIndex, Tree.Link, BOOL];
        PushRecordCtx: PROC[RecordSEIndex, Tree.Link, BOOL]; 
        RecordLhs: PROC[ISEIndex];
        RecordMention: PROC[ISEIndex];
        SealRefStack: PROC;
        SearchCtxList: PROC[HTIndex, CTXIndex] RETURNS[found: BOOL, sei: ISEIndex];
        Shared: PROC[CTXIndex] RETURNS[BOOL];
        TopCtx: PROC RETURNS[CTXIndex];
        UnsealRefStack: PROC;
        UpdateTreeAttr: PROC[Tree.Link] RETURNS[attr: Attr];

    <<exported by Pass3M>>

        CatchPhrase: PROC[Tree.Link] RETURNS[unwindCaught: BOOL];
        Cons: PROC[Tree.Index, Type] RETURNS[Tree.Link];
        CopyLock: PROC RETURNS[Tree.Link];
        FindLockParams: PROC RETURNS[formal, actual: ISEIndex];
        ItemType: PROC[Type] RETURNS[Type];
        ListCons: PROC[Tree.Index, Type];
        LockVar: PROC[Tree.Link] RETURNS[Tree.Link];
        MakeFrameRecord: PROC[Tree.Link] RETURNS[CSEIndex];
        MiscStmt: PROC[Tree.Index] RETURNS[Tree.Link];
        MiscXfer: PROC[Tree.Index, Type] RETURNS[Tree.Link];
        New: PROC[Tree.Index, Type];
        TextRep: PROC[Type] RETURNS[TextForm];
        XferForFrame: PROC[CTXIndex] RETURNS[CSEIndex];

        InsertCatchLabel: SIGNAL [catchSeen, exit: BOOL];

    <<exported by Pass3S>>

        pathNP: VAR NPUse;

        BodyList: PROC[firstBti: BTIndex];
        BumpArgRefs: PROC[record: RecordSEIndex, write: BOOL];
        Case: PROC[Tree.Index, Tree.Map];
        CheckLocals: PROC[Tree.Link] RETURNS[localsOnly: BOOL];
        SafetyAttr: PROC[Tree.Index] RETURNS[Safety];
        SetSafety: PROC[Safety];
        Scope: PROC[Tree.Index, Tree.Map];
        Stmt: Tree.Map;

    <<exported by Pass3V>>

        DiscriminatedType: PROC[CSEIndex, Tree.Link] RETURNS[CSEIndex];
        Discrimination: PROC[Tree.Index, Tree.Map];
        Narrowing: PROC[type, target: Type] RETURNS[NarrowOp];
        SelectVariantType: PROC[Type, HTIndex] RETURNS[ISEIndex];
        SequenceField: PROC[RecordSEIndex] RETURNS[ISEIndex];
        VariantUnionType: PROC[Type] RETURNS[CSEIndex];

    <<exported by Pass3Xa>>

        phraseNP: VAR NPUse;

        All: PROC[node: Tree.Index, target: Type, init: BOOL_FALSE];
        Apply: PROC[Tree.Index, Type, BOOL] RETURNS[Tree.Index];
        Assignment: PROC[Tree.Index];
        CheckLength: PROC[Tree.Link, INTEGER];
        CheckScope: PROC[Tree.Link, Type] RETURNS[Tree.Link];
        Dot: PROC[Tree.Index, Type] RETURNS[Tree.Index];
        Extract: PROC[Tree.Index];
        FieldDefault: PROC[ISEIndex] RETURNS[Tree.Link];
        FieldVoid: PROC[Tree.Link] RETURNS[Tree.Link];
        Initialization: PROC[Tree.Link, Type] RETURNS[Tree.Link];
        InterfaceCtx: PROC[CSEIndex, Tree.Link] RETURNS[CTXIndex];
        KeyedList: PROC[Tree.Link] RETURNS[BOOL];
        MatchFields: PROC[
            record: RecordSEIndex, expList: Tree.Link,
            init: BOOL_FALSE, scopeCheck: BOOL_TRUE]
            RETURNS[Tree.Link];
        VoidComponent: PROC[Type];

    <<exported by Pass3Xb>>

        ExpInit: PROC;
        ExpReset: PROC;

        Exp: PROC[Tree.Link, Type] RETURNS[Tree.Link];
        Interval: PROC[Tree.Link, Type, BOOL];
        ForceType: PROC[Tree.Link, Type] RETURNS[Tree.Link];
        RAttr: PROC RETURNS[Attr];
        Rhs: PROC[Tree.Link, Type] RETURNS[Tree.Link];
        RPop: PROC;
        RPush: PROC[Type, Attr];
        RType: PROC RETURNS[Type];
        SetType: PROC[Type];
        UType: PROC RETURNS[CSEIndex];
        VoidExp: Tree.Map;

    <<exported by Pass3Xc>>

        AddrOp: PROC[Tree.Index, Type];
        Range: PROC[Tree.Link, Type] RETURNS[Tree.Link];
        Span: PROC[CSEIndex] RETURNS[first, last: Copier.SEToken];

        }.

