/// <summary> /// Aggregate LLOC to the /// - File level /// - Scope level /// - Component level /// </summary> /// <returns></returns> private static Dictionary <uint, HashSet <uint> > GetFileLLOC() { Dictionary <uint, HashSet <uint> > fileLLOC = new Dictionary <uint, HashSet <uint> >(); foreach (var idIt in MainDeclaration.Instance.LLOCMap) { Lim.Asg.Nodes.Base.Base @ref = MainDeclaration.Instance.LimFactory.getRef(idIt.Key); // File var TLLOC_ofScope = idIt.Value; TLLOC.MergePathLineMaps(ref fileLLOC, ref TLLOC_ofScope); // Scope if (Lim.Asg.Common.getIsScope(@ref)) { Lim.Asg.Nodes.Logical.Scope scope = @ref as Lim.Asg.Nodes.Logical.Scope; foreach (var item in idIt.Value) { scope.LLOC += (uint)item.Value.Count; } } // Component else if (Lim.Asg.Common.getIsComponent(@ref)) { Lim.Asg.Nodes.Base.Component component = @ref as Lim.Asg.Nodes.Base.Component; foreach (var item in idIt.Value) { component.TLLOC += (uint)item.Value.Count; } } } return(fileLLOC); }
/// <summary> /// TLLOC and TLOC calculation /// </summary> private static void CalculateTotalLineMetrics() { Lim.Asg.Factory.Iterator it = MainDeclaration.Instance.LimFactory.getIterator(); while (it.hasNext()) { Lim.Asg.Nodes.Base.Base baseIt = it.getNext(); if (Lim.Asg.Common.getIsScope(baseIt)) { Lim.Asg.Nodes.Logical.Scope scope = baseIt as Lim.Asg.Nodes.Logical.Scope; scope.TLLOC = (uint)TLLOC.CollectTLLOC(ref scope); scope.SetLOC(); } if (Lim.Asg.Common.getIsComponent(baseIt)) { ulong tloc = 0; if (MainDeclaration.Instance.ComponentTLOCMap.ContainsKey(baseIt.Id)) { foreach (var itFileKeys in MainDeclaration.Instance.ComponentTLOCMap[baseIt.Id]) { tloc += itFileKeys.Value; } } (baseIt as Lim.Asg.Nodes.Base.Component).TLOC = (uint)tloc; } } }
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); }