'From Squeak5.3beta of 18 January 2020 [latest update: #19328] on 20 January 2020 at 12:38:44 pm'!

!ECContext methodsFor: 'accessing' stamp: 'ct 1/20/2020 12:38'!
temporariesFromContext
	^ executionContext
		ifNotNil: [:context | (context tempNames
				withIndexCollect: [:each :index | ECLocalEntry
						contents: each
						type: (index <= executionContext numArgs
								ifTrue: [#patternArg]
								ifFalse: [#patternTempVar])])
				copyWith: (ECLocalEntry
						contents: Encoder doItInContextName
						type: #patternArg)]
		ifNil: #()! !

!ECContext methodsFor: 'private-type-guessing' stamp: 'ct 1/20/2020 12:24'!
guessTypeFromContext: aString

	| index |
	executionContext ifNil: [^ nil].
	aString = Encoder doItInContextName
		ifTrue: [^ executionContext class].
	index := (executionContext debuggerMap tempNamesForContext: executionContext)
			indexOf: aString
			ifAbsent: [^ nil].
	^ (executionContext tempAt: index) class! !


!Encoder methodsFor: 'encoding' stamp: 'ct 1/20/2020 12:24'!
doItInContextName
	^ self class doItInContextName! !


!Encoder class methodsFor: 'accessing' stamp: 'ct 1/20/2020 12:23'!
doItInContextName
	^ 'ThisContext'! !


!SHParserST80 methodsFor: 'parse support' stamp: 'ct 1/20/2020 12:26'!
initializeVariablesFromContext

	| contextSourcePcIndex contextSourceParser |
	contextSourcePcIndex := (context debuggerMap
		rangeForPC: (context isDead ifTrue: [context endPC] ifFalse: [context pc])
		in: context method
		contextIsActiveContext: true "... to really use the context's pc.")
			start.
	contextSourceParser := self class new
		classOrMetaClass: context method methodClass;
		environment: self environment;
		source: (context method getSource first: contextSourcePcIndex);
		yourself.
	contextSourceParser parse.
	arguments := contextSourceParser activeArguments.
	temporaries  := contextSourceParser activeTemporaries.
	self pushArgument: Encoder doItInContextName.! !

!SHParserST80 methodsFor: 'parse' stamp: 'ct 1/20/2020 12:16'!
parseArgument: expectedArgumentType
	"Add currentToken to the current scope as argument. Scan past expectedArgumentType if the argument is valid."

	self currentTokenType == #name ifFalse: [ self fail ": name expected" ].
	(self reservedKeywordNames includes: currentToken) ifTrue: [
		"Reserved keyword"
		^self scanPast: #invalid ].
	
	1 to: arguments size do: [ :index |
		(arguments at: index) ifNotNil: [ :scopeArguments |
			(scopeArguments includes: currentToken) ifTrue: [
				"Name is already used."
				^self scanPast: #invalid ] ].
		(temporaries at: index) ifNotNil: [ :scopeTemporaries |
			(scopeTemporaries includes: currentToken) ifTrue: [
				"Name is already used."
				^self scanPast: #invalid ] ] ].
	
	self pushArgument: currentToken.
	^self scanPast: expectedArgumentType! !

!SHParserST80 methodsFor: 'parse' stamp: 'ct 1/20/2020 12:16'!
parseTemporary: expectedTemporaryType
	"Add currentToken to the current scope as temporary. Scan past expectedTemporaryType if the argument is valid. Assume that currentTokenType is #name."

	(self reservedKeywordNames includes: currentToken) ifTrue: [
		"Reserved keyword"
		^self scanPast: #invalid ].
	
	1 to: arguments size do: [ :index |
		(arguments at: index) ifNotNil: [ :scopeArguments |
			(scopeArguments includes: currentToken) ifTrue: [
				"Name is already used."
				^self scanPast: #invalid ] ].
		(temporaries at: index) ifNotNil: [ :scopeTemporaries |
			(scopeTemporaries includes: currentToken) ifTrue: [
				"Name is already used."
				^self scanPast: #invalid ] ] ].
		
	self pushTemporary: currentToken.
	^self scanPast: expectedTemporaryType! !

!SHParserST80 methodsFor: 'parse' stamp: 'ct 1/20/2020 12:17'!
pushArgument: aToken

	arguments last 
		ifNil: [ arguments atLast: 1 put: (OrderedCollection with: aToken) ]
		ifNotNil: [ :scopeArguments | scopeArguments addLast: aToken ].! !

!SHParserST80 methodsFor: 'parse' stamp: 'ct 1/20/2020 12:16'!
pushTemporary: aToken

	temporaries last 
		ifNil: [ temporaries atLast: 1 put: (OrderedCollection with: aToken) ]
		ifNotNil: [ :scopeTemporaries | scopeTemporaries addLast: aToken ].! !

