DIRECTORY BasicTime USING [], FS USING [StreamOpen], HashTable USING [EachPairAction, Erase, Fetch, GetSize, Insert, Pairs, Value], IO USING [int, rope, Close, PutF, PutFR, STREAM], Rope USING [ROPE, Concat, Equal], SiroccoPrivate USING [AquireState, CComponent, CType, DirectoryEntry, FileHeader, Handle, Marshal, Nest, TABLES, UnDo, UnMarshal]; GenerateClient: CEDAR PROGRAM IMPORTS Rope, HashTable, IO, FS, SiroccoPrivate EXPORTS SiroccoPrivate ~ { OPEN SiroccoPrivate; ROPE: TYPE ~ Rope.ROPE; Value: TYPE ~ HashTable.Value; GenCImpl: PUBLIC PROC [] ~ { failure: BOOLEAN; programKey: ROPE; programKeyWD: ROPE; cImplStream: IO.STREAM; allTheTables: TABLES; uniqueNo: NAT; h: Handle; CollectProcsAndErrors: HashTable.EachPairAction ~ { entry: REF DirectoryEntry _ NARROW [value]; successful: BOOLEAN; type: CType; value1: Value; [successful, value1] _ HashTable.Fetch[allTheTables.condensedTypeTable, entry.type]; type _ NARROW [value1]; IF (type.class = procedure) THEN [] _ HashTable.Insert[allTheTables.procedures, key, value] ELSE { IF (type.class = error) THEN [] _ HashTable.Insert[allTheTables.errors, key, value]; }; RETURN[FALSE]; }; GenerateRemoteProc: HashTable.EachPairAction ~ { entry: REF DirectoryEntry _ NARROW [value]; name: ROPE _ NARROW [key]; code: ROPE; id: ROPE; list: CComponent; successful: BOOLEAN; type: CType; value1: Value; [successful, value1] _ HashTable.Fetch[allTheTables.condensedTypeTable, entry.type]; type _ NARROW[value1]; IO.PutF[cImplStream, Nest["", 1]]; IO.PutF[cImplStream, "%g: PUBLIC PROC [h: CrRPC.Handle", IO.rope[name] ]; list _ type.children; IF (list # NIL) THEN { FOR loopindex: CARD IN [0..type.bound) DO IO.PutF[cImplStream,", %g: %g", IO.rope[list.name], IO.rope[SiroccoPrivate.UnDo[list.type, programKey]] ]; list _ list.sibling; ENDLOOP; IO.PutF[cImplStream, "] RETURNS ["]; IF (list # NIL) THEN { IO.PutF[cImplStream,"%g: %g", IO.rope[list.name], IO.rope[SiroccoPrivate.UnDo[list.type, programKey]] ]; list _ list.sibling; }; WHILE (list # NIL) DO IO.PutF[cImplStream,", %g: %g", IO.rope[list.name], IO.rope[SiroccoPrivate.UnDo[list.type, programKey]] ]; list _ list.sibling; ENDLOOP; }; IO.PutF[cImplStream, Nest["] ~ {", 2]]; IO.PutF[cImplStream, Nest["PutArgs: CrRPC.PutArgsProc ~ {", 3]]; list _ type.children; uniqueNo _ 0; IF (list = NIL) THEN IO.PutF[cImplStream, Nest["NULL", 3]] ELSE { FOR loopindex: CARD IN [0..type.bound) DO code _ " "; [successful, value1] _ HashTable.Fetch[allTheTables.condensedTypeTable, list.type]; type _ NARROW[value1]; [code, id] _ SiroccoPrivate.Marshal[h, type, list.type, list.name, code, uniqueNo, 3]; IO.PutF[cImplStream, Nest["%g", 3], IO.rope[code] ]; list _ list.sibling; ENDLOOP; }; IO.PutF[cImplStream, Nest["};", 2]]; IO.PutF[cImplStream, Nest["GetResults: CrRPC.GetResultsProc ~ {", 3]]; uniqueNo _ 0; IF (list = NIL) THEN IO.PutF[cImplStream, Nest["NULL", 3]]; WHILE (list # NIL) DO code _ ""; [successful, value1] _ HashTable.Fetch[allTheTables.condensedTypeTable, list.type]; type _ NARROW [value1]; [code, id] _ SiroccoPrivate.UnMarshal[h, type, list.type, list.name, code, uniqueNo, 3]; IO.PutF[cImplStream, Nest["%g", 3], IO.rope[code] ]; list _ list.sibling; ENDLOOP; IO.PutF[cImplStream, Nest["};", 3]]; IO.PutF[cImplStream, Nest["", 2]]; IO.PutF[cImplStream, Nest["CrRPC.Call[h~h, remotePgm~%g, remotePgmVersion~%g, remoteProc~%g, putArgs~PutArgs, getResults~GetResults, getError~GetError];", 2], IO.int[h.programNo], IO.int[h.versionNo], IO.rope[entry.constant] ]; IO.PutF[cImplStream, Nest["};", 1]]; }; GenerateErrorDefinition: HashTable.EachPairAction ~ { name: ROPE _ NARROW [key]; entry: REF DirectoryEntry _ NARROW [value]; list: CComponent; successful: BOOLEAN; type: CType; value1: Value; [successful, value1] _ HashTable.Fetch[allTheTables.condensedTypeTable, entry.type]; type _ NARROW[value1]; IO.PutF[cImplStream, "%g: ", IO.rope[name] ]; IO.PutF[cImplStream, "PUBLIC ERROR"]; list _ type.children; IF (list # NIL) THEN { IO.PutF[cImplStream, " ["]; IO.PutF[cImplStream,"%g: %g", IO.rope[list.name], IO.rope[SiroccoPrivate.UnDo[list.type, programKey]] ]; list _ list.sibling; WHILE (list # NIL) DO IO.PutF[cImplStream,", %g: %g", IO.rope[list.name], IO.rope[SiroccoPrivate.UnDo[list.type, programKey]] ]; list _ list.sibling; ENDLOOP; IO.PutF[cImplStream, "]"]; }; IO.PutF[cImplStream, Nest[" ~ CODE;", 1]] }; GenerateErrorCase: HashTable.EachPairAction ~ { entry: REF DirectoryEntry _ NARROW [value]; name: ROPE _ NARROW [key]; code: ROPE; id: ROPE; list: CComponent; successful: BOOLEAN; type: CType; value1: Value; IF Rope.Equal[entry.constant , ""] THEN RETURN; IO.PutF[cImplStream, "%g => ", IO.rope[entry.constant] ]; [successful, value1] _ HashTable.Fetch[allTheTables.condensedTypeTable, entry.type]; type _ NARROW[value1]; list _ type.children; IF (list = NIL) THEN { IO.PutF[cImplStream, Nest["ERROR %g[];", 3], IO.rope[name] ]; } ELSE { IO.PutF[cImplStream, Nest["{", 4]]; WHILE (list # NIL) DO IO.PutF[cImplStream, Nest["%g: %g;", 4], IO.rope[list.name], IO.rope[SiroccoPrivate.UnDo[list.type, programKey]] ]; list _ list.sibling; ENDLOOP; list _ type.children; WHILE (list # NIL) DO code _ ""; [successful, value1] _ HashTable.Fetch[allTheTables.condensedTypeTable, list.type]; [code, id] _ SiroccoPrivate.UnMarshal[h, NARROW [value1], list.type, list.name, code, uniqueNo, 3]; IO.PutF[cImplStream, Nest["%g", 4], IO.rope[code] ]; list _ list.sibling; ENDLOOP; list _ type.children; IO.PutF[cImplStream, "ERROR %g[%g", IO.rope[name], IO.rope[list.name] ]; list _ list.sibling; WHILE (list # NIL) DO IO.PutF[cImplStream, ", %g", IO.rope[list.name] ]; list _ list.sibling; ENDLOOP; IO.PutF[cImplStream, Nest["]", 4]]; IO.PutF[cImplStream, Nest["};", 3]]; }; }; Heading: PROC [out: IO.STREAM] ~ { PutDirectory: HashTable.EachPairAction ~ { interface: ROPE ~ NARROW [value]; IO.PutF[out, Nest["%g,", 1], IO.rope[interface] ]; }; SiroccoPrivate.FileHeader[out, Rope.Concat[programKeyWD,"ClientImpl.Mesa"]]; IO.PutF[out, Nest["DIRECTORY", 1]]; IO.PutF[out, Nest["CrRPC,", 1]]; failure _ HashTable.Pairs[allTheTables.directory, PutDirectory]; IO.PutF[out, Nest["%g;", 0], IO.rope[programKeyWD]]; IO.PutF[out, Nest["", 0]]; IO.PutF[out, Nest["%gClientImpl: CEDAR PROGRAM", 1], IO.rope[programKeyWD]]; IO.PutF[out, Nest["IMPORTS CrRPC", 1]]; IO.PutF[out, Nest["EXPORTS %g ~ {", 1], IO.rope[programKeyWD]]; IO.PutF[out, Nest["OPEN %g;", 0], IO.rope[programKeyWD]]; IO.PutF[out, Nest["", 0]]; }; h _ SIGNAL SiroccoPrivate.AquireState[]; allTheTables _ h.allTheTables; programKey _ h.programKey; programKeyWD _ IO.PutFR["%gP%gV%g", IO.rope[h.programName], IO.int[h.programNo], IO.int[h.versionNo] ]; cImplStream _ FS.StreamOpen[Rope.Concat[programKeyWD,"ClientImpl.Mesa"], $create]; Heading[cImplStream]; HashTable.Erase[allTheTables.procedures]; HashTable.Erase[allTheTables.errors]; failure _ HashTable.Pairs[allTheTables.localTable, CollectProcsAndErrors]; IF (HashTable.GetSize[allTheTables.errors] = 0) THEN { IO.PutF[cImplStream, Nest["GetError: CrRPC.GetErrorProc ~ {", 2]]; IO.PutF[cImplStream, Nest["ERROR CrRPC.Error[h, remoteError, \"%g\"];", 2], IO.rope["Unexpected Remote Error"] ]; IO.PutF[cImplStream, Nest["};", 1]]; } ELSE { IO.PutF[cImplStream, Nest["-- Errors", 1]]; IO.PutF[cImplStream, Nest["", 1]]; failure _ HashTable.Pairs[allTheTables.errors, GenerateErrorDefinition]; IO.PutF[cImplStream, Nest["", 0]]; IO.PutF[cImplStream, Nest["-- GetErrorProc", 1]]; IO.PutF[cImplStream, Nest["", 1]]; IO.PutF[cImplStream, Nest["GetError: CrRPC.GetErrorProc ~ {", 2]]; IO.PutF[cImplStream, Nest["SELECT errNum FROM", 3]]; failure _ HashTable.Pairs[allTheTables.errors, GenerateErrorCase]; IO.PutF[cImplStream, Nest["ENDCASE => {", 4]]; IO.PutF[cImplStream, Nest["ERROR CrRPC.Error[h, remoteError, \"%g\"];", 4], IO.rope["Unexpected Remote Error"] ]; IO.PutF[cImplStream, Nest["};", 2]]; IO.PutF[cImplStream, Nest["};", 1]]; }; IO.PutF[cImplStream, Nest["", 0]]; IO.PutF[cImplStream, Nest["-- Remote Procedures", 1]]; failure _ HashTable.Pairs[allTheTables.procedures, GenerateRemoteProc]; IO.PutF[cImplStream, Nest["", 0]]; IO.PutF[cImplStream, Nest["}...", 0]]; IO.Close[cImplStream]; }; }... ΨGenerateClient.mesa Copyright c 1986 by Xerox Corporation. All rights reserved. Bhargava, August 10, 1986 1:12:31 pm PDT Bill Jackson (bj) September 25, 1986 3:15:52 am PDT Copied Types Procs GenCImpl MAIN Κ Λ˜codešœ™Kšœ Οmœ1™˜@Kšœ˜K˜ šžœ žœ˜Kšžœžœ#˜*šžœ˜šžœ žœžœž˜)Kšœ ˜ KšœS˜SKšœžœ ˜KšœW˜Wšžœ!˜#Kšžœ ˜ Kšœ˜—Kšœ˜Kšžœ˜—Kšœ˜——Kšžœ"˜$K˜KšžœD˜FK˜ šžœ žœ˜Kšžœžœ$˜+—šžœ žœž˜Kšœ ˜ KšœS˜SKšœžœ ˜KšœX˜Xšžœ!˜#Kšžœ ˜ Kšœ˜—Kšœ˜Kšžœ˜—Kšžœ"˜$K˜Kšžœ ˜"K˜šžœœ˜žKšžœ˜Kšžœ˜Kšžœ˜Kšœ˜—Kšžœ"˜$K˜K˜—šŸœ˜5Kšœžœžœ˜Kšœžœžœ ˜+Kšœ˜Kšœ žœ˜K˜ Kšœ˜K˜KšœT˜TKšœžœ ˜K˜šžœ˜Kšžœ ˜ Kšœ˜—Kšžœ#˜%K˜Kšœ˜šžœ žœžœ˜Kšžœ˜šžœ˜Kšžœ˜Kšžœ1˜3Kšœ˜K˜—Kšœ˜šžœ žœž˜šžœ˜Kšžœ˜Kšžœ1˜3Kšœ˜—Kšœ˜Kšžœ˜—Kšžœ˜Kšœ˜K˜—Kšžœ'˜)K˜K˜—šŸœ˜/Kšœžœžœ ˜+Kšœžœžœ˜Kšœžœ˜ Kšœžœ˜ K˜Kšœ žœ˜K˜ K˜K˜Kšžœ!žœžœ˜/K˜šžœ˜Kšžœ˜Kšœ˜K˜—KšœT˜TKšœžœ ˜K˜Kšœ˜šžœ žœ˜šžœ˜šžœ*˜,Kšžœ ˜ Kšœ˜—Kšœ˜—šžœ˜Kšžœ!˜#K˜šžœ žœž˜šžœ&˜(Kšžœ˜Kšžœ1˜3Kšœ˜—Kšœ˜Kšžœ˜K˜—Kšœ˜šžœ žœž˜K˜ K˜KšœS˜SK˜Kšœ)žœ4˜cšžœ!˜#Kšžœ ˜ Kšœ˜—Kšœ˜Kšžœ˜K˜—Kšœ˜šžœ!˜#Kšžœ ˜Kšžœ˜Kšœ˜—K˜Kšœ˜šžœ žœž˜šžœ˜Kšžœ˜Kšœ˜—Kšœ˜Kšžœ˜K˜—Kšžœ!˜#Kšžœ"˜$Kšœ˜——K˜K˜—šŸœžœžœžœ˜"šŸ œ˜*Kšœ žœžœ ˜!šžœ˜Kšžœ˜Kšœ˜—K˜—KšœL˜LK˜Kšžœ!˜#Kšžœ˜ Kšœ@˜@Kšžœžœ˜5Kšžœ˜K˜Kšžœ3žœ˜LKšžœ%˜'Kšžœ&žœ˜?Kšžœ žœ˜9Kšžœ˜Kšœ˜K˜—Kšœ ž™ K™Kšœžœ˜(Kšœ˜Kšœ˜K˜šœžœ˜#Kšžœ˜Kšžœ˜Kšžœ˜Kšœ˜—K˜KšœžœB˜RK˜Kšœ˜K˜Kšœ)˜)Kšœ%˜%K˜KšœJ˜JK˜šžœ-˜/šžœž˜Kšžœ@˜BšžœI˜KKšžœ ˜"Kšœ˜—Kšžœ"˜$K˜—šžœ˜Kšžœ)˜+Kšžœ ˜"KšœH˜HKšžœ ˜"K˜Kšžœ/˜1Kšžœ ˜"Kšžœ@˜BKšžœ2˜4K˜KšœB˜BK˜Kšžœ,˜.šžœI˜KKšžœ ˜"Kšœ˜—Kšžœ"˜$Kšžœ"˜$K˜K˜——Kšžœ ˜"Kšžœ4˜6KšœG˜GKšžœ ˜"K˜Kšžœ$˜&Kšžœ˜K˜——K˜Kšœ˜K˜—…— +₯