[Pharo-dev] declareTempAndPaste:

Alexandre Bergel alexandre.bergel at me.com
Mon Nov 11 09:22:30 EST 2013


Hi!

Many of us have discovered that in the last Pharo adding a temporary variable is added before the | .. | part of the section.

Pablo Estefo and I spend time on understanding where this comes from. But since this is deep into the compilation chain, it would be great if an expert (Marcus ? :-) could check what we have done.

OCUndeclaredVariableWarning>>declareTempAndPaste:  is the culprit method. We have changed:
	tempsMark :=  self methodNode body  leftBar ifNil: [ self methodNode body start ].
into 
	tempsMark :=  self methodNode body  rightBar ifNil: [ self methodNode body start ].


So, the new version of the method should be:
-=-=-=-=-=-=-=-=-=-=-=-=
OCUndeclaredVariableWarning>>declareTempAndPaste: name
	| insertion delta theTextString characterBeforeMark tempsMark |

	theTextString := self methodNode source.
	tempsMark :=  self methodNode body  rightBar ifNil: [ self methodNode body start ].
	characterBeforeMark := theTextString at: tempsMark-1 ifAbsent: [$ ].
	
	(theTextString at: tempsMark) = $| ifTrue:  [
  		"Paste it before the second vertical bar"
		insertion := name, ' '.
		
		characterBeforeMark isSeparator ifFalse: [insertion := ' ', insertion].
		delta := 0.
	] ifFalse: [
		"No bars - insert some with CR, tab"
		insertion := '| ' , name , ' |',String cr.
		delta := 2.	"the bar and CR"
		characterBeforeMark = Character tab ifTrue: [
			insertion := insertion , String tab.
			delta := delta + 1.	"the tab" ]
		].
	tempsMark := tempsMark +
		(self substituteWord: insertion
			wordInterval: (tempsMark to: tempsMark-1)
			offset: 0) - delta.
	self methodNode scope addTemp: name.
	^ (node owningScope lookupVar: node name)
		ifNil: [self error: 'should not happen']
-=-=-=-=-=-=-=-=-=-=-=-=

We have tried different cases and it seems to work.
Does this makes sense?

Cheers,
Alexandre
	
-- 
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.







More information about the Pharo-dev mailing list