Skip to content

Commit

Permalink
Move all options related classes to a 'options' package
Browse files Browse the repository at this point in the history
Do this for same reasons as for the 'cli' package.
Also inline EngineMode and AutoFixMode enum in the 'LKQLOptions' class.
  • Loading branch information
HugoGGuerrier committed Dec 10, 2024
1 parent 339acf2 commit a1335ca
Show file tree
Hide file tree
Showing 28 changed files with 80 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

package com.adacore.lkql_jit.cli;

import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.RuleInstance;
import com.adacore.lkql_jit.options.LKQLOptions;
import com.adacore.lkql_jit.options.RuleInstance;
import java.util.*;
import java.util.concurrent.Callable;
import org.graalvm.launcher.AbstractLanguageLauncher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

package com.adacore.lkql_jit.cli;

import com.adacore.lkql_jit.EngineMode;
import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.RuleInstance;
import com.adacore.lkql_jit.options.LKQLOptions;
import com.adacore.lkql_jit.options.RuleInstance;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -206,7 +205,7 @@ protected int executeScript(Context.Builder contextBuilder) {

// Forward the command line options to the options object builder
optionsBuilder
.engineMode(EngineMode.CHECKER)
.engineMode(LKQLOptions.EngineMode.CHECKER)
.verbose(this.args.verbose)
.projectFile(this.args.project)
.subprojectFile(this.args.subProject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

package com.adacore.lkql_jit.cli;

import com.adacore.lkql_jit.EngineMode;
import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.options.LKQLOptions;
import picocli.CommandLine;

/**
Expand Down Expand Up @@ -44,6 +43,9 @@ public LKQLChecker(LKQLChecker.Args args) {

@Override
protected LKQLOptions getOptions() {
return getBaseOptionsBuilder().engineMode(EngineMode.CHECKER).checkerDebug(true).build();
return getBaseOptionsBuilder()
.engineMode(LKQLOptions.EngineMode.CHECKER)
.checkerDebug(true)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package com.adacore.lkql_jit.cli;

import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.options.LKQLOptions;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.FileSystems;
Expand Down
10 changes: 4 additions & 6 deletions lkql_jit/cli/src/main/java/com/adacore/lkql_jit/cli/LKQLFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

package com.adacore.lkql_jit.cli;

import com.adacore.lkql_jit.AutoFixMode;
import com.adacore.lkql_jit.EngineMode;
import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.options.LKQLOptions;
import java.util.Arrays;
import java.util.Iterator;
import picocli.CommandLine;
Expand All @@ -33,7 +31,7 @@ public static class Args extends BaseLKQLChecker.Args {
"Mode to apply auto fixes (default is DISPLAY)"
+ "%nPossible values: ${COMPLETION-CANDIDATES}",
completionCandidates = AutoFixModeCompletion.class)
public AutoFixMode autoFixMode = AutoFixMode.DISPLAY;
public LKQLOptions.AutoFixMode autoFixMode = LKQLOptions.AutoFixMode.DISPLAY;

@Override
public Integer call() {
Expand All @@ -46,7 +44,7 @@ public Integer call() {
public static class AutoFixModeCompletion implements Iterable<String> {
@Override
public Iterator<String> iterator() {
return Arrays.stream(AutoFixMode.values()).map(Object::toString).iterator();
return Arrays.stream(LKQLOptions.AutoFixMode.values()).map(Object::toString).iterator();
}
}

Expand All @@ -61,7 +59,7 @@ public LKQLFix(LKQLFix.Args args) {
@Override
protected LKQLOptions getOptions() {
return getBaseOptionsBuilder()
.engineMode(EngineMode.FIXER)
.engineMode(LKQLOptions.EngineMode.FIXER)
.checkerDebug(true)
.autoFixMode(((Args) args).autoFixMode)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

package com.adacore.lkql_jit.cli;

import com.adacore.lkql_jit.EngineMode;
import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.options.LKQLOptions;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -164,7 +163,7 @@ protected int executeScript(Context.Builder contextBuilder) {

// Forward the command line options to the options object builder
optionsBuilder
.engineMode(EngineMode.INTERPRETER)
.engineMode(LKQLOptions.EngineMode.INTERPRETER)
.verbose(this.args.verbose)
.projectFile(this.args.project)
.target(this.args.target)
Expand Down
6 changes: 6 additions & 0 deletions lkql_jit/language/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
<artifactId>libadalang</artifactId>
<version>${config.libadalangVersion}</version>
</dependency>
<dependency>
<groupId>com.adacore</groupId>
<artifactId>options</artifactId>
<version>0.1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.adacore.lkql_jit.checker.UnitChecker;
import com.adacore.lkql_jit.checker.utils.CheckerUtils;
import com.adacore.lkql_jit.exception.LKQLRuntimeException;
import com.adacore.lkql_jit.options.LKQLOptions;
import com.adacore.lkql_jit.options.RuleInstance;
import com.adacore.lkql_jit.runtime.CallStack;
import com.adacore.lkql_jit.runtime.GlobalScope;
import com.adacore.lkql_jit.utils.Constants;
Expand Down Expand Up @@ -250,7 +252,7 @@ public LKQLOptions getOptions() {
return this.options;
}

public EngineMode getEngineMode() {
public LKQLOptions.EngineMode getEngineMode() {
return this.getOptions().engineMode();
}

Expand Down Expand Up @@ -327,7 +329,7 @@ public boolean isCheckerDebug() {
}

@CompilerDirectives.TruffleBoundary
public AutoFixMode getAutoFixMode() {
public LKQLOptions.AutoFixMode getAutoFixMode() {
return this.getOptions().autoFixMode();
}

Expand Down Expand Up @@ -709,7 +711,7 @@ private void initCheckerCaches() {
}

// If the engine is in "fixer" mode, check that the rule has an auto-fixing function
if (getEngineMode() == EngineMode.FIXER && checker.autoFix == null) {
if (getEngineMode() == LKQLOptions.EngineMode.FIXER && checker.autoFix == null) {
throw LKQLRuntimeException.fromMessage(
"Rule \""
+ instance.ruleName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package com.adacore.lkql_jit.checker.built_ins;

import com.adacore.libadalang.Libadalang;
import com.adacore.lkql_jit.EngineMode;
import com.adacore.lkql_jit.LKQLContext;
import com.adacore.lkql_jit.LKQLLanguage;
import com.adacore.lkql_jit.LKQLTypeSystemGen;
Expand All @@ -17,6 +16,7 @@
import com.adacore.lkql_jit.exception.LKQLRuntimeException;
import com.adacore.lkql_jit.exception.LangkitException;
import com.adacore.lkql_jit.nodes.expressions.Expr;
import com.adacore.lkql_jit.options.LKQLOptions;
import com.adacore.lkql_jit.runtime.values.LKQLFunction;
import com.adacore.lkql_jit.runtime.values.LKQLUnit;
import com.adacore.lkql_jit.utils.LKQLTypesHelper;
Expand Down Expand Up @@ -171,7 +171,8 @@ public Object executeGeneric(VirtualFrame frame) {
}

// If the engine is in fixing mode and the current unit has some modification
if (context.getEngineMode() == EngineMode.FIXER && context.hasRewritingContext()) {
if (context.getEngineMode() == LKQLOptions.EngineMode.FIXER
&& context.hasRewritingContext()) {
// Apply the current rewriting context
final var applyRes = context.applyOrCloseRewritingContext();
if (!applyRes.success) {
Expand Down Expand Up @@ -331,9 +332,10 @@ private void applyNodeRule(
}

if (ruleResult) {
if (context.getEngineMode() == EngineMode.CHECKER) {
if (context.getEngineMode() == LKQLOptions.EngineMode.CHECKER) {
reportViolation(context, checker, node);
} else if (context.getEngineMode() == EngineMode.FIXER && checker.autoFix != null) {
} else if (context.getEngineMode() == LKQLOptions.EngineMode.FIXER
&& checker.autoFix != null) {
callAutoFix(
context, context.getRewritingContext(), interopLibrary, checker, node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

package com.adacore.lkql_jit.nodes.root_nodes;

import com.adacore.lkql_jit.EngineMode;
import com.adacore.lkql_jit.LKQLLanguage;
import com.adacore.lkql_jit.nodes.TopLevelList;
import com.adacore.lkql_jit.options.LKQLOptions;
import com.oracle.truffle.api.frame.VirtualFrame;

/**
Expand Down Expand Up @@ -56,7 +56,9 @@ public TopLevelRootNode(
public Object execute(VirtualFrame frame) {
// If the checker mode is activated add all rule imports
final var engineMode = LKQLLanguage.getContext(this.program).getEngineMode();
if (!fromImport && (engineMode == EngineMode.CHECKER || engineMode == EngineMode.FIXER)) {
if (!fromImport
&& (engineMode == LKQLOptions.EngineMode.CHECKER
|| engineMode == LKQLOptions.EngineMode.FIXER)) {
this.program.addRuleImports();
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//

package com.adacore.lkql_jit; //
package com.adacore.lkql_jit.options; //

import java.util.Map;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//

package com.adacore.lkql_jit;
package com.adacore.lkql_jit.options;

import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -167,6 +167,32 @@ public enum DiagnosticOutputMode {
GNATCHECK
}

/** This enum represents the mode for the auto fixes application. */
public enum AutoFixMode {
/** Display the patched analysis unit to stdout. */
DISPLAY,

/** Create a new file alongside the original one, containing the patched analysis unit. */
NEW_FILE,

/** Replace the content of the original file with the patched analysis unit. */
PATCH_FILE
}

/** Represents the mode the LKQL engine runs on. */
public enum EngineMode {
/** LKQL engine is just going to run the provided LKQL script, without doing more. */
INTERPRETER,

/** LKQL engine will seek for defined rules and make them accessible. */
CHECKER,

/**
* LKQL engine will seek for rules and check that they all define an auto-fixing function.
*/
FIXER
}

/** Util class to build a new LKQL options object. */
public static final class Builder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//

package com.adacore.lkql_jit;
package com.adacore.lkql_jit.options;

import java.util.Map;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/** This package contains all classes and tools to forward options to the LKQL engine. */
package com.adacore.lkql_jit;
package com.adacore.lkql_jit.options;
2 changes: 1 addition & 1 deletion testsuite/tests/interop/function/Main.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.options.LKQLOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;

Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/interop/iterator/Main.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.options.LKQLOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;

Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/interop/list/Main.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.options.LKQLOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;

Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/interop/list_comp/Main.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.options.LKQLOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;

Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/interop/namespace/Main.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.options.LKQLOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;

Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/interop/null/Main.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.options.LKQLOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;

Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/interop/object/Main.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.options.LKQLOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;

Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/interop/pattern/Main.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.options.LKQLOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;

Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/interop/property/Main.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.options.LKQLOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;

Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/interop/selector/Main.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.options.LKQLOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;

Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/interop/tuple/Main.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.adacore.lkql_jit.LKQLOptions;
import com.adacore.lkql_jit.options.LKQLOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;

Expand Down
Loading

0 comments on commit a1335ca

Please sign in to comment.