Example #1
0
 /// <summary>Returns whether the given value corresponds to an array reference.</summary>
 /// <param name="value">a value.</param>
 /// <returns>whether 'value' corresponds to an array reference.</returns>
 protected internal virtual bool IsArrayValue(BasicValue value)
 {
     return(value.IsReference());
 }
Example #2
0
        /// <exception cref="AnalyzerException" />
        public override BasicValue CopyOperation(AbstractInsnNode insn, BasicValue value)
        {
            Value expected;

            switch (insn.GetOpcode())
            {
            case OpcodesConstants.Iload:
            case OpcodesConstants.Istore:
            {
                expected = BasicValue.Int_Value;
                break;
            }

            case OpcodesConstants.Fload:
            case OpcodesConstants.Fstore:
            {
                expected = BasicValue.Float_Value;
                break;
            }

            case OpcodesConstants.Lload:
            case OpcodesConstants.Lstore:
            {
                expected = BasicValue.Long_Value;
                break;
            }

            case OpcodesConstants.Dload:
            case OpcodesConstants.Dstore:
            {
                expected = BasicValue.Double_Value;
                break;
            }

            case OpcodesConstants.Aload:
            {
                if (!value.IsReference())
                {
                    throw new AnalyzerException(insn, null, "an object reference", value);
                }
                return(value);
            }

            case OpcodesConstants.Astore:
            {
                if (!value.IsReference() && !BasicValue.Returnaddress_Value.Equals(value))
                {
                    throw new AnalyzerException(insn, null, "an object reference or a return address"
                                                , value);
                }
                return(value);
            }

            default:
            {
                return(value);
            }
            }

            if (!expected.Equals(value))
            {
                throw new AnalyzerException(insn, null, expected, value);
            }
            return(value);
        }
Example #3
0
        /// <exception cref="AnalyzerException" />
        public override BasicValue UnaryOperation(AbstractInsnNode insn, BasicValue value
                                                  )
        {
            BasicValue expected;

            switch (insn.GetOpcode())
            {
            case OpcodesConstants.Ineg:
            case OpcodesConstants.Iinc:
            case OpcodesConstants.I2f:
            case OpcodesConstants.I2l:
            case OpcodesConstants.I2d:
            case OpcodesConstants.I2b:
            case OpcodesConstants.I2c:
            case OpcodesConstants.I2s:
            case OpcodesConstants.Ifeq:
            case OpcodesConstants.Ifne:
            case OpcodesConstants.Iflt:
            case OpcodesConstants.Ifge:
            case OpcodesConstants.Ifgt:
            case OpcodesConstants.Ifle:
            case OpcodesConstants.Tableswitch:
            case OpcodesConstants.Lookupswitch:
            case OpcodesConstants.Ireturn:
            case OpcodesConstants.Newarray:
            case OpcodesConstants.Anewarray:
            {
                expected = BasicValue.Int_Value;
                break;
            }

            case OpcodesConstants.Fneg:
            case OpcodesConstants.F2i:
            case OpcodesConstants.F2l:
            case OpcodesConstants.F2d:
            case OpcodesConstants.Freturn:
            {
                expected = BasicValue.Float_Value;
                break;
            }

            case OpcodesConstants.Lneg:
            case OpcodesConstants.L2i:
            case OpcodesConstants.L2f:
            case OpcodesConstants.L2d:
            case OpcodesConstants.Lreturn:
            {
                expected = BasicValue.Long_Value;
                break;
            }

            case OpcodesConstants.Dneg:
            case OpcodesConstants.D2i:
            case OpcodesConstants.D2f:
            case OpcodesConstants.D2l:
            case OpcodesConstants.Dreturn:
            {
                expected = BasicValue.Double_Value;
                break;
            }

            case OpcodesConstants.Getfield:
            {
                expected = NewValue(Type.GetObjectType(((FieldInsnNode)insn).owner));
                break;
            }

            case OpcodesConstants.Arraylength:
            {
                if (!IsArrayValue(value))
                {
                    throw new AnalyzerException(insn, null, "an array reference", value);
                }
                return(base.UnaryOperation(insn, value));
            }

            case OpcodesConstants.Checkcast:
            case OpcodesConstants.Areturn:
            case OpcodesConstants.Athrow:
            case OpcodesConstants.Instanceof:
            case OpcodesConstants.Monitorenter:
            case OpcodesConstants.Monitorexit:
            case OpcodesConstants.Ifnull:
            case OpcodesConstants.Ifnonnull:
            {
                if (!value.IsReference())
                {
                    throw new AnalyzerException(insn, null, "an object reference", value);
                }
                return(base.UnaryOperation(insn, value));
            }

            case OpcodesConstants.Putstatic:
            {
                expected = NewValue(Type.GetType(((FieldInsnNode)insn).desc));
                break;
            }

            default:
            {
                throw new AssertionError();
            }
            }

            if (!IsSubTypeOf(value, expected))
            {
                throw new AnalyzerException(insn, null, expected, value);
            }
            return(base.UnaryOperation(insn, value));
        }