diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2024-04-30 10:47:10 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-30 10:47:10 -0700 |
| commit | 492f56e02fe9e9902eabefaa34f5b2fc9778dd47 (patch) | |
| tree | 7bbef87fd9b0b117f01a1d34227bbd02f227f783 | |
| parent | f1221b80c3c5f59ed533147825ea414bef5e9df2 (diff) | |
Add option -disable-short-circuit (#4054)
Add option -disable-short-circuit to disable short circuit for logic
operators && and ||. Also, disable the short circuit by default in the
stdlib.
| -rw-r--r-- | slang.h | 1 | ||||
| -rw-r--r-- | source/slang/slang-check-impl.h | 8 | ||||
| -rw-r--r-- | source/slang/slang-options.cpp | 6 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 1 |
4 files changed, 15 insertions, 1 deletions
@@ -860,6 +860,7 @@ extern "C" SourceEmbedStyle, SourceEmbedName, SourceEmbedLanguage, + DisableShortCircuit, // bool // Target diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h index f0c6d693d..d90c3c4b0 100644 --- a/source/slang/slang-check-impl.h +++ b/source/slang/slang-check-impl.h @@ -798,7 +798,13 @@ namespace Slang : m_shared(shared) , m_sink(shared->getSink()) , m_astBuilder(shared->getLinkage()->getASTBuilder()) - {} + { + if (shared->getLinkage()->m_optionSet.hasOption(CompilerOptionName::DisableShortCircuit)) + { + m_shouldShortCircuitLogicExpr = + !shared->getLinkage()->m_optionSet.getBoolOption(CompilerOptionName::DisableShortCircuit); + } + } SharedSemanticsContext* getShared() { return m_shared; } CompilerOptionSet& getOptionSet() { return getShared()->getOptionSet(); } diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index dad69350e..7337b9210 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -343,6 +343,7 @@ void initCommandOptions(CommandOptions& options) "The name used as the basis for variables output for source embedding."}, { OptionKind::SourceEmbedLanguage, "-source-embed-language", "-source-embed-language <language>", "The language to be used for source embedding. Defaults to C/C++. Currently only C/C++ are supported"}, + { OptionKind::DisableShortCircuit, "-disable-short-circuit", nullptr, "Disable short-circuiting for \"&&\" and \"||\" operations" }, }; _addOptions(makeConstArrayView(generalOpts), options); @@ -2298,6 +2299,11 @@ SlangResult OptionsParser::_parse( break; } + case OptionKind::DisableShortCircuit: + { + linkage->m_optionSet.add(OptionKind::DisableShortCircuit, true); + break; + } default: { // Hmmm, we looked up and produced a valid enum, but it wasn't handled in the switch... diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 4a446a351..112ec2058 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -170,6 +170,7 @@ void Session::init() // Built in linkage uses the built in builder m_builtinLinkage = new Linkage(this, builtinAstBuilder, nullptr); m_builtinLinkage->m_optionSet.set(CompilerOptionName::DebugInformation, DebugInfoLevel::None); + m_builtinLinkage->m_optionSet.set(CompilerOptionName::DisableShortCircuit, true); // Because the `Session` retains the builtin `Linkage`, // we need to make sure that the parent pointer inside |
