<> <> <> <> <> <<>> DIRECTORY Convert USING [ RopeFromCard, RopeFromInt ], IO USING [ card, int, rope, PutF, PutFR, STREAM ], PriorityQueue USING [ Insert ], Rope USING [ ROPE, Cat, Equal ], SiroccoATDef USING [ ConstantNode, TypeNode ], SiroccoBaseDef USING [ CreateTables ], SiroccoCGDef USING [ Generic ], SiroccoPrivate USING [ AquireState, CComponent, CType, EndItAll, Handle, MakeUpName, PQItem, TABLES, UnresolvedConstantTableEntry ], SymTab USING [ Delete, Erase, GetSize, Insert ], ThreeC4Support USING [ GetReportStream, GetSourceInfo ]; SiroccoBase2Impl: CEDAR PROGRAM IMPORTS SiroccoBaseDef, Convert, IO, PriorityQueue, Rope, SiroccoPrivate, SymTab, ThreeC4Support EXPORTS SiroccoBaseDef ~ { OPEN SiroccoPrivate; ROPE: TYPE ~ Rope.ROPE; <> <> <> < {>> <> <> <<[info.constant, tables1] _ const.procs.ConstantToRope[info.value, info.type, tables];>> <<};>> <> <<};>> < {>> <> <<};>> <<};>> <<>> <> <> <> <> <<};>> <> <> < {>> <> < {>> <> <> <> <<};>> < { [] _ SendError["Compiler Error"]; };>> <<};>> < { NULL }; -- fall thru>> <> < {>> <> <> <> <> <<[cannonicalType, typeTree, t1] _ typeNode.procs.CanonicalType[typeNode, t1];>> <> <> <> <> <> <> <<}>> <> <<}>> < {>> <<[] _ SendError["Undeclared Identifier"];>> <<};>> <<};>> << >> CheckIfEmpty: PUBLIC PROC [tables: TABLES] RETURNS [empty: BOOLEAN] ~ { empty _ TRUE; IF ( SymTab.GetSize[tables.workTable] # 0 ) THEN [] _ SendError["Missing Enumeration in Choice"]; }; ClearWorkTable: PUBLIC PROC [tables: TABLES] RETURNS [new: TABLES] ~ { SymTab.Erase[tables.workTable]; new _ tables; }; CompareClass: PUBLIC PROC [first: CType, second: SiroccoCGDef.Generic] RETURNS [comp: CComponent] ~ { IF ( first.class # second ) THEN [] _ SendError["Type Mismatch"]; comp _ first.children; }; EnterNamesIntoWorkTable: PUBLIC PROC [ctype: CType, tables: TABLES] RETURNS [new: TABLES] ~ { SymTab.Erase[tables.workTable]; FOR list: CComponent _ ctype.children, list.sibling WHILE ( list # NIL ) DO IF ( NOT SymTab.Insert[tables.workTable, list.name, ""] ) THEN ERROR; ENDLOOP; new _ tables; }; FillWorkTable: PUBLIC PROC [type: CType, tables: TABLES] RETURNS [new: TABLES] ~ { length: INT _ -1; SymTab.Erase[tables.workTable]; FOR list: CComponent _ type.children, list.sibling WHILE ( list # NIL ) DO IF ( NOT SymTab.Insert[tables.workTable, list.name, ""] ) THEN ERROR; IF ( NOT SymTab.Insert[tables.workTable, Convert.RopeFromInt[list.val], ""] ) THEN ERROR; length _ length.SUCC; ENDLOOP; WHILE ( length >= 0 ) DO IF ( NOT SymTab.Delete[tables.workTable, Convert.RopeFromInt[length]] ) THEN [] _ SendError["Enumeration not Continuous, hence cannot be used as tag for Choice"]; length _ length.PRED; ENDLOOP; new _ tables; }; <> <> <> <> <<};>> <> <> < { -- Already resolved>> <> < {>> <> <> <> <> <<};>> < {>> <<[] _ SendError["Compiler Error"];>> <<};>> <<}>> < { -- Unresolved>> <> < {>> <> <> <> <> <> <> <> <> <> <<[cannonicalType, typeTree, t1] _ tNode.procs.CanonicalType[value.type, t1];>> <> <> <> <> <> <> <<[info.constant, t1] _ cNode.procs.ConstantToRope[value.constant, cannonicalType, t1];>> <> <> <> <> <<}>> <> <<[] _ SendError["Cyclic Dependancy"]>> <<};>> <<}>> <> <<}>> < {>> <<[] _ SendError["Undeclared Identifier"];>> <<};>> <<};>> <<};>> <<>> GetCTypeFirstChild: PUBLIC PROC [first: CType] RETURNS [comp: CComponent] ~ { comp _ first.children; }; <> <> <> <> <<[cannonicalType, type, constant, t] _ GetConstantType[id, t];>> <> <> <<};>> <<>> BuildTypeDAG: PUBLIC PROC [key: ROPE, index: INT, node: SiroccoATDef.TypeNode] RETURNS [new: TABLES] ~ { guy: REF PQItem ~ NEW [PQItem _ [index, key]]; new _ SiroccoBaseDef.CreateTables[]; IF ( NOT SymTab.Insert[new.unresolvedTypeTable, key, node] ) THEN [] _ SendError["Redeclared Identifier"]; PriorityQueue.Insert[new.index, guy]; }; BuildConstantDAG: PUBLIC PROC [key: ROPE, index: INT, type: SiroccoATDef.TypeNode, constant: SiroccoATDef.ConstantNode] RETURNS [new: TABLES] ~ { guy: REF PQItem ~ NEW [PQItem _ [index, key]]; value: REF UnresolvedConstantTableEntry ~ NEW[UnresolvedConstantTableEntry]; new _ SiroccoBaseDef.CreateTables[]; value.type _ type; value.constant _ constant; IF ( NOT SymTab.Insert[new.unresolvedConstantTable, key, value] ) THEN [] _ SendError["Redeclared Identifier"]; PriorityQueue.Insert[new.index, guy]; }; IsEnumerationConstant: PUBLIC PROC [type: CType, id: ROPE] RETURNS [INT _ 0] ~ { FOR tail: CComponent _ type.children, tail.sibling WHILE ( tail # NIL ) DO IF ( Rope.Equal[tail.name, id] ) THEN RETURN; ENDLOOP; [] _ SendError["Undeclared Enumeration"]; }; Remove: PUBLIC PROC [id: ROPE, tables: TABLES] RETURNS [new: TABLES] ~ { IF ( NOT SymTab.Delete[tables.workTable, id] ) THEN [] _ SendError["Undeclared or Redeclared Identifier"]; new _ tables; }; SeeIfDuplicated: PUBLIC PROC [tables: TABLES, id: ROPE, constant: CARD] RETURNS [new: TABLES] ~ { IF ( NOT SymTab.Insert[tables.workTable, id,""] ) THEN [] _ SendError[Rope.Cat["Duplicates in Enumerated Type, ", id, " redeclared"]]; IF ( NOT SymTab.Insert[tables.workTable, Convert.RopeFromCard[constant],""] ) THEN [] _ SendError["Two identifiers have the same value in Enumerated Type"]; new _ tables; }; SeeIfInt: PUBLIC PROC [type: CType] RETURNS [yes: BOOLEAN _ TRUE] ~ { IF ( ( type.class = int16 ) OR ( type.class = int32 ) ) THEN NULL ELSE [] _ SendError["Type Mismatch, negative number not expected"]; }; SendError: PUBLIC PROC [errMsg: ROPE] RETURNS [c: CARD] ~ { length: INT; position: INT; outstream: IO.STREAM _ SIGNAL ThreeC4Support.GetReportStream; [position, length] _ SIGNAL ThreeC4Support.GetSourceInfo; IO.PutF[outstream, "\nError: %g at %g..%g\n", IO.rope[errMsg], IO.int[position], IO.int[(position+length)] ]; ERROR SiroccoPrivate.EndItAll; }; TryToCoerceNumber: PUBLIC PROC [first: CType, value: CARD] RETURNS [num: INT] ~ { IllegalValue: PROC ~ { [] _ SendError["Wrong Number"]; -- should be recovered from }; num _ 1; SELECT first.class FROM card32 => { IF ( NOT value IN CARD32 ) THEN IllegalValue[]; }; int16 => { IF ( NOT value IN [0..32768] ) THEN IllegalValue[]; }; int32 => { IF ( NOT value IN [0..2147483648) ) THEN IllegalValue[]; }; proc, card16, error, unspec => { IF ( NOT value IN CARD16 ) THEN IllegalValue[]; }; ENDCASE => { IllegalValue[]; num _ 0; }; }; GetObjectName: PUBLIC PROC [name: ROPE, tables: TABLES] RETURNS [objectName: ROPE] ~ { RETURN [SiroccoPrivate.MakeUpName[name, "Object", tables]] }; MakeUpFunctionName: PUBLIC PROC RETURNS [madeUpName: ROPE] ~ { h: SiroccoPrivate.Handle _ SIGNAL SiroccoPrivate.AquireState; madeUpName _ IO.PutFR["P%gV%gFcn%g", IO.card[h.programNo], IO.card[h.versionNo], IO.card[h.uniqueNo] ]; h.uniqueNo _ h.uniqueNo.SUCC; }; <> <> <> <> <<};>> <<>> <> <> <<};>> <<>> <> <> <<};>> <<>> }.