55
66package com .adacore .lkql_jit ;
77
8+ import com .adacore .langkit_support .LangkitSupport ;
89import com .adacore .libadalang .Libadalang ;
910import com .adacore .liblkqllang .Liblkqllang ;
1011import com .adacore .lkql_jit .checker .BaseChecker ;
1819import com .adacore .lkql_jit .runtime .GlobalScope ;
1920import com .adacore .lkql_jit .utils .Constants ;
2021import 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 ;
2223import com .oracle .truffle .api .CompilerDirectives ;
2324import com .oracle .truffle .api .TruffleLanguage ;
2425import com .oracle .truffle .api .TruffleLogger ;
@@ -58,10 +59,10 @@ public final class LKQLContext {
5859 // ----- Ada project attributes -----
5960
6061 /** The analysis context for the ada files. */
61- private Libadalang . AnalysisContext adaContext ;
62+ private LangkitSupport . AnalysisContextInterface analysisContext ;
6263
6364 /** The rewriting context, opened from the Ada analysis context. */
64- private Libadalang . RewritingContext rewritingContext ;
65+ private LangkitSupport . RewritingContextInterface rewritingContext ;
6566
6667 /** The project manager for the ada project. */
6768 private Libadalang .ProjectManager projectManager ;
@@ -73,7 +74,7 @@ public final class LKQLContext {
7374 boolean isFatal = !this .keepGoingOnMissingFile ();
7475 this .getDiagnosticEmitter ()
7576 .emitFileNotFound (
76- new LalLocationWrapper (from .getRoot (), this .linesCache ),
77+ new LangkitLocationWrapper (from .getRoot (), this .linesCache ),
7778 name ,
7879 isFatal
7980 );
@@ -104,13 +105,13 @@ public final class LKQLContext {
104105 * The user-specified units to analyze. If not explicitly specified, those will be the units of
105106 * the root project.
106107 */
107- private Libadalang .AnalysisUnit [] specifiedUnits ;
108+ private LangkitSupport .AnalysisUnit [] specifiedUnits ;
108109
109110 /** All the units of the project, including those of its non-externally-built dependencies. */
110- private Libadalang .AnalysisUnit [] allUnits ;
111+ private LangkitSupport .AnalysisUnit [] allUnits ;
111112
112113 /** The root nodes of all the analysis units of the project. */
113- private Libadalang . AdaNode [] allUnitsRoots ;
114+ private LangkitSupport . NodeInterface [] allUnitsRoots ;
114115
115116 // ----- Checker attributes -----
116117
@@ -124,7 +125,7 @@ public final class LKQLContext {
124125 private NodeChecker [] filteredGeneralNodeCheckers = null ;
125126
126127 /** Node checkers to run on non-SPARK nodes from the Ada sources. */
127- private NodeChecker [] filteredAdaNodeCheckers = null ;
128+ private NodeChecker [] filteredNodeCheckers = null ;
128129
129130 /** Node checkers to run only on SPARK nodes from the Ada sources. */
130131 private NodeChecker [] filteredSparkNodeCheckers = null ;
@@ -175,7 +176,7 @@ public void finalizeContext() {
175176 this .rewritingContext .close ();
176177 }
177178 this .eventHandler .close ();
178- this .adaContext .close ();
179+ this .analysisContext .close ();
179180 if (this .projectManager != null ) this .projectManager .close ();
180181 }
181182
@@ -189,21 +190,21 @@ public GlobalScope getGlobal() {
189190 return this .global ;
190191 }
191192
192- public Libadalang .AnalysisUnit [] getSpecifiedUnits () {
193+ public LangkitSupport .AnalysisUnit [] getSpecifiedUnits () {
193194 if (!this .parsed ) {
194195 this .parseSources ();
195196 }
196197 return this .specifiedUnits ;
197198 }
198199
199- public Libadalang .AnalysisUnit [] getAllUnits () {
200+ public LangkitSupport .AnalysisUnit [] getAllUnits () {
200201 if (!this .parsed ) {
201202 this .parseSources ();
202203 }
203204 return this .allUnits ;
204205 }
205206
206- public Libadalang . AdaNode [] getAllUnitsRoots () {
207+ public LangkitSupport . NodeInterface [] getAllUnitsRoots () {
207208 if (!this .parsed ) {
208209 this .parseSources ();
209210 }
@@ -214,12 +215,12 @@ public boolean hasRewritingContext() {
214215 return this .rewritingContext != null ;
215216 }
216217
217- public Libadalang . RewritingContext getRewritingContext () {
218+ public LangkitSupport . RewritingContextInterface getRewritingContext () {
218219 if (this .rewritingContext == null ) {
219220 if (!this .parsed ) {
220221 this .parseSources ();
221222 }
222- this .rewritingContext = this .adaContext .startRewriting ();
223+ this .rewritingContext = this .analysisContext .startRewriting ();
223224 }
224225 return this .rewritingContext ;
225226 }
@@ -229,7 +230,7 @@ public Libadalang.RewritingContext getRewritingContext() {
229230 * operation is a success then discard the current rewriting context. Otherwise, close it. This
230231 * method assumes that the current rewriting context is not null.
231232 */
232- public Libadalang .RewritingApplyResult applyOrCloseRewritingContext () {
233+ public LangkitSupport .RewritingApplyResult applyOrCloseRewritingContext () {
233234 final var res = this .rewritingContext .apply ();
234235 if (!res .success ) {
235236 this .rewritingContext .close ();
@@ -441,20 +442,20 @@ public void parseSources() {
441442
442443 // For each specified source file, store its corresponding analysis unit in the list of
443444 // specified units
444- this .specifiedUnits = new Libadalang .AnalysisUnit [usedSources .length ];
445+ this .specifiedUnits = new LangkitSupport .AnalysisUnit [usedSources .length ];
445446 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 ]);
447448 }
448449
449450 // For each source file of the project, store its corresponding analysis unit in the list of
450451 // all
451452 // the units
452453 // 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 ()];
455456
456457 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 ));
458459 this .allUnitsRoots [i ] = this .allUnits [i ].getRoot ();
459460 }
460461
@@ -531,7 +532,7 @@ public void initSources() {
531532 ).toList ()
532533 );
533534
534- this .adaContext = this .projectManager .createContext (
535+ this .analysisContext = this .projectManager .createContext (
535536 this .getOptions ().subprojectFile ().orElse (null ),
536537 this .eventHandler ,
537538 true ,
@@ -566,7 +567,11 @@ public void initSources() {
566567 final Libadalang .UnitProvider provider = this .projectManager .getProvider ();
567568
568569 // 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 (
570575 charset ,
571576 null ,
572577 provider ,
@@ -577,7 +582,7 @@ public void initSources() {
577582
578583 // In the absence of a project file, we consider for now that there are no configuration
579584 // pragmas.
580- this .adaContext .setConfigPragmasMapping (null , null );
585+ this .analysisContext .setConfigPragmasMapping (null , null );
581586 }
582587 }
583588
@@ -657,11 +662,11 @@ public NodeChecker[] getAllNodeCheckers() {
657662 *
658663 * @return The node checkers array for Ada code only.
659664 */
660- public NodeChecker [] getAdaNodeCheckers () {
661- if (this .filteredAdaNodeCheckers == null ) {
665+ public NodeChecker [] getNodeCheckers () {
666+ if (this .filteredNodeCheckers == null ) {
662667 this .initCheckerCaches ();
663668 }
664- return this .filteredAdaNodeCheckers ;
669+ return this .filteredNodeCheckers ;
665670 }
666671
667672 /**
@@ -694,18 +699,18 @@ public UnitChecker[] getUnitCheckersFiltered() {
694699 private void initCheckerCaches () {
695700 // Prepare the working variables
696701 final List <NodeChecker > generalNodeCheckers = new ArrayList <>();
697- final List <NodeChecker > adaNodeCheckers = new ArrayList <>();
702+ final List <NodeChecker > nodeCheckers = new ArrayList <>();
698703 final List <NodeChecker > sparkNodeCheckers = new ArrayList <>();
699704 final List <UnitChecker > unitCheckers = new ArrayList <>();
700705 final Map <String , BaseChecker > allCheckers = this .global .getCheckers ();
701706
702707 // Lambda to dispatch checkers in the correct lists
703708 final BiConsumer <BaseChecker , List <NodeChecker >> dispatchChecker = (
704709 checker ,
705- nodeCheckers
710+ nodeCheckerList
706711 ) -> {
707712 if (checker instanceof NodeChecker nodeChecker ) {
708- nodeCheckers .add (nodeChecker );
713+ nodeCheckerList .add (nodeChecker );
709714 if (nodeChecker .isFollowGenericInstantiations ()) {
710715 needsToFollowInstantiations = true ;
711716 }
@@ -753,15 +758,15 @@ private void initCheckerCaches() {
753758
754759 switch (instance .sourceMode ()) {
755760 case GENERAL -> dispatchChecker .accept (checker , generalNodeCheckers );
756- case ADA -> dispatchChecker .accept (checker , adaNodeCheckers );
761+ case ADA -> dispatchChecker .accept (checker , nodeCheckers );
757762 case SPARK -> dispatchChecker .accept (checker , sparkNodeCheckers );
758763 }
759764 }
760765 }
761766
762767 // Set the checker caches
763768 this .filteredGeneralNodeCheckers = generalNodeCheckers .toArray (new NodeChecker [0 ]);
764- this .filteredAdaNodeCheckers = adaNodeCheckers .toArray (new NodeChecker [0 ]);
769+ this .filteredNodeCheckers = nodeCheckers .toArray (new NodeChecker [0 ]);
765770 this .filteredSparkNodeCheckers = sparkNodeCheckers .toArray (new NodeChecker [0 ]);
766771 this .filteredUnitCheckers = unitCheckers .toArray (new UnitChecker [0 ]);
767772 }
0 commit comments