~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/Mono.Debugging/Mono.Debugging.Client/FunctionBreakpoint.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
using System;
27
27
using System.Xml;
 
28
using System.Collections.Generic;
28
29
 
29
30
namespace Mono.Debugging.Client
30
31
{
31
32
        [Serializable]
32
33
        public class FunctionBreakpoint : Breakpoint
33
34
        {
34
 
                public FunctionBreakpoint (string functionName, string language) : base (null, 1/*, 1*/)
 
35
                public FunctionBreakpoint (string functionName, string language) : base (null, 1, 1)
35
36
                {
36
37
                        FunctionName = functionName;
37
38
                        Language = language;
38
39
                }
 
40
 
 
41
                static bool SkipArrayRank (string text, ref int index, int endIndex)
 
42
                {
 
43
                        char c;
 
44
 
 
45
                        while (index < endIndex) {
 
46
                                if ((c = text[index++]) == ']')
 
47
                                        return true;
 
48
 
 
49
                                if (c != ',' && !char.IsWhiteSpace (c) && !char.IsDigit (c))
 
50
                                        return false;
 
51
                        }
 
52
 
 
53
                        return false;
 
54
                }
 
55
 
 
56
                static bool SkipGenericArgs (string text, ref int index, int endIndex)
 
57
                {
 
58
                        char c;
 
59
 
 
60
                        while (index < endIndex) {
 
61
                                if ((c = text[index++]) == '>')
 
62
                                        return true;
 
63
 
 
64
                                if (c == '<') {
 
65
                                        if (!SkipGenericArgs (text, ref index, endIndex))
 
66
                                                return false;
 
67
 
 
68
                                        while (index < endIndex && !char.IsWhiteSpace (text[index]))
 
69
                                                index++;
 
70
 
 
71
                                        // the only chars allowed after a '>' are: '>', '[', and ','
 
72
                                        if (">[,".IndexOf (text[index]) == -1)
 
73
                                                return false;
 
74
                                } else if (c == '[') {
 
75
                                        if (!SkipArrayRank (text, ref index, endIndex))
 
76
                                                return false;
 
77
 
 
78
                                        while (index < endIndex && !char.IsWhiteSpace (text[index]))
 
79
                                                index++;
 
80
 
 
81
                                        // the only chars allowed after a ']' are: '>', '[', and ','
 
82
                                        if (">[,".IndexOf (text[index]) == -1)
 
83
                                                return false;
 
84
                                } else if (c != '.' && c != '+' && c != ',' && !char.IsWhiteSpace (c) && !char.IsLetterOrDigit (c)) {
 
85
                                        return false;
 
86
                                }
 
87
                        }
 
88
 
 
89
                        return false;
 
90
                }
 
91
 
 
92
                public static bool TryParseParameters (string text, int startIndex, int endIndex, out string[] paramTypes)
 
93
                {
 
94
                        List<string> parsedParamTypes = new List<string> ();
 
95
                        int index = startIndex;
 
96
                        int start;
 
97
                        char c;
 
98
 
 
99
                        paramTypes = null;
 
100
 
 
101
                        while (index < endIndex) {
 
102
                                while (char.IsWhiteSpace (text[index]))
 
103
                                        index++;
 
104
 
 
105
                                start = index;
 
106
                                while (index < endIndex) {
 
107
                                        if ((c = text[index]) == ',')
 
108
                                                break;
 
109
 
 
110
                                        index++;
 
111
 
 
112
                                        if (c == '<') {
 
113
                                                if (!SkipGenericArgs (text, ref index, endIndex))
 
114
                                                        return false;
 
115
                                        } else if (c == '[') {
 
116
                                                if (!SkipArrayRank (text, ref index, endIndex))
 
117
                                                        return false;
 
118
                                        }
 
119
                                }
 
120
 
 
121
                                parsedParamTypes.Add (text.Substring (start, index - start).TrimEnd ());
 
122
 
 
123
                                if (index < endIndex)
 
124
                                        index++;
 
125
                        }
 
126
 
 
127
                        paramTypes = parsedParamTypes.ToArray ();
 
128
 
 
129
                        return true;
 
130
                }
39
131
                
40
132
                internal FunctionBreakpoint (XmlElement elem) : base (elem)
41
133
                {
42
134
                        FunctionName = elem.GetAttribute ("function");
43
135
                        
44
 
                        string s = elem.GetAttribute ("language");
45
 
                        if (string.IsNullOrEmpty (s))
 
136
                        string text = elem.GetAttribute ("language");
 
137
                        if (string.IsNullOrEmpty (text))
46
138
                                Language = "C#";
47
139
                        else
48
 
                                Language = s;
49
 
                        
50
 
                        s = elem.GetAttribute ("params");
51
 
                        if (!string.IsNullOrEmpty (s))
52
 
                                ParamTypes = s.Split (new char [] { ',' });
 
140
                                Language = text;
 
141
 
 
142
                        if (elem.HasAttribute ("params")) {
 
143
                                string[] paramTypes;
 
144
 
 
145
                                text = elem.GetAttribute ("params").Trim ();
 
146
                                if (text.Length > 0 && TryParseParameters (text, 0, text.Length, out paramTypes))
 
147
                                        ParamTypes = paramTypes;
 
148
                                else
 
149
                                        ParamTypes = new string[0];
 
150
                        }
 
151
 
 
152
                        FileName = null;
53
153
                }
54
154
                
55
155
                internal override XmlElement ToXml (XmlDocument doc)
60
160
                        elem.SetAttribute ("language", Language);
61
161
                        
62
162
                        if (ParamTypes != null)
63
 
                                elem.SetAttribute ("params", string.Join (",", ParamTypes));
 
163
                                elem.SetAttribute ("params", string.Join (", ", ParamTypes));
64
164
                        
65
165
                        return elem;
66
166
                }
77
177
                        get; set;
78
178
                }
79
179
                
80
 
                public void SetResolvedFileName (string resolvedFileName)
81
 
                {
82
 
                        FileName = resolvedFileName;
83
 
                }
84
 
                
85
180
                public override void CopyFrom (BreakEvent ev)
86
181
                {
87
182
                        base.CopyFrom (ev);
88
183
                        
89
184
                        FunctionBreakpoint bp = (FunctionBreakpoint) ev;
90
185
                        FunctionName = bp.FunctionName;
 
186
                        ParamTypes = bp.ParamTypes;
91
187
                }
92
188
        }
93
189
}