compiler/PPCMethod.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 05 Nov 2014 23:05:19 +0000
changeset 414 0eaf09920532
parent 399 b5b7a6db033b
child 422 116d2b2af905
permissions -rw-r--r--
Merged JK's work on PetitCompiler Name: PetitCompiler-JanKurs.57 Author: JanKurs Time: 05-11-2014, 05:10:47 AM UUID: 4c625efe-77fd-465d-bd63-72ead0b5d3ba Name: PetitCompiler-Tests-JanVrany.13 Author: JanVrany Time: 05-11-2014, 09:31:07 AM UUID: 189ae287-6bc1-40ba-8458-b8392c4260a0

"{ 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 add: name.
!

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
! !

!PPCMethod class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !