public override bool Unify(IRExpression template, Dictionary <IRVariable, IRExpression> varMapping)
        {
            if (template is IRVariable templateVar && templateVar.Type == Type)
            {
                if (varMapping.ContainsKey(templateVar))
                {
                    return(varMapping[templateVar].Equals(this));
                }
                varMapping[templateVar] = this;
                return(true);
            }

            if (!(template is IRCallExpression exp) || exp.TargetName != TargetName ||
                !exp.Type.Equals(Type) || exp.Arguments.Count != Arguments.Count)
            {
                return(false);
            }
            for (int i = 0; i < Arguments.Count; i++)
            {
                if (!Arguments[i].Unify(exp.Arguments[i], varMapping))
                {
                    return(false);
                }
            }
            return(true);
        }
 public override void Substitute(IRVariable variable, IRExpression expression)
 {
     if (ReferenceEquals(Pointer, variable))
     {
         Pointer = expression.CloneComplete();
     }
     else
     {
         Pointer.Substitute(variable, expression);
     }
 }
示例#3
0
 public override bool Unify(IRExpression template, Dictionary <IRVariable, IRExpression> varMapping)
 {
     if (!(template is IRVariable exp) || !exp.Type.Equals(Type))
     {
         return(false);
     }
     if (varMapping.ContainsKey(exp))
     {
         return(varMapping[exp].Equals(this));
     }
     varMapping[exp] = this;
     return(true);
 }
 public override void Substitute(IRVariable variable, IRExpression expression)
 {
     for (int i = 0; i < Arguments.Count; i++)
     {
         if (ReferenceEquals(Arguments[i], variable))
         {
             Arguments[i] = expression.CloneComplete();
         }
         else
         {
             Arguments[i].Substitute(variable, expression);
         }
     }
 }
        public override bool Unify(IRExpression template, Dictionary <IRVariable, IRExpression> varMapping)
        {
            if (template is IRVariable templateVar && templateVar.Type == Type)
            {
                if (varMapping.ContainsKey(templateVar))
                {
                    return(varMapping[templateVar].Equals(this));
                }
                varMapping[templateVar] = this;
                return(true);
            }

            if (!(template is IRDerefExpression exp) || !exp.Type.Equals(Type))
            {
                return(false);
            }
            return(Pointer.Unify(exp.Pointer, varMapping));
        }
        public override void Substitute(IRExpression template, IRExpression substitution, OnMatchFoundHandler callback)
        {
            Pointer.Substitute(template, substitution, callback);
            var mapping = new Dictionary <IRVariable, IRExpression>();

            if (Pointer.Unify(template, mapping) && callback(mapping))
            {
                if (substitution is IRVariable v)
                {
                    Pointer = mapping[v].CloneComplete();
                }
                else
                {
                    var newExpr = substitution.CloneComplete();
                    foreach (var varMap in mapping)
                    {
                        newExpr.Substitute(varMap.Key, varMap.Value);
                    }
                    Pointer = newExpr;
                }
            }
        }
示例#7
0
 public IRComparisonExpression UnsignedLessThan(IRExpression b)
 => new IRComparisonExpression(IRComparisonOperator.UnsignedLess, this, b);
示例#8
0
 public abstract void Substitute(IRExpression template, IRExpression substitution, OnMatchFoundHandler callback);
示例#9
0
 public void Substitute(IRExpression template, IRExpression substitution)
 {
     Substitute(template, substitution, _ => true);
 }
示例#10
0
 public abstract bool Unify(IRExpression template, Dictionary <IRVariable, IRExpression> varMapping);
示例#11
0
 public IRComparisonExpression UnsignedGreaterEqualAs(IRExpression b)
 => new IRComparisonExpression(IRComparisonOperator.UnsignedGreaterEqual, this, b);
示例#12
0
 public abstract void Substitute(IRVariable variable, IRExpression expression);
示例#13
0
 public IRComparisonExpression GreaterThan(IRExpression b)
 => new IRComparisonExpression(IRComparisonOperator.Greater, this, b);
 public IRDerefExpression(IRType type, IRExpression pointer)
     : base(type)
 {
     Pointer = pointer;
 }
示例#15
0
 public override void Substitute(IRExpression template, IRExpression substitution, OnMatchFoundHandler callback)
 {
 }
示例#16
0
 public IRBinaryExpression ShiftRightArithmetic(IRExpression amount)
 => new IRBinaryExpression(Type, IRBinaryOperator.Asr, this, amount.Cast(Type));
示例#17
0
 public IRBinaryExpression ShiftRightLogical(IRExpression amount)
 => new IRBinaryExpression(Type, IRBinaryOperator.Lsr, this, amount.Cast(Type));
示例#18
0
 public IRBinaryExpression ShiftLeft(IRExpression amount)
 => new IRBinaryExpression(Type, IRBinaryOperator.Lsl, this, amount.Cast(Type));
示例#19
0
 public override void Substitute(IRVariable variable, IRExpression expression)
 {
 }
示例#20
0
 public IRComparisonExpression LessEqualAs(IRExpression b)
 => new IRComparisonExpression(IRComparisonOperator.LessEqual, this, b);