Esempio n. 1
0
        private Expression GetExpressionFromIValue(IValue value)
        {
            if (RequiresAllocation(value) || value is Dereference) // if true, value is in a subset of IReferenceable stuff
            {
                // something requires an allocation because it has been reference (it is referenceable)
                IReferenceable referenceable = value as IReferenceable;
                return(memAddr.ReadAddr(memAddr.AddressOf(referenceable)));
            }

            if (value.Type is IManagedPointerType)
            {
                AddressExpression addr = memAddr.AddressOf(value) as AddressExpression;
                return(addr.Expr);
            }

            if (value is Constant constant)
            {
                return(BoogieLiteral.FromDotNetConstant(constant));
            }

            // we use old memory model here because they were not referenced
            if (value is IReferenceable || value is Reference)
            {
                Addressable addressable = memBCT.AddressOf(value);
                return(memBCT.ReadAddr(addressable));
            }

            throw new NotImplementedException();
        }
Esempio n. 2
0
        private static BoogieLiteral GetDefaultConstant(Helpers.BoogieType boogieType)
        {
            if (boogieType == Helpers.BoogieType.Int)
            {
                Constant zero = new Constant(0)
                {
                    Type = Types.Instance.PlatformType.SystemInt32
                };
                return(BoogieLiteral.Numeric(zero));
            }

            if (boogieType == Helpers.BoogieType.Bool)
            {
                return(BoogieLiteral.False);
            }

            if (boogieType == Helpers.BoogieType.Real)
            {
                Constant zero = new Constant(0F)
                {
                    Type = Types.Instance.PlatformType.SystemFloat32
                };
                return(BoogieLiteral.Numeric(zero));
            }

            if (boogieType == Helpers.BoogieType.Object)
            {
                return(BoogieLiteral.NullObject);
            }

            // address should not require a default value, you create one the same time you are referencing something.
            throw new NotImplementedException("Unexpected type to initialize");
        }
Esempio n. 3
0
        public override StatementList VariableAssignment(IVariable variableA, IValue value)
        {
            Constant      cons           = value as Constant;
            BoogieLiteral boogieConstant = null;

            if (cons != null)
            {
                boogieConstant = BoogieLiteral.FromDotNetConstant(cons);
            }


            var boogieType = Helpers.GetBoogieType(variableA);

            if (value is Constant)
            {
                if (boogieConstant != null)
                {
                    return(bg.VariableAssignment(variableA, boogieConstant));
                }
                else
                {
                    throw new NotImplementedException();
                    // return WriteAddr(variableA, value.ToString());
                }
            }
            else if (value is IVariable && !(value.Type is IManagedPointerType))
            { // right operand is not a pointer (therefore left operand is not a pointer)
                return(dispatcher.WriteAddr(dispatcher.AddressOf(variableA), dispatcher.ReadAddr(value as IVariable)));
            }
            else if (value is Dereference)
            {
                var dereference = value as Dereference;
                var content     = dispatcher.ReadAddr(dereference.Reference);
                return(dispatcher.WriteAddr(dispatcher.AddressOf(variableA), content));
            }
            else if (value.Type is IManagedPointerType)
            {
                // if the right operand is a pointer also the left one is a pointer
                // there are two cases for value:
                // 1) value has the form &<something> (in analysis-net this is a Reference object)
                // 2) value is just a variable (static, instance, local, array element) with pointer type
                // for 1) we want to take the allocated address of something and assign it to the boogie variable of the left operand
                // for 2) we just want to make a boogie assignment between the boogie variables of the left and right operands

                // AddressOf will do the work to separate case 1) and 2)
                var addr = dispatcher.AddressOf(value) as AddressExpression;
                Contract.Assume(addr != null);
                return(BoogieStatement.VariableAssignment(BoogieVariable.AddressVar(variableA), addr.Expr));
            }

            Contract.Assert(false);
            // This shouldn't be reachable.
            throw new NotImplementedException();
        }
Esempio n. 4
0
        public override StatementList VariableAssignment(IVariable variableA, IValue value)
        {
            Constant cons = value as Constant;

            if (cons != null)
            {
                return(bg.VariableAssignment(variableA, BoogieLiteral.FromDotNetConstant(cons)));
            }
            else if (value is Dereference)
            {
                var dereference = value as Dereference;
                return(VariableAssignment(variableA, dereference.Reference));
            }

            return(bg.VariableAssignment(variableA, dispatcher.ReadAddr(dispatcher.AddressOf(value))));
        }
Esempio n. 5
0
            public static Expression FixStringLiteral(IValue v, BoogieGenerator bg)
            {
                string vStr = v.ToString();

                if (v is Constant cons)
                {
                    return(BoogieLiteral.FromString(cons));
                }
                else if (v is IVariable variable)
                {
                    return(bg.ReadAddr(variable));
                }
                else
                {
                    throw new NotImplementedException();
                }
            }