From 506226a67d91f482401ab9d49d64f3ebf234b8a9 Mon Sep 17 00:00:00 2001 From: AbbasNS Date: Mon, 2 Sep 2024 14:35:18 +0200 Subject: [PATCH] SLVS-1435 Support C Language standard flags --- .../CFamily/CmdBuilderTests.cs | 28 +++++++++++++++++++ .../CFamily/VcxProject/CmdBuilder.cs | 25 +++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/Integration.Vsix.UnitTests/CFamily/CmdBuilderTests.cs b/src/Integration.Vsix.UnitTests/CFamily/CmdBuilderTests.cs index 948caad7f8..eaf1bd6a60 100644 --- a/src/Integration.Vsix.UnitTests/CFamily/CmdBuilderTests.cs +++ b/src/Integration.Vsix.UnitTests/CFamily/CmdBuilderTests.cs @@ -185,6 +185,29 @@ public void ConvertCppStandard(string input, string output) } } + [TestMethod] + [DataRow("", "")] + [DataRow("Default", "")] + [DataRow(null, "")] + [DataRow("stdclatest", "/std:clatest")] + [DataRow("stdc23", "/std:c23")] + [DataRow("stdc17", "/std:c17")] + [DataRow("stdc11", "/std:c11")] + [DataRow("Invalid", "Unsupported LanguageStandard_C: Invalid")] + public void ConvertCStandard(string input, string output) + { + if ("Invalid".Equals(input)) + { + Action action = () => CmdBuilder.ConvertCStandard(input); + action.Should().ThrowExactly().And.Message.Should() + .StartWith(output); + } + else + { + CmdBuilder.ConvertCStandard(input).Should().Be(output); + } + } + [TestMethod] [DataRow("", "")] [DataRow("Default", "")] @@ -237,6 +260,11 @@ public void ConvertStructMemberAlignment(string input, string output) [DataRow("LanguageStandard", "stdcpp17", "/std:c++17 ")] [DataRow("LanguageStandard", "stdcpp14", "/std:c++14 ")] [DataRow("LanguageStandard", "Default", "")] + [DataRow("LanguageStandard_C", "stdclatest", "/std:clatest ")] + [DataRow("LanguageStandard_C", "stdc23", "/std:c23 ")] + [DataRow("LanguageStandard_C", "stdc17", "/std:c17 ")] + [DataRow("LanguageStandard_C", "stdc11", "/std:c11 ")] + [DataRow("LanguageStandard_C", "Default", "")] [DataRow("ExceptionHandling", "Sync", "/EHsc ")] [DataRow("ExceptionHandling", "SyncCThrow", "/EHs ")] [DataRow("ExceptionHandling", "Async", "/EHa ")] diff --git a/src/Integration.Vsix/CFamily/VcxProject/CmdBuilder.cs b/src/Integration.Vsix/CFamily/VcxProject/CmdBuilder.cs index c3387d805a..5774d6170f 100644 --- a/src/Integration.Vsix/CFamily/VcxProject/CmdBuilder.cs +++ b/src/Integration.Vsix/CFamily/VcxProject/CmdBuilder.cs @@ -145,6 +145,9 @@ internal void AddOptFromProperties(IVCRulePropertyStorage properties) var cppStandard = GetPotentiallyUnsupportedPropertyValue(properties, "LanguageStandard", ""); AddCmdOpt(ConvertCppStandard(cppStandard)); + var cStandard = GetPotentiallyUnsupportedPropertyValue(properties, "LanguageStandard_C", ""); + AddCmdOpt(ConvertCStandard(cStandard)); + var exceptionHandling = properties.GetEvaluatedPropertyValue("ExceptionHandling"); AddCmdOpt(ConvertExceptionHandling(exceptionHandling)); @@ -378,6 +381,28 @@ private void AddTrueFalse(IVCRulePropertyStorage ivcRulePropertyStorage, string return "/std:c++14"; } } + + internal /* for testing */ static string ConvertCStandard(string value) + { + switch (value) + { + default: + throw new ArgumentException($"Unsupported LanguageStandard_C: {value}", nameof(value)); + case null: + case "": + case "Default": + return ""; + case "stdclatest": + return "/std:clatest"; + case "stdc23": + return "/std:c23"; + case "stdc17": + return "/std:c17"; + case "stdc11": + return "/std:c11"; + } + } + /// /// Returns the value of a property that might not be supported by the current version of the compiler. /// If the property is not supported the default value is returned.