Skip to content

Commit 335e310

Browse files
committed
Rename DP to PlatformAndVersion
1 parent a12e45e commit 335e310

File tree

1 file changed

+79
-66
lines changed

1 file changed

+79
-66
lines changed

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 79 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,14 +2254,14 @@ std::optional<DarwinPlatform> getDeploymentTargetFromTargetArg(
22542254
<< A->getSpelling() << A->getValue();
22552255
}
22562256
}
2257-
DarwinPlatform DP = DarwinPlatform::createFromTarget(
2257+
DarwinPlatform PlatformAndVersion = DarwinPlatform::createFromTarget(
22582258
Triple, Args.getLastArg(options::OPT_target), TargetVariantTriple,
22592259
SDKInfo);
22602260

22612261
// Override the OSVersion if it doesn't match the one from the triple.
22622262
if (Triple.getOSVersion() != OSVersion)
2263-
DP.setOSVersion(OSVersion);
2264-
return DP;
2263+
PlatformAndVersion.setOSVersion(OSVersion);
2264+
return PlatformAndVersion;
22652265
}
22662266

22672267
/// Returns the deployment target that's specified using the -mtargetos option.
@@ -2340,129 +2340,138 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
23402340
SDKInfo = parseSDKSettings(getVFS(), Args, getDriver());
23412341

23422342
// The OS and the version can be specified using the -target argument.
2343-
std::optional<DarwinPlatform> DP =
2343+
std::optional<DarwinPlatform> PlatformAndVersion =
23442344
getDeploymentTargetFromTargetArg(Args, getTriple(), getDriver(), SDKInfo);
2345-
if (DP) {
2345+
if (PlatformAndVersion) {
23462346
// Disallow mixing -target and -mtargetos=.
23472347
if (const auto *MTargetOSArg = Args.getLastArg(options::OPT_mtargetos_EQ)) {
2348-
std::string TargetArgStr = DP->getAsString(Args, Opts);
2348+
std::string TargetArgStr = PlatformAndVersion->getAsString(Args, Opts);
23492349
std::string MTargetOSArgStr = MTargetOSArg->getAsString(Args);
23502350
getDriver().Diag(diag::err_drv_cannot_mix_options)
23512351
<< TargetArgStr << MTargetOSArgStr;
23522352
}
2353-
std::optional<DarwinPlatform> OSVersionArgTarget =
2353+
std::optional<DarwinPlatform> PlatformAndVersionFromOSVersionArg =
23542354
getDeploymentTargetFromOSVersionArg(Args, getDriver());
2355-
if (OSVersionArgTarget) {
2355+
if (PlatformAndVersionFromOSVersionArg) {
23562356
unsigned TargetMajor, TargetMinor, TargetMicro;
23572357
bool TargetExtra;
23582358
unsigned ArgMajor, ArgMinor, ArgMicro;
23592359
bool ArgExtra;
2360-
if (DP->getPlatform() != OSVersionArgTarget->getPlatform() ||
2361-
(Driver::GetReleaseVersion(DP->getOSVersion().getAsString(),
2362-
TargetMajor, TargetMinor, TargetMicro,
2363-
TargetExtra) &&
2360+
if (PlatformAndVersion->getPlatform() !=
2361+
PlatformAndVersionFromOSVersionArg->getPlatform() ||
2362+
(Driver::GetReleaseVersion(
2363+
PlatformAndVersion->getOSVersion().getAsString(), TargetMajor,
2364+
TargetMinor, TargetMicro, TargetExtra) &&
23642365
Driver::GetReleaseVersion(
2365-
OSVersionArgTarget->getOSVersion().getAsString(), ArgMajor,
2366-
ArgMinor, ArgMicro, ArgExtra) &&
2366+
PlatformAndVersionFromOSVersionArg->getOSVersion().getAsString(),
2367+
ArgMajor, ArgMinor, ArgMicro, ArgExtra) &&
23672368
(VersionTuple(TargetMajor, TargetMinor, TargetMicro) !=
23682369
VersionTuple(ArgMajor, ArgMinor, ArgMicro) ||
23692370
TargetExtra != ArgExtra))) {
23702371
// Select the OS version from the -m<os>-version-min argument when
23712372
// the -target does not include an OS version.
2372-
if (DP->getPlatform() == OSVersionArgTarget->getPlatform() &&
2373-
!DP->providedOSVersion()) {
2374-
DP->setOSVersion(OSVersionArgTarget->getOSVersion());
2373+
if (PlatformAndVersion->getPlatform() ==
2374+
PlatformAndVersionFromOSVersionArg->getPlatform() &&
2375+
!PlatformAndVersion->providedOSVersion()) {
2376+
PlatformAndVersion->setOSVersion(
2377+
PlatformAndVersionFromOSVersionArg->getOSVersion());
23752378
} else {
23762379
// Warn about -m<os>-version-min that doesn't match the OS version
23772380
// that's specified in the target.
23782381
std::string OSVersionArg =
2379-
OSVersionArgTarget->getAsString(Args, Opts);
2380-
std::string TargetArg = DP->getAsString(Args, Opts);
2382+
PlatformAndVersionFromOSVersionArg->getAsString(Args, Opts);
2383+
std::string TargetArg = PlatformAndVersion->getAsString(Args, Opts);
23812384
getDriver().Diag(clang::diag::warn_drv_overriding_option)
23822385
<< OSVersionArg << TargetArg;
23832386
}
23842387
}
23852388
}
2386-
} else if ((DP = getDeploymentTargetFromMTargetOSArg(Args, getDriver(),
2387-
SDKInfo))) {
2389+
} else if ((PlatformAndVersion = getDeploymentTargetFromMTargetOSArg(
2390+
Args, getDriver(), SDKInfo))) {
23882391
// The OS target can be specified using the -mtargetos= argument.
23892392
// Disallow mixing -mtargetos= and -m<os>version-min=.
2390-
std::optional<DarwinPlatform> OSVersionArgTarget =
2393+
std::optional<DarwinPlatform> PlatformAndVersionFromOSVersionArg =
23912394
getDeploymentTargetFromOSVersionArg(Args, getDriver());
2392-
if (OSVersionArgTarget) {
2393-
std::string MTargetOSArgStr = DP->getAsString(Args, Opts);
2394-
std::string OSVersionArgStr = OSVersionArgTarget->getAsString(Args, Opts);
2395+
if (PlatformAndVersionFromOSVersionArg) {
2396+
std::string MTargetOSArgStr = PlatformAndVersion->getAsString(Args, Opts);
2397+
std::string OSVersionArgStr =
2398+
PlatformAndVersionFromOSVersionArg->getAsString(Args, Opts);
23952399
getDriver().Diag(diag::err_drv_cannot_mix_options)
23962400
<< MTargetOSArgStr << OSVersionArgStr;
23972401
}
23982402
} else {
23992403
// The OS target can be specified using the -m<os>version-min argument.
2400-
DP = getDeploymentTargetFromOSVersionArg(Args, getDriver());
2404+
PlatformAndVersion = getDeploymentTargetFromOSVersionArg(Args, getDriver());
24012405
// If no deployment target was specified on the command line, check for
24022406
// environment defines.
2403-
if (!DP) {
2404-
DP =
2407+
if (!PlatformAndVersion) {
2408+
PlatformAndVersion =
24052409
getDeploymentTargetFromEnvironmentVariables(getDriver(), getTriple());
2406-
if (DP) {
2410+
if (PlatformAndVersion) {
24072411
// Don't infer simulator from the arch when the SDK is also specified.
24082412
std::optional<DarwinPlatform> SDKTarget =
24092413
inferDeploymentTargetFromSDK(Args, SDKInfo);
24102414
if (SDKTarget)
2411-
DP->setEnvironment(SDKTarget->getEnvironment());
2415+
PlatformAndVersion->setEnvironment(SDKTarget->getEnvironment());
24122416
}
24132417
}
24142418
// If there is no command-line argument to specify the Target version and
24152419
// no environment variable defined, see if we can set the default based
24162420
// on -isysroot using SDKSettings.json if it exists.
2417-
if (!DP) {
2418-
DP = inferDeploymentTargetFromSDK(Args, SDKInfo);
2421+
if (!PlatformAndVersion) {
2422+
PlatformAndVersion = inferDeploymentTargetFromSDK(Args, SDKInfo);
24192423
/// If the target was successfully constructed from the SDK path, try to
24202424
/// infer the SDK info if the SDK doesn't have it.
2421-
if (DP && !SDKInfo)
2422-
SDKInfo = DP->inferSDKInfo();
2425+
if (PlatformAndVersion && !SDKInfo)
2426+
SDKInfo = PlatformAndVersion->inferSDKInfo();
24232427
}
24242428
// If no OS targets have been specified, try to guess platform from -target
24252429
// or arch name and compute the version from the triple.
2426-
if (!DP)
2427-
DP = inferDeploymentTargetFromArch(Args, *this, getTriple(), getDriver());
2430+
if (!PlatformAndVersion)
2431+
PlatformAndVersion =
2432+
inferDeploymentTargetFromArch(Args, *this, getTriple(), getDriver());
24282433
}
24292434

2430-
assert(DP && "Unable to infer Darwin variant");
2435+
assert(PlatformAndVersion && "Unable to infer Darwin variant");
24312436
// After the deployment OS version has been resolved, set it to the canonical
24322437
// version before further error detection and converting to a proper target
24332438
// triple.
2434-
VersionTuple CanonicalVersion = DP->getCanonicalOSVersion();
2435-
if (CanonicalVersion != DP->getOSVersion()) {
2439+
VersionTuple CanonicalVersion = PlatformAndVersion->getCanonicalOSVersion();
2440+
if (CanonicalVersion != PlatformAndVersion->getOSVersion()) {
24362441
getDriver().Diag(diag::warn_drv_overriding_deployment_version)
2437-
<< DP->getOSVersion().getAsString() << CanonicalVersion.getAsString();
2438-
DP->setOSVersion(CanonicalVersion);
2442+
<< PlatformAndVersion->getOSVersion().getAsString()
2443+
<< CanonicalVersion.getAsString();
2444+
PlatformAndVersion->setOSVersion(CanonicalVersion);
24392445
}
24402446

2441-
DP->addOSVersionMinArgument(Args, Opts);
2442-
DarwinPlatformKind Platform = DP->getPlatform();
2447+
PlatformAndVersion->addOSVersionMinArgument(Args, Opts);
2448+
DarwinPlatformKind Platform = PlatformAndVersion->getPlatform();
24432449

24442450
unsigned Major, Minor, Micro;
24452451
bool HadExtra;
24462452
// The major version should not be over this number.
24472453
const unsigned MajorVersionLimit = 1000;
2448-
const std::string DPVersion = DP->getOSVersion().getAsString();
2454+
const std::string OSVersionStr =
2455+
PlatformAndVersion->getOSVersion().getAsString();
24492456
// Set the tool chain target information.
24502457
if (Platform == MacOS) {
2451-
if (!Driver::GetReleaseVersion(DPVersion, Major, Minor, Micro, HadExtra) ||
2458+
if (!Driver::GetReleaseVersion(OSVersionStr, Major, Minor, Micro,
2459+
HadExtra) ||
24522460
HadExtra || Major < 10 || Major >= MajorVersionLimit || Minor >= 100 ||
24532461
Micro >= 100)
24542462
getDriver().Diag(diag::err_drv_invalid_version_number)
2455-
<< DP->getAsString(Args, Opts);
2463+
<< PlatformAndVersion->getAsString(Args, Opts);
24562464
} else if (Platform == IPhoneOS) {
2457-
if (!Driver::GetReleaseVersion(DPVersion, Major, Minor, Micro, HadExtra) ||
2465+
if (!Driver::GetReleaseVersion(OSVersionStr, Major, Minor, Micro,
2466+
HadExtra) ||
24582467
HadExtra || Major >= MajorVersionLimit || Minor >= 100 || Micro >= 100)
24592468
getDriver().Diag(diag::err_drv_invalid_version_number)
2460-
<< DP->getAsString(Args, Opts);
2469+
<< PlatformAndVersion->getAsString(Args, Opts);
24612470
;
2462-
if (DP->getEnvironment() == MacCatalyst &&
2471+
if (PlatformAndVersion->getEnvironment() == MacCatalyst &&
24632472
(Major < 13 || (Major == 13 && Minor < 1))) {
24642473
getDriver().Diag(diag::err_drv_invalid_version_number)
2465-
<< DP->getAsString(Args, Opts);
2474+
<< PlatformAndVersion->getAsString(Args, Opts);
24662475
Major = 13;
24672476
Minor = 1;
24682477
Micro = 0;
@@ -2471,12 +2480,12 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
24712480
// iOS 11.
24722481
if (getTriple().isArch32Bit() && Major >= 11) {
24732482
// If the deployment target is explicitly specified, print a diagnostic.
2474-
if (DP->isExplicitlySpecified()) {
2475-
if (DP->getEnvironment() == MacCatalyst)
2483+
if (PlatformAndVersion->isExplicitlySpecified()) {
2484+
if (PlatformAndVersion->getEnvironment() == MacCatalyst)
24762485
getDriver().Diag(diag::err_invalid_macos_32bit_deployment_target);
24772486
else
24782487
getDriver().Diag(diag::warn_invalid_ios_deployment_target)
2479-
<< DP->getAsString(Args, Opts);
2488+
<< PlatformAndVersion->getAsString(Args, Opts);
24802489
// Otherwise, set it to 10.99.99.
24812490
} else {
24822491
Major = 10;
@@ -2485,42 +2494,46 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
24852494
}
24862495
}
24872496
} else if (Platform == TvOS) {
2488-
if (!Driver::GetReleaseVersion(DPVersion, Major, Minor, Micro, HadExtra) ||
2497+
if (!Driver::GetReleaseVersion(OSVersionStr, Major, Minor, Micro,
2498+
HadExtra) ||
24892499
HadExtra || Major >= MajorVersionLimit || Minor >= 100 || Micro >= 100)
24902500
getDriver().Diag(diag::err_drv_invalid_version_number)
2491-
<< DP->getAsString(Args, Opts);
2501+
<< PlatformAndVersion->getAsString(Args, Opts);
24922502
} else if (Platform == WatchOS) {
2493-
if (!Driver::GetReleaseVersion(DPVersion, Major, Minor, Micro, HadExtra) ||
2503+
if (!Driver::GetReleaseVersion(OSVersionStr, Major, Minor, Micro,
2504+
HadExtra) ||
24942505
HadExtra || Major >= MajorVersionLimit || Minor >= 100 || Micro >= 100)
24952506
getDriver().Diag(diag::err_drv_invalid_version_number)
2496-
<< DP->getAsString(Args, Opts);
2507+
<< PlatformAndVersion->getAsString(Args, Opts);
24972508
} else if (Platform == DriverKit) {
2498-
if (!Driver::GetReleaseVersion(DPVersion, Major, Minor, Micro, HadExtra) ||
2509+
if (!Driver::GetReleaseVersion(OSVersionStr, Major, Minor, Micro,
2510+
HadExtra) ||
24992511
HadExtra || Major < 19 || Major >= MajorVersionLimit || Minor >= 100 ||
25002512
Micro >= 100)
25012513
getDriver().Diag(diag::err_drv_invalid_version_number)
2502-
<< DP->getAsString(Args, Opts);
2514+
<< PlatformAndVersion->getAsString(Args, Opts);
25032515
} else if (Platform == XROS) {
2504-
if (!Driver::GetReleaseVersion(DPVersion, Major, Minor, Micro, HadExtra) ||
2516+
if (!Driver::GetReleaseVersion(OSVersionStr, Major, Minor, Micro,
2517+
HadExtra) ||
25052518
HadExtra || Major < 1 || Major >= MajorVersionLimit || Minor >= 100 ||
25062519
Micro >= 100)
25072520
getDriver().Diag(diag::err_drv_invalid_version_number)
2508-
<< DP->getAsString(Args, Opts);
2521+
<< PlatformAndVersion->getAsString(Args, Opts);
25092522
} else
25102523
llvm_unreachable("unknown kind of Darwin platform");
25112524

2512-
DarwinEnvironmentKind Environment = DP->getEnvironment();
2525+
DarwinEnvironmentKind Environment = PlatformAndVersion->getEnvironment();
25132526
// Recognize iOS targets with an x86 architecture as the iOS simulator.
25142527
if (Environment == NativeEnvironment && Platform != MacOS &&
2515-
Platform != DriverKit && DP->canInferSimulatorFromArch() &&
2516-
getTriple().isX86())
2528+
Platform != DriverKit &&
2529+
PlatformAndVersion->canInferSimulatorFromArch() && getTriple().isX86())
25172530
Environment = Simulator;
25182531

25192532
VersionTuple ZipperedOSVersion;
25202533
if (Environment == MacCatalyst)
2521-
ZipperedOSVersion = DP->getZipperedOSVersion();
2534+
ZipperedOSVersion = PlatformAndVersion->getZipperedOSVersion();
25222535
setTarget(Platform, Environment, Major, Minor, Micro, ZipperedOSVersion);
2523-
TargetVariantTriple = DP->getTargetVariantTriple();
2536+
TargetVariantTriple = PlatformAndVersion->getTargetVariantTriple();
25242537

25252538
if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
25262539
StringRef SDK = getSDKName(A->getValue());

0 commit comments

Comments
 (0)