From c3bc49624891d9799975ae4a47e598961eea8aab Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 26 Feb 2018 14:02:29 -0800 Subject: Merge from 0.9.x (#429) * Fix bug when subscripting a type that must be split (#396) The logic was creating a `PairPseudoExpr` as part of a subscript (`operator[]`) operation, but neglecting to fill in its `pairInfo` field, which led to a null-pointer crash further along. * Allow writes to UAV textures (#416) Work on #415 This issue is already fixed in the `v0.10.*` line, but I'm back-porting the fix to `v0.9.*`. The issue here was that the stdlib declarations for texture types were only including the `get` accessor for subscript operations, even if the texture was write-able. I've also included the fixes for other subscript accessors in the stdlib (notably that `OutputPatch` is readable, but not writable, despite what the name seems to imply). * Fix infinite loop in semantic parsing (#424) The code for parsing semantics was looking for a fixed set of tokens to terminate a semantic list, rather than assuming that whenever you don't see a `:` ahead, you probably are done with semantics. This meant that you could get into an infinite loop just with simple mistakes like leaving out a `;`. This change fixes the parser to note infinite loop in this case, and adds a test case to verify the fix. --- source/slang/parser.cpp | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'source/slang/parser.cpp') diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index 037268244..82f79af17 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -1863,12 +1863,18 @@ namespace Slang ParseHLSLLayoutSemantic(parser, semantic.Ptr()); return semantic; } - else + else if (parser->LookAheadToken(TokenType::Identifier)) { RefPtr semantic = new HLSLSimpleSemantic(); semantic->name = parser->ReadToken(TokenType::Identifier); return semantic; } + else + { + // expect an identifier, just to produce an error message + parser->ReadToken(TokenType::Identifier); + return nullptr; + } } // @@ -1893,20 +1899,26 @@ namespace Slang link = &semantic->next; } - switch (parser->tokenReader.PeekTokenType()) + // If we see another `:`, then that means there + // is yet another semantic to be processed. + // Otherwise we assume we are at the end of the list. + // + // TODO: This could produce sub-optimal diagnostics + // when the user *meant* to apply multiple semantics + // to a single declaration: + // + // Foo foo : register(t0) register(s0); + // ^ + // missing ':' here | + // + // However, that is an uncommon occurence, and trying + // to continue parsing semantics here even if we didn't + // see a colon forces us to be careful about + // avoiding an infinite loop here. + if (!AdvanceIf(parser, TokenType::Colon)) { - case TokenType::LBrace: - case TokenType::Semicolon: - case TokenType::Comma: - case TokenType::RParent: - case TokenType::EndOfFile: return result; - - default: - break; } - - parser->ReadToken(TokenType::Colon); } } -- cgit v1.2.3