compiler/PPCMethod.st
changeset 391 553a5456963b
child 392 9b297f0d949c
equal deleted inserted replaced
390:17ba167b8ee1 391:553a5456963b
       
     1 "{ Package: 'stx:goodies/petitparser/compiler' }"
       
     2 
       
     3 Object subclass:#PPCMethod
       
     4 	instanceVariableNames:'buffer variables indentation id profile canInline'
       
     5 	classVariableNames:''
       
     6 	poolDictionaries:''
       
     7 	category:'PetitCompiler-Core'
       
     8 !
       
     9 
       
    10 PPCMethod comment:''
       
    11 !
       
    12 
       
    13 !PPCMethod methodsFor:'as yet unclassified'!
       
    14 
       
    15 add: string
       
    16 	self nl.
       
    17 	indentation timesRepeat: [ buffer nextPutAll: '  ' ].
       
    18 	self addOnLine: string.
       
    19 !
       
    20 
       
    21 addOnLine: string
       
    22 	buffer nextPutAll: string.
       
    23 !
       
    24 
       
    25 addVariable: name
       
    26 	variables add: name.
       
    27 !
       
    28 
       
    29 allowInline
       
    30 	canInline := true
       
    31 !
       
    32 
       
    33 body
       
    34 	^ buffer contents
       
    35 !
       
    36 
       
    37 bridge
       
    38 	^ PPCBridge on: self methodName.
       
    39 !
       
    40 
       
    41 call
       
    42 	^ 'self ', self methodName, '.'.
       
    43 !
       
    44 
       
    45 code
       
    46 	^ self methodName, String cr,  
       
    47 		self variables, String cr,
       
    48 		self profilingBegin, String cr,
       
    49 		self body, String cr
       
    50 "		self profilingEnd"
       
    51 !
       
    52 
       
    53 dedent
       
    54 	indentation := indentation - 1
       
    55 !
       
    56 
       
    57 id: value
       
    58 	id := value
       
    59 !
       
    60 
       
    61 indent 
       
    62 	indentation := indentation + 1
       
    63 !
       
    64 
       
    65 isMethod
       
    66 	^ true
       
    67 !
       
    68 
       
    69 methodName
       
    70 	^ id
       
    71 !
       
    72 
       
    73 nl
       
    74 	^ buffer nextPut: Character cr
       
    75 !
       
    76 
       
    77 profile
       
    78 	^ profile
       
    79 !
       
    80 
       
    81 profile: aBoolean
       
    82 	profile := aBoolean 
       
    83 !
       
    84 
       
    85 profilingBegin
       
    86 	self profile ifTrue: [ 
       
    87  		^ '  context methodInvoked: #', id, '.'	
       
    88 	].
       
    89 	^ ''
       
    90 !
       
    91 
       
    92 profilingEnd
       
    93 	self profile ifTrue: [ 
       
    94  		^ '  context methodFinished: #', id, '.'	
       
    95 	].
       
    96 	^ ''
       
    97 !
       
    98 
       
    99 variables
       
   100 	^ '  | ', (variables inject: '' into: [ :s :e | s, ' ', e]), ' |'
       
   101 ! !
       
   102 
       
   103 !PPCMethod methodsFor:'initialization'!
       
   104 
       
   105 initialize
       
   106 	buffer := WriteStream on: ''.
       
   107 	indentation := 1.
       
   108 	variables := OrderedCollection new.
       
   109 	canInline := false
       
   110 ! !
       
   111