HLSL: Fix a grammar error related to constructors in parenthetical expressions
This commit is contained in:
@@ -1718,27 +1718,29 @@ bool HlslGrammar::acceptUnaryExpression(TIntermTyped*& node)
|
||||
if (acceptTokenClass(EHTokLeftParen)) {
|
||||
TType castType;
|
||||
if (acceptType(castType)) {
|
||||
if (! acceptTokenClass(EHTokRightParen)) {
|
||||
expected(")");
|
||||
return false;
|
||||
if (acceptTokenClass(EHTokRightParen)) {
|
||||
// We've matched "(type)" now, get the expression to cast
|
||||
TSourceLoc loc = token.loc;
|
||||
if (! acceptUnaryExpression(node))
|
||||
return false;
|
||||
|
||||
// Hook it up like a constructor
|
||||
TFunction* constructorFunction = parseContext.handleConstructorCall(loc, castType);
|
||||
if (constructorFunction == nullptr) {
|
||||
expected("type that can be constructed");
|
||||
return false;
|
||||
}
|
||||
TIntermTyped* arguments = nullptr;
|
||||
parseContext.handleFunctionArgument(constructorFunction, arguments, node);
|
||||
node = parseContext.handleFunctionCall(loc, constructorFunction, arguments);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
// This could be a parenthesized constructor, ala (int(3)), and we just accepted
|
||||
// the '(int' part. We must back up twice.
|
||||
recedeToken();
|
||||
recedeToken();
|
||||
}
|
||||
|
||||
// We've matched "(type)" now, get the expression to cast
|
||||
TSourceLoc loc = token.loc;
|
||||
if (! acceptUnaryExpression(node))
|
||||
return false;
|
||||
|
||||
// Hook it up like a constructor
|
||||
TFunction* constructorFunction = parseContext.handleConstructorCall(loc, castType);
|
||||
if (constructorFunction == nullptr) {
|
||||
expected("type that can be constructed");
|
||||
return false;
|
||||
}
|
||||
TIntermTyped* arguments = nullptr;
|
||||
parseContext.handleFunctionArgument(constructorFunction, arguments, node);
|
||||
node = parseContext.handleFunctionCall(loc, constructorFunction, arguments);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
// This isn't a type cast, but it still started "(", so if it is a
|
||||
// unary expression, it can only be a postfix_expression, so try that.
|
||||
|
||||
@@ -39,27 +39,29 @@ namespace glslang {
|
||||
|
||||
void HlslTokenStream::pushPreToken(const HlslToken& tok)
|
||||
{
|
||||
assert(preTokenStackSize == 0);
|
||||
preTokenStack = tok;
|
||||
++preTokenStackSize;
|
||||
assert(preTokenStackSize < tokenBufferSize);
|
||||
preTokenStack[preTokenStackSize++] = tok;
|
||||
}
|
||||
|
||||
HlslToken HlslTokenStream::popPreToken()
|
||||
{
|
||||
assert(preTokenStackSize == 1);
|
||||
--preTokenStackSize;
|
||||
assert(preTokenStackSize > 0);
|
||||
|
||||
return preTokenStack;
|
||||
return preTokenStack[--preTokenStackSize];
|
||||
}
|
||||
|
||||
void HlslTokenStream::pushTokenBuffer(const HlslToken& tok)
|
||||
{
|
||||
tokenBuffer = tok;
|
||||
tokenBuffer[tokenBufferPos] = tok;
|
||||
tokenBufferPos = (tokenBufferPos+1) % tokenBufferSize;
|
||||
}
|
||||
|
||||
HlslToken HlslTokenStream::popTokenBuffer()
|
||||
{
|
||||
return tokenBuffer;
|
||||
// Back up
|
||||
tokenBufferPos = (tokenBufferPos+tokenBufferSize-1) % tokenBufferSize;
|
||||
|
||||
return tokenBuffer[tokenBufferPos];
|
||||
}
|
||||
|
||||
// Load 'token' with the next token in the stream of tokens.
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace glslang {
|
||||
class HlslTokenStream {
|
||||
public:
|
||||
explicit HlslTokenStream(HlslScanContext& scanner)
|
||||
: scanner(scanner), preTokenStackSize(0) { }
|
||||
: scanner(scanner), preTokenStackSize(0), tokenBufferPos(0) { }
|
||||
virtual ~HlslTokenStream() { }
|
||||
|
||||
public:
|
||||
@@ -62,20 +62,24 @@ namespace glslang {
|
||||
|
||||
HlslScanContext& scanner; // lexical scanner, to get next token
|
||||
|
||||
// This is the number of tokens we can recedeToken() over.
|
||||
static const int tokenBufferSize = 2;
|
||||
|
||||
// Previously scanned tokens, returned for future advances,
|
||||
// so logically in front of the token stream.
|
||||
// Is logically a stack; needs last in last out semantics.
|
||||
// Currently implemented as a stack of size 1.
|
||||
HlslToken preTokenStack;
|
||||
// Currently implemented as a stack of size 2.
|
||||
HlslToken preTokenStack[tokenBufferSize];
|
||||
int preTokenStackSize;
|
||||
void pushPreToken(const HlslToken&);
|
||||
HlslToken popPreToken();
|
||||
|
||||
// Previously scanned tokens, not yet return for future advances,
|
||||
// Previously scanned tokens, not yet returned for future advances,
|
||||
// but available for that.
|
||||
// Is logically a fifo for normal advances, and a stack for recession.
|
||||
// Currently implemented with an intrinsic size of 1.
|
||||
HlslToken tokenBuffer;
|
||||
// Currently implemented with an intrinsic size of 2.
|
||||
HlslToken tokenBuffer[tokenBufferSize];
|
||||
int tokenBufferPos;
|
||||
void pushTokenBuffer(const HlslToken&);
|
||||
HlslToken popTokenBuffer();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user