From 3f48e1c0d84bf4909954154ad147559656e87516 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 19 Jul 2017 09:36:35 -0700 Subject: 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. --- source/slang/lexer.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source/slang/lexer.cpp') 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(); } -- cgit v1.2.3