From d67522bdc6cb2f9ae3d804e05bb63907f5133d23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20Ils=C3=B8=20Christensen?= Date: Tue, 4 Apr 2006 21:14:44 +0000 Subject: [PATCH] =?UTF-8?q?2006-04-04=20=20Jacob=20Ils=C3=B8=20Christensen?= =?UTF-8?q?=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * CoverageModel.cs: Removed redundant for loops in GetSourceRangeFor. * Makefile: Use -debug instead of -g. svn path=/trunk/monocov/; revision=59041 --- ChangeLog | 8 ++++ CoverageModel.cs | 113 +++++++++++++++-------------------------------- Makefile | 4 +- 3 files changed, 45 insertions(+), 80 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2c30c70..88991f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-04-04 Jacob Ilsø Christensen + + * CoverageModel.cs: Removed redundant for loops + in GetSourceRangeFor. + + * Makefile: Use -debug instead of -g. + 2006-04-04 Jacob Ilsø Christensen * Makefile: Fixed clean target. @@ -44,6 +51,7 @@ public. 2004-04-15 Rafael Teixeira + *: README - nowadays it's mono --profile=xxx and not --profile:xxx 2004-04-15 Zoltan Varga diff --git a/CoverageModel.cs b/CoverageModel.cs index 3a7da98..a5c9ede 100644 --- a/CoverageModel.cs +++ b/CoverageModel.cs @@ -1,4 +1,3 @@ - using System; using System.Collections; using System.Xml; @@ -7,7 +6,8 @@ using System.Reflection; using System.Text.RegularExpressions; using Mono.CompilerServices.SymbolWriter; -namespace MonoCov { +namespace MonoCov +{ public class CoverageModel : CoverageItem { @@ -23,7 +23,8 @@ public class CoverageModel : CoverageItem { */ private ArrayList filters; - public CoverageModel () { + public CoverageModel () + { namespaces = new Hashtable (); classes = new Hashtable (); sources = new Hashtable (); @@ -46,7 +47,8 @@ public class CoverageModel : CoverageItem { filters.Add (pattern); } - private bool IsFiltered (string name) { + private bool IsFiltered (string name) + { // Check positive filters first bool hasPositive = false; @@ -76,7 +78,8 @@ public class CoverageModel : CoverageItem { return false; } - private void LoadAssemblies (XmlDocument dom) { + private void LoadAssemblies (XmlDocument dom) + { foreach (XmlNode n in dom.GetElementsByTagName ("assembly")) { string assemblyName = n.Attributes ["name"].Value; string guid = n.Attributes ["guid"].Value; @@ -110,13 +113,15 @@ public class CoverageModel : CoverageItem { } } - private void LoadFilters (XmlDocument dom) { + private void LoadFilters (XmlDocument dom) + { foreach (XmlNode n in dom.GetElementsByTagName ("filter")) { AddFilter (n.Attributes ["pattern"].Value); } } - public void ReadFromFile (string fileName) { + public void ReadFromFile (string fileName) + { namespaces = new Hashtable (); classes = new Hashtable (); @@ -241,9 +246,8 @@ public class CoverageModel : CoverageItem { return n; } - private void computeMethodCoverage (MethodCoverageItem method, - LineNumberEntry[] lines, - string cov_info) { + private void computeMethodCoverage (MethodCoverageItem method, LineNumberEntry[] lines, string cov_info) + { ClassCoverageItem klass = method.Class; SourceFileCoverageData source = klass.sourceFile; @@ -325,83 +329,35 @@ public class CoverageModel : CoverageItem { // Return a range of source lines which have something to do with OFFSET. // private bool GetSourceRangeFor (int offset, MethodCoverageItem method, - LineNumberEntry[] lines, - ref int startLine, ref int endLine) { - - /** - * The line number info generated by mcs is pretty strange sometimes... :) - */ - - /** - * First, we split the range of IL offsets into consecutive blocks and - * identify the block which contains OFFSET. Then we identify the range - * of source lines which are mapped to this range by the line number - * entries. - */ - - int beginOffset = 0; - int endOffset = 0; - int i; - - for (i = 0; i < lines.Length; ++i) { + LineNumberEntry[] lines, + ref int startLine, ref int endLine) + { + for (int i = 0; i < lines.Length; ++i) { if (offset >= lines [i].Offset) if (i == lines.Length - 1) { - beginOffset = lines [i].Offset; - endOffset = lines [i].Offset; - break; + startLine = lines [i].Row; + endLine = lines [i].Row; + return true; } else if (offset < lines [i + 1].Offset) { - beginOffset = lines [i].Offset; - endOffset = lines [i + 1].Offset - 1; - break; - } - } - - /* - if (method.Name.IndexOf ("Find") != -1) { - Console.WriteLine ("OFFSET: " + offset + " " + beginOffset + " " + endOffset); - } - */ - - if (i == lines.Length) { - if (offset <= lines [0].Offset) { - return false; - } - else { - for (i = 0; i < lines.Length; ++i) - Console.WriteLine (lines [i]); - throw new Exception ("Unable to determine source range for offset " + offset + " in " + method.name); - } - } - - /* Find start line */ - for (i = 0; i < lines.Length; ++i) - if (lines [i].Offset == beginOffset) { - startLine = lines [i].Row; - break; - } - - // g_assert (i < num_line_numbers); - - /* Find end line */ - if (lines.Length == 1) - endLine = lines [0].Row; - else { - for (i = 0; i < lines.Length; ++i) - if (i == lines.Length - 1) { - endLine = lines [i].Row; - break; - } - else if (lines [i + 1].Offset > endOffset) { + startLine = lines [i].Row; endLine = lines [i + 1].Row - 1; - break; + return true; } } - return true; + if (offset <= lines [0].Offset) { + return false; + } + else { + for (int i = 0; i < lines.Length; ++i) + Console.WriteLine (lines [i]); + throw new Exception ("Unable to determine source range for offset " + offset + " in " + method.name); + } } - private ClassCoverageItem ProcessClass (Type t) { + private ClassCoverageItem ProcessClass (Type t) + { string className = t.FullName; int nsindex = className.LastIndexOf ("."); string namespace2; @@ -454,7 +410,8 @@ public class CoverageModel : CoverageItem { return klass; } - private void ProcessMethod (MethodBase monoMethod, MethodEntry entry, ClassCoverageItem klass, string methodName, string cov_info) { + private void ProcessMethod (MethodBase monoMethod, MethodEntry entry, ClassCoverageItem klass, string methodName, string cov_info) + { if (entry == null) // Compiler generated, abstract method etc. return; diff --git a/Makefile b/Makefile index 9900911..4bc3178 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ libmono-profiler-monocov.so: coverage.c $(CC) -g -I$(MONO_ROOT) `pkg-config --cflags glib-2.0` --shared -fPIC -o $@ $^ test: - gmcs -g test.cs + gmcs -debug test.cs mono --profile=monocov:outfile=res.cov test.exe cortests: @@ -74,7 +74,7 @@ hash-test: mono --profile=monocov:+Hashtable hash-table.exe test-colorizer.exe: test-colorizer.cs SyntaxHighlighter.cs - gmcs -g /out:$@ $^ + gmcs -debug /out:$@ $^ clean: rm -f monocov.exe monocov.exe.mdb symbols.exe symbols.exe.mdb nunit-console.exe libmono-profiler-monocov.so