From be6c9b35e7237ab10807aec771f0a5aa539b452c Mon Sep 17 00:00:00 2001 From: Elaheh Rashedi Date: Tue, 2 Mar 2021 13:46:36 -0800 Subject: [PATCH 1/6] not send a default standard --- src/cpptools.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/cpptools.ts b/src/cpptools.ts index 106ca8d2c..e5f2afb20 100644 --- a/src/cpptools.ts +++ b/src/cpptools.ts @@ -22,13 +22,12 @@ const localize: nls.LocalizeFunc = nls.loadMessageBundle(); const log = createLogger('cpptools'); type Architecture = 'x86' | 'x64' | 'arm' | 'arm64' | undefined; -type StandardVersion = "c89" | "c99" | "c11" | "c17" | "c++98" | "c++03" | "c++11" | "c++14" | "c++17" | "c++20" - | "gnu89" | "gnu99" | "gnu11" | "gnu17" | "gnu++98" | "gnu++03" | "gnu++11" | "gnu++14" | "gnu++17" | "gnu++20"; +type StandardVersion = "c89" | "c99" | "c11" | "c17" | "c++98" | "c++03" | "c++11" | "c++14" | "c++17" | "c++20" | "gnu89" | "gnu99" | "gnu11" | "gnu17" | "gnu++98" | "gnu++03" | "gnu++11" | "gnu++14" | "gnu++17" | "gnu++20"; export interface CompileFlagInformation { extraDefinitions: string[]; - standard: StandardVersion; + standard: StandardVersion | undefined; targetArch: Architecture; } @@ -41,7 +40,7 @@ interface TargetDefaults { defines: string[]; } -function parseCppStandard(std: string, can_use_gnu: boolean): StandardVersion|null { +function parseCppStandard(std: string, can_use_gnu: boolean): StandardVersion | undefined { const is_gnu = can_use_gnu && std.startsWith('gnu'); if (std.endsWith('++2a') || std.endsWith('++20') || std.endsWith('++latest')) { return is_gnu ? 'gnu++20' : 'c++20'; @@ -56,11 +55,11 @@ function parseCppStandard(std: string, can_use_gnu: boolean): StandardVersion|nu } else if (std.endsWith('++98')) { return is_gnu ? 'gnu++98' : 'c++98'; } else { - return null; + return undefined; } } -function parseCStandard(std: string, can_use_gnu: boolean): StandardVersion|null { +function parseCStandard(std: string, can_use_gnu: boolean): StandardVersion | undefined { // GNU options from: https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options const is_gnu = can_use_gnu && std.startsWith('gnu'); if (/(c|gnu)(90|89|iso9899:(1990|199409))/.test(std)) { @@ -77,7 +76,7 @@ function parseCStandard(std: string, can_use_gnu: boolean): StandardVersion|null return 'c11'; } } else { - return null; + return undefined; } } @@ -117,7 +116,7 @@ export function parseCompileFlags(cptVersion: cpt.Version, args: string[], lang? const can_use_gnu_std = (cptVersion >= cpt.Version.v4); const iter = args[Symbol.iterator](); const extraDefinitions: string[] = []; - let standard: StandardVersion = (lang === 'C') ? 'c11' : 'c++17'; + let standard: StandardVersion | undefined = undefined; let targetArch: Architecture = undefined; while (1) { const {done, value} = iter.next(); From 392b3d1ac96c8a9d45d6705fefd7b1fe94be58f2 Mon Sep 17 00:00:00 2001 From: Elaheh Rashedi Date: Mon, 15 Mar 2021 09:49:38 -0700 Subject: [PATCH 2/6] minor fixes --- src/cpptools.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpptools.ts b/src/cpptools.ts index e5f2afb20..9ce6a2aa9 100644 --- a/src/cpptools.ts +++ b/src/cpptools.ts @@ -27,7 +27,7 @@ type StandardVersion = "c89" | "c99" | "c11" | "c17" | "c++98" | "c++03" | "c++1 export interface CompileFlagInformation { extraDefinitions: string[]; - standard: StandardVersion | undefined; + standard?: StandardVersion; targetArch: Architecture; } @@ -116,7 +116,7 @@ export function parseCompileFlags(cptVersion: cpt.Version, args: string[], lang? const can_use_gnu_std = (cptVersion >= cpt.Version.v4); const iter = args[Symbol.iterator](); const extraDefinitions: string[] = []; - let standard: StandardVersion | undefined = undefined; + let standard: StandardVersion | undefined; let targetArch: Architecture = undefined; while (1) { const {done, value} = iter.next(); From b0c01171d2ae4102468fe3b729bd2c836ac41b61 Mon Sep 17 00:00:00 2001 From: Elaheh Rashedi Date: Mon, 15 Mar 2021 10:00:32 -0700 Subject: [PATCH 3/6] check for null and undefined both --- src/cpptools.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cpptools.ts b/src/cpptools.ts index 9ce6a2aa9..052cfd81e 100644 --- a/src/cpptools.ts +++ b/src/cpptools.ts @@ -166,14 +166,14 @@ export function parseCompileFlags(cptVersion: cpt.Version, args: string[], lang? const std = value.substring(5); if (lang === 'CXX' || lang === 'OBJCXX' || lang === 'CUDA' ) { const s = parseCppStandard(std, can_use_gnu_std); - if (s === null) { + if (!s) { log.warning(localize('unknown.control.gflag.cpp', 'Unknown C++ standard control flag: {0}', value)); } else { standard = s; } } else if (lang === 'C' || lang === 'OBJC' ) { const s = parseCStandard(std, can_use_gnu_std); - if (s === null) { + if (!s) { log.warning(localize('unknown.control.gflag.c', 'Unknown C standard control flag: {0}', value)); } else { standard = s; @@ -183,7 +183,7 @@ export function parseCompileFlags(cptVersion: cpt.Version, args: string[], lang? if (s === null) { s = parseCStandard(std, can_use_gnu_std); } - if (s === null) { + if (!s) { log.warning(localize('unknown.control.gflag', 'Unknown standard control flag: {0}', value)); } else { standard = s; From fb5372de6c6e440c8c255f73adfa9ff0f8033aeb Mon Sep 17 00:00:00 2001 From: Elaheh Rashedi Date: Mon, 15 Mar 2021 10:56:15 -0700 Subject: [PATCH 4/6] check for null and undefined both --- src/cpptools.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpptools.ts b/src/cpptools.ts index 052cfd81e..674c91107 100644 --- a/src/cpptools.ts +++ b/src/cpptools.ts @@ -180,7 +180,7 @@ export function parseCompileFlags(cptVersion: cpt.Version, args: string[], lang? } } else if (lang === undefined) { let s = parseCppStandard(std, can_use_gnu_std); - if (s === null) { + if (!s) { s = parseCStandard(std, can_use_gnu_std); } if (!s) { From ca91af841d9038b3f753117b9ccfa16f0d6b8688 Mon Sep 17 00:00:00 2001 From: Elaheh Rashedi Date: Mon, 15 Mar 2021 11:34:10 -0700 Subject: [PATCH 5/6] test for 'undefined' standard in compile Flags --- test/unit-tests/cpptools.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit-tests/cpptools.test.ts b/test/unit-tests/cpptools.test.ts index 99a2ca5af..578f72dfe 100644 --- a/test/unit-tests/cpptools.test.ts +++ b/test/unit-tests/cpptools.test.ts @@ -27,7 +27,7 @@ suite('CppTools tests', () => { expect(info.extraDefinitions).to.eql(['FOO=BAR']); info = parseCompileFlags(cpptoolsVersion4, ['-DFOO=BAR', '/D', 'BAZ=QUX']); expect(info.extraDefinitions).to.eql(['FOO=BAR', 'BAZ=QUX']); - expect(info.standard).to.eql('c++17'); + expect(info.standard).to.eql(undefined); // Parse language standard info = parseCompileFlags(cpptoolsVersion4, ['-std=c++03']); expect(info.standard).to.eql('c++03'); From fb9342daffbd6253fdc515599f71bb0b12c7bed6 Mon Sep 17 00:00:00 2001 From: Elaheh Rashedi Date: Tue, 16 Mar 2021 10:54:44 -0700 Subject: [PATCH 6/6] remove line --- src/cpptools.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpptools.ts b/src/cpptools.ts index 674c91107..a37b85f10 100644 --- a/src/cpptools.ts +++ b/src/cpptools.ts @@ -22,8 +22,8 @@ const localize: nls.LocalizeFunc = nls.loadMessageBundle(); const log = createLogger('cpptools'); type Architecture = 'x86' | 'x64' | 'arm' | 'arm64' | undefined; -type StandardVersion = "c89" | "c99" | "c11" | "c17" | "c++98" | "c++03" | "c++11" | "c++14" | "c++17" | "c++20" | "gnu89" | "gnu99" | "gnu11" | "gnu17" | "gnu++98" | "gnu++03" | "gnu++11" | "gnu++14" | "gnu++17" | "gnu++20"; - +type StandardVersion = "c89" | "c99" | "c11" | "c17" | "c++98" | "c++03" | "c++11" | "c++14" | "c++17" | "c++20" + | "gnu89" | "gnu99" | "gnu11" | "gnu17" | "gnu++98" | "gnu++03" | "gnu++11" | "gnu++14" | "gnu++17" | "gnu++20"; export interface CompileFlagInformation { extraDefinitions: string[];