9982
|
1 |
"
|
10071
|
2 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
|
9982
|
3 |
All Rights Reserved
|
|
4 |
|
10071
|
5 |
Permission is hereby granted, free of charge, to any person
|
|
6 |
obtaining a copy of this software and associated documentation
|
|
7 |
files (the 'Software'), to deal in the Software without
|
|
8 |
restriction, including without limitation the rights to use,
|
|
9 |
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10 |
copies of the Software, and to permit persons to whom the
|
|
11 |
Software is furnished to do so, subject to the following
|
|
12 |
conditions:
|
|
13 |
|
|
14 |
The above copyright notice and this permission notice shall be
|
|
15 |
included in all copies or substantial portions of the Software.
|
|
16 |
|
|
17 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
18 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
19 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
21 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
22 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
24 |
OTHER DEALINGS IN THE SOFTWARE.
|
9982
|
25 |
"
|
|
26 |
"{ Package: 'stx:libtool' }"
|
|
27 |
|
|
28 |
"{ NameSpace: Tools }"
|
|
29 |
|
|
30 |
CodeViewService subclass:#BreakpointService
|
10208
|
31 |
instanceVariableNames:'breakpoints currentMethod'
|
9982
|
32 |
classVariableNames:''
|
|
33 |
poolDictionaries:''
|
|
34 |
category:'Interface-CodeView'
|
|
35 |
!
|
|
36 |
|
|
37 |
!BreakpointService class methodsFor:'documentation'!
|
|
38 |
|
|
39 |
copyright
|
|
40 |
"
|
10071
|
41 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
|
9982
|
42 |
All Rights Reserved
|
|
43 |
|
10071
|
44 |
Permission is hereby granted, free of charge, to any person
|
|
45 |
obtaining a copy of this software and associated documentation
|
|
46 |
files (the 'Software'), to deal in the Software without
|
|
47 |
restriction, including without limitation the rights to use,
|
|
48 |
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
49 |
copies of the Software, and to permit persons to whom the
|
|
50 |
Software is furnished to do so, subject to the following
|
|
51 |
conditions:
|
|
52 |
|
|
53 |
The above copyright notice and this permission notice shall be
|
|
54 |
included in all copies or substantial portions of the Software.
|
|
55 |
|
|
56 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
57 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
58 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
59 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
60 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
61 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
62 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
63 |
OTHER DEALINGS IN THE SOFTWARE.
|
9982
|
64 |
"
|
|
65 |
! !
|
|
66 |
|
10208
|
67 |
!BreakpointService methodsFor:'change & update'!
|
|
68 |
|
|
69 |
update: aspect with: param from: sender
|
|
70 |
|method|
|
|
71 |
|
|
72 |
method := codeView methodHolder value.
|
|
73 |
method ~~ currentMethod ifTrue:[
|
|
74 |
self updateBreakPointsFor:method.
|
|
75 |
].
|
|
76 |
|
|
77 |
super update: aspect with: param from: sender
|
|
78 |
|
|
79 |
"Created: / 06-07-2011 / 15:21:08 / cg"
|
|
80 |
!
|
|
81 |
|
|
82 |
updateBreakPointsFor:aMethod
|
|
83 |
|methodsBreakPoints|
|
|
84 |
|
|
85 |
methodsBreakPoints := OrderedCollection new.
|
|
86 |
aMethod notNil ifTrue:[
|
|
87 |
aMethod literalsDo:[:eachLiteral |
|
|
88 |
eachLiteral class == Breakpoint ifTrue:[
|
|
89 |
methodsBreakPoints add:eachLiteral.
|
|
90 |
].
|
|
91 |
].
|
|
92 |
].
|
|
93 |
breakpoints := methodsBreakPoints.
|
|
94 |
currentMethod := aMethod.
|
|
95 |
|
|
96 |
"Created: / 06-07-2011 / 15:24:09 / cg"
|
|
97 |
! !
|
|
98 |
|
9982
|
99 |
!BreakpointService methodsFor:'event handling'!
|
|
100 |
|
10182
|
101 |
buttonPress:button x:x y:y in:view
|
|
102 |
codeView methodHolder value isNil ifTrue:[
|
|
103 |
^ false
|
|
104 |
].
|
9982
|
105 |
view == gutterView ifTrue:[
|
|
106 |
button == 1 ifTrue:[
|
10182
|
107 |
self setOrToggleBreakpointAtLine:(textView yVisibleToLineNr:y).
|
|
108 |
^ true.
|
9982
|
109 |
].
|
|
110 |
button == 3 ifTrue:[
|
10182
|
111 |
^ true.
|
9982
|
112 |
]
|
|
113 |
].
|
10182
|
114 |
^ false
|
9982
|
115 |
|
|
116 |
"Created: / 17-06-2011 / 13:05:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
117 |
"Modified: / 28-06-2011 / 08:31:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
10182
|
118 |
"Modified (format): / 05-07-2011 / 21:33:29 / cg"
|
9982
|
119 |
! !
|
|
120 |
|
|
121 |
!BreakpointService methodsFor:'initialization'!
|
|
122 |
|
|
123 |
initialize
|
|
124 |
|
|
125 |
super initialize.
|
|
126 |
breakpoints := OrderedCollection new.
|
|
127 |
|
|
128 |
"Created: / 17-06-2011 / 13:49:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
129 |
! !
|
|
130 |
|
|
131 |
!BreakpointService methodsFor:'private'!
|
|
132 |
|
10182
|
133 |
breakpointAtLine:line
|
|
134 |
|pos|
|
9982
|
135 |
|
|
136 |
pos := textView characterPositionOfLine:line col:1.
|
|
137 |
^ breakpoints ? #() detect:[:each | each position = pos ] ifNone:[ nil ]
|
|
138 |
|
|
139 |
"Modified: / 17-06-2011 / 13:59:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
10182
|
140 |
"Modified (format): / 05-07-2011 / 21:33:23 / cg"
|
|
141 |
!
|
|
142 |
|
|
143 |
recompile
|
|
144 |
"recompile the current method for changed breakpoints"
|
|
145 |
|
|
146 |
|method|
|
|
147 |
|
|
148 |
method := codeView methodHolder value.
|
|
149 |
(method notNil and:[method hasPrimitiveCode not]) ifTrue:[
|
|
150 |
"/ be careful: if the text has been edited/modified, do not compile
|
|
151 |
textView modified ifTrue:[
|
|
152 |
self halt
|
|
153 |
] ifFalse:[
|
|
154 |
"/ prepare to get reachable bpts
|
|
155 |
breakpoints do:[:bp | bp isReached:false].
|
|
156 |
|
|
157 |
ByteCodeCompilerWithBreakpointSupport new
|
|
158 |
breakpoints:breakpoints;
|
|
159 |
|
|
160 |
compile:method source
|
|
161 |
forClass:method mclass
|
|
162 |
inCategory:method category
|
|
163 |
notifying:nil
|
|
164 |
install:true
|
|
165 |
skipIfSame:false
|
|
166 |
silent:true
|
|
167 |
foldConstants:true
|
|
168 |
ifFail:[ self halt ].
|
|
169 |
|
|
170 |
breakpoints := breakpoints select:[:bp | bp isReached]
|
|
171 |
]
|
|
172 |
]
|
|
173 |
|
|
174 |
"Created: / 05-07-2011 / 21:33:13 / cg"
|
9982
|
175 |
!
|
|
176 |
|
|
177 |
setOrToggleBreakpointAtLine:line
|
|
178 |
|pos bpnt|
|
|
179 |
|
|
180 |
pos := textView characterPositionOfLine:line col:1.
|
|
181 |
bpnt := self breakpointAtLine:line.
|
10182
|
182 |
bpnt isNil ifTrue:[
|
|
183 |
breakpoints add:((Breakpoint new)
|
|
184 |
position:pos;
|
|
185 |
line:line).
|
|
186 |
self recompile.
|
|
187 |
] ifFalse:[
|
|
188 |
bpnt toggle.
|
|
189 |
].
|
9982
|
190 |
gutterView redrawLine:line.
|
|
191 |
|
|
192 |
"Created: / 17-06-2011 / 13:45:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
10182
|
193 |
"Modified: / 05-07-2011 / 21:32:49 / cg"
|
9982
|
194 |
! !
|
|
195 |
|
|
196 |
!BreakpointService methodsFor:'redrawing'!
|
|
197 |
|
10182
|
198 |
drawLine:lineNo in:view atX:x y:y width:w height:h from:startCol to:endColOrNil with:fg and:bg
|
9982
|
199 |
"Called by both gutterView and textView (well, not yet) to
|
|
200 |
allow services to draw custom things on text view.
|
|
201 |
Ask JV what the args means if unsure (I'm lazy to document
|
|
202 |
them, now it is just an experiment...)"
|
10182
|
203 |
|
|
204 |
|bpnt icon dx dy|
|
9982
|
205 |
|
10182
|
206 |
codeView methodHolder value isNil ifTrue:[
|
|
207 |
^ self
|
|
208 |
].
|
|
209 |
view == gutterView ifTrue:[
|
|
210 |
bpnt := self breakpointAtLine:lineNo.
|
|
211 |
bpnt isNil ifTrue:[
|
|
212 |
^ self
|
|
213 |
].
|
|
214 |
icon := bpnt icon.
|
|
215 |
icon isNil ifTrue:[
|
|
216 |
^ self
|
|
217 |
].
|
|
218 |
dx := ((w - icon width) / 2) rounded.
|
|
219 |
dy := ((h - icon height) / 2) rounded.
|
|
220 |
icon
|
|
221 |
displayOn:view
|
|
222 |
x:x + dx
|
|
223 |
y:y - h + dy + 4. "TODO: Magic constant"
|
9982
|
224 |
].
|
|
225 |
|
|
226 |
"Created: / 17-06-2011 / 13:52:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
10182
|
227 |
"Modified (format): / 05-07-2011 / 22:14:33 / cg"
|
9982
|
228 |
! !
|
|
229 |
|
|
230 |
!BreakpointService class methodsFor:'documentation'!
|
|
231 |
|
|
232 |
version_CVS
|
10208
|
233 |
^ '$Header: /cvs/stx/stx/libtool/Tools__BreakpointService.st,v 1.4 2011-07-06 14:08:38 cg Exp $'
|
9982
|
234 |
!
|
|
235 |
|
|
236 |
version_SVN
|
|
237 |
^ '§Id§'
|
|
238 |
! !
|