Beispiel #1
0
        public static ulong Calculate(Lim.Asg.Nodes.Logical.Scope limScope, ref List <Interval> intervals)
        {
            ulong TLOC = 0;

            if (limScope.Factory.getFilterState(limScope.Id) == Lim.Asg.Filter.FilterState.Filtered)
            {
                return(0);
            }

            // The root package does not have all the isContainedIn edges
            // So we calculate its TLOC by the sum of its child package's TLOC

            // Subpackages are not physically inside their parent Packages
            // ( unlike e.g. local or anonym classes inside other classes )
            // So the TLOC of a Package is computed recursively
            if (Lim.Asg.Common.getIsPackage(limScope))
            {
                ListIterator <Lim.Asg.Nodes.Logical.Member> subPackageIt = limScope.HasMemberListIteratorBegin;
                while (subPackageIt.getValue() != null)
                {
                    Lim.Asg.Nodes.Logical.Member subPackage = subPackageIt.getValue();
                    if (!Lim.Asg.Common.getIsPackage(subPackage))
                    {
                        subPackageIt = subPackageIt.getNext();
                        continue;
                    }
                    Lim.Asg.Nodes.Logical.Package _subPackage = subPackage as Lim.Asg.Nodes.Logical.Package;
                    TLOC        += Calculate(_subPackage, ref intervals);
                    subPackageIt = subPackageIt.getNext();
                }
            }

            ListIteratorAssocSourcePosition <File> sourcePositionInFileBeginIt = limScope.IsContainedInListIteratorAssocBegin;

            for (var fileIt = sourcePositionInFileBeginIt.getValue(); fileIt != null; fileIt = sourcePositionInFileBeginIt.getNext().getValue())
            {
                var pos = sourcePositionInFileBeginIt.getAssocItem();
                var i   = new Interval
                {
                    Key  = limScope.Factory.StringTable.set(Lim.Asg.Common.GetFullPath(fileIt)),
                    From = pos.Line,
                    To   = pos.EndLine
                };
                intervals.Add(i);

                TLOC += i.To - i.From + 1;
            }

            return(TLOC);
        }
Beispiel #2
0
 /// <summary>
 /// Aggregate LLOC to the component
 /// </summary>
 /// <param name="NodeId">LIM node id</param>
 /// <param name="pathKey">Path hash code</param>
 /// <param name="line">Start line position</param>
 private static void AddLogicalLineOfComponent(uint NodeId, uint pathKey, uint line)
 {
     if (line > 0)
     {
         MainDeclaration.Instance.LLOCMap.Add(NodeId, pathKey, line);
         ListIterator <Base> itBegin = MainDeclaration.Instance.RevEdges.constIteratorBegin(NodeId, Types.EdgeKind.edkComponent_Contains);
         while (itBegin.getValue() != null)
         {
             AddLogicalLineOfComponent(itBegin.getValue().Id, pathKey, line);
             itBegin = itBegin.getNext();
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// Check Root component node contains the actual component
        /// </summary>
        /// <returns></returns>
        private static bool GetAlreadyContain(Component node)
        {
            bool alreadyContain         = false;
            ListIterator <Component> it = MainDeclaration.Instance.LimFactory.ComponentRootRef.ContainsListIteratorBegin;

            while (it.getValue() != null)
            {
                Component comp = it.getValue();
                if (comp.Id == node.Id)
                {
                    alreadyContain = true;
                    break;
                }
                it = it.getNext();
            }
            return(alreadyContain);
        }
Beispiel #4
0
        private static void MergeTLLOC(ref Scope limScope, ref Dictionary <uint, HashSet <uint> > TLLOC_Scope)
        {
            if (MainDeclaration.Instance.LLOCMap.ContainsKey(limScope.Id))
            {
                var TLLOC_ofScope = MainDeclaration.Instance.LLOCMap[limScope.Id];
                MergePathLineMaps(ref TLLOC_Scope, ref TLLOC_ofScope);
            }

            ListIterator <Member> it = limScope.HasMemberListIteratorBegin;

            while (it.getValue() != null)
            {
                Member memberIt = it.getValue();
                if (Lim.Asg.Common.getIsScope(memberIt))
                {
                    Scope memberItScope = memberIt as Scope;
                    MergeTLLOC(ref memberItScope, ref TLLOC_Scope);
                }
                it = it.getNext();
            }
        }
Beispiel #5
0
        public static void fillCollectedMethodData(Method method, MethodInfo methodInfo)
        {
            method.NestingLevel       = (ushort)methodInfo.NL;
            method.NestingLevelElseIf = (ushort)methodInfo.NLE;
            method.NumberOfBranches   = (ushort)methodInfo.NOB;
            method.NumberOfStatements = (ushort)methodInfo.NOS;

            foreach (KeyValuePair <uint, bool> call in methodInfo.Calls)
            {
                if (call.Value)
                {
                    MainDeclaration.Instance.LimFactory.setFiltered(call.Key);
                }
                Commons.Common.Safe_Edge(method, "Calls", call.Key);
            }
            foreach (KeyValuePair <uint, bool> throws in methodInfo.Throws)
            {
                if (throws.Value)
                {
                    MainDeclaration.Instance.LimFactory.setFiltered(throws.Key);
                }
                Commons.Common.Safe_Edge(method, "Throws", throws.Key);
            }
            foreach (KeyValuePair <uint, bool> canThrows in methodInfo.CanThrow)
            {
                if (canThrows.Value)
                {
                    MainDeclaration.Instance.LimFactory.setFiltered(canThrows.Key);
                }
                Commons.Common.Safe_Edge(method, "CanThrow", canThrows.Key);
            }
            foreach (KeyValuePair <uint, bool> instantiates in methodInfo.Instantiates)
            {
                if (instantiates.Value)
                {
                    MainDeclaration.Instance.LimFactory.setFiltered(instantiates.Key);
                }
                Commons.Common.Safe_Edge(method, "Instantiates", instantiates.Key);
            }
            foreach (KeyValuePair <uint, bool> accessAttribute in methodInfo.AccessAttribute)
            {
                if (accessAttribute.Value)
                {
                    MainDeclaration.Instance.LimFactory.setFiltered(accessAttribute.Key);
                }
                Commons.Common.Safe_Edge(method, "AccessesAttribute", accessAttribute.Key);
            }

            if (!method.ReturnsIsEmpty)
            {
                Lim.Asg.Nodes.Type.Type returnType = method.ReturnsListIteratorBegin.getValue();
                if (returnType != null)
                {
                    MainDeclaration.Instance.UsesStack.Peek().Remove(returnType.Id);
                }
            }

            if (!method.HasParameterIsEmpty)
            {
                ListIterator <Lim.Asg.Nodes.Logical.Parameter> paramIt = method.HasParameterListIteratorBegin;
                while (paramIt.getValue() != null)
                {
                    MainDeclaration.Instance.UsesStack.Peek().Remove(paramIt.getValue().getHasType());
                    paramIt = paramIt.getNext();
                }
            }

            IEnumerable <uint> _throws       = methodInfo.Throws.Select(t => t.Key);
            IEnumerable <uint> _canThrows    = methodInfo.CanThrow.Select(t => t.Key);
            IEnumerable <uint> _instantiates = methodInfo.Instantiates.Select(t => t.Key);

            Commons.Common.Remove(ref _throws);
            Commons.Common.Remove(ref _canThrows);
            Commons.Common.Remove(ref _instantiates);

            Commons.Common.AddUses(method);
        }