Skip to content

Commit

Permalink
Adds Instance Probe class and interval determination for it
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeAtHPI committed Sep 21, 2023
1 parent 0c0758f commit e47ec04
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 44 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ui
canBeAnnotatedTo

^ #(stringLiteral)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testing
isInstanceVariableProbe

^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
wantsMetaClassIndication

^ false
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"class" : {
},
"instance" : {
"canBeAnnotatedTo" : "joabe 9/21/2023 21:08",
"isInstanceVariableProbe" : "joabe 9/21/2023 21:18",
"wantsMetaClassIndication" : "joabe 9/21/2023 21:08" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"category" : "Babylonian-Core-Annotations",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
],
"name" : "BPInstanceVariableProbe",
"pools" : [
],
"super" : "BPProbe",
"type" : "normal" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testing
isInstanceVariableProbe

^ false
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"hasExpression" : "pre 6/7/2021 16:52",
"hasLabel" : "lu 5/20/2021 15:14",
"instrumentationCallFor:" : "pre 1/10/2023 17:33",
"isInstanceVariableProbe" : "joabe 9/21/2023 21:18",
"isProbe" : "pre 7/3/2019 11:12",
"isTemporaryProbe" : "pre 9/2/2022 14:40",
"label" : "joabe 5/9/2023 17:37",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*Babylonian-UI-annotations
addProbeToSelection

self addAnnotationAtSelection: BPProbe new.
self editSelection == #editClass
ifTrue: [self addAnnotationAtSelection: BPInstanceVariableProbe new]
ifFalse: [self addAnnotationAtSelection: BPProbe new]

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
*Babylonian-UI-private
allAndLowestUsefulAncestorFor: aListOfNodes canBeAnnotatedTo: aListOfKeywords

"This is necessary as we do only assume that the last node is the lowest one, not that
the rest of the nodes is necessarily ordered according to the tree"
| ancestors lowestCommonAncestorIndex parents |
parents := aListOfNodes collect: [:allNodes | {allNodes last} , allNodes last allParents].

"This is a naiive approach but is fine as the trees are not that deep."
lowestCommonAncestorIndex := parents first findFirst: [:n | parents second includes: n].
lowestCommonAncestorIndex = 0 ifTrue: [self error: 'broken tree, no common root found'].

ancestors := parents first
copyFrom: lowestCommonAncestorIndex
to: parents first size.

"This is not enough yet, we have the list of AST nodes covering the selected interval
and their full ranges, but these nodes could be nonsensical to annotate."
^ {ancestors. ancestors
detect: [:n | aListOfKeywords includes: n ruleName]
ifNone: ["This can happen if users selected more than one statement,
we now have to search for the first statement below the current index"
(parents first first: lowestCommonAncestorIndex) reverse
detect: [:n | aListOfKeywords includes: n ruleName]
ifNone: ["Try it again for the end of the interval"
(parents second copyUpTo: (parents first at: lowestCommonAncestorIndex)) reverse
detect: [:n | aListOfKeywords includes: n ruleName]
ifNone: [nil "There really is nothing to annotate"]]]}.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*Babylonian-UI-private
bpClassDeclarationSourceMap

| result map |
result := BPSmalltalkGrammar
match: self contents
startingFrom: #KeywordMessageSend.
result succeeded ifFalse: [self haltOnce. ^ #()].
map := (BPSmalltalkGrammar semanticAction: BPSourceMapping new)
createSourceMapFor: result cst.
^ map
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
*Babylonian-UI-private
determineIntervalOfVariableNameIn: anInterval having: aTopologicalCollectionOfAncestors

| lowestKeywordMessageSegment selectedText |

lowestKeywordMessageSegment := aTopologicalCollectionOfAncestors
detect: [:n | n ruleName = #KeywordMessageSegment]
ifNone: [^ nil].

((self contents atAll: lowestKeywordMessageSegment children first interval) ~= 'instanceVariableNames:') ifTrue: [^ nil].

selectedText := (self contents atAll: anInterval) withBlanksTrimmed.

^ self selectedClassOrMetaClass instVarNames
detect: [:aVariable | aVariable = selectedText]
ifFound: [:matchingVariable | | start |
start := self contents findString: matchingVariable.
^ Interval from: start to: start + matchingVariable size]


This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
*Babylonian-UI-private
determineIntervalToAnnotateFor: anAnnotation in: anInterval

| result sourceMap |
"This determines the interval to annotate for a selected interval.
The selected interval can also be a 0 width selection.
If there is not valid interval this method will return nil."

self bpEnsureContentsAndSelectedMessage.
self halt.
sourceMap := currentCompiledMethod ifNotNil: [currentCompiledMethod bpSourceMap] ifNil: [self bpClassDeclarationSourceMap].
result := self
allAndLowestUsefulAncestorFor: (sourceMap atAll: anInterval)
canBeAnnotatedTo: anAnnotation canBeAnnotatedTo.
result second ifNil: [^ nil].

anAnnotation isInstanceVariableProbe ifFalse: [^ result second interval].

(self editSelection == #editClass and: [self metaClassIndicated == anAnnotation wantsMetaClassIndication]) ifFalse: [^ nil].

^ self
determineIntervalOfVariableNameIn: anInterval
having: result first.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ determineMessageSendNodeIn: anInterval

| nodes messageSendRuleNames lowestMessageSend |
self bpEnsureContentsAndSelectedMessage.

self flag: #todo. "will break for instance probes jb"
nodes := currentCompiledMethod bpSourceMap at: anInterval start.
messageSendRuleNames := #(ExpressionOperandCascade ExpressionUnaryCascade ExpressionBinaryCascade UnaryMessageSend BinaryMessageSend KeywordMessageSend).
^ lowestMessageSend := nodes reversed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
doAddAnnotation: anAnnotation in: interval
"Separated from addAnotationIn: to allow for multiple annotations to be added without saving first."
| text actualInterval newMorph |
actualInterval := self determineIntervalToAnnotateFor: interval forNodes: anAnnotation canBeAnnotatedTo.
actualInterval := self determineIntervalToAnnotateFor: anAnnotation in: interval.
actualInterval ifNil: [self codeTextMorph textMorph flash. ^ self].
anAnnotation methodReference: self methodReference.
text := self codeTextMorph text.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@
"addAnnotation:in:" : "pre 8/17/2023 11:49",
"addAnnotationAtSelection:" : "pre 7/23/2022 20:17",
"addAssertionToSelection" : "pre 11/13/2019 17:37",
"addProbeToSelection" : "pre 8/6/2019 16:11",
"addProbeToSelection" : "joabe 9/21/2023 21:38",
"addProfilingProbeToSelection" : "pre 11/29/2022 16:32",
"addReplacementToSelection" : "pre 11/14/2019 15:50",
"addSliderToSelection" : "pre 9/22/2020 18:27",
"addTypeProbeToSelection" : "pre 11/30/2022 09:40",
"allAndLowestUsefulAncestorFor:canBeAnnotatedTo:" : "joabe 9/21/2023 20:26",
"annotationsInSelection" : "pre 11/8/2019 12:05",
"bindingOf:" : "pre 5/3/2021 14:26",
"bpClassDeclarationSourceMap" : "joabe 9/21/2023 17:59",
"bpEnsureContentsAndSelectedMessage" : "pre 9/1/2022 22:03",
"browseActualImplementers" : "pre 9/2/2022 15:27",
"codePaneMenuAnnotationItems:" : "pre 11/30/2022 09:40",
"codePaneMenuBPTracingItems:" : "pre 9/2/2022 15:06",
"compiledMethod" : "ct 3/30/2022 16:48",
"determineIntervalOfReceiver:" : "pre 9/2/2022 14:29",
"determineIntervalToAnnotateFor:forNodes:" : "pre 9/1/2022 22:03",
"determineMessageSendNodeIn:" : "pre 9/2/2022 14:06",
"determineIntervalOfVariableNameIn:having:" : "joabe 9/21/2023 21:40",
"determineIntervalToAnnotateFor:in:" : "joabe 9/21/2023 21:29",
"determineMessageSendNodeIn:" : "joabe 9/21/2023 21:31",
"determineSelectorOfMessageSend:" : "pre 9/2/2022 14:49",
"doAddAnnotation:in:" : "pre 8/17/2023 11:48",
"doAddAnnotation:in:" : "joabe 9/21/2023 21:28",
"doBrowseActualImplementersFromProbe:andSelector:" : "pre 9/2/2022 15:54",
"doItReceiver" : "ct 3/30/2022 16:48",
"exampleForEvaluation" : "ct 8/18/2021 23:15",
Expand Down

0 comments on commit e47ec04

Please sign in to comment.