Implement `Context >> argAndVarNames` using compiler-recorded debug info
This implementation overrides the one from stx:libbasic which
never worked properly (and it's horribly complex).
--- a/extensions.st Fri May 22 23:03:41 2020 +0100
+++ b/extensions.st Wed May 27 15:47:18 2020 +0100
@@ -13,11 +13,48 @@
dbgVariables
"Return a list of variables for this context (as collection
- of `DIVariable` instances)"
+ of `DIVariable` instances) or nil if no debug info is recorded"
- ^ self dbgVariableTable variables select:[:e | e physicalBlockSourceOffset == sourcePos ]
+ | vartab |
+
+ vartab := self dbgVariableTable.
+ ^ vartab notNil ifTrue:[ vartab variables select:[:e | e physicalBlockSourceOffset == sourcePos ] ] ifFalse:[ nil ]
"Created: / 07-02-2019 / 08:46:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 27-05-2020 / 15:21:57 / Jan Vrany <jan.vrany@labware.com>"
+! !
+
+!Context methodsFor:'special accessing'!
+
+argAndVarNames
+ "helper: given a context, return a collection of arg&var names"
+ "/
+ "/ Note that this method overrides the default implementation
+ "/ from stx:libbasic.
+ "/ The default is horrible, complex and buggy, never worked properly.
+ "/ And will be removed later without notice
+
+ |varinfos varnames |
+
+ varinfos := self dbgVariables.
+ varnames := Array new: self numArgs + self numVars.
+ varinfos size ~~ varnames size ifTrue:[
+ "/ Not all variables recorded, generate synthetic ones
+ self breakPoint: #jv.
+ 1 to: self numArgs do:[:i |
+ varnames at: i put: ('arg', i printString)
+ ].
+ self numArgs + 1 to: varnames size do:[:i |
+ varnames at: i put: ('local', (i - self numArgs) printString)
+ ]
+ ].
+ varinfos do:[:varinfo |
+ varnames at: varinfo frameOffset put: varinfo name
+ ].
+ ^ varnames.
+
+ "Modified: / 26-12-2015 / 08:20:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 27-05-2020 / 15:40:39 / Jan Vrany <jan.vrany@labware.com>"
! !
!Context methodsFor:'accessing'!
@@ -33,10 +70,12 @@
dbgVariables
"Return a list of variables for this context (as collection
- of `DIVariable` instances)"
+ of `DIVariable` instances) or nil if no debug info is recorded"
+
^ method dbgVariables
"Created: / 07-02-2019 / 08:45:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (comment): / 27-05-2020 / 15:22:32 / Jan Vrany <jan.vrany@labware.com>"
! !
!Method methodsFor:'accessing'!
@@ -61,22 +100,30 @@
!Method methodsFor:'accessing'!
dbgVariableTable
- "Return a DIVariableTable for this method"
- ^ self dbgInfo dbgVariableTable
+ "Return a DIVariableTable for this method or nil if not debug info is recorded"
+ | info |
+
+ info := self dbgInfo.
+ ^ info notNil ifTrue:[ info dbgVariableTable ] ifFalse:[ nil ]
"Created: / 15-07-2018 / 11:52:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified (comment): / 07-02-2019 / 08:41:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 27-05-2020 / 15:19:45 / Jan Vrany <jan.vrany@labware.com>"
! !
!Method methodsFor:'accessing'!
dbgVariables
"Return a list of variables for this context (as collection
- of `DIVariable` instances)"
+ of `DIVariable` instances) or nil if no debug info is recorded"
- ^ self dbgVariableTable variables select:[:e | e physicalBlockSourceOffset == 0 ]
+ | vartab |
+
+ vartab := self dbgVariableTable.
+ ^ vartab notNil ifTrue:[ vartab variables select:[:e | e physicalBlockSourceOffset == 0 ] ] ifFalse:[ nil ]
"Created: / 07-02-2019 / 08:47:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 27-05-2020 / 15:21:14 / Jan Vrany <jan.vrany@labware.com>"
! !
!Object methodsFor:'user interaction & notifications'!
--- a/stx_libcomp.st Fri May 22 23:03:41 2020 +0100
+++ b/stx_libcomp.st Wed May 27 15:47:18 2020 +0100
@@ -1,6 +1,7 @@
"
COPYRIGHT (c) 1989 by Claus Gittinger / eXept Software AG
COPYRIGHT (c) 2016 Jan Vrany
+ COPYRIGHT (c) 2020 LabWare
All Rights Reserved
This software is furnished under a license and may be used
@@ -27,6 +28,7 @@
"
COPYRIGHT (c) 1989 by Claus Gittinger / eXept Software AG
COPYRIGHT (c) 2016 Jan Vrany
+ COPYRIGHT (c) 2020 LabWare
All Rights Reserved
This software is furnished under a license and may be used
@@ -262,6 +264,7 @@
Context dbgVariableTable
Context dbgVariables
Method dbgVariables
+ Context argAndVarNames
)
!