static void createApplicationComponentAbstractInner(IList <object> body_items, IList <Tuple <string, string, EnvironmentPortType> > bindings_application, ref IList <string> port_names) { int port_count = 0; port_names = new List <string> (); foreach (Tuple <string, string, EnvironmentPortType> binding in bindings_application) { string componentRef = binding.Item1; string port_name = binding.Item2; // search for the type of the component connected to the application through the environment port AbstractComponentFunctor acf = backend.DGAC.BackEnd.acfdao.retrieve_libraryPath(componentRef); // search for the type of the environment port in the inner component. InnerComponent ic = backend.DGAC.BackEnd.icdao.retrieve(acf.Id_abstract, port_name); AbstractComponentFunctor acf_inner = backend.DGAC.BackEnd.acfdao.retrieve(ic.Id_abstract_inner); String library_path = acf_inner.Library_path; InnerComponentType ci = new InnerComponentType(); ci.package = acf_inner.Package; ci.name = acf_inner.Name; ci.localRef = port_name + (port_count++); ci.multiple = false; ci.exposed = true; port_names.Add(ci.localRef); body_items.Add(ci); } }
private CodeNamespaceImport[] createUsingDependencies() { IList <CodeNamespaceImport> using_dependencies_list = new List <CodeNamespaceImport>(); IList <Slice> slice_list = BackEnd.sdao.listByInterface(id_abstract, id_interface); foreach (Slice s in slice_list) { InnerComponent ic = BackEnd.icdao.retrieve(s.Id_abstract, s.Id_inner); IList <string> package_list = fetchPackages(ic.Id_functor_app); foreach (string package in package_list) { CodeNamespaceImport using_dependency = new CodeNamespaceImport(package); using_dependencies_list.Add(using_dependency); } } CodeNamespaceImport[] using_dependencies = new CodeNamespaceImport[using_dependencies_list.Count]; using_dependencies_list.CopyTo(using_dependencies, 0); return(using_dependencies); }
public override void Semantic() { //if(Name.ToLower() == Name) // Interpreter.semanticError.Add(new Error("#1001 Component class \"" + Name + "\" must start with big letter!", Interpreter.ErrorType.WARNING, Token)); if (_componentNotFound) { Interpreter.semanticError.Add(new Error("#1001 Component \"" + Name + "\" was not found!", Interpreter.ErrorType.ERROR, Token)); } if (_componentNotHaveConstructor) { Interpreter.semanticError.Add(new Error("#1002 Component \"" + Name + "\" must have constructor!", Interpreter.ErrorType.ERROR, Token)); } if (_componentNotHaveParent) { Interpreter.semanticError.Add(new Error("#1003 Component \"" + Name + "\" must inherit from class \"Component\"!", Interpreter.ErrorType.ERROR, Token)); } if (InnerComponent.Count > 0) { InnerComponent.ForEach(x => x.Semantic()); } Fun?.Semantic(); Arguments?.Any(x => { x.Value.Semantic(); return(false); }); }
private void loadInterfaces(AbstractComponentFunctor absC) { if (unit != null) { int count = 0; // for each interface ... foreach (UnitType u in unit) { string uRef = u.uRef; string iRef = u.iRef; string uRefSuper = u.super == null || u.super.Length == 0 ? "" : u.super[0].uRef; if (u.super != null) { for (int j = 1; j < u.super.Length; j++) { uRefSuper += "+" + u.super[j].uRef; } } InterfaceType ui = lookForInterface(iRef); int nargs = ui.nArgsSpecified ? ui.nArgs : 0; Console.Error.WriteLine("STEP 5.3"); Interface i = new Interface(); i.Id_abstract = absC.Id_abstract; i.Id_interface = uRef; // i.Unit_replica = unit_replica; i.Facet = u.facet; i.Id_interface_super = uRefSuper; i.Class_name = xc.header.packagePath + "." + xc.header.name + "." + iRef; i.Class_nargs = nargs; // TODO i.Assembly_string = i.Class_name + ", Culture=neutral, Version=0.0.0.0"; // In the current implementation, the name of the dll is the name of the class of the unit. i.Order = ++count; i.Is_parallel = u.multiple; Console.Error.WriteLine("STEP 5.4"); if (ui.parameter != null) { Console.Error.WriteLine("STEP 5.4 - " + ui.parameter); foreach (InterfaceParameterType ipx in ui.parameter) { Console.Error.WriteLine("STEP 5.4 BEGIN 1- " + ipx.parid); InterfaceParameter ip = new InterfaceParameter(); Console.Error.WriteLine("STEP 5.4 BEGIN 2- " + ipx.parid); ip.Id_abstract = i.Id_abstract; ip.Id_interface = i.Id_interface; ip.ParId = ipx.parid; ip.VarId = ipx.varid; ip.Id_interface_parameter = ipx.iname; ip.Id_unit_parameter = ipx.uname; ip.ParOrder = ipx.order; br.ufc.pargo.hpe.backend.DGAC.BackEnd.ipdao.insert(ip); Console.Error.WriteLine("STEP 5.4 END - " + ipx.parid); } } Console.Error.WriteLine("BEFORE STEP 5.5 " + (ui == null)); Console.Error.WriteLine("STEP 5.5 --- " + (ui.sources[ui.sources.Length - 1].file == null)); int order = 0; foreach (SourceFileType sft in ui.sources[ui.sources.Length - 1].file) { Console.Error.WriteLine("STEP 5.5.0"); SourceCode ss = new SourceCode(); ss.Type_owner = 'i'; ss.Id_owner_container = i.Id_abstract; ss.Id_owner = i.Id_interface; ss.Contents = sft.contents; ss.File_name = sft.name; ss.File_type = "dll"; ss.Order = order++; Console.Error.WriteLine("STEP 5.5.1"); br.ufc.pargo.hpe.backend.DGAC.BackEnd.scdao.insert(ss); int size = (sft.externalDependency == null ? 0 : sft.externalDependency.Length) + (ui.externalReferences == null ? 0 : ui.externalReferences.Length); Console.Error.WriteLine("STEP 5.5.2"); if (size > 0) { string[] allRefs = new string[size]; if (ui.externalReferences != null) { ui.externalReferences.CopyTo(allRefs, 0); } if (sft.externalDependency != null) { sft.externalDependency.CopyTo(allRefs, ui.externalReferences == null ? 0 : ui.externalReferences.Length); } Console.Error.WriteLine("STEP 5.5.3"); foreach (string extRef in allRefs) { Console.WriteLine("external reference = " + extRef); SourceCodeReference ssr = new SourceCodeReference(); ssr.Type_owner = ss.Type_owner; ssr.Id_owner_container = ss.Id_owner_container; ssr.Id_owner = ss.Id_owner; ssr.File_name = ss.File_name; ssr.Reference = extRef; if (br.ufc.pargo.hpe.backend.DGAC.BackEnd.scrdao.retrieve(ssr) == null) { br.ufc.pargo.hpe.backend.DGAC.BackEnd.scrdao.insert(ssr); } } Console.Error.WriteLine("STEP 5.5.4"); } } Console.Error.WriteLine("STEP 5.6"); br.ufc.pargo.hpe.backend.DGAC.BackEnd.idao.insert(i); if (u.slices != null) { IList <string> mS = new List <string>(); IList <String> mP = new List <string>(); IDictionary <string, UnitSliceType> m = new Dictionary <string, UnitSliceType>(); // 1st PASS: COLLECT ALL MAPPINGS SLICE/EXPOSED SLICES foreach (UnitSliceType uS in u.slices) { string sliceName = uS.sliceName; if (uS.port != null) { foreach (string portName in uS.port) { mS.Add(sliceName); mP.Add(portName); } } } // 2nd PASS: foreach (UnitSliceType uS in u.slices) { string sliceName = uS.sliceName; if (mP.Contains(sliceName) && !m.ContainsKey(sliceName)) { Console.Error.WriteLine("ADDING " + sliceName + " TO m"); m.Add(sliceName, uS); } } Console.Error.WriteLine("STEP 5.7"); // 3rd PASS: foreach (UnitSliceType uS in u.slices) { string sname = uS.sliceName; string cRefS = uS.cRef; string uRefS = uS.uRef; InnerComponentType innerC = lookForInnerComponent(cRefS); Console.Error.WriteLine("STEP 5.8"); InnerComponent inner = br.ufc.pargo.hpe.backend.DGAC.BackEnd.icdao.retrieve(absC.Id_abstract, cRefS); Console.Error.WriteLine("STEP 5.9 ---" + absC.Id_abstract + "," + cRefS); Interface iii = br.ufc.pargo.hpe.backend.DGAC.BackEnd.idao.retrieveTop(inner.Id_abstract_inner, uRefS); Console.Error.WriteLine("STEP 5.9.5 ---" + (iii == null)); Slice s = new Slice(); s.Id_abstract = absC.Id_abstract; s.Id_inner = innerC.localRef; s.Id_interface_slice = iii == null ? uRefS : iii.Id_interface; s.Id_interface = uRef; s.Transitive = mP.Contains(sname); Console.Error.WriteLine("STEP 5.10"); string property_name = uS.sliceName; string fstletter = property_name.Substring(0, 1); property_name = fstletter.ToUpper() + property_name.Substring(1, property_name.Length - 1); Console.Error.WriteLine("STEP 5.11"); s.PortName = property_name; if (!s.Transitive && uS.port != null) { Console.Error.WriteLine("STEP 5.12"); foreach (string pname in uS.port) { Console.Error.WriteLine("STEP 5.12.1 -- " + pname + ", " + (m.Count)); UnitSliceType usPort = null; m.TryGetValue(pname, out usPort); Console.Error.WriteLine("STEP 5.12.2 -- " + pname + ", " + (usPort == null)); Console.Error.WriteLine("STEP 5.12.5 -- " + usPort.cRef); InnerComponentType innerCPort = lookForInnerComponent(usPort.cRef); Console.Error.WriteLine("STEP 5.13"); InnerComponent inner2 = br.ufc.pargo.hpe.backend.DGAC.BackEnd.icdao.retrieve(absC.Id_abstract, usPort.cRef); Interface iii2 = br.ufc.pargo.hpe.backend.DGAC.BackEnd.idao.retrieveTop(inner2.Id_abstract_inner, usPort.uRef); SliceExposed se = new SliceExposed(); se.Id_abstract = s.Id_abstract; se.Id_inner = innerCPort.localRef; se.Id_inner_owner = s.Id_inner; se.Id_interface_slice_owner = s.Id_interface_slice_top; // mudado de s.Id_interface_slice em 28/06/2011 se.Id_interface_slice = iii2 == null ? usPort.uRef : iii2.Id_interface; // achar innerRenaming para cNewName = usPort.cRef e cRef = cRefS (uS.cRef) -- Id_inner_original = cOldName string id_inner_original = lookForRenamingOld(cRefS, usPort.cRef, usPort.inner_replica); se.Id_inner_original = id_inner_original != null ? id_inner_original : usPort.cRef; se.Id_interface_slice_original = usPort.uRef; // DEVE SER O TOP !!! if (br.ufc.pargo.hpe.backend.DGAC.BackEnd.sedao.retrieve2(se.Id_inner, se.Id_interface_slice, se.Id_abstract, se.Id_interface_slice_owner, se.Id_inner_owner) == null) { br.ufc.pargo.hpe.backend.DGAC.BackEnd.sedao.insert(se); } } } if (br.ufc.pargo.hpe.backend.DGAC.BackEnd.sdao.retrieve(s.Id_abstract, s.Id_inner, s.Id_interface_slice, s.Id_interface) == null) { br.ufc.pargo.hpe.backend.DGAC.BackEnd.sdao.insert(s); Console.WriteLine("SLICE REGISTERED " + s.Id_abstract + "/" + s.Id_inner + "/" + s.Id_interface_slice + " --- " + s.Id_interface); } else { Console.WriteLine("SLICE NOT REGISTERED " + s.Id_abstract + "/" + s.Id_inner + "/" + s.Id_interface_slice + " --- " + s.Id_interface); } } } //if (ui.protocol != null) readProtocol(i, ui); } } }
protected override HashComponent loadComponent_(ComponentType c) { // CREATE Component AbstractComponentFunctor c_ = new AbstractComponentFunctor(); c_.Id_abstract = Connector.nextKey("id_abstract", "abstractcomponentfunctor"); c_.Hash_component_UID = c.header.hash_component_UID; c_.Library_path = c.header.packagePath + "." + c.header.name; c_.Kind = c.header.kind.ToString(); if (c.header.baseType != null) { ExtensionTypeType extType = c.header.baseType.extensionType; ComponentInUseType baseC = null; if (extType.ItemElementName == ItemChoiceType.extends && extType.Item) { baseC = c.header.baseType.component; parameterRenamingSuper = baseC.parameter; AbstractComponentFunctorApplication baseCapp = newAbstractComponentFunctorApplication(baseC); // FOLLOW arrow subtype if (baseCapp == null) { throw new Exception("DEPLOY ERROR: Unresolved Dependency for base component (extends) : " + baseC.name); } c_.Id_functor_app_supertype = baseCapp.Id_functor_app; } br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfdao.insert(c_); // LOAD EXPOSED INNER COMPONENTS OF THE BASE if (baseC.port != null) { foreach (InnerComponentType port in baseC.port) { innerAll.Add(port); InnerComponent iNewPort = new InnerComponent(); iNewPort.Id_abstract_owner = c_.Id_abstract; string old_port_localRef = port.localRef; port.localRef = lookForRenamingNew(baseC.localRef, old_port_localRef, port.index_replica); iNewPort.Id_inner = port.localRef; iNewPort.Parameter_top = port.parameter_id; iNewPort.Transitive = true; iNewPort.IsPublic = true; iNewPort.Multiple = port.multipleSpecified ? port.multiple : false; AbstractComponentFunctorApplication appPort = newAbstractComponentFunctorApplication(port); if (appPort == null) { throw new Exception("DEPLOY ERROR: Unresolved Dependency for base component (public inner component) : " + port.name); } iNewPort.Id_functor_app = appPort.Id_functor_app; iNewPort.Id_abstract_inner = appPort.Id_abstract; InnerComponentExposed ice = new InnerComponentExposed(); ice.Id_abstract = c_.Id_abstract; ice.Id_inner_rename = iNewPort.Id_inner; ice.Id_inner_owner = null; ice.Id_inner = old_port_localRef; br.ufc.pargo.hpe.backend.DGAC.BackEnd.icedao.insert(ice); if (br.ufc.pargo.hpe.backend.DGAC.BackEnd.icdao.retrieve(iNewPort.Id_abstract_owner, iNewPort.Id_inner) == null) { br.ufc.pargo.hpe.backend.DGAC.BackEnd.icdao.insert(iNewPort); } } } } else { br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfdao.insert(c_); } loadAbstractComponentFunctorParameters(c_); return(c_); }
private void importInnerComponentsOfSuper(AbstractComponentFunctor absC, IList <InnerComponentType> includeAsInner) { Console.WriteLine("importInnerComponentsOfSupper : " + "START"); IDictionary <string, SupplyParameter> parsSuper = new Dictionary <string, SupplyParameter>(); // Inner components of the supertype. if (absC.Id_functor_app_supertype > 0) { AbstractComponentFunctorApplication acfa = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfadao.retrieve(absC.Id_functor_app_supertype); // It is a parameter in the subtype. Check if it is supplied in the type. IList <SupplyParameter> spList = br.ufc.pargo.hpe.backend.DGAC.BackEnd.spdao.list(acfa.Id_functor_app); foreach (SupplyParameter sp in spList) { Console.WriteLine("Adding to parSuper - key=" + sp.Id_parameter + ", value: " + sp.Id_functor_app + "/" + sp.Id_abstract + "/" + sp.Id_parameter); parsSuper.Add(sp.Id_parameter, sp); } IList <InnerComponent> iss = br.ufc.pargo.hpe.backend.DGAC.BackEnd.icdao.list(acfa.Id_abstract); Console.WriteLine("importInnerComponentsOfSuper: " + iss.Count + " - acfa.Id_abstract=" + acfa.Id_abstract); foreach (InnerComponent i in iss) //if (!i.IsPublic) { Console.WriteLine("importInnerComponentsOfSupper 1: " + i.Id_inner + " , " + i.Id_functor_app + " , " + (i.Parameter_top)); InnerComponent iNew = new InnerComponent(); if (i.Parameter_top != null && i.Parameter_top != "") { SupplyParameter sp = null; parsSuper.TryGetValue(i.Parameter_top, out sp); Console.WriteLine("importInnerComponentsOfSupper 2: " + i.Parameter_top + "," + i.Id_inner); if (sp is SupplyParameterComponent) { Console.WriteLine("importInnerComponentsOfSupper 3: " + "sp is SupplyParameterComponent"); // 1th CASE: It is not a parameter in the current component. // NOT YET TESTED !!! SupplyParameterComponent spc = (SupplyParameterComponent)sp; AbstractComponentFunctorApplication acfaReplace = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfadao.retrieve(spc.Id_functor_app_actual); if (br.ufc.pargo.hpe.backend.DGAC.BackEnd.icdao.retrieve(absC.Id_abstract, i.Id_inner) == null) { iNew.Id_abstract_inner = acfaReplace.Id_abstract; //iNew.Parameter_top = i.Parameter_top; // TODO: Testando ......... iNew.Id_abstract_owner = absC.Id_abstract; iNew.Id_functor_app = liftFunctorApp(acfaReplace.Id_functor_app, parsSuper); iNew.Id_inner = i.Id_inner; br.ufc.pargo.hpe.backend.DGAC.BackEnd.icdao.insert(iNew); } } else if (sp is SupplyParameterParameter) { Console.WriteLine("importInnerComponentsOfSupper 4: " + "sp is SupplyParameterParameter"); // 2nd CASE: It continues to be a parameter in the current component. SupplyParameterParameter spp = (SupplyParameterParameter)sp; String varName = null; foreach (ParameterRenaming pr in parameterRenamingSuper) { if (pr.formFieldId.Equals(i.Parameter_top)) { varName = pr.varName; ParameterType parameter = this.lookForParameterByVarName(varName); InnerComponentType cReplace = lookForInnerComponent(parameter.componentRef); //cReplace.localRef = i.Id_inner; cReplace.exposed = i.IsPublic; cReplace.multiple = i.Multiple; // cReplace.parameter_id = i.Parameter_top; // TODO: Testano includeAsInner.Add(cReplace); } } ParameterSupplyType supply = lookForSupplyForVarName(varName); if (supply != null) { InnerComponentType cReplace = lookForInnerComponent(supply.cRef); if (cReplace != null) { includeAsInner.Add(cReplace); } } } } else { // 3rd CASE: // NOT YET TESTED !!! iNew.Id_abstract_inner = i.Id_abstract_inner; iNew.Parameter_top = null; iNew.Id_abstract_owner = absC.Id_abstract; iNew.Id_functor_app = liftFunctorApp(i.Id_functor_app, parsSuper); iNew.Id_inner = i.Id_inner; iNew.IsPublic = i.IsPublic; br.ufc.pargo.hpe.backend.DGAC.BackEnd.icdao.insert(iNew); } } } Console.WriteLine("importInnerComponentsOfSuper : FINISH"); }
private void loadInnerComponents(AbstractComponentFunctor absC) { IList <InnerComponentType> includeAsInner = new List <InnerComponentType>(); IDictionary <string, InnerComponentType> innersByVarName = new Dictionary <string, InnerComponentType>(); if (parameter != null) { foreach (ParameterType ir in parameter) { InnerComponentType ic = this.lookForInnerComponent(ir.componentRef); if (ic == null) { Console.WriteLine("LOOK FOR INNER COMPONENT RETURNED NULL " + ir.componentRef); } if (!innersByVarName.ContainsKey(ir.varName)) { innersByVarName[ir.varName] = ic; } else { Console.WriteLine("ALREADY EXISTS - key=" + ir.varName + ", value=" + ic.localRef); } } } if (parameterSupply != null) { foreach (ParameterSupplyType ir in parameterSupply) { InnerComponentType ic = this.lookForInnerComponent(ir.cRef); if (!innersByVarName.ContainsKey(ir.varName)) { innersByVarName[ir.varName] = ic; } else { Console.WriteLine("ALREADY EXISTS - key=" + ir.varName + ", value=" + ic.localRef); } } } importInnerComponentsOfSuper(absC, includeAsInner); if (inner != null) { foreach (InnerComponentType c in inner) { Console.WriteLine("BEGIN loadInnerComponent : " + c.localRef + " :: " + c.package + "." + c.name); // innerAll.Add(c); if (((isNotInSupply(c) || this.findInSlices(c.localRef)) && (isNotParameter(c) || this.findInSlices(c.localRef))) || includeAsInner.Contains(c)) { // CREATE INNER COMPONENT InnerComponent iNew = new InnerComponent(); iNew.Id_abstract_owner = absC.Id_abstract; iNew.Id_inner = c.localRef; // localRef is used to uniquely identify the inner component among the inner components.... // FOLLOW arrow has-parameters AbstractComponentFunctorApplication app = newAbstractComponentFunctorApplication(c); if (app == null) { throw new Exception("DEPLOY ERROR: Unresolved Dependency for base component (inner component) : " + c.name); } iNew.Id_functor_app = app.Id_functor_app; iNew.Id_abstract_inner = app.Id_abstract; // CHECKS IF IT IS A TOP PARAMETER ParameterType p = lookForParameterByCRef(c.localRef); iNew.Parameter_top = p != null ? p.formFieldId : null; iNew.Transitive = false; iNew.IsPublic = c.exposed; iNew.Multiple = c.multipleSpecified ? c.multiple : false; // LOAD EXPOSED INNER COMPONENTS if (c.port != null) { foreach (InnerComponentType port in c.port) { Console.WriteLine("loadInnerComponent - BEGIN PORT " + port.localRef); // -------------------------------------------------- string varName = null; int id_abstract_port = app.Id_abstract; string id_inner_port = port.localRef; InnerComponent ic_port = br.ufc.pargo.hpe.backend.DGAC.BackEnd.icdao.retrieve(id_abstract_port, id_inner_port); Console.WriteLine("loadInnerComponent - STEP 1"); if (c.parameter != null && ic_port != null) { foreach (ParameterRenaming par in c.parameter) { Console.WriteLine("loadInnerComponent - STEP 2 begin " + par.formFieldId + " - " + par.varName); if (par.formFieldId.Equals(ic_port.Parameter_top)) { varName = par.varName; } Console.WriteLine("loadInnerComponent - STEP 2 end " + par.formFieldId + " - " + par.varName); } } InnerComponentType port_replace = port; if (varName != null) { Console.WriteLine("loadInnerComponent - STEP 3 " + varName); foreach (KeyValuePair <string, InnerComponentType> iii in innersByVarName) { Console.WriteLine("loadInnerComponent x " + iii.Key); Console.WriteLine("loadInnerComponent y " + (iii.Value == null)); Console.WriteLine("loadInnerComponent z " + c.package); Console.WriteLine("loadInnerComponent w " + c.name); } port_replace = innersByVarName[varName]; } else { Console.WriteLine("loadInnerComponent - STEP 3 "); } // -------------------------------------------------- innerAll.Add(port); InnerComponent iNewPort = new InnerComponent(); iNewPort.Id_abstract_owner = absC.Id_abstract; string old_port_localRef = port.localRef; port.localRef = lookForRenamingNew(c.localRef, old_port_localRef, port.index_replica); iNewPort.Id_inner = port.localRef; iNewPort.Parameter_top = port_replace.parameter_id; iNewPort.Transitive = true; iNewPort.IsPublic = port.exposed; iNewPort.Multiple = port.multipleSpecified ? port.multiple : false; AbstractComponentFunctorApplication appPort = newAbstractComponentFunctorApplication(port_replace); if (appPort == null) { throw new Exception("DEPLOY ERROR: Unresolved Dependency for base component (public inner component) : " + port.name); } iNewPort.Id_functor_app = appPort.Id_functor_app; iNewPort.Id_abstract_inner = appPort.Id_abstract; InnerComponentExposed ice = new InnerComponentExposed(); ice.Id_abstract = absC.Id_abstract; ice.Id_inner_rename = iNewPort.Id_inner; ice.Id_inner_owner = iNew.Id_inner; ice.Id_inner = old_port_localRef; br.ufc.pargo.hpe.backend.DGAC.BackEnd.icedao.insert(ice); InnerComponent ic_port_exists = br.ufc.pargo.hpe.backend.DGAC.BackEnd.icdao.retrieve(iNewPort.Id_abstract_owner, iNewPort.Id_inner); if (ic_port_exists == null && (fusion == null || !fusion.ContainsKey(port.localRef) || (fusion.ContainsKey(port.localRef) && fusion[port.localRef].Equals(c.localRef)))) { br.ufc.pargo.hpe.backend.DGAC.BackEnd.icdao.insert(iNewPort); } Console.WriteLine("loadInnerComponent - END PORT " + port.localRef); } } InnerComponent ic = br.ufc.pargo.hpe.backend.DGAC.BackEnd.icdao.retrieve(iNew.Id_abstract_owner, iNew.Id_inner); if (ic != null && includeAsInner.Contains(c)) { Console.WriteLine("loadInnerComponent - BLOCK 2 OPEN"); br.ufc.pargo.hpe.backend.DGAC.BackEnd.icdao.remove(iNew.Id_abstract_owner, iNew.Id_inner); br.ufc.pargo.hpe.backend.DGAC.BackEnd.icdao.insert(iNew); Console.WriteLine("loadInnerComponent - BLOCK 2 CLOSE"); } else if (ic == null) { Console.WriteLine("loadInnerComponent - BLOCK 3 OPEN"); br.ufc.pargo.hpe.backend.DGAC.BackEnd.icdao.insert(iNew); Console.WriteLine("loadInnerComponent - BLOCK 3 CLOSE"); } } Console.WriteLine("END loadInnerComponent : " + c.localRef + " :: " + c.package + "." + c.name); } } }
private InterfaceSignature calculateParameters(Interface i, IDictionary <string, int> closed_pars, IDictionary <string, string> open_pars) { // id_abstract, id_interface, partition_index, id_interface_super, partition_index_super, uri_source, class_nargs, id_interface_super_top, partition_index_super_top, order // '43', 'compute_rhs', '0', '', '0', 'adi.ComputeRHS.IComputeRHS', '', '2', 'compute_rhs', '0', '1' InterfaceSignature isig; AbstractComponentFunctor acf = (AbstractComponentFunctor)BackEnd.acfdao.retrieve(i.Id_abstract); isig.package_path = acf.Library_path; isig.the_interface = i; isig.parameters = new Dictionary <string, InterfaceSignature>(); isig.varId = new Dictionary <string, string>(); isig.slice_types = new Dictionary <string, InterfaceSignature>(); IList <Slice> slice_list = BackEnd.sdao.listByInterface(i.Id_abstract, i.Id_interface); // id_abstract, id_inner, id_interface_slice, partition_index, id_interface, property_name, transitive // '43', 'cells_info', 'cells', '0', 'compute_rhs', 'Cells', '0' // '43', 'problem_data', 'problem', '0', 'compute_rhs', 'Problem', '0' foreach (Slice s in slice_list) { InnerComponent ic = BackEnd.icdao.retrieve(s.Id_abstract, s.Id_inner); // id_abstract_owner, id_functor_app, id_inner, id_abstract_inner, parameter_top, transitive, public // 1st loop: // '43', '131', 'cells_info', '31', '', '0', '-1' // 2nd loop: // '43', '132', 'problem_data', '40', '', '0', '-1' int id_functor_app_actual = ic.Id_functor_app; // 1st loop: id_functor_app_actual = 131 // 2nd loop: id_functor_app_actual = 132 Interface i_ = BackEnd.idao.retrieve(ic.Id_abstract_inner, s.Id_interface_slice); // id_abstract, id_interface, partition_index, id_interface_super, partition_index_super, uri_source, class_nargs, id_interface_super_top, partition_index_super_top, order // 1st loop: // '31', 'cells', '0', '', '0', 'common.datapartition.MultiPartitionCells.ICells', '', '0', 'cells', '0', '1', NULL, NULL, NULL // 2nd loop: // '40', 'problem', '0', '', '0', 'adi.data.ProblemDefinition.IProblemDefinition', '', '2', 'problem', '0', '1', NULL, NULL, NULL if (!ic.Parameter_top.Equals("")) // 1st loop: FALSE 2nd loop: FALSE { if (closed_pars.ContainsKey(ic.Parameter_top)) { id_functor_app_actual = closed_pars[ic.Parameter_top]; } InterfaceParameter ip = BackEnd.ipdao.retrieve(i.Id_abstract, i.Id_interface, ic.Parameter_top); AbstractComponentFunctorApplication acfa = BackEnd.acfadao.retrieve(id_functor_app_actual); i_ = BackEnd.idao.retrieveTop(acfa.Id_abstract, ip.Id_unit_parameter); } IList <string> parameters = new List <string>(); IDictionary <string, int> closed_pars_ = new Dictionary <string, int>(); IDictionary <string, string> open_pars_ = new Dictionary <string, string>(); IList <SupplyParameter> sp_list = BackEnd.spdao.list(id_functor_app_actual); // id_parameter, id_functor_app, id_abstract // 1st loop: empty // 2nd loop: // 'class', '132', '40' // 'instance_type', '132', '40' foreach (SupplyParameter sp in sp_list) { if (sp is SupplyParameterComponent) // always false { SupplyParameterComponent spc = (SupplyParameterComponent)sp; if (!closed_pars_.ContainsKey(spc.Id_parameter)) { closed_pars_.Add(spc.Id_parameter, spc.Id_functor_app_actual); } } else if (sp is SupplyParameterParameter) { SupplyParameterParameter spp = (SupplyParameterParameter)sp; // id_parameter, id_functor_app, id_parameter_actual, freeVariable // 2nd outer loop / 1st inner loop: // 'class', '132', 'class', '0' // 2nd outer loop / 2nd inner loop // 'instance_type', '132', 'instance_type', '0' int id_functor_app_actual_parameter; if (closed_pars.ContainsKey(spp.Id_argument)) // ALWAYS FALSE { id_functor_app_actual_parameter = closed_pars[spp.Id_argument]; if (!closed_pars_.ContainsKey(spp.Id_parameter)) { closed_pars_.Add(spp.Id_parameter, id_functor_app_actual_parameter); } } else if (open_pars.ContainsKey(spp.Id_argument)) { if (!open_pars_.ContainsKey(spp.Id_parameter)) { open_pars_.Add(spp.Id_parameter, open_pars[spp.Id_argument]); } // 2nd outer loop / 1st inner loop: add 'class' -> 'C' // 2nd outer loop / 2nd inner loop: add 'instance_type' -> 'I' } else { // NEVER REACH THIS ARM ... } parameters.Add(spp.Id_parameter); // 2nd outer loop / 1st inner loop: add 'class' // 2nd outer loop / 2nd inner loop: add 'instance_type' } } InterfaceSignature par_ic = calculateParameters(i_, closed_pars_, open_pars_); if (!isig.slice_types.ContainsKey(s.PortName)) { isig.slice_types.Add(s.PortName, par_ic); } else { Console.WriteLine("EXISTENTE {0}", s.PortName); } // 1st loop: // InterfaceSignature [ // the_interface = ('31', 'cells', '0', '', '0', 'common.datapartition.MultiPartitionCells.ICells', '', '0', 'cells', '0', '1') // parameters = {} // parId = {} // ] // 2nd loop: // InterfaceSignature [ // the_interface = ('40', 'problem', '0', '', '0', 'adi.data.ProblemDefinition.IProblemDefinition', '', '2', 'problem', '0', '1') // parameters = {C -> InterfaceSignature [ IClass ... ] , I -> InterfaceSignature [ IInstance ... ]} // parId = {C -> class, I -> instance_type} // ] foreach (KeyValuePair <string, InterfaceSignature> is_par in par_ic.parameters) { string par_id = is_par.Key; // 2nd outer loop / 1st inner loop: var_id = C, par_id = class // 2nd outer loop / 2nd inner loop: var_id = I, par_id = instance_type if (parameters.Contains(par_id)) { if (!isig.parameters.ContainsKey(par_id)) { isig.parameters.Add(par_id, is_par.Value); } else { ; } // 2nd outer loop / 1st inner loop: add (class, InterfaceSignature [ IClass ... ]) // 2nd outer loop / 2nd inner loop: add (instance_type, InterfaceSignature [ IInstance[C] ... ]) if (open_pars_.ContainsKey(par_id) && !isig.varId.ContainsKey(par_id)) { isig.varId.Add(par_id, open_pars_[par_id]); } // 2nd outer loop / 1st inner loop: add (class, C) // 2nd outer loop / 2nd inner loop: add (instance_type, I) } } if (!ic.Parameter_top.Equals("")) // never { if (isig.parameters.ContainsKey(ic.Parameter_top)) { isig.parameters.Remove(ic.Parameter_top); } isig.parameters.Add(ic.Parameter_top, par_ic); if (open_pars.ContainsKey(ic.Parameter_top)) { if (isig.varId.ContainsKey(ic.Parameter_top)) { isig.varId.Remove(ic.Parameter_top); } isig.varId.Add(ic.Parameter_top, open_pars[ic.Parameter_top]); } } } return(isig); }
public string Compile(int tabs = 0, bool iret = false) { var tbs = DoTabs(tabs); string ret = ""; if (assignTo != "") { var func = (Function)assingBlock.SymbolTable.Get(assignTo); if (func.attributes?.Where(x => x.GetName(true) == "Debug").Count() > 0) { ret += "/*Component: " + Name + "*/"; } } var _oname = Name; /*if (_rewr.ContainsKey(_name) && (!iret || _inner.Count > 0 )) * _name = _rewr[_name];*/ var txt = InnerText.Replace("\r\n", "").Replace("\t", ""); Regex re = new Regex(@"\{(.*)\}"); var replace = re.Replace(txt, x => { var s = x.Value.Substring(1, x.Value.Length - 2); var find = assingBlock.SymbolTable.Get(s); if (assingBlock.assingToType?.assignTo != null) { var _class = assingBlock.SymbolTable.Get(assingBlock.assingToType?.assignTo); if (_class is Class cls) { var parent = cls.GetParent(); find = parent.assingBlock.SymbolTable.Get(s); } } if (find is Variable) { return("\"+" + s + "+\""); } else if (find is Function) { return("fun"); } else if (find is Assign fa) { return("\"+" + s + "+\""); } else if (find is Class) { return("\"+" + s.Replace("this", "_this") + "+\""); } return(""); }); var pou = ""; foreach (var p in Arguments) { if (p.Value is Assign pa) { if (pa.Left is Variable pav) { var cml = p.Value.Compile(); pou += "" + p.Key + ": " + cml.Replace("this", "_this") + ", "; //args += "{name: \"" + pav.Value + "\", value: " + cml + "}, "; } } else if (p.Value is Variable pv) { var cml = p.Value.Compile(); if (Char.IsLetterOrDigit(p.Key[0])) { pou += "" + p.Key + ": "; } else { pou += "\"" + p.Key + "\": "; } if ((p.Key.Substring(0, 2) != "on" && cml.Contains("this"))) { pou += "function(){ return " + cml.Replace("this", "_this") + "; }, "; } else { pou += cml.Replace("this", "_this") + ", "; } //args += "{name: \"" + pv.Value + "\", value: " + cml + "}, "; } else if (p.Value is Lambda arl) { arl.endit = false; arl.replaceThis = "_this"; var cml = arl.Compile(); if (Char.IsLetterOrDigit(p.Key[0])) { pou += "" + p.Key + ": " + cml.Replace("this", "_this").Replace("__this", "_this") + ", "; } else { pou += "\"" + p.Key + "\": " + cml.Replace("this", "_this").Replace("__this", "_this") + ", "; } } else { if (Char.IsLetterOrDigit(p.Key[0])) { pou += "" + p.Key + ": " + p.Value.Compile().Replace("this", "_this") + ", "; } else { pou += "\"" + p.Key + "\": " + p.Value.Compile().Replace("this", "_this") + ", "; } } } if (pou != "") { pou = pou.Substring(0, pou.Length - 2); } if (Name == "") { var tb0 = DoTabs(iret ? 0 : tabs); if (Fun == null) { ret += tb0 + "\"" + replace + "\""; } else { if (Fun is UnaryOp fu && fu.Op == "call") { fu.endit = false; //ret += tb0 + Fun.Compile().Replace("this", "_this"); } //else ret += tb0 + "function(){ return " + Fun.Compile().Replace("this", "_this").Replace("__this", "_this") + "; }"; } } else if (InnerComponent.Count > 0) { var tb0 = DoTabs(iret ? 0 : tabs); var tb1 = DoTabs(iret ? tabs + 2 : tabs + 1); var hm0 = iret ? tabs + 2 : tabs + 1; if (_base.Contains(_oname) || _oname.ToLower() == _oname) { var f = assingBlock.SymbolTable.Get(Name); if (f is Error) { ret += tb0 + "new Pyr.createElement(\r\n" + tb1 + "\"" + _oname + "\""; } else { ret += tb0 + "new Pyr.createElement(\r\n" + tb1 + "" + _oname + ""; } } else { ret += tb0 + "new Pyr.createElement(\r\n" + tb1 + Name; } if (pou != "") { ret += ",\r\n" + tb1 + "{ " + pou + " }, \r\n"; } else { ret += ",\r\n" + tb1 + "null, \r\n"; } InnerComponent.ForEach(x => { ret += x.Compile(hm0, false) + ", \r\n"; }); ret = ret.Substring(0, ret.Length - 4); ret += "\r\n" + tb0 + ")"; } else { var tb0 = DoTabs(iret ? 0 : tabs); if (_base.Contains(_oname) || _oname.ToLower() == _oname) { ret += tb0 + "new Pyr.createElement(" + "\"" + _oname + "\""; } else { var fncreate = assingBlock.SymbolTable.Get("constructor " + Name); if (fncreate is Error) { _componentNotHaveConstructor = true; if (assingBlock.SymbolTable.Get(Name) is Error) { _componentNotHaveConstructor = false; _componentNotFound = true; } return(""); } else { var cls = assingBlock.SymbolTable.Get(Name); if (cls is Class clss) { if (clss.GetParent()?.Name.Value != "Component") { _componentNotHaveParent = true; return(""); } } } if (fncreate is Function fa) { ret += tb0 + "new Pyr.createElement(" + Name + "." + fa.Name; } else { ret += tb0 + "new Pyr.createElement(" + Name; } } if (pou != "") { ret += ", { " + pou + " }, "; } else { ret += ", null, "; } if (replace != "") { ret += "\"" + replace + "\""; } else { ret += "null"; } ret += ")"; } if (IsStart) { return("var _this = this;\r\n" + DoTabs(tabs + 1) + "return " + ret + ";"); } if (iret) { return("return " + ret + ";"); } return(ret); }