Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Incorrect return types for `Length`, `High`, and `Low` on open/dynamic arrays depending on the
compiler version and toolchain.

## [1.11.0] - 2024-11-04

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,4 +569,8 @@ public IntegerType integerFromLiteralValue(BigInteger value) {
public CompilerVersion getCompilerVersion() {
return compilerVersion;
}

public Toolchain getToolchain() {
return toolchain;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.sonar.plugins.communitydelphi.api.type.IntrinsicType.UNICODESTRING;
import static org.sonar.plugins.communitydelphi.api.type.IntrinsicType.WIDECHAR;

import au.com.integradev.delphi.compiler.Architecture;
import au.com.integradev.delphi.compiler.CompilerVersion;
import au.com.integradev.delphi.type.TypeImpl;
import au.com.integradev.delphi.type.factory.ArrayOption;
Expand Down Expand Up @@ -96,19 +97,37 @@ public static Type argumentByIndex(int index) {
return new ArgumentByIndexReturnType(index);
}

private static Type getOpenArraySizeType(TypeFactory typeFactory) {
if (((TypeFactoryImpl) typeFactory).getToolchain().architecture == Architecture.X86) {
return typeFactory.getIntrinsic(IntrinsicType.INTEGER);
} else {
return typeFactory.getIntrinsic(
((TypeFactoryImpl) typeFactory).getCompilerVersion().compareTo(VERSION_ATHENS) >= 0
? IntrinsicType.NATIVEINT
: IntrinsicType.INTEGER);
}
}

private static Type getDynamicArraySizeType(TypeFactory typeFactory) {
if (((TypeFactoryImpl) typeFactory).getToolchain().architecture == Architecture.X86) {
return typeFactory.getIntrinsic(IntrinsicType.INTEGER);
} else {
return typeFactory.getIntrinsic(IntrinsicType.NATIVEINT);
}
}

private static final class LengthReturnType extends IntrinsicReturnType {
private final Type byteType;
private final Type integerType;

private final Type openArraySizeType;
private final Type dynamicArraySizeType;

private LengthReturnType(TypeFactory typeFactory) {
this.byteType = typeFactory.getIntrinsic(IntrinsicType.BYTE);
this.integerType = typeFactory.getIntrinsic(IntrinsicType.INTEGER);
this.openArraySizeType =
typeFactory.getIntrinsic(
((TypeFactoryImpl) typeFactory).getCompilerVersion().compareTo(VERSION_ATHENS) >= 0
? IntrinsicType.NATIVEINT
: IntrinsicType.INTEGER);
this.openArraySizeType = getOpenArraySizeType(typeFactory);
this.dynamicArraySizeType = getDynamicArraySizeType(typeFactory);
}

@Override
Expand All @@ -118,6 +137,8 @@ public Type getReturnType(List<Type> arguments) {
return byteType;
} else if (type.isOpenArray()) {
return openArraySizeType;
} else if (type.isDynamicArray()) {
return dynamicArraySizeType;
} else {
return integerType;
}
Expand All @@ -127,14 +148,12 @@ public Type getReturnType(List<Type> arguments) {
private static final class HighLowReturnType extends IntrinsicReturnType {
private final Type integerType;
private final Type openArraySizeType;
private final Type dynamicArraySizeType;

private HighLowReturnType(TypeFactory typeFactory) {
this.integerType = typeFactory.getIntrinsic(IntrinsicType.INTEGER);
this.openArraySizeType =
typeFactory.getIntrinsic(
((TypeFactoryImpl) typeFactory).getCompilerVersion().compareTo(VERSION_ATHENS) >= 0
? IntrinsicType.NATIVEINT
: IntrinsicType.INTEGER);
this.openArraySizeType = getOpenArraySizeType(typeFactory);
this.dynamicArraySizeType = getDynamicArraySizeType(typeFactory);
}

@Override
Expand All @@ -147,6 +166,8 @@ public Type getReturnType(List<Type> arguments) {

if (type.isOpenArray()) {
type = openArraySizeType;
} else if (type.isDynamicArray()) {
type = dynamicArraySizeType;
} else if (type.isArray() || type.isString()) {
type = integerType;
}
Expand Down
Loading
Loading