<> <> <> <<>> <> <<>> DIRECTORY IO USING [atom, PutF, rope, STREAM], IPInterpreter USING [ErrorClass, Get, Integer, IntegerFromAny, MasterErrorType, MasterWarningType, Shape, State, Vector, VectorShape], List USING [AList, Assoc, PutAssoc], ProcessProps USING [AddPropList, GetPropList], Rope USING [FromProc, ROPE]; IPErrorImpl: CEDAR PROGRAM IMPORTS IO, IPInterpreter, List, ProcessProps, Rope EXPORTS IPInterpreter ~ BEGIN OPEN IPInterpreter; ROPE: TYPE ~ Rope.ROPE; STREAM: TYPE ~ IO.STREAM; Error: PUBLIC ERROR ~ CODE; stateKey: ATOM ~ $InterpressState; AddState: PUBLIC PROC[state: State, inner: PROC] ~ { aList: List.AList _ NIL; aList _ List.PutAssoc[key: stateKey, val: state, aList: aList]; ProcessProps.AddPropList[aList, inner]; }; GetState: PUBLIC PROC RETURNS[State] ~ { aList: List.AList ~ ProcessProps.GetPropList[]; value: REF ~ List.Assoc[key: stateKey, aList: aList]; WITH value SELECT FROM state: State => RETURN[state]; ENDCASE; RETURN[NIL]; }; RopeFromClass: PROC[class: ErrorClass] RETURNS[ROPE] ~ { RETURN[SELECT class FROM masterError => "Master Error", masterWarning => "Master Warning", appearanceError => "Appearance Error", appearanceWarning => "Appearance Warning", comment => "Comment", ENDCASE => NIL]; }; ReportError: PUBLIC PROC[class: ErrorClass, code: ATOM, explanation: ROPE] ~ { self: State ~ GetState[]; IF self#NIL THEN { log: STREAM ~ self.log; IF log=NIL THEN RETURN; log.PutF["%g (%g):\n", IO.rope[RopeFromClass[class]], IO.atom[code]]; log.PutF[" %g\n", IO.rope[explanation]]; }; }; NonDefaultingATOM: TYPE ~ ATOM _; MasterErrorCodeTable: TYPE ~ ARRAY MasterErrorType OF NonDefaultingATOM; MasterWarningCodeTable: TYPE ~ ARRAY MasterWarningType OF NonDefaultingATOM; masterErrorCode: REF MasterErrorCodeTable ~ NEW[MasterErrorCodeTable _ [bug: $bug, unimplemented: $unimplemented, boundsFault: $boundsFault, nilFault: $nilFault, invalidArgs: $invalidArgs, limitExceeded: $limitExceeded, markMismatch: $markMismatch, missingBody: $missingBody, notInteger: $notInteger, stackOverflow: $stackOverflow, stackUnderflow: $stackUnderflow, undefinedOperation: $undefinedOperation, undefinedProperty: $undefinedProperty, unmarkFailed: $unmarkFailed, wrongType: $wrongType]]; masterWarningCode: REF MasterWarningCodeTable ~ NEW[MasterWarningCodeTable _ [bug: $bug, unimplemented: $unimplemented, nullValue: $nullValue, illegalIdentifier: $illegalIdentifier, illegalString: $illegalString, unknownToken: $unknownToken]]; MasterError: PUBLIC PROC[type: MasterErrorType, explanation: ROPE _] ~ { ReportError[$masterError, masterErrorCode[type], explanation]; }; MasterWarning: PUBLIC PROC[type: MasterWarningType, explanation: ROPE _] ~ { ReportError[$masterWarning, masterWarningCode[type], explanation]; }; AppearanceError: PUBLIC PROC[code: ATOM, explanation: ROPE _] ~ { ReportError[$appearanceError, code, explanation]; }; AppearanceWarning: PUBLIC PROC[code: ATOM, explanation: ROPE _] ~ { ReportError[$appearanceWarning, code, explanation]; }; RopeFromVector: PUBLIC PROC[v: Vector] RETURNS[ROPE] ~ { shape: VectorShape ~ Shape[v]; i: Integer _ shape.l; p: PROC RETURNS[CHAR] ~ { n: Integer ~ IntegerFromAny[Get[v, i]]; i _ i+1; IF n IN[0..255] THEN RETURN[0C+n] ELSE { MasterError[$boundsFault, "Ascii character not in [0..255]."]; RETURN['-] }; }; RETURN[Rope.FromProc[len: shape.n, p: p]]; }; END.