Skip to content

Commit 76eec4d

Browse files
committed
Add support for undocumented varargs intrinsics
1 parent 30ec100 commit 76eec4d

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Support for the `WEAK_NATIVEINT` symbol, which is defined from Delphi 12 onward.
13+
- Support for undocumented intrinsics usable within `varargs` routines:
14+
- `VarArgStart`
15+
- `VarArgGetValue`
16+
- `VarArgCopy`
17+
- `VarArgEnd`
1318

1419
### Changed
1520

delphi-frontend/src/main/java/au/com/integradev/delphi/type/intrinsic/IntrinsicReturnType.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ public static Type slice(TypeFactory typeFactory) {
8585
return new SliceReturnType(typeFactory);
8686
}
8787

88-
public static Type classReferenceValue() {
89-
return new ClassReferenceValueType();
88+
public static Type classReferenceValue(int argumentIndex) {
89+
return new ClassReferenceValueType(argumentIndex);
9090
}
9191

9292
public static Type argumentByIndex(int index) {
@@ -179,9 +179,15 @@ public Type getReturnType(List<Type> arguments) {
179179
}
180180

181181
private static final class ClassReferenceValueType extends IntrinsicReturnType {
182+
private final int argumentIndex;
183+
184+
private ClassReferenceValueType(int argumentIndex) {
185+
this.argumentIndex = argumentIndex;
186+
}
187+
182188
@Override
183189
public Type getReturnType(List<Type> arguments) {
184-
Type type = arguments.get(0);
190+
Type type = arguments.get(argumentIndex);
185191
if (type.isClassReference()) {
186192
return ((ClassReferenceType) type).classType();
187193
}

delphi-frontend/src/main/java/au/com/integradev/delphi/type/intrinsic/IntrinsicsInjector.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private void buildRoutines() {
202202
routine("Dec").varParam(ANY_TYPED_POINTER).param(type(INTEGER)).required(1);
203203
routine("Default")
204204
.param(ANY_CLASS_REFERENCE)
205-
.returns(IntrinsicReturnType.classReferenceValue());
205+
.returns(IntrinsicReturnType.classReferenceValue(0));
206206
routine("Delete").varParam(ANY_STRING).param(type(INTEGER)).param(type(INTEGER));
207207
routine("Delete")
208208
.varParam(LIKE_DYNAMIC_ARRAY)
@@ -312,6 +312,13 @@ private void buildRoutines() {
312312
.param(ANY_STRING)
313313
.varParam(TypeFactory.untypedType())
314314
.varParam(ANY_32_BIT_INTEGER);
315+
routine("VarArgStart").varParam(TypeFactory.untypedType());
316+
routine("VarArgGetValue")
317+
.varParam(TypeFactory.untypedType())
318+
.param(ANY_CLASS_REFERENCE)
319+
.returns(IntrinsicReturnType.classReferenceValue(1));
320+
routine("VarArgCopy").varParam(TypeFactory.untypedType()).varParam(TypeFactory.untypedType());
321+
routine("VarArgEnd").varParam(TypeFactory.untypedType());
315322
routine("VarArrayRedim").varParam(ANY_VARIANT).param(type(INTEGER));
316323
routine("VarCast").varParam(ANY_VARIANT).param(ANY_VARIANT).param(type(INTEGER));
317324
routine("VarClear").varParam(ANY_VARIANT);

delphi-frontend/src/test/java/au/com/integradev/delphi/type/intrinsic/IntrinsicReturnTypeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void testClassReferenceValueType() {
148148
Type classType = mock(StructType.class);
149149
Type classReference = TYPE_FACTORY_64_ALEXANDRIA.classOf("Foo", classType);
150150

151-
var classReferenceValue = (IntrinsicReturnType) IntrinsicReturnType.classReferenceValue();
151+
var classReferenceValue = (IntrinsicReturnType) IntrinsicReturnType.classReferenceValue(0);
152152
assertThat(classReferenceValue.getReturnType(List.of(classReference))).isSameAs(classType);
153153
assertThat(classReferenceValue.getReturnType(List.of(classType)).isUnknown()).isTrue();
154154
}

0 commit comments

Comments
 (0)