Пример #1
0
 protected internal override void VisitStObj(StObj inst)
 {
     base.VisitStObj(inst);
     if (EarlyExpressionTransforms.StObjToStLoc(inst, context))
     {
         context.RequestRerun();
         return;
     }
     TransformAssignment.HandleCompoundAssign(inst, context);
 }
 protected internal override void VisitStObj(StObj inst)
 {
     if (IsDisplayClassFieldAccess(inst.Target, out var v, out var displayClass, out var field)) {
         VariableToDeclare vd = displayClass.VariablesToDeclare[(IField)field.MemberDefinition];
         if (vd.CanPropagate && vd.Initializers.Contains(inst)) {
             if (inst.Parent is Block containingBlock) {
                 context.Step($"Remove initializer of {v.Name}.{vd.Name} due to propagation", inst);
                 containingBlock.Instructions.Remove(inst);
                 return;
             }
         }
     }
     base.VisitStObj(inst);
     EarlyExpressionTransforms.StObjToStLoc(inst, context);
 }
Пример #3
0
        protected internal override void VisitStObj(StObj inst)
        {
            base.VisitStObj(inst);
            if (EarlyExpressionTransforms.StObjToStLoc(inst, context))
            {
                context.RequestRerun();
                return;
            }

            if (inst.Value is BinaryNumericInstruction binary &&
                binary.Left.MatchLdObj(out ILInstruction target, out IType t) &&
                inst.Target.Match(target).Success &&
                SemanticHelper.IsPure(target.Flags) &&
                CompoundAssignmentInstruction.IsBinaryCompatibleWithType(binary, t))
            {
                context.Step("compound assignment", inst);
                // stobj(target, binary.op(ldobj(target), ...))
                // => compound.op(target, ...)
                inst.ReplaceWith(new CompoundAssignmentInstruction(
                                     binary, binary.Left, binary.Right,
                                     t, CompoundAssignmentType.EvaluatesToNewValue));
            }
        }
Пример #4
0
 protected internal override void VisitStObj(StObj inst)
 {
     inst.Value.AcceptVisitor(this);
     if (inst.Parent is Block)
     {
         if (IsParameterAssignment(inst, out var displayClass, out var field, out var parameter))
         {
             context.Step($"Detected parameter assignment {parameter.Name}", inst);
             displayClass.Variables.Add((IField)field.MemberDefinition, parameter);
             instructionsToRemove.Add(inst);
             return;
         }
         if (IsDisplayClassAssignment(inst, out displayClass, out field, out var variable))
         {
             context.Step($"Detected display-class assignment {variable.Name}", inst);
             displayClass.Variables.Add((IField)field.MemberDefinition, variable);
             instructionsToRemove.Add(inst);
             return;
         }
     }
     inst.Target.AcceptVisitor(this);
     EarlyExpressionTransforms.StObjToStLoc(inst, context);
 }