2016-03-13 03:11:22 +00:00
|
|
|
//
|
|
|
|
//Copyright (C) 2016 Google, Inc.
|
2016-06-24 01:13:48 +00:00
|
|
|
//Copyright (C) 2016 LunarG, Inc.
|
2016-03-13 03:11:22 +00:00
|
|
|
//
|
|
|
|
//All rights reserved.
|
|
|
|
//
|
|
|
|
//Redistribution and use in source and binary forms, with or without
|
|
|
|
//modification, are permitted provided that the following conditions
|
|
|
|
//are met:
|
|
|
|
//
|
|
|
|
// Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
//
|
|
|
|
// Neither the name of Google, Inc., nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
//POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
|
|
|
|
2016-03-13 17:24:20 +00:00
|
|
|
//
|
|
|
|
// This is a set of mutually recursive methods implementing the HLSL grammar.
|
|
|
|
// Generally, each returns
|
|
|
|
// - through an argument: a type specifically appropriate to which rule it
|
|
|
|
// recognized
|
|
|
|
// - through the return value: true/false to indicate whether or not it
|
|
|
|
// recognized its rule
|
|
|
|
//
|
|
|
|
// As much as possible, only grammar recognition should happen in this file,
|
2016-03-14 16:02:11 +00:00
|
|
|
// with all other work being farmed out to hlslParseHelper.cpp, which in turn
|
2016-03-13 17:24:20 +00:00
|
|
|
// will build the AST.
|
|
|
|
//
|
|
|
|
// The next token, yet to be "accepted" is always sitting in 'token'.
|
|
|
|
// When a method says it accepts a rule, that means all tokens involved
|
|
|
|
// in the rule will have been consumed, and none left in 'token'.
|
|
|
|
//
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
#include "hlslTokens.h"
|
|
|
|
#include "hlslGrammar.h"
|
2016-10-20 19:07:10 +00:00
|
|
|
#include "hlslAttributes.h"
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
namespace glslang {
|
|
|
|
|
|
|
|
// Root entry point to this recursive decent parser.
|
|
|
|
// Return true if compilation unit was successfully accepted.
|
|
|
|
bool HlslGrammar::parse()
|
|
|
|
{
|
|
|
|
advanceToken();
|
|
|
|
return acceptCompilationUnit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HlslGrammar::expected(const char* syntax)
|
|
|
|
{
|
|
|
|
parseContext.error(token.loc, "Expected", syntax, "");
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:58:58 +00:00
|
|
|
void HlslGrammar::unimplemented(const char* error)
|
|
|
|
{
|
|
|
|
parseContext.error(token.loc, "Unimplemented", error, "");
|
|
|
|
}
|
|
|
|
|
2016-03-14 16:46:34 +00:00
|
|
|
// Only process the next token if it is an identifier.
|
|
|
|
// Return true if it was an identifier.
|
|
|
|
bool HlslGrammar::acceptIdentifier(HlslToken& idToken)
|
|
|
|
{
|
|
|
|
if (peekTokenClass(EHTokIdentifier)) {
|
|
|
|
idToken = token;
|
|
|
|
advanceToken();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-16 20:22:11 +00:00
|
|
|
// Even though "sample" is a keyword (for interpolation modifiers), it IS still accepted as
|
|
|
|
// an identifier. This appears to be a solitary exception: other interp modifier keywords such
|
|
|
|
// as "linear" or "centroid" NOT valid identifiers. This code special cases "sample",
|
|
|
|
// so e.g, "int sample;" is accepted.
|
|
|
|
if (peekTokenClass(EHTokSample)) {
|
2016-12-19 00:51:14 +00:00
|
|
|
token.string = NewPoolTString("sample");
|
|
|
|
token.tokenClass = EHTokIdentifier;
|
|
|
|
token.symbol = nullptr;
|
|
|
|
|
|
|
|
idToken = token;
|
2016-11-16 20:22:11 +00:00
|
|
|
advanceToken();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-14 16:46:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
// compilationUnit
|
|
|
|
// : list of externalDeclaration
|
2016-08-03 13:04:18 +00:00
|
|
|
// | SEMICOLONS
|
2016-03-13 03:11:22 +00:00
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptCompilationUnit()
|
|
|
|
{
|
2016-03-13 17:24:20 +00:00
|
|
|
TIntermNode* unitNode = nullptr;
|
|
|
|
|
2016-05-04 04:49:24 +00:00
|
|
|
while (! peekTokenClass(EHTokNone)) {
|
2016-08-03 13:04:18 +00:00
|
|
|
// HLSL allows semicolons between global declarations, e.g, between functions.
|
|
|
|
if (acceptTokenClass(EHTokSemicolon))
|
|
|
|
continue;
|
|
|
|
|
2016-03-13 17:24:20 +00:00
|
|
|
// externalDeclaration
|
|
|
|
TIntermNode* declarationNode;
|
|
|
|
if (! acceptDeclaration(declarationNode))
|
2016-03-13 03:11:22 +00:00
|
|
|
return false;
|
2016-03-13 17:24:20 +00:00
|
|
|
|
|
|
|
// hook it up
|
2016-03-14 16:02:11 +00:00
|
|
|
unitNode = intermediate.growAggregate(unitNode, declarationNode);
|
2016-03-13 03:11:22 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 17:24:20 +00:00
|
|
|
// set root of AST
|
2016-03-14 16:02:11 +00:00
|
|
|
intermediate.setTreeRoot(unitNode);
|
2016-03-13 17:24:20 +00:00
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:58:58 +00:00
|
|
|
// sampler_state
|
|
|
|
// : LEFT_BRACE [sampler_state_assignment ... ] RIGHT_BRACE
|
|
|
|
//
|
|
|
|
// sampler_state_assignment
|
|
|
|
// : sampler_state_identifier EQUAL value SEMICOLON
|
|
|
|
//
|
|
|
|
// sampler_state_identifier
|
|
|
|
// : ADDRESSU
|
|
|
|
// | ADDRESSV
|
|
|
|
// | ADDRESSW
|
|
|
|
// | BORDERCOLOR
|
|
|
|
// | FILTER
|
|
|
|
// | MAXANISOTROPY
|
|
|
|
// | MAXLOD
|
|
|
|
// | MINLOD
|
|
|
|
// | MIPLODBIAS
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptSamplerState()
|
|
|
|
{
|
|
|
|
// TODO: this should be genericized to accept a list of valid tokens and
|
|
|
|
// return token/value pairs. Presently it is specific to texture values.
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokLeftBrace))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
parseContext.warn(token.loc, "unimplemented", "immediate sampler state", "");
|
|
|
|
|
|
|
|
do {
|
|
|
|
// read state name
|
|
|
|
HlslToken state;
|
|
|
|
if (! acceptIdentifier(state))
|
|
|
|
break; // end of list
|
|
|
|
|
|
|
|
// FXC accepts any case
|
|
|
|
TString stateName = *state.string;
|
|
|
|
std::transform(stateName.begin(), stateName.end(), stateName.begin(), ::tolower);
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokAssign)) {
|
|
|
|
expected("assign");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stateName == "minlod" || stateName == "maxlod") {
|
|
|
|
if (! peekTokenClass(EHTokIntConstant)) {
|
|
|
|
expected("integer");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TIntermTyped* lod = nullptr;
|
|
|
|
if (! acceptLiteral(lod)) // should never fail, since we just looked for an integer
|
|
|
|
return false;
|
|
|
|
} else if (stateName == "maxanisotropy") {
|
|
|
|
if (! peekTokenClass(EHTokIntConstant)) {
|
|
|
|
expected("integer");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TIntermTyped* maxAnisotropy = nullptr;
|
|
|
|
if (! acceptLiteral(maxAnisotropy)) // should never fail, since we just looked for an integer
|
|
|
|
return false;
|
|
|
|
} else if (stateName == "filter") {
|
|
|
|
HlslToken filterMode;
|
|
|
|
if (! acceptIdentifier(filterMode)) {
|
|
|
|
expected("filter mode");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (stateName == "addressu" || stateName == "addressv" || stateName == "addressw") {
|
|
|
|
HlslToken addrMode;
|
|
|
|
if (! acceptIdentifier(addrMode)) {
|
|
|
|
expected("texture address mode");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (stateName == "miplodbias") {
|
|
|
|
TIntermTyped* lodBias = nullptr;
|
|
|
|
if (! acceptLiteral(lodBias)) {
|
|
|
|
expected("lod bias");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (stateName == "bordercolor") {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
expected("texture state");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// SEMICOLON
|
|
|
|
if (! acceptTokenClass(EHTokSemicolon)) {
|
|
|
|
expected("semicolon");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} while (true);
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokRightBrace))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// sampler_declaration_dx9
|
|
|
|
// : SAMPLER identifier EQUAL sampler_type sampler_state
|
|
|
|
//
|
2016-07-16 16:19:43 +00:00
|
|
|
bool HlslGrammar::acceptSamplerDeclarationDX9(TType& /*type*/)
|
2016-06-29 16:58:58 +00:00
|
|
|
{
|
|
|
|
if (! acceptTokenClass(EHTokSampler))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// TODO: remove this when DX9 style declarations are implemented.
|
|
|
|
unimplemented("Direct3D 9 sampler declaration");
|
|
|
|
|
|
|
|
// read sampler name
|
|
|
|
HlslToken name;
|
|
|
|
if (! acceptIdentifier(name)) {
|
|
|
|
expected("sampler name");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokAssign)) {
|
|
|
|
expected("=");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
// declaration
|
2016-06-29 16:58:58 +00:00
|
|
|
// : sampler_declaration_dx9 post_decls SEMICOLON
|
|
|
|
// | fully_specified_type declarator_list SEMICOLON
|
2016-06-13 05:52:12 +00:00
|
|
|
// | fully_specified_type identifier function_parameters post_decls compound_statement // function definition
|
2016-06-29 16:58:58 +00:00
|
|
|
// | fully_specified_type identifier sampler_state post_decls compound_statement // sampler definition
|
2016-07-05 06:02:40 +00:00
|
|
|
// | typedef declaration
|
2016-03-13 03:24:24 +00:00
|
|
|
//
|
2016-07-04 23:32:45 +00:00
|
|
|
// declarator_list
|
|
|
|
// : declarator COMMA declarator COMMA declarator... // zero or more declarators
|
2016-07-02 01:06:44 +00:00
|
|
|
//
|
2016-07-04 23:32:45 +00:00
|
|
|
// declarator
|
2016-07-02 01:06:44 +00:00
|
|
|
// : identifier array_specifier post_decls
|
|
|
|
// | identifier array_specifier post_decls EQUAL assignment_expression
|
2016-07-04 23:32:45 +00:00
|
|
|
// | identifier function_parameters post_decls // function prototype
|
2016-07-02 01:06:44 +00:00
|
|
|
//
|
2016-07-04 23:32:45 +00:00
|
|
|
// Parsing has to go pretty far in to know whether it's a variable, prototype, or
|
|
|
|
// function definition, so the implementation below doesn't perfectly divide up the grammar
|
2016-07-02 01:06:44 +00:00
|
|
|
// as above. (The 'identifier' in the first item in init_declarator list is the
|
|
|
|
// same as 'identifier' for function declarations.)
|
|
|
|
//
|
|
|
|
// 'node' could get populated if the declaration creates code, like an initializer
|
2016-03-13 17:24:20 +00:00
|
|
|
// or a function body.
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptDeclaration(TIntermNode*& node)
|
2016-03-13 03:11:22 +00:00
|
|
|
{
|
2016-03-13 17:24:20 +00:00
|
|
|
node = nullptr;
|
2016-07-04 23:32:45 +00:00
|
|
|
bool list = false;
|
2016-03-13 17:24:20 +00:00
|
|
|
|
2016-10-20 19:07:10 +00:00
|
|
|
// attributes
|
|
|
|
TAttributeMap attributes;
|
|
|
|
acceptAttributes(attributes);
|
|
|
|
|
2016-07-05 06:02:40 +00:00
|
|
|
// typedef
|
|
|
|
bool typedefDecl = acceptTokenClass(EHTokTypedef);
|
|
|
|
|
2016-09-27 20:38:57 +00:00
|
|
|
TType declaredType;
|
2016-06-29 16:58:58 +00:00
|
|
|
|
|
|
|
// DX9 sampler declaration use a different syntax
|
2016-08-05 23:34:34 +00:00
|
|
|
// DX9 shaders need to run through HLSL compiler (fxc) via a back compat mode, it isn't going to
|
|
|
|
// be possible to simultaneously compile D3D10+ style shaders and DX9 shaders. If we want to compile DX9
|
|
|
|
// HLSL shaders, this will have to be a master level switch
|
|
|
|
// As such, the sampler keyword in D3D10+ turns into an automatic sampler type, and is commonly used
|
|
|
|
// For that reason, this line is commented out
|
2016-08-05 18:52:38 +00:00
|
|
|
|
2016-09-27 20:38:57 +00:00
|
|
|
// if (acceptSamplerDeclarationDX9(declaredType))
|
2016-08-05 18:52:38 +00:00
|
|
|
// return true;
|
2016-06-29 16:58:58 +00:00
|
|
|
|
|
|
|
// fully_specified_type
|
2016-09-27 20:38:57 +00:00
|
|
|
if (! acceptFullySpecifiedType(declaredType))
|
2016-03-13 03:24:24 +00:00
|
|
|
return false;
|
2016-06-29 16:58:58 +00:00
|
|
|
|
2016-03-13 03:24:24 +00:00
|
|
|
// identifier
|
2016-03-14 16:46:34 +00:00
|
|
|
HlslToken idToken;
|
2016-07-04 23:32:45 +00:00
|
|
|
while (acceptIdentifier(idToken)) {
|
2016-10-31 21:13:43 +00:00
|
|
|
TString* fnName = idToken.string;
|
|
|
|
|
|
|
|
// Potentially rename shader entry point function. No-op most of the time.
|
|
|
|
parseContext.renameShaderFunction(fnName);
|
|
|
|
|
2016-07-04 23:32:45 +00:00
|
|
|
// function_parameters
|
2016-10-31 21:13:43 +00:00
|
|
|
TFunction& function = *new TFunction(fnName, declaredType);
|
2016-09-03 02:05:19 +00:00
|
|
|
if (acceptFunctionParameters(function)) {
|
2016-07-04 23:32:45 +00:00
|
|
|
// post_decls
|
2016-09-05 18:40:06 +00:00
|
|
|
acceptPostDecls(function.getWritableType().getQualifier());
|
2016-06-19 17:50:34 +00:00
|
|
|
|
2016-07-04 23:32:45 +00:00
|
|
|
// compound_statement (function body definition) or just a prototype?
|
|
|
|
if (peekTokenClass(EHTokLeftBrace)) {
|
|
|
|
if (list)
|
|
|
|
parseContext.error(idToken.loc, "function body can't be in a declarator list", "{", "");
|
2016-07-05 06:02:40 +00:00
|
|
|
if (typedefDecl)
|
|
|
|
parseContext.error(idToken.loc, "function body can't be in a typedef", "{", "");
|
2016-10-20 19:07:10 +00:00
|
|
|
return acceptFunctionDefinition(function, node, attributes);
|
2016-07-05 06:02:40 +00:00
|
|
|
} else {
|
|
|
|
if (typedefDecl)
|
|
|
|
parseContext.error(idToken.loc, "function typedefs not implemented", "{", "");
|
2016-09-03 02:05:19 +00:00
|
|
|
parseContext.handleFunctionDeclarator(idToken.loc, function, true);
|
2016-07-05 06:02:40 +00:00
|
|
|
}
|
2016-07-04 23:32:45 +00:00
|
|
|
} else {
|
2016-09-28 01:13:05 +00:00
|
|
|
// A variable declaration. Fix the storage qualifier if it's a global.
|
|
|
|
if (declaredType.getQualifier().storage == EvqTemporary && parseContext.symbolTable.atGlobalLevel())
|
|
|
|
declaredType.getQualifier().storage = EvqUniform;
|
|
|
|
|
2016-09-27 20:38:57 +00:00
|
|
|
// We can handle multiple variables per type declaration, so
|
|
|
|
// the number of types can expand when arrayness is different.
|
|
|
|
TType variableType;
|
|
|
|
variableType.shallowCopy(declaredType);
|
2016-06-19 17:50:34 +00:00
|
|
|
|
2016-09-27 20:38:57 +00:00
|
|
|
// recognize array_specifier
|
2016-07-04 23:32:45 +00:00
|
|
|
TArraySizes* arraySizes = nullptr;
|
|
|
|
acceptArraySpecifier(arraySizes);
|
2016-03-13 03:24:24 +00:00
|
|
|
|
2016-09-27 20:38:57 +00:00
|
|
|
// Fix arrayness in the variableType
|
|
|
|
if (declaredType.isImplicitlySizedArray()) {
|
|
|
|
// Because "int[] a = int[2](...), b = int[3](...)" makes two arrays a and b
|
|
|
|
// of different sizes, for this case sharing the shallow copy of arrayness
|
|
|
|
// with the parseType oversubscribes it, so get a deep copy of the arrayness.
|
|
|
|
variableType.newArraySizes(declaredType.getArraySizes());
|
|
|
|
}
|
|
|
|
if (arraySizes || variableType.isArray()) {
|
|
|
|
// In the most general case, arrayness is potentially coming both from the
|
|
|
|
// declared type and from the variable: "int[] a[];" or just one or the other.
|
|
|
|
// Merge it all to the variableType, so all arrayness is part of the variableType.
|
|
|
|
parseContext.arrayDimMerge(variableType, arraySizes);
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:58:58 +00:00
|
|
|
// samplers accept immediate sampler state
|
2016-09-27 20:38:57 +00:00
|
|
|
if (variableType.getBasicType() == EbtSampler) {
|
2016-06-29 16:58:58 +00:00
|
|
|
if (! acceptSamplerState())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-04 23:32:45 +00:00
|
|
|
// post_decls
|
2016-09-27 20:38:57 +00:00
|
|
|
acceptPostDecls(variableType.getQualifier());
|
2016-07-02 01:06:44 +00:00
|
|
|
|
2016-07-04 23:32:45 +00:00
|
|
|
// EQUAL assignment_expression
|
|
|
|
TIntermTyped* expressionNode = nullptr;
|
|
|
|
if (acceptTokenClass(EHTokAssign)) {
|
2016-07-05 06:02:40 +00:00
|
|
|
if (typedefDecl)
|
|
|
|
parseContext.error(idToken.loc, "can't have an initializer", "typedef", "");
|
2016-07-04 23:32:45 +00:00
|
|
|
if (! acceptAssignmentExpression(expressionNode)) {
|
|
|
|
expected("initializer");
|
2016-07-02 01:06:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-04 23:32:45 +00:00
|
|
|
}
|
2016-07-02 01:06:44 +00:00
|
|
|
|
2016-09-28 01:13:05 +00:00
|
|
|
// Hand off the actual declaration
|
|
|
|
|
|
|
|
// TODO: things scoped within an annotation need their own name space;
|
|
|
|
// TODO: strings are not yet handled.
|
|
|
|
if (variableType.getBasicType() != EbtString && parseContext.getAnnotationNestingLevel() == 0) {
|
|
|
|
if (typedefDecl)
|
|
|
|
parseContext.declareTypedef(idToken.loc, *idToken.string, variableType);
|
|
|
|
else if (variableType.getBasicType() == EbtBlock)
|
|
|
|
parseContext.declareBlock(idToken.loc, variableType, idToken.string);
|
|
|
|
else {
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
if (variableType.getQualifier().storage == EvqUniform && ! variableType.containsOpaque()) {
|
2016-09-28 01:13:05 +00:00
|
|
|
// this isn't really an individual variable, but a member of the $Global buffer
|
|
|
|
parseContext.growGlobalUniformBlock(idToken.loc, variableType, *idToken.string);
|
|
|
|
} else {
|
|
|
|
// Declare the variable and add any initializer code to the AST.
|
|
|
|
// The top-level node is always made into an aggregate, as that's
|
|
|
|
// historically how the AST has been.
|
|
|
|
node = intermediate.growAggregate(node,
|
|
|
|
parseContext.declareVariable(idToken.loc, *idToken.string, variableType,
|
|
|
|
expressionNode),
|
|
|
|
idToken.loc);
|
|
|
|
}
|
|
|
|
}
|
2016-07-05 06:02:40 +00:00
|
|
|
}
|
2016-07-02 01:06:44 +00:00
|
|
|
}
|
|
|
|
|
2016-07-04 23:32:45 +00:00
|
|
|
if (acceptTokenClass(EHTokComma)) {
|
|
|
|
list = true;
|
|
|
|
continue;
|
2016-03-13 03:24:24 +00:00
|
|
|
}
|
2016-07-04 23:32:45 +00:00
|
|
|
};
|
2016-03-13 23:58:25 +00:00
|
|
|
|
2016-07-04 23:32:45 +00:00
|
|
|
// The top-level node is a sequence.
|
|
|
|
if (node != nullptr)
|
|
|
|
node->getAsAggregate()->setOperator(EOpSequence);
|
2016-03-13 03:24:24 +00:00
|
|
|
|
2016-03-14 16:02:11 +00:00
|
|
|
// SEMICOLON
|
2016-07-04 23:32:45 +00:00
|
|
|
if (! acceptTokenClass(EHTokSemicolon)) {
|
|
|
|
expected(";");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-13 03:24:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-20 07:22:38 +00:00
|
|
|
// control_declaration
|
|
|
|
// : fully_specified_type identifier EQUAL expression
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptControlDeclaration(TIntermNode*& node)
|
|
|
|
{
|
|
|
|
node = nullptr;
|
|
|
|
|
|
|
|
// fully_specified_type
|
|
|
|
TType type;
|
|
|
|
if (! acceptFullySpecifiedType(type))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// identifier
|
|
|
|
HlslToken idToken;
|
|
|
|
if (! acceptIdentifier(idToken)) {
|
|
|
|
expected("identifier");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// EQUAL
|
|
|
|
TIntermTyped* expressionNode = nullptr;
|
|
|
|
if (! acceptTokenClass(EHTokAssign)) {
|
|
|
|
expected("=");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// expression
|
|
|
|
if (! acceptExpression(expressionNode)) {
|
|
|
|
expected("initializer");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-27 20:38:57 +00:00
|
|
|
node = parseContext.declareVariable(idToken.loc, *idToken.string, type, expressionNode);
|
2016-06-20 07:22:38 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-13 03:24:24 +00:00
|
|
|
// fully_specified_type
|
|
|
|
// : type_specifier
|
|
|
|
// | type_qualifier type_specifier
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptFullySpecifiedType(TType& type)
|
|
|
|
{
|
|
|
|
// type_qualifier
|
|
|
|
TQualifier qualifier;
|
|
|
|
qualifier.clear();
|
2016-08-17 16:22:08 +00:00
|
|
|
if (! acceptQualifier(qualifier))
|
|
|
|
return false;
|
2016-07-25 22:05:33 +00:00
|
|
|
TSourceLoc loc = token.loc;
|
2016-03-13 03:24:24 +00:00
|
|
|
|
|
|
|
// type_specifier
|
2016-12-19 00:51:14 +00:00
|
|
|
if (! acceptType(type)) {
|
|
|
|
// If this is not a type, we may have inadvertently gone down a wrong path
|
|
|
|
// py parsing "sample", which can be treated like either an identifier or a
|
|
|
|
// qualifier. Back it out, if we did.
|
|
|
|
if (qualifier.sample)
|
|
|
|
recedeToken();
|
|
|
|
|
2016-03-13 03:24:24 +00:00
|
|
|
return false;
|
2016-12-19 00:51:14 +00:00
|
|
|
}
|
2016-07-25 22:05:33 +00:00
|
|
|
if (type.getBasicType() == EbtBlock) {
|
|
|
|
// the type was a block, which set some parts of the qualifier
|
2016-09-16 23:10:39 +00:00
|
|
|
parseContext.mergeQualifiers(type.getQualifier(), qualifier);
|
2016-07-25 22:05:33 +00:00
|
|
|
// further, it can create an anonymous instance of the block
|
|
|
|
if (peekTokenClass(EHTokSemicolon))
|
|
|
|
parseContext.declareBlock(loc, type);
|
2016-10-04 22:58:14 +00:00
|
|
|
} else {
|
|
|
|
// Some qualifiers are set when parsing the type. Merge those with
|
|
|
|
// whatever comes from acceptQualifier.
|
|
|
|
assert(qualifier.layoutFormat == ElfNone);
|
2016-11-17 22:04:20 +00:00
|
|
|
|
2016-10-04 22:58:14 +00:00
|
|
|
qualifier.layoutFormat = type.getQualifier().layoutFormat;
|
2016-10-27 01:18:55 +00:00
|
|
|
qualifier.precision = type.getQualifier().precision;
|
2016-11-17 22:04:20 +00:00
|
|
|
|
|
|
|
if (type.getQualifier().storage == EvqVaryingOut)
|
|
|
|
qualifier.storage = type.getQualifier().storage;
|
|
|
|
|
|
|
|
type.getQualifier() = qualifier;
|
2016-10-04 22:58:14 +00:00
|
|
|
}
|
2016-03-13 03:24:24 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-13 05:52:12 +00:00
|
|
|
// type_qualifier
|
|
|
|
// : qualifier qualifier ...
|
|
|
|
//
|
|
|
|
// Zero or more of these, so this can't return false.
|
|
|
|
//
|
2016-08-17 16:22:08 +00:00
|
|
|
bool HlslGrammar::acceptQualifier(TQualifier& qualifier)
|
2016-03-13 03:24:24 +00:00
|
|
|
{
|
2016-06-13 05:52:12 +00:00
|
|
|
do {
|
|
|
|
switch (peek()) {
|
|
|
|
case EHTokStatic:
|
2016-09-28 01:13:05 +00:00
|
|
|
qualifier.storage = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;
|
2016-06-13 05:52:12 +00:00
|
|
|
break;
|
|
|
|
case EHTokExtern:
|
|
|
|
// TODO: no meaning in glslang?
|
|
|
|
break;
|
|
|
|
case EHTokShared:
|
|
|
|
// TODO: hint
|
|
|
|
break;
|
|
|
|
case EHTokGroupShared:
|
|
|
|
qualifier.storage = EvqShared;
|
|
|
|
break;
|
|
|
|
case EHTokUniform:
|
|
|
|
qualifier.storage = EvqUniform;
|
|
|
|
break;
|
|
|
|
case EHTokConst:
|
|
|
|
qualifier.storage = EvqConst;
|
|
|
|
break;
|
|
|
|
case EHTokVolatile:
|
|
|
|
qualifier.volatil = true;
|
|
|
|
break;
|
|
|
|
case EHTokLinear:
|
|
|
|
qualifier.smooth = true;
|
|
|
|
break;
|
|
|
|
case EHTokCentroid:
|
|
|
|
qualifier.centroid = true;
|
|
|
|
break;
|
|
|
|
case EHTokNointerpolation:
|
|
|
|
qualifier.flat = true;
|
|
|
|
break;
|
|
|
|
case EHTokNoperspective:
|
|
|
|
qualifier.nopersp = true;
|
|
|
|
break;
|
|
|
|
case EHTokSample:
|
|
|
|
qualifier.sample = true;
|
|
|
|
break;
|
|
|
|
case EHTokRowMajor:
|
2016-09-26 02:25:06 +00:00
|
|
|
qualifier.layoutMatrix = ElmColumnMajor;
|
2016-06-13 05:52:12 +00:00
|
|
|
break;
|
|
|
|
case EHTokColumnMajor:
|
2016-09-26 02:25:06 +00:00
|
|
|
qualifier.layoutMatrix = ElmRowMajor;
|
2016-06-13 05:52:12 +00:00
|
|
|
break;
|
|
|
|
case EHTokPrecise:
|
|
|
|
qualifier.noContraction = true;
|
|
|
|
break;
|
2016-07-13 02:44:32 +00:00
|
|
|
case EHTokIn:
|
|
|
|
qualifier.storage = EvqIn;
|
|
|
|
break;
|
|
|
|
case EHTokOut:
|
|
|
|
qualifier.storage = EvqOut;
|
|
|
|
break;
|
|
|
|
case EHTokInOut:
|
|
|
|
qualifier.storage = EvqInOut;
|
|
|
|
break;
|
2016-08-17 16:22:08 +00:00
|
|
|
case EHTokLayout:
|
|
|
|
if (! acceptLayoutQualifierList(qualifier))
|
|
|
|
return false;
|
|
|
|
continue;
|
2016-11-17 22:04:20 +00:00
|
|
|
|
|
|
|
// GS geometries: these are specified on stage input variables, and are an error (not verified here)
|
|
|
|
// for output variables.
|
|
|
|
case EHTokPoint:
|
|
|
|
qualifier.storage = EvqIn;
|
|
|
|
if (!parseContext.handleInputGeometry(token.loc, ElgPoints))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case EHTokLine:
|
|
|
|
qualifier.storage = EvqIn;
|
|
|
|
if (!parseContext.handleInputGeometry(token.loc, ElgLines))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case EHTokTriangle:
|
|
|
|
qualifier.storage = EvqIn;
|
|
|
|
if (!parseContext.handleInputGeometry(token.loc, ElgTriangles))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case EHTokLineAdj:
|
|
|
|
qualifier.storage = EvqIn;
|
|
|
|
if (!parseContext.handleInputGeometry(token.loc, ElgLinesAdjacency))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case EHTokTriangleAdj:
|
|
|
|
qualifier.storage = EvqIn;
|
|
|
|
if (!parseContext.handleInputGeometry(token.loc, ElgTrianglesAdjacency))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
2016-06-13 05:52:12 +00:00
|
|
|
default:
|
2016-08-17 16:22:08 +00:00
|
|
|
return true;
|
2016-06-13 05:52:12 +00:00
|
|
|
}
|
|
|
|
advanceToken();
|
|
|
|
} while (true);
|
2016-03-13 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 16:22:08 +00:00
|
|
|
// layout_qualifier_list
|
2016-09-05 20:37:03 +00:00
|
|
|
// : LAYOUT LEFT_PAREN layout_qualifier COMMA layout_qualifier ... RIGHT_PAREN
|
2016-08-17 16:22:08 +00:00
|
|
|
//
|
|
|
|
// layout_qualifier
|
|
|
|
// : identifier
|
2016-09-03 03:12:23 +00:00
|
|
|
// | identifier EQUAL expression
|
2016-08-17 16:22:08 +00:00
|
|
|
//
|
|
|
|
// Zero or more of these, so this can't return false.
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptLayoutQualifierList(TQualifier& qualifier)
|
|
|
|
{
|
|
|
|
if (! acceptTokenClass(EHTokLayout))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// LEFT_PAREN
|
|
|
|
if (! acceptTokenClass(EHTokLeftParen))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
do {
|
|
|
|
// identifier
|
|
|
|
HlslToken idToken;
|
|
|
|
if (! acceptIdentifier(idToken))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// EQUAL expression
|
|
|
|
if (acceptTokenClass(EHTokAssign)) {
|
|
|
|
TIntermTyped* expr;
|
|
|
|
if (! acceptConditionalExpression(expr)) {
|
|
|
|
expected("expression");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
parseContext.setLayoutQualifier(idToken.loc, qualifier, *idToken.string, expr);
|
|
|
|
} else
|
|
|
|
parseContext.setLayoutQualifier(idToken.loc, qualifier, *idToken.string);
|
|
|
|
|
|
|
|
// COMMA
|
|
|
|
if (! acceptTokenClass(EHTokComma))
|
|
|
|
break;
|
|
|
|
} while (true);
|
|
|
|
|
|
|
|
// RIGHT_PAREN
|
|
|
|
if (! acceptTokenClass(EHTokRightParen)) {
|
|
|
|
expected(")");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-24 01:13:48 +00:00
|
|
|
// template_type
|
|
|
|
// : FLOAT
|
|
|
|
// | DOUBLE
|
|
|
|
// | INT
|
|
|
|
// | DWORD
|
|
|
|
// | UINT
|
|
|
|
// | BOOL
|
|
|
|
//
|
2016-11-17 22:04:20 +00:00
|
|
|
bool HlslGrammar::acceptTemplateVecMatBasicType(TBasicType& basicType)
|
2016-06-24 01:13:48 +00:00
|
|
|
{
|
|
|
|
switch (peek()) {
|
|
|
|
case EHTokFloat:
|
|
|
|
basicType = EbtFloat;
|
|
|
|
break;
|
|
|
|
case EHTokDouble:
|
|
|
|
basicType = EbtDouble;
|
|
|
|
break;
|
|
|
|
case EHTokInt:
|
|
|
|
case EHTokDword:
|
|
|
|
basicType = EbtInt;
|
|
|
|
break;
|
|
|
|
case EHTokUint:
|
|
|
|
basicType = EbtUint;
|
|
|
|
break;
|
|
|
|
case EHTokBool:
|
|
|
|
basicType = EbtBool;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
advanceToken();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// vector_template_type
|
|
|
|
// : VECTOR
|
|
|
|
// | VECTOR LEFT_ANGLE template_type COMMA integer_literal RIGHT_ANGLE
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptVectorTemplateType(TType& type)
|
|
|
|
{
|
|
|
|
if (! acceptTokenClass(EHTokVector))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokLeftAngle)) {
|
|
|
|
// in HLSL, 'vector' alone means float4.
|
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 4);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
TBasicType basicType;
|
2016-11-17 22:04:20 +00:00
|
|
|
if (! acceptTemplateVecMatBasicType(basicType)) {
|
2016-06-24 01:13:48 +00:00
|
|
|
expected("scalar type");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// COMMA
|
|
|
|
if (! acceptTokenClass(EHTokComma)) {
|
|
|
|
expected(",");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// integer
|
|
|
|
if (! peekTokenClass(EHTokIntConstant)) {
|
|
|
|
expected("literal integer");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TIntermTyped* vecSize;
|
|
|
|
if (! acceptLiteral(vecSize))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const int vecSizeI = vecSize->getAsConstantUnion()->getConstArray()[0].getIConst();
|
|
|
|
|
|
|
|
new(&type) TType(basicType, EvqTemporary, vecSizeI);
|
|
|
|
|
|
|
|
if (vecSizeI == 1)
|
|
|
|
type.makeVector();
|
|
|
|
|
|
|
|
if (!acceptTokenClass(EHTokRightAngle)) {
|
|
|
|
expected("right angle bracket");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// matrix_template_type
|
|
|
|
// : MATRIX
|
|
|
|
// | MATRIX LEFT_ANGLE template_type COMMA integer_literal COMMA integer_literal RIGHT_ANGLE
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptMatrixTemplateType(TType& type)
|
|
|
|
{
|
|
|
|
if (! acceptTokenClass(EHTokMatrix))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokLeftAngle)) {
|
|
|
|
// in HLSL, 'matrix' alone means float4x4.
|
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 4);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
TBasicType basicType;
|
2016-11-17 22:04:20 +00:00
|
|
|
if (! acceptTemplateVecMatBasicType(basicType)) {
|
2016-06-24 01:13:48 +00:00
|
|
|
expected("scalar type");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// COMMA
|
|
|
|
if (! acceptTokenClass(EHTokComma)) {
|
|
|
|
expected(",");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// integer rows
|
|
|
|
if (! peekTokenClass(EHTokIntConstant)) {
|
|
|
|
expected("literal integer");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TIntermTyped* rows;
|
|
|
|
if (! acceptLiteral(rows))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// COMMA
|
|
|
|
if (! acceptTokenClass(EHTokComma)) {
|
|
|
|
expected(",");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// integer cols
|
|
|
|
if (! peekTokenClass(EHTokIntConstant)) {
|
|
|
|
expected("literal integer");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TIntermTyped* cols;
|
|
|
|
if (! acceptLiteral(cols))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
new(&type) TType(basicType, EvqTemporary, 0,
|
2016-08-24 20:36:13 +00:00
|
|
|
rows->getAsConstantUnion()->getConstArray()[0].getIConst(),
|
|
|
|
cols->getAsConstantUnion()->getConstArray()[0].getIConst());
|
2016-06-24 01:13:48 +00:00
|
|
|
|
|
|
|
if (!acceptTokenClass(EHTokRightAngle)) {
|
|
|
|
expected("right angle bracket");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-17 22:04:20 +00:00
|
|
|
// layout_geometry
|
|
|
|
// : LINESTREAM
|
|
|
|
// | POINTSTREAM
|
|
|
|
// | TRIANGLESTREAM
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptOutputPrimitiveGeometry(TLayoutGeometry& geometry)
|
|
|
|
{
|
|
|
|
// read geometry type
|
|
|
|
const EHlslTokenClass geometryType = peek();
|
|
|
|
|
|
|
|
switch (geometryType) {
|
|
|
|
case EHTokPointStream: geometry = ElgPoints; break;
|
|
|
|
case EHTokLineStream: geometry = ElgLineStrip; break;
|
|
|
|
case EHTokTriangleStream: geometry = ElgTriangleStrip; break;
|
|
|
|
default:
|
|
|
|
return false; // not a layout geometry
|
|
|
|
}
|
|
|
|
|
|
|
|
advanceToken(); // consume the layout keyword
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// stream_out_template_type
|
|
|
|
// : output_primitive_geometry_type LEFT_ANGLE type RIGHT_ANGLE
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptStreamOutTemplateType(TType& type, TLayoutGeometry& geometry)
|
|
|
|
{
|
|
|
|
geometry = ElgNone;
|
|
|
|
|
|
|
|
if (! acceptOutputPrimitiveGeometry(geometry))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokLeftAngle))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (! acceptType(type)) {
|
|
|
|
expected("stream output type");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
type.getQualifier().storage = EvqVaryingOut;
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokRightAngle)) {
|
|
|
|
expected("right angle bracket");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-20 19:22:58 +00:00
|
|
|
// annotations
|
|
|
|
// : LEFT_ANGLE declaration SEMI_COLON ... declaration SEMICOLON RIGHT_ANGLE
|
2016-09-20 02:23:18 +00:00
|
|
|
//
|
2016-09-20 19:22:58 +00:00
|
|
|
bool HlslGrammar::acceptAnnotations(TQualifier&)
|
2016-09-20 02:23:18 +00:00
|
|
|
{
|
2016-09-20 19:22:58 +00:00
|
|
|
if (! acceptTokenClass(EHTokLeftAngle))
|
2016-09-20 02:23:18 +00:00
|
|
|
return false;
|
|
|
|
|
2016-09-20 19:22:58 +00:00
|
|
|
// note that we are nesting a name space
|
|
|
|
parseContext.nestAnnotations();
|
2016-09-20 02:23:18 +00:00
|
|
|
|
|
|
|
// declaration SEMI_COLON ... declaration SEMICOLON RIGHT_ANGLE
|
|
|
|
do {
|
|
|
|
// eat any extra SEMI_COLON; don't know if the grammar calls for this or not
|
|
|
|
while (acceptTokenClass(EHTokSemicolon))
|
|
|
|
;
|
|
|
|
|
|
|
|
if (acceptTokenClass(EHTokRightAngle))
|
2016-09-20 19:22:58 +00:00
|
|
|
break;
|
2016-09-20 02:23:18 +00:00
|
|
|
|
|
|
|
// declaration
|
|
|
|
TIntermNode* node;
|
|
|
|
if (! acceptDeclaration(node)) {
|
2016-09-20 19:22:58 +00:00
|
|
|
expected("declaration in annotation");
|
2016-09-20 02:23:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} while (true);
|
2016-09-20 19:22:58 +00:00
|
|
|
|
|
|
|
parseContext.unnestAnnotations();
|
|
|
|
return true;
|
2016-09-20 02:23:18 +00:00
|
|
|
}
|
2016-06-24 01:13:48 +00:00
|
|
|
|
2016-06-29 16:58:58 +00:00
|
|
|
// sampler_type
|
|
|
|
// : SAMPLER
|
|
|
|
// | SAMPLER1D
|
|
|
|
// | SAMPLER2D
|
|
|
|
// | SAMPLER3D
|
|
|
|
// | SAMPLERCUBE
|
|
|
|
// | SAMPLERSTATE
|
|
|
|
// | SAMPLERCOMPARISONSTATE
|
|
|
|
bool HlslGrammar::acceptSamplerType(TType& type)
|
|
|
|
{
|
|
|
|
// read sampler type
|
|
|
|
const EHlslTokenClass samplerType = peek();
|
|
|
|
|
2016-07-19 20:28:05 +00:00
|
|
|
// TODO: for DX9
|
2016-07-15 17:22:24 +00:00
|
|
|
// TSamplerDim dim = EsdNone;
|
2016-06-29 16:58:58 +00:00
|
|
|
|
2016-07-19 20:28:05 +00:00
|
|
|
bool isShadow = false;
|
|
|
|
|
2016-06-29 16:58:58 +00:00
|
|
|
switch (samplerType) {
|
|
|
|
case EHTokSampler: break;
|
2016-07-15 17:22:24 +00:00
|
|
|
case EHTokSampler1d: /*dim = Esd1D*/; break;
|
|
|
|
case EHTokSampler2d: /*dim = Esd2D*/; break;
|
|
|
|
case EHTokSampler3d: /*dim = Esd3D*/; break;
|
|
|
|
case EHTokSamplerCube: /*dim = EsdCube*/; break;
|
2016-06-29 16:58:58 +00:00
|
|
|
case EHTokSamplerState: break;
|
2016-07-19 20:28:05 +00:00
|
|
|
case EHTokSamplerComparisonState: isShadow = true; break;
|
2016-06-29 16:58:58 +00:00
|
|
|
default:
|
|
|
|
return false; // not a sampler declaration
|
|
|
|
}
|
|
|
|
|
|
|
|
advanceToken(); // consume the sampler type keyword
|
|
|
|
|
|
|
|
TArraySizes* arraySizes = nullptr; // TODO: array
|
|
|
|
|
|
|
|
TSampler sampler;
|
2016-07-19 20:28:05 +00:00
|
|
|
sampler.setPureSampler(isShadow);
|
2016-06-29 16:58:58 +00:00
|
|
|
|
|
|
|
type.shallowCopy(TType(sampler, EvqUniform, arraySizes));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// texture_type
|
|
|
|
// | BUFFER
|
|
|
|
// | TEXTURE1D
|
|
|
|
// | TEXTURE1DARRAY
|
|
|
|
// | TEXTURE2D
|
|
|
|
// | TEXTURE2DARRAY
|
|
|
|
// | TEXTURE3D
|
|
|
|
// | TEXTURECUBE
|
|
|
|
// | TEXTURECUBEARRAY
|
|
|
|
// | TEXTURE2DMS
|
|
|
|
// | TEXTURE2DMSARRAY
|
2016-10-04 22:58:14 +00:00
|
|
|
// | RWBUFFER
|
|
|
|
// | RWTEXTURE1D
|
|
|
|
// | RWTEXTURE1DARRAY
|
|
|
|
// | RWTEXTURE2D
|
|
|
|
// | RWTEXTURE2DARRAY
|
|
|
|
// | RWTEXTURE3D
|
|
|
|
|
2016-06-29 16:58:58 +00:00
|
|
|
bool HlslGrammar::acceptTextureType(TType& type)
|
|
|
|
{
|
|
|
|
const EHlslTokenClass textureType = peek();
|
|
|
|
|
|
|
|
TSamplerDim dim = EsdNone;
|
|
|
|
bool array = false;
|
|
|
|
bool ms = false;
|
2016-10-04 22:58:14 +00:00
|
|
|
bool image = false;
|
2016-06-29 16:58:58 +00:00
|
|
|
|
|
|
|
switch (textureType) {
|
|
|
|
case EHTokBuffer: dim = EsdBuffer; break;
|
|
|
|
case EHTokTexture1d: dim = Esd1D; break;
|
|
|
|
case EHTokTexture1darray: dim = Esd1D; array = true; break;
|
|
|
|
case EHTokTexture2d: dim = Esd2D; break;
|
|
|
|
case EHTokTexture2darray: dim = Esd2D; array = true; break;
|
|
|
|
case EHTokTexture3d: dim = Esd3D; break;
|
|
|
|
case EHTokTextureCube: dim = EsdCube; break;
|
|
|
|
case EHTokTextureCubearray: dim = EsdCube; array = true; break;
|
|
|
|
case EHTokTexture2DMS: dim = Esd2D; ms = true; break;
|
|
|
|
case EHTokTexture2DMSarray: dim = Esd2D; array = true; ms = true; break;
|
2016-10-04 22:58:14 +00:00
|
|
|
case EHTokRWBuffer: dim = EsdBuffer; image=true; break;
|
|
|
|
case EHTokRWTexture1d: dim = Esd1D; array=false; image=true; break;
|
|
|
|
case EHTokRWTexture1darray: dim = Esd1D; array=true; image=true; break;
|
|
|
|
case EHTokRWTexture2d: dim = Esd2D; array=false; image=true; break;
|
|
|
|
case EHTokRWTexture2darray: dim = Esd2D; array=true; image=true; break;
|
|
|
|
case EHTokRWTexture3d: dim = Esd3D; array=false; image=true; break;
|
2016-06-29 16:58:58 +00:00
|
|
|
default:
|
|
|
|
return false; // not a texture declaration
|
|
|
|
}
|
|
|
|
|
|
|
|
advanceToken(); // consume the texture object keyword
|
|
|
|
|
|
|
|
TType txType(EbtFloat, EvqUniform, 4); // default type is float4
|
|
|
|
|
|
|
|
TIntermTyped* msCount = nullptr;
|
|
|
|
|
2016-10-04 22:58:14 +00:00
|
|
|
// texture type: required for multisample types and RWBuffer/RWTextures!
|
2016-06-29 16:58:58 +00:00
|
|
|
if (acceptTokenClass(EHTokLeftAngle)) {
|
|
|
|
if (! acceptType(txType)) {
|
|
|
|
expected("scalar or vector type");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TBasicType basicRetType = txType.getBasicType() ;
|
|
|
|
|
|
|
|
if (basicRetType != EbtFloat && basicRetType != EbtUint && basicRetType != EbtInt) {
|
|
|
|
unimplemented("basic type in texture");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-27 21:46:48 +00:00
|
|
|
// Buffers can handle small mats if they fit in 4 components
|
|
|
|
if (dim == EsdBuffer && txType.isMatrix()) {
|
|
|
|
if ((txType.getMatrixCols() * txType.getMatrixRows()) > 4) {
|
|
|
|
expected("components < 4 in matrix buffer type");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: except we don't handle it yet...
|
|
|
|
unimplemented("matrix type in buffer");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:58:58 +00:00
|
|
|
if (!txType.isScalar() && !txType.isVector()) {
|
|
|
|
expected("scalar or vector type");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ms && acceptTokenClass(EHTokComma)) {
|
|
|
|
// read sample count for multisample types, if given
|
|
|
|
if (! peekTokenClass(EHTokIntConstant)) {
|
|
|
|
expected("multisample count");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! acceptLiteral(msCount)) // should never fail, since we just found an integer
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokRightAngle)) {
|
|
|
|
expected("right angle bracket");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (ms) {
|
|
|
|
expected("texture type for multisample");
|
|
|
|
return false;
|
2016-10-04 22:58:14 +00:00
|
|
|
} else if (image) {
|
|
|
|
expected("type for RWTexture/RWBuffer");
|
|
|
|
return false;
|
2016-06-29 16:58:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TArraySizes* arraySizes = nullptr;
|
2016-10-10 21:24:57 +00:00
|
|
|
const bool shadow = false; // declared on the sampler
|
2016-06-29 16:58:58 +00:00
|
|
|
|
|
|
|
TSampler sampler;
|
2016-10-04 22:58:14 +00:00
|
|
|
TLayoutFormat format = ElfNone;
|
|
|
|
|
2016-10-10 21:24:57 +00:00
|
|
|
// Buffer, RWBuffer and RWTexture (images) require a TLayoutFormat. We handle only a limit set.
|
|
|
|
if (image || dim == EsdBuffer)
|
|
|
|
format = parseContext.getLayoutFromTxType(token.loc, txType);
|
2016-10-04 22:58:14 +00:00
|
|
|
|
|
|
|
// Non-image Buffers are combined
|
|
|
|
if (dim == EsdBuffer && !image) {
|
2016-07-27 21:46:48 +00:00
|
|
|
sampler.set(txType.getBasicType(), dim, array);
|
|
|
|
} else {
|
|
|
|
// DX10 textures are separated. TODO: DX9.
|
2016-10-04 22:58:14 +00:00
|
|
|
if (image) {
|
|
|
|
sampler.setImage(txType.getBasicType(), dim, array, shadow, ms);
|
|
|
|
} else {
|
|
|
|
sampler.setTexture(txType.getBasicType(), dim, array, shadow, ms);
|
|
|
|
}
|
2016-07-27 21:46:48 +00:00
|
|
|
}
|
2016-10-14 22:40:32 +00:00
|
|
|
|
|
|
|
// Remember the declared vector size.
|
|
|
|
sampler.vectorSize = txType.getVectorSize();
|
2016-06-29 16:58:58 +00:00
|
|
|
|
|
|
|
type.shallowCopy(TType(sampler, EvqUniform, arraySizes));
|
2016-10-04 22:58:14 +00:00
|
|
|
type.getQualifier().layoutFormat = format;
|
2016-06-29 16:58:58 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-13 03:24:24 +00:00
|
|
|
// If token is for a type, update 'type' with the type information,
|
|
|
|
// and return true and advance.
|
|
|
|
// Otherwise, return false, and don't advance
|
|
|
|
bool HlslGrammar::acceptType(TType& type)
|
|
|
|
{
|
2016-10-27 01:18:55 +00:00
|
|
|
// Basic types for min* types, broken out here in case of future
|
|
|
|
// changes, e.g, to use native halfs.
|
|
|
|
static const TBasicType min16float_bt = EbtFloat;
|
|
|
|
static const TBasicType min10float_bt = EbtFloat;
|
|
|
|
static const TBasicType min16int_bt = EbtInt;
|
|
|
|
static const TBasicType min12int_bt = EbtInt;
|
|
|
|
static const TBasicType min16uint_bt = EbtUint;
|
|
|
|
|
2016-05-04 04:49:24 +00:00
|
|
|
switch (peek()) {
|
2016-06-24 01:13:48 +00:00
|
|
|
case EHTokVector:
|
|
|
|
return acceptVectorTemplateType(type);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EHTokMatrix:
|
|
|
|
return acceptMatrixTemplateType(type);
|
|
|
|
break;
|
|
|
|
|
2016-11-17 22:04:20 +00:00
|
|
|
case EHTokPointStream: // fall through
|
|
|
|
case EHTokLineStream: // ...
|
|
|
|
case EHTokTriangleStream: // ...
|
|
|
|
{
|
|
|
|
TLayoutGeometry geometry;
|
|
|
|
if (! acceptStreamOutTemplateType(type, geometry))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (! parseContext.handleOutputGeometry(token.loc, geometry))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:58:58 +00:00
|
|
|
case EHTokSampler: // fall through
|
|
|
|
case EHTokSampler1d: // ...
|
|
|
|
case EHTokSampler2d: // ...
|
|
|
|
case EHTokSampler3d: // ...
|
|
|
|
case EHTokSamplerCube: // ...
|
|
|
|
case EHTokSamplerState: // ...
|
|
|
|
case EHTokSamplerComparisonState: // ...
|
|
|
|
return acceptSamplerType(type);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EHTokBuffer: // fall through
|
|
|
|
case EHTokTexture1d: // ...
|
|
|
|
case EHTokTexture1darray: // ...
|
|
|
|
case EHTokTexture2d: // ...
|
|
|
|
case EHTokTexture2darray: // ...
|
|
|
|
case EHTokTexture3d: // ...
|
|
|
|
case EHTokTextureCube: // ...
|
|
|
|
case EHTokTextureCubearray: // ...
|
|
|
|
case EHTokTexture2DMS: // ...
|
|
|
|
case EHTokTexture2DMSarray: // ...
|
2016-10-04 22:58:14 +00:00
|
|
|
case EHTokRWTexture1d: // ...
|
|
|
|
case EHTokRWTexture1darray: // ...
|
|
|
|
case EHTokRWTexture2d: // ...
|
|
|
|
case EHTokRWTexture2darray: // ...
|
|
|
|
case EHTokRWTexture3d: // ...
|
|
|
|
case EHTokRWBuffer: // ...
|
2016-06-29 16:58:58 +00:00
|
|
|
return acceptTextureType(type);
|
|
|
|
break;
|
|
|
|
|
2016-06-11 22:43:14 +00:00
|
|
|
case EHTokStruct:
|
2016-07-25 22:05:33 +00:00
|
|
|
case EHTokCBuffer:
|
|
|
|
case EHTokTBuffer:
|
2016-06-11 22:43:14 +00:00
|
|
|
return acceptStruct(type);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EHTokIdentifier:
|
|
|
|
// An identifier could be for a user-defined type.
|
|
|
|
// Note we cache the symbol table lookup, to save for a later rule
|
|
|
|
// when this is not a type.
|
|
|
|
token.symbol = parseContext.symbolTable.find(*token.string);
|
|
|
|
if (token.symbol && token.symbol->getAsVariable() && token.symbol->getAsVariable()->isUserType()) {
|
|
|
|
type.shallowCopy(token.symbol->getType());
|
|
|
|
advanceToken();
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
|
2016-06-08 18:50:56 +00:00
|
|
|
case EHTokVoid:
|
|
|
|
new(&type) TType(EbtVoid);
|
2016-03-13 03:24:24 +00:00
|
|
|
break;
|
2016-06-08 18:50:56 +00:00
|
|
|
|
2016-09-20 19:22:58 +00:00
|
|
|
case EHTokString:
|
|
|
|
new(&type) TType(EbtString);
|
|
|
|
break;
|
|
|
|
|
2016-03-13 03:24:24 +00:00
|
|
|
case EHTokFloat:
|
2016-05-20 18:06:03 +00:00
|
|
|
new(&type) TType(EbtFloat);
|
|
|
|
break;
|
2016-03-13 03:24:24 +00:00
|
|
|
case EHTokFloat1:
|
|
|
|
new(&type) TType(EbtFloat);
|
2016-05-20 18:06:03 +00:00
|
|
|
type.makeVector();
|
2016-03-13 03:24:24 +00:00
|
|
|
break;
|
|
|
|
case EHTokFloat2:
|
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 2);
|
|
|
|
break;
|
|
|
|
case EHTokFloat3:
|
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 3);
|
|
|
|
break;
|
|
|
|
case EHTokFloat4:
|
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 4);
|
|
|
|
break;
|
|
|
|
|
2016-06-08 18:50:56 +00:00
|
|
|
case EHTokDouble:
|
|
|
|
new(&type) TType(EbtDouble);
|
|
|
|
break;
|
|
|
|
case EHTokDouble1:
|
|
|
|
new(&type) TType(EbtDouble);
|
|
|
|
type.makeVector();
|
|
|
|
break;
|
|
|
|
case EHTokDouble2:
|
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 2);
|
|
|
|
break;
|
|
|
|
case EHTokDouble3:
|
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 3);
|
|
|
|
break;
|
|
|
|
case EHTokDouble4:
|
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EHTokInt:
|
|
|
|
case EHTokDword:
|
|
|
|
new(&type) TType(EbtInt);
|
|
|
|
break;
|
|
|
|
case EHTokInt1:
|
|
|
|
new(&type) TType(EbtInt);
|
|
|
|
type.makeVector();
|
|
|
|
break;
|
2016-03-13 03:24:24 +00:00
|
|
|
case EHTokInt2:
|
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 2);
|
|
|
|
break;
|
|
|
|
case EHTokInt3:
|
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 3);
|
|
|
|
break;
|
|
|
|
case EHTokInt4:
|
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 4);
|
|
|
|
break;
|
|
|
|
|
2016-06-08 18:50:56 +00:00
|
|
|
case EHTokUint:
|
|
|
|
new(&type) TType(EbtUint);
|
|
|
|
break;
|
|
|
|
case EHTokUint1:
|
|
|
|
new(&type) TType(EbtUint);
|
|
|
|
type.makeVector();
|
|
|
|
break;
|
|
|
|
case EHTokUint2:
|
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 2);
|
|
|
|
break;
|
|
|
|
case EHTokUint3:
|
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 3);
|
|
|
|
break;
|
|
|
|
case EHTokUint4:
|
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 4);
|
|
|
|
break;
|
|
|
|
|
2016-06-24 01:13:48 +00:00
|
|
|
|
2016-06-08 18:50:56 +00:00
|
|
|
case EHTokBool:
|
|
|
|
new(&type) TType(EbtBool);
|
|
|
|
break;
|
|
|
|
case EHTokBool1:
|
|
|
|
new(&type) TType(EbtBool);
|
|
|
|
type.makeVector();
|
|
|
|
break;
|
2016-03-13 03:24:24 +00:00
|
|
|
case EHTokBool2:
|
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 2);
|
|
|
|
break;
|
|
|
|
case EHTokBool3:
|
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 3);
|
|
|
|
break;
|
|
|
|
case EHTokBool4:
|
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 4);
|
|
|
|
break;
|
|
|
|
|
2016-10-27 01:18:55 +00:00
|
|
|
case EHTokMin16float:
|
|
|
|
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium);
|
|
|
|
break;
|
|
|
|
case EHTokMin16float1:
|
|
|
|
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium);
|
|
|
|
type.makeVector();
|
|
|
|
break;
|
|
|
|
case EHTokMin16float2:
|
|
|
|
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 2);
|
|
|
|
break;
|
|
|
|
case EHTokMin16float3:
|
|
|
|
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 3);
|
|
|
|
break;
|
|
|
|
case EHTokMin16float4:
|
|
|
|
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EHTokMin10float:
|
|
|
|
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium);
|
|
|
|
break;
|
|
|
|
case EHTokMin10float1:
|
|
|
|
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium);
|
|
|
|
type.makeVector();
|
|
|
|
break;
|
|
|
|
case EHTokMin10float2:
|
|
|
|
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 2);
|
|
|
|
break;
|
|
|
|
case EHTokMin10float3:
|
|
|
|
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 3);
|
|
|
|
break;
|
|
|
|
case EHTokMin10float4:
|
|
|
|
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EHTokMin16int:
|
|
|
|
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium);
|
|
|
|
break;
|
|
|
|
case EHTokMin16int1:
|
|
|
|
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium);
|
|
|
|
type.makeVector();
|
|
|
|
break;
|
|
|
|
case EHTokMin16int2:
|
|
|
|
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 2);
|
|
|
|
break;
|
|
|
|
case EHTokMin16int3:
|
|
|
|
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 3);
|
|
|
|
break;
|
|
|
|
case EHTokMin16int4:
|
|
|
|
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EHTokMin12int:
|
|
|
|
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium);
|
|
|
|
break;
|
|
|
|
case EHTokMin12int1:
|
|
|
|
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium);
|
|
|
|
type.makeVector();
|
|
|
|
break;
|
|
|
|
case EHTokMin12int2:
|
|
|
|
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 2);
|
|
|
|
break;
|
|
|
|
case EHTokMin12int3:
|
|
|
|
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 3);
|
|
|
|
break;
|
|
|
|
case EHTokMin12int4:
|
|
|
|
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EHTokMin16uint:
|
|
|
|
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium);
|
|
|
|
break;
|
|
|
|
case EHTokMin16uint1:
|
|
|
|
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium);
|
|
|
|
type.makeVector();
|
|
|
|
break;
|
|
|
|
case EHTokMin16uint2:
|
|
|
|
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 2);
|
|
|
|
break;
|
|
|
|
case EHTokMin16uint3:
|
|
|
|
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 3);
|
|
|
|
break;
|
|
|
|
case EHTokMin16uint4:
|
|
|
|
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 4);
|
|
|
|
break;
|
|
|
|
|
2016-05-20 18:17:26 +00:00
|
|
|
case EHTokInt1x1:
|
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 1);
|
|
|
|
break;
|
|
|
|
case EHTokInt1x2:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 2);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokInt1x3:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 3);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokInt1x4:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 4);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokInt2x1:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 2, 1);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokInt2x2:
|
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 2, 2);
|
|
|
|
break;
|
|
|
|
case EHTokInt2x3:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 2, 3);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokInt2x4:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 2, 4);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokInt3x1:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 3, 1);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokInt3x2:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 3, 2);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokInt3x3:
|
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 3, 3);
|
|
|
|
break;
|
|
|
|
case EHTokInt3x4:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 3, 4);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokInt4x1:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 4, 1);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokInt4x2:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 4, 2);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokInt4x3:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 4, 3);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokInt4x4:
|
|
|
|
new(&type) TType(EbtInt, EvqTemporary, 0, 4, 4);
|
|
|
|
break;
|
|
|
|
|
2016-06-08 18:50:56 +00:00
|
|
|
case EHTokUint1x1:
|
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 1, 1);
|
|
|
|
break;
|
|
|
|
case EHTokUint1x2:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 1, 2);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokUint1x3:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 1, 3);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokUint1x4:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 1, 4);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokUint2x1:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 2, 1);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokUint2x2:
|
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 2, 2);
|
|
|
|
break;
|
|
|
|
case EHTokUint2x3:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 2, 3);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokUint2x4:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 2, 4);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokUint3x1:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 3, 1);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokUint3x2:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 3, 2);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokUint3x3:
|
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 3, 3);
|
|
|
|
break;
|
|
|
|
case EHTokUint3x4:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 3, 4);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokUint4x1:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 4, 1);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokUint4x2:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 4, 2);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokUint4x3:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 4, 3);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokUint4x4:
|
|
|
|
new(&type) TType(EbtUint, EvqTemporary, 0, 4, 4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EHTokBool1x1:
|
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 1, 1);
|
|
|
|
break;
|
|
|
|
case EHTokBool1x2:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 1, 2);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokBool1x3:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 1, 3);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokBool1x4:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 1, 4);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokBool2x1:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 2, 1);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokBool2x2:
|
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 2, 2);
|
|
|
|
break;
|
|
|
|
case EHTokBool2x3:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 2, 3);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokBool2x4:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 2, 4);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokBool3x1:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 3, 1);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokBool3x2:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 3, 2);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokBool3x3:
|
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 3, 3);
|
|
|
|
break;
|
|
|
|
case EHTokBool3x4:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 3, 4);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokBool4x1:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 4, 1);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokBool4x2:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 4, 2);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokBool4x3:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 4, 3);
|
2016-06-08 18:50:56 +00:00
|
|
|
break;
|
|
|
|
case EHTokBool4x4:
|
|
|
|
new(&type) TType(EbtBool, EvqTemporary, 0, 4, 4);
|
|
|
|
break;
|
|
|
|
|
2016-05-20 18:17:26 +00:00
|
|
|
case EHTokFloat1x1:
|
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 1);
|
|
|
|
break;
|
|
|
|
case EHTokFloat1x2:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 2);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokFloat1x3:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 3);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokFloat1x4:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 4);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokFloat2x1:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 1);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
2016-03-13 03:24:24 +00:00
|
|
|
case EHTokFloat2x2:
|
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 2);
|
|
|
|
break;
|
|
|
|
case EHTokFloat2x3:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 3);
|
2016-03-13 03:24:24 +00:00
|
|
|
break;
|
|
|
|
case EHTokFloat2x4:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 4);
|
2016-03-13 03:24:24 +00:00
|
|
|
break;
|
2016-05-20 18:17:26 +00:00
|
|
|
case EHTokFloat3x1:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 1);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
2016-03-13 03:24:24 +00:00
|
|
|
case EHTokFloat3x2:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 2);
|
2016-03-13 03:24:24 +00:00
|
|
|
break;
|
|
|
|
case EHTokFloat3x3:
|
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 3);
|
|
|
|
break;
|
|
|
|
case EHTokFloat3x4:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 4);
|
2016-03-13 03:24:24 +00:00
|
|
|
break;
|
2016-05-20 18:17:26 +00:00
|
|
|
case EHTokFloat4x1:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 1);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
2016-03-13 03:24:24 +00:00
|
|
|
case EHTokFloat4x2:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 2);
|
2016-03-13 03:24:24 +00:00
|
|
|
break;
|
|
|
|
case EHTokFloat4x3:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 3);
|
2016-03-13 03:24:24 +00:00
|
|
|
break;
|
|
|
|
case EHTokFloat4x4:
|
|
|
|
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 4);
|
|
|
|
break;
|
|
|
|
|
2016-05-20 18:17:26 +00:00
|
|
|
case EHTokDouble1x1:
|
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 1);
|
|
|
|
break;
|
|
|
|
case EHTokDouble1x2:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 2);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokDouble1x3:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 3);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokDouble1x4:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 4);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokDouble2x1:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 1);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokDouble2x2:
|
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 2);
|
|
|
|
break;
|
|
|
|
case EHTokDouble2x3:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 3);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokDouble2x4:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 4);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokDouble3x1:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 1);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokDouble3x2:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 2);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokDouble3x3:
|
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 3);
|
|
|
|
break;
|
|
|
|
case EHTokDouble3x4:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 4);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokDouble4x1:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 1);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokDouble4x2:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 2);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokDouble4x3:
|
2016-08-24 20:36:13 +00:00
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 3);
|
2016-05-20 18:17:26 +00:00
|
|
|
break;
|
|
|
|
case EHTokDouble4x4:
|
|
|
|
new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 4);
|
|
|
|
break;
|
|
|
|
|
2016-03-13 03:24:24 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
advanceToken();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-11 22:43:14 +00:00
|
|
|
// struct
|
2016-07-25 22:05:33 +00:00
|
|
|
// : struct_type IDENTIFIER post_decls LEFT_BRACE struct_declaration_list RIGHT_BRACE
|
|
|
|
// | struct_type post_decls LEFT_BRACE struct_declaration_list RIGHT_BRACE
|
|
|
|
//
|
|
|
|
// struct_type
|
|
|
|
// : STRUCT
|
|
|
|
// | CBUFFER
|
|
|
|
// | TBUFFER
|
2016-06-11 22:43:14 +00:00
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptStruct(TType& type)
|
|
|
|
{
|
2016-09-05 18:19:18 +00:00
|
|
|
// This storage qualifier will tell us whether it's an AST
|
|
|
|
// block type or just a generic structure type.
|
|
|
|
TStorageQualifier storageQualifier = EvqTemporary;
|
2016-07-25 22:05:33 +00:00
|
|
|
|
|
|
|
// CBUFFER
|
|
|
|
if (acceptTokenClass(EHTokCBuffer))
|
2016-09-05 18:19:18 +00:00
|
|
|
storageQualifier = EvqUniform;
|
2016-07-25 22:05:33 +00:00
|
|
|
// TBUFFER
|
|
|
|
else if (acceptTokenClass(EHTokTBuffer))
|
2016-09-05 18:19:18 +00:00
|
|
|
storageQualifier = EvqBuffer;
|
2016-06-11 22:43:14 +00:00
|
|
|
// STRUCT
|
2016-07-25 22:05:33 +00:00
|
|
|
else if (! acceptTokenClass(EHTokStruct))
|
2016-06-11 22:43:14 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// IDENTIFIER
|
|
|
|
TString structName = "";
|
|
|
|
if (peekTokenClass(EHTokIdentifier)) {
|
|
|
|
structName = *token.string;
|
|
|
|
advanceToken();
|
|
|
|
}
|
|
|
|
|
2016-07-25 22:05:33 +00:00
|
|
|
// post_decls
|
2016-09-05 18:40:06 +00:00
|
|
|
TQualifier postDeclQualifier;
|
|
|
|
postDeclQualifier.clear();
|
|
|
|
acceptPostDecls(postDeclQualifier);
|
2016-07-25 22:05:33 +00:00
|
|
|
|
2016-06-11 22:43:14 +00:00
|
|
|
// LEFT_BRACE
|
|
|
|
if (! acceptTokenClass(EHTokLeftBrace)) {
|
|
|
|
expected("{");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// struct_declaration_list
|
|
|
|
TTypeList* typeList;
|
|
|
|
if (! acceptStructDeclarationList(typeList)) {
|
|
|
|
expected("struct member declarations");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// RIGHT_BRACE
|
|
|
|
if (! acceptTokenClass(EHTokRightBrace)) {
|
|
|
|
expected("}");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create the user-defined type
|
2016-09-05 18:19:18 +00:00
|
|
|
if (storageQualifier == EvqTemporary)
|
2016-07-25 22:05:33 +00:00
|
|
|
new(&type) TType(typeList, structName);
|
2016-09-05 18:19:18 +00:00
|
|
|
else {
|
2016-09-05 18:40:06 +00:00
|
|
|
postDeclQualifier.storage = storageQualifier;
|
|
|
|
new(&type) TType(typeList, structName, postDeclQualifier); // sets EbtBlock
|
2016-09-05 18:19:18 +00:00
|
|
|
}
|
2016-07-25 22:05:33 +00:00
|
|
|
|
|
|
|
// If it was named, which means the type can be reused later, add
|
|
|
|
// it to the symbol table. (Unless it's a block, in which
|
|
|
|
// case the name is not a type.)
|
|
|
|
if (type.getBasicType() != EbtBlock && structName.size() > 0) {
|
2016-06-11 22:43:14 +00:00
|
|
|
TVariable* userTypeDef = new TVariable(&structName, type, true);
|
|
|
|
if (! parseContext.symbolTable.insert(*userTypeDef))
|
|
|
|
parseContext.error(token.loc, "redefinition", structName.c_str(), "struct");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// struct_declaration_list
|
|
|
|
// : struct_declaration SEMI_COLON struct_declaration SEMI_COLON ...
|
|
|
|
//
|
|
|
|
// struct_declaration
|
|
|
|
// : fully_specified_type struct_declarator COMMA struct_declarator ...
|
|
|
|
//
|
|
|
|
// struct_declarator
|
2016-06-13 05:52:12 +00:00
|
|
|
// : IDENTIFIER post_decls
|
|
|
|
// | IDENTIFIER array_specifier post_decls
|
2016-06-11 22:43:14 +00:00
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptStructDeclarationList(TTypeList*& typeList)
|
|
|
|
{
|
|
|
|
typeList = new TTypeList();
|
|
|
|
|
|
|
|
do {
|
|
|
|
// success on seeing the RIGHT_BRACE coming up
|
|
|
|
if (peekTokenClass(EHTokRightBrace))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// struct_declaration
|
|
|
|
|
|
|
|
// fully_specified_type
|
|
|
|
TType memberType;
|
|
|
|
if (! acceptFullySpecifiedType(memberType)) {
|
|
|
|
expected("member type");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// struct_declarator COMMA struct_declarator ...
|
|
|
|
do {
|
|
|
|
// peek IDENTIFIER
|
|
|
|
if (! peekTokenClass(EHTokIdentifier)) {
|
|
|
|
expected("member name");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add it to the list of members
|
|
|
|
TTypeLoc member = { new TType(EbtVoid), token.loc };
|
|
|
|
member.type->shallowCopy(memberType);
|
|
|
|
member.type->setFieldName(*token.string);
|
|
|
|
typeList->push_back(member);
|
|
|
|
|
|
|
|
// accept IDENTIFIER
|
|
|
|
advanceToken();
|
|
|
|
|
|
|
|
// array_specifier
|
2016-06-19 17:50:34 +00:00
|
|
|
TArraySizes* arraySizes = nullptr;
|
|
|
|
acceptArraySpecifier(arraySizes);
|
|
|
|
if (arraySizes)
|
|
|
|
typeList->back().type->newArraySizes(*arraySizes);
|
2016-06-11 22:43:14 +00:00
|
|
|
|
2016-09-05 18:40:06 +00:00
|
|
|
acceptPostDecls(member.type->getQualifier());
|
2016-06-13 05:52:12 +00:00
|
|
|
|
2016-06-11 22:43:14 +00:00
|
|
|
// success on seeing the SEMICOLON coming up
|
|
|
|
if (peekTokenClass(EHTokSemicolon))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// COMMA
|
|
|
|
if (! acceptTokenClass(EHTokComma)) {
|
|
|
|
expected(",");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (true);
|
|
|
|
|
|
|
|
// SEMI_COLON
|
|
|
|
if (! acceptTokenClass(EHTokSemicolon)) {
|
|
|
|
expected(";");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
2016-03-13 23:58:25 +00:00
|
|
|
// function_parameters
|
2016-03-14 16:02:11 +00:00
|
|
|
// : LEFT_PAREN parameter_declaration COMMA parameter_declaration ... RIGHT_PAREN
|
2016-06-08 18:50:56 +00:00
|
|
|
// | LEFT_PAREN VOID RIGHT_PAREN
|
2016-03-13 23:58:25 +00:00
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptFunctionParameters(TFunction& function)
|
|
|
|
{
|
2016-03-14 16:02:11 +00:00
|
|
|
// LEFT_PAREN
|
2016-03-13 23:58:25 +00:00
|
|
|
if (! acceptTokenClass(EHTokLeftParen))
|
|
|
|
return false;
|
|
|
|
|
2016-06-08 18:50:56 +00:00
|
|
|
// VOID RIGHT_PAREN
|
|
|
|
if (! acceptTokenClass(EHTokVoid)) {
|
|
|
|
do {
|
|
|
|
// parameter_declaration
|
|
|
|
if (! acceptParameterDeclaration(function))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// COMMA
|
|
|
|
if (! acceptTokenClass(EHTokComma))
|
|
|
|
break;
|
|
|
|
} while (true);
|
|
|
|
}
|
2016-03-13 23:58:25 +00:00
|
|
|
|
2016-03-14 16:02:11 +00:00
|
|
|
// RIGHT_PAREN
|
2016-03-13 23:58:25 +00:00
|
|
|
if (! acceptTokenClass(EHTokRightParen)) {
|
2016-06-05 17:23:11 +00:00
|
|
|
expected(")");
|
2016-03-13 23:58:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-24 01:56:57 +00:00
|
|
|
|
|
|
|
// default_parameter_declaration
|
|
|
|
// : EQUAL conditional_expression
|
|
|
|
// : EQUAL initializer
|
|
|
|
bool HlslGrammar::acceptDefaultParameterDeclaration(const TType& type, TIntermTyped*& node)
|
|
|
|
{
|
|
|
|
node = nullptr;
|
|
|
|
|
|
|
|
// Valid not to have a default_parameter_declaration
|
|
|
|
if (!acceptTokenClass(EHTokAssign))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!acceptConditionalExpression(node)) {
|
|
|
|
if (!acceptInitializer(node))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// For initializer lists, we have to const-fold into a constructor for the type, so build
|
|
|
|
// that.
|
|
|
|
TFunction* constructor = parseContext.handleConstructorCall(token.loc, type);
|
|
|
|
if (constructor == nullptr) // cannot construct
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TIntermTyped* arguments = nullptr;
|
|
|
|
for (int i=0; i<int(node->getAsAggregate()->getSequence().size()); i++)
|
|
|
|
parseContext.handleFunctionArgument(constructor, arguments, node->getAsAggregate()->getSequence()[i]->getAsTyped());
|
|
|
|
|
|
|
|
node = parseContext.handleFunctionCall(token.loc, constructor, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is simply a constant, we can use it directly.
|
|
|
|
if (node->getAsConstantUnion())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Otherwise, it has to be const-foldable.
|
|
|
|
TIntermTyped* origNode = node;
|
|
|
|
|
|
|
|
node = intermediate.fold(node->getAsAggregate());
|
|
|
|
|
|
|
|
if (node != nullptr && origNode != node)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
parseContext.error(token.loc, "invalid default parameter value", "", "");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-13 23:58:25 +00:00
|
|
|
// parameter_declaration
|
2016-12-24 01:56:57 +00:00
|
|
|
// : fully_specified_type post_decls [ = default_parameter_declaration ]
|
|
|
|
// | fully_specified_type identifier array_specifier post_decls [ = default_parameter_declaration ]
|
2016-03-13 23:58:25 +00:00
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptParameterDeclaration(TFunction& function)
|
|
|
|
{
|
|
|
|
// fully_specified_type
|
|
|
|
TType* type = new TType;
|
|
|
|
if (! acceptFullySpecifiedType(*type))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// identifier
|
2016-03-14 16:46:34 +00:00
|
|
|
HlslToken idToken;
|
|
|
|
acceptIdentifier(idToken);
|
2016-03-13 23:58:25 +00:00
|
|
|
|
2016-06-19 17:50:34 +00:00
|
|
|
// array_specifier
|
|
|
|
TArraySizes* arraySizes = nullptr;
|
|
|
|
acceptArraySpecifier(arraySizes);
|
2016-09-27 16:57:35 +00:00
|
|
|
if (arraySizes) {
|
|
|
|
if (arraySizes->isImplicit()) {
|
|
|
|
parseContext.error(token.loc, "function parameter array cannot be implicitly sized", "", "");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-19 17:50:34 +00:00
|
|
|
type->newArraySizes(*arraySizes);
|
2016-09-27 16:57:35 +00:00
|
|
|
}
|
2016-06-19 17:50:34 +00:00
|
|
|
|
|
|
|
// post_decls
|
2016-09-05 18:40:06 +00:00
|
|
|
acceptPostDecls(type->getQualifier());
|
2016-06-17 20:21:02 +00:00
|
|
|
|
2016-12-24 01:56:57 +00:00
|
|
|
TIntermTyped* defaultValue;
|
|
|
|
if (!acceptDefaultParameterDeclaration(*type, defaultValue))
|
|
|
|
return false;
|
|
|
|
|
2016-06-17 21:50:47 +00:00
|
|
|
parseContext.paramFix(*type);
|
|
|
|
|
2016-12-24 01:56:57 +00:00
|
|
|
// If any prior parameters have default values, all the parameters after that must as well.
|
|
|
|
if (defaultValue == nullptr && function.getDefaultParamCount() > 0) {
|
|
|
|
parseContext.error(idToken.loc, "invalid parameter after default value parameters", idToken.string->c_str(), "");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TParameter param = { idToken.string, type, defaultValue };
|
2016-03-13 23:58:25 +00:00
|
|
|
function.addParameter(param);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do the work to create the function definition in addition to
|
|
|
|
// parsing the body (compound_statement).
|
2016-10-20 19:07:10 +00:00
|
|
|
bool HlslGrammar::acceptFunctionDefinition(TFunction& function, TIntermNode*& node, const TAttributeMap& attributes)
|
2016-03-13 23:58:25 +00:00
|
|
|
{
|
2016-09-03 01:13:36 +00:00
|
|
|
TFunction& functionDeclarator = parseContext.handleFunctionDeclarator(token.loc, function, false /* not prototype */);
|
2016-09-03 01:05:24 +00:00
|
|
|
TSourceLoc loc = token.loc;
|
2016-03-13 23:58:25 +00:00
|
|
|
|
2016-06-09 08:02:17 +00:00
|
|
|
// This does a pushScope()
|
2016-10-20 19:07:10 +00:00
|
|
|
node = parseContext.handleFunctionDefinition(loc, functionDeclarator, attributes);
|
2016-03-13 23:58:25 +00:00
|
|
|
|
|
|
|
// compound_statement
|
2016-06-04 17:46:33 +00:00
|
|
|
TIntermNode* functionBody = nullptr;
|
2016-03-13 23:58:25 +00:00
|
|
|
if (acceptCompoundStatement(functionBody)) {
|
2016-09-03 01:13:36 +00:00
|
|
|
parseContext.handleFunctionBody(loc, functionDeclarator, functionBody, node);
|
2016-03-13 23:58:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-05 17:23:11 +00:00
|
|
|
// Accept an expression with parenthesis around it, where
|
|
|
|
// the parenthesis ARE NOT expression parenthesis, but the
|
2016-06-20 07:22:38 +00:00
|
|
|
// syntactically required ones like in "if ( expression )".
|
|
|
|
//
|
|
|
|
// Also accepts a declaration expression; "if (int a = expression)".
|
2016-06-05 17:23:11 +00:00
|
|
|
//
|
|
|
|
// Note this one is not set up to be speculative; as it gives
|
|
|
|
// errors if not found.
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptParenExpression(TIntermTyped*& expression)
|
|
|
|
{
|
|
|
|
// LEFT_PAREN
|
|
|
|
if (! acceptTokenClass(EHTokLeftParen))
|
|
|
|
expected("(");
|
|
|
|
|
2016-06-20 07:22:38 +00:00
|
|
|
bool decl = false;
|
|
|
|
TIntermNode* declNode = nullptr;
|
|
|
|
decl = acceptControlDeclaration(declNode);
|
|
|
|
if (decl) {
|
|
|
|
if (declNode == nullptr || declNode->getAsTyped() == nullptr) {
|
|
|
|
expected("initialized declaration");
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
expression = declNode->getAsTyped();
|
|
|
|
} else {
|
|
|
|
// no declaration
|
|
|
|
if (! acceptExpression(expression)) {
|
|
|
|
expected("expression");
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-05 17:23:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RIGHT_PAREN
|
|
|
|
if (! acceptTokenClass(EHTokRightParen))
|
|
|
|
expected(")");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-04 05:17:20 +00:00
|
|
|
// The top-level full expression recognizer.
|
|
|
|
//
|
2016-03-13 03:24:24 +00:00
|
|
|
// expression
|
2016-05-04 05:17:20 +00:00
|
|
|
// : assignment_expression COMMA assignment_expression COMMA assignment_expression ...
|
2016-03-13 03:24:24 +00:00
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptExpression(TIntermTyped*& node)
|
|
|
|
{
|
2016-06-03 15:17:51 +00:00
|
|
|
node = nullptr;
|
|
|
|
|
2016-05-04 05:17:20 +00:00
|
|
|
// assignment_expression
|
|
|
|
if (! acceptAssignmentExpression(node))
|
|
|
|
return false;
|
2016-03-13 23:58:25 +00:00
|
|
|
|
2016-05-04 05:17:20 +00:00
|
|
|
if (! peekTokenClass(EHTokComma))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
do {
|
|
|
|
// ... COMMA
|
2016-03-13 23:58:25 +00:00
|
|
|
TSourceLoc loc = token.loc;
|
2016-05-04 05:17:20 +00:00
|
|
|
advanceToken();
|
2016-03-13 23:58:25 +00:00
|
|
|
|
2016-05-04 05:17:20 +00:00
|
|
|
// ... assignment_expression
|
|
|
|
TIntermTyped* rightNode = nullptr;
|
|
|
|
if (! acceptAssignmentExpression(rightNode)) {
|
|
|
|
expected("assignment expression");
|
|
|
|
return false;
|
2016-03-13 23:58:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 05:17:20 +00:00
|
|
|
node = intermediate.addComma(node, rightNode, loc);
|
|
|
|
|
|
|
|
if (! peekTokenClass(EHTokComma))
|
|
|
|
return true;
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
2016-07-02 01:58:06 +00:00
|
|
|
// initializer
|
2016-11-28 00:39:07 +00:00
|
|
|
// : LEFT_BRACE RIGHT_BRACE
|
|
|
|
// | LEFT_BRACE initializer_list RIGHT_BRACE
|
2016-07-02 01:58:06 +00:00
|
|
|
//
|
|
|
|
// initializer_list
|
|
|
|
// : assignment_expression COMMA assignment_expression COMMA ...
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptInitializer(TIntermTyped*& node)
|
|
|
|
{
|
|
|
|
// LEFT_BRACE
|
|
|
|
if (! acceptTokenClass(EHTokLeftBrace))
|
|
|
|
return false;
|
|
|
|
|
2016-11-28 00:39:07 +00:00
|
|
|
// RIGHT_BRACE
|
2016-07-02 01:58:06 +00:00
|
|
|
TSourceLoc loc = token.loc;
|
2016-11-28 00:39:07 +00:00
|
|
|
if (acceptTokenClass(EHTokRightBrace)) {
|
|
|
|
// a zero-length initializer list
|
|
|
|
node = intermediate.makeAggregate(loc);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// initializer_list
|
2016-07-02 01:58:06 +00:00
|
|
|
node = nullptr;
|
|
|
|
do {
|
|
|
|
// assignment_expression
|
|
|
|
TIntermTyped* expr;
|
|
|
|
if (! acceptAssignmentExpression(expr)) {
|
|
|
|
expected("assignment expression in initializer list");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
node = intermediate.growAggregate(node, expr, loc);
|
|
|
|
|
|
|
|
// COMMA
|
2016-07-30 16:36:09 +00:00
|
|
|
if (acceptTokenClass(EHTokComma)) {
|
|
|
|
if (acceptTokenClass(EHTokRightBrace)) // allow trailing comma
|
|
|
|
return true;
|
2016-07-02 01:58:06 +00:00
|
|
|
continue;
|
2016-07-30 16:36:09 +00:00
|
|
|
}
|
2016-07-02 01:58:06 +00:00
|
|
|
|
|
|
|
// RIGHT_BRACE
|
|
|
|
if (acceptTokenClass(EHTokRightBrace))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
expected(", or }");
|
|
|
|
return false;
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
2016-05-04 05:17:20 +00:00
|
|
|
// Accept an assignment expression, where assignment operations
|
2016-07-02 01:58:06 +00:00
|
|
|
// associate right-to-left. That is, it is implicit, for example
|
2016-05-04 05:17:20 +00:00
|
|
|
//
|
|
|
|
// a op (b op (c op d))
|
|
|
|
//
|
|
|
|
// assigment_expression
|
2016-07-27 16:39:57 +00:00
|
|
|
// : initializer
|
|
|
|
// | conditional_expression
|
|
|
|
// | conditional_expression assign_op conditional_expression assign_op conditional_expression ...
|
2016-05-04 05:17:20 +00:00
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptAssignmentExpression(TIntermTyped*& node)
|
|
|
|
{
|
2016-07-02 01:58:06 +00:00
|
|
|
// initializer
|
|
|
|
if (peekTokenClass(EHTokLeftBrace)) {
|
|
|
|
if (acceptInitializer(node))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
expected("initializer");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-27 16:39:57 +00:00
|
|
|
// conditional_expression
|
|
|
|
if (! acceptConditionalExpression(node))
|
2016-05-04 05:17:20 +00:00
|
|
|
return false;
|
|
|
|
|
2016-07-02 01:58:06 +00:00
|
|
|
// assignment operation?
|
2016-05-04 05:17:20 +00:00
|
|
|
TOperator assignOp = HlslOpMap::assignment(peek());
|
|
|
|
if (assignOp == EOpNull)
|
|
|
|
return true;
|
|
|
|
|
2016-07-27 16:39:57 +00:00
|
|
|
// assign_op
|
2016-05-04 05:17:20 +00:00
|
|
|
TSourceLoc loc = token.loc;
|
|
|
|
advanceToken();
|
|
|
|
|
2016-07-27 16:39:57 +00:00
|
|
|
// conditional_expression assign_op conditional_expression ...
|
|
|
|
// Done by recursing this function, which automatically
|
2016-05-04 05:17:20 +00:00
|
|
|
// gets the right-to-left associativity.
|
|
|
|
TIntermTyped* rightNode = nullptr;
|
|
|
|
if (! acceptAssignmentExpression(rightNode)) {
|
|
|
|
expected("assignment expression");
|
2016-03-13 23:58:25 +00:00
|
|
|
return false;
|
2016-03-13 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
2016-09-16 09:05:12 +00:00
|
|
|
node = parseContext.handleAssign(loc, assignOp, node, rightNode);
|
2016-10-08 01:35:40 +00:00
|
|
|
node = parseContext.handleLvalue(loc, "assign", node);
|
|
|
|
|
2016-07-28 23:53:56 +00:00
|
|
|
if (node == nullptr) {
|
|
|
|
parseContext.error(loc, "could not create assignment", "", "");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-04 05:17:20 +00:00
|
|
|
|
|
|
|
if (! peekTokenClass(EHTokComma))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-27 16:39:57 +00:00
|
|
|
// Accept a conditional expression, which associates right-to-left,
|
|
|
|
// accomplished by the "true" expression calling down to lower
|
|
|
|
// precedence levels than this level.
|
|
|
|
//
|
|
|
|
// conditional_expression
|
|
|
|
// : binary_expression
|
|
|
|
// | binary_expression QUESTION expression COLON assignment_expression
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptConditionalExpression(TIntermTyped*& node)
|
|
|
|
{
|
|
|
|
// binary_expression
|
|
|
|
if (! acceptBinaryExpression(node, PlLogicalOr))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokQuestion))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
TIntermTyped* trueNode = nullptr;
|
|
|
|
if (! acceptExpression(trueNode)) {
|
|
|
|
expected("expression after ?");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
TSourceLoc loc = token.loc;
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokColon)) {
|
|
|
|
expected(":");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TIntermTyped* falseNode = nullptr;
|
|
|
|
if (! acceptAssignmentExpression(falseNode)) {
|
|
|
|
expected("expression after :");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = intermediate.addSelection(node, trueNode, falseNode, loc);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-04 05:17:20 +00:00
|
|
|
// Accept a binary expression, for binary operations that
|
|
|
|
// associate left-to-right. This is, it is implicit, for example
|
|
|
|
//
|
|
|
|
// ((a op b) op c) op d
|
|
|
|
//
|
|
|
|
// binary_expression
|
|
|
|
// : expression op expression op expression ...
|
|
|
|
//
|
|
|
|
// where 'expression' is the next higher level in precedence.
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptBinaryExpression(TIntermTyped*& node, PrecedenceLevel precedenceLevel)
|
|
|
|
{
|
|
|
|
if (precedenceLevel > PlMul)
|
|
|
|
return acceptUnaryExpression(node);
|
|
|
|
|
|
|
|
// assignment_expression
|
|
|
|
if (! acceptBinaryExpression(node, (PrecedenceLevel)(precedenceLevel + 1)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
do {
|
2016-07-29 03:43:17 +00:00
|
|
|
TOperator op = HlslOpMap::binary(peek());
|
|
|
|
PrecedenceLevel tokenLevel = HlslOpMap::precedenceLevel(op);
|
|
|
|
if (tokenLevel < precedenceLevel)
|
|
|
|
return true;
|
|
|
|
|
2016-05-04 05:17:20 +00:00
|
|
|
// ... op
|
|
|
|
TSourceLoc loc = token.loc;
|
|
|
|
advanceToken();
|
|
|
|
|
|
|
|
// ... expression
|
|
|
|
TIntermTyped* rightNode = nullptr;
|
|
|
|
if (! acceptBinaryExpression(rightNode, (PrecedenceLevel)(precedenceLevel + 1))) {
|
|
|
|
expected("expression");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = intermediate.addBinaryMath(op, node, rightNode, loc);
|
2016-07-28 23:53:56 +00:00
|
|
|
if (node == nullptr) {
|
|
|
|
parseContext.error(loc, "Could not perform requested binary operation", "", "");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-04 05:17:20 +00:00
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// unary_expression
|
2016-06-03 22:55:49 +00:00
|
|
|
// : (type) unary_expression
|
|
|
|
// | + unary_expression
|
2016-05-04 05:17:20 +00:00
|
|
|
// | - unary_expression
|
|
|
|
// | ! unary_expression
|
|
|
|
// | ~ unary_expression
|
|
|
|
// | ++ unary_expression
|
|
|
|
// | -- unary_expression
|
|
|
|
// | postfix_expression
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptUnaryExpression(TIntermTyped*& node)
|
|
|
|
{
|
2016-06-03 22:55:49 +00:00
|
|
|
// (type) unary_expression
|
|
|
|
// Have to look two steps ahead, because this could be, e.g., a
|
|
|
|
// postfix_expression instead, since that also starts with at "(".
|
|
|
|
if (acceptTokenClass(EHTokLeftParen)) {
|
|
|
|
TType castType;
|
|
|
|
if (acceptType(castType)) {
|
2016-07-30 13:38:55 +00:00
|
|
|
if (acceptTokenClass(EHTokRightParen)) {
|
|
|
|
// We've matched "(type)" now, get the expression to cast
|
|
|
|
TSourceLoc loc = token.loc;
|
|
|
|
if (! acceptUnaryExpression(node))
|
|
|
|
return false;
|
2016-06-03 22:55:49 +00:00
|
|
|
|
2016-07-30 13:38:55 +00:00
|
|
|
// 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);
|
2016-06-03 22:55:49 +00:00
|
|
|
|
2016-07-30 13:38:55 +00:00
|
|
|
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();
|
2016-06-03 22:55:49 +00:00
|
|
|
}
|
|
|
|
} 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.
|
|
|
|
// Back it up first.
|
|
|
|
recedeToken();
|
|
|
|
return acceptPostfixExpression(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// peek for "op unary_expression"
|
2016-05-04 05:17:20 +00:00
|
|
|
TOperator unaryOp = HlslOpMap::preUnary(peek());
|
|
|
|
|
2016-06-03 22:55:49 +00:00
|
|
|
// postfix_expression (if no unary operator)
|
2016-05-04 05:17:20 +00:00
|
|
|
if (unaryOp == EOpNull)
|
|
|
|
return acceptPostfixExpression(node);
|
|
|
|
|
|
|
|
// op unary_expression
|
|
|
|
TSourceLoc loc = token.loc;
|
|
|
|
advanceToken();
|
|
|
|
if (! acceptUnaryExpression(node))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// + is a no-op
|
|
|
|
if (unaryOp == EOpAdd)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
node = intermediate.addUnaryMath(unaryOp, node, loc);
|
2016-10-15 16:29:58 +00:00
|
|
|
|
|
|
|
// These unary ops require lvalues
|
|
|
|
if (unaryOp == EOpPreIncrement || unaryOp == EOpPreDecrement)
|
|
|
|
node = parseContext.handleLvalue(loc, "unary operator", node);
|
2016-05-04 05:17:20 +00:00
|
|
|
|
|
|
|
return node != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// postfix_expression
|
|
|
|
// : LEFT_PAREN expression RIGHT_PAREN
|
|
|
|
// | literal
|
|
|
|
// | constructor
|
|
|
|
// | identifier
|
|
|
|
// | function_call
|
|
|
|
// | postfix_expression LEFT_BRACKET integer_expression RIGHT_BRACKET
|
|
|
|
// | postfix_expression DOT IDENTIFIER
|
|
|
|
// | postfix_expression INC_OP
|
|
|
|
// | postfix_expression DEC_OP
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptPostfixExpression(TIntermTyped*& node)
|
|
|
|
{
|
|
|
|
// Not implemented as self-recursive:
|
|
|
|
// The logical "right recursion" is done with an loop at the end
|
|
|
|
|
|
|
|
// idToken will pick up either a variable or a function name in a function call
|
|
|
|
HlslToken idToken;
|
|
|
|
|
2016-06-04 17:46:33 +00:00
|
|
|
// Find something before the postfix operations, as they can't operate
|
|
|
|
// on nothing. So, no "return true", they fall through, only "return false".
|
2016-03-13 03:24:24 +00:00
|
|
|
if (acceptTokenClass(EHTokLeftParen)) {
|
2016-06-04 17:46:33 +00:00
|
|
|
// LEFT_PAREN expression RIGHT_PAREN
|
2016-03-13 03:24:24 +00:00
|
|
|
if (! acceptExpression(node)) {
|
|
|
|
expected("expression");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (! acceptTokenClass(EHTokRightParen)) {
|
2016-06-05 17:23:11 +00:00
|
|
|
expected(")");
|
2016-03-13 03:24:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-04 05:17:20 +00:00
|
|
|
} else if (acceptLiteral(node)) {
|
|
|
|
// literal (nothing else to do yet), go on to the
|
|
|
|
} else if (acceptConstructor(node)) {
|
|
|
|
// constructor (nothing else to do yet)
|
|
|
|
} else if (acceptIdentifier(idToken)) {
|
|
|
|
// identifier or function_call name
|
|
|
|
if (! peekTokenClass(EHTokLeftParen)) {
|
2016-12-19 00:51:14 +00:00
|
|
|
node = parseContext.handleVariable(idToken.loc, idToken.symbol, idToken.string);
|
2016-05-04 05:17:20 +00:00
|
|
|
} else if (acceptFunctionCall(idToken, node)) {
|
|
|
|
// function_call (nothing else to do yet)
|
|
|
|
} else {
|
|
|
|
expected("function call arguments");
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-04 17:46:33 +00:00
|
|
|
} else {
|
|
|
|
// nothing found, can't post operate
|
|
|
|
return false;
|
2016-03-13 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
// This is to guarantee we do this no matter how we get out of the stack frame.
|
|
|
|
// This way there's no bug if an early return forgets to do it.
|
|
|
|
struct tFinalize {
|
|
|
|
tFinalize(HlslParseContext& p) : parseContext(p) { }
|
|
|
|
~tFinalize() { parseContext.finalizeFlattening(); }
|
|
|
|
HlslParseContext& parseContext;
|
|
|
|
} finalize(parseContext);
|
|
|
|
|
|
|
|
// Initialize the flattening accumulation data, so we can track data across multiple bracket or
|
|
|
|
// dot operators. This can also be nested, e.g, for [], so we have to track each nesting
|
|
|
|
// level: hence the init and finalize. Even though in practice these must be
|
|
|
|
// constants, they are parsed no matter what.
|
|
|
|
parseContext.initFlattening();
|
|
|
|
|
2016-06-04 17:46:33 +00:00
|
|
|
// Something was found, chain as many postfix operations as exist.
|
2016-05-04 05:17:20 +00:00
|
|
|
do {
|
|
|
|
TSourceLoc loc = token.loc;
|
|
|
|
TOperator postOp = HlslOpMap::postUnary(peek());
|
|
|
|
|
|
|
|
// Consume only a valid post-unary operator, otherwise we are done.
|
|
|
|
switch (postOp) {
|
|
|
|
case EOpIndexDirectStruct:
|
|
|
|
case EOpIndexIndirect:
|
|
|
|
case EOpPostIncrement:
|
|
|
|
case EOpPostDecrement:
|
|
|
|
advanceToken();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-13 03:24:24 +00:00
|
|
|
|
2016-05-04 05:17:20 +00:00
|
|
|
// We have a valid post-unary operator, process it.
|
|
|
|
switch (postOp) {
|
|
|
|
case EOpIndexDirectStruct:
|
2016-06-17 23:16:27 +00:00
|
|
|
{
|
2016-06-19 17:50:34 +00:00
|
|
|
// DOT IDENTIFIER
|
|
|
|
// includes swizzles and struct members
|
2016-06-17 23:16:27 +00:00
|
|
|
HlslToken field;
|
|
|
|
if (! acceptIdentifier(field)) {
|
|
|
|
expected("swizzle or member");
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-29 16:58:58 +00:00
|
|
|
|
|
|
|
TIntermTyped* base = node; // preserve for method function calls
|
2016-06-17 23:16:27 +00:00
|
|
|
node = parseContext.handleDotDereference(field.loc, node, *field.string);
|
2016-06-29 16:58:58 +00:00
|
|
|
|
|
|
|
// In the event of a method node, we look for an open paren and accept the function call.
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
if (node != nullptr && node->getAsMethodNode() != nullptr && peekTokenClass(EHTokLeftParen)) {
|
2016-06-29 16:58:58 +00:00
|
|
|
if (! acceptFunctionCall(field, node, base)) {
|
|
|
|
expected("function parameters");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-04 05:17:20 +00:00
|
|
|
break;
|
2016-06-17 23:16:27 +00:00
|
|
|
}
|
2016-05-04 05:17:20 +00:00
|
|
|
case EOpIndexIndirect:
|
|
|
|
{
|
2016-06-19 17:50:34 +00:00
|
|
|
// LEFT_BRACKET integer_expression RIGHT_BRACKET
|
2016-05-04 05:17:20 +00:00
|
|
|
TIntermTyped* indexNode = nullptr;
|
|
|
|
if (! acceptExpression(indexNode) ||
|
|
|
|
! peekTokenClass(EHTokRightBracket)) {
|
|
|
|
expected("expression followed by ']'");
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-19 17:50:34 +00:00
|
|
|
advanceToken();
|
|
|
|
node = parseContext.handleBracketDereference(indexNode->getLoc(), node, indexNode);
|
|
|
|
break;
|
2016-05-04 05:17:20 +00:00
|
|
|
}
|
|
|
|
case EOpPostIncrement:
|
2016-06-19 17:50:34 +00:00
|
|
|
// INC_OP
|
|
|
|
// fall through
|
2016-05-04 05:17:20 +00:00
|
|
|
case EOpPostDecrement:
|
2016-06-19 17:50:34 +00:00
|
|
|
// DEC_OP
|
2016-05-04 05:17:20 +00:00
|
|
|
node = intermediate.addUnaryMath(postOp, node, loc);
|
2016-10-10 16:00:14 +00:00
|
|
|
node = parseContext.handleLvalue(loc, "unary operator", node);
|
2016-05-04 05:17:20 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (true);
|
2016-03-13 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 17:24:20 +00:00
|
|
|
// constructor
|
2016-03-14 16:02:11 +00:00
|
|
|
// : type argument_list
|
2016-03-13 17:24:20 +00:00
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptConstructor(TIntermTyped*& node)
|
|
|
|
{
|
|
|
|
// type
|
|
|
|
TType type;
|
|
|
|
if (acceptType(type)) {
|
|
|
|
TFunction* constructorFunction = parseContext.handleConstructorCall(token.loc, type);
|
|
|
|
if (constructorFunction == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// arguments
|
2016-05-13 15:33:42 +00:00
|
|
|
TIntermTyped* arguments = nullptr;
|
2016-03-13 17:24:20 +00:00
|
|
|
if (! acceptArguments(constructorFunction, arguments)) {
|
|
|
|
expected("constructor arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// hook it up
|
|
|
|
node = parseContext.handleFunctionCall(arguments->getLoc(), constructorFunction, arguments);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-04 05:17:20 +00:00
|
|
|
// The function_call identifier was already recognized, and passed in as idToken.
|
|
|
|
//
|
|
|
|
// function_call
|
|
|
|
// : [idToken] arguments
|
|
|
|
//
|
2016-06-29 16:58:58 +00:00
|
|
|
bool HlslGrammar::acceptFunctionCall(HlslToken idToken, TIntermTyped*& node, TIntermTyped* base)
|
2016-05-04 05:17:20 +00:00
|
|
|
{
|
2016-05-13 15:33:42 +00:00
|
|
|
// arguments
|
|
|
|
TFunction* function = new TFunction(idToken.string, TType(EbtVoid));
|
|
|
|
TIntermTyped* arguments = nullptr;
|
2016-06-29 16:58:58 +00:00
|
|
|
|
|
|
|
// methods have an implicit first argument of the calling object.
|
|
|
|
if (base != nullptr)
|
|
|
|
parseContext.handleFunctionArgument(function, arguments, base);
|
|
|
|
|
2016-05-13 15:33:42 +00:00
|
|
|
if (! acceptArguments(function, arguments))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
node = parseContext.handleFunctionCall(idToken.loc, function, arguments);
|
|
|
|
|
|
|
|
return true;
|
2016-05-04 05:17:20 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 03:24:24 +00:00
|
|
|
// arguments
|
2016-03-14 16:02:11 +00:00
|
|
|
// : LEFT_PAREN expression COMMA expression COMMA ... RIGHT_PAREN
|
2016-03-13 03:24:24 +00:00
|
|
|
//
|
2016-03-13 17:24:20 +00:00
|
|
|
// The arguments are pushed onto the 'function' argument list and
|
|
|
|
// onto the 'arguments' aggregate.
|
|
|
|
//
|
2016-05-13 15:33:42 +00:00
|
|
|
bool HlslGrammar::acceptArguments(TFunction* function, TIntermTyped*& arguments)
|
2016-03-13 03:24:24 +00:00
|
|
|
{
|
2016-03-14 16:02:11 +00:00
|
|
|
// LEFT_PAREN
|
2016-03-13 03:24:24 +00:00
|
|
|
if (! acceptTokenClass(EHTokLeftParen))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
do {
|
2016-03-13 17:24:20 +00:00
|
|
|
// expression
|
2016-03-13 03:24:24 +00:00
|
|
|
TIntermTyped* arg;
|
2016-05-13 15:33:42 +00:00
|
|
|
if (! acceptAssignmentExpression(arg))
|
2016-03-13 03:24:24 +00:00
|
|
|
break;
|
2016-03-13 17:24:20 +00:00
|
|
|
|
|
|
|
// hook it up
|
|
|
|
parseContext.handleFunctionArgument(function, arguments, arg);
|
|
|
|
|
2016-03-14 16:02:11 +00:00
|
|
|
// COMMA
|
2016-03-13 03:24:24 +00:00
|
|
|
if (! acceptTokenClass(EHTokComma))
|
|
|
|
break;
|
|
|
|
} while (true);
|
|
|
|
|
2016-03-14 16:02:11 +00:00
|
|
|
// RIGHT_PAREN
|
2016-03-13 03:24:24 +00:00
|
|
|
if (! acceptTokenClass(EHTokRightParen)) {
|
2016-06-05 17:23:11 +00:00
|
|
|
expected(")");
|
2016-03-13 03:24:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HlslGrammar::acceptLiteral(TIntermTyped*& node)
|
|
|
|
{
|
|
|
|
switch (token.tokenClass) {
|
|
|
|
case EHTokIntConstant:
|
2016-03-14 16:02:11 +00:00
|
|
|
node = intermediate.addConstantUnion(token.i, token.loc, true);
|
2016-03-13 03:24:24 +00:00
|
|
|
break;
|
2016-07-28 20:49:48 +00:00
|
|
|
case EHTokUintConstant:
|
|
|
|
node = intermediate.addConstantUnion(token.u, token.loc, true);
|
|
|
|
break;
|
2016-03-13 03:24:24 +00:00
|
|
|
case EHTokFloatConstant:
|
2016-03-14 16:02:11 +00:00
|
|
|
node = intermediate.addConstantUnion(token.d, EbtFloat, token.loc, true);
|
2016-03-13 03:24:24 +00:00
|
|
|
break;
|
|
|
|
case EHTokDoubleConstant:
|
2016-03-14 16:02:11 +00:00
|
|
|
node = intermediate.addConstantUnion(token.d, EbtDouble, token.loc, true);
|
2016-03-13 03:24:24 +00:00
|
|
|
break;
|
|
|
|
case EHTokBoolConstant:
|
2016-03-14 16:02:11 +00:00
|
|
|
node = intermediate.addConstantUnion(token.b, token.loc, true);
|
2016-03-13 03:24:24 +00:00
|
|
|
break;
|
2016-09-20 02:23:18 +00:00
|
|
|
case EHTokStringConstant:
|
|
|
|
node = nullptr;
|
|
|
|
break;
|
2016-03-13 03:24:24 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
advanceToken();
|
2016-03-13 03:24:24 +00:00
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-13 23:58:25 +00:00
|
|
|
// compound_statement
|
2016-05-04 05:17:20 +00:00
|
|
|
// : LEFT_CURLY statement statement ... RIGHT_CURLY
|
2016-03-13 23:58:25 +00:00
|
|
|
//
|
2016-06-04 17:46:33 +00:00
|
|
|
bool HlslGrammar::acceptCompoundStatement(TIntermNode*& retStatement)
|
2016-03-13 03:24:24 +00:00
|
|
|
{
|
2016-06-04 17:46:33 +00:00
|
|
|
TIntermAggregate* compoundStatement = nullptr;
|
|
|
|
|
2016-05-04 05:17:20 +00:00
|
|
|
// LEFT_CURLY
|
2016-03-13 23:58:25 +00:00
|
|
|
if (! acceptTokenClass(EHTokLeftBrace))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// statement statement ...
|
|
|
|
TIntermNode* statement = nullptr;
|
|
|
|
while (acceptStatement(statement)) {
|
2016-07-01 06:04:11 +00:00
|
|
|
TIntermBranch* branch = statement ? statement->getAsBranchNode() : nullptr;
|
|
|
|
if (branch != nullptr && (branch->getFlowOp() == EOpCase ||
|
|
|
|
branch->getFlowOp() == EOpDefault)) {
|
|
|
|
// hook up individual subsequences within a switch statement
|
|
|
|
parseContext.wrapupSwitchSubsequence(compoundStatement, statement);
|
|
|
|
compoundStatement = nullptr;
|
|
|
|
} else {
|
|
|
|
// hook it up to the growing compound statement
|
|
|
|
compoundStatement = intermediate.growAggregate(compoundStatement, statement);
|
|
|
|
}
|
2016-03-13 23:58:25 +00:00
|
|
|
}
|
2016-05-04 05:17:20 +00:00
|
|
|
if (compoundStatement)
|
|
|
|
compoundStatement->setOperator(EOpSequence);
|
2016-03-13 23:58:25 +00:00
|
|
|
|
2016-06-04 17:46:33 +00:00
|
|
|
retStatement = compoundStatement;
|
|
|
|
|
2016-05-04 05:17:20 +00:00
|
|
|
// RIGHT_CURLY
|
2016-03-13 23:58:25 +00:00
|
|
|
return acceptTokenClass(EHTokRightBrace);
|
|
|
|
}
|
|
|
|
|
2016-06-05 17:23:11 +00:00
|
|
|
bool HlslGrammar::acceptScopedStatement(TIntermNode*& statement)
|
|
|
|
{
|
|
|
|
parseContext.pushScope();
|
2016-06-09 08:02:17 +00:00
|
|
|
bool result = acceptStatement(statement);
|
2016-06-05 17:23:11 +00:00
|
|
|
parseContext.popScope();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-06-09 08:02:17 +00:00
|
|
|
bool HlslGrammar::acceptScopedCompoundStatement(TIntermNode*& statement)
|
2016-06-05 17:23:11 +00:00
|
|
|
{
|
2016-06-09 08:02:17 +00:00
|
|
|
parseContext.pushScope();
|
|
|
|
bool result = acceptCompoundStatement(statement);
|
|
|
|
parseContext.popScope();
|
2016-06-05 17:23:11 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-13 23:58:25 +00:00
|
|
|
// statement
|
2016-06-04 17:46:33 +00:00
|
|
|
// : attributes attributed_statement
|
|
|
|
//
|
|
|
|
// attributed_statement
|
2016-03-13 23:58:25 +00:00
|
|
|
// : compound_statement
|
2016-06-04 17:46:33 +00:00
|
|
|
// | SEMICOLON
|
2016-03-14 16:02:11 +00:00
|
|
|
// | expression SEMICOLON
|
2016-06-04 17:46:33 +00:00
|
|
|
// | declaration_statement
|
|
|
|
// | selection_statement
|
|
|
|
// | switch_statement
|
|
|
|
// | case_label
|
|
|
|
// | iteration_statement
|
|
|
|
// | jump_statement
|
2016-03-13 23:58:25 +00:00
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptStatement(TIntermNode*& statement)
|
|
|
|
{
|
2016-06-04 17:46:33 +00:00
|
|
|
statement = nullptr;
|
2016-03-13 23:58:25 +00:00
|
|
|
|
2016-06-04 17:46:33 +00:00
|
|
|
// attributes
|
2016-10-20 19:07:10 +00:00
|
|
|
TAttributeMap attributes;
|
|
|
|
acceptAttributes(attributes);
|
2016-03-13 23:58:25 +00:00
|
|
|
|
2016-06-04 17:46:33 +00:00
|
|
|
// attributed_statement
|
|
|
|
switch (peek()) {
|
|
|
|
case EHTokLeftBrace:
|
2016-06-09 08:02:17 +00:00
|
|
|
return acceptScopedCompoundStatement(statement);
|
2016-03-13 23:58:25 +00:00
|
|
|
|
2016-06-04 17:46:33 +00:00
|
|
|
case EHTokIf:
|
|
|
|
return acceptSelectionStatement(statement);
|
2016-03-13 23:58:25 +00:00
|
|
|
|
2016-06-04 17:46:33 +00:00
|
|
|
case EHTokSwitch:
|
|
|
|
return acceptSwitchStatement(statement);
|
2016-03-13 23:58:25 +00:00
|
|
|
|
2016-06-04 17:46:33 +00:00
|
|
|
case EHTokFor:
|
|
|
|
case EHTokDo:
|
|
|
|
case EHTokWhile:
|
|
|
|
return acceptIterationStatement(statement);
|
|
|
|
|
|
|
|
case EHTokContinue:
|
|
|
|
case EHTokBreak:
|
|
|
|
case EHTokDiscard:
|
|
|
|
case EHTokReturn:
|
|
|
|
return acceptJumpStatement(statement);
|
|
|
|
|
|
|
|
case EHTokCase:
|
|
|
|
return acceptCaseLabel(statement);
|
2016-07-01 06:04:11 +00:00
|
|
|
case EHTokDefault:
|
|
|
|
return acceptDefaultLabel(statement);
|
2016-06-04 17:46:33 +00:00
|
|
|
|
|
|
|
case EHTokSemicolon:
|
|
|
|
return acceptTokenClass(EHTokSemicolon);
|
|
|
|
|
|
|
|
case EHTokRightBrace:
|
|
|
|
// Performance: not strictly necessary, but stops a bunch of hunting early,
|
|
|
|
// and is how sequences of statements end.
|
2016-03-13 23:58:25 +00:00
|
|
|
return false;
|
|
|
|
|
2016-06-04 17:46:33 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
// declaration
|
|
|
|
if (acceptDeclaration(statement))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// expression
|
|
|
|
TIntermTyped* node;
|
|
|
|
if (acceptExpression(node))
|
|
|
|
statement = node;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// SEMICOLON (following an expression)
|
|
|
|
if (! acceptTokenClass(EHTokSemicolon)) {
|
2016-06-05 17:23:11 +00:00
|
|
|
expected(";");
|
2016-06-04 17:46:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-13 23:58:25 +00:00
|
|
|
return true;
|
2016-03-13 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
2016-06-04 17:46:33 +00:00
|
|
|
// attributes
|
|
|
|
// : list of zero or more of: LEFT_BRACKET attribute RIGHT_BRACKET
|
|
|
|
//
|
|
|
|
// attribute:
|
|
|
|
// : UNROLL
|
|
|
|
// | UNROLL LEFT_PAREN literal RIGHT_PAREN
|
|
|
|
// | FASTOPT
|
|
|
|
// | ALLOW_UAV_CONDITION
|
|
|
|
// | BRANCH
|
|
|
|
// | FLATTEN
|
|
|
|
// | FORCECASE
|
|
|
|
// | CALL
|
2016-10-20 19:07:10 +00:00
|
|
|
// | DOMAIN
|
|
|
|
// | EARLYDEPTHSTENCIL
|
|
|
|
// | INSTANCE
|
|
|
|
// | MAXTESSFACTOR
|
|
|
|
// | OUTPUTCONTROLPOINTS
|
|
|
|
// | OUTPUTTOPOLOGY
|
|
|
|
// | PARTITIONING
|
|
|
|
// | PATCHCONSTANTFUNC
|
|
|
|
// | NUMTHREADS LEFT_PAREN x_size, y_size,z z_size RIGHT_PAREN
|
|
|
|
//
|
|
|
|
void HlslGrammar::acceptAttributes(TAttributeMap& attributes)
|
2016-06-04 17:46:33 +00:00
|
|
|
{
|
2016-10-20 19:07:10 +00:00
|
|
|
// For now, accept the [ XXX(X) ] syntax, but drop all but
|
|
|
|
// numthreads, which is used to set the CS local size.
|
2016-06-05 17:23:11 +00:00
|
|
|
// TODO: subset to correct set? Pass on?
|
|
|
|
do {
|
2016-10-20 19:07:10 +00:00
|
|
|
HlslToken idToken;
|
|
|
|
|
2016-06-05 17:23:11 +00:00
|
|
|
// LEFT_BRACKET?
|
|
|
|
if (! acceptTokenClass(EHTokLeftBracket))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// attribute
|
2016-10-20 19:07:10 +00:00
|
|
|
if (acceptIdentifier(idToken)) {
|
|
|
|
// 'idToken.string' is the attribute
|
2016-06-05 17:23:11 +00:00
|
|
|
} else if (! peekTokenClass(EHTokRightBracket)) {
|
|
|
|
expected("identifier");
|
|
|
|
advanceToken();
|
|
|
|
}
|
|
|
|
|
2016-11-11 15:17:44 +00:00
|
|
|
TIntermAggregate* expressions = nullptr;
|
2016-10-20 19:07:10 +00:00
|
|
|
|
|
|
|
// (x, ...)
|
2016-06-05 17:23:11 +00:00
|
|
|
if (acceptTokenClass(EHTokLeftParen)) {
|
2016-11-11 15:17:44 +00:00
|
|
|
expressions = new TIntermAggregate;
|
2016-10-20 19:07:10 +00:00
|
|
|
|
2016-06-05 17:23:11 +00:00
|
|
|
TIntermTyped* node;
|
2016-11-11 15:17:44 +00:00
|
|
|
bool expectingExpression = false;
|
2016-10-20 19:07:10 +00:00
|
|
|
|
2016-11-11 15:17:44 +00:00
|
|
|
while (acceptAssignmentExpression(node)) {
|
|
|
|
expectingExpression = false;
|
|
|
|
expressions->getSequence().push_back(node);
|
2016-10-20 19:07:10 +00:00
|
|
|
if (acceptTokenClass(EHTokComma))
|
2016-11-11 15:17:44 +00:00
|
|
|
expectingExpression = true;
|
2016-10-20 19:07:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-11 15:17:44 +00:00
|
|
|
// 'expressions' is an aggregate with the expressions in it
|
2016-06-05 17:23:11 +00:00
|
|
|
if (! acceptTokenClass(EHTokRightParen))
|
|
|
|
expected(")");
|
2016-11-11 15:17:44 +00:00
|
|
|
|
|
|
|
// Error for partial or missing expression
|
|
|
|
if (expectingExpression || expressions->getSequence().empty())
|
|
|
|
expected("expression");
|
2016-06-05 17:23:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RIGHT_BRACKET
|
2016-10-20 19:07:10 +00:00
|
|
|
if (!acceptTokenClass(EHTokRightBracket)) {
|
|
|
|
expected("]");
|
|
|
|
return;
|
|
|
|
}
|
2016-06-05 17:23:11 +00:00
|
|
|
|
2016-10-20 19:07:10 +00:00
|
|
|
// Add any values we found into the attribute map. This accepts
|
|
|
|
// (and ignores) values not mapping to a known TAttributeType;
|
2016-11-11 15:17:44 +00:00
|
|
|
attributes.setAttribute(idToken.string, expressions);
|
2016-06-05 17:23:11 +00:00
|
|
|
} while (true);
|
2016-06-04 17:46:33 +00:00
|
|
|
}
|
|
|
|
|
2016-06-05 17:23:11 +00:00
|
|
|
// selection_statement
|
|
|
|
// : IF LEFT_PAREN expression RIGHT_PAREN statement
|
|
|
|
// : IF LEFT_PAREN expression RIGHT_PAREN statement ELSE statement
|
|
|
|
//
|
2016-06-04 17:46:33 +00:00
|
|
|
bool HlslGrammar::acceptSelectionStatement(TIntermNode*& statement)
|
|
|
|
{
|
2016-06-05 17:23:11 +00:00
|
|
|
TSourceLoc loc = token.loc;
|
|
|
|
|
|
|
|
// IF
|
|
|
|
if (! acceptTokenClass(EHTokIf))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// so that something declared in the condition is scoped to the lifetimes
|
|
|
|
// of the then-else statements
|
|
|
|
parseContext.pushScope();
|
|
|
|
|
|
|
|
// LEFT_PAREN expression RIGHT_PAREN
|
|
|
|
TIntermTyped* condition;
|
|
|
|
if (! acceptParenExpression(condition))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// create the child statements
|
|
|
|
TIntermNodePair thenElse = { nullptr, nullptr };
|
|
|
|
|
|
|
|
// then statement
|
|
|
|
if (! acceptScopedStatement(thenElse.node1)) {
|
|
|
|
expected("then statement");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ELSE
|
|
|
|
if (acceptTokenClass(EHTokElse)) {
|
|
|
|
// else statement
|
|
|
|
if (! acceptScopedStatement(thenElse.node2)) {
|
|
|
|
expected("else statement");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put the pieces together
|
|
|
|
statement = intermediate.addSelection(condition, thenElse, loc);
|
|
|
|
parseContext.popScope();
|
|
|
|
|
|
|
|
return true;
|
2016-06-04 17:46:33 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 06:04:11 +00:00
|
|
|
// switch_statement
|
|
|
|
// : SWITCH LEFT_PAREN expression RIGHT_PAREN compound_statement
|
|
|
|
//
|
2016-06-04 17:46:33 +00:00
|
|
|
bool HlslGrammar::acceptSwitchStatement(TIntermNode*& statement)
|
|
|
|
{
|
2016-07-01 06:04:11 +00:00
|
|
|
// SWITCH
|
|
|
|
TSourceLoc loc = token.loc;
|
|
|
|
if (! acceptTokenClass(EHTokSwitch))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// LEFT_PAREN expression RIGHT_PAREN
|
|
|
|
parseContext.pushScope();
|
|
|
|
TIntermTyped* switchExpression;
|
|
|
|
if (! acceptParenExpression(switchExpression)) {
|
|
|
|
parseContext.popScope();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// compound_statement
|
|
|
|
parseContext.pushSwitchSequence(new TIntermSequence);
|
|
|
|
bool statementOkay = acceptCompoundStatement(statement);
|
|
|
|
if (statementOkay)
|
|
|
|
statement = parseContext.addSwitch(loc, switchExpression, statement ? statement->getAsAggregate() : nullptr);
|
|
|
|
|
|
|
|
parseContext.popSwitchSequence();
|
|
|
|
parseContext.popScope();
|
|
|
|
|
|
|
|
return statementOkay;
|
2016-06-04 17:46:33 +00:00
|
|
|
}
|
|
|
|
|
2016-06-05 21:44:07 +00:00
|
|
|
// iteration_statement
|
|
|
|
// : WHILE LEFT_PAREN condition RIGHT_PAREN statement
|
|
|
|
// | DO LEFT_BRACE statement RIGHT_BRACE WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON
|
|
|
|
// | FOR LEFT_PAREN for_init_statement for_rest_statement RIGHT_PAREN statement
|
|
|
|
//
|
|
|
|
// Non-speculative, only call if it needs to be found; WHILE or DO or FOR already seen.
|
2016-06-04 17:46:33 +00:00
|
|
|
bool HlslGrammar::acceptIterationStatement(TIntermNode*& statement)
|
|
|
|
{
|
2016-06-05 21:44:07 +00:00
|
|
|
TSourceLoc loc = token.loc;
|
|
|
|
TIntermTyped* condition = nullptr;
|
|
|
|
|
|
|
|
EHlslTokenClass loop = peek();
|
|
|
|
assert(loop == EHTokDo || loop == EHTokFor || loop == EHTokWhile);
|
|
|
|
|
|
|
|
// WHILE or DO or FOR
|
|
|
|
advanceToken();
|
|
|
|
|
|
|
|
switch (loop) {
|
|
|
|
case EHTokWhile:
|
|
|
|
// so that something declared in the condition is scoped to the lifetime
|
|
|
|
// of the while sub-statement
|
|
|
|
parseContext.pushScope();
|
|
|
|
parseContext.nestLooping();
|
|
|
|
|
|
|
|
// LEFT_PAREN condition RIGHT_PAREN
|
|
|
|
if (! acceptParenExpression(condition))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// statement
|
|
|
|
if (! acceptScopedStatement(statement)) {
|
|
|
|
expected("while sub-statement");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
parseContext.unnestLooping();
|
|
|
|
parseContext.popScope();
|
|
|
|
|
|
|
|
statement = intermediate.addLoop(statement, condition, nullptr, true, loc);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case EHTokDo:
|
|
|
|
parseContext.nestLooping();
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokLeftBrace))
|
|
|
|
expected("{");
|
|
|
|
|
|
|
|
// statement
|
|
|
|
if (! peekTokenClass(EHTokRightBrace) && ! acceptScopedStatement(statement)) {
|
|
|
|
expected("do sub-statement");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokRightBrace))
|
|
|
|
expected("}");
|
|
|
|
|
|
|
|
// WHILE
|
|
|
|
if (! acceptTokenClass(EHTokWhile)) {
|
|
|
|
expected("while");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// LEFT_PAREN condition RIGHT_PAREN
|
|
|
|
TIntermTyped* condition;
|
|
|
|
if (! acceptParenExpression(condition))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokSemicolon))
|
|
|
|
expected(";");
|
|
|
|
|
|
|
|
parseContext.unnestLooping();
|
|
|
|
|
|
|
|
statement = intermediate.addLoop(statement, condition, 0, false, loc);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case EHTokFor:
|
|
|
|
{
|
|
|
|
// LEFT_PAREN
|
|
|
|
if (! acceptTokenClass(EHTokLeftParen))
|
|
|
|
expected("(");
|
|
|
|
|
|
|
|
// so that something declared in the condition is scoped to the lifetime
|
|
|
|
// of the for sub-statement
|
|
|
|
parseContext.pushScope();
|
|
|
|
|
2016-06-20 07:22:38 +00:00
|
|
|
// initializer
|
|
|
|
TIntermNode* initNode = nullptr;
|
|
|
|
if (! acceptControlDeclaration(initNode)) {
|
|
|
|
TIntermTyped* initExpr = nullptr;
|
|
|
|
acceptExpression(initExpr);
|
|
|
|
initNode = initExpr;
|
|
|
|
}
|
|
|
|
// SEMI_COLON
|
2016-06-05 21:44:07 +00:00
|
|
|
if (! acceptTokenClass(EHTokSemicolon))
|
|
|
|
expected(";");
|
|
|
|
|
|
|
|
parseContext.nestLooping();
|
|
|
|
|
|
|
|
// condition SEMI_COLON
|
|
|
|
acceptExpression(condition);
|
|
|
|
if (! acceptTokenClass(EHTokSemicolon))
|
|
|
|
expected(";");
|
|
|
|
|
|
|
|
// iterator SEMI_COLON
|
|
|
|
TIntermTyped* iterator = nullptr;
|
|
|
|
acceptExpression(iterator);
|
|
|
|
if (! acceptTokenClass(EHTokRightParen))
|
|
|
|
expected(")");
|
|
|
|
|
|
|
|
// statement
|
|
|
|
if (! acceptScopedStatement(statement)) {
|
|
|
|
expected("for sub-statement");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-20 07:22:38 +00:00
|
|
|
statement = intermediate.addForLoop(statement, initNode, condition, iterator, true, loc);
|
2016-06-05 21:44:07 +00:00
|
|
|
|
|
|
|
parseContext.popScope();
|
|
|
|
parseContext.unnestLooping();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-04 17:46:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// jump_statement
|
|
|
|
// : CONTINUE SEMICOLON
|
|
|
|
// | BREAK SEMICOLON
|
|
|
|
// | DISCARD SEMICOLON
|
|
|
|
// | RETURN SEMICOLON
|
|
|
|
// | RETURN expression SEMICOLON
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptJumpStatement(TIntermNode*& statement)
|
|
|
|
{
|
2016-06-20 07:22:38 +00:00
|
|
|
EHlslTokenClass jump = peek();
|
|
|
|
switch (jump) {
|
2016-06-04 17:46:33 +00:00
|
|
|
case EHTokContinue:
|
|
|
|
case EHTokBreak:
|
|
|
|
case EHTokDiscard:
|
|
|
|
case EHTokReturn:
|
2016-06-20 07:22:38 +00:00
|
|
|
advanceToken();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// not something we handle in this function
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-04 17:46:33 +00:00
|
|
|
|
2016-06-20 07:22:38 +00:00
|
|
|
switch (jump) {
|
|
|
|
case EHTokContinue:
|
|
|
|
statement = intermediate.addBranch(EOpContinue, token.loc);
|
|
|
|
break;
|
|
|
|
case EHTokBreak:
|
|
|
|
statement = intermediate.addBranch(EOpBreak, token.loc);
|
|
|
|
break;
|
|
|
|
case EHTokDiscard:
|
|
|
|
statement = intermediate.addBranch(EOpKill, token.loc);
|
|
|
|
break;
|
2016-06-04 17:46:33 +00:00
|
|
|
|
2016-06-20 07:22:38 +00:00
|
|
|
case EHTokReturn:
|
|
|
|
{
|
|
|
|
// expression
|
|
|
|
TIntermTyped* node;
|
|
|
|
if (acceptExpression(node)) {
|
|
|
|
// hook it up
|
2016-08-09 17:28:03 +00:00
|
|
|
statement = parseContext.handleReturnValue(token.loc, node);
|
2016-06-20 07:22:38 +00:00
|
|
|
} else
|
|
|
|
statement = intermediate.addBranch(EOpReturn, token.loc);
|
|
|
|
break;
|
|
|
|
}
|
2016-06-04 17:46:33 +00:00
|
|
|
|
|
|
|
default:
|
2016-06-20 07:22:38 +00:00
|
|
|
assert(0);
|
2016-06-04 17:46:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-20 07:22:38 +00:00
|
|
|
// SEMICOLON
|
|
|
|
if (! acceptTokenClass(EHTokSemicolon))
|
|
|
|
expected(";");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-04 17:46:33 +00:00
|
|
|
|
2016-07-01 06:04:11 +00:00
|
|
|
// case_label
|
|
|
|
// : CASE expression COLON
|
|
|
|
//
|
2016-06-04 17:46:33 +00:00
|
|
|
bool HlslGrammar::acceptCaseLabel(TIntermNode*& statement)
|
|
|
|
{
|
2016-07-01 06:04:11 +00:00
|
|
|
TSourceLoc loc = token.loc;
|
|
|
|
if (! acceptTokenClass(EHTokCase))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TIntermTyped* expression;
|
|
|
|
if (! acceptExpression(expression)) {
|
|
|
|
expected("case expression");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokColon)) {
|
|
|
|
expected(":");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
statement = parseContext.intermediate.addBranch(EOpCase, expression, loc);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// default_label
|
|
|
|
// : DEFAULT COLON
|
|
|
|
//
|
|
|
|
bool HlslGrammar::acceptDefaultLabel(TIntermNode*& statement)
|
|
|
|
{
|
|
|
|
TSourceLoc loc = token.loc;
|
|
|
|
if (! acceptTokenClass(EHTokDefault))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (! acceptTokenClass(EHTokColon)) {
|
|
|
|
expected(":");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
statement = parseContext.intermediate.addBranch(EOpDefault, loc);
|
|
|
|
|
|
|
|
return true;
|
2016-06-04 17:46:33 +00:00
|
|
|
}
|
|
|
|
|
2016-06-19 17:50:34 +00:00
|
|
|
// array_specifier
|
2016-10-13 18:26:18 +00:00
|
|
|
// : LEFT_BRACKET integer_expression RGHT_BRACKET ... // optional
|
|
|
|
// : LEFT_BRACKET RGHT_BRACKET // optional
|
2016-06-19 17:50:34 +00:00
|
|
|
//
|
|
|
|
void HlslGrammar::acceptArraySpecifier(TArraySizes*& arraySizes)
|
|
|
|
{
|
|
|
|
arraySizes = nullptr;
|
|
|
|
|
2016-10-13 18:26:18 +00:00
|
|
|
// Early-out if there aren't any array dimensions
|
|
|
|
if (!peekTokenClass(EHTokLeftBracket))
|
2016-06-19 17:50:34 +00:00
|
|
|
return;
|
|
|
|
|
2016-10-13 18:26:18 +00:00
|
|
|
// If we get here, we have at least one array dimension. This will track the sizes we find.
|
|
|
|
arraySizes = new TArraySizes;
|
2016-09-27 16:57:35 +00:00
|
|
|
|
2016-10-13 18:26:18 +00:00
|
|
|
// Collect each array dimension.
|
|
|
|
while (acceptTokenClass(EHTokLeftBracket)) {
|
|
|
|
TSourceLoc loc = token.loc;
|
|
|
|
TIntermTyped* sizeExpr = nullptr;
|
2016-06-19 17:50:34 +00:00
|
|
|
|
2016-10-13 18:26:18 +00:00
|
|
|
// Array sizing expression is optional. If ommitted, array will be later sized by initializer list.
|
|
|
|
const bool hasArraySize = acceptAssignmentExpression(sizeExpr);
|
2016-06-19 17:50:34 +00:00
|
|
|
|
2016-10-13 18:26:18 +00:00
|
|
|
if (! acceptTokenClass(EHTokRightBracket)) {
|
|
|
|
expected("]");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasArraySize) {
|
|
|
|
TArraySize arraySize;
|
|
|
|
parseContext.arraySizeCheck(loc, sizeExpr, arraySize);
|
|
|
|
arraySizes->addInnerSize(arraySize);
|
|
|
|
} else {
|
|
|
|
arraySizes->addInnerSize(0); // sized by initializers.
|
|
|
|
}
|
2016-09-27 16:57:35 +00:00
|
|
|
}
|
2016-06-19 17:50:34 +00:00
|
|
|
}
|
|
|
|
|
2016-06-13 05:52:12 +00:00
|
|
|
// post_decls
|
2016-09-05 22:03:12 +00:00
|
|
|
// : COLON semantic // optional
|
|
|
|
// COLON PACKOFFSET LEFT_PAREN c[Subcomponent][.component] RIGHT_PAREN // optional
|
|
|
|
// COLON REGISTER LEFT_PAREN [shader_profile,] Type#[subcomp]opt (COMMA SPACEN)opt RIGHT_PAREN // optional
|
2016-09-05 20:37:03 +00:00
|
|
|
// COLON LAYOUT layout_qualifier_list
|
2016-09-05 22:03:12 +00:00
|
|
|
// annotations // optional
|
2016-06-13 05:52:12 +00:00
|
|
|
//
|
2016-09-05 18:40:06 +00:00
|
|
|
void HlslGrammar::acceptPostDecls(TQualifier& qualifier)
|
2016-03-14 16:02:11 +00:00
|
|
|
{
|
2016-06-13 05:52:12 +00:00
|
|
|
do {
|
|
|
|
// COLON
|
|
|
|
if (acceptTokenClass(EHTokColon)) {
|
|
|
|
HlslToken idToken;
|
2016-09-05 20:37:03 +00:00
|
|
|
if (peekTokenClass(EHTokLayout))
|
|
|
|
acceptLayoutQualifierList(qualifier);
|
|
|
|
else if (acceptTokenClass(EHTokPackOffset)) {
|
2016-07-29 20:28:39 +00:00
|
|
|
// PACKOFFSET LEFT_PAREN c[Subcomponent][.component] RIGHT_PAREN
|
2016-06-13 05:52:12 +00:00
|
|
|
if (! acceptTokenClass(EHTokLeftParen)) {
|
|
|
|
expected("(");
|
|
|
|
return;
|
|
|
|
}
|
2016-07-29 19:03:05 +00:00
|
|
|
HlslToken locationToken;
|
|
|
|
if (! acceptIdentifier(locationToken)) {
|
|
|
|
expected("c[subcomponent][.component]");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
HlslToken componentToken;
|
|
|
|
if (acceptTokenClass(EHTokDot)) {
|
|
|
|
if (! acceptIdentifier(componentToken)) {
|
|
|
|
expected("component");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-06-13 05:52:12 +00:00
|
|
|
if (! acceptTokenClass(EHTokRightParen)) {
|
|
|
|
expected(")");
|
|
|
|
break;
|
|
|
|
}
|
2016-09-05 18:40:06 +00:00
|
|
|
parseContext.handlePackOffset(locationToken.loc, qualifier, *locationToken.string, componentToken.string);
|
2016-06-13 05:52:12 +00:00
|
|
|
} else if (! acceptIdentifier(idToken)) {
|
2016-09-05 20:37:03 +00:00
|
|
|
expected("layout, semantic, packoffset, or register");
|
2016-06-13 05:52:12 +00:00
|
|
|
return;
|
|
|
|
} else if (*idToken.string == "register") {
|
2016-09-05 22:03:12 +00:00
|
|
|
// REGISTER LEFT_PAREN [shader_profile,] Type#[subcomp]opt (COMMA SPACEN)opt RIGHT_PAREN
|
|
|
|
// LEFT_PAREN
|
2016-06-13 05:52:12 +00:00
|
|
|
if (! acceptTokenClass(EHTokLeftParen)) {
|
|
|
|
expected("(");
|
|
|
|
return;
|
|
|
|
}
|
2016-07-30 16:29:54 +00:00
|
|
|
HlslToken registerDesc; // for Type#
|
|
|
|
HlslToken profile;
|
2016-07-29 20:28:39 +00:00
|
|
|
if (! acceptIdentifier(registerDesc)) {
|
|
|
|
expected("register number description");
|
|
|
|
return;
|
|
|
|
}
|
2016-09-05 22:03:12 +00:00
|
|
|
if (registerDesc.string->size() > 1 && !isdigit((*registerDesc.string)[1]) &&
|
|
|
|
acceptTokenClass(EHTokComma)) {
|
2016-07-30 16:29:54 +00:00
|
|
|
// Then we didn't really see the registerDesc yet, it was
|
|
|
|
// actually the profile. Adjust...
|
2016-07-29 20:28:39 +00:00
|
|
|
profile = registerDesc;
|
|
|
|
if (! acceptIdentifier(registerDesc)) {
|
|
|
|
expected("register number description");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-07-30 16:29:54 +00:00
|
|
|
int subComponent = 0;
|
|
|
|
if (acceptTokenClass(EHTokLeftBracket)) {
|
|
|
|
// LEFT_BRACKET subcomponent RIGHT_BRACKET
|
|
|
|
if (! peekTokenClass(EHTokIntConstant)) {
|
|
|
|
expected("literal integer");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
subComponent = token.i;
|
|
|
|
advanceToken();
|
|
|
|
if (! acceptTokenClass(EHTokRightBracket)) {
|
|
|
|
expected("]");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-05 22:03:12 +00:00
|
|
|
// (COMMA SPACEN)opt
|
|
|
|
HlslToken spaceDesc;
|
|
|
|
if (acceptTokenClass(EHTokComma)) {
|
|
|
|
if (! acceptIdentifier(spaceDesc)) {
|
|
|
|
expected ("space identifier");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// RIGHT_PAREN
|
2016-06-13 05:52:12 +00:00
|
|
|
if (! acceptTokenClass(EHTokRightParen)) {
|
|
|
|
expected(")");
|
|
|
|
break;
|
|
|
|
}
|
2016-09-05 22:03:12 +00:00
|
|
|
parseContext.handleRegister(registerDesc.loc, qualifier, profile.string, *registerDesc.string, subComponent, spaceDesc.string);
|
2016-06-13 05:52:12 +00:00
|
|
|
} else {
|
|
|
|
// semantic, in idToken.string
|
2016-09-05 18:40:06 +00:00
|
|
|
parseContext.handleSemantic(idToken.loc, qualifier, *idToken.string);
|
2016-06-13 05:52:12 +00:00
|
|
|
}
|
2016-09-20 19:22:58 +00:00
|
|
|
} else if (peekTokenClass(EHTokLeftAngle))
|
|
|
|
acceptAnnotations(qualifier);
|
|
|
|
else
|
2016-06-13 05:52:12 +00:00
|
|
|
break;
|
2016-03-14 16:02:11 +00:00
|
|
|
|
2016-06-13 05:52:12 +00:00
|
|
|
} while (true);
|
2016-03-14 16:02:11 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
} // end namespace glslang
|