예제 #1
0
        //////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////
        private void dumpVariable(ProgramVariable v)
        {
            string name = removeAtSigns(v.name);

            Debug.Assert(!name.Contains('@'));
            file.WriteLine("var " + name + " : " + toBoogie(v.type) + ";");
        }
예제 #2
0
        ///////////////////////////////////////////////////////////////////////
        public ProgramVariable findVariable(string name)
        {
            ProgramVariable result = tryFindVariable(name);

            Debug.Assert(result != null);
            return(result);
        }
예제 #3
0
 //////////////////////////////////////////////////////////////
 public void include(ProgramVariable v)
 {
     if (!value.ContainsKey(v.name))
     {
         value.Add(v.name, v);
     }
 }
예제 #4
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private static void getOwnAssume(BasicBlock bb, out Expression assumeE)
        {
            assumeE = null;

            ProgramVariable cv = (bb.getControlStatement() as ConditionalBranch).condition;

            {
                if (bb.statements.Count > 1)
                {
                    var pa = bb.statements[bb.statements.Count - 2].statement as Assume;
                    if (pa != null)
                    {
                        var fae = pa.expression as FAE;
                        if (fae != null && BFunction.isEquality(fae.function))
                        {
                            var apv = fae.arguments[0] as ProgramVariableExpression;
                            if (apv != null && ReferenceEquals(apv.programVariable, cv))
                            {
                                assumeE = fae.arguments[1];
                            }
                        }
                    }
                }
            }
        }
 public override ProgramVariable visitReadProgramVariable(ProgramVariable v)
 {
     if (!v.isConstant && !v.isGlobal && !v.isInput)
     {
         liveVariables.Add(v.name);
     }
     return(v);
 }
예제 #6
0
 ////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////
 public override ProgramVariable visitReadProgramVariable(ProgramVariable v)
 {
     if (isMap(v))
     {
         maps.add(v);
     }
     return(v);
 }
예제 #7
0
 private void addFirstOccurenceIfNotInitialized(ProgramVariable v)
 {
     if (!firstOccurence.ContainsKey(v.name))
     {
         firstOccurence.Add(v.name, new Dictionary <string, Tuple <PropositionalFormula, StatementId> >());
         firstOccurence[v.name].Add(currentStatement.ToString(),
                                    new Tuple <PropositionalFormula, StatementId>(pathCondition, currentStatement));
     }
 }
예제 #8
0
        ////////////////////////////////////////////////////////////////////////////
        public override Statement visit(ConditionalBranch s)
        {
            ControlStatement result = s;

//            var ne = si.fae.visit(this);
            ProgramVariable oc = s.condition;
            ProgramVariable nc = s.condition;

            EqualityDatabase.Representative rep = database.tryGetRepresentative(s.condition);

            if (rep != null)
            {
                Expression ne = rep.expression;

                if (ne is LiteralExpression)
                {
                    if (((ne as LiteralExpression).value as BooleanValue).value)
                    {
                        result = new UnconditionalBranch(s.trueBranch.source, s.trueBranch.target);
                    }
                    else
                    {
                        result = new UnconditionalBranch(s.falseBranch.source, s.falseBranch.target);
                    }
                    nc = null;
                }
                else
                {
                    if (ne is ProgramVariableExpression)
                    {
                        s.condition = (ne as ProgramVariableExpression).programVariable;
                        nc          = s.condition;
                    }
                    else
                    {
                        nc =
                            (EqualityDatabase.getCompactNegationIfBoolean(ne) as ProgramVariableExpression).
                            programVariable;

                        result = new ConditionalBranch(
                            database.statementId.basicBlock,
                            nc,
                            s.falseBranch.target,
                            s.trueBranch.target
                            );
                    }
                }
            }

            if (nc != null && !database.conditionVariableIndices.ContainsKey(nc.name))
            {
                database.addConditionVariable(nc);
            }

            return(result);
        }
예제 #9
0
            internal void add(ProgramVariable v)
            {
                string name = procedure.getBaseIncarnation(v.name).name;

                if (!mapData.ContainsKey(name))
                {
                    mapData.Add(name, new MapData(name));
                }
                mapData[name].add(v);
            }
예제 #10
0
        //////////////////////////////////////////////////////////////

        public void apply(ModifyingVisitor visitor)
        {
            var newValue = new Dictionary <string, ProgramVariable>();

            foreach (var kv in value)
            {
                ProgramVariable v = visitor(kv.Value);
                newValue.Add(v.name, v);
            }
            value = newValue;
        }
 //////////////////////////////////////////////
 public BoogieProgramVariableExpression(IdentifierExpr boogieExpression, ProgramVariable variable)
     : base(variable)
 {
     Debug.Assert(boogieExpression != null);
     Debug.Assert(
         boogieExpression.Decl is GlobalVariable ||
         boogieExpression.Decl is LocalVariable ||
         boogieExpression.Decl is Formal ||
         boogieExpression.Decl is Constant
         );
     boogieIdentifierExpression = boogieExpression;
 }
예제 #12
0
        public virtual Expression visit(ProgramVariableExpression e)
        {
            ProgramVariable newV = visitReadProgramVariable(e.programVariable);

            if (!ReferenceEquals(e.programVariable, newV))
            {
                return(new BasicProgramVariableExpression(newV));
            }
            else
            {
                return(e);
            }
        }
    public GameObject AddVariable(ProgramVariable variable)
    {
        GameObject newProgramFileGraphic     = GameObject.Instantiate(programVariableGraphicPrefab);
        ProgramGUIVariableGraphic newGraphic = newProgramFileGraphic.GetComponent <ProgramGUIVariableGraphic> ();

        programVariableGraphics.Add(newGraphic);
        newProgramFileGraphic.GetComponent <RectTransform> ().parent           = variableParent;
        newProgramFileGraphic.GetComponent <RectTransform> ().anchoredPosition = new Vector2(
            0,
            150 + (-100 * (programVariableGraphics.Count - 1)));

        return(newProgramFileGraphic);
    }
예제 #14
0
        public ConditionalBranch(BasicBlock source, ProgramVariable condition, BasicBlock trueTarget,
                                 BasicBlock falseTarget)
        {
            Debug.Assert(source != null);
            Debug.Assert(trueTarget != null);
            Debug.Assert(falseTarget != null);
            Debug.Assert(condition != null);

            trueBranch = new BasicEdge(source, trueTarget,
                                       new BasicEdge.Guard(new BasicProgramVariableExpression(condition)));
            falseBranch = new BasicEdge(source, falseTarget,
                                        new BasicEdge.Guard(makeNegation(new BasicProgramVariableExpression(condition))));
            this.condition = condition;
        }
예제 #15
0
 //////////////////////////////////////////////////////////////
 //Exclude v if in set, nop otherwise
 public void exclude(ProgramVariable v)
 {
     if (value.ContainsKey(v.name))
     {
         if (value[v.name] == v)
         {
             value.Remove(v.name);
         }
         else
         {
             throw new Exception("Internal error - scoping error with programVariable \"" + v.name + "\"");
         }
     }
 }
예제 #16
0
/*        ///////////////////////////////////////////////////////////////////////
 *      public ProgramVariable makeFreshProgramVariable(DataType type)
 *      {
 *          if (parentScope != null)
 *              return parentScope.makeFreshProgramVariable(type);
 *
 *          string name = "$t_" + freshProgramVariableIndex.ToString();
 *          freshProgramVariableIndex++;
 *          ProgramVariable result = new ProgramVariable(name,type,false,false,false,false);
 *          addVariable(result);
 *          return result;
 *      }
 */
        ///////////////////////////////////////////////////////////////////////
        public ProgramVariable makeFreshProgramVariable(string baseName, IType type)
        {
            int    index = 0;
            string name  = baseName;

            while (tryFindVariable(name) != null)
            {
                name = baseName + "_$" + (index++).ToString();
            }

            var result = new ProgramVariable(name, type, false, false, false, false);

            addVariable(result);
            return(result);
        }
예제 #17
0
        ///////////////////////////////////////////////////////////////////////

/*        public void addVariable(Scope scope,Microsoft.Boogie.NamedDeclaration d, bool isInput, bool isOutput, bool isGlobal, bool isConstant)
 *      {
 * //            addVariable(new ProgramVariable(d.Name,makeType())
 *      }*/
        public void addVariable(ProgramVariable variable)
        {
            if (variableMap.ContainsKey(variable.name))
            {
                return;
            }
            Debug.Assert(!variableMap.ContainsKey(variable.name));
#if DEBUG
//            if (variable.name.StartsWith(@"call5"))
//                Debugger.Break();
#endif
            variableMap[variable.name] = variable;
//            if (variable.isInput)
//                addInitialIncarnation(variable);
        }
예제 #18
0
        ///////////////////////////////////////////////////////////////////////

        ///////////////////////////////////////////////////////////////////////

        #region Scope Members

        public ProgramVariable tryFindVariable(string name)
        {
            ProgramVariable result = null;

            variableMap.TryGetValue(name, out result);
#if DEBUG
//            if (name.StartsWith(@"call5"))
//                Debugger.Break();
#endif
            if (result == null && parentScope != null)
            {
                result = parentScope.tryFindVariable(name);
            }
            //            Debug.Assert(result != null);
            return(result);
        }
예제 #19
0
            public BlockEntry(BasicBlock bb, IEnumerable <BlockEntry> successors)
            {
                this.bb = bb;

                var variables = new HashSet <ProgramVariable>();

                foreach (var s in successors)
                {
                    variables.UnionWith(s.variableMap.Keys);
                }

                foreach (var v in variables)
                {
                    variableMap.Add(v,
                                    new ConditionVariableEntry(bb, v,
                                                               from s in successors
                                                               select
                                                                   (s.variableMap.ContainsKey(v)
                                                                        ? s.variableMap[v]
                                                                        : null)));
                }

                var cb = bb.getControlStatement() as ConditionalBranch;

                if (cb != null)
                {
                    ProgramVariable cv         = cb.condition;
                    Assignment      assignment = null;
                    if (bb.statements.Count > 1)
                    {
                        assignment = getAssignment(cv, bb.statements[bb.statements.Count - 2].statementId);
                    }
                    else
                    {
                        assignment = new Assignment(bb, cv);
                    }

                    if (variableMap.ContainsKey(cv))
                    {
                        variableMap[cv].add(assignment);
                    }
                    else
                    {
                        variableMap.Add(cv, new ConditionVariableEntry(assignment));
                    }
                }
            }
예제 #20
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private static void redirectFriend(BasicBlock f, BasicBlock assumeInsertion)
        {
            bool polarity = true;

            var fcb = f.getControlStatement() as ConditionalBranch;

            Debug.Assert(fcb != null);

            var icb = assumeInsertion.getControlStatement() as ConditionalBranch;

            Debug.Assert(icb != null);

            ProgramVariable icv = icb.condition;

            Debug.Assert(
                (fcb.trueBranch.target == icb.trueBranch.target && fcb.falseBranch.target == icb.falseBranch.target) ||
                (fcb.trueBranch.target == icb.falseBranch.target && fcb.falseBranch.target == icb.trueBranch.target)
                );

            if (fcb.trueBranch.target == icb.trueBranch.target)
            {
                polarity = true;
            }
            else
            {
                polarity = false;
            }

            Expression assumeE;

            getOwnAssume(f, out assumeE);

            if (assumeE != null)
            {
                var        assume     = f.statements[f.statements.Count - 2].statement as Assume;
                Expression newAssumeE = (polarity) ? assumeE : EqualityDatabase.getCompactNegationIfBoolean(assumeE);
                assume.expression = new BasicFAE(
                    BFunction.equivalence, //eq(BooleanType.booleanType),
                    new ExpressionList(
                        new BasicProgramVariableExpression(icv),
                        newAssumeE
                        )
                    );
            }
            f.setControlStatement(new UnconditionalBranch(f, assumeInsertion));
        }
예제 #21
0
        private Expression makeMapWriteMap(FAE fae)
        {
            Debug.Assert(fae.function is MapWrite);
            Debug.Assert(fae.arguments[0].type is MapType);
            var        mu = fae.function as MapWrite;
            Expression result;

            if (!versionMap.TryGetValue(fae.ToString(), out result))
            {
                var ot = fae.arguments[0].type as MapType;
                Debug.Assert(ot != null);
                var s = new TypeParameterInstantiation(ot.typeParameters, mu.typeArguments.Skip(1).ToArray());
//                var ots = new MapType(new TypeVariable[0], (from m in ot.domain select m.substitute(s)).ToArray(), ot.range.substitute(s));
                Expression   m = fae.arguments[0];
                Expression[] i = fae.arguments.Take(fae.arguments.count - 1).Skip(1).ToArray();

                if (fae.freeVariables.Count > 0)
                {
//m(fv)[i(fv):=x(fv)] ==> v(fv)  (assume v(fv)[i]==x, assume forall fv : forall j : j!=i(fv) ==> v(fv)[j] == m(fv)[j]
                    var    fvt = TypeTuple.make(from fv in fae.freeVariables select fv.type);
                    string fn  = getFreshMUName("mu");
                    var    ft  = new BFunctionTemplate(fn, "", new TypeVariable[0], new BasicFunctionSignature(ot, fvt),
                                                       null);
                    Function f = ft.getInstance();
                    IEnumerable <BasicBoundVariableExpression> fve = from fv in fae.freeVariables
                                                                     select new BasicBoundVariableExpression(fv);
                    result = new BasicFAE(f, new ExpressionList(fve));
                }
                else
                {
                    //m[i:=x] ==> v  (assume v[i]==x, assume forall j : j!=i ==> v[j] == m[j]
                    string nvn = getFreshMUName("mu");
                    var    nv  = new ProgramVariable(nvn, ot, false, false, false, false);
                    procedure.addVariable(nv);
                    result = new BasicProgramVariableExpression(nv);
                }
                Expression[] j =
                    (from e in i select new BasicBoundVariableExpression(makeBoundVariable(e.type))).ToArray();
                //forall j : j!=i ==> v[j]==m[j]
                addConditionalMapEqualityAxiom(i, result, m, mu.typeArguments);
                //v[i]==x;
                Expression x = fae.arguments.Last();
                addEqualityAxiom(ml(result, i, mu.typeArguments.Skip(1).ToArray(), x.type), fae.arguments.Last());
            }
            return(result);
        }
예제 #22
0
                public ConditionVariableEntry(BasicBlock bb, ProgramVariable v,
                                              IEnumerable <ConditionVariableEntry> successors)
                {
                    // TODO: Complete member initialization
                    Debug.Assert(bb != null);
                    Debug.Assert(v != null);
                    Debug.Assert(successors != null);
                    Debug.Assert(successors.Count() > 0);

                    this.v = v;

                    foreach (var s in successors)
                    {
                        if (s != null)
                        {
                            assignments.UnionWith(s.assignments);
                        }
                    }

                    definition = null;
                    foreach (var s in successors)
                    {
                        if (s != null)
                        {
                            if (definition == null)
                            {
                                definition = s.definition;
                            }
                            else if (definition != s.definition)
                            {
                                definition = bb;
                                break;
                            }
                        }
                    }
                    {
                        Assignment e = assignments.First();
                        foreach (var a in assignments)
                        {
                            Debug.Assert(a.variable == v);

                            Debug.Assert((e.value == null && a.value == null) ||
                                         e.value.ToString() == a.value.ToString());
                        }
                    }
                }
예제 #23
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 private static bool getVariable(Expression e, out ProgramVariable v)
 {
     if (e is ProgramVariableExpression)
     {
         v = (e as ProgramVariableExpression).programVariable;
         return(true);
     }
     else
     {
         var fae = e as FAE;
         Debug.Assert(fae != null);
         Debug.Assert(BFunction.isNegation(fae.function));
         v = (fae.arguments[0] as ProgramVariableExpression).programVariable;
         Debug.Assert(v != null);
         return(false);
     }
 }
예제 #24
0
        public static void appendSubexpressions(Procedure p)
        {
            var subExpressionLeaves = new Dictionary <string, SubExpressionOrderNode>();

            foreach (var sec in p.cfg.startNode.getPreState(0).subexpressionCounter.subexpressionCounts)
            {
                if (sec.Value.contexts.Count > 1 ||
                    (sec.Value.contexts.First().Key == null && sec.Value.contexts.First().Value.Count > 1))
                {
                    subExpressionLeaves.Add(sec.Key, new SubExpressionOrderNode(sec.Value));
                }
            }

            foreach (var ses in subExpressionLeaves.Values)

/*                process(subExpressionLeaves,ses.Value);
 *
 *          Queue<SubExpressionOrderNode> q = new Queue<SubExpressionOrderNode>();
 *
 *          foreach (var ses in subExpressionLeaves)
 *              if (ses.Value.numDescendants==0)
 *                  q.Enqueue(ses.Value);
 *
 *          int numStatements = 0;
 *          while (q.Count>0)*/
            {
                Expression      e  = ses.subExpression.expression;
                IType           t  = e.type;
                ProgramVariable nv = p.makeFreshProgramVariable("se", t);
                var             s  =
                    new Assume(
                        new BasicFAE(
                            BFunction.eq(t),
                            new ExpressionList(
                                new BasicProgramVariableExpression(nv),
                                e
                                )
                            )
                        );
                ses.subExpression.definition.prependStatement(s);
            }
        }
예제 #25
0
        private void treeViewTestBtn_Click(object sender, RoutedEventArgs e)
        {
            //System.GC.Collect();

            DataBaseConnectManager.DBConnection_
                = DataBaseConnectManager.ConnectionFactory(EnvironmentVariable.MarketDataDBFile_);

            //EVENT_INFO_Table_DAOManager d = new EVENT_INFO_Table_DAOManager();

            //d.delete(DataBaseConnectManager.DBConnection_);

            ProgramVariable.initialize_CurrencyStringList();

            RootBookViewModel.setRootBookReferenceDate(DateTime.Now);

            BookFolderView bfv = new BookFolderView();

            bfv.ReferenceDate_ = this.loadLastPositionDate();
            bfv.positionXmlReload();

            //RootBookViewModel root_bvm = new RootBookViewModel();

            //root_bvm.loadPosition();

            //RootFavoriteViewModel root_fvm = new RootFavoriteViewModel();

            //root_fvm.loadPosition();

            //bfv.RootBookViewModel_ = root_bvm;
            //bfv.RootFavoriteViewModel_ = root_fvm;

            Window w = new Window();

            w.Width      = 600;
            w.Height     = 400;
            w.Content    = bfv;
            w.Visibility = 0;
        }
예제 #26
0
            private Assignment getAssignment(ProgramVariable v, StatementId statementId)
            {
                StatementId si     = statementId;
                var         assume = statementId.statement as Assume;

                if (assume == null)
                {
                    si = null;
                }
                else
                {
                    var fae = assume.expression as FAE;

                    if (fae == null || !BFunction.isEquality(fae.function))
                    {
                        si = null;
                    }
                    else
                    {
                        var dest = fae.arguments[0] as ProgramVariableExpression;
                        if (dest == null || (dest.programVariable != v))
                        {
                            si = null;
                        }
                    }
                }

                if (si == null)
                {
                    return(new Assignment(statementId.basicBlock, v));
                }
                else
                {
                    return(new Assignment(si));
                }
            }
 public void DeleteVariable(ProgramVariable variable)
 {
 }
예제 #28
0
 public virtual ProgramVariable visitHavokProgramVariable(ProgramVariable v)
 {
     v.type.visit(this);
     return(v);
 }
 public override ProgramVariable visitWriteProgramVariable(ProgramVariable v)
 {
     liveVariables.Remove(v.name);
     return(v);
 }
예제 #30
0
        /////////////////////////////////////////////////////////////////////////////////////
        private void setControlStatement(BasicBlock current, GotoCmd gotoCmd, BasicBlock next)
        {
            if (gotoCmd.labelNames.Count == 0)
            {
                current.setControlStatement(new Programs.Statements.Block(current));
            }
            else if (gotoCmd.labelNames.Count == 1)
            {
                BasicBlock target = cfg.lookupOrAddNode(gotoCmd.labelNames[0]);
                current.setControlStatement(new UnconditionalBranch(current, target));
            }
            else
            {
                var conditionVariables = new List <ProgramVariable>();
                while ((1 << conditionVariables.Count) < gotoCmd.labelNames.Count)
                {
                    ProgramVariable nd = scope.makeFreshProgramVariable(pathConditionPrefix, makeBooleanType());
                    conditionVariables.Add(nd);
                    nondeterministicConditionVariables.Add(nd);
                }

                string basicLabel = "$cascade_" + labelIndex.ToString();
                labelIndex++;

                int currentTarget = 0;

                for (int i = 0; (1 << i) <= gotoCmd.labelNames.Count; i++)
                {
                    for (int j = 0; (j < (1 << i)) && ((1 << i) + j < gotoCmd.labelNames.Count); j += 2)
                    {
                        int        index = (1 << i) + j;
                        string     label = basicLabel + "_$" + i.ToString() + "_$" + j.ToString();
                        BasicBlock block = (i == 0) ? current : cfg.lookupOrAddNode(label);

                        string targetLabel1 =
                            (index * 2 < gotoCmd.labelNames.Count)
                                ? basicLabel + "_$" + (i + 1).ToString() + "_$" + (j * 2).ToString()
                                : gotoCmd.labelNames[currentTarget++];

                        string targetLabel2 =
                            (index * 2 + 1 < gotoCmd.labelNames.Count)
                                ? basicLabel + "_$" + (i + 1).ToString() + "_$" + (j * 2 + 1).ToString()
                                : (
                                (currentTarget < gotoCmd.labelNames.Count)
                                          ? gotoCmd.labelNames[currentTarget++]
                                          : null
                                );

                        BasicBlock target1 = cfg.lookupOrAddNode(targetLabel1);
                        BasicBlock target2 = (targetLabel2 == null) ? null : cfg.lookupOrAddNode(targetLabel2);

                        if (target2 != null)
                        {
                            block.setControlStatement(new ConditionalBranch(block, conditionVariables[i], target1,
                                                                            target2));
                        }
                        else
                        {
                            block.setControlStatement(new UnconditionalBranch(block, target1));
                        }
                    }
                }
            }
        }