Skip to content

Commit

Permalink
Merge branch 'topic/update_array_types' into 'master'
Browse files Browse the repository at this point in the history
Update array types

See merge request eng/libadalang/langkit-query-language!198
  • Loading branch information
Rémi Segard committed Apr 29, 2024
2 parents e0a38ac + f73bda6 commit a11826c
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lkql_jit/language/pom.xml
Expand Up @@ -102,4 +102,4 @@
</dependency>
</dependencies>

</project>
</project>
Expand Up @@ -23,7 +23,6 @@
import com.oracle.truffle.api.source.Source;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import org.graalvm.options.OptionCategory;
import org.graalvm.options.OptionDescriptors;
import org.graalvm.options.OptionKey;
Expand Down Expand Up @@ -342,8 +341,8 @@ protected CallTarget parse(ParsingRequest request) {
}

// Verify the parsing result
final List<Liblkqllang.Diagnostic> diagnostics = unit.getDiagnostics();
if (diagnostics.size() > 0) {
final Liblkqllang.Diagnostic[] diagnostics = unit.getDiagnostics();
if (diagnostics.length > 0) {
throw LKQLRuntimeException.parsingException(diagnostics, request.getSource());
}

Expand Down
Expand Up @@ -191,13 +191,13 @@ private void applyUnitRule(
Object loc = violation.getUncached("loc");
final Libadalang.AnalysisUnit locUnit;
final Libadalang.SourceLocationRange slocRange;
final Libadalang.AdaNodeArray genericInstantiations;
final Libadalang.AdaNode[] genericInstantiations;

if (LKQLTypeSystemGen.isToken(loc)) {
final Libadalang.Token token = LKQLTypeSystemGen.asToken(loc);
locUnit = token.unit;
slocRange = token.sourceLocationRange;
genericInstantiations = Libadalang.AdaNodeArray.NONE;
genericInstantiations = new Libadalang.AdaNode[0];
} else if (LKQLTypeSystemGen.isAdaNode(loc)) {
final Libadalang.AdaNode node = LKQLTypeSystemGen.asAdaNode(loc);
locUnit = node.getUnit();
Expand Down
Expand Up @@ -15,7 +15,6 @@
import com.oracle.truffle.api.exception.AbstractTruffleException;
import com.oracle.truffle.api.source.Source;
import java.io.Serial;
import java.util.List;

/**
* This exception means that there is an error in the LKQL execution.
Expand Down Expand Up @@ -125,7 +124,7 @@ public static LKQLRuntimeException shouldNotHappen(String message) {
*/
@CompilerDirectives.TruffleBoundary
public static LKQLRuntimeException parsingException(
List<Liblkqllang.Diagnostic> diagnostics, Source source) {
Liblkqllang.Diagnostic[] diagnostics, Source source) {
// Prepare the error message builder
StringBuilder builder = new StringBuilder();

Expand Down
Expand Up @@ -383,7 +383,7 @@ && inGenericInstantiation(next)) {
* @param node The node to check
*/
private static boolean inGenericInstantiation(Libadalang.AdaNode node) {
return node.pGenericInstantiations().size() > 0;
return node.pGenericInstantiations().length > 0;
}

// ----- Un-needed methods -----
Expand Down
Expand Up @@ -241,8 +241,8 @@ else if (javaValue instanceof Libadalang.AnalysisUnit) {
}

// If the source is an array from libadalang
else if (javaValue instanceof Libadalang.ArrayBase<?> array) {
Object[] res = new Object[array.size()];
else if (javaValue instanceof Object[] array) {
Object[] res = new Object[array.length];
int i = 0;
for (Object obj : array) {
res[i] = toLKQLValue(obj);
Expand Down
Expand Up @@ -62,7 +62,7 @@ void emitRuleViolation(
String message,
Libadalang.SourceLocationRange slocRange,
Libadalang.AnalysisUnit unit,
Libadalang.AdaNodeArray genericInstantiations,
Libadalang.AdaNode[] genericInstantiations,
SourceLinesCache linesCache,
LKQLContext context);

Expand Down Expand Up @@ -104,7 +104,7 @@ public void emitRuleViolation(
String message,
Libadalang.SourceLocationRange slocRange,
Libadalang.AnalysisUnit unit,
Libadalang.AdaNodeArray genericInstantiations,
Libadalang.AdaNode[] genericInstantiations,
SourceLinesCache linesCache,
LKQLContext context) {
printRuleViolation(
Expand Down Expand Up @@ -214,28 +214,28 @@ public void emitRuleViolation(
String message,
Libadalang.SourceLocationRange slocRange,
Libadalang.AnalysisUnit unit,
Libadalang.AdaNodeArray genericInstantiations,
Libadalang.AdaNode[] genericInstantiations,
SourceLinesCache linesCache,
LKQLContext context) {
// Get the file name
final String fileName = FileUtils.baseName(unit.getFileName());
final String colPrefix = slocRange.start.column < 10 ? "0" : "";

// Append generic instantiation information to the message
if (genericInstantiations.size() > 0) {
if (genericInstantiations.length > 0) {
StringBuilder messageBuilder = new StringBuilder(message);
for (int i = 0; i < genericInstantiations.size(); ++i) {
for (int i = 0; i < genericInstantiations.length; ++i) {
if (i > 0) {
messageBuilder.append(" [");
} else {
messageBuilder.append(" [instance at ");
}
final Libadalang.AdaNode inst = genericInstantiations.get(i);
final Libadalang.AdaNode inst = genericInstantiations[i];
messageBuilder.append(FileUtils.baseName(inst.getUnit().getFileName()));
messageBuilder.append(":");
messageBuilder.append(inst.getSourceLocationRange().start.line);
}
messageBuilder.append("]".repeat(genericInstantiations.size()));
messageBuilder.append("]".repeat(genericInstantiations.length));
message = messageBuilder.toString();
}

Expand Down
Expand Up @@ -60,7 +60,7 @@ public static Object refineArgument(Object source, Class<?> type, Arg argument)
}

// If the required type is a unit array
else if (type.equals(Libadalang.AnalysisUnitArray.class)) {
else if (type.equals(Libadalang.AnalysisUnit[].class)) {
LKQLList resList;
try {
resList = LKQLTypeSystemGen.expectLKQLList(res);
Expand All @@ -70,11 +70,10 @@ else if (type.equals(Libadalang.AnalysisUnitArray.class)) {
LKQLTypesHelper.fromJava(e.getResult()),
argument);
}
Libadalang.AnalysisUnitArray resArray =
Libadalang.AnalysisUnitArray.create((int) resList.size());
Libadalang.AnalysisUnit[] resArray = new Libadalang.AnalysisUnit[(int) resList.size()];
for (int i = 0; i < resList.size(); i++) {
try {
resArray.set(i, LKQLTypeSystemGen.expectAnalysisUnit(resList.get(i)));
resArray[i] = LKQLTypeSystemGen.expectAnalysisUnit(resList.get(i));
} catch (UnexpectedResultException e) {
throw LKQLRuntimeException.wrongType(
LKQLTypesHelper.ANALYSIS_UNIT,
Expand Down

0 comments on commit a11826c

Please sign in to comment.