Skip to content

Commit

Permalink
fixes: #4410
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducasse committed Sep 8, 2019
1 parent ca17407 commit d8ddc13
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 6 deletions.
40 changes: 40 additions & 0 deletions src/ClassParser-Tests/CDMoreComplexSlotParserTest.class.st
@@ -0,0 +1,40 @@
Class {
#name : #CDMoreComplexSlotParserTest,
#superclass : #CDClassDefinitionParserTest,
#category : #'ClassParser-Tests'
}

{ #category : #helpers }
CDMoreComplexSlotParserTest >> classDefinitionString [

^ '{superclassname} subclass: #{classname}
slots: \{
''{instvar1}'' => LazyClassVariable default: 5.
''{instvar2}'' => InstanceVariableSlot.
''instVar3''
\}
classVariableNames: ''{classvar1} {classvar2}''
package: #MyPackage'
format: {
'classname' -> self className.
'superclassname' -> self superclassName.
'instvar1' -> self firstInstanceVariableName.
'instvar2' -> self secondInstanceVariableName.
'classvar1' -> self firstClassVariableName.
'classvar2' -> self secondClassVariableName. } asDictionary
]

{ #category : #helpers }
CDMoreComplexSlotParserTest >> testClassDefFromLegacyStringHasSlots [

self assert: classDefinition slotNodes first name equals: self firstInstanceVariableName.
self assert: classDefinition slotNodes first typeName equals: #LazyClassVariable.
self assert: classDefinition slotNodes first initializationMessage equals: 'default: 5'.

self assert: classDefinition slotNodes second name equals: self secondInstanceVariableName.
self assert: classDefinition slotNodes second typeName equals: #InstanceVariableSlot.

self assert: classDefinition slotNodes third name equals: 'instVar3'


]
23 changes: 20 additions & 3 deletions src/ClassParser/CDClassDefinitionParser.class.st
Expand Up @@ -175,6 +175,9 @@ CDClassDefinitionParser >> parseSelectorPart: aString withArgument: aNode [

{ #category : #parsing }
CDClassDefinitionParser >> parseSlotNode: aRBMessageNode [
"what ugly method!"

"when a slot is just 'inst'"
aRBMessageNode isLiteralNode
ifTrue: [ | slot |
slot := CDSlotNode
Expand All @@ -186,13 +189,27 @@ CDClassDefinitionParser >> parseSlotNode: aRBMessageNode [
classDefinition addSlot: slot.
^ self ].

self flag: #fixme. "This seems to not support Slots with Parameters for now".
aRBMessageNode selector = '=>'
"when a slot is just 'inst' => InstanceVariableSlot."
aRBMessageNode receiver isLiteralNode
ifTrue: [ | slot |
slot := CDSlotNode
node: aRBMessageNode
name: aRBMessageNode receiver value
typeName: aRBMessageNode arguments first name
typeName: aRBMessageNode arguments first name
start: aRBMessageNode start
stop: aRBMessageNode stop.
classDefinition addSlot: slot.
^ self ].

"when a slot is just 'inst' => InstanceVariableSlot default: 5."
aRBMessageNode receiver selector = '=>'
ifTrue: [ | slot slotDefNode |
slotDefNode := aRBMessageNode receiver.
slot := CDSlotNode
node: aRBMessageNode
name: slotDefNode value receiver value
typeName: slotDefNode arguments first name
initializationMessage: aRBMessageNode selectorAndArgumentNames
start: aRBMessageNode start
stop: aRBMessageNode stop.
classDefinition addSlot: slot.
Expand Down
40 changes: 37 additions & 3 deletions src/ClassParser/CDSlotNode.class.st
Expand Up @@ -8,11 +8,25 @@ Class {
'start',
'stop',
'name',
'typeName'
'typeName',
'initializationMessage'
],
#category : #'ClassParser-Model'
}

{ #category : #'instance-creation' }
CDSlotNode class >> node: aNode name: aName typeName: aTypeName initializationMessage: aString start: start stop: stop [

^ self new
node: aNode;
name: aName;
typeName: aTypeName;
initializationMessage: aString;
start: start;
stop: stop;
yourself
]

{ #category : #'instance-creation' }
CDSlotNode class >> node: aNode name: aName typeName: aTypeName start: start stop: stop [

Expand Down Expand Up @@ -42,6 +56,18 @@ CDSlotNode >> index: anInteger [
index := anInteger
]

{ #category : #accessing }
CDSlotNode >> initializationMessage [

^ initializationMessage
]

{ #category : #accessing }
CDSlotNode >> initializationMessage: aString [

initializationMessage := aString
]

{ #category : #testing }
CDSlotNode >> isClassVariable [
"To be polymorphic to RB method nodes"
Expand Down Expand Up @@ -116,9 +142,9 @@ CDSlotNode >> printOn: aStream [
aStream
nextPutAll: self class name;
nextPutAll: '(';
nextPutAll: name;
print: name ;
nextPutAll: ' => ';
nextPutAll: typeName;
print: typeName;
nextPutAll: ')'
]

Expand Down Expand Up @@ -149,6 +175,14 @@ CDSlotNode >> stop: anInteger [
stop := anInteger
]

{ #category : #accessing }
CDSlotNode >> typeName [
"Return the type of the slot: i.e., 'x' => InstanceVariableSlot typeName will return
#InstanceVariableSlot"

^ typeName
]

{ #category : #accessing }
CDSlotNode >> typeName: aString [

Expand Down

0 comments on commit d8ddc13

Please sign in to comment.