609
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2013 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libjavascript' }"
|
|
13 |
|
|
14 |
JavaScriptCompiler subclass:#JavaScriptCompilerWithBreakpointSupport
|
|
15 |
instanceVariableNames:'breakpoints'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Languages-JavaScript-Compiling & Parsing'
|
|
19 |
!
|
|
20 |
|
|
21 |
!JavaScriptCompilerWithBreakpointSupport class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2013 by eXept Software AG
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
!
|
|
36 |
|
|
37 |
documentation
|
|
38 |
"
|
|
39 |
I'm an experimental compiler class that supports breakpoints.
|
|
40 |
Once tested, the code might be merged to JavaScriptCompiler.
|
|
41 |
|
|
42 |
[author:]
|
|
43 |
code stolen from BytecodeCompilerWithBreakpointSupport
|
|
44 |
|
|
45 |
[instance variables:]
|
|
46 |
|
|
47 |
[class variables:]
|
|
48 |
|
|
49 |
[see also:]
|
|
50 |
|
|
51 |
"
|
|
52 |
! !
|
|
53 |
|
|
54 |
!JavaScriptCompilerWithBreakpointSupport methodsFor:'adding breakpoint'!
|
|
55 |
|
|
56 |
possiblyWrapABreakPointAround:aBlock
|
|
57 |
"refactored Jan's original code; changed to not wrap an already wrapped expression"
|
|
58 |
|
|
59 |
| expr bpnt tokenPositionBefore tokenLineNrBefore |
|
|
60 |
|
|
61 |
tokenPositionBefore := tokenPosition ? source position.
|
|
62 |
tokenLineNrBefore := tokenLineNr.
|
|
63 |
|
|
64 |
"/ find the very first breakpoint, which is right after the
|
|
65 |
"/ current line start, and remove it from the breakpoints collection,
|
|
66 |
"/ incl. all before. This removes breakpoints on empty lines or inside strings etc.
|
|
67 |
[
|
|
68 |
breakpoints notEmpty
|
|
69 |
and:[breakpoints first position < tokenPositionBefore]
|
|
70 |
] whileTrue:[
|
|
71 |
bpnt := breakpoints removeFirst
|
|
72 |
].
|
|
73 |
|
|
74 |
expr := aBlock value.
|
|
75 |
|
|
76 |
bpnt isNil ifTrue:[^expr].
|
|
77 |
expr isBreakPointNode ifTrue:[^expr].
|
|
78 |
tokenPositionBefore = tokenPosition ifTrue:[
|
|
79 |
"/ nothing scanned - happens with unaryExpression which does not find anything,
|
|
80 |
"/ but returns due to a ')' or ']' token.
|
|
81 |
^expr
|
|
82 |
].
|
|
83 |
|
|
84 |
bpnt isReached:true.
|
|
85 |
|
|
86 |
"/ Transcript show:'adding breakpoint '; show:bpnt; show:' before: '; showCR:expr.
|
|
87 |
|
|
88 |
^ BreakpointNode new
|
|
89 |
breakpoint: bpnt;
|
|
90 |
expression: expr;
|
|
91 |
lineNumber:(bpnt line ? tokenLineNrBefore);
|
|
92 |
yourself
|
|
93 |
|
|
94 |
"Created: / 05-07-2011 / 21:11:19 / cg"
|
|
95 |
!
|
|
96 |
|
|
97 |
possiblyWrapABreakPointBefore:aBlock
|
|
98 |
"refactored Jan's original code; changed to not wrap an already wrapped expression"
|
|
99 |
|
|
100 |
| stat bpnt tokenPositionBefore tokenLineNrBefore |
|
|
101 |
|
|
102 |
tokenPositionBefore := tokenPosition ? source position.
|
|
103 |
tokenLineNrBefore := tokenLineNr.
|
|
104 |
|
|
105 |
"/ find the very first breakpoint, which is right after the
|
|
106 |
"/ current line start, and remove it from the breakpoints collection,
|
|
107 |
"/ incl. all before. This removes breakpoints on empty lines or inside strings etc.
|
|
108 |
[
|
|
109 |
breakpoints notEmpty
|
|
110 |
and:[breakpoints first position < tokenPositionBefore]
|
|
111 |
] whileTrue:[
|
|
112 |
bpnt := breakpoints removeFirst
|
|
113 |
].
|
|
114 |
|
|
115 |
stat := aBlock value.
|
|
116 |
|
|
117 |
bpnt isNil ifTrue:[^stat].
|
|
118 |
((stat isKindOf:JavaScriptParser::StatementBlockNode)
|
|
119 |
and:[stat statements first isBreakPointNode]) ifTrue:[^stat].
|
|
120 |
|
|
121 |
tokenPositionBefore = tokenPosition ifTrue:[
|
|
122 |
"/ nothing scanned - happens with unaryExpression which does not find anything,
|
|
123 |
"/ but returns due to a ')' or ']' token.
|
|
124 |
^stat
|
|
125 |
].
|
|
126 |
|
|
127 |
bpnt isReached:true.
|
|
128 |
|
|
129 |
"/ Transcript show:'adding breakpoint '; show:bpnt; show:' before: '; showCR:expr.
|
|
130 |
|
|
131 |
^ JavaScriptParser::StatementBlockNode new
|
|
132 |
statements:{
|
|
133 |
BreakpointNode new
|
|
134 |
breakpoint: bpnt;
|
|
135 |
expression: nil;
|
|
136 |
lineNumber:(bpnt line ? tokenLineNrBefore);
|
|
137 |
yourself
|
|
138 |
.
|
|
139 |
stat
|
|
140 |
}
|
|
141 |
|
|
142 |
"Created: / 22-07-2013 / 15:42:08 / cg"
|
|
143 |
!
|
|
144 |
|
|
145 |
removeMissedBreakpointsBefore:aPosition
|
|
146 |
[
|
|
147 |
breakpoints notEmpty
|
|
148 |
and:[breakpoints first position < aPosition]
|
|
149 |
] whileTrue:[
|
|
150 |
breakpoints removeFirst
|
|
151 |
].
|
|
152 |
|
|
153 |
"Created: / 05-07-2011 / 23:13:25 / cg"
|
|
154 |
! !
|
|
155 |
|
|
156 |
!JavaScriptCompilerWithBreakpointSupport methodsFor:'parsing-expressions'!
|
|
157 |
|
|
158 |
addExpression
|
|
159 |
^ self possiblyWrapABreakPointAround:[super addExpression]
|
|
160 |
|
|
161 |
"Created: / 22-07-2013 / 15:36:03 / cg"
|
|
162 |
!
|
|
163 |
|
|
164 |
block
|
|
165 |
|blockNode|
|
|
166 |
|
|
167 |
self removeMissedBreakpointsBefore:source position.
|
|
168 |
blockNode := super block.
|
|
169 |
self removeMissedBreakpointsBefore:blockNode endPosition+2.
|
|
170 |
^ blockNode
|
|
171 |
|
|
172 |
"Created: / 05-07-2011 / 22:56:19 / cg"
|
|
173 |
!
|
|
174 |
|
|
175 |
expression
|
|
176 |
^ self possiblyWrapABreakPointAround:[super expression]
|
|
177 |
|
|
178 |
"Created: / 16-06-2011 / 14:58:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
179 |
"Modified: / 05-07-2011 / 21:11:38 / cg"
|
|
180 |
!
|
|
181 |
|
|
182 |
primaryExpression
|
|
183 |
^ self possiblyWrapABreakPointAround:[super primaryExpression]
|
|
184 |
|
|
185 |
"Created: / 22-07-2013 / 15:37:04 / cg"
|
|
186 |
!
|
|
187 |
|
|
188 |
unaryExpression
|
|
189 |
^ self possiblyWrapABreakPointAround:[super unaryExpression]
|
|
190 |
|
|
191 |
"Created: / 05-07-2011 / 23:08:54 / cg"
|
|
192 |
! !
|
|
193 |
|
|
194 |
!JavaScriptCompilerWithBreakpointSupport methodsFor:'parsing-statements'!
|
|
195 |
|
|
196 |
statement
|
|
197 |
^ self possiblyWrapABreakPointBefore:[super statement]
|
|
198 |
|
|
199 |
"Created: / 22-07-2013 / 15:42:53 / cg"
|
|
200 |
! !
|
|
201 |
|
|
202 |
!JavaScriptCompilerWithBreakpointSupport methodsFor:'private'!
|
|
203 |
|
|
204 |
breakpoints:aCollection
|
|
205 |
breakpoints := aCollection copy sort:[:a :b|a position < b position].
|
|
206 |
|
|
207 |
"Created: / 16-06-2011 / 14:35:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
208 |
"Created: / 05-07-2011 / 21:37:28 / cg"
|
|
209 |
!
|
|
210 |
|
|
211 |
methodClass
|
|
212 |
^ methodClass ? JavaScriptFunctionWithBreakpoints
|
|
213 |
|
|
214 |
"Created: / 22-07-2013 / 15:53:54 / cg"
|
|
215 |
!
|
|
216 |
|
|
217 |
notifying: anObject
|
|
218 |
super notifying: anObject.
|
|
219 |
anObject notNil ifTrue:[
|
|
220 |
breakpoints isNil ifTrue:[
|
|
221 |
self breakpoints:(anObject perform: #breakpoints ifNotUnderstood:#()).
|
|
222 |
]
|
|
223 |
]
|
|
224 |
|
|
225 |
"Created: / 16-06-2011 / 14:35:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
226 |
"Modified: / 05-07-2011 / 21:48:37 / cg"
|
|
227 |
! !
|
|
228 |
|
|
229 |
!JavaScriptCompilerWithBreakpointSupport class methodsFor:'documentation'!
|
|
230 |
|
|
231 |
version
|
|
232 |
^ '$Header$'
|
|
233 |
!
|
|
234 |
|
|
235 |
version_CVS
|
|
236 |
^ '$Header$'
|
|
237 |
! !
|
|
238 |
|