-- ThreeC4RootImpl.ThreeC4 -- Sturgis, May 10, 1986 3:40:32 pm PDT Include[ThreeC4BaseDecl, ThreeC4RecFcnDecl, ThreeC4BasicAbTypes, ThreeC4RootAbGram]; ThreeC4RootImpl: Module = Begin for MainGoal: AbstractProduction[WholeFile] let FormFileSeq[tree, context] _ BuildEmptyFileSeq[]; for WholeFile: AbstractProduction[IncludeClause, ModuleList] let FormFileSeq[tree, context] _ ConcatFileSeq[files1, files2] -- note: context will contain only the parse trees of previously read files where junk _ TearDownGraphs[lookupContext] where _ if TestFormControlFile[ModuleList] then (FormControlFileList[ModuleList, nProds, ConcatCode2[ ConcatCodePairs2[ SyntaxFileCodes[ModuleList, lookupContext], SyntaxFileCodes[IncludeClause, lookupContext]]], ConcatCode2[linkCallCode1, linkCallCode2], linkUsage] where _ FormLinkCallCode[ IncludeClause, lookupContext, linkUsage1] where _ FormLinkCallCode[ ModuleList, lookupContext, BuildEmptyUsage[]]) else where files1 _ MakeFileSeq[ModuleList, lookupContext] where check1 _ InspectContext[lookupContext] where lookupContext _ BuildBasicLookupContext[context7] where context7 _ CollectRightSideSymbols[ModuleList, context6] where context6 _ CollectRightSideSymbols[IncludeClause, context5] where context5 _ CollectFunctionTypes[ModuleList, context4] where context4 _ CollectFunctionTypes[IncludeClause, context3] where context3 _ CollectValueTypes[ModuleList, context2] where context2 _ CollectValueTypes[IncludeClause, context1] where _ CollectProductions[ModuleList, 0, baseContext] where baseContext _ RecordGlobalTreeType[ context, BuildRopeName["Tree"], RopeCode["REF ANY"]] let CollectValueTypes[tree, context] _ CollectValueTypes[ModuleList, context] let CollectFunctionTypes[tree, context] _ CollectFunctionTypes[ModuleList, context] let CollectRightSideSymbols[tree, context] _ CollectRightSideSymbols[ModuleList, context] let FormLinkCallCode[tree, context, usage] _ FormLinkCallCode[ModuleList, context, usage] let SyntaxFileCodes[tree, context] _ SyntaxFileCodes[ModuleList, context]; for IncludeClause: AbstractProduction[IdList] let CollectValueTypes[tree, context] _ CollectValueTypes[IdList, context] let CollectFunctionTypes[tree, context] _ CollectFunctionTypes[IdList, context] let CollectRightSideSymbols[tree, context] _ CollectRightSideSymbols[IdList, context] let FormLinkCallCode[tree, context, usage] _ FormLinkCallCode[IdList, context, usage] let SyntaxFileCodes[tree, context] _ SyntaxFileCodes[IdList, context]; for ModuleList.One: AbstractProduction[ModuleBody] let CollectValueTypes[tree, context] _ CollectValueTypes[ModuleBody, context] let CollectFunctionTypes[tree, context] _ CollectFunctionTypes[ModuleBody, context] let CollectProductions[tree, first, context] _ CollectProductions[ModuleBody, first, context] let CollectRightSideSymbols[tree, context] _ CollectRightSideSymbols[ModuleBody, context] let SyntaxFileCodes[tree, context] _ SyntaxFileCodes[ModuleBody, context] let MakeFileSeq[tree, context] _ MakeFileSeq[ModuleBody, context] let TestFormControlFile[tree] _ TestFormControlFile[ModuleBody] let FormLinkCallCode[tree, context, usage] _ FormLinkCallCode[ModuleBody, context, usage] let FormControlFileList[tree, nProds, syntax, linkCalls, linkUsage] _ FormControlFileList[ModuleBody, nProds, syntax, linkCalls, linkUsage]; for ModuleList.Many: AbstractProduction[ModuleList, ModuleBody] let CollectValueTypes[tree, context] _ CollectValueTypes[ModuleBody, CollectValueTypes[ModuleList, context]] let CollectFunctionTypes[tree, context] _ CollectFunctionTypes[ModuleBody, CollectFunctionTypes[ModuleList, context]] let CollectProductions[tree, first, context] _ CollectProductions[ModuleBody, CollectProductions[ModuleList, first, context]] let CollectRightSideSymbols[tree, context] _ CollectRightSideSymbols[ModuleBody, CollectRightSideSymbols[ModuleList, context]] let SyntaxFileCodes[tree, context] _ ConcatCodePairs2[ SyntaxFileCodes[ModuleList, context], SyntaxFileCodes[ModuleBody, context]] let MakeFileSeq[tree, context] _ ConcatFileSeq[ MakeFileSeq[ModuleList, context], MakeFileSeq[ModuleBody, context]] let TestFormControlFile[tree] _ Or[TestFormControlFile[ModuleList], TestFormControlFile[ModuleBody]] let FormLinkCallCode[tree, context, usage] _ where _ FormLinkCallCode[ModuleBody, context, use1] where _ FormLinkCallCode[ModuleList, context, usage] let FormControlFileList[tree, nProds, syntax, linkCalls, linkUsage] _ where _ FormControlFileList[ModuleList, nProds, syntax1, linkCalls1, use2] where _ FormControlFileList[ModuleBody, nProds, syntax2, linkCalls2, linkUsage] where syntax1 _ RopeCode1["%g", CodeFill[syntax2]] where syntax2 _ RopeCode1["%g", CodeFill[syntax]] where linkCalls1 _ RopeCode1["%g", CodeFill[linkCalls2]] where linkCalls2 _ RopeCode1["%g", CodeFill[linkCalls]]; for ModuleBody.control: AbstractProduction[Identifier] let CollectValueTypes[tree, context] _ RecordControlModule[context, ConcatRopes2[RopeFromIdentifierNode[Identifier], "Def"]] let CollectFunctionTypes[tree, context] _ FakeCopyContextForConditional[context] let CollectProductions[tree, first, context] _ let CollectRightSideSymbols[tree, context] _ FakeCopyContextForConditional[context] let SyntaxFileCodes[tree, context] _ let MakeFileSeq[tree, context] _ BuildEmptyFileSeq[] let TestFormControlFile[tree] _ EqualRopes["True", "True"] let FormLinkCallCode[tree, context, usage] _ let FormControlFileList[tree, nProds, syntax, linkCalls, linkUsage] _ where syntaxFiles _ BuildOneFileSeq[RopeCode1["%g.OneCasaba", IdFill[Identifier]], ConcatCode3[ RopeCode["Begin\N"], RopeCode1["%g", CodeFill[syntax]], RopeCode["End."]]] where defFiles _ BuildOneFileSeq[RopeCode1["%gDef.mesa", IdFill[Identifier]], ConcatCode5[ defDirCode, RopeCode1["%gDef: CEDAR DEFINITIONS =\N", IdFill[Identifier]], RopeCode["BEGIN\N\N"], RopeCode["ParseOneStream: PROC[from: IO.STREAM, debugFlags: CARDINAL, debuggingTextTo: IO.STREAM] RETURNS[REF ANY];\N\N"], RopeCode["END..\N"]]] where defDirCode _ ConcatCode2[ RopeCode["DIRECTORY\N"], RopeCode["\TIO USING[STREAM];\N"]] where implFiles _ BuildOneFileSeq[RopeCode1["%gImpl.mesa", IdFill[Identifier]], ConcatCode6[ ConcatCode6[ implDirCode, RopeCode1["%gImpl: CEDAR PROGRAM", IdFill[Identifier]], implImpCode, implExpCode, RopeCode["= \NBEGIN\N"], implOpenCode], table, driverProced, linkProced, getTable, RopeCode["END..\N"]]] where _ BuildImplUseCode[use5] where use5 _ RecordDefFileUse[use4, "FS", Use.import] where use4 _ RecordDefFileUse[use3, "OneCasabaParser", Use.import] where use3 _ RecordDefFileUse[use2, ConcatRopes2[RopeFromIdentifierNode[Identifier], "Def"], Use.export] where use2 _ RecordDefFileUse[use1, "ThreeC4Support", Use.import] where use1 _ RecordDefFileUse[linkUsage, "IO", Use.import] where table _ RopeCode["ParseTable: OneCasabaParser.ParserTable _ NIL;\N\N"] where driverProced _ ConcatCode4[ RopeCode["ParseOneStream: PUBLIC PROC[from: IO.STREAM, debugFlags: CARDINAL, debuggingTextTo: IO.STREAM] RETURNS[REF ANY] =\N"], RopeCode["BEGIN\N"], RopeCode1["RETURN[ThreeC4Support.ParseOneStream[from, ParseTable, SetUpLinks, %g, debugFlags, debuggingTextTo]]\N", IntFill[nProds]], RopeCode["END;\N\N"]] where linkProced _ ConcatCode4[ RopeCode["SetUpLinks: PROC[prodLinkArray: SeeProdLinkArray, tknLinkArray: TokenLinkArray] =\N"], RopeCode["BEGIN\N"], RopeCode1["%g", CodeFill[linkCalls]], RopeCode["END;\N\N"]] where getTable _ ConcatCode6[ RopeCode["\N-- obtain parser table\N\N"], RopeCode["\TBEGIN\N"], RopeCode1["\TtableStream: IO.STREAM _ FS.StreamOpen[\"%g.kipperedParseTables\"];\N", IdFill[Identifier]], RopeCode["\TParseTable _ OneCasabaParser.BuildParserTableFromKipperedStream[tableStream];\N"], RopeCode["\TIO.Close[tableStream];\N"], RopeCode["\TEND;\N\N"]]; for ModuleBody.normal: AbstractProduction[Identifier, ModuleItemList] let CollectValueTypes[tree, context] _ CollectModuleValueTypes[ModuleItemList, defFileName, context] where defFileName _ ConcatRopes2[RopeFromIdentifierNode[Identifier], "Def"] let CollectFunctionTypes[tree, context] _ CollectModuleFunctionTypes[ModuleItemList, defFileName, context] where defFileName _ ConcatRopes2[RopeFromIdentifierNode[Identifier], "Def"] let CollectProductions[tree, first, context] _ CollectProductions[ModuleItemList, first, context] let CollectRightSideSymbols[tree, context] _ CollectRightSideSymbols[ModuleItemList, context] let SyntaxFileCodes[tree, context] _ SyntaxFileCodes[ModuleItemList, context] let MakeFileSeq[tree, context] _ seq2 where seq2 _ if TestEmptyCode[defCode] then FakeCopyFileSeqForConditional[seq1] else AppendToFileSeq[seq1, RopeCode1["%gDef.mesa", IdFill[Identifier]], ConcatCode6[ defDirCode, RopeCode1["%gDef: CEDAR DEFINITIONS = \N", IdFill[Identifier]], RopeCode["BEGIN\N"], defOpenCode, RopeCode1["%g", CodeFill[defCode]], RopeCode["END..\N"]]] where seq1 _ if TestEmptyCode[implCode] then BuildEmptyFileSeq[] else BuildOneFileSeq[ RopeCode1["%gImpl.mesa", IdFill[Identifier]], ConcatCode9[ implDirCode, RopeCode1["%gImpl: CEDAR PROGRAM", IdFill[Identifier]], implImpCode, implExpCode, RopeCode["= \NBEGIN\N"], implOpenCode, linkProcedCode, implCode, RopeCode["END..\N"]]] where _ BuildDefUseCode[dUse, defFileName] where dUse _ if noLinks then FakeUsageCopy[dUse1] else RecordDefFileUse[dUse1, "ThreeC4Support", Use.ref] where defCode _ ConcatCode2[ linkDefCode, defCode1] where _ DefFileCode[ModuleItemList, context, BuildEmptyUsage[]] where _ BuildImplUseCode[iUse] where linkProcedCode _ if noLinks then BuildEmptyCode[] else ConcatCode4[ RopeCode1["%gLinkProc: PUBLIC PROC[prodLinkArray: SeeProdLinkArray, tknLinkArray: TokenLinkArray] =\N", IdFill[Identifier]], RopeCode["BEGIN\N"], linkCode, RopeCode["END;\N\N"]] where linkDefCode _ if noLinks then BuildEmptyCode[] else RopeCode1["%gLinkProc: PROC[SeeProdLinkArray, TokenLinkArray];\N", IdFill[Identifier]] where iUse _ if noLinks then FakeUsageCopy[iUse2] else (RecordDefFileUse[iUse3, defFileName, Use.export] where iUse3 _ RecordDefFileUse[iUse2, "ThreeC4Support", Use.ref]) where defFileName _ ConcatRopes2[RopeFromIdentifierNode[Identifier], "Def"] where noLinks _ TestEmptyCode[linkCode] where _ LinkFileCode[ModuleItemList, context, iUse1] where _ ImplFileCode[ModuleItemList, context, iUse0] where iUse0 _ BuildEmptyUsage[] let TestFormControlFile[tree] _ EqualRopes["True", "False"] let FormLinkCallCode[tree, context, usage] _ if TestLinkPresent[ModuleItemList] then ( where defFileName _ ConcatRopes2[RopeFromIdentifierNode[Identifier], "Def"]) else let FormControlFileList[tree, nProds, syntax, linkCalls, linkUsage] _ ; for ModuleItemList.One: AbstractProduction[ModuleItem] let CollectModuleValueTypes[tree, defFileName, context] _ CollectModuleValueTypes[ModuleItem, defFileName, context] let CollectModuleFunctionTypes[tree, defFileName, context] _ CollectModuleFunctionTypes[ModuleItem, defFileName, context] let CollectProductions[tree, first, context] _ CollectProductions[ModuleItem, first, context] let CollectRightSideSymbols[tree, context] _ CollectRightSideSymbols[ModuleItem, context] let DefFileCode[tree, context, usage] _ DefFileCode[ModuleItem, context, usage] let ImplFileCode[tree, context, usage] _ ImplFileCode[ModuleItem, context, usage] let LinkFileCode[tree, context, usage] _ LinkFileCode[ModuleItem, context, usage] let SyntaxFileCodes[tree, context] _ SyntaxFileCodes[ModuleItem, context] let TestLinkPresent[tree] _ TestLinkPresent[ModuleItem]; for ModuleItemList.Many: AbstractProduction[ModuleItemList, ModuleItem] let CollectModuleValueTypes[tree, defFileName, context] _ CollectModuleValueTypes[ModuleItem, defFileName, CollectModuleValueTypes[ModuleItemList, defFileName, context]] let CollectModuleFunctionTypes[tree, defFileName, context] _ CollectModuleFunctionTypes[ModuleItem, defFileName, CollectModuleFunctionTypes[ModuleItemList, defFileName, context]] let CollectProductions[tree, first, context] _ CollectProductions[ModuleItem, CollectProductions[ModuleItemList, first, context]] let CollectRightSideSymbols[tree, context] _ CollectRightSideSymbols[ModuleItem, CollectRightSideSymbols[ModuleItemList, context]] let DefFileCode[tree, context, usage] _ where code _ ConcatCode2[code1, code2] where _ DefFileCode[ModuleItem, context, use1] where _ DefFileCode[ModuleItemList, context, usage] let ImplFileCode[tree, context, usage] _ where code _ ConcatCode2[code1, code2] where _ ImplFileCode[ModuleItem, context, use1] where _ ImplFileCode[ModuleItemList, context, usage] let LinkFileCode[tree, context, usage] _ where code _ ConcatCode2[code1, code2] where _ LinkFileCode[ModuleItem, context, use1] where _ LinkFileCode[ModuleItemList, context, usage] let SyntaxFileCodes[tree, context] _ ConcatCodePairs2[ SyntaxFileCodes[ModuleItemList, context], SyntaxFileCodes[ModuleItem, context]] let TestLinkPresent[tree] _ Or[TestLinkPresent[ModuleItemList], TestLinkPresent[ModuleItem]] End. Ź5˜Jš œĄ5Ļk œ œø  œ œ©6˜ķu—…—:š;+