Example #1
0
 public DummyInstructionPattern(DummyOpCode opCode, params Pattern <object>[] operands)
 {
     OpCode = new LiteralPattern <DummyOpCode>(opCode);
     foreach (var operand in operands)
     {
         Operands.Add(operand);
     }
 }
Example #2
0
 public DummyInstructionPattern(DummyOpCode opCode)
 {
     OpCode = new LiteralPattern <DummyOpCode>(opCode);
 }
Example #3
0
            /// <summary>
            /// Return the coercion (union) of the two patterns
            /// </summary>
            /// <param name="p">the pattern to coerce</param>
            /// <returns>the new pattern.</returns>
            public Pattern Coerce(Pattern p)
            {
                if (p is WildcardPattern)
                    return p;
                else if (p is RangePattern)
                    return new EmptyPattern();
                else if (p is ListPattern)
                    return new ListPattern(this, p as ListPattern);
                else if (p is LiteralPattern)
                {
                    LiteralPattern litP = p as LiteralPattern;
                    bool fFound = false;
                    for (int i = 0; fFound == false && i < Values.Length; i++)
                        fFound = Values[i].Equals(litP.Value);

                    if (fFound)
                        return this;
                    else
                    {
                        List<object> lpNew = new List<object>(Values);
                        lpNew.Add(litP.Value);
                        LiteralPattern[] rgNew = new LiteralPattern[lpNew.Count];
                        lpNew.CopyTo(rgNew);
                        return new ListPattern(rgNew);
                    }
                }
                else
                    return new EmptyPattern();
            }
Example #4
0
            /// <summary>
            /// Return the coercion of the two patterns
            /// </summary>
            /// <param name="p">the pattern to coerce</param>
            /// <returns>the new pattern.</returns>
            public Pattern Coerce(Pattern p)
            {
                if (p is WildcardPattern)
                    return p;
                else if (p is RangePattern)
                {
                    RangePattern rp = p as RangePattern;
                    if (((IComparable)rp.MinValue).CompareTo(Value) < 0 && ((IComparable)rp.MaxValue).CompareTo(Value) > 0)
                        return rp;
                    else
                        return new EmptyPattern();
                }
                else if (p is ListPattern)
                {
                    ListPattern listP = p as ListPattern;
                    bool fFound = false;
                    for (int i = 0; i < listP.Values.Length && fFound == false; i++)
                        fFound = (listP.Values[i] == Value);

                    if (!fFound)
                    {
                        List<object> lpNew = new List<object>(listP.Values);
                        lpNew.Add(this.Value);
                        object[] rgNew = new object[lpNew.Count];
                        lpNew.CopyTo(rgNew);
                        return new ListPattern(rgNew);
                    }
                    else
                        return p;
                }
                else if (p is LiteralPattern)
                {
                    LiteralPattern lp = p as LiteralPattern;
                    if (lp.Value == Value)
                        return this;
                    else
                    {
                        LiteralPattern[] rglpNew = new LiteralPattern[2];
                        rglpNew[0] = lp; rglpNew[1] = this;
                        return new ListPattern(rglpNew);
                    }
                }
                else if (p is EmptyPattern)
                    return this;
                else
                    return new EmptyPattern();
            }
Example #5
0
 private List<Punctuation> Flatten(Punctuation p, int iAttr, List<Punctuation> ret)
 {
     if (iAttr == p.Count)
     {
         return ret;
     }
     else
     {
         if (p[iAttr] is Punctuation.RangePattern)
             return null;
         else if (p[iAttr] is Punctuation.LiteralPattern || p[iAttr] is Punctuation.WildcardPattern)
             return Flatten(p, iAttr + 1, ret);
         else //ListPattern
         {
             for (int i = 0; i < ret.Count; i++)
             {
                 for (int j = 0; j < ((ListPattern)ret[i][iAttr]).Values.Length; j++)
                 {
                     Punctuation pRet = ret[i].Copy();
                     pRet[iAttr] = new LiteralPattern(((ListPattern)ret[i][iAttr]).Values[j]);
                     ret.Insert(i + j + 1, pRet);
                 }
                 ret.RemoveAt(i);
                 i += ((ListPattern)p[iAttr]).Values.Length - 1;
             }
             return Flatten(p, iAttr + 1, ret);
         }
     }
 }