private void CheckWellFormedness(RenameModuleExpr renameExpr) { if (renameExpr.ModuleInfo != null) { return; } //check that component module is wellformed CheckWellFormedness(renameExpr.ComponentModule); //check that the module is wellformed var componentModuleInfo = renameExpr.ComponentModule.ModuleInfo; // 1) receives set of both new and old interface must be same if (!renameExpr.NewInterface.ReceivableEvents.IsSame(renameExpr.OldInterface.ReceivableEvents)) { throw handler.InvalidRenameExpr(renameExpr.SourceLocation, $"{renameExpr.NewInterface.Name} and {renameExpr.OldInterface.Name} must have the same receive set"); } // 2) oldInterface must belong to implemented or created interface if (!componentModuleInfo.Creates.Interfaces.Union(componentModuleInfo.InterfaceDef.Keys) .Contains(renameExpr.OldInterface)) { throw handler.InvalidRenameExpr(renameExpr.SourceLocation, $"{renameExpr.OldInterface.Name} must belong to either created interfaces or bounded interfaces of the module"); } // 3) newInterface must not belong to created and implemented interfaces. if (componentModuleInfo.Creates.Interfaces.Union(componentModuleInfo.InterfaceDef.Keys) .Contains(renameExpr.NewInterface)) { throw handler.InvalidRenameExpr(renameExpr.SourceLocation, $"{renameExpr.NewInterface.Name} must not belong to created interfaces or bounded interfaces of the module"); } //populate the attributes of the module renameExpr.ModuleInfo = new ModuleInfo(); var currentModuleInfo = renameExpr.ModuleInfo; // compute the new monitor map foreach (var monMap in componentModuleInfo.MonitorMap) { var interfaceList = monMap.Value.Select(@interface => @interface.Equals(renameExpr.OldInterface) ? renameExpr.NewInterface : @interface).ToList(); currentModuleInfo.MonitorMap[monMap.Key] = interfaceList; } // compute the new private interfaces foreach (var @interface in componentModuleInfo.PrivateInterfaces.Interfaces) { currentModuleInfo.PrivateInterfaces.AddInterface( @interface.Equals(renameExpr.OldInterface) ? renameExpr.NewInterface : @interface); } // compute the new interface definition map foreach (var interfaceDefItem in componentModuleInfo.InterfaceDef) { currentModuleInfo.InterfaceDef.Add( interfaceDefItem.Key.Equals(renameExpr.OldInterface) ? renameExpr.NewInterface : interfaceDefItem.Key, interfaceDefItem.Value); } // compute the new link map foreach (var linkMapItem in componentModuleInfo .LinkMap) { var keyInterface = linkMapItem.Key.Equals(renameExpr.OldInterface) ? renameExpr.NewInterface : linkMapItem.Key; currentModuleInfo.LinkMap[keyInterface] = new Dictionary <Interface, Interface>(); foreach (var localLinkMap in linkMapItem.Value) { currentModuleInfo.LinkMap[keyInterface].Add(localLinkMap.Key, localLinkMap.Value.Equals(renameExpr.OldInterface) ? renameExpr.NewInterface : localLinkMap.Value); } } // compute the sends currentModuleInfo.Sends.AddEvents(componentModuleInfo.Sends.Events); // compute the receives currentModuleInfo.Receives.AddEvents(componentModuleInfo.Receives.Events); // compute the creates foreach (var binding in currentModuleInfo.InterfaceDef) { foreach (var createdInterface in binding.Value.Creates.Interfaces) { currentModuleInfo.Creates.AddInterface(currentModuleInfo.LinkMap[binding.Key][createdInterface]); } } }