summaryrefslogtreecommitdiffstats
path: root/source/core/slang-common.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-10-04 14:15:51 -0400
committerGitHub <noreply@github.com>2021-10-04 14:15:51 -0400
commit97bb82ebcdf8f1391b9d93b5a8d7b1dfc4e88e52 (patch)
treef120ba282cbea96d23ed179737984a4610d3b520 /source/core/slang-common.h
parentb3dfe383c6d31ff3dbd76dcfb32de8d536382f3e (diff)
Removing exceptions from core/compiler-core (#1953)
* #include an absolute path didn't work - because paths were taken to always be relative. * Refactor Stream. Working on all tests. * Split out CharEncode. * Make method names lower camel. m_prefix in Writer/Reader * Tidy up around CharEncode interface. * Small improvements around encode/decode. * Better use of types. * Remove readLine from TextReader. * Remove exceptions from Stream/Text handling. * Fix some typos. * Fix tabbing. * Fix missing override. * Remove remaining exception throw/catch via using signal mechanism. * Remove exceptions that are not used anymore. * Document the Stream interface. * Remove index for decoding 'get byte' function. * Fix CharReader -> ByteReader.
Diffstat (limited to 'source/core/slang-common.h')
-rw-r--r--source/core/slang-common.h50
1 files changed, 24 insertions, 26 deletions
diff --git a/source/core/slang-common.h b/source/core/slang-common.h
index 717b63740..eb6502b41 100644
--- a/source/core/slang-common.h
+++ b/source/core/slang-common.h
@@ -7,11 +7,7 @@
#include <stdint.h>
-#ifdef __GNUC__
-#define CORE_LIB_ALIGN_16(x) x __attribute__((aligned(16)))
-#else
-#define CORE_LIB_ALIGN_16(x) __declspec(align(16)) x
-#endif
+#include "slang-signal.h"
#define VARIADIC_TEMPLATE
@@ -27,13 +23,33 @@ namespace Slang
typedef SlangUInt UInt;
typedef SlangInt Int;
+ static const UInt kMaxUInt = ~UInt(0);
+ static const Int kMaxInt = Int(kMaxUInt >> 1);
+
// typedef unsigned short Word;
typedef intptr_t PtrInt;
+ // TODO(JS): It looks like Index is actually 64 bit on 64 bit targets(!)
+ // Previous discussions landed on Index being int32_t.
+
// Type used for indexing, in arrays/views etc
typedef Int Index;
+ static const Index kMaxIndex = kMaxInt;
+
+ typedef uint8_t Byte;
+
+ // TODO(JS):
+ // Perhaps these should be named Utf8, Utf16 and UnicodePoint/Rune/etc? For now, just keep it simple
+ //
+ typedef char Char8;
+ // 16 bit character. Note much like in utf8, a character may or may not represent a code point (it can be part of a code point).
+ typedef uint16_t Char16;
+
+ // Can always hold a unicode code point.
+ typedef uint32_t Char32;
+
template <typename T>
inline T&& _Move(T & obj)
{
@@ -48,15 +64,7 @@ namespace Slang
v1 = _Move(tmp);
}
-#ifdef _MSC_VER
-# define SLANG_RETURN_NEVER __declspec(noreturn)
-//#elif SLANG_CLANG
-//# define SLANG_RETURN_NEVER [[noreturn]]
-#else
-# define SLANG_RETURN_NEVER [[noreturn]]
-//# define SLANG_RETURN_NEVER /* empty */
-#endif
-
+// TODO: Shouldn't these be SLANG_ prefixed?
#ifdef _MSC_VER
#define UNREACHABLE_RETURN(x)
#define UNREACHABLE(x)
@@ -65,27 +73,17 @@ namespace Slang
#define UNREACHABLE(x) x;
#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_EXPECT(VALUE, MSG) if(VALUE) {} else SLANG_ASSERT_FAILURE(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_ASSERT(VALUE) if(VALUE) {} else SLANG_ASSERT_FAILURE(#VALUE)
#define SLANG_RELEASE_EXPECT(VALUE, WHAT) if(VALUE) {} else SLANG_UNEXPECTED(WHAT)
template<typename T> void slang_use_obj(T&) {}