Пример #1
0
        /// <summary>
        ///     Provides all the function calls related to this namespace
        /// </summary>
        /// <param name="system">The system in which the calls should be gathered</param>
        /// <param name="container">If provided, indicates that the calls should be limited to a given container</param>
        /// <returns></returns>
        public static List <AccessMode> getAccesses(EfsSystem system, IEnclosesNameSpaces container = null)
        {
            SortedSet <ProcedureOrFunctionCall> procedureCalls      = new SortedSet <ProcedureOrFunctionCall>();
            SortedSet <AccessToVariable>        accessesToVariables = new SortedSet <AccessToVariable>();

            foreach (Usage usage in system.FindReferences(IsCallableOrIsVariable.INSTANCE))
            {
                ModelElement target = (ModelElement)usage.Referenced;
                ModelElement source = usage.User;

                NameSpace sourceNameSpace = getCorrespondingNameSpace(source, container, true);
                NameSpace targetNameSpace = getCorrespondingNameSpace(target, container, false);

                if (IsCallable.Predicate(usage.Referenced))
                {
                    if (considerCall(usage, container, sourceNameSpace, targetNameSpace))
                    {
                        procedureCalls.Add(new ProcedureOrFunctionCall(sourceNameSpace, targetNameSpace,
                                                                       (ICallable)target));
                    }
                }
                else
                {
                    // IsVariable(usage.Referenced)
                    if (considerVariableReference(usage, container, sourceNameSpace, targetNameSpace))
                    {
                        Usage.ModeEnum mode = (Usage.ModeEnum)usage.Mode;

                        // Find a corresponding access to variable (same source and target namespaces, and same variable
                        AccessToVariable otherAccess = null;
                        foreach (AccessToVariable access in accessesToVariables)
                        {
                            if (access.Target == usage.Referenced && access.Source == sourceNameSpace &&
                                access.Target == targetNameSpace)
                            {
                                otherAccess = access;
                                break;
                            }
                        }

                        if (otherAccess != null)
                        {
                            if (otherAccess.AccessMode != mode)
                            {
                                // Since the access mode is different, one of them is either Read or ReadWrite and the other is ReadWrite or Write.
                                // So, in any case, the resulting access mode is ReadWrite
                                accessesToVariables.Remove(otherAccess);
                                accessesToVariables.Add(new AccessToVariable(sourceNameSpace, targetNameSpace,
                                                                             (IVariable)target, Usage.ModeEnum.ReadAndWrite));
                            }
                            else
                            {
                                // Already exists, do nothing
                            }
                        }
                        else
                        {
                            // Does not already exists, insert it in the list
                            accessesToVariables.Add(new AccessToVariable(sourceNameSpace, targetNameSpace,
                                                                         (IVariable)target, mode));
                        }
                    }
                }
            }

            // Build the results based on the intermediate results
            List <AccessMode> retVal = new List <AccessMode>();

            retVal.AddRange(procedureCalls);
            retVal.AddRange(accessesToVariables);

            return(retVal);
        }
        /// <summary>
        ///     Creates a section for a namespace
        /// </summary>
        /// <param name="nameSpace">The namespace to consider</param>
        /// <param name="accesses">The accesses performed in the system</param>
        /// <returns></returns>
        public void CreateNameSpaceSection(NameSpace nameSpace, List <AccessMode> accesses)
        {
            AddSubParagraph("Namespace " + nameSpace.FullName);

            Dictionary <Procedure, List <ProcedureOrFunctionCall> > procedureCalls =
                new Dictionary <Procedure, List <ProcedureOrFunctionCall> >();
            Dictionary <Function, List <ProcedureOrFunctionCall> > functionCalls =
                new Dictionary <Function, List <ProcedureOrFunctionCall> >();
            Dictionary <IVariable, List <AccessToVariable> > accessesToVariables =
                new Dictionary <IVariable, List <AccessToVariable> >();

            foreach (AccessMode access in accesses)
            {
                ProcedureOrFunctionCall call = access as ProcedureOrFunctionCall;
                if (call != null)
                {
                    if (call.Target == nameSpace)
                    {
                        {
                            Function function = call.ReferencedModel as Function;
                            if (function != null)
                            {
                                List <ProcedureOrFunctionCall> calls;
                                if (!functionCalls.TryGetValue(function, out calls))
                                {
                                    calls = new List <ProcedureOrFunctionCall>();
                                    functionCalls.Add(function, calls);
                                }
                                calls.Add(call);
                            }
                        }

                        {
                            Procedure procedure = call.ReferencedModel as Procedure;
                            if (procedure != null)
                            {
                                List <ProcedureOrFunctionCall> calls;
                                if (!procedureCalls.TryGetValue(procedure, out calls))
                                {
                                    calls = new List <ProcedureOrFunctionCall>();
                                    procedureCalls.Add(procedure, calls);
                                }
                                calls.Add(call);
                            }
                        }
                    }
                }

                AccessToVariable accessToVariable = access as AccessToVariable;
                if (accessToVariable != null)
                {
                    if (accessToVariable.Target == nameSpace)
                    {
                        List <AccessToVariable> variableAccesses;
                        if (!accessesToVariables.TryGetValue(accessToVariable.Variable, out variableAccesses))
                        {
                            variableAccesses = new List <AccessToVariable>();
                            accessesToVariables.Add(accessToVariable.Variable, variableAccesses);
                        }
                        variableAccesses.Add(accessToVariable);
                    }
                }
            }

            if (procedureCalls.Keys.Count > 0)
            {
                AddSubParagraph("Exposed procedures");
                foreach (KeyValuePair <Procedure, List <ProcedureOrFunctionCall> > pair in procedureCalls)
                {
                    Procedure procedure = pair.Key;
                    AddSubParagraph("Procedure " + procedure.Name);
                    CreateProcedureOrFunctionHeader(procedure);
                    CreateProcedureOrFunctionUsage(pair.Value);
                    CloseSubParagraph();
                }
                CloseSubParagraph();
            }

            if (functionCalls.Keys.Count > 0)
            {
                AddSubParagraph("Exposed functions");
                foreach (KeyValuePair <Function, List <ProcedureOrFunctionCall> > pair in functionCalls)
                {
                    Function function = pair.Key;
                    AddSubParagraph("Function " + function.Name);
                    CreateProcedureOrFunctionHeader(function);
                    CreateProcedureOrFunctionUsage(pair.Value);
                    CloseSubParagraph();
                }
                CloseSubParagraph();
            }

            if (accessesToVariables.Count > 0)
            {
                AddSubParagraph("Exposed variables");
                foreach (KeyValuePair <IVariable, List <AccessToVariable> > pair in accessesToVariables)
                {
                    IVariable variable = pair.Key;
                    AddSubParagraph("Variable " + variable.Name);
                    CreateVariableHeader(variable);
                    CreateVariableUsage(pair.Value);
                    CloseSubParagraph();
                }
                CloseSubParagraph();
            }
            CloseSubParagraph();
        }