/
OpalCompiler.class.st
742 lines (631 loc) · 22.2 KB
/
OpalCompiler.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
"
I provide the API of the whole Compiler Package for the case that the input is sourcecode.
(if there is already and AST, call #generate (to compile) or #evaluate directly on the node)
a pre-configures compiler instance can be requested with:
- Smalltalk compiler
- a Class compiler
The compiler instance (actually: the compilation context) needs to be setup. See #class: #source: #noPattern: #requestor: for the most important accessors (more are in the accessing protocol).
See the class comment of CompilationContext for more information.
The final step is one of three actions:
-> parsing: parse source and return an AST.
-> compile: parse and compile, return a CompiledMethod
-> evaluate: parse, compile, evaluate and return result
Example:
Smalltalk compiler
source: 'test 1+2';
class: Object;
compile.
This returns a CompiledMethod.
"
Class {
#name : #OpalCompiler,
#superclass : #AbstractCompiler,
#instVars : [
'ast',
'source',
'context',
'receiver',
'compilationContext',
'compilationContextClass'
],
#classInstVars : [
'overlayEnvironment'
],
#category : #'OpalCompiler-Core-FrontEnd'
}
{ #category : #options }
OpalCompiler class >> compilerSpecificSettingsOn: aBuilder [
(aBuilder pickOne: #bytecodeBackend)
order: 0;
target: CompilationContext;
description: 'Sets the bytecode encoding of the compiled code generated by the Opal compiler';
label: 'Bytecode Backend';
domainValues:
{#V3PlusClosures -> EncoderForV3PlusClosures.
#SistaV1 -> EncoderForSistaV1 }.
CompilationContext compilerSpecificSettingsOn: aBuilder.
]
{ #category : #overlay }
OpalCompiler class >> createAndEnableOverlay [
^self overlayIsActive
]
{ #category : #overlay }
OpalCompiler class >> createAndEnableOverlay: aBoolean [
aBoolean = self overlayIsActive ifTrue: [ ^self ].
aBoolean
ifTrue: [ self startUsingOverlayForDevelopment ]
ifFalse: [ self stopUsingOverlayForDevelopment ]
]
{ #category : #public }
OpalCompiler class >> debuggerMethodMapForMethod: aMethod [
^ DebuggerMethodMapOpal forMethod: aMethod
]
{ #category : #'old - deprecated' }
OpalCompiler class >> evaluate: textOrString [
self
deprecated: 'Please use new compiler API instead'
transformWith: '`@receiver evaluate: `@statements1 ' -> '`@receiver new source: `@statements1; evaluate'.
^ self new
source: textOrString;
evaluate
]
{ #category : #'old - deprecated' }
OpalCompiler class >> evaluate: textOrString for: anObject logged: logFlag [
self
deprecated: 'Please use new compiler API instead'
transformWith:
'`@receiver evaluate: `@statements1 for: `@statements2 logged: `@statements3 '
-> '`@receiver new source: `@statements1; logged: `@statements3; receiver: `@statements2; evaluate.'.
^ self new
source: textOrString;
logged: logFlag;
receiver: anObject;
evaluate
]
{ #category : #'old - deprecated' }
OpalCompiler class >> evaluate: textOrString for: anObject notifying: aController logged: logFlag [
self
deprecated: 'Please use new compiler API instead'
transformWith:
'`@receiver evaluate: `@statements1 for: `@statements2 notifying: `@statements3 logged: `@statements4'
-> '`@receiver new source: `@statements1; logged: `@statements4; receiver: `@statements2; requestor: `@statements3; evaluate'.
^ self new
source: textOrString;
logged: logFlag;
receiver: anObject;
requestor: aController;
evaluate
]
{ #category : #'old - deprecated' }
OpalCompiler class >> evaluate: textOrString logged: logFlag [
self
deprecated: 'Please use new compiler API instead'
transformWith: '`@receiver evaluate: `@statements1 logged: `@statements2 ' -> '`@receiver new source: `@statements1; logged: `@statements2; evaluate.'.
^ self new
source: textOrString;
logged: logFlag;
evaluate
]
{ #category : #'old - deprecated' }
OpalCompiler class >> evaluate: textOrString notifying: aController logged: logFlag [
self
deprecated: 'Please use new compiler API instead'
transformWith:
'`@receiver evaluate: `@statements1 notifying: `@statements2 logged: `@statements3'
-> '`@receiver new source: `@statements1; logged: `@statements3; requestor: `@statements2; evaluate'.
^ self new
source: textOrString;
logged: logFlag;
requestor: aController;
evaluate
]
{ #category : #'old - deprecated' }
OpalCompiler class >> format: textOrStream in: aClass notifying: aRequestor [
self
deprecated: 'Please use new compiler API instead'
transformWith:
'`@receiver format: `@statements1 in: `@statements2 notifying: `@statements3'
-> '`@receiver new source: `@statements1; class: `@statements2; requestor: `@statements3; format'.
^ self new
source: textOrStream;
class: aClass;
requestor: aRequestor;
format
]
{ #category : #public }
OpalCompiler class >> isActive [
^Smalltalk compilerClass == self
]
{ #category : #overlay }
OpalCompiler class >> overlayClasses [
"here the classes for the overlay can changed. the default is just the compiler"
^self package definedClasses
"Compiler and AST:
self package definedClasses, RBProgramNode package definedClasses, {TRBProgramNodeVisitor}
"
]
{ #category : #overlay }
OpalCompiler class >> overlayEnvironment [
^overlayEnvironment
]
{ #category : #overlay }
OpalCompiler class >> overlayIsActive [
^overlayEnvironment notNil
]
{ #category : #public }
OpalCompiler class >> recompileAll [
"Recompile all classes and traits in the system."
Smalltalk image recompile
]
{ #category : #overlay }
OpalCompiler class >> startUsingOverlayForDevelopment [
"this method sets up an overlay so we can change the compiler package without breaking the compiler"
<script>
overlayEnvironment := Dictionary new.
"now we put a copy of all the classes into the environment"
self overlayClasses do: [ :class | overlayEnvironment at: class name put: class copy ].
"now we recompile the classes in the environment with itself as an overlay"
overlayEnvironment valuesDo: [ :class |
class methodsDo: [ :method |
| newMethod |
newMethod := class compiler
bindings: overlayEnvironment;
compile: method sourceCode.
class addSelectorSilently: method selector withMethod: newMethod ] ].
"make sure superclass pointers are correct"
overlayEnvironment valuesDo: [ :class |
(class isTrait not and: [overlayEnvironment includesKey: class superclass name]) ifTrue: [
class superclass: (overlayEnvironment at: class superclass name)]].
"make the copy the default compiler for the image"
SmalltalkImage compilerClass: (overlayEnvironment at: #OpalCompiler).
ASTCache reset.
]
{ #category : #overlay }
OpalCompiler class >> stopUsingOverlayForDevelopment [
"set compiler back to normal and throw away overlay environment"
<script>
SmalltalkImage compilerClass: nil.
overlayEnvironment := nil.
ASTCache reset
]
{ #category : #plugins }
OpalCompiler >> addPlugin: aClass [
compilationContext addASTTransformationPlugin: aClass
]
{ #category : #accessing }
OpalCompiler >> bindings: aDictionary [
"allows to define additional binding, note: Globals are not shadowed"
self compilationContext bindings: aDictionary
]
{ #category : #private }
OpalCompiler >> callPlugins [
| plugins |
plugins := compilationContext astTransformPlugins ifEmpty: [ ^self ].
plugins sort: [:a :b | a priority > b priority]. "priority 0 is sorted last"
plugins do: [ :each | ast := each transform: ast].
]
{ #category : #accessing }
OpalCompiler >> class: aClass [
self compilationContext class: aClass.
]
{ #category : #accessing }
OpalCompiler >> compilationContext [
^ compilationContext ifNil: [ compilationContext := self compilationContextClass default ]
]
{ #category : #accessing }
OpalCompiler >> compilationContext: anObject [
compilationContext := anObject
]
{ #category : #plugins }
OpalCompiler >> compilationContextClass [
^compilationContextClass ifNil: [ CompilationContext ]
]
{ #category : #plugins }
OpalCompiler >> compilationContextClass: aClass [
compilationContextClass := aClass.
]
{ #category : #'public access' }
OpalCompiler >> compile [
| cm |
[ [ self parse.
self doSemanticAnalysis.
self callPlugins.
] on: ReparseAfterSourceEditing
do:
[ :notification |
self source: notification newSource.
notification retry.
].
cm := compilationContext optionEmbeddSources
ifTrue: [ ast generateWithSource ]
ifFalse: [ast generate: self compilationContext compiledMethodTrailer ]
] on: SyntaxErrorNotification
do: [ :exception |
self compilationContext requestor
ifNotNil: [
self compilationContext requestor
notify: exception errorMessage , ' ->'
at: exception location
in: exception errorCode.
^ self compilationContext failBlock value ]
ifNil: [ exception pass ]].
^cm
]
{ #category : #'public access' }
OpalCompiler >> compile: textOrString [
^self
source: textOrString;
compile.
]
{ #category : #'old - deprecated' }
OpalCompiler >> compile: textOrStream in: aClass classified: aCategory notifying: aRequestor ifFail: aFailBlock [
self
deprecated: 'Please use new compiler API instead'
transformWith:
'`@receiver compile: `@statements1 in: `@statements2 classified: `@statements3 notifying: `@statements4 ifFail: `@statements5'
-> '`@receiver source: `@statements1; class: `@statements2; requestor: `@statements4; failBlock: `@statements5; parse'.
^ self
source: textOrStream;
class: aClass;
requestor: aRequestor;
failBlock: aFailBlock;
parse
]
{ #category : #'old - deprecated' }
OpalCompiler >> compile: textOrStream in: aClass notifying: aRequestor ifFail: aFailBlock [
self
deprecated: 'Please use new compiler API instead'
transformWith:
'`@receiver compile: `@statements1 in: `@statements2 notifying: `@statements3 ifFail: `@statements4'
-> '`@receiver source: `@statements1; class: `@statements2; requestor: `@statements3; failBlock: `@statements4; parse'.
^ self
source: textOrStream;
class: aClass;
requestor: aRequestor;
failBlock: aFailBlock;
parse
]
{ #category : #'old - deprecated' }
OpalCompiler >> compileNoPattern: textOrStream in: aClass context: aContext notifying: aRequestor ifFail: aFailBlock [
self
deprecated: 'Please use new compiler API instead'
transformWith:
'`@receiver compileNoPattern: `@statements1 in: `@statements2 context: `@statements3 notifying: `@statements4 ifFail: `@statements5'
-> '`@receiver source: `@statements1; class: `@statements2; context: `@statements3; requestor: `@statements4; noPattern: true; failBlock: `@statements5; parse'.
^self
source: textOrStream;
class: aClass;
context: aContext;
requestor: aRequestor;
noPattern: true;
failBlock: aFailBlock;
parse
]
{ #category : #accessing }
OpalCompiler >> compiledMethodTrailer: bytes [
self compilationContext compiledMethodTrailer: bytes
]
{ #category : #accessing }
OpalCompiler >> context: aContext [
context := aContext
]
{ #category : #'public access' }
OpalCompiler >> decompileMethod: aCompiledMethod [
^ Smalltalk globals
at: #FBDDecompiler
ifPresent: [ :decompilerClass | [ decompilerClass new decompile: aCompiledMethod ]
on: Error
do: [ RBMethodNode errorMethodNode: aCompiledMethod selector errorMessage: 'Decompilation failed'. ] ]
ifAbsent: [ RBMethodNode errorMethodNode: aCompiledMethod selector errorMessage: 'No decompiler available'. ]
]
{ #category : #private }
OpalCompiler >> doSemanticAnalysis [
^[ast doSemanticAnalysis]
on: OCSemanticError
do: [ :ex | ex defaultAction. ^ self compilationContext failBlock value ]
]
{ #category : #plugins }
OpalCompiler >> encoderClass: aClass [
self compilationContext encoderClass: aClass
]
{ #category : #accessing }
OpalCompiler >> environment: anEnvironment [
"Set the environment (dictionary of class, traits and globals) used during the compilation"
self compilationContext environment: anEnvironment
]
{ #category : #'public access' }
OpalCompiler >> evaluate [
"Compiles the sourceStream into a parse tree, then generates code into
a method. If aContext is not nil, the text can refer to temporaries in that
context (the Debugger uses this). If aRequestor is not nil, then it will receive
a notify:at: message before the attempt to evaluate is aborted. Finally, the
compiled method is invoked from here via withArgs:executeMethod:, hence
the system no longer creates Doit method litter on errors."
| value |
self noPattern: true.
self getSourceFromRequestorSelection.
self class: (context ifNil: [ receiver class ] ifNotNil: [ context method methodClass ]).
value := receiver withArgs: (context ifNil: [ #() ] ifNotNil: [ {context} ]) executeMethod: self compile.
self logDoIt.
^ value
]
{ #category : #'public access' }
OpalCompiler >> evaluate: textOrString [
^self
source: textOrString;
evaluate
]
{ #category : #'old - deprecated' }
OpalCompiler >> evaluate: textOrString for: anObject logged: logFlag [
self
deprecated: 'Please use new compiler API instead'
transformWith:
'`@receiver evaluate: `@statements1 for: `@statements2 logged: `@statements3'
->
'`@receiver source: `@statements1; logged: `@statements3; receiver: `@statements2; evaluate'.
^ self
source: textOrString;
logged: logFlag;
receiver: anObject;
evaluate
]
{ #category : #'old - deprecated' }
OpalCompiler >> evaluate: textOrString for: anObject notifying: aController logged: logFlag [
self
deprecated: 'Please use new compiler API instead'
transformWith:
'`@receiver evaluate: `@statements1 for: `@statements2 notifying: `@statements3 logged: `@statements4'
-> '`@receiver source: `@statements1; logged: `@statements2; receiver: `@statements3; requestor: `@statements4; evaluate'.
^ self
source: textOrString;
logged: logFlag;
receiver: anObject;
requestor: aController;
evaluate
]
{ #category : #'old - deprecated' }
OpalCompiler >> evaluate: aString in: aContext to: aReceiver [
self
deprecated: 'Please use new compiler API instead'
transformWith: '`@receiver evaluate: `@statements1 in: `@statements2 to: `@statements3'
-> '`@receiver source: `@statements1; context: `@statements2; receiver: `@statements3; parse.'.
^self
source: aString;
context: aContext;
receiver: aReceiver;
failBlock: [^ #failedDoit];
evaluate
]
{ #category : #'old - deprecated' }
OpalCompiler >> evaluate: textOrStream in: aContext to: aReceiver notifying: aRequestor ifFail: aFailBlock [
self
deprecated: 'Please use new compiler API instead'
transformWith:
'`@receiver evaluate: `@statements1 in: `@statements2 to: `@statements3 notifying: `@statements4 ifFail: `@statements5'
->
'`@receiver source: `@statements1; context: `@statements2; receiver: `@statements3; requestor: `@statements4; failBlock: `@statements5; evaluate'.
^ self
source: textOrStream;
context: aContext;
receiver: aReceiver;
requestor: aRequestor;
failBlock: aFailBlock;
evaluate
]
{ #category : #'old - deprecated' }
OpalCompiler >> evaluate: textOrStream in: aContext to: aReceiver notifying: aRequestor ifFail: aFailBlock logged: logFlag [
self
deprecated: 'Please use new compiler API instead'
transformWith:
'`@receiver evaluate: `@statements1 in: `@statements2 to: `@statements3 notifying: `@statements4 ifFail: `@statements5 logged: `@statements6'
-> '`@receiver source: `@statements1; context: `@statements2; receiver: `@statements3; requestor: `@statements4; failBlock: `@statements5; logged: `@statements6; evaluate'.
^ self
source: textOrStream;
context: aContext;
receiver: aReceiver;
requestor: aRequestor;
failBlock: aFailBlock;
logged: logFlag;
evaluate
]
{ #category : #'old - deprecated' }
OpalCompiler >> evaluate: textOrString logged: logFlag [
self
deprecated: 'Please use new compiler API instead'
transformWith: '`@receiver evaluate: `@statements1 logged: `@statements2'
-> '`@receiver source: `@statements1; logged: `@statements2; evaluate'.
^ self
source: textOrString;
logged: logFlag;
evaluate
]
{ #category : #'old - deprecated' }
OpalCompiler >> evaluate: textOrString notifying: aController logged: logFlag [
self
deprecated: 'Please use new compiler API instead'
transformWith: '`@receiver evaluate: `@statements1 notifying: `@statements2 logged: `@statements3'
-> '`@receiver source: `@statements1; logged: `@statements2; requestor: `@statements3; evaluate'.
^ self
source: textOrString;
logged: logFlag;
requestor: aController;
evaluate
]
{ #category : #accessing }
OpalCompiler >> failBlock: aBlock [
self compilationContext failBlock: aBlock.
]
{ #category : #'public access' }
OpalCompiler >> format [
^self parse formattedCode.
]
{ #category : #'public access' }
OpalCompiler >> format: textOrString [
^self
source: textOrString;
format
]
{ #category : #'old - deprecated' }
OpalCompiler >> format: textOrStream in: aClass notifying: aRequestor [
self
deprecated: 'Please use new compiler API instead'
transformWith: '`@receiver format: `@statements1 in: `@statements2 notifying: `@statements3'
-> '`@receiver source: `@statements1; class: `@statements2; requestor: `@statements3; format'.
^ self
source: textOrStream;
class: aClass;
requestor: aRequestor;
format
]
{ #category : #private }
OpalCompiler >> getSourceFromRequestorSelection [
| selectionString |
"if the requestor can provide a selection, we use that as the source"
(self compilationContext requestor respondsTo: #selection) ifFalse: [ ^self ].
selectionString := self compilationContext requestor selection asString.
selectionString isEmptyOrNil ifTrue: [ ^self ].
self source: selectionString.
]
{ #category : #private }
OpalCompiler >> isInteractiveFor: aRequestor [
"the requester can override if the compiler is interactive or not"
aRequestor ifNil: [^ false ].
^(aRequestor respondsTo: #interactive)
ifTrue: [ aRequestor interactive ]
ifFalse: [ true ]
]
{ #category : #private }
OpalCompiler >> logDoIt [
self compilationContext logged ifFalse: [ ^self ].
Smalltalk globals
at: #SystemAnnouncer
ifPresent: [ :sysAnn |
sysAnn uniqueInstance evaluated: source contents context: context ]
]
{ #category : #accessing }
OpalCompiler >> logged: aBoolean [
self compilationContext logged: aBoolean.
]
{ #category : #accessing }
OpalCompiler >> noPattern: aBoolean [
self compilationContext noPattern: aBoolean.
"when we compile an expression, embedd sources, as the resulting method will never be installed"
compilationContext parseOptions: #(+ #optionEmbeddSources).
]
{ #category : #'public access' }
OpalCompiler >> options: anOptionsArray [
self compilationContext parseOptions: anOptionsArray
]
{ #category : #'public access' }
OpalCompiler >> parse [
^self compilationContext noPattern
ifTrue: [ self parseExpression ]
ifFalse: [ self parseMethod ].
]
{ #category : #'public access' }
OpalCompiler >> parse: textOrString [
^self
source: textOrString;
parse
]
{ #category : #'old - deprecated' }
OpalCompiler >> parse: aString class: aClass [
self
deprecated: 'Please use new compiler API instead'
transformWith: '`@receiver parse: `@statements1 class: `@statements2'
-> '`@receiver source: `@statements1; class: `@statements2; parse.'.
^self
source: aString;
class: aClass;
parse
]
{ #category : #'old - deprecated' }
OpalCompiler >> parse: aString class: aClass noPattern: aBoolean context: aContext notifying: req ifFail: aBlock [
self
deprecated: 'Please use new compiler API instead'
transformWith:
'`@receiver parse: `@statements1 class: `@statements2 noPattern: `@statements3 context: `@statements4 notifying: `@statements5 ifFail: `@statements6'
->'`@receiver source: `@statements1; class: `@statements2; noPattern: `@statements3; context: `@statements4; requestor: `@statements5; failBlock: `@statements6; parse.'.
^ self
source: aString;
class: aClass;
noPattern: aBoolean;
context: aContext;
requestor: req;
failBlock: aBlock;
parse
]
{ #category : #'old - deprecated' }
OpalCompiler >> parse: textOrStream in: aClass notifying: req [
self
deprecated: 'Please use new compiler API instead'
transformWith:
'`@receiver parse: `@statements1 in: `@statements2 notifying: `@statements3' -> '`@receiver source: `@statements1; class: `@statements2; requestor: `@statements3; parse.'.
^ self
source: textOrStream;
class: aClass;
requestor: req;
parse
]
{ #category : #private }
OpalCompiler >> parseExpression [
| expression |
expression := self compilationContext optionParseErrors
ifTrue: [self parserClass parseFaultyExpression: source contents]
ifFalse: [self parserClass parseExpression: source contents].
ast := context
ifNil: [expression asDoit]
ifNotNil: [expression asDoitForContext: context].
ast compilationContext: self compilationContext.
^ast.
]
{ #category : #'public access' }
OpalCompiler >> parseLiterals: aString [
^self parserClass parseLiterals: aString
]
{ #category : #private }
OpalCompiler >> parseMethod [
ast := self compilationContext optionParseErrors
ifTrue: [self parserClass parseFaultyMethod: source contents]
ifFalse: [self parserClass parseMethod: source contents].
ast compilationContext: self compilationContext.
^ast.
]
{ #category : #'public access' }
OpalCompiler >> parseSelector: aString [
"Answer the message selector for the argument, aString, which should parse successfully up to the temporary declaration or the end of the method header."
^[self parserClass parseMethodPattern: aString] on: Error do: [nil].
]
{ #category : #plugins }
OpalCompiler >> parserClass [
^self compilationContext parserClass
]
{ #category : #accessing }
OpalCompiler >> productionEnvironment: anObject [
compilationContext productionEnvironment: anObject
]
{ #category : #accessing }
OpalCompiler >> receiver: anObject [
receiver := anObject.
]
{ #category : #accessing }
OpalCompiler >> requestor: aRequestor [
self compilationContext requestor: aRequestor.
self compilationContext interactive: (self isInteractiveFor: aRequestor).
]
{ #category : #plugins }
OpalCompiler >> requestorScopeClass: aClass [
"clients can set their own subclass of OCRequestorScope if needed"
self compilationContext requestorScopeClass: aClass
]
{ #category : #accessing }
OpalCompiler >> source: aString [
source := aString readStream.
]
{ #category : #'old - deprecated' }
OpalCompiler >> translate [
self
deprecated: 'Please use #parse instead'
transformWith: '`@receiver translate' -> '`@receiver parse'.
^self parse.
]