Example #1
0
            private IEnumerator Execute()
            {
                var passesProp = serializedProperty.FindPropertyRelative("m_Passes");
                int passCnt    = passesProp.arraySize;

                passes = new List <PassInfo>(passCnt);
                this.yieldChk.SetPassCount(passCnt);
                for (int i = 0; i < passesProp.arraySize; ++i)
                {
                    var currentPassProp = passesProp.GetArrayElementAtIndex(i);
                    var passInfo        = new PassInfo(currentPassProp, yieldChk);
                    while (passInfo.MoveNext())
                    {
                        yield return(null);
                    }
                    passes.Add(passInfo);
                    // yield
                    yieldChk.CompletePassIdx(i);
                    if (yieldChk.ShouldYield())
                    {
                        yield return(null);
                    }
                }
                yield return(null);
            }
 public ActionResult ResetPassword(PassInfo info)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (info == null || string.IsNullOrEmpty(info.NewPassword))
             {
                 ViewBag.Status = "Error";
                 ViewBag.Error  = "Error collecting information";
             }
             else
             {
                 if (ChangePasswordInfo(info))
                 {
                     ViewBag.Status = "Passed";
                     //info = new PassInfo(); //clean view model
                 }
                 else
                 {
                     ViewBag.Status = "Error";
                     ViewBag.Error  = "";
                 }
             }
         }
         return(PartialView("ResetPassword", info));
     }
     catch (Exception e)
     {
         _log.ErrorFormat("Error reset Password [{0}], Trace [{1}]", e.Message, e.StackTrace);
         ViewBag.Status = "Error";
         //ViewBag.Error = "Error: [" + HttpUtility.HtmlEncode(e.Message) + "]";
         return(PartialView("ResetPassword", info));
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            string username = Request.QueryString["username"]; if (!userLogin.CheckLogin(username))

            {
                string js = "alert('您没有登录或操作超时,请重新登录!');window.top.location.href='" + StaticInfo.LoginPage + "'"; System.Web.HttpContext.Current.Response.Write("<script type='text/javascript'>" + js + "</script>"); return;
            }

            if (!X.IsAjaxRequest)
            {
                try
                {
                    if (Session["Condition"] != null)
                    {
                        PassInfo con = Session["Condition"] as PassInfo;
                        labhphm.FieldLabel = "&nbsp&nbsp&nbsp&nbsp号牌号码:" + con.Hphm1 + "&nbsp&nbsp&nbsp&nbsp距离:" + con.Len + "米" + "&nbsp&nbsp&nbsp&nbsp时间点:" + con.Gcsj1 + "---" + con.Gcsj2;
                        string points = con.Xpos1 + "," + con.Ypos1 + "|" + con.Xpos2 + "," + con.Ypos2;
                        string js     = "BMAP.addMarkerbs('../Map/img/com.png','" + con.Xpos1 + "','" + con.Ypos1 + "','" + con.Lkmc1 + "','','" + con.Zjwj1 + "');";
                        this.ResourceManager1.RegisterAfterClientInitScript(js);
                        //js="BMAP.addMarkerlabel('../Map/img/com.png','" + con.Xpos2 + "','" + con.Ypos2 + "','" + con.Lkmc2 + "','');";
                        js = "BMAP.addMarkerbs('../Map/img/com.png','" + con.Xpos2 + "','" + con.Ypos2 + "','" + con.Lkmc2 + "','','" + con.Zjwj2 + "');";
                        js = js + "BMAP.addPolyline2('#ff0000','" + points + "', '" + con.Len + "'); ";
                        this.ResourceManager1.RegisterAfterClientInitScript(js);
                        //js= "BMAP.openWindow('" + con.Zjwj1 + "','" + con.Xpos1 + "','" + con.Ypos1 + "');";
                        //js += "BMAP.openWindow('" + con.Zjwj2 + "','" + con.Xpos2 + "','" + con.Ypos2 + "');";
                        // this.ResourceManager1.RegisterAfterClientInitScript(js);
                    }
                }
                catch (Exception ex)
                {
                    ILog.WriteErrorLog(ex.Message);
                }
            }
        }
            public bool RunOn(Microsoft.Boogie.Program prog, PassInfo passInfo)
            {
                var  blocks  = prog.Blocks();
                bool changed = false;

                foreach (var block in blocks)
                {
                    var newCmds = new List <Cmd>();
                    foreach (var cmd in block.Cmds)
                    {
                        if (cmd is AssumeCmd)
                        {
                            var assumeCmd = cmd as AssumeCmd;
                            if (ExprUtil.IsTrue(assumeCmd.Expr))
                            {
                                // This is a trivial assume
                                Console.WriteLine("Removing trivial assume true on line {0}", assumeCmd.tok.line);
                                changed = true;
                                continue;
                            }
                        }
                        // Add the existing command to the list if we want to keep it
                        newCmds.Add(cmd);
                    }

                    if (block.cmds.Count > newCmds.Count)
                    {
                        // Assign new list if necessary
                        block.Cmds = newCmds;
                    }
                }
                return(changed);
            }
Example #5
0
    public PassInfo loadPassInfo()
    {
        PassInfo          info = new PassInfo();
        XmlDocument       xml  = new XmlDocument();
        XmlReaderSettings set  = new XmlReaderSettings();

        set.IgnoreComments = true;//这个设置是忽略xml注释文档的影响。有时候注释会影响到xml的读取
        xml.Load(XmlReader.Create((Application.streamingAssetsPath + "/passInfo.xml"), set));

        //得到objects节点下的所有子节点
        XmlNodeList xmlNodeList = xml.SelectSingleNode("Map").ChildNodes;

        //遍历所有子节点
        foreach (XmlElement xl1 in xmlNodeList)
        {
            if (xl1.Name == "born")
            {
                info.setborn(xl1.InnerXml);
            }
            else if (xl1.Name == "completeType")
            {
                info.passtye = xl1.InnerXml;
            }
            else if (xl1.Name == "targetVetor3")
            {
                info.setTraget(xl1.InnerXml);
            }
            else if (xl1.Name == "trap")
            {
                info.settrap(xl1.InnerXml);
            }
        }

        return(info);
    }
Example #6
0
 public bool RunOn(Microsoft.Boogie.Program prog, PassInfo passInfo)
 {
     foreach (var impl in prog.Implementations)
     {
         impl.PruneUnreachableBlocks();
     }
     return(true);
 }
Example #7
0
            public bool RunOn(Program prog, PassInfo passInfo)
            {
                var  canonicaliser = new OldExprCanonicaliserVisitor();
                bool changed       = false;

                foreach (var proc in prog.TopLevelDeclarations.OfType <Procedure>())
                {
                    canonicaliser.Visit(proc);
                    var GVs = new List <GlobalVariable>();

                    GVs.AddRange(canonicaliser.GlobalsInsideOldExpr);
                    GlobalsInsideOldExprUsedByProcedure[proc] = GVs;

                    if (AnnotateProceduresAndImplementations)
                    {
                        // Add as metadata for easy retrival during execution
                        proc.SetMetadata <IList <GlobalVariable> >((int)Annotation.AnnotationIndex.GLOBALS_USED_IN_OLD_EXPR, GVs);
                    }

                    if (GVs.Count > 0)
                    {
                        changed = true;
                    }

                    // Clear the recorded globals for next iteration
                    canonicaliser.ResetGlobals();
                }

                foreach (var impl in prog.TopLevelDeclarations.OfType <Implementation>())
                {
                    // Note this will Visit the implementation and the corresponding procedure
                    canonicaliser.Visit(impl);
                    var GVs = new List <GlobalVariable>();

                    GVs.AddRange(canonicaliser.GlobalsInsideOldExpr);
                    GlobalsInsideOldExprUsedByImpl[impl] = GVs;

                    if (AnnotateProceduresAndImplementations)
                    {
                        // Add as metadata for easy retrival during execution
                        impl.SetMetadata <IList <GlobalVariable> >((int)Annotation.AnnotationIndex.GLOBALS_USED_IN_OLD_EXPR, GVs);
                    }

                    if (GVs.Count > 0)
                    {
                        changed = true;
                    }

                    // Clear the recorded globals for next iteration
                    canonicaliser.ResetGlobals();
                }

                return(changed);
            }
Example #8
0
            public SubShaderInfo(SerializedProperty serializedProperty)
            {
                var passesProp = serializedProperty.FindPropertyRelative("m_Passes");

                passes = new List <PassInfo>(passesProp.arraySize);
                for (int j = 0; j < passesProp.arraySize; ++j)
                {
                    var currentPassProp = passesProp.GetArrayElementAtIndex(j);
                    var passInfo        = new PassInfo(currentPassProp);
                    passes.Add(passInfo);
                }
            }
            public bool RunOn(Program prog, PassInfo passInfo)
            {
                // We assume that types are uniqued so "GroupBy" works correctly
                var  groupedVariables = prog.TopLevelDeclarations.OfType <Constant>().Where(c => c.Unique).GroupBy(c => c.TypedIdent.Type);
                bool changed          = false;

                foreach (var pair in groupedVariables)
                {
                    var listOfUniqueVars = pair.ToList();
                    if (listOfUniqueVars.Count > 1)
                    {
                        Expr axiomExpr = null;
                        changed = true;

                        // Create IdentifierExprs
                        Dictionary <Variable, IdentifierExpr> ids = new Dictionary <Variable, IdentifierExpr>();
                        foreach (var uv in listOfUniqueVars)
                        {
                            ids.Add(uv, new IdentifierExpr(Token.NoToken, uv));
                        }

                        // Create an Expr asserting that all variables are different from each other (pair wise)
                        for (int firstVarIndex = 0; firstVarIndex < listOfUniqueVars.Count - 1; ++firstVarIndex)
                        {
                            for (int secondVarIndex = firstVarIndex + 1; secondVarIndex < listOfUniqueVars.Count; ++secondVarIndex)
                            {
                                var firstVar  = listOfUniqueVars[firstVarIndex];
                                var secondVar = listOfUniqueVars[secondVarIndex];
                                var notEq     = Expr.Neq(ids[firstVar], ids[secondVar]); // FIXME: Use ExprBuilder instead

                                if (axiomExpr == null)
                                {
                                    axiomExpr = notEq;
                                }
                                else
                                {
                                    axiomExpr = Expr.And(axiomExpr, notEq);
                                }
                            }
                        }

                        // Create the Axiom
                        var axiom = new Axiom(Token.NoToken, axiomExpr);
                        axiom.AddAttribute("symbooglix_enforce_unique", Expr.True);
                        prog.AddTopLevelDeclaration(axiom);
                        InternalAddedAxioms.Add(axiom);
                        Console.WriteLine("Adding axiom to enforce uniqueness of constant variables of {0} type that use the unique keyword", pair.Key.ToString());
                    }
                }

                return(changed);
            }
Example #10
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            PassInfo passInfo = new PassInfo();

            passInfo.PassName = txtPassName.Text.Trim();
            passInfo.SiteUrl = txtSiteUrl.Text.Trim();
            passInfo.UserName = txtUserName.Text.Trim();
            passInfo.Password = txtPassword.Text.Trim();
            passInfo.Remark = txtRemark.Text.Trim();

            string jsonPassInfo = JsonConvert.SerializeObject(passInfo);

            await SavePassInfo(jsonPassInfo);
        }
Example #11
0
        void ReleaseDesignerOutlets()
        {
            if (edData != null)
            {
                edData.Dispose();
                edData = null;
            }

            if (FmlaButton != null)
            {
                FmlaButton.Dispose();
                FmlaButton = null;
            }

            if (LangButton != null)
            {
                LangButton.Dispose();
                LangButton = null;
            }

            if (PassInfo != null)
            {
                PassInfo.Dispose();
                PassInfo = null;
            }

            if (TextFinder != null)
            {
                TextFinder.Dispose();
                TextFinder = null;
            }

            if (PassPassword != null)
            {
                PassPassword.Dispose();
                PassPassword = null;
            }

            if (PasswordPanel != null)
            {
                PasswordPanel.Dispose();
                PasswordPanel = null;
            }

            if (SheetControl != null)
            {
                SheetControl.Dispose();
                SheetControl = null;
            }
        }
Example #12
0
        public BenchmarkResults Run()
        {
            var results = new BenchmarkResults();

            for (var i = 1; i <= PassesCount; i++)
            {
                var passInfo = new PassInfo(i);

                var startTime = DateTime.Now;
                Action(passInfo);
                var elapsed = startTime - DateTime.Now;

                results.AddPass(i, elapsed);
            }

            return LastResults = results;
        }
Example #13
0
    private void gamestrat()
    {
        //gameObject.SetActive(false);
        curPassInfo = xml.loadPassInfo();

        string fullPath = Application.dataPath + "/Resources/map/Prefabs" + "/";

        DirectoryInfo direction = new DirectoryInfo(fullPath);

        FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);

        gameObject.GetComponent <MapManager>().initmap(xml.LoadXml());

        gameObject.GetComponent <MonsterManager>().initMonsterPatrol(patrolObject);
        ;
        gameObject.GetComponent <PassMananger>().initBox(xml.LoadBoxXml());
        gameObject.GetComponent <PassMananger>().initPassInfo(curPassInfo);
        gameObject.GetComponent <TrapManager>().inittrap(curPassInfo.trapList);
    }
Example #14
0
    void SetSelectedPass(int index, bool init = false)
    {
        if (init || index != m_SelectedPass)
        {
            m_SelectedPass = index;

            m_SelectedKeywords.Clear();

            if (m_SelectedPass >= 0 && m_SelectedPass < m_Passes.Count)
            {
                PassInfo info = m_Passes[m_SelectedPass];

                for (int i = 0; i < info.keywords.Count; i++)
                {
                    m_SelectedKeywords.Add(0);
                }
            }
        }
    }
Example #15
0
        private bool ChangePasswordInfo(PassInfo model)
        {
            bool response = false;

            try
            {
                var            accountUser    = _userBusinessLogic.GetById(Guid.Parse(model.UserId));
                MembershipUser membershipUser = Membership.GetUser(accountUser.AppUser.UserName);
                if (membershipUser != null)
                {
                    response = membershipUser.ChangePassword(accountUser.AppUser.PasswordHash, model.NewPassword);
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(response);
        }
Example #16
0
            public bool RunOn(Program prog, PassInfo passInfo)
            {
                var functionInlingVisitor = new FunctionInlingVisitor(Condition);

                // Apply to axioms
                foreach (var axiom in prog.TopLevelDeclarations.OfType <Axiom>())
                {
                    functionInlingVisitor.Visit(axiom);
                }

                // Apply to each Procedure's requires and ensures
                foreach (var procedure in prog.TopLevelDeclarations.OfType <Procedure>())
                {
                    foreach (var ensures in procedure.Ensures)
                    {
                        functionInlingVisitor.Visit(ensures);
                    }

                    foreach (var requires in procedure.Requires)
                    {
                        functionInlingVisitor.Visit(requires);
                    }
                }

                // Apply to functions too, is this correct??
                foreach (var function in prog.TopLevelDeclarations.OfType <Function>())
                {
                    if (function.Body != null)
                    {
                        function.Body = functionInlingVisitor.Visit(function.Body) as Expr;
                    }
                }

                // Apply to Commands in basic blocks
                foreach (var basicBlock in prog.Blocks())
                {
                    functionInlingVisitor.Visit(basicBlock);
                }

                return(functionInlingVisitor.InlineCounter > 0);
            }
Example #17
0
            public void Add(IPass pass)
            {
                var passInfo = new PassInfo();

                // Get the dependencies
                pass.SetPassInfo(ref passInfo);
                var tuple = Tuple.Create(pass, passInfo);

                if (passInfo.Dependencies != null)
                {
                    // We could be more sophisticatd here and try to optimise
                    // the list of passes so we don't run redundant analyses
                    // Leave this for now

                    // The pass has Dependencies so Add them

                    // It is not safe to iterate over a dictionary and modify it
                    // at the same time so do it in two stages.
                    // 1. Collect all the KeyValue Pairs in the dictionary
                    // 2. Iterate over the collected KeyValue pairs and modify the dictionary
                    var depList = new List <KeyValuePair <System.Type, IPass> >();
                    foreach (var keyValuePair in passInfo.Dependencies)
                    {
                        depList.Add(keyValuePair);
                    }

                    foreach (var keyValuePair in depList)
                    {
                        // Create dependency. This requires that the pass has a default constructor
                        IPass dependencyOfPass = Activator.CreateInstance(keyValuePair.Key) as IPass;

                        passInfo.Dependencies[keyValuePair.Key] = dependencyOfPass;

                        // Do this recursively so we handle any dependencies of the dependencies (of the...)*
                        Add(dependencyOfPass);
                    }
                }

                Passes.Add(tuple);
            }
Example #18
0
        private PassInfo CreatePassInfo(string str, int strPos, int currentPassIdx)
        {
            PassInfo passInfo = new PassInfo(currentPassIdx, strPos);
            int      length   = str.Length;

            // skip first line
            strPos = GetLineEndIdx(str, strPos);
            strPos = SkipTrimChars(str, strPos);
            while (strPos < length)
            {
                int nextStrPos = strPos;
                if (IsMatch(str, strPos, "////", out nextStrPos))
                {
                    strPos = nextStrPos;
                    break;
                }
                if (IsMatch(str, strPos, "Name", out nextStrPos))
                {
                    strPos        = nextStrPos;
                    nextStrPos    = GetLineEndIdx(str, strPos);
                    passInfo.name = str.Substring(strPos, nextStrPos - strPos);
                    strPos        = SkipTrimChars(str, nextStrPos);
                }
                else if (IsMatch(str, strPos, "Tags", out nextStrPos))
                {
                    strPos        = nextStrPos;
                    nextStrPos    = GetLineEndIdx(str, strPos);
                    passInfo.tags = str.Substring(strPos, nextStrPos - strPos);
                    strPos        = SkipTrimChars(str, nextStrPos);
                }
                else
                {
                    // next
                    strPos = GetLineEndIdx(str, strPos);
                    strPos = SkipTrimChars(str, strPos);
                }
            }
            return(passInfo);
        }
        public ChangePassModel ChangePass(PassInfo model)
        {
            //model.passOld = md5(model.passOld);
            model.passOld = Encrypt(model.passOld);
            var user = db.Users.Where(x => x.username == model.email && x.password == model.passOld).FirstOrDefault();

            if (user != null)
            {
                //user.password = md5(model.passNew);
                user.password = Encrypt(model.passNew);
                db.SaveChanges();
                return(new ChangePassModel {
                    IsSuccess = true,
                    Message = "Đổi mật khẩu thành công!"
                });
            }
            return(new ChangePassModel
            {
                IsSuccess = false,
                Message = "Đổi mật khẩu thất bại!"
            });
        }
Example #20
0
        internal override void ValidateShaderModels(PassInfo pass)
        {
            int major, minor;

            if (!string.IsNullOrEmpty(pass.vsFunction))
            {
                ParseShaderModel(pass.vsModel, HlslVertexShaderRegex, out major, out minor);
                if (major <= 3)
                {
                    throw new Exception(String.Format("Invalid profile '{0}'. Vertex shader '{1}' must be SM 4.0 level 9.1 or higher!", pass.vsModel, pass.vsFunction));
                }
            }

            if (!string.IsNullOrEmpty(pass.psFunction))
            {
                ParseShaderModel(pass.psModel, HlslPixelShaderRegex, out major, out minor);
                if (major <= 3)
                {
                    throw new Exception(String.Format("Invalid profile '{0}'. Pixel shader '{1}' must be SM 4.0 level 9.1 or higher!", pass.vsModel, pass.psFunction));
                }
            }
        }
Example #21
0
        internal override void ValidateShaderModels(PassInfo pass)
        {
            if (!string.IsNullOrEmpty(pass.vsFunction))
            {
                ParseShaderModel(pass.vsModel, GlslVertexShaderRegex, out int major, out _);
                if (major > 3)
                {
                    throw new Exception(string.Format(
                                            "Invalid profile '{0}'. Vertex shader '{1}' must be SM 3.0 or lower!",
                                            pass.vsModel, pass.vsFunction));
                }
            }

            if (!string.IsNullOrEmpty(pass.psFunction))
            {
                ParseShaderModel(pass.psModel, GlslPixelShaderRegex, out int major, out _);
                if (major > 3)
                {
                    throw new Exception(string.Format(
                                            "Invalid profile '{0}'. Pixel shader '{1}' must be SM 3.0 or lower!",
                                            pass.vsModel, pass.psFunction));
                }
            }
        }
Example #22
0
    void ProcessShader(Shader target, bool force = false)
    {
        // Reset
        if (target == null)
        {
            m_Keywords.Clear();
            m_Passes.Clear();
            m_SelectedPass = -1;
            m_Target       = null;
            m_PassNames    = null;
        }
        else if (target != m_Target || force)
        {
            m_Keywords.Clear();
            m_Passes.Clear();

            if (!force)
            {
                m_SelectedPass = 0;
            }

            m_Target = target;

            ShaderData data = ShaderUtil.GetShaderData(target);

            List <string> names = new List <string>();

            StringBuilder sb = new StringBuilder(k_MaxHintLength * 3);

            for (int sub = 0; sub < data.SubshaderCount; sub++)
            {
                ShaderData.Subshader subshader = data.GetSubshader(sub);
                for (int p = 0; p < subshader.PassCount; p++)
                {
                    PassInfo passInfo = new PassInfo();
                    passInfo.subShader = sub;
                    passInfo.pass      = subshader.GetPass(p);
                    passInfo.name      = passInfo.pass.Name;

                    ParseKeywords(passInfo.pass.SourceCode, ref passInfo.keywords);

                    // Create some label hints
                    for (int i = 0; i < passInfo.keywords.Count; i++)
                    {
                        for (int j = 0; j < passInfo.keywords[i].Count; j++)
                        {
                            if (passInfo.keywords[i][j].Length > 0)
                            {
                                sb.Append(passInfo.keywords[i][j]);

                                if (sb.Length > k_MaxHintLength)
                                {
                                    sb.Remove(k_MaxHintLength, sb.Length - k_MaxHintLength);
                                    sb[15] = '.';
                                    sb[16] = '.';
                                    sb[17] = '.';

                                    break;
                                }
                                else if (sb.Length == k_MaxHintLength)
                                {
                                    break;
                                }
                                else if (j < passInfo.keywords[i].Count - 1)
                                {
                                    sb.Append(',');
                                }
                            }
                        }

                        passInfo.keywordHint.Add(sb.ToString());
                        sb.Clear();
                    }

                    m_Passes.Add(passInfo);
                    names.Add(passInfo.name);
                }
            }

            if (m_SelectedPass < 0)
            {
                m_SelectedPass = 0;
            }
            else if (m_SelectedPass >= m_Passes.Count)
            {
                m_SelectedPass = m_Passes.Count - 1;
            }

            SetSelectedPass(m_SelectedPass, true);

            m_PassNames = names.ToArray();
        }
    }
Example #23
0
 public void SetPassInfo(ref PassInfo passInfo)
 {
     return;
 }
Example #24
0
 internal abstract void ValidateShaderModels(PassInfo pass);
Example #25
0
    public void initPassInfo(PassInfo info)
    {
        int random = Random.Range(0, info.bornList.Count);

        gameObject.GetComponent <GameMain>().player.transform.position = info.bornList[random];
    }
Example #26
0
            public bool RunOn(Microsoft.Boogie.Program prog, PassInfo passInfo)
            {
                var toRemove      = new HashSet <Declaration>();
                var implToFalsify = new List <Implementation>();
                var procToKeep    = new HashSet <Declaration>();

                // Check there is at least one entry point
                bool containsEntryPoint = false;

                foreach (var impl in prog.TopLevelDeclarations.OfType <Implementation>())
                {
                    if (IsEntryPoint(impl))
                    {
                        containsEntryPoint = true;
                        break;
                    }
                }

                if (!containsEntryPoint)
                {
                    throw new EntryPointNotFoundException();
                }

                // Determine which implementation we want to remove and
                // which implementations we will need to keep
                foreach (var decl in prog.TopLevelDeclarations)
                {
                    var declAsImplementation = decl as Implementation;
                    if (declAsImplementation == null)
                    {
                        continue;
                    }

                    if (!IsEntryPoint(declAsImplementation))
                    {
                        // We want to remove this implementation
                        toRemove.Add(declAsImplementation);
                    }
                    else
                    {
                        implToFalsify.Add(declAsImplementation);
                        Debug.Assert(declAsImplementation.Proc != null);
                        procToKeep.Add(declAsImplementation.Proc);
                    }
                }

                // Determine which procedures we should remove
                foreach (var decl in prog.TopLevelDeclarations)
                {
                    var declAsProc = decl as Procedure;
                    if (declAsProc == null)
                    {
                        continue;
                    }

                    if (!procToKeep.Contains(declAsProc))
                    {
                        toRemove.Add(declAsProc);
                    }
                }

                // Now remove the procedures and implementations we don't need
                foreach (var decl in toRemove)
                {
                    prog.RemoveTopLevelDeclaration(decl);
                }

                // Now change entry point bodies to just contain an "assert false"
                foreach (var impl in implToFalsify)
                {
                    // Remove any ensures. We probably aren't maintaining it
                    // any more if we remove the body.
                    impl.Proc.Ensures.Clear();

                    // The body won't be modifying anything so clear the modset
                    impl.Proc.Modifies.Clear();

                    // Remove existing blocks
                    impl.Blocks.Clear();

                    // Add block that asserts false and then returns
                    var newBlock = new Block(Token.NoToken,
                                             "entry",
                                             new List <Cmd>()
                    {
                        new AssertCmd(Token.NoToken, Expr.False)
                    },
                                             new ReturnCmd(Token.NoToken));
                    impl.Blocks.Add(newBlock);
                }

                return((toRemove.Count + implToFalsify.Count) > 0);
            }
Example #27
0
            public bool RunOn(Program prog, PassInfo passInfo)
            {
                // Collect used functions and global variables.
                // Note we don't want to consider an axiom as "using" interpreted functions because
                // axioms using interpreted functions aren't (or at least shouldn't be) constraining
                // those interpreted functions. If we considered interpreted functions as being used by
                // axioms then this might prevent those axioms (and uninterpreted functions in those axioms)
                // form being removed.
                var FFV = new FindUsedFunctionAndGlobalVariableVisitor(/*ignoreInterpretedFunctionsInAxioms=*/ true);

                FFV.Visit(prog);

                // Initialise with all declared functions
                var functionsToRemove = new HashSet <Function>(prog.TopLevelDeclarations.OfType <Function>());

                // reduce the set by removing functions used in code
                functionsToRemove.ExceptWith(FFV.FuncsUsedInCode);

                // Initialise with all declared global variables
                var gvsToRemove = new HashSet <Variable>(prog.TopLevelDeclarations.OfType <Variable>());

                // reduce the set by removing variables used in code
                gvsToRemove.ExceptWith(FFV.VarsUsedInCode);

                // We don't Initialise with all declared axioms
                var axiomsToRemove = new HashSet <Axiom>();

                // Compute transitive closure of axiom dependencies.
                // Some axioms may share variables for example
                // axiom e > f;
                // axiom f > g;
                // axiom g > h;
                //
                // if we decide that only variable h is live we need to keep all three axioms
                // which requires that we know how axioms depend on each other
                //
                // An axiom A is directly dependent on axiom B iff they share any common
                // functions or global variables.
                //
                // Axioms can be transitively dependent on each other
                Dictionary <Axiom, HashSet <Axiom> > axiomDeps = new Dictionary <Axiom, HashSet <Axiom> >();

                foreach (var axiom in prog.TopLevelDeclarations.OfType <Axiom>())
                {
                    axiomDeps[axiom] = new HashSet <Axiom>();
                }

                // Compute direct dependencies
                foreach (var axiom in prog.TopLevelDeclarations.OfType <Axiom>())
                {
                    foreach (var otherAxiom in prog.TopLevelDeclarations.OfType <Axiom>().Where(a => a != axiom))
                    {
                        if (axiomDeps[axiom].Contains(otherAxiom))
                        {
                            continue;
                        }

                        if (FFV.FuncsUsedInAxiom[axiom].Overlaps(FFV.FuncsUsedInAxiom[otherAxiom]) ||
                            FFV.VarsUsedInAxiom[axiom].Overlaps(FFV.VarsUsedInAxiom[otherAxiom])
                            )
                        {
                            axiomDeps[axiom].Add(otherAxiom);
                            axiomDeps[otherAxiom].Add(axiom);
                        }
                    }
                }

                // For each axiom compute the transistive closure of dependencies by reaching a fixed point for each axiom
                foreach (var axiom in prog.TopLevelDeclarations.OfType <Axiom>())
                {
                    bool setChanged = false;
                    do
                    {
                        var axiomsToAdd = new HashSet <Axiom>();
                        setChanged = false;

                        foreach (var dep in axiomDeps[axiom])
                        {
                            axiomsToAdd.UnionWith(axiomDeps[dep]);
                        }

                        int previousNumberOfDeps = axiomDeps[axiom].Count;
                        axiomDeps[axiom].UnionWith(axiomsToAdd);

                        if (axiomDeps[axiom].Count > previousNumberOfDeps)
                        {
                            setChanged = true;
                        }
                    } while (setChanged);
                }

                // Work out which axioms to remove
                var axiomsMustKeep = new HashSet <Axiom>();

                foreach (var axiom in prog.TopLevelDeclarations.OfType <Axiom>())
                {
                    var liveVars = new HashSet <Variable>(FFV.VarsUsedInAxiom[axiom]);
                    // Remove the variables (that we plan to remove) from the set so we are only left with live variables
                    liveVars.ExceptWith(gvsToRemove);

                    var liveFuncs = new HashSet <Function>(FFV.FuncsUsedInAxiom[axiom]);
                    // Remove the functions (that we plan to remove) from the set so we are only left with live functions
                    liveFuncs.ExceptWith(functionsToRemove);

                    if (liveVars.Count == 0 && liveFuncs.Count == 0)
                    {
                        axiomsToRemove.Add(axiom);
                    }
                    else
                    {
                        // Can't remove axiom. This means we shouldn't remove any of its dependencies
                        // We can't modify axiomsToRemove directly (i.e. axiomsToRemove.ExceptWith(axiomDeps[axiom]) )
                        // because the dependencies might be added to axiomsToRemove in a later iteration of this loop
                        axiomsMustKeep.UnionWith(axiomDeps[axiom]);
                    }
                }

                // Remove any axioms from the set that we discovered must be kept.
                axiomsToRemove.ExceptWith(axiomsMustKeep);


                // Work out which functions to remove
                var newFunctionsToRemove = new HashSet <Function>(); // can't modify set whilst iterating so write into temp

                foreach (var f in functionsToRemove)
                {
                    if (!FFV.AxiomsUsingFunc.ContainsKey(f))
                    {
                        // no axioms use this function so we can definitely remove it
                        newFunctionsToRemove.Add(f);
                        continue;
                    }
                    var liveAxiomsUsingFunc = new HashSet <Axiom>(FFV.AxiomsUsingFunc[f]);

                    // Compute which live axioms use this function
                    liveAxiomsUsingFunc.ExceptWith(axiomsToRemove);

                    if (liveAxiomsUsingFunc.Count == 0)
                    {
                        // We can remove this function
                        newFunctionsToRemove.Add(f);
                    }
                }
                functionsToRemove = newFunctionsToRemove;

                // Work out which global variables to remove
                var newGvsToRemove = new HashSet <Variable>(); // can't modify the set whilst iterarting so write into temp

                foreach (var gv in gvsToRemove)
                {
                    if (!FFV.AxiomsUsingVar.ContainsKey(gv))
                    {
                        // no axioms use this variable so we can definitely remove it
                        newGvsToRemove.Add(gv);
                        continue;
                    }

                    var liveAxiomsUsingVar = new HashSet <Axiom>(FFV.AxiomsUsingVar[gv]);

                    // compute which live axioms use this variable
                    liveAxiomsUsingVar.ExceptWith(axiomsToRemove);

                    if (liveAxiomsUsingVar.Count == 0)
                    {
                        // We can remove this variable
                        newGvsToRemove.Add(gv);
                    }
                }
                gvsToRemove = newGvsToRemove;

                bool changed = false;

                // Now remove the axioms
                foreach (var axiom in axiomsToRemove)
                {
                    changed = true;
                    Console.Error.WriteLine("Warning removing dead axiom: {0}", axiom.Expr.ToString());
                    prog.RemoveTopLevelDeclaration(axiom);
                }

                // Now remove the functions
                foreach (var f in functionsToRemove)
                {
                    changed = true;
                    Console.Error.WriteLine("Warning removing dead function {0}", f.Name);
                    prog.RemoveTopLevelDeclaration(f);
                }

                // Now remove the globally scoped variables
                foreach (var gv in gvsToRemove)
                {
                    changed = true;
                    Console.Error.WriteLine("Warning removing dead globally scoped variable {0}", gv.Name);
                    prog.RemoveTopLevelDeclaration(gv);
                }

                // FIXME: We need some way of validating the Boogie Program to make sure
                // all function Calls point to top level declared functions and that reference globals
                // are still top level declarations.
                return(changed);
            }