45
45
import org .eclipse .lsp .cobol .core .CobolParser ;
46
46
import org .eclipse .lsp .cobol .core .engine .dialects .DialectService ;
47
47
import org .eclipse .lsp .cobol .core .engine .processor .AstProcessor ;
48
- import org .eclipse .lsp .cobol .core .engine .symbols .SymbolService ;
48
+ import org .eclipse .lsp .cobol .core .engine .symbols .SymbolAccumulatorService ;
49
+ import org .eclipse .lsp .cobol .core .engine .symbols .SymbolTable ;
50
+ import org .eclipse .lsp .cobol .core .engine .symbols .SymbolsRepository ;
49
51
import org .eclipse .lsp .cobol .core .model .*;
50
52
import org .eclipse .lsp .cobol .core .model .tree .*;
51
53
import org .eclipse .lsp .cobol .core .model .tree .logic .*;
68
70
import org .eclipse .lsp .cobol .service .delegates .validations .AnalysisResult ;
69
71
import org .eclipse .lsp4j .Location ;
70
72
71
- import java .util .ArrayList ;
72
- import java .util .List ;
73
- import java .util .Map ;
73
+ import java .util .*;
74
74
import java .util .function .Function ;
75
75
import java .util .function .Predicate ;
76
76
import java .util .stream .Stream ;
@@ -95,9 +95,10 @@ public class CobolLanguageEngine {
95
95
private final SubroutineService subroutineService ;
96
96
private final CachingConfigurationService cachingConfigurationService ;
97
97
private final DialectService dialectService ;
98
- private final SymbolService symbolService ;
98
+ private final SymbolAccumulatorService symbolAccumulatorService ;
99
99
private final AstProcessor astProcessor ;
100
100
private final InjectService injectService ;
101
+ private final SymbolsRepository symbolsRepository ;
101
102
102
103
@ Inject
103
104
public CobolLanguageEngine (
@@ -107,18 +108,20 @@ public CobolLanguageEngine(
107
108
SubroutineService subroutineService ,
108
109
CachingConfigurationService cachingConfigurationService ,
109
110
DialectService dialectService ,
110
- SymbolService symbolService ,
111
+ SymbolAccumulatorService symbolAccumulatorService ,
111
112
AstProcessor astProcessor ,
112
- InjectService injectService ) {
113
+ InjectService injectService ,
114
+ SymbolsRepository symbolsRepository ) {
113
115
this .preprocessor = preprocessor ;
114
116
this .messageService = messageService ;
115
117
this .treeListener = treeListener ;
116
118
this .subroutineService = subroutineService ;
117
119
this .cachingConfigurationService = cachingConfigurationService ;
118
120
this .dialectService = dialectService ;
119
- this .symbolService = symbolService ;
121
+ this .symbolAccumulatorService = symbolAccumulatorService ;
120
122
this .astProcessor = astProcessor ;
121
123
this .injectService = injectService ;
124
+ this .symbolsRepository = symbolsRepository ;
122
125
}
123
126
124
127
/**
@@ -139,7 +142,6 @@ public ResultWithErrors<AnalysisResult> run(
139
142
Timing .Builder timingBuilder = Timing .builder ();
140
143
141
144
timingBuilder .getDialectsTimer ().start ();
142
- symbolService .reset (documentUri );
143
145
List <SyntaxError > accumulatedErrors = new ArrayList <>();
144
146
TextTransformations cleanText =
145
147
preprocessor .cleanUpCode (documentUri , text ).unwrap (accumulatedErrors ::addAll );
@@ -252,7 +254,7 @@ public ResultWithErrors<AnalysisResult> run(
252
254
embeddedCodeParts ,
253
255
messageService ,
254
256
subroutineService ,
255
- symbolService ,
257
+ symbolsRepository ,
256
258
dialectOutcome .getDialectNodes (),
257
259
cachingConfigurationService );
258
260
List <Node > syntaxTree = visitor .visit (tree );
@@ -290,10 +292,14 @@ public ResultWithErrors<AnalysisResult> run(
290
292
timing .getLateErrorProcessingTime ());
291
293
}
292
294
295
+ Map <String , SymbolTable > symbolTableMap = Collections .synchronizedMap (new HashMap <>(symbolAccumulatorService .getProgramSymbols ()));
296
+ symbolsRepository .updateSymbols (symbolTableMap );
297
+ symbolAccumulatorService .reset (documentUri );
298
+
293
299
return new ResultWithErrors <>(
294
300
AnalysisResult .builder ()
295
301
.rootNode (rootNode )
296
- .symbolTableMap (symbolService . getProgramSymbols () )
302
+ .symbolTableMap (symbolTableMap )
297
303
.build (),
298
304
accumulatedErrors .stream ().map (this ::constructErrorMessage ).collect (toList ()));
299
305
}
@@ -307,63 +313,63 @@ private void registerProcessors(AnalysisConfig analysisConfig, ProcessingContext
307
313
new ProcessorDescription (
308
314
SectionNode .class ,
309
315
ProcessingPhase .TRANSFORMATION ,
310
- new ProcessNodeWithVariableDefinitions (symbolService )));
316
+ new ProcessNodeWithVariableDefinitions (symbolAccumulatorService )));
311
317
ctx .register (
312
318
new ProcessorDescription (
313
319
FileEntryNode .class , ProcessingPhase .TRANSFORMATION , new FileEntryProcess ()));
314
320
ctx .register (
315
321
new ProcessorDescription (
316
322
FileDescriptionNode .class ,
317
323
ProcessingPhase .TRANSFORMATION ,
318
- new FileDescriptionProcess (symbolService )));
324
+ new FileDescriptionProcess (symbolAccumulatorService )));
319
325
ctx .register (
320
326
new ProcessorDescription (
321
327
DeclarativeProcedureSectionNode .class ,
322
328
ProcessingPhase .TRANSFORMATION ,
323
- new DeclarativeProcedureSectionRegister (symbolService )));
329
+ new DeclarativeProcedureSectionRegister (symbolAccumulatorService , symbolsRepository )));
324
330
// Phase DEFINITION
325
331
ctx .register (
326
332
new ProcessorDescription (
327
- ParagraphsNode .class , ProcessingPhase .DEFINITION , new DefineCodeBlock (symbolService )));
333
+ ParagraphsNode .class , ProcessingPhase .DEFINITION , new DefineCodeBlock (symbolAccumulatorService )));
328
334
ctx .register (
329
335
new ProcessorDescription (
330
336
SectionNameNode .class ,
331
337
ProcessingPhase .DEFINITION ,
332
- new SectionNameRegister (symbolService )));
338
+ new SectionNameRegister (symbolAccumulatorService )));
333
339
ctx .register (
334
340
new ProcessorDescription (
335
341
ParagraphNameNode .class ,
336
342
ProcessingPhase .DEFINITION ,
337
- new ParagraphNameRegister (symbolService )));
343
+ new ParagraphNameRegister (symbolAccumulatorService )));
338
344
ctx .register (
339
345
new ProcessorDescription (
340
346
ProcedureDivisionBodyNode .class ,
341
347
ProcessingPhase .DEFINITION ,
342
- new DefineCodeBlock (symbolService )));
348
+ new DefineCodeBlock (symbolAccumulatorService )));
343
349
// Phase USAGE
344
350
ctx .register (
345
351
new ProcessorDescription (
346
- CodeBlockUsageNode .class , ProcessingPhase .USAGE , new CodeBlockUsage (symbolService )));
352
+ CodeBlockUsageNode .class , ProcessingPhase .USAGE , new CodeBlockUsage (symbolAccumulatorService )));
347
353
ctx .register (
348
354
new ProcessorDescription (
349
355
RootNode .class , ProcessingPhase .USAGE , new RootNodeUpdateCopyNodesByPositionInTree ()));
350
356
ctx .register (
351
357
new ProcessorDescription (
352
358
QualifiedReferenceNode .class ,
353
359
ProcessingPhase .USAGE ,
354
- new QualifiedReferenceUpdateVariableUsage (symbolService )));
360
+ new QualifiedReferenceUpdateVariableUsage (symbolAccumulatorService )));
355
361
356
362
// ENRICHMENT
357
363
ctx .register (
358
364
new ProcessorDescription (
359
365
SectionNameNode .class ,
360
366
ProcessingPhase .VALIDATION ,
361
- new SectionNameNodeEnricher (symbolService )));
367
+ new SectionNameNodeEnricher (symbolAccumulatorService )));
362
368
ctx .register (
363
369
new ProcessorDescription (
364
370
CodeBlockUsageNode .class ,
365
371
ProcessingPhase .VALIDATION ,
366
- new CodeBlockUsageNodeEnricher (symbolService )));
372
+ new CodeBlockUsageNodeEnricher (symbolAccumulatorService )));
367
373
368
374
// Phase VALIDATION
369
375
ctx .register (
0 commit comments