예제 #1
0
        public bool Activate(bool activateDependencies)
        {
            if (MissingDependencies.Count > 0)
            {
                return(false);
            }

            if (IsActive)
            {
                return(true);
            }

            //check whether all predececcors are active -> actual plugin depends on
            if (activateDependencies)
            {
                //try to activate depend plugins
                if (Predecessors.Count(elem => !((PluginNode)elem).Activate(true)) > 0)
                {
                    return(false);
                }
            }
            else
            {
                //just count inactive plugins
                if (Predecessors.Count(elem => !((PluginNode)elem).IsActive) > 0)
                {
                    return(false);
                }
            }

            PluginInstance = Graph.PluginManager.CreatePluginInstance(Value);

            if (PluginInstance == null)
            {
                return(false);
            }

            Graph.NotifyPlugins(PluginInstance, PluginNotification.Created);

            PluginContext = Graph.PluginManager.CreatePluginContext(PluginInstance);

            PluginInstance.ActivatePlugin(PluginContext);

            IsActive = true;

            Graph.NotifyPlugins(PluginInstance, PluginNotification.Activated);

            return(true);
        }
예제 #2
0
        public bool Deactivate(bool deactivateDependencies)
        {
            if (!IsActive)
            {
                return(true);
            }

            //check all successors -> these are the ones which depends on actual plugin
            if (deactivateDependencies)
            {
                //try to activate depend plugins
                if (Predecessors.Count(elem => !((PluginNode)elem).Deactivate(true)) > 0)
                {
                    return(false);
                }
            }
            else
            {
                //just count active plugins
                if (Predecessors.Count(elem => ((PluginNode)elem).IsActive) > 0)
                {
                    return(false);
                }
            }

            PluginInstance.DeactivatePlugin(PluginContext);

            IsActive = false;

            Graph.NotifyPlugins(PluginInstance, PluginNotification.Deactivated);

            PluginInstance.Dispose();

            Graph.NotifyPlugins(PluginInstance, PluginNotification.Disposed);

            PluginInstance = null;
            PluginContext  = null;

            return(true);
        }
예제 #3
0
        public void Validate()
        {
            if (RefSuccessors.Count > 0)
            {
                throw new ValidatorException("Basic block contains a reference to successors that could not be resolved. Basic block: " + ID);
            }
            if (RefPredecessors.Count > 0)
            {
                throw new ValidatorException("Basic block contains a reference to successors that could not be resolved. Basic block: " + ID);
            }

            if (Instructions.Last().statementType == Common.StatementType.ConditionalJump && Successors.Count != 2)
            {
                throw new ValidatorException("Basic block with ConditionalJump statement type must have exactly 2 successors.");
            }
            if (Predecessors.Count == 0 && Successors.Count == 0)
            {
                throw new ValidatorException("No predecessors and no successors found for basic block " + ID);
            }
            if (Instructions.Count == 0)
            {
                throw new ValidatorException("No instructions found for basic block " + ID);
            }
            if (Successors.Count > 2)
            {
                throw new ValidatorException("More than two successors found in basic block " + ID);
            }
            if (Predecessors.Count == 0 && !parent.BasicBlocks.First().Equals(this))
            {
                throw new ValidatorException("No predecessors found at basic block " + ID + ". By convention, only the first basic block has empty Predecessors list.");
            }
            if (Successors.Count == 0 && (Instructions.Count != 1 || Instructions[0].TACtext != "return"))
            {
                throw new ValidatorException("No successors found at basic block " + ID + ". By convention, only the 'fake exit block' has empty Successors list.");
            }
            if (Successors.Count == 2)
            {
                if (Instructions.Last().statementType != Common.StatementType.ConditionalJump)
                {
                    throw new ValidatorException("To have 2 successors, the last instruction of a basic block must be a ConditionalJump. Basic block: " + ID);
                }
                string resultString = Regex.Match(Instructions.Last().TACtext, @"\bID_[A-F0-9]{8}(?:-[A-F0-9]{4}){3}-[A-F0-9]{12}\b").Value;
                if (!resultString.Equals(Successors[0].ID))
                {
                    throw new ValidatorException("The first successor ID does not match the GOTO instruction. Basic block: " + ID);
                }
            }
            if (Predecessors.Count > 1 && Successors.Count > 0)
            {
                int preds_goto = Predecessors.Count(x =>
                                                    (x.Instructions.Last().statementType == Common.StatementType.ConditionalJump && this.Equals(x.getSuccessors.First())) ||
                                                    x.Instructions.Last().statementType == Common.StatementType.UnconditionalJump);
                if (Predecessors.Count - preds_goto > 1)
                {
                    throw new ValidatorException("Basic block has more that one direct predecessor (without GOTO). Basic block: " + ID);
                }
            }
            if (Successors.Count == 0)
            {
                int preds_proc = Predecessors.Count(x =>
                                                    x.Instructions.Last().statementType == Common.StatementType.Procedural);
                if (Predecessors.Count - preds_proc > 0)
                {
                    throw new ValidatorException("The 'fake exit block' can only have predecessors with last 'return' statement. Basic block: " + ID);
                }
            }

            // If a basic block has one predecessor, then it should be a direct predecessor without goto
            //if(Predecessors.Count==1 && Predecessors[0].Instructions.Last().statementType == Common.StatementType.UnconditionalJump)
            //    throw new ValidatorException("A basic block: " + ID + " has a single direct predecessor with unconditional GOTO.");

            // Checking Successor-Predecessor links
            foreach (BasicBlock succ in Successors)
            {
                if (!succ.Predecessors.Contains(this) && succ.RefPredecessors.Count == 0)
                {
                    throw new ValidatorException("Broken successor-predecessor link in basic block " + ID);
                }
            }
            foreach (BasicBlock pred in Predecessors)
            {
                if (!pred.Successors.Contains(this) && pred.RefSuccessors.Count == 0)
                {
                    throw new ValidatorException("Broken predecessor-successor link in basic block " + ID);
                }
            }

            foreach (Instruction inst in this.Instructions)
            {
                if (inst.parent != this)
                {
                    throw new ValidatorException("Instruction's 'parent' property is incorrect. Instruction: " + inst.ID);
                }
                inst.Validate();
            }
        }