-- ThreeC4MiscImpl.ThreeC4 -- Sturgis, May 10, 1986 3:21:40 pm PDT Include[ThreeC4BaseDecl, ThreeC4RecFcnDecl, ThreeC4BasicAbTypes, ThreeC4MiscAbGram]; ThreeC4MiscImpl: Module = Begin for ModId.oneId: AbstractProduction[Identifier] let FormName[tree] _ BuildName[Identifier] let FormFirstId[tree] _ Identifier let FormType[tree, context] _ LookUpType[context, BuildName[Identifier]] let FormValueInfo[tree, context] _ LookUpSimpleValue[context, Identifier] let FormExpCode[tree, context, usage] _ where code _ RopeCode1["%g", NameFill[name]] where check _ Check[FoundType[type]] where type _ LookUpRightSideSymbol[context, name] where name _ FormName[tree] let FormTypeUse[tree, usage, context] _ RecordTypeUse[usage, LookUpType[context, BuildName[Identifier]]] let FormTypeEarly[tree, context] _ FindType[context, BuildName[Identifier]]; for ModId.twoIds: AbstractProduction[Identifier.left, Identifier.right] let FormName[tree] _ BuildName2[Identifier.left, Identifier.right] let FormFirstId[tree] _ Identifier.left let FormType[tree, context] _ LookUpType[context, BuildName[Identifier.left]] let FormValueInfo[tree, context] _ LookUpValue2[context, Identifier.left, Identifier.right] let FormExpCode[tree, context, usage] _ if FoundType[type1] then else ( where use2 _ RecordTypeUse[usage, type2] where _ LookUpEnumTypeVal[context, BuildName[Identifier.left], BuildName[Identifier.right]]) where type1 _ LookUpRightSideSymbol[context, name1] where name1 _ FormName[tree] let FormTypeUse[tree, usage, context] _ RecordTypeUse[usage, LookUpType[context, BuildName[Identifier.left]]] let FormTypeEarly[tree, context] _ FindType[context, BuildName[Identifier.left]]; for ModIdList.Empty: AbstractProduction[] let FormNameList[tree] _ BuildEmptyNameList[] let FormTypeList[tree, context] _ BuildEmptyTypeList[] let FormAbstRightSideContext[tree, context] _ FakeCopyContextForConditional[context] let FormTypeUse[tree, usage, context] _ FakeUsageCopy[usage] let ProdDataTypeDefCode[tree, prodNameCode, context] _ BuildErrorCode["GetRidOf ProdDataTypeDefCode as it is never used"] let DataBodyFieldTypeCode[tree, context] _ BuildEmptyCode[] let ProdBuildDataRcdCode[tree, typeNameCode, prodNameCode] _ BuildErrorCode["GetRidOf ProdBuildDataRcdCode as it is never used"] let FormTypeListEarly[tree, context] _ BuildEmptyTypeList[] let FormTypesCode[tree, context, usage] _ ; for ModIdList.Many: AbstractProduction[ModIdList, ModId] let FormNameList[tree] _ AppendToNameList[FormNameList[ModIdList], FormName[ModId]] let FormTypeList[tree, context] _ AppendToTypeList[FormTypeList[ModIdList, context], FormType[ModId, context]] let FormAbstRightSideContext[tree, context] _ RecordAbstRightSideSymbol[ FormAbstRightSideContext[ModIdList, context], FormName[ModId], BuildName[FormFirstId[ModId]]] let FormTypeUse[tree, usage, context] _ FormTypeUse[ModId, FormTypeUse[ModIdList, usage, context], context] let ProdDataTypeDefCode[tree, prodNameCode, context] _ BuildErrorCode["GetRidOf ProdDataTypeDefCode as it is never used"] let DataBodyFieldTypeCode[tree, context] _ RopeCode1[", %g", CodeFill[BuildArgNameTypeCode[names, types]]] where names _ FormNameList[tree] where types _ FormTypeList[tree, context] let ProdBuildDataRcdCode[tree, typeNameCode, prodNameCode] _ BuildErrorCode["GetRidOf ProdBuildDataRcdCode as it is never used"] let FormTypeListEarly[tree, context] _ AppendToTypeList[ FormTypeListEarly[ModIdList, context], FormTypeEarly[ModId, context]] let FormTypesCode[tree, context, usage] _ where code _ ConcatCode2[ if TestEmptyCode[listCode] then BuildEmptyCode[] else RopeCode1["%g, ", CodeFill[listCode]], GetTypeCodeName[type]] where use _ RecordTypeUse[use1, type] where type _ FormType[ModId, context] where _ FormTypesCode[ModIdList, context, usage]; for IdList.Empty: AbstractProduction[] let RecordCedarTypesFrom[tree, defFileName, context] _ FakeCopyContextForConditional[context] let RecordCedarTypes[tree, context] _ FakeCopyContextForConditional[context] let FormTypeListEarly[tree, context] _ BuildEmptyTypeList[] let FormNameList[tree] _ BuildEmptyNameList[] let CollectValueTypes[tree, context] _ FakeCopyContextForConditional[context] let CollectFunctionTypes[tree, context] _ FakeCopyContextForConditional[context] let CollectRightSideSymbols[tree, context] _ FakeCopyContextForConditional[context] let RecordMultipleBaseTypes[tree, file, context] _ FakeCopyContextForConditional[context] let ProcFieldTypeCode[tree, context, usage] _ let BaseDeclCode[tree, context] _ BuildEmptyCode[] let FormProcsNamesCode[tree, prodNameCode] _ BuildEmptyCode[] let FormTypesCode[tree, context, usage] _ let FormRecFcnsDeclCode[tree, prodNameCode, context, usage] _ let FormVarDeclCode[tree, types] _ BuildEmptyCode[] let FormLinkCallCode[tree, context, usage] _ let SyntaxFileCodes[tree, context] _ ; for IdList.nonEmpty: AbstractProduction[Identifier, IdList] let RecordCedarTypesFrom[tree, defFileName, context] _ RecordCedarTypesFrom[IdList, defFileName, RecordCedarType[context, BuildName[Identifier], defFileName, codeName] where codeName _ RopeCode1["%g", IdFill[Identifier]]] let RecordCedarTypes[tree, context] _ RecordCedarTypes[IdList, RecordPreDefinedCedarType[context, BuildName[Identifier], codeName] where codeName _ RopeCode1["%g", IdFill[Identifier]]] let FormTypeListEarly[tree, context] _ PrefixToTypeList[ FindType[context, BuildName[Identifier]], FormTypeListEarly[IdList, context]] let FormNameList[tree] _ PrefixToNameList[ BuildName[Identifier], FormNameList[IdList]] let CollectValueTypes[tree, context] _ CollectValueTypes[fileTree, context2] where _ FindOrReadAndParseTree[context1, BuildName[Identifier]] where context1 _ CollectValueTypes[IdList, context] let CollectFunctionTypes[tree, context] _ CollectFunctionTypes[fileTree, context1] where fileTree _ FindParseTree[context1, BuildName[Identifier]] where context1 _ CollectFunctionTypes[IdList, context] let CollectRightSideSymbols[tree, context]_ CollectRightSideSymbols[fileTree, context1] where fileTree _ FindParseTree[context1, BuildName[Identifier]] where context1 _ CollectRightSideSymbols[IdList, context] let RecordMultipleBaseTypes[tree, file, context] _ RecordSimpleBaseType[context1, name, file, codeName] where name _ BuildName[Identifier] where codeName _ RopeCode1["%gNode", IdFill[Identifier]] where context1 _ RecordMultipleBaseTypes[IdList, file, context] let ProcFieldTypeCode[tree, context, usage] _ where code _ ConcatCode2[ RopeCode2["\N\T%g: %gProcType", IdFill[Identifier], IdFill[Identifier]], tailCode] where use _ RecordFcnUse[use1, BuildName[Identifier], Use.ref, context] where tailCode _ if TestEmptyCode[idListCode] then BuildEmptyCode[] else ConcatCode2[RopeCode[", "], idListCode] where _ ProcFieldTypeCode[IdList, context, usage] let BaseDeclCode[tree, context] _ ConcatCode2[ ConcatCode2[ RopeCode2["%g: TYPE = REF %gBody;\N", CodeFill[codeName], CodeFill[codeName]], RopeCode1["%gBody: TYPE;\N\N", CodeFill[codeName]]], BaseDeclCode[IdList, context]] where codeName _ GetTypeCodeName[LookUpType[context, BuildName[Identifier]]] let FormProcsNamesCode[tree, prodNameCode] _ ConcatCode2[ RopeCode2["%g%g", CodeFill[prodNameCode], IdFill[Identifier]], if TestEmptyCode[idListCode] then BuildEmptyCode[] else RopeCode1[", %g", CodeFill[idListCode]]] where idListCode _ FormProcsNamesCode[IdList, prodNameCode] let FormTypesCode[tree, context, usage] _ where code _ ConcatCode2[ GetTypeCodeName[type], if TestEmptyCode[idListCode] then BuildEmptyCode[] else RopeCode1[", %g", CodeFill[idListCode]]] where use _ RecordTypeUse[use1, type] where type _ LookUpType[context, BuildName[Identifier]] where _ FormTypesCode[IdList, context, usage] let FormRecFcnsDeclCode[tree, prodNameCode, context, usage] _ where code _ ConcatCode2[ RopeCode3["%g%g: %gProcType;\N", CodeFill[prodNameCode], IdFill[Identifier], IdFill[Identifier]], idListCode] where use _ RecordFcnUse[use1, BuildName[Identifier], Use.ref, context] where _ FormRecFcnsDeclCode[IdList, prodNameCode, context, usage] let FormVarDeclCode[tree, types] _ ConcatCode2[ RopeCode2["%g: %g;\N", IdFill[Identifier], CodeFill[GetTypeCodeName[firstType]]], FormVarDeclCode[IdList, restTypes]] where _ PartitionFirstType[types] let FormLinkCallCode[tree, context, usage] _ where _ FormLinkCallCode[IdList, context, use1] where _ FormLinkCallCode[fileTree, context, usage] where fileTree _ LookUpParseTree[context, BuildName[Identifier]] let SyntaxFileCodes[tree, context] _ ConcatCodePairs2[SyntaxFileCodes[fileTree, context], SyntaxFileCodes[IdList, context]] where fileTree _ LookUpParseTree[context, BuildName[Identifier]]; for RopeList.One: AbstractProduction[Rope] let CollectRightSideSymbols[tree, context] _ RecordRopeToken[context, Rope] let SyntaxFileCodes[tree, context] _ where tkn _ RopeCode1["\"%g\"", CodeFill[RopeCode[RopeFromRopeNode[Rope]]]] let SpecialSyntaxTokenFileCode[tree] _ if EqualRopes[";", RopeFromRopeNode[Rope]] then RopeCode["SpelledTerminals: semiColon ; ;\N"] else BuildEmptyCode[]; for RopeList.Many: AbstractProduction[RopeList, Rope] let CollectRightSideSymbols[tree, context] _ RecordRopeToken[CollectRightSideSymbols[RopeList, context], Rope] let SyntaxFileCodes[tree, context] _ where tkn _ ConcatCode3[ listCode, RopeCode[" "], RopeCode1["\"%g\"", CodeFill[RopeCode[RopeFromRopeNode[Rope]]]]] where _ SyntaxFileCodes[RopeList, context] let SpecialSyntaxTokenFileCode[tree] _ ConcatCode2[ SpecialSyntaxTokenFileCode[RopeList], if EqualRopes[";", RopeFromRopeNode[Rope]] then RopeCode["SpelledTerminals: semiColon ; ;\N"] else BuildEmptyCode[]] End.