summaryrefslogtreecommitdiff
path: root/source/slang/lexer.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-07-19 09:36:35 -0700
committerTim Foley <tfoley@nvidia.com>2017-07-19 18:15:37 -0700
commit3f48e1c0d84bf4909954154ad147559656e87516 (patch)
tree0b93a109d51e6565560ad785519a863386490e2a /source/slang/lexer.cpp
parenta2b8b4c20632d79721052abd232fe2d1bdf2700d (diff)
Try to improve handling of failures during compilation
The change is mostly about trying to make sure the compiler "fails safe" when it encounters an internal assumption that isn't met. Most internal errors will now throw exceptions (yes, exceptions are evil, but this will work for now), and these get caught in `spCompile` so that they don't propagate to the user (they just see a message that compilation aborted due to an internal error). Subsequent changes are going to need to work on diagnosing as many of these situations as possible, so that users can at least know what construct in their code was unexpected or unhandled by the compiler.
Diffstat (limited to 'source/slang/lexer.cpp')
-rw-r--r--source/slang/lexer.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/source/slang/lexer.cpp b/source/slang/lexer.cpp
index d8211fb20..49856c1c9 100644
--- a/source/slang/lexer.cpp
+++ b/source/slang/lexer.cpp
@@ -11,14 +11,14 @@ namespace Slang
Token* TokenList::begin() const
{
- assert(mTokens.Count());
+ SLANG_ASSERT(mTokens.Count());
return &mTokens[0];
}
Token* TokenList::end() const
{
- assert(mTokens.Count());
- assert(mTokens[mTokens.Count()-1].Type == TokenType::EndOfFile);
+ SLANG_ASSERT(mTokens.Count());
+ SLANG_ASSERT(mTokens[mTokens.Count()-1].Type == TokenType::EndOfFile);
return &mTokens[mTokens.Count() - 1];
}
@@ -48,7 +48,7 @@ namespace Slang
{
if (mCursor == mEnd)
return TokenType::EndOfFile;
- assert(mCursor);
+ SLANG_ASSERT(mCursor);
return mCursor->Type;
}
@@ -56,7 +56,7 @@ namespace Slang
{
if (!mCursor)
return CodePosition();
- assert(mCursor);
+ SLANG_ASSERT(mCursor);
return mCursor->Position;
}
@@ -135,7 +135,7 @@ namespace Slang
//
static void handleNewLineInner(Lexer* lexer, int c)
{
- assert(c == '\n' || c == '\r');
+ SLANG_ASSERT(c == '\n' || c == '\r');
int d = peekRaw(lexer);
if( (c ^ d) == ('\n' ^ '\r') )
@@ -774,26 +774,26 @@ namespace Slang
String getStringLiteralTokenValue(Token const& token)
{
- assert(token.Type == TokenType::StringLiteral
+ SLANG_ASSERT(token.Type == TokenType::StringLiteral
|| token.Type == TokenType::CharLiteral);
char const* cursor = token.Content.begin();
char const* end = token.Content.end();
auto quote = *cursor++;
- assert(quote == '\'' || quote == '"');
+ SLANG_ASSERT(quote == '\'' || quote == '"');
StringBuilder valueBuilder;
for(;;)
{
- assert(cursor != end);
+ SLANG_ASSERT(cursor != end);
auto c = *cursor++;
// If we see a closing quote, then we are at the end of the string literal
if(c == quote)
{
- assert(cursor == end);
+ SLANG_ASSERT(cursor == end);
return valueBuilder.ProduceString();
}