private bool AddImplicitConversion(EndpointKey fromEP, EndpointKey toEP, signals.IFunctionSpec convFunc) { Element newElm = new Element(convFunc); add(newElm); this.connections[fromEP] = new EndpointKey(newElm, 0); this.connections[new EndpointKey(newElm, 0)] = toEP; return(true); }
public void add(signals.IFunctionSpec func) { string key = func.Name; List <signals.IFunctionSpec> list; if (!funcs.TryGetValue(key, out list)) { list = new List <signals.IFunctionSpec>(); funcs.Add(key, list); } list.Add(func); }
public Element(signals.IFunctionSpec realSpec) { if (realSpec == null) { throw new ArgumentNullException("realSpec"); } type = ElementType.Function; name = realSpec.Name; nodeId = null; circuitId = 0; availObjects = new List <signals.ICircuitConnectible>(); availObjects.Add(realSpec); explicitAvail = true; }
public CppProxyFunction(signals.IFunctionSpec spec, IntPtr native) { if (spec == null) throw new ArgumentNullException("spec"); if (native == IntPtr.Zero) throw new ArgumentNullException("native"); m_nativeRef = native; m_spec = spec; Registration.storeObject(native, this); m_native = (Native.IFunction)CppNativeProxy.CreateCallout(native, typeof(Native.IFunction)); }
public void add(signals.IFunctionSpec realSpec) { add(new Element(realSpec)); }
private void resolveNeighbors(sharptest.ModLibrary library, Element elm) { if (elm.availObjects.Count != 1) { throw new ApplicationException("elm should contain a single availObject by this point"); } signals.ICircuitConnectible avail = elm.availObjects[0]; Dictionary <Element, bool> recurseList = new Dictionary <Element, bool>(); List <KeyValuePair <EndpointKey, EndpointKey> > tempCollect = new List <KeyValuePair <EndpointKey, EndpointKey> >(); tempCollect.AddRange(connections); foreach (KeyValuePair <EndpointKey, EndpointKey> entry in tempCollect) { EndpointKey key = entry.Key; EndpointKey value = entry.Value; if (key.elem == elm) { Element otherElm = value.elem; signals.EType ourType = key.OutputType(avail); bool changed = false; if (otherElm.availObjects.Count > 1) { // if we have more than one option here, just look for possible compatibility List <signals.ICircuitConnectible> newAvail = new List <signals.ICircuitConnectible>(); foreach (signals.ICircuitConnectible otherAvail in otherElm.availObjects) { signals.EType otherType = value.InputType(otherAvail); if (ourType != otherType && findImplicitConversion(library, ourType, otherType) == null) { changed = true; } else { newAvail.Add(otherAvail); } } otherElm.availObjects = newAvail; } if (otherElm.availObjects.Count == 1) { // if we're on one-to-one terms, we might add compat connections signals.ICircuitConnectible otherAvail = otherElm.availObjects[0]; signals.EType otherType = value.InputType(otherAvail); if (ourType != otherType) { signals.IFunctionSpec func = findImplicitConversion(library, ourType, otherType); if (func == null) { // only option isn't type-compatible? Looks like we broke a connection throw new LinkTypeFailure(entry.Key, ourType, entry.Value, otherType); } else { AddImplicitConversion(key, value, func); } } } else if (otherElm.availObjects.Count == 0) { // ran out of possible connections? Looks like we broke a connection throw new CannotResolveElement(otherElm); } if (changed) { recurseList.Add(value.elem, true); } } if (value.elem == elm) { Element otherElm = key.elem; signals.EType ourType = value.InputType(avail); bool changed = false; if (otherElm.availObjects.Count > 1) { // if we have more than one option here, just look for possible compatibility List <signals.ICircuitConnectible> newAvail = new List <signals.ICircuitConnectible>(); foreach (signals.ICircuitConnectible otherAvail in otherElm.availObjects) { signals.EType otherType = key.OutputType(otherAvail); if (ourType != otherType && findImplicitConversion(library, otherType, ourType) == null) { changed = true; } else { newAvail.Add(otherAvail); } } otherElm.availObjects = newAvail; } if (otherElm.availObjects.Count == 1) { // if we're on one-to-one terms, we might add compat connections signals.ICircuitConnectible otherAvail = otherElm.availObjects[0]; signals.EType otherType = key.OutputType(otherAvail); if (ourType != otherType) { signals.IFunctionSpec func = findImplicitConversion(library, otherType, ourType); if (func == null) { // only option isn't type-compatible? Looks like we broke a connection throw new LinkTypeFailure(entry.Key, otherType, entry.Value, ourType); } else { AddImplicitConversion(key, value, func); } } } else if (otherElm.availObjects.Count == 0) { // ran out of possible connections? Looks like we broke a connection throw new CannotResolveElement(otherElm); } if (changed) { recurseList.Add(value.elem, true); } } } foreach (KeyValuePair <Element, bool> entry in recurseList) { if (entry.Key.availObjects.Count == 1) { resolveNeighbors(library, entry.Key); } } }