5
5
6
6
package com .adacore .lkql_jit ;
7
7
8
+ import com .adacore .langkit_support .LangkitSupport ;
8
9
import com .adacore .libadalang .Libadalang ;
9
10
import com .adacore .liblkqllang .Liblkqllang ;
10
11
import com .adacore .lkql_jit .checker .BaseChecker ;
18
19
import com .adacore .lkql_jit .runtime .GlobalScope ;
19
20
import com .adacore .lkql_jit .utils .Constants ;
20
21
import com .adacore .lkql_jit .utils .functions .StringUtils ;
21
- import com .adacore .lkql_jit .utils .source_location .LalLocationWrapper ;
22
+ import com .adacore .lkql_jit .utils .source_location .LangkitLocationWrapper ;
22
23
import com .oracle .truffle .api .CompilerDirectives ;
23
24
import com .oracle .truffle .api .TruffleLanguage ;
24
25
import com .oracle .truffle .api .TruffleLogger ;
@@ -58,10 +59,10 @@ public final class LKQLContext {
58
59
// ----- Ada project attributes -----
59
60
60
61
/** The analysis context for the ada files. */
61
- private Libadalang . AnalysisContext adaContext ;
62
+ private LangkitSupport . AnalysisContextInterface analysisContext ;
62
63
63
64
/** The rewriting context, opened from the Ada analysis context. */
64
- private Libadalang . RewritingContext rewritingContext ;
65
+ private LangkitSupport . RewritingContextInterface rewritingContext ;
65
66
66
67
/** The project manager for the ada project. */
67
68
private Libadalang .ProjectManager projectManager ;
@@ -73,7 +74,7 @@ public final class LKQLContext {
73
74
boolean isFatal = !this .keepGoingOnMissingFile ();
74
75
this .getDiagnosticEmitter ()
75
76
.emitFileNotFound (
76
- new LalLocationWrapper (from .getRoot (), this .linesCache ),
77
+ new LangkitLocationWrapper (from .getRoot (), this .linesCache ),
77
78
name ,
78
79
isFatal
79
80
);
@@ -104,13 +105,13 @@ public final class LKQLContext {
104
105
* The user-specified units to analyze. If not explicitly specified, those will be the units of
105
106
* the root project.
106
107
*/
107
- private Libadalang .AnalysisUnit [] specifiedUnits ;
108
+ private LangkitSupport .AnalysisUnit [] specifiedUnits ;
108
109
109
110
/** All the units of the project, including those of its non-externally-built dependencies. */
110
- private Libadalang .AnalysisUnit [] allUnits ;
111
+ private LangkitSupport .AnalysisUnit [] allUnits ;
111
112
112
113
/** The root nodes of all the analysis units of the project. */
113
- private Libadalang . AdaNode [] allUnitsRoots ;
114
+ private LangkitSupport . NodeInterface [] allUnitsRoots ;
114
115
115
116
// ----- Checker attributes -----
116
117
@@ -124,7 +125,7 @@ public final class LKQLContext {
124
125
private NodeChecker [] filteredGeneralNodeCheckers = null ;
125
126
126
127
/** Node checkers to run on non-SPARK nodes from the Ada sources. */
127
- private NodeChecker [] filteredAdaNodeCheckers = null ;
128
+ private NodeChecker [] filteredNodeCheckers = null ;
128
129
129
130
/** Node checkers to run only on SPARK nodes from the Ada sources. */
130
131
private NodeChecker [] filteredSparkNodeCheckers = null ;
@@ -175,7 +176,7 @@ public void finalizeContext() {
175
176
this .rewritingContext .close ();
176
177
}
177
178
this .eventHandler .close ();
178
- this .adaContext .close ();
179
+ this .analysisContext .close ();
179
180
if (this .projectManager != null ) this .projectManager .close ();
180
181
}
181
182
@@ -189,21 +190,21 @@ public GlobalScope getGlobal() {
189
190
return this .global ;
190
191
}
191
192
192
- public Libadalang .AnalysisUnit [] getSpecifiedUnits () {
193
+ public LangkitSupport .AnalysisUnit [] getSpecifiedUnits () {
193
194
if (!this .parsed ) {
194
195
this .parseSources ();
195
196
}
196
197
return this .specifiedUnits ;
197
198
}
198
199
199
- public Libadalang .AnalysisUnit [] getAllUnits () {
200
+ public LangkitSupport .AnalysisUnit [] getAllUnits () {
200
201
if (!this .parsed ) {
201
202
this .parseSources ();
202
203
}
203
204
return this .allUnits ;
204
205
}
205
206
206
- public Libadalang . AdaNode [] getAllUnitsRoots () {
207
+ public LangkitSupport . NodeInterface [] getAllUnitsRoots () {
207
208
if (!this .parsed ) {
208
209
this .parseSources ();
209
210
}
@@ -214,12 +215,12 @@ public boolean hasRewritingContext() {
214
215
return this .rewritingContext != null ;
215
216
}
216
217
217
- public Libadalang . RewritingContext getRewritingContext () {
218
+ public LangkitSupport . RewritingContextInterface getRewritingContext () {
218
219
if (this .rewritingContext == null ) {
219
220
if (!this .parsed ) {
220
221
this .parseSources ();
221
222
}
222
- this .rewritingContext = this .adaContext .startRewriting ();
223
+ this .rewritingContext = this .analysisContext .startRewriting ();
223
224
}
224
225
return this .rewritingContext ;
225
226
}
@@ -229,7 +230,7 @@ public Libadalang.RewritingContext getRewritingContext() {
229
230
* operation is a success then discard the current rewriting context. Otherwise, close it. This
230
231
* method assumes that the current rewriting context is not null.
231
232
*/
232
- public Libadalang .RewritingApplyResult applyOrCloseRewritingContext () {
233
+ public LangkitSupport .RewritingApplyResult applyOrCloseRewritingContext () {
233
234
final var res = this .rewritingContext .apply ();
234
235
if (!res .success ) {
235
236
this .rewritingContext .close ();
@@ -441,20 +442,20 @@ public void parseSources() {
441
442
442
443
// For each specified source file, store its corresponding analysis unit in the list of
443
444
// specified units
444
- this .specifiedUnits = new Libadalang .AnalysisUnit [usedSources .length ];
445
+ this .specifiedUnits = new LangkitSupport .AnalysisUnit [usedSources .length ];
445
446
for (int i = 0 ; i < usedSources .length ; i ++) {
446
- this .specifiedUnits [i ] = this .adaContext .getUnitFromFile (usedSources [i ]);
447
+ this .specifiedUnits [i ] = this .analysisContext .getUnitFromFile (usedSources [i ]);
447
448
}
448
449
449
450
// For each source file of the project, store its corresponding analysis unit in the list of
450
451
// all
451
452
// the units
452
453
// of the project, as well as their root nodes.
453
- this .allUnits = new Libadalang .AnalysisUnit [this .allSourceFiles .size ()];
454
- this .allUnitsRoots = new Libadalang . AdaNode [this .allSourceFiles .size ()];
454
+ this .allUnits = new LangkitSupport .AnalysisUnit [this .allSourceFiles .size ()];
455
+ this .allUnitsRoots = new LangkitSupport . NodeInterface [this .allSourceFiles .size ()];
455
456
456
457
for (int i = 0 ; i < this .allUnits .length ; i ++) {
457
- this .allUnits [i ] = this .adaContext .getUnitFromFile (this .allSourceFiles .get (i ));
458
+ this .allUnits [i ] = this .analysisContext .getUnitFromFile (this .allSourceFiles .get (i ));
458
459
this .allUnitsRoots [i ] = this .allUnits [i ].getRoot ();
459
460
}
460
461
@@ -531,7 +532,7 @@ public void initSources() {
531
532
).toList ()
532
533
);
533
534
534
- this .adaContext = this .projectManager .createContext (
535
+ this .analysisContext = this .projectManager .createContext (
535
536
this .getOptions ().subprojectFile ().orElse (null ),
536
537
this .eventHandler ,
537
538
true ,
@@ -566,7 +567,11 @@ public void initSources() {
566
567
final Libadalang .UnitProvider provider = this .projectManager .getProvider ();
567
568
568
569
// Create the ada context and store it in the LKQL context
569
- this .adaContext = Libadalang .AnalysisContext .create (
570
+ /*
571
+ * TODO: Genericize LKQL or Java issue #502. Requires to make create static but not possible
572
+ * via an interface nor an abstract class.
573
+ */
574
+ this .analysisContext = Libadalang .AnalysisContext .create (
570
575
charset ,
571
576
null ,
572
577
provider ,
@@ -577,7 +582,7 @@ public void initSources() {
577
582
578
583
// In the absence of a project file, we consider for now that there are no configuration
579
584
// pragmas.
580
- this .adaContext .setConfigPragmasMapping (null , null );
585
+ this .analysisContext .setConfigPragmasMapping (null , null );
581
586
}
582
587
}
583
588
@@ -657,11 +662,11 @@ public NodeChecker[] getAllNodeCheckers() {
657
662
*
658
663
* @return The node checkers array for Ada code only.
659
664
*/
660
- public NodeChecker [] getAdaNodeCheckers () {
661
- if (this .filteredAdaNodeCheckers == null ) {
665
+ public NodeChecker [] getNodeCheckers () {
666
+ if (this .filteredNodeCheckers == null ) {
662
667
this .initCheckerCaches ();
663
668
}
664
- return this .filteredAdaNodeCheckers ;
669
+ return this .filteredNodeCheckers ;
665
670
}
666
671
667
672
/**
@@ -694,18 +699,18 @@ public UnitChecker[] getUnitCheckersFiltered() {
694
699
private void initCheckerCaches () {
695
700
// Prepare the working variables
696
701
final List <NodeChecker > generalNodeCheckers = new ArrayList <>();
697
- final List <NodeChecker > adaNodeCheckers = new ArrayList <>();
702
+ final List <NodeChecker > nodeCheckers = new ArrayList <>();
698
703
final List <NodeChecker > sparkNodeCheckers = new ArrayList <>();
699
704
final List <UnitChecker > unitCheckers = new ArrayList <>();
700
705
final Map <String , BaseChecker > allCheckers = this .global .getCheckers ();
701
706
702
707
// Lambda to dispatch checkers in the correct lists
703
708
final BiConsumer <BaseChecker , List <NodeChecker >> dispatchChecker = (
704
709
checker ,
705
- nodeCheckers
710
+ nodeCheckerList
706
711
) -> {
707
712
if (checker instanceof NodeChecker nodeChecker ) {
708
- nodeCheckers .add (nodeChecker );
713
+ nodeCheckerList .add (nodeChecker );
709
714
if (nodeChecker .isFollowGenericInstantiations ()) {
710
715
needsToFollowInstantiations = true ;
711
716
}
@@ -753,15 +758,15 @@ private void initCheckerCaches() {
753
758
754
759
switch (instance .sourceMode ()) {
755
760
case GENERAL -> dispatchChecker .accept (checker , generalNodeCheckers );
756
- case ADA -> dispatchChecker .accept (checker , adaNodeCheckers );
761
+ case ADA -> dispatchChecker .accept (checker , nodeCheckers );
757
762
case SPARK -> dispatchChecker .accept (checker , sparkNodeCheckers );
758
763
}
759
764
}
760
765
}
761
766
762
767
// Set the checker caches
763
768
this .filteredGeneralNodeCheckers = generalNodeCheckers .toArray (new NodeChecker [0 ]);
764
- this .filteredAdaNodeCheckers = adaNodeCheckers .toArray (new NodeChecker [0 ]);
769
+ this .filteredNodeCheckers = nodeCheckers .toArray (new NodeChecker [0 ]);
765
770
this .filteredSparkNodeCheckers = sparkNodeCheckers .toArray (new NodeChecker [0 ]);
766
771
this .filteredUnitCheckers = unitCheckers .toArray (new UnitChecker [0 ]);
767
772
}
0 commit comments