summaryrefslogtreecommitdiffstats
path: root/source/core/common.h
diff options
context:
space:
mode:
authorTim Foley <tim.foley.is@gmail.com>2017-07-19 18:52:38 -0700
committerGitHub <noreply@github.com>2017-07-19 18:52:38 -0700
commitf07c01ceb012b9b325a8ecebd12cdd5797d8d5b3 (patch)
tree0b93a109d51e6565560ad785519a863386490e2a /source/core/common.h
parenta2b8b4c20632d79721052abd232fe2d1bdf2700d (diff)
parent3f48e1c0d84bf4909954154ad147559656e87516 (diff)
Merge pull request #128 from tfoleyNV/improve-failure-modes
Try to improve handling of failures during compilation
Diffstat (limited to 'source/core/common.h')
-rw-r--r--source/core/common.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/source/core/common.h b/source/core/common.h
index 25e85dc66..f0f6902d1 100644
--- a/source/core/common.h
+++ b/source/core/common.h
@@ -34,6 +34,35 @@ namespace Slang
v0 = _Move(v1);
v1 = _Move(tmp);
}
+
+#ifdef _MSC_VER
+#define SLANG_RETURN_NEVER __declspec(noreturn)
+#else
+#efine SLANG_RETURN_NEVER /* empty */
+#endif
+
+ SLANG_RETURN_NEVER void signalUnexpectedError(char const* message);
}
+#define SLANG_UNEXPECTED(reason) \
+ Slang::signalUnexpectedError("unexpected: " reason)
+
+#define SLANG_UNIMPLEMENTED_X(what) \
+ Slang::signalUnexpectedError("unimplemented: " what)
+
+#define SLANG_UNREACHABLE(msg) \
+ Slang::signalUnexpectedError("unreachable code executed: " msg)
+
+#ifdef _DEBUG
+#define SLANG_EXPECT(VALUE, MSG) if(VALUE) {} else Slang::signalUnexpectedError("assertion failed: '" MSG "'")
+#define SLANG_ASSERT(VALUE) SLANG_EXPECT(VALUE, #VALUE)
+#else
+#define SLANG_EXPECT(VALUE, MSG) do {} while(0)
+#define SLANG_ASSERT(VALUE) do {} while(0)
+#endif
+
+#define SLANG_RELEASE_ASSERT(VALUE) if(VALUE) {} else Slang::signalUnexpectedError("assertion failed")
+#define SLANG_RELEASE_EXPECT(VALUE, WHAT) if(VALUE) {} else SLANG_UNEXPECTED(WHAT)
+
+
#endif