Skip to content

Commit

Permalink
Add #isExpression to TAssignmentNode, TSendNode, TStatementListNode a…
Browse files Browse the repository at this point in the history
…nd TSwitchStmtNode, which redefines #asCASTExpressionIn: method.

Add #isExpression to TParseNode which answers false.
Add another palette which also display the C-AST in addition to the C-AST Expression.
  • Loading branch information
Hernán Morales Durand committed Sep 7, 2023
1 parent f7bbbca commit 8dd3c03
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 deletions.
6 changes: 6 additions & 0 deletions smalltalksrc/Slang/TAssignmentNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ TAssignmentNode >> isAssignment [
^true
]

{ #category : #testing }
TAssignmentNode >> isExpression [

^ true
]

{ #category : #testing }
TAssignmentNode >> isSameAs: aTParseNode [
^aTParseNode isAssignment
Expand Down
6 changes: 6 additions & 0 deletions smalltalksrc/Slang/TParseNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ TParseNode >> isDefine [
^false
]

{ #category : #testing }
TParseNode >> isExpression [

^ false
]

{ #category : #testing }
TParseNode >> isGoTo [

Expand Down
6 changes: 6 additions & 0 deletions smalltalksrc/Slang/TSendNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@ TSendNode >> isConditionalSend [
ifNil:ifNotNil: ifNotNil:ifNil: ifNil: ifNotNil) includes: selector
]

{ #category : #testing }
TSendNode >> isExpression [

^ true
]

{ #category : #testing }
TSendNode >> isLiteralArrayDeclaration [
^selector == #cCoerce:to:
Expand Down
6 changes: 6 additions & 0 deletions smalltalksrc/Slang/TStatementListNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ TStatementListNode >> initialize [
arguments := #()
]

{ #category : #testing }
TStatementListNode >> isExpression [

^ true
]

{ #category : #testing }
TStatementListNode >> isNilStmtListNode [

Expand Down
6 changes: 6 additions & 0 deletions smalltalksrc/Slang/TSwitchStmtNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ TSwitchStmtNode >> expression: expr cases: aTBraceNode otherwiseOrNil: otherwise
self otherwiseOrNil: otherwiseOrNilNode
]

{ #category : #testing }
TSwitchStmtNode >> isExpression [

^ true
]

{ #category : #comparing }
TSwitchStmtNode >> isSameAs: anotherNode [

Expand Down
29 changes: 23 additions & 6 deletions smalltalksrc/VMMaker-Tools/TParseNode.extension.st
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Extension { #name : #TParseNode }

{ #category : #'*VMMaker-Tools' }
TParseNode >> inspectNode: specBuilder [
<inspectorPresentationOrder: 910 title: 'C'>
TParseNode >> inspectNode [
<inspectorPresentationOrder: 912 title: 'C (AST)'>

^ SpTextPresenter new
text: (String streamContents: [ : stream |
Expand All @@ -15,10 +15,27 @@ TParseNode >> inspectNode: specBuilder [
definingClass: self class;
yourself).
cg pushScope: TStatementListNode new.
(self respondsTo: #expression)
ifTrue: [ (self asCASTExpressionIn: cg) prettyPrintOn: stream ]
ifFalse: [ (self asCASTIn: cg) prettyPrintOn: stream ] ]);
yourself
(self asCASTIn: cg) prettyPrintOn: stream ]);
yourself
]

{ #category : #'*VMMaker-Tools' }
TParseNode >> inspectNodeExpression [
<inspectorPresentationOrder: 910 title: 'C (AST Expr)'>

^ SpTextPresenter new
text: (String streamContents: [ : stream |
| cg |
cg := MLVMCCodeGenerator new.
cg vmMaker: VMMaker new.
cg vmMaker vmmakerConfiguration: VMMakerConfiguration.
cg currentMethod: (TMethod new
labels: Set new;
definingClass: self class;
yourself).
cg pushScope: TStatementListNode new.
(self asCASTExpressionIn: cg) prettyPrintOn: stream ]);
yourself
]

{ #category : #'*VMMaker-Tools' }
Expand Down

0 comments on commit 8dd3c03

Please sign in to comment.