'From Cuis 2.6 of 10 August 2010 [latest update: #540] on 29 August 2010 at 6:22:06 pm'!

!Parser methodsFor: 'error correction' stamp: 'jmv 8/29/2010 18:21'!
declareUndeclaredTemps: methodNode
	"Declare any undeclared temps, declaring them at the smallest enclosing scope."
	| undeclared userSelection blocksToVars |
	(undeclared _ encoder undeclaredTemps) isEmpty ifTrue: [ ^ self ].
	userSelection _ requestor selectionInterval.
	blocksToVars _ IdentityDictionary new.
	undeclared do: [ :var |
		(blocksToVars
			at: (var tag == #method
				ifTrue: [ methodNode block ]
				ifFalse: [ methodNode accept: (VariableScopeFinder new ofVariable: var) ])
			ifAbsentPut: [ SortedCollection new ]) add: var name ].
	(blocksToVars removeKey: methodNode block ifAbsent: nil) ifNotNil: [ :rootVars |
		rootVars do: [ :varName |
			self pasteTempAtMethodLevel: varName ]].
	(blocksToVars keys sorted: [ :a :b |
		a tempsMark < b tempsMark ]) do: [ :block | | decl |
		decl _ String streamContents: [ :strm |
			(blocksToVars at: block) do: [ :v |
				strm nextPutAll: v; nextPut: $  ]].
		block temporaries isEmpty
			ifTrue: [
				self
					substituteWord: ' | ' , decl , '|'
					wordInterval: (block tempsMark + 1 to: block tempsMark)
					offset: requestorOffset ]
			ifFalse: [
				self
					substituteWord: decl
					wordInterval: (block tempsMark to: block tempsMark - 1)
					offset: requestorOffset ]].
	requestor
		selectInvisiblyFrom: userSelection first
		to: userSelection last + requestorOffset.
	ReparseAfterSourceEditing signal! !


!UndeclaredVariable methodsFor: 'as yet unclassified' stamp: 'jmv 8/29/2010 16:43'!
openMenuIn: aBlock
	| alternatives labels actions lines caption choice |
	alternatives _ parser possibleVariablesFor: name.
	labels _ OrderedCollection new.
	actions _ OrderedCollection new.
	lines _ OrderedCollection new.
	name first isLowercase
		ifTrue: [
			labels add: 'declare block-local temp'.
			actions add: [
				parser
					declareTemp: name
					at: #block ].
			labels add: 'declare method temp'.
			actions add: [
				parser
					declareTemp: name
					at: #method ].
			labels add: 'declare instance'.
			actions add: [ parser declareInstVar: name ]]
		ifFalse: [
			labels add: 'define new class'.
			actions add: [ parser defineClass: name ].
			labels add: 'declare global'.
			actions add: [ parser declareGlobal: name ].
			parser canDeclareClassVariable ifTrue: [
				labels add: 'declare class variable'.
				actions add: [ parser declareClassVar: name ]]].
	lines add: labels size.
	alternatives do: [ :each |
		labels add: each.
		actions add: [
			parser
				substituteVariable: each
				atInterval: interval ]].
	lines add: labels size.
	labels add: 'cancel'.
	caption _ 'Unknown variable: ' , name , ' please correct, or cancel:'.
	choice _ aBlock
		value: labels
		value: lines
		value: caption.
	self resume:
		(actions
			at: choice
			ifAbsent: [ ]).! !

