Fix in PPCMethod>>addVariable: make sure variable is added only once.
Having two variables with the same name is forbidden.
"{ Package: 'stx:goodies/petitparser/compiler' }"
Object subclass:#PPCMethod
instanceVariableNames:'buffer variables indentation id profile canInline'
classVariableNames:''
poolDictionaries:''
category:'PetitCompiler-Core'
!
!PPCMethod class methodsFor:'instance creation'!
new
"return an initialized instance"
^ self basicNew initialize.
! !
!PPCMethod methodsFor:'as yet unclassified'!
add: string
self nl.
indentation timesRepeat: [ buffer nextPutAll: ' ' ].
self addOnLine: string.
!
addOnLine: string
buffer nextPutAll: string.
!
addVariable: name
(variables includes: name) ifFalse:[ variables add: name ].
"Modified: / 30-10-2014 / 23:00:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
allowInline
canInline := true
!
body
^ buffer contents
!
bridge
^ PPCBridge on: self methodName.
!
call
^ 'self ', self methodName, '.'.
!
code
^ self methodName, String cr,
self variables, String cr,
self profilingBegin, String cr,
self body, String cr
" self profilingEnd"
!
dedent
indentation := indentation - 1
!
id: value
id := value
!
indent
indentation := indentation + 1
!
isMethod
^ true
!
methodName
^ id
!
nl
^ buffer nextPut: Character cr
!
profile
^ profile
!
profile: aBoolean
profile := aBoolean
!
profilingBegin
self profile ifTrue: [
^ ' context methodInvoked: #', id, '.'
].
^ ''
!
profilingEnd
self profile ifTrue: [
^ ' context methodFinished: #', id, '.'
].
^ ''
!
variables
^ ' | ', (variables inject: '' into: [ :s :e | s, ' ', e]), ' |'
! !
!PPCMethod methodsFor:'initialization'!
initialize
buffer := WriteStream on: ''.
indentation := 1.
variables := OrderedCollection new.
canInline := false
"Modified: / 30-10-2014 / 22:59:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!PPCMethod class methodsFor:'documentation'!
version_HG
^ '$Changeset: <not expanded> $'
! !