Skip to content

Commit

Permalink
implement GtPharoEvaluatedSelector methods [feenkcom/gtoolkit#3735]
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajKubelka committed May 14, 2024
1 parent 19e0d63 commit f18e9bb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/GToolkit-Pharo-Coder-Method/GtPharoEvaluatedCode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ GtPharoEvaluatedCode >> findRelevantContextInStack: aStack [
]

{ #category : #accessing }
GtPharoEvaluatedCode >> findSourceAstForContext: aContext [
"Return an AST node that corresponds to a given executed code."
GtPharoEvaluatedCode >> findSourceIntervalForContext: aContext sourceString: aSourceString [
"Return source code interval that corresponds to a given executed code."

<return: #RBMessageNode>
^ aContext method sourceNodeForPC: aContext pc
<return: #Interval or: nil>
| aUsedAst anInterval |
aUsedAst := aContext method sourceNodeForPC: aContext pc.
anInterval := GtPharoMethodNodeSourceIntervalFinder new
methodNode: aUsedAst;
sourceString: aSourceString;
find.
^ anInterval last isZero ifTrue: [ nil ] ifFalse: [ anInterval ]
]

{ #category : #printing }
Expand Down
28 changes: 28 additions & 0 deletions src/GToolkit-Pharo-Coder-Method/GtPharoEvaluatedSelector.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,34 @@ Class {
#category : #'GToolkit-Pharo-Coder-Method-Context'
}

{ #category : #accessing }
GtPharoEvaluatedSelector >> findRelevantContextInStack: aStack [
"Return a stack context that corresponds to a given evaluated code."

<return: #Context or: nil>
aStack
do: [ :aContext | (self isRelevantContextInStack: aContext) ifTrue: [ ^ aContext ] ].
^ nil
]

{ #category : #accessing }
GtPharoEvaluatedSelector >> findSourceIntervalForContext: aContext sourceString: aSourceString [
"Return an AST node that corresponds to a given executed code."

<return: #RBMessageNode>
^ aContext method rangeForPC: aContext pc
]

{ #category : #testing }
GtPharoEvaluatedSelector >> isRelevantContextInStack: aContext [
| aMethod |
aMethod := aContext isBlockContext
ifTrue: [ aContext compiledCode method ]
ifFalse: [ aContext compiledCode ].
^ aMethod selector = self methodSelector
and: [ aContext receiver == self receiver ]
]

{ #category : #accessing }
GtPharoEvaluatedSelector >> methodArguments [
^ methodArguments
Expand Down

0 comments on commit f18e9bb

Please sign in to comment.