Skip to content

Commit

Permalink
Merge pull request #17067 from jecisc/ast/renamings
Browse files Browse the repository at this point in the history
Keep renaming AST nodes to start with AST instead of RB
  • Loading branch information
Ducasse authored Sep 5, 2024
2 parents 341d0ab + 16e9c6b commit 7a67513
Show file tree
Hide file tree
Showing 101 changed files with 674 additions and 673 deletions.
28 changes: 14 additions & 14 deletions doc/RefactoringEngine/4-RefactoringEngineFoundation.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ a single element
- ASTLiteralValueNode
an expression
- ASTAssignmentNode
- RBMessageNode
- ASTMessageNode
- ASTReturnNode
- ASTCascadeNode
a sequence of expressions
- RBSequenceNode
- ASTSequenceNode
or a block or Method
- RBBlockNode
- ASTBlockNode
- RBMethodNode

These nodes are part of a class hierarchy starting with ASTProgramNode an abstract class defining the common operations needed for all nodes. Every node knows about its child nodes, the source code location, any comment attached (comment prior to this node in the source code, or for RBMethodNodes the "method comment" line), and the type (by its subclass) - see the is-Methods in "testing"-protocol.
Expand Down Expand Up @@ -54,8 +54,8 @@ Therefor a parser first translates the source code into an abstract syntax tree

The tree consists of nodes for every source code element, tagged it with some "type" information (the node subclass), source code location, and optional properties. And it represents the whole source code structure.

For example, the AST for the source code of a method has a RBMethodNode with child nodes RBArgument for the arguments (if any) and a RBSequenceNode for the code body. The RBSequenceNode has child nodes for any
defined temporaries and the actual code, ASTAssignmentNode for variable assignments, RBMessageNode for message sends.
For example, the AST for the source code of a method has a RBMethodNode with child nodes RBArgument for the arguments (if any) and a ASTSequenceNode for the code body. The ASTSequenceNode has child nodes for any
defined temporaries and the actual code, ASTAssignmentNode for variable assignments, ASTMessageNode for message sends.

This is how the structure for Numbers #sgn method AST looks:

Expand All @@ -67,21 +67,21 @@ RBParser parseMethod:'sign
```
```
|->RBMethodNode sign
|->RBSequenceNode self > 0 ifTrue: [ ^ 1 ]. self < 0 ifTrue: [ ^ -1 ]. ^ 0
|->RBMessageNode ifTrue:
|->RBMessageNode >
|->ASTSequenceNode self > 0 ifTrue: [ ^ 1 ]. self < 0 ifTrue: [ ^ -1 ]. ^ 0
|->ASTMessageNode ifTrue:
|->ASTMessageNode >
|->RBSelfNode self
|->ASTLiteralValueNode 0
|->RBBlockNode [ ^ 1 ]
|->RBSequenceNode ^ 1
|->ASTBlockNode [ ^ 1 ]
|->ASTSequenceNode ^ 1
|->ASTReturnNode ^ 1
|->ASTLiteralValueNode 1
|->RBMessageNode ifTrue:
|->RBMessageNode <
|->ASTMessageNode ifTrue:
|->ASTMessageNode <
|->RBSelfNode self
|->ASTLiteralValueNode 0
|->RBBlockNode [ ^ -1 ]
|->RBSequenceNode ^ -1
|->ASTBlockNode [ ^ -1 ]
|->ASTSequenceNode ^ -1
|->ASTReturnNode ^ -1
|->ASTLiteralValueNode -1
|->ASTReturnNode ^ 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
Class {
#name : 'RBBlockNodeTest',
#name : 'ASTBlockNodeTest',
#superclass : 'RBParseTreeTest',
#category : 'AST-Core-Tests-Nodes',
#package : 'AST-Core-Tests',
#tag : 'Nodes'
}

{ #category : 'tests' }
RBBlockNodeTest >> testConstantValue [
ASTBlockNodeTest >> testConstantValue [

self assert: [ ] sourceNode constantValue equals: nil.
self assert: [ 1 ] sourceNode constantValue equals: 1.
self should: [[ ^1 ] sourceNode constantValue] raise: TestResult error
]

{ #category : 'tests' }
RBBlockNodeTest >> testHasNonLocalReturn [
ASTBlockNodeTest >> testHasNonLocalReturn [

self deny: [ ] sourceNode hasNonLocalReturn.
self deny: [ [ ] ] sourceNode hasNonLocalReturn.
Expand All @@ -29,7 +29,7 @@ RBBlockNodeTest >> testHasNonLocalReturn [
]

{ #category : 'tests' }
RBBlockNodeTest >> testIsClean [
ASTBlockNodeTest >> testIsClean [
| escpWrite escpRead |
escpRead := escpWrite := 1.
self deny: [ self yourself ] sourceNode isClean.
Expand Down Expand Up @@ -59,7 +59,7 @@ RBBlockNodeTest >> testIsClean [
]

{ #category : 'tests' }
RBBlockNodeTest >> testIsConstant [
ASTBlockNodeTest >> testIsConstant [

self assert: [ ] sourceNode isConstant.
self assert: [ 1 ] sourceNode isConstant.
Expand All @@ -68,7 +68,7 @@ RBBlockNodeTest >> testIsConstant [
]

{ #category : 'tests' }
RBBlockNodeTest >> testNumArgs [
ASTBlockNodeTest >> testNumArgs [
self assert: [ ] sourceNode numArgs equals: 0.
self assert: [:a | ] sourceNode numArgs equals: 1.
self assert: [:a :b | ] sourceNode numArgs equals: [:a :b | ] numArgs
Expand Down
2 changes: 1 addition & 1 deletion src/AST-Core-Tests/ASTEvaluationTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Class {
{ #category : 'tests' }
ASTEvaluationTest >> testEvaluate [
self assert: (ASTLiteralNode value: 5) evaluate equals: 5.
self assert: (RBMessageNode receiver: 5 asLiteralNode selector: #class ) evaluate equals: 5 class
self assert: (ASTMessageNode receiver: 5 asLiteralNode selector: #class ) evaluate equals: 5 class
]

{ #category : 'tests' }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
Class {
#name : 'RBMessageNodeTest',
#name : 'ASTMessageNodeTest',
#superclass : 'RBParseTreeTest',
#category : 'AST-Core-Tests-Nodes',
#package : 'AST-Core-Tests',
#tag : 'Nodes'
}

{ #category : 'tests' }
RBMessageNodeTest >> testArgumentPartsForBinaryMessages [
ASTMessageNodeTest >> testArgumentPartsForBinaryMessages [
| tree message |
tree := self parseMethod: 'test 1 + 2 '.
message := tree sendNodes first.
self assert: message argumentPartStrings equals: #('2')
]

{ #category : 'tests' }
RBMessageNodeTest >> testArgumentPartsForKeywordMessages [
ASTMessageNodeTest >> testArgumentPartsForKeywordMessages [
| tree message |
tree := self parseMethod: 'test self between: x + 2 and: (y foo: 3)'.
message := tree sendNodes first.
self assert: message argumentPartStrings asArray equals: #('x + 2' '(y foo: 3)')
]
{ #category : 'tests' }
RBMessageNodeTest >> testArgumentPartsForKeywordMessages1 [
ASTMessageNodeTest >> testArgumentPartsForKeywordMessages1 [
| tree message |
tree := self parseMethod: 'test self between: 2 and: 3'.
message := tree sendNodes first.
self assert: message argumentPartStrings asArray equals: #('2' '3')
]
{ #category : 'tests' }
RBMessageNodeTest >> testArgumentPartsForKeywordMessages2 [
ASTMessageNodeTest >> testArgumentPartsForKeywordMessages2 [
| tree message |
tree := self parseMethod: 'test self between: x and: y'.
Expand All @@ -44,15 +44,15 @@ RBMessageNodeTest >> testArgumentPartsForKeywordMessages2 [
]
{ #category : 'tests' }
RBMessageNodeTest >> testArgumentPartsForUnaryMessages [
ASTMessageNodeTest >> testArgumentPartsForUnaryMessages [
| tree message |
tree := self parseMethod: 'test 1 foo '.
message := tree sendNodes first.
self assert: message argumentPartStrings equals: #()
]
{ #category : 'tests' }
RBMessageNodeTest >> testIntersectsInterval [
ASTMessageNodeTest >> testIntersectsInterval [
| tree message |
tree := self parseMethod: 'test self doit.'.
message := tree sendNodes first.
Expand All @@ -63,7 +63,7 @@ RBMessageNodeTest >> testIntersectsInterval [
]
{ #category : 'tests' }
RBMessageNodeTest >> testIsInlineToDo [
ASTMessageNodeTest >> testIsInlineToDo [
| messageNode |
messageNode := (RBParser parseExpression: '1 to: 2 by: 2 do: [:each |]').
self assert: messageNode isInlineToDo.
Expand All @@ -72,7 +72,7 @@ RBMessageNodeTest >> testIsInlineToDo [
]
{ #category : 'tests' }
RBMessageNodeTest >> testSelectorAndArgumentNamesForComposedKeywords [
ASTMessageNodeTest >> testSelectorAndArgumentNamesForComposedKeywords [
| tree message |
tree := self parseMethod: 'test self between: x and: y'.
message := tree sendNodes first.
Expand All @@ -84,31 +84,31 @@ RBMessageNodeTest >> testSelectorAndArgumentNamesForComposedKeywords [
]
{ #category : 'tests' }
RBMessageNodeTest >> testSelectorAndArgumentNamesForComposedKeywordsAndComplexArgs [
ASTMessageNodeTest >> testSelectorAndArgumentNamesForComposedKeywordsAndComplexArgs [
| tree message |
tree := self parseMethod: 'test self between: x + 2 and: (y foo: 3)'.
message := tree sendNodes first.
self assert: message selectorAndArgumentNames equals: 'between: x + 2 and: (y foo: 3)'
]
{ #category : 'tests' }
RBMessageNodeTest >> testSelectorAndArgumentNamesForSimpleKeywords [
ASTMessageNodeTest >> testSelectorAndArgumentNamesForSimpleKeywords [
| tree message |
tree := self parseMethod: 'test self doit: 5'.
message := tree sendNodes first.
self assert: message selectorAndArgumentNames equals: 'doit: 5'
]
{ #category : 'tests' }
RBMessageNodeTest >> testSelectorAndArgumentNamesForUnary [
ASTMessageNodeTest >> testSelectorAndArgumentNamesForUnary [
| tree message |
tree := self parseMethod: 'test self doit'.
message := tree sendNodes first.
self assert: message selectorAndArgumentNames equals: 'doit'
]
{ #category : 'tests' }
RBMessageNodeTest >> testSelectorInterval [
ASTMessageNodeTest >> testSelectorInterval [
| tree message |
tree := self parseMethod: 'test self doit'.
message := tree sendNodes first.
Expand All @@ -119,15 +119,15 @@ RBMessageNodeTest >> testSelectorInterval [
]
{ #category : 'tests' }
RBMessageNodeTest >> testSelectorPartsForBinaryMessages [
ASTMessageNodeTest >> testSelectorPartsForBinaryMessages [
| tree message |
tree := self parseMethod: 'test 1 + 2 '.
message := tree sendNodes first.
self assert: message selectorParts equals: #(#+)
]
{ #category : 'tests' }
RBMessageNodeTest >> testSelectorPartsForKeywordMessages [
ASTMessageNodeTest >> testSelectorPartsForKeywordMessages [
| tree message |
tree := self parseMethod: 'test self doit: 5'.
message := tree sendNodes first.
Expand All @@ -139,15 +139,15 @@ RBMessageNodeTest >> testSelectorPartsForKeywordMessages [
]
{ #category : 'tests' }
RBMessageNodeTest >> testSelectorPartsForUnaryMessages [
ASTMessageNodeTest >> testSelectorPartsForUnaryMessages [
| tree message |
tree := self parseMethod: 'test self doit'.
message := tree sendNodes first.
self assert: message selectorParts equals: #(#doit)
]
{ #category : 'tests' }
RBMessageNodeTest >> testStart [
ASTMessageNodeTest >> testStart [
| tree message delta |
tree := self parseMethod: 'test self doit.'.
Expand Down
10 changes: 5 additions & 5 deletions src/AST-Core-Tests/ASTProgramNodeTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ ASTProgramNodeTest >> testHasSameExitPointWhenSequenceWithLastReturnAndNonLocalR
instVar := true ifFalse: [ ^ 1 ].
instVar isOdd ifTrue: [ instVar := instVar + 1 ].
^ self end'.
sequence := RBSequenceNode statements: ast body statements allButFirst.
sequence := ASTSequenceNode statements: ast body statements allButFirst.
sequence parent: ast body.
self assert: sequence hasSameExitPoint
]
Expand All @@ -788,7 +788,7 @@ ASTProgramNodeTest >> testHasSameExitPointWhenSequenceWithLastReturnExpectTrue [
self foo.
instVar := true ifFalse: [ 1 ].
^ 2'.
sequence := RBSequenceNode statements: ast body statements allButFirst.
sequence := ASTSequenceNode statements: ast body statements allButFirst.
sequence parent: ast body.
self assert: sequence hasSameExitPoint
]
Expand All @@ -801,7 +801,7 @@ ASTProgramNodeTest >> testHasSameExitPointWhenSequenceWithoutAnyReturnsExpectTru
self foo.
instVar := true ifFalse: [ 1 ]
self end'.
sequence := RBSequenceNode statements: ast body statements allButFirst.
sequence := ASTSequenceNode statements: ast body statements allButFirst.
sequence parent: ast body.
self assert: sequence hasSameExitPoint
]
Expand All @@ -817,7 +817,7 @@ ASTProgramNodeTest >> testHasSameExitPointWhenSequenceWithoutLastReturnAndMultip
whileTrue: [ instVar < 10 ].
instVar := true ifFalse: [ ^ 1 ].
self end'.
sequence := RBSequenceNode statements: ast body statements allButLast.
sequence := ASTSequenceNode statements: ast body statements allButLast.
sequence parent: ast body.
self deny: sequence hasSameExitPoint
]
Expand All @@ -830,7 +830,7 @@ ASTProgramNodeTest >> testHasSameExitPointWhenSequenceWithoutLastReturnAndNonLoc
self foo.
instVar := true ifFalse: [ ^ 1 ]
self end'.
sequence := RBSequenceNode statements: ast body statements allButFirst.
sequence := ASTSequenceNode statements: ast body statements allButFirst.
sequence parent: ast body.
self deny: sequence hasSameExitPoint
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Class {
#name : 'RBSequenceNodeTest',
#name : 'ASTSequenceNodeTest',
#superclass : 'RBParseTreeTest',
#category : 'AST-Core-Tests-Nodes',
#package : 'AST-Core-Tests',
#tag : 'Nodes'
}

{ #category : 'tests' }
RBSequenceNodeTest >> testModifyParametersShouldNotModifyPeriods [
ASTSequenceNodeTest >> testModifyParametersShouldNotModifyPeriods [

| sequenceNode |
sequenceNode := RBSequenceNode new.
sequenceNode := ASTSequenceNode new.
sequenceNode statements add: #example.
self
assertCollection: sequenceNode statements
Expand All @@ -20,7 +20,7 @@ RBSequenceNodeTest >> testModifyParametersShouldNotModifyPeriods [
]

{ #category : 'tests' }
RBSequenceNodeTest >> testStop [
ASTSequenceNodeTest >> testStop [
| ast |
ast := self parserClass parseMethod: 'method | temp |'.
self assert: ast body stop equals: ast body temporaries last stop
Expand Down
Loading

0 comments on commit 7a67513

Please sign in to comment.