This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
/
SourceLocation.cs
117 lines (99 loc) · 2.26 KB
/
SourceLocation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Runtime.Serialization;
namespace Mono.Debugger
{
// <summary>
// Represents a location in the source code on which we can insert a breakpoint.
// Instances of this class are normally created as the result of a user action
// such as a method lookup.
// </summary>
[Serializable]
public class SourceLocation
{
Module module;
SourceMethod source;
ISourceBuffer buffer;
int line;
public Module Module {
get { return module; }
}
public bool HasSourceFile {
get { return source != null; }
}
public ISourceBuffer SourceBuffer {
get {
if (HasSourceFile)
throw new InvalidOperationException ();
return buffer;
}
}
public SourceFile SourceFile {
get {
if (!HasSourceFile)
throw new InvalidOperationException ();
return source.SourceFile;
}
}
public SourceMethod Method {
get {
if (!HasSourceFile)
throw new InvalidOperationException ();
return source;
}
}
public int Line {
get {
if (line == -1)
return source.StartRow;
else
return line;
}
}
public string Name {
get {
if (line == -1)
return source.Name;
else if (HasSourceFile)
return String.Format ("{0}:{1}", SourceFile.FileName, line);
else
return String.Format ("{0}:{1}", SourceBuffer.Name, line);
}
}
public SourceLocation (SourceMethod source)
: this (source, -1)
{ }
public SourceLocation (SourceMethod source, int line)
{
this.module = source.SourceFile.Module;
this.source = source;
this.line = line;
if (source == null)
throw new InvalidOperationException ();
}
public SourceLocation (Module module, ISourceBuffer buffer, int line)
{
this.module = module;
this.buffer = buffer;
this.line = line;
}
internal TargetAddress GetAddress (int domain)
{
Method method = source.GetMethod (domain);
if (method == null)
return TargetAddress.Null;
if (line != -1) {
if (method.HasSource)
return method.Source.Lookup (line);
else
return TargetAddress.Null;
} else if (method.HasMethodBounds)
return method.MethodStartAddress;
else
return method.StartAddress;
}
public override string ToString ()
{
return String.Format ("SourceLocation ({0})", Name);
}
}
}