2006-04-04 Jacob Ilsø Christensen <jacobilsoe@gmail.com>

* CoverageModel.cs: Removed redundant for loops
	in GetSourceRangeFor.

	* Makefile: Use -debug instead of -g.


svn path=/trunk/monocov/; revision=59041
This commit is contained in:
Jacob Ilsø Christensen 2006-04-04 21:14:44 +00:00
Родитель 47c4264592
Коммит d67522bdc6
3 изменённых файлов: 45 добавлений и 80 удалений

Просмотреть файл

@ -1,3 +1,10 @@
2006-04-04 Jacob Ilsø Christensen <jacobilsoe@gmail.com>
* CoverageModel.cs: Removed redundant for loops
in GetSourceRangeFor.
* Makefile: Use -debug instead of -g.
2006-04-04 Jacob Ilsø Christensen <jacobilsoe@gmail.com>
* Makefile: Fixed clean target.
@ -44,6 +51,7 @@
public.
2004-04-15 Rafael Teixeira <rafaelteixeirabr@hotmail.com>
*: README - nowadays it's mono --profile=xxx and not --profile:xxx
2004-04-15 Zoltan Varga <vargaz@freemail.hu>

Просмотреть файл

@ -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;

Просмотреть файл

@ -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