Пример #1
0
        // returns a map from integer id to an atomic Boogie predicate
        public static Dictionary <int, BoogieExpr> GenerateHoudiniVarMapping(ContractDefinition contract, TranslatorContext context)
        {
            Dictionary <int, BoogieExpr>  ret       = new Dictionary <int, BoogieExpr>();
            HashSet <VariableDeclaration> stateVars = context.GetVisibleStateVarsByContract(contract);

            // collect all state variables of type address
            List <VariableDeclaration> addressVariables = new List <VariableDeclaration>();

            foreach (VariableDeclaration stateVar in stateVars)
            {
                if (stateVar.TypeName is ElementaryTypeName elementaryType)
                {
                    if (elementaryType.TypeDescriptions.TypeString.Equals("address") ||
                        elementaryType.TypeDescriptions.TypeString.Equals("address payable"))
                    {
                        addressVariables.Add(stateVar);
                    }
                }
            }

            int id = 0;

            // equaility and disequality to null
            foreach (VariableDeclaration addressVar in addressVariables)
            {
                BoogieExpr lhs      = GetBoogieExprOfStateVar(addressVar, context);
                BoogieExpr rhs      = new BoogieIdentifierExpr("null");
                BoogieExpr equality = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.EQ, lhs, rhs);
                ret[++id] = equality;
                BoogieExpr disequality = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.NEQ, lhs, rhs);
                ret[++id] = disequality;
            }

            // pair-wise equality and disequality
            for (int i = 0; i < addressVariables.Count; ++i)
            {
                BoogieExpr lhs = GetBoogieExprOfStateVar(addressVariables[i], context);
                for (int j = i + 1; j < addressVariables.Count; ++j)
                {
                    BoogieExpr rhs      = GetBoogieExprOfStateVar(addressVariables[j], context);
                    BoogieExpr equality = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.EQ, lhs, rhs);
                    ret[++id] = equality;
                    BoogieExpr disequality = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.NEQ, lhs, rhs);
                    ret[++id] = disequality;
                }
            }

            // PrintHoudiniCandidateMap(ret);
            return(ret);
        }