26
26
import static org .sonar .plugins .communitydelphi .api .type .IntrinsicType .UNICODESTRING ;
27
27
import static org .sonar .plugins .communitydelphi .api .type .IntrinsicType .WIDECHAR ;
28
28
29
+ import au .com .integradev .delphi .compiler .Architecture ;
29
30
import au .com .integradev .delphi .compiler .CompilerVersion ;
30
31
import au .com .integradev .delphi .type .TypeImpl ;
31
32
import au .com .integradev .delphi .type .factory .ArrayOption ;
@@ -96,19 +97,37 @@ public static Type argumentByIndex(int index) {
96
97
return new ArgumentByIndexReturnType (index );
97
98
}
98
99
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
+
99
119
private static final class LengthReturnType extends IntrinsicReturnType {
100
120
private final Type byteType ;
101
121
private final Type integerType ;
122
+
102
123
private final Type openArraySizeType ;
124
+ private final Type dynamicArraySizeType ;
103
125
104
126
private LengthReturnType (TypeFactory typeFactory ) {
105
127
this .byteType = typeFactory .getIntrinsic (IntrinsicType .BYTE );
106
128
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 );
112
131
}
113
132
114
133
@ Override
@@ -118,6 +137,8 @@ public Type getReturnType(List<Type> arguments) {
118
137
return byteType ;
119
138
} else if (type .isOpenArray ()) {
120
139
return openArraySizeType ;
140
+ } else if (type .isDynamicArray ()) {
141
+ return dynamicArraySizeType ;
121
142
} else {
122
143
return integerType ;
123
144
}
@@ -127,14 +148,12 @@ public Type getReturnType(List<Type> arguments) {
127
148
private static final class HighLowReturnType extends IntrinsicReturnType {
128
149
private final Type integerType ;
129
150
private final Type openArraySizeType ;
151
+ private final Type dynamicArraySizeType ;
130
152
131
153
private HighLowReturnType (TypeFactory typeFactory ) {
132
154
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 );
138
157
}
139
158
140
159
@ Override
@@ -147,6 +166,8 @@ public Type getReturnType(List<Type> arguments) {
147
166
148
167
if (type .isOpenArray ()) {
149
168
type = openArraySizeType ;
169
+ } else if (type .isDynamicArray ()) {
170
+ type = dynamicArraySizeType ;
150
171
} else if (type .isArray () || type .isString ()) {
151
172
type = integerType ;
152
173
}
0 commit comments