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

Added new feature that allows to leave all variables undeclared if option selected in dialog #17482

Open
wants to merge 3 commits into
base: Pharo13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/AST-Core/ASTVariableNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Class {
'variable',
'start'
],
#classVars : [
'UndeclaredVariableFlag'
],
#category : 'AST-Core-Nodes',
#package : 'AST-Core',
#tag : 'Nodes'
Expand Down Expand Up @@ -69,6 +72,18 @@ ASTVariableNode class >> thisProcessNode [
^ self named: #thisProcess
]

{ #category : 'accessing' }
ASTVariableNode class >> undeclaredVariableFlag [

^ UndeclaredVariableFlag
]

{ #category : 'settings - accessing' }
ASTVariableNode class >> undeclaredVariableFlag: aBoolean [

UndeclaredVariableFlag := aBoolean
]

{ #category : 'comparing' }
ASTVariableNode >> = anObject [
self == anObject ifTrue: [^true].
Expand All @@ -82,6 +97,14 @@ ASTVariableNode >> acceptVisitor: aProgramNodeVisitor [
^ variable acceptVisitor: aProgramNodeVisitor node: self
]

{ #category : 'action' }
ASTVariableNode >> changeFlag [

self class undeclaredVariableFlag
ifFalse: [ self class undeclaredVariableFlag: true ]

]

{ #category : 'matching' }
ASTVariableNode >> copyInContext: aDictionary [
^ self class named: name
Expand Down Expand Up @@ -116,7 +139,8 @@ ASTVariableNode >> initialize [
super initialize.
variable := UnresolvedVariable instance.
name := ''.
start := 0
start := 0.
self class undeclaredVariableFlag: false
]

{ #category : 'testing' }
Expand Down
27 changes: 14 additions & 13 deletions src/OpalCompiler-Core/OpalCompiler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -303,29 +303,30 @@ OpalCompiler >> checkNotice: aNotice [
signal.
^ true ].

self requestor ifNotNil: [
"A requestor is available. We are in quirks mode and are expected to do UI things."
"Reparation menu in quirks mode:
self requestor ifNotNil: [ "A requestor is available. We are in quirks mode and are expected to do UI things.""Reparation menu in quirks mode:
* require a requestor (because quirks mode, and also some reparations expect a requestor)
* require interactive mode (because GUI)
* require method definition becase some reparation assume it's a method body"
self isInteractive ifTrue: [
aNotice reparator ifNotNil: [ :reparator |
| res |
res := reparator
requestor: requestor;
openMenu.
res ifNil: [ ^ true "reparation unneded, let AST as is" ].
res ifFalse: [ ^ false "operation cancelled, fail" ].
self parse: requestor text. "some reparation was done, reparse"
^ nil ] ].
aNotice node class undeclaredVariableFlag
ifTrue: [ ^ true ]
ifFalse: [
aNotice reparator ifNotNil: [ :reparator |
| res |
res := reparator
requestor: requestor;
openMenu.
res ifNil: [ ^ true "reparation unneded, let AST as is" ].
res ifFalse: [ ^ false "operation cancelled, fail" ].
self parse: requestor text. "some reparation was done, reparse"
^ nil ] ] ].

"Quirks mode: otherwise, push the error message to the requestor"
requestor
notify: aNotice messageText , ' ->'
at: aNotice position
in: aNotice node source.

"Quirks mode: Then leave"
^ false ].

Expand Down
6 changes: 6 additions & 0 deletions src/OpalCompiler-UI/OCCodeReparator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ OCCodeReparator >> openMenu [
labels add: 'Declare new instance variable'.
actions add: [ self declareInstVar: name ] ]
ifFalse: [
labels add: 'Leave all variables undeclared'.
actions add: [
node changeFlag.
^ nil ].
labels add: 'Leave variable undeclared'.
actions add: [ ^ nil ].
lines add: labels size.
Expand All @@ -170,11 +174,13 @@ OCCodeReparator >> openMenu [
labels add: 'Cancel'.
caption := 'Unknown variable: ' , name
, ' please correct, or cancel:'.

choice := MorphicUIManager new
chooseFrom: labels
lines: lines
title: caption.
(actions at: choice ifAbsent: [ ^ false ]) value.

^ true
]

Expand Down