/// <summary>Constructs an exact or partial match, depending on the value of AIsExact.</summary> public OperatorMatch(OperatorSignature signature, bool isExact) : base() { Signature = signature; _conversionContexts = new ConversionContext[signature.Signature.Count]; _canConvert = new BitArray(signature.Signature.Count); IsExact = isExact; IsMatch = true; }
/// <summary>Constructs a potential match.</summary> public OperatorMatch(OperatorSignature signature) : base() { Signature = signature; _conversionContexts = new ConversionContext[signature.Signature.Count]; _canConvert = new BitArray(signature.Signature.Count); for (int index = 0; index < _canConvert.Length; index++) { _canConvert[index] = true; } }
/* * Insertion Algorithm -> * for each signature * if the signature being added is the signature * add the signature to this signature * else if the signature is the signature being added * for each signature in this list * if the signature is the signature being added * remove it from this list * add it to the signature being added * add all child signatures of signatures in this list to the signature, if applicable * add the signature to this list * if the signature has not yet been added * add all child signatures of signatures in this list to the signature, if applicable * add the signature to this list */ //public override int Add(object AValue) public void Add(OperatorSignature signature) { #if USETYPEINHERITANCE bool added = false; int index; for (index = 0; index < Count; index++) { if (ASignature.Signature.Equals(this[index].Signature)) { continue; } else if (ASignature.Signature.Is(this[index].Signature)) { if (!this[index].Signatures.Contains(ASignature)) { this[index].Signatures.Add(ASignature); } added = true; } else if (this[index].Signature.Is(ASignature.Signature)) { if (!Contains(ASignature)) { for (int innerIndex = Count - 1; innerIndex >= 0; innerIndex--) { if (this[innerIndex].Signature.Is(ASignature.Signature)) { if (!ASignature.Signatures.Contains(this[innerIndex].Signature)) { ASignature.Signatures.Add(InternalRemoveAt(innerIndex)); } else { InternalRemoveAt(innerIndex); } } } InternalAdd(ASignature); } added = true; } } if (!added) { InternalAdd(ASignature); } Adding(AValue, index); return(index); #endif _signatures.Add(signature.Signature, signature); }
public OperatorSignature ResolveInherited(Signature ASignature) { OperatorSignature LSignature = Resolve(ASignature, false); if (LSignature == null) { return(null); } else { if (LSignature.ParentSignatures.Count == 1) { return((OperatorSignature)LSignature.ParentSignatures[0]); } else { throw new SchemaException(SchemaException.Codes.AmbiguousInheritedCall, LSignature.Operator.Name); } } }
public bool Contains(OperatorSignature signature) { return(Contains(signature.Signature)); }
/* * Resolution Algorithm -> * if the signature is in this list * return the operator signature * else * for each signature in this list * if the given signature is the signature * return the Resolve on the signature * return null */ public void Resolve(Plan plan, OperatorBindingContext context) { OperatorSignature resultSignature = null; if (_signatures.TryGetValue(context.CallSignature, out resultSignature)) { if (!context.Matches.Contains(resultSignature)) { context.Matches.Add(new OperatorMatch(resultSignature, true)); } } else { foreach (KeyValuePair <Signature, OperatorSignature> entry in _signatures) { var signature = entry.Value; if (context.CallSignature.Is(signature.Signature)) { int matchCount = context.Matches.Count; signature.Signatures.Resolve(plan, context); if (context.Matches.IsExact) { break; } else if (matchCount == context.Matches.Count) { if (!context.Matches.Contains(signature)) { OperatorMatch match = new OperatorMatch(signature, false); for (int index = 0; index < signature.Signature.Count; index++) { match.CanConvert[index] = true; } context.Matches.Add(match); } } } else { if (context.CallSignature.Count == signature.Signature.Count) { if (!context.Matches.Contains(signature)) { OperatorMatch match = new OperatorMatch(signature); bool addMatch = true; match.IsMatch = true; for (int elementIndex = 0; elementIndex < context.CallSignature.Count; elementIndex++) { match.CanConvert[elementIndex] = context.CallSignature[elementIndex].DataType.Is(signature.Signature[elementIndex].DataType); if (!match.CanConvert[elementIndex] && (context.CallSignature[elementIndex].Modifier != Modifier.Var) && (signature.Signature[elementIndex].Modifier != Modifier.Var)) { match.ConversionContexts[elementIndex] = Compiler.FindConversionPath(plan, context.CallSignature[elementIndex].DataType, signature.Signature[elementIndex].DataType); match.CanConvert[elementIndex] = match.ConversionContexts[elementIndex].CanConvert; // As soon as the match being constructed is more narrowing or longer than the best match found so far, it can be safely discarded as a candidate. if ((match.NarrowingScore < context.Matches.BestNarrowingScore) || ((match.NarrowingScore == context.Matches.BestNarrowingScore) && (match.PathLength > context.Matches.ShortestPathLength))) { addMatch = false; break; } } if (!match.CanConvert[elementIndex]) { match.IsMatch = false; } } if (addMatch) { context.Matches.Add(match); } } } } } } }
public void Remove(OperatorSignature signature) { Remove(signature.Signature); }
public OperatorSignatures(OperatorSignature signature) : base() { _signature = signature; }
public Operator ResolveInheritedSignature(Signature ASignature) { OperatorSignature LSignature = FSignatures.ResolveInherited(ASignature); return(LSignature != null ? LSignature.Operator : null); }
public int IndexOf(OperatorSignature signature) { return(IndexOf(signature.Operator)); }