예제 #1
0
        private void CheckWellFormedness(HideInterfaceModuleExpr hideIExpr)
        {
            if (hideIExpr.ModuleInfo != null)
            {
                return;
            }

            //check that component module is wellformed
            CheckWellFormedness(hideIExpr.ComponentModule);

            //check if the current module is wellformed
            var componentModuleInfo = hideIExpr.ComponentModule.ModuleInfo;

            // 1) interfaces to be hidden must be both implemented and created by the module
            var interfacesImplementedAndCreated =
                componentModuleInfo.Creates.Interfaces.Intersect(componentModuleInfo.InterfaceDef.Keys);

            foreach (var @interface in hideIExpr.HideInterfaces.Where(
                         it => !interfacesImplementedAndCreated.Contains(it)))
            {
                throw handler.InvalidHideInterfaceExpr(hideIExpr.SourceLocation,
                                                       $"interface {@interface.Name} cannot be made private. Interface {@interface.Name} must be both created and bounded in the module");
            }

            hideIExpr.ModuleInfo = new ModuleInfo();
            var currentModuleInfo = hideIExpr.ModuleInfo;

            //populate the attributes of the module
            currentModuleInfo.PrivateEvents.AddEvents(componentModuleInfo.PrivateEvents.Events);
            currentModuleInfo.PrivateInterfaces.AddInterfaces(
                componentModuleInfo.PrivateInterfaces.Interfaces.Union(hideIExpr.HideInterfaces));
            currentModuleInfo.Sends.AddEvents(componentModuleInfo.Sends.Events);
            currentModuleInfo.Receives.AddEvents(componentModuleInfo.Receives.Events);
            currentModuleInfo.Creates.AddInterfaces(componentModuleInfo.Creates.Interfaces);

            foreach (var monMap in componentModuleInfo.MonitorMap)
            {
                currentModuleInfo.MonitorMap[monMap.Key] = monMap.Value.ToList();
            }

            foreach (var linkMapItem in componentModuleInfo
                     .LinkMap)
            {
                currentModuleInfo.LinkMap[linkMapItem.Key] = new Dictionary <Interface, Interface>();
                foreach (var localLinkMap in linkMapItem.Value)
                {
                    currentModuleInfo.LinkMap[linkMapItem.Key].Add(localLinkMap.Key, localLinkMap.Value);
                }
            }

            foreach (var ipItem in componentModuleInfo.InterfaceDef)
            {
                currentModuleInfo.InterfaceDef.Add(ipItem.Key, ipItem.Value);
            }
        }