@@ -525,6 +525,40 @@ static void diagnoseCxxInteropCompatMode(Arg *verArg, ArgList &Args,
525
525
diags.diagnose (SourceLoc (), diag::valid_cxx_interop_modes, versStr);
526
526
}
527
527
528
+ void LangOptions::setCxxInteropFromArgs (ArgList &Args,
529
+ swift::DiagnosticEngine &Diags) {
530
+ if (Arg *A = Args.getLastArg (options::OPT_cxx_interoperability_mode)) {
531
+ if (Args.hasArg (options::OPT_enable_experimental_cxx_interop)) {
532
+ Diags.diagnose (SourceLoc (), diag::dont_enable_interop_and_compat);
533
+ }
534
+
535
+ auto interopCompatMode = validateCxxInteropCompatibilityMode (A->getValue ());
536
+ EnableCXXInterop |=
537
+ (interopCompatMode.first == CxxCompatMode::enabled);
538
+ if (EnableCXXInterop) {
539
+ cxxInteropCompatVersion = interopCompatMode.second ;
540
+ // The default is tied to the current language version.
541
+ if (cxxInteropCompatVersion.empty ())
542
+ cxxInteropCompatVersion =
543
+ EffectiveLanguageVersion.asMajorVersion ();
544
+ }
545
+
546
+ if (interopCompatMode.first == CxxCompatMode::invalid)
547
+ diagnoseCxxInteropCompatMode (A, Args, Diags);
548
+ }
549
+
550
+ if (Args.hasArg (options::OPT_enable_experimental_cxx_interop)) {
551
+ Diags.diagnose (SourceLoc (), diag::enable_interop_flag_deprecated);
552
+ Diags.diagnose (SourceLoc (), diag::swift_will_maintain_compat);
553
+ EnableCXXInterop |= true ;
554
+ // Using the deprecated option only forces the 'swift-5.9' compat
555
+ // mode.
556
+ if (cxxInteropCompatVersion.empty ())
557
+ cxxInteropCompatVersion =
558
+ validateCxxInteropCompatibilityMode (" swift-5.9" ).second ;
559
+ }
560
+ }
561
+
528
562
static std::optional<swift::StrictConcurrency>
529
563
parseStrictConcurrency (StringRef value) {
530
564
return llvm::StringSwitch<std::optional<swift::StrictConcurrency>>(value)
@@ -1255,37 +1289,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
1255
1289
if (const Arg *A = Args.getLastArg (OPT_clang_target)) {
1256
1290
Opts.ClangTarget = llvm::Triple (A->getValue ());
1257
1291
}
1258
-
1259
- if (Arg *A = Args.getLastArg (OPT_cxx_interoperability_mode)) {
1260
- if (Args.hasArg (OPT_enable_experimental_cxx_interop)) {
1261
- Diags.diagnose (SourceLoc (), diag::dont_enable_interop_and_compat);
1262
- }
1263
-
1264
- auto interopCompatMode = validateCxxInteropCompatibilityMode (A->getValue ());
1265
- Opts.EnableCXXInterop |=
1266
- (interopCompatMode.first == CxxCompatMode::enabled);
1267
- if (Opts.EnableCXXInterop ) {
1268
- Opts.cxxInteropCompatVersion = interopCompatMode.second ;
1269
- // The default is tied to the current language version.
1270
- if (Opts.cxxInteropCompatVersion .empty ())
1271
- Opts.cxxInteropCompatVersion =
1272
- Opts.EffectiveLanguageVersion .asMajorVersion ();
1273
- }
1274
-
1275
- if (interopCompatMode.first == CxxCompatMode::invalid)
1276
- diagnoseCxxInteropCompatMode (A, Args, Diags);
1277
- }
1278
-
1279
- if (Args.hasArg (OPT_enable_experimental_cxx_interop)) {
1280
- Diags.diagnose (SourceLoc (), diag::enable_interop_flag_deprecated);
1281
- Diags.diagnose (SourceLoc (), diag::swift_will_maintain_compat);
1282
- Opts.EnableCXXInterop |= true ;
1283
- // Using the deprecated option only forces the 'swift-5.9' compat
1284
- // mode.
1285
- if (Opts.cxxInteropCompatVersion .empty ())
1286
- Opts.cxxInteropCompatVersion =
1287
- validateCxxInteropCompatibilityMode (" swift-5.9" ).second ;
1288
- }
1292
+
1293
+ Opts.setCxxInteropFromArgs (Args, Diags);
1289
1294
1290
1295
Opts.EnableObjCInterop =
1291
1296
Args.hasFlag (OPT_enable_objc_interop, OPT_disable_objc_interop,
0 commit comments