Skip to content

Commit fa18f61

Browse files
committed
Handle native integer types as weak aliases in Delphi 12+
Closes #81
1 parent 50ea105 commit fa18f61

File tree

8 files changed

+237
-85
lines changed

8 files changed

+237
-85
lines changed

CHANGELOG.md

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

1212
- Support for the `TEXTBLOCK` directive.
1313
- **API:** `CompilerDirectiveParser` can now return a new `TextBlockDirective` type.
14+
- **API:** `CheckVerifier::withCompilerVersion` method.
15+
- **API:** `CheckVerifier::withToolchain` method.
1416

1517
### Changed
1618

19+
- `NativeInt` and `NativeUInt` are now treated as weak aliases in Delphi 12+.
1720
- Performance improvements.
1821

1922
### Fixed

delphi-checks-testkit/src/main/java/au/com/integradev/delphi/checks/verifier/CheckVerifier.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import au.com.integradev.delphi.builders.DelphiTestFile;
2222
import au.com.integradev.delphi.builders.DelphiTestUnitBuilder;
23+
import au.com.integradev.delphi.compiler.CompilerVersion;
24+
import au.com.integradev.delphi.compiler.Toolchain;
2325
import org.sonar.plugins.communitydelphi.api.check.DelphiCheck;
2426

2527
public interface CheckVerifier {
@@ -29,6 +31,10 @@ static CheckVerifier newVerifier() {
2931

3032
CheckVerifier withCheck(DelphiCheck check);
3133

34+
CheckVerifier withCompilerVersion(CompilerVersion compilerVersion);
35+
36+
CheckVerifier withToolchain(Toolchain toolchain);
37+
3238
CheckVerifier withUnitScopeName(String unitScope);
3339

3440
CheckVerifier withUnitAlias(String alias, String unitName);

delphi-checks-testkit/src/main/java/au/com/integradev/delphi/checks/verifier/CheckVerifierImpl.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import au.com.integradev.delphi.builders.DelphiTestUnitBuilder;
2828
import au.com.integradev.delphi.check.DelphiCheckContextImpl;
2929
import au.com.integradev.delphi.check.MasterCheckRegistrar;
30+
import au.com.integradev.delphi.compiler.CompilerVersion;
3031
import au.com.integradev.delphi.compiler.Platform;
32+
import au.com.integradev.delphi.compiler.Toolchain;
3133
import au.com.integradev.delphi.file.DelphiFile.DelphiInputFile;
3234
import au.com.integradev.delphi.preprocessor.DelphiPreprocessorFactory;
3335
import au.com.integradev.delphi.preprocessor.directive.CompilerDirectiveParserImpl;
@@ -80,6 +82,8 @@ public class CheckVerifierImpl implements CheckVerifier {
8082

8183
private DelphiCheck check;
8284
private DelphiTestFile testFile;
85+
private CompilerVersion compilerVersion = DelphiProperties.COMPILER_VERSION_DEFAULT;
86+
private Toolchain toolchain = DelphiProperties.COMPILER_TOOLCHAIN_DEFAULT;
8387
private final Set<String> unitScopeNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
8488
private final Map<String, String> unitAliases = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
8589
private final List<DelphiTestUnitBuilder> searchPathUnits = new ArrayList<>();
@@ -92,6 +96,18 @@ public CheckVerifier withCheck(DelphiCheck check) {
9296
return this;
9397
}
9498

99+
@Override
100+
public CheckVerifier withCompilerVersion(CompilerVersion compilerVersion) {
101+
this.compilerVersion = compilerVersion;
102+
return this;
103+
}
104+
105+
@Override
106+
public CheckVerifier withToolchain(Toolchain toolchain) {
107+
this.toolchain = toolchain;
108+
return this;
109+
}
110+
95111
@Override
96112
public CheckVerifier withUnitScopeName(String unitScopeName) {
97113
unitScopeNames.add(unitScopeName);
@@ -248,10 +264,7 @@ private List<Issue> execute() {
248264
SymbolTable symbolTable =
249265
SymbolTable.builder()
250266
.preprocessorFactory(new DelphiPreprocessorFactory(Platform.WINDOWS))
251-
.typeFactory(
252-
new TypeFactoryImpl(
253-
DelphiProperties.COMPILER_TOOLCHAIN_DEFAULT,
254-
DelphiProperties.COMPILER_VERSION_DEFAULT))
267+
.typeFactory(new TypeFactoryImpl(toolchain, compilerVersion))
255268
.standardLibraryPath(standardLibraryPath)
256269
.sourceFiles(List.of(file.getSourceCodeFile().toPath()))
257270
.unitAliases(unitAliases)

delphi-checks/src/test/java/au/com/integradev/delphi/checks/PlatformDependentCastCheckTest.java

Lines changed: 78 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,20 @@
2020

2121
import au.com.integradev.delphi.builders.DelphiTestUnitBuilder;
2222
import au.com.integradev.delphi.checks.verifier.CheckVerifier;
23-
import org.junit.jupiter.api.Test;
23+
import au.com.integradev.delphi.compiler.CompilerVersion;
24+
import org.junit.jupiter.params.ParameterizedTest;
25+
import org.junit.jupiter.params.provider.ValueSource;
2426

2527
class PlatformDependentCastCheckTest {
26-
@Test
27-
void testPointerIntegerCastsShouldAddIssue() {
28+
private static final String VERSION_ALEXANDRIA = "VER350";
29+
private static final String VERSION_ATHENS = "VER360";
30+
31+
@ParameterizedTest
32+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
33+
void testPointerIntegerCastsShouldAddIssue(String versionSymbol) {
2834
CheckVerifier.newVerifier()
2935
.withCheck(new PlatformDependentCastCheck())
36+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
3037
.onFile(
3138
new DelphiTestUnitBuilder()
3239
.appendImpl("procedure Foo;")
@@ -40,10 +47,12 @@ void testPointerIntegerCastsShouldAddIssue() {
4047
.verifyIssues();
4148
}
4249

43-
@Test
44-
void testObjectIntegerCastsShouldAddIssue() {
50+
@ParameterizedTest
51+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
52+
void testObjectIntegerCastsShouldAddIssue(String versionSymbol) {
4553
CheckVerifier.newVerifier()
4654
.withCheck(new PlatformDependentCastCheck())
55+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
4756
.onFile(
4857
new DelphiTestUnitBuilder()
4958
.appendImpl("procedure Foo;")
@@ -57,10 +66,12 @@ void testObjectIntegerCastsShouldAddIssue() {
5766
.verifyIssues();
5867
}
5968

60-
@Test
61-
void testInterfaceIntegerCastsShouldAddIssue() {
69+
@ParameterizedTest
70+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
71+
void testInterfaceIntegerCastsShouldAddIssue(String versionSymbol) {
6272
CheckVerifier.newVerifier()
6373
.withCheck(new PlatformDependentCastCheck())
74+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
6475
.onFile(
6576
new DelphiTestUnitBuilder()
6677
.appendImpl("procedure Foo;")
@@ -74,10 +85,12 @@ void testInterfaceIntegerCastsShouldAddIssue() {
7485
.verifyIssues();
7586
}
7687

77-
@Test
78-
void testNativeIntIntegerCastsShouldAddIssue() {
88+
@ParameterizedTest
89+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
90+
void testNativeIntIntegerCastsShouldAddIssue(String versionSymbol) {
7991
CheckVerifier.newVerifier()
8092
.withCheck(new PlatformDependentCastCheck())
93+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
8194
.onFile(
8295
new DelphiTestUnitBuilder()
8396
.appendImpl("procedure Foo;")
@@ -91,10 +104,12 @@ void testNativeIntIntegerCastsShouldAddIssue() {
91104
.verifyIssues();
92105
}
93106

94-
@Test
95-
void testNativeIntPointerCastsShouldNotAddIssue() {
107+
@ParameterizedTest
108+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
109+
void testNativeIntPointerCastsShouldNotAddIssue(String versionSymbol) {
96110
CheckVerifier.newVerifier()
97111
.withCheck(new PlatformDependentCastCheck())
112+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
98113
.onFile(
99114
new DelphiTestUnitBuilder()
100115
.appendImpl("procedure Foo;")
@@ -108,10 +123,12 @@ void testNativeIntPointerCastsShouldNotAddIssue() {
108123
.verifyNoIssues();
109124
}
110125

111-
@Test
112-
void testNativeIntObjectCastsShouldNotAddIssue() {
126+
@ParameterizedTest
127+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
128+
void testNativeIntObjectCastsShouldNotAddIssue(String versionSymbol) {
113129
CheckVerifier.newVerifier()
114130
.withCheck(new PlatformDependentCastCheck())
131+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
115132
.onFile(
116133
new DelphiTestUnitBuilder()
117134
.appendImpl("procedure Foo;")
@@ -125,10 +142,12 @@ void testNativeIntObjectCastsShouldNotAddIssue() {
125142
.verifyNoIssues();
126143
}
127144

128-
@Test
129-
void testNativeIntInterfaceCastsShouldNotAddIssue() {
145+
@ParameterizedTest
146+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
147+
void testNativeIntInterfaceCastsShouldNotAddIssue(String versionSymbol) {
130148
CheckVerifier.newVerifier()
131149
.withCheck(new PlatformDependentCastCheck())
150+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
132151
.onFile(
133152
new DelphiTestUnitBuilder()
134153
.appendImpl("procedure Foo;")
@@ -142,10 +161,12 @@ void testNativeIntInterfaceCastsShouldNotAddIssue() {
142161
.verifyNoIssues();
143162
}
144163

145-
@Test
146-
void testIntegerLiteralCastsShouldNotAddIssue() {
164+
@ParameterizedTest
165+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
166+
void testIntegerLiteralCastsShouldNotAddIssue(String versionSymbol) {
147167
CheckVerifier.newVerifier()
148168
.withCheck(new PlatformDependentCastCheck())
169+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
149170
.onFile(
150171
new DelphiTestUnitBuilder()
151172
.appendImpl("procedure Foo;")
@@ -159,10 +180,12 @@ void testIntegerLiteralCastsShouldNotAddIssue() {
159180
.verifyNoIssues();
160181
}
161182

162-
@Test
163-
void testHexadecimalLiteralCastsShouldNotAddIssue() {
183+
@ParameterizedTest
184+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
185+
void testHexadecimalLiteralCastsShouldNotAddIssue(String versionSymbol) {
164186
CheckVerifier.newVerifier()
165187
.withCheck(new PlatformDependentCastCheck())
188+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
166189
.onFile(
167190
new DelphiTestUnitBuilder()
168191
.appendImpl("procedure Foo;")
@@ -176,10 +199,12 @@ void testHexadecimalLiteralCastsShouldNotAddIssue() {
176199
.verifyNoIssues();
177200
}
178201

179-
@Test
180-
void testBinaryLiteralCastsShouldNotAddIssue() {
202+
@ParameterizedTest
203+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
204+
void testBinaryLiteralCastsShouldNotAddIssue(String versionSymbol) {
181205
CheckVerifier.newVerifier()
182206
.withCheck(new PlatformDependentCastCheck())
207+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
183208
.onFile(
184209
new DelphiTestUnitBuilder()
185210
.appendImpl("procedure Foo;")
@@ -193,10 +218,12 @@ void testBinaryLiteralCastsShouldNotAddIssue() {
193218
.verifyNoIssues();
194219
}
195220

196-
@Test
197-
void testTObjectStringCastsShouldNotAddIssue() {
221+
@ParameterizedTest
222+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
223+
void testTObjectStringCastsShouldNotAddIssue(String versionSymbol) {
198224
CheckVerifier.newVerifier()
199225
.withCheck(new PlatformDependentCastCheck())
226+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
200227
.onFile(
201228
new DelphiTestUnitBuilder()
202229
.appendImpl("procedure Foo;")
@@ -210,10 +237,12 @@ void testTObjectStringCastsShouldNotAddIssue() {
210237
.verifyNoIssues();
211238
}
212239

213-
@Test
214-
void testTObjectRecordCastsShouldNotAddIssue() {
240+
@ParameterizedTest
241+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
242+
void testTObjectRecordCastsShouldNotAddIssue(String versionSymbol) {
215243
CheckVerifier.newVerifier()
216244
.withCheck(new PlatformDependentCastCheck())
245+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
217246
.onFile(
218247
new DelphiTestUnitBuilder()
219248
.appendDecl("type")
@@ -230,10 +259,12 @@ void testTObjectRecordCastsShouldNotAddIssue() {
230259
.verifyNoIssues();
231260
}
232261

233-
@Test
234-
void testRecordIntegerCastsShouldNotAddIssue() {
262+
@ParameterizedTest
263+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
264+
void testRecordIntegerCastsShouldNotAddIssue(String versionSymbol) {
235265
CheckVerifier.newVerifier()
236266
.withCheck(new PlatformDependentCastCheck())
267+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
237268
.onFile(
238269
new DelphiTestUnitBuilder()
239270
.appendDecl("type")
@@ -249,10 +280,12 @@ void testRecordIntegerCastsShouldNotAddIssue() {
249280
.verifyNoIssues();
250281
}
251282

252-
@Test
253-
void testIntegerStringCastsShouldAddIssue() {
283+
@ParameterizedTest
284+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
285+
void testIntegerStringCastsShouldAddIssue(String versionSymbol) {
254286
CheckVerifier.newVerifier()
255287
.withCheck(new PlatformDependentCastCheck())
288+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
256289
.onFile(
257290
new DelphiTestUnitBuilder()
258291
.appendImpl("procedure Foo;")
@@ -266,10 +299,12 @@ void testIntegerStringCastsShouldAddIssue() {
266299
.verifyIssues();
267300
}
268301

269-
@Test
270-
void testNativeIntStringCastsShouldNotAddIssue() {
302+
@ParameterizedTest
303+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
304+
void testNativeIntStringCastsShouldNotAddIssue(String versionSymbol) {
271305
CheckVerifier.newVerifier()
272306
.withCheck(new PlatformDependentCastCheck())
307+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
273308
.onFile(
274309
new DelphiTestUnitBuilder()
275310
.appendImpl("procedure Foo;")
@@ -283,10 +318,12 @@ void testNativeIntStringCastsShouldNotAddIssue() {
283318
.verifyNoIssues();
284319
}
285320

286-
@Test
287-
void testIntegerArrayCastsShouldAddIssue() {
321+
@ParameterizedTest
322+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
323+
void testIntegerArrayCastsShouldAddIssue(String versionSymbol) {
288324
CheckVerifier.newVerifier()
289325
.withCheck(new PlatformDependentCastCheck())
326+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
290327
.onFile(
291328
new DelphiTestUnitBuilder()
292329
.appendImpl("procedure Foo;")
@@ -300,10 +337,12 @@ void testIntegerArrayCastsShouldAddIssue() {
300337
.verifyIssues();
301338
}
302339

303-
@Test
304-
void testNativeIntArrayCastsShouldNotAddIssue() {
340+
@ParameterizedTest
341+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
342+
void testNativeIntArrayCastsShouldNotAddIssue(String versionSymbol) {
305343
CheckVerifier.newVerifier()
306344
.withCheck(new PlatformDependentCastCheck())
345+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
307346
.onFile(
308347
new DelphiTestUnitBuilder()
309348
.appendImpl("procedure Foo;")
@@ -317,10 +356,12 @@ void testNativeIntArrayCastsShouldNotAddIssue() {
317356
.verifyNoIssues();
318357
}
319358

320-
@Test
321-
void testStrongAliasCastsShouldAddIssue() {
359+
@ParameterizedTest
360+
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
361+
void testStrongAliasCastsShouldAddIssue(String versionSymbol) {
322362
CheckVerifier.newVerifier()
323363
.withCheck(new PlatformDependentCastCheck())
364+
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
324365
.onFile(
325366
new DelphiTestUnitBuilder()
326367
.appendImpl("procedure Foo;")

0 commit comments

Comments
 (0)