2626import static org .sonar .plugins .communitydelphi .api .type .IntrinsicType .UNICODESTRING ;
2727import static org .sonar .plugins .communitydelphi .api .type .IntrinsicType .WIDECHAR ;
2828
29+ import au .com .integradev .delphi .compiler .Architecture ;
2930import au .com .integradev .delphi .compiler .CompilerVersion ;
3031import au .com .integradev .delphi .type .TypeImpl ;
3132import au .com .integradev .delphi .type .factory .ArrayOption ;
@@ -96,19 +97,37 @@ public static Type argumentByIndex(int index) {
9697 return new ArgumentByIndexReturnType (index );
9798 }
9899
100+ private static Type getOpenArraySizeType (TypeFactory typeFactory ) {
101+ if (((TypeFactoryImpl ) typeFactory ).getToolchain ().architecture == Architecture .X86 ) {
102+ return typeFactory .getIntrinsic (IntrinsicType .INTEGER );
103+ } else {
104+ return typeFactory .getIntrinsic (
105+ ((TypeFactoryImpl ) typeFactory ).getCompilerVersion ().compareTo (VERSION_ATHENS ) >= 0
106+ ? IntrinsicType .NATIVEINT
107+ : IntrinsicType .INTEGER );
108+ }
109+ }
110+
111+ private static Type getDynamicArraySizeType (TypeFactory typeFactory ) {
112+ if (((TypeFactoryImpl ) typeFactory ).getToolchain ().architecture == Architecture .X86 ) {
113+ return typeFactory .getIntrinsic (IntrinsicType .INTEGER );
114+ } else {
115+ return typeFactory .getIntrinsic (IntrinsicType .NATIVEINT );
116+ }
117+ }
118+
99119 private static final class LengthReturnType extends IntrinsicReturnType {
100120 private final Type byteType ;
101121 private final Type integerType ;
122+
102123 private final Type openArraySizeType ;
124+ private final Type dynamicArraySizeType ;
103125
104126 private LengthReturnType (TypeFactory typeFactory ) {
105127 this .byteType = typeFactory .getIntrinsic (IntrinsicType .BYTE );
106128 this .integerType = typeFactory .getIntrinsic (IntrinsicType .INTEGER );
107- this .openArraySizeType =
108- typeFactory .getIntrinsic (
109- ((TypeFactoryImpl ) typeFactory ).getCompilerVersion ().compareTo (VERSION_ATHENS ) >= 0
110- ? IntrinsicType .NATIVEINT
111- : IntrinsicType .INTEGER );
129+ this .openArraySizeType = getOpenArraySizeType (typeFactory );
130+ this .dynamicArraySizeType = getDynamicArraySizeType (typeFactory );
112131 }
113132
114133 @ Override
@@ -118,6 +137,8 @@ public Type getReturnType(List<Type> arguments) {
118137 return byteType ;
119138 } else if (type .isOpenArray ()) {
120139 return openArraySizeType ;
140+ } else if (type .isDynamicArray ()) {
141+ return dynamicArraySizeType ;
121142 } else {
122143 return integerType ;
123144 }
@@ -127,14 +148,12 @@ public Type getReturnType(List<Type> arguments) {
127148 private static final class HighLowReturnType extends IntrinsicReturnType {
128149 private final Type integerType ;
129150 private final Type openArraySizeType ;
151+ private final Type dynamicArraySizeType ;
130152
131153 private HighLowReturnType (TypeFactory typeFactory ) {
132154 this .integerType = typeFactory .getIntrinsic (IntrinsicType .INTEGER );
133- this .openArraySizeType =
134- typeFactory .getIntrinsic (
135- ((TypeFactoryImpl ) typeFactory ).getCompilerVersion ().compareTo (VERSION_ATHENS ) >= 0
136- ? IntrinsicType .NATIVEINT
137- : IntrinsicType .INTEGER );
155+ this .openArraySizeType = getOpenArraySizeType (typeFactory );
156+ this .dynamicArraySizeType = getDynamicArraySizeType (typeFactory );
138157 }
139158
140159 @ Override
@@ -147,6 +166,8 @@ public Type getReturnType(List<Type> arguments) {
147166
148167 if (type .isOpenArray ()) {
149168 type = openArraySizeType ;
169+ } else if (type .isDynamicArray ()) {
170+ type = dynamicArraySizeType ;
150171 } else if (type .isArray () || type .isString ()) {
151172 type = integerType ;
152173 }
0 commit comments