-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
SmaCCMethodNodeSourceIntervalFinder
- Loading branch information
1 parent
deaaa3b
commit a9e6c0c
Showing
2 changed files
with
83 additions
and
20 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/SmaCC_Rewrite_Engine_UI/SmaCCMethodNodeSourceIntervalFinder.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
Class { | ||
#name : #SmaCCMethodNodeSourceIntervalFinder, | ||
#superclass : #Object, | ||
#instVars : [ | ||
'methodNode', | ||
'sourceString', | ||
'sourceAst', | ||
'sourceNode', | ||
'sourceInterval' | ||
], | ||
#category : #'SmaCC_Rewrite_Engine_UI-Context' | ||
} | ||
|
||
{ #category : #finding } | ||
SmaCCMethodNodeSourceIntervalFinder >> equivalentNodeTo: aNode in: otherTree [ | ||
"Taken from GtSmaCCTransformationToolkitDebuggerElement>>#equivalentNodeTo:in:" | ||
|
||
| equivParent nodeIndex equivNode | | ||
aNode isMethod ifTrue: [ ^ otherTree ]. | ||
(aNode parent isReturn and: [ aNode parent parent parent isMethod ]) | ||
ifTrue: [ equivNode := otherTree isSequence | ||
ifTrue: [ otherTree statements last ] | ||
ifFalse: [ otherTree ]. | ||
^ equivNode isReturn ifTrue: [ equivNode value ] ifFalse: [ equivNode ] ]. | ||
aNode parent isMethod | ||
ifTrue: [ otherTree isSequence ifTrue: [ ^ otherTree ] ifFalse: [ ^ otherTree parent ] ]. | ||
equivParent := self equivalentNodeTo: aNode parent in: otherTree. | ||
equivParent ifNil: [ ^ nil ]. | ||
nodeIndex := aNode parent children identityIndexOf: aNode. | ||
^ equivParent children at: nodeIndex ifAbsent: [ nil ] | ||
] | ||
|
||
{ #category : #finding } | ||
SmaCCMethodNodeSourceIntervalFinder >> find [ | ||
"Adopted from GtSmaCCTransformationToolkitDebuggerElement>>#intervalFromMethodNode:inSource:" | ||
|
||
<return: #Interval> | ||
sourceAst := RBParser | ||
parseExpression: sourceString | ||
onError: [ :msg :pos | ^ sourceInterval := 1 to: 0 ]. | ||
sourceNode := self equivalentNodeTo: methodNode in: sourceAst. | ||
sourceNode ifNil: [ ^ sourceInterval := 1 to: 0 ]. | ||
^ sourceInterval := sourceNode start to: sourceNode stop | ||
] | ||
|
||
{ #category : #accessing } | ||
SmaCCMethodNodeSourceIntervalFinder >> methodNode [ | ||
^ methodNode | ||
] | ||
|
||
{ #category : #accessing } | ||
SmaCCMethodNodeSourceIntervalFinder >> methodNode: anObject [ | ||
methodNode := anObject | ||
] | ||
|
||
{ #category : #'accessing - computed' } | ||
SmaCCMethodNodeSourceIntervalFinder >> sourceAst [ | ||
^ sourceAst | ||
] | ||
|
||
{ #category : #'accessing - computed' } | ||
SmaCCMethodNodeSourceIntervalFinder >> sourceInterval [ | ||
^ sourceInterval | ||
] | ||
|
||
{ #category : #'accessing - computed' } | ||
SmaCCMethodNodeSourceIntervalFinder >> sourceNode [ | ||
^ sourceNode | ||
] | ||
|
||
{ #category : #accessing } | ||
SmaCCMethodNodeSourceIntervalFinder >> sourceString [ | ||
^ sourceString | ||
] | ||
|
||
{ #category : #accessing } | ||
SmaCCMethodNodeSourceIntervalFinder >> sourceString: anObject [ | ||
sourceString := anObject | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters