Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit use of OCParseTreeSearcher in Compiler #17752

Open
Ducasse opened this issue Feb 2, 2025 · 0 comments
Open

Limit use of OCParseTreeSearcher in Compiler #17752

Ducasse opened this issue Feb 2, 2025 · 0 comments

Comments

@Ducasse
Copy link
Member

Ducasse commented Feb 2, 2025

In some cases the use of ParseTreeSearcher lead to more complex code that is more arcane.

For example

isInlineToDo

	| block step |
	self methodCompilationContextOrNil ifNotNil:[:c | c optionInlineToDo ifFalse: [ ^false ]].

	self receiver isBlock ifTrue: [^ false].
	self isCascaded ifTrue: [^ false].
	(#(to:do: to:by:do:) includes: self selector) ifFalse: [^ false].
	block := self arguments last.
	block isBlock ifFalse: [^ false].
	block arguments size = 1 ifFalse: [^ false].
	self arguments first isVariable ifTrue: [
		(OCParseTreeSearcher new
			matches: self arguments first name , ' := `@object' do: [:n :a | true];
			executeTree: block initialAnswer: false) ifTrue: [^ false].
	].
	self arguments size = 3 "to:by:do:" ifTrue: [
		step := self arguments second.
		(step isLiteralNode and: [step value isNumber])ifFalse: [^ false].
		step value = 0 ifTrue: [^ false].
	].
	^ true

In Armor compiler we have the following.

ARCompiler >> isInlineToDo: anARMessageNode [

	| block step |
	(anARMessageNode methodNode ifNotNil: [ :node |
		 node compilationContext ]) ifNotNil: [ :c |
		c optionInlineToDo ifFalse: [ ^ false ] ].

	anARMessageNode receiver isBlock ifTrue: [ ^ false ].
	anARMessageNode isCascaded ifTrue: [ ^ false ].
	(#( to:do: to:by:do: ) includes: anARMessageNode selector) ifFalse: [
		^ false ].
	block := anARMessageNode arguments last.
	block isBlock ifFalse: [ ^ false ].
	block arguments size = 1 ifFalse: [ ^ false ].
	anARMessageNode arguments first isVariable ifTrue: [
		(block allChildren anySatisfy: [ :child |
			 child isAssignment and: [
				 child variable = anARMessageNode arguments first ] ]) ifTrue: [
			^ false ] ].
	anARMessageNode arguments size = 3 ifTrue: [
		step := anARMessageNode arguments second.
		(step isLiteralNode and: [ step value isNumber ]) ifFalse: [
			^ false ].
		step value = 0 ifTrue: [ ^ false ] ]. "to:by:do:"
	^ true
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant