예제 #1
0
        protected override void Validate(object AValue)
        {
            base.Validate(AValue);
            OperatorMatch LMatch = (OperatorMatch)AValue;

            if (IndexOf(LMatch) >= 0)
            {
                throw new SchemaException(SchemaException.Codes.DuplicateOperatorMatch, LMatch.Signature.Operator.Name);
            }
        }
예제 #2
0
 protected override void Removing(OperatorMatch tempValue, int index)
         #endif
 {
     if (!_isClearing)
     {
         ComputeBestNarrowingScore();
         ComputeBestMatches();
         _isMatchComputed = false;
     }
     //base.Removing(AValue, AIndex);
 }
예제 #3
0
        private void FindMatch()
        {
            _match = null;
            int exactCount = 0;

            foreach (OperatorMatch match in _bestMatches)
            {
                if (match.IsExact)
                {
                    exactCount++;
                    if (exactCount == 1)
                    {
                        _match = match;
                    }
                    else
                    {
                        _match = null;
                        break;
                    }
                }
                else if (match.IsPartial)
                {
                    if (_match == null)
                    {
                        if (match.PathLength == _shortestPathLength)
                        {
                            _match = match;
                        }
                    }
                    else
                    {
                        if (_match.PathLength == match.PathLength)
                        {
                            _match = null;
                            break;
                        }
                    }
                }
            }
        }
예제 #4
0
        protected override void Adding(OperatorMatch LMatch, int index)
        {
                #endif
            if (LMatch.IsMatch)
            {
                if (LMatch.NarrowingScore > _bestNarrowingScore)
                {
                    _bestNarrowingScore = LMatch.NarrowingScore;
                    ComputeBestMatches();
                }
                else if (LMatch.NarrowingScore == _bestNarrowingScore)
                {
                    _bestMatches.Add(LMatch);
                    if (LMatch.PathLength < _shortestPathLength)
                    {
                        _shortestPathLength = LMatch.PathLength;
                    }
                }
            }

            _isMatchComputed = false;

            //base.Adding(AValue, AIndex);
        }
예제 #5
0
        /*
         *      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);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #6
0
 protected override void Adding(object AValue, int AIndex)
 {
     OperatorMatch LMatch = (OperatorMatch)AValue;