Esempio n. 1
0
 static bool IsNullOrZero(ILInstruction inst)
 {
     while (inst is Conv conv)
     {
         inst = conv.Argument;
     }
     return(inst.MatchLdcI4(0) || inst.MatchLdNull());
 }
Esempio n. 2
0
 private bool IsGenericNewPattern(ILInstruction compLeft, ILInstruction compRight, ILInstruction trueInst, ILInstruction falseInst)
 {
     // (default(T) == null) ? Activator.CreateInstance<T>() : default(T)
     return(falseInst.MatchDefaultValue(out var type) &&
            (trueInst is Call c && c.Method.FullName == "System.Activator.CreateInstance" && c.Method.TypeArguments.Count == 1) &&
            type.Kind == TypeKind.TypeParameter &&
            compLeft.MatchDefaultValue(out var type2) &&
            type.Equals(type2) &&
            compRight.MatchLdNull());
 }
Esempio n. 3
0
        static bool IsNullOrZero(ILInstruction inst)
        {
            var conv = inst as Conv;

            if (conv != null)
            {
                inst = conv.Argument;
            }
            return(inst.MatchLdcI4(0) || inst.MatchLdNull());
        }
Esempio n. 4
0
        public static IType GetInstType(ILInstruction inst, IType typeHint = null)
        {
            if (inst.MatchCastClass(out ILInstruction arg, out IType type))
            {
                return(type);
            }

            var call = inst as CallInstruction;

            if (call != null)
            {
                return(call.Method.ReturnType);
            }

            if (inst.MatchLdLoc(out ILVariable var))
            {
                return(GetVariableType(var));
            }

            if (inst.MatchLdNull())
            {
                return(null);
            }

            if (inst.MatchLdStr(out string xx))
            {
                // we don't handle string literals. Should be replaced finally
                return(null);
            }

            if (inst.MatchLdObj(out var target, out var fldType))
            {
                if (target.MatchLdsFlda(out var sfield))
                {
                    return(sfield.Type);
                }

                if (target.MatchLdFlda(out var target2, out var field))
                {
                    return(field.Type);
                }
            }
            if (inst.MatchLdLoca(out var v))
            {
                return(new PointerType(v.Type));
            }

            if (inst.MatchLdFlda(out var target3, out var field2))
            {
                return(new PointerType(field2.Type));
            }

            if (inst.MatchLdsFlda(out var field4))
            {
                return(new PointerType(field4.Type));
            }

            if (inst.MatchLdObj(out var target4, out var type3))
            {
                return(type3);
            }


            if (inst.MatchLdTypeToken(out var type4))
            {
                return(null);
            }

            if (inst is Conv c)
            {
                // todo handle integer types
                return(null);
            }
            // todo field, etc
            Debug.Assert(false, "Implement this type: " + inst.GetType().Name);
            return(null);
        }