John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 1 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 2 | // Copyright (C) 2016 Google, Inc. |
| 3 | // Copyright (C) 2016 LunarG, Inc. |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 4 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 5 | // All rights reserved. |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 6 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 7 | // Redistribution and use in source and binary forms, with or without |
| 8 | // modification, are permitted provided that the following conditions |
| 9 | // are met: |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 10 | // |
| 11 | // Redistributions of source code must retain the above copyright |
| 12 | // notice, this list of conditions and the following disclaimer. |
| 13 | // |
| 14 | // Redistributions in binary form must reproduce the above |
| 15 | // copyright notice, this list of conditions and the following |
| 16 | // disclaimer in the documentation and/or other materials provided |
| 17 | // with the distribution. |
| 18 | // |
| 19 | // Neither the name of Google, Inc., nor the names of its |
| 20 | // contributors may be used to endorse or promote products derived |
| 21 | // from this software without specific prior written permission. |
| 22 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 26 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 27 | // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 28 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 29 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 30 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 31 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 32 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 33 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 34 | // POSSIBILITY OF SUCH DAMAGE. |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 35 | // |
| 36 | |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 37 | // |
| 38 | // This is a set of mutually recursive methods implementing the HLSL grammar. |
| 39 | // Generally, each returns |
| 40 | // - through an argument: a type specifically appropriate to which rule it |
| 41 | // recognized |
| 42 | // - through the return value: true/false to indicate whether or not it |
| 43 | // recognized its rule |
| 44 | // |
| 45 | // As much as possible, only grammar recognition should happen in this file, |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 46 | // with all other work being farmed out to hlslParseHelper.cpp, which in turn |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 47 | // will build the AST. |
| 48 | // |
| 49 | // The next token, yet to be "accepted" is always sitting in 'token'. |
| 50 | // When a method says it accepts a rule, that means all tokens involved |
| 51 | // in the rule will have been consumed, and none left in 'token'. |
| 52 | // |
| 53 | |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 54 | #include "hlslTokens.h" |
| 55 | #include "hlslGrammar.h" |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 56 | #include "hlslAttributes.h" |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 57 | |
| 58 | namespace glslang { |
| 59 | |
| 60 | // Root entry point to this recursive decent parser. |
| 61 | // Return true if compilation unit was successfully accepted. |
| 62 | bool HlslGrammar::parse() |
| 63 | { |
| 64 | advanceToken(); |
| 65 | return acceptCompilationUnit(); |
| 66 | } |
| 67 | |
| 68 | void HlslGrammar::expected(const char* syntax) |
| 69 | { |
| 70 | parseContext.error(token.loc, "Expected", syntax, ""); |
| 71 | } |
| 72 | |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 73 | void HlslGrammar::unimplemented(const char* error) |
| 74 | { |
| 75 | parseContext.error(token.loc, "Unimplemented", error, ""); |
| 76 | } |
| 77 | |
John Kessenich | aecd497 | 2016-03-14 10:46:34 -0600 | [diff] [blame] | 78 | // Only process the next token if it is an identifier. |
| 79 | // Return true if it was an identifier. |
| 80 | bool HlslGrammar::acceptIdentifier(HlslToken& idToken) |
| 81 | { |
| 82 | if (peekTokenClass(EHTokIdentifier)) { |
| 83 | idToken = token; |
| 84 | advanceToken(); |
| 85 | return true; |
| 86 | } |
| 87 | |
steve-lunarg | 5ca85ad | 2016-12-26 18:45:52 -0700 | [diff] [blame] | 88 | // Even though "sample", "bool", "float", etc keywords (for types, interpolation modifiers), |
| 89 | // they ARE still accepted as identifiers. This is not a dense space: e.g, "void" is not a |
| 90 | // valid identifier, nor is "linear". This code special cases the known instances of this, so |
| 91 | // e.g, "int sample;" or "float float;" is accepted. Other cases can be added here if needed. |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 92 | |
steve-lunarg | 5ca85ad | 2016-12-26 18:45:52 -0700 | [diff] [blame] | 93 | TString* idString = nullptr; |
| 94 | switch (peek()) { |
| 95 | case EHTokSample: idString = NewPoolTString("sample"); break; |
| 96 | case EHTokHalf: idString = NewPoolTString("half"); break; |
| 97 | case EHTokBool: idString = NewPoolTString("bool"); break; |
| 98 | case EHTokFloat: idString = NewPoolTString("float"); break; |
| 99 | case EHTokDouble: idString = NewPoolTString("double"); break; |
| 100 | case EHTokInt: idString = NewPoolTString("int"); break; |
| 101 | case EHTokUint: idString = NewPoolTString("uint"); break; |
| 102 | case EHTokMin16float: idString = NewPoolTString("min16float"); break; |
| 103 | case EHTokMin10float: idString = NewPoolTString("min10float"); break; |
| 104 | case EHTokMin16int: idString = NewPoolTString("min16int"); break; |
| 105 | case EHTokMin12int: idString = NewPoolTString("min12int"); break; |
| 106 | default: |
| 107 | return false; |
steve-lunarg | 75fd223 | 2016-11-16 13:22:11 -0700 | [diff] [blame] | 108 | } |
| 109 | |
steve-lunarg | 5ca85ad | 2016-12-26 18:45:52 -0700 | [diff] [blame] | 110 | token.string = idString; |
| 111 | token.tokenClass = EHTokIdentifier; |
| 112 | token.symbol = nullptr; |
| 113 | idToken = token; |
| 114 | |
| 115 | advanceToken(); |
| 116 | |
| 117 | return true; |
John Kessenich | aecd497 | 2016-03-14 10:46:34 -0600 | [diff] [blame] | 118 | } |
| 119 | |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 120 | // compilationUnit |
| 121 | // : list of externalDeclaration |
steve-lunarg | cb88de5 | 2016-08-03 07:04:18 -0600 | [diff] [blame] | 122 | // | SEMICOLONS |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 123 | // |
| 124 | bool HlslGrammar::acceptCompilationUnit() |
| 125 | { |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 126 | TIntermNode* unitNode = nullptr; |
| 127 | |
John Kessenich | 9c86c6a | 2016-05-03 22:49:24 -0600 | [diff] [blame] | 128 | while (! peekTokenClass(EHTokNone)) { |
steve-lunarg | cb88de5 | 2016-08-03 07:04:18 -0600 | [diff] [blame] | 129 | // HLSL allows semicolons between global declarations, e.g, between functions. |
| 130 | if (acceptTokenClass(EHTokSemicolon)) |
| 131 | continue; |
| 132 | |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 133 | // externalDeclaration |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 134 | if (! acceptDeclaration(unitNode)) |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 135 | return false; |
| 136 | } |
| 137 | |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 138 | // set root of AST |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 139 | if (unitNode && !unitNode->getAsAggregate()) |
| 140 | unitNode = intermediate.growAggregate(nullptr, unitNode); |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 141 | intermediate.setTreeRoot(unitNode); |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 142 | |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 143 | return true; |
| 144 | } |
| 145 | |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 146 | // sampler_state |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 147 | // : LEFT_BRACE [sampler_state_assignment ... ] RIGHT_BRACE |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 148 | // |
| 149 | // sampler_state_assignment |
| 150 | // : sampler_state_identifier EQUAL value SEMICOLON |
| 151 | // |
| 152 | // sampler_state_identifier |
| 153 | // : ADDRESSU |
| 154 | // | ADDRESSV |
| 155 | // | ADDRESSW |
| 156 | // | BORDERCOLOR |
| 157 | // | FILTER |
| 158 | // | MAXANISOTROPY |
| 159 | // | MAXLOD |
| 160 | // | MINLOD |
| 161 | // | MIPLODBIAS |
| 162 | // |
| 163 | bool HlslGrammar::acceptSamplerState() |
| 164 | { |
| 165 | // TODO: this should be genericized to accept a list of valid tokens and |
| 166 | // return token/value pairs. Presently it is specific to texture values. |
| 167 | |
| 168 | if (! acceptTokenClass(EHTokLeftBrace)) |
| 169 | return true; |
| 170 | |
| 171 | parseContext.warn(token.loc, "unimplemented", "immediate sampler state", ""); |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 172 | |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 173 | do { |
| 174 | // read state name |
| 175 | HlslToken state; |
| 176 | if (! acceptIdentifier(state)) |
| 177 | break; // end of list |
| 178 | |
| 179 | // FXC accepts any case |
| 180 | TString stateName = *state.string; |
| 181 | std::transform(stateName.begin(), stateName.end(), stateName.begin(), ::tolower); |
| 182 | |
| 183 | if (! acceptTokenClass(EHTokAssign)) { |
| 184 | expected("assign"); |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | if (stateName == "minlod" || stateName == "maxlod") { |
| 189 | if (! peekTokenClass(EHTokIntConstant)) { |
| 190 | expected("integer"); |
| 191 | return false; |
| 192 | } |
| 193 | |
| 194 | TIntermTyped* lod = nullptr; |
| 195 | if (! acceptLiteral(lod)) // should never fail, since we just looked for an integer |
| 196 | return false; |
| 197 | } else if (stateName == "maxanisotropy") { |
| 198 | if (! peekTokenClass(EHTokIntConstant)) { |
| 199 | expected("integer"); |
| 200 | return false; |
| 201 | } |
| 202 | |
| 203 | TIntermTyped* maxAnisotropy = nullptr; |
| 204 | if (! acceptLiteral(maxAnisotropy)) // should never fail, since we just looked for an integer |
| 205 | return false; |
| 206 | } else if (stateName == "filter") { |
| 207 | HlslToken filterMode; |
| 208 | if (! acceptIdentifier(filterMode)) { |
| 209 | expected("filter mode"); |
| 210 | return false; |
| 211 | } |
| 212 | } else if (stateName == "addressu" || stateName == "addressv" || stateName == "addressw") { |
| 213 | HlslToken addrMode; |
| 214 | if (! acceptIdentifier(addrMode)) { |
| 215 | expected("texture address mode"); |
| 216 | return false; |
| 217 | } |
| 218 | } else if (stateName == "miplodbias") { |
| 219 | TIntermTyped* lodBias = nullptr; |
| 220 | if (! acceptLiteral(lodBias)) { |
| 221 | expected("lod bias"); |
| 222 | return false; |
| 223 | } |
| 224 | } else if (stateName == "bordercolor") { |
| 225 | return false; |
| 226 | } else { |
| 227 | expected("texture state"); |
| 228 | return false; |
| 229 | } |
| 230 | |
| 231 | // SEMICOLON |
| 232 | if (! acceptTokenClass(EHTokSemicolon)) { |
| 233 | expected("semicolon"); |
| 234 | return false; |
| 235 | } |
| 236 | } while (true); |
| 237 | |
| 238 | if (! acceptTokenClass(EHTokRightBrace)) |
| 239 | return false; |
| 240 | |
| 241 | return true; |
| 242 | } |
| 243 | |
| 244 | // sampler_declaration_dx9 |
| 245 | // : SAMPLER identifier EQUAL sampler_type sampler_state |
| 246 | // |
John Kessenich | e4821e4 | 2016-07-16 10:19:43 -0600 | [diff] [blame] | 247 | bool HlslGrammar::acceptSamplerDeclarationDX9(TType& /*type*/) |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 248 | { |
| 249 | if (! acceptTokenClass(EHTokSampler)) |
| 250 | return false; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 251 | |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 252 | // TODO: remove this when DX9 style declarations are implemented. |
| 253 | unimplemented("Direct3D 9 sampler declaration"); |
| 254 | |
| 255 | // read sampler name |
| 256 | HlslToken name; |
| 257 | if (! acceptIdentifier(name)) { |
| 258 | expected("sampler name"); |
| 259 | return false; |
| 260 | } |
| 261 | |
| 262 | if (! acceptTokenClass(EHTokAssign)) { |
| 263 | expected("="); |
| 264 | return false; |
| 265 | } |
| 266 | |
| 267 | return false; |
| 268 | } |
| 269 | |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 270 | // declaration |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 271 | // : sampler_declaration_dx9 post_decls SEMICOLON |
| 272 | // | fully_specified_type declarator_list SEMICOLON |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 273 | // | fully_specified_type identifier function_parameters post_decls compound_statement // function definition |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 274 | // | fully_specified_type identifier sampler_state post_decls compound_statement // sampler definition |
John Kessenich | 5e69ec6 | 2016-07-05 00:02:40 -0600 | [diff] [blame] | 275 | // | typedef declaration |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 276 | // |
John Kessenich | d5ed0b6 | 2016-07-04 17:32:45 -0600 | [diff] [blame] | 277 | // declarator_list |
| 278 | // : declarator COMMA declarator COMMA declarator... // zero or more declarators |
John Kessenich | 532543c | 2016-07-01 19:06:44 -0600 | [diff] [blame] | 279 | // |
John Kessenich | d5ed0b6 | 2016-07-04 17:32:45 -0600 | [diff] [blame] | 280 | // declarator |
John Kessenich | 532543c | 2016-07-01 19:06:44 -0600 | [diff] [blame] | 281 | // : identifier array_specifier post_decls |
| 282 | // | identifier array_specifier post_decls EQUAL assignment_expression |
John Kessenich | d5ed0b6 | 2016-07-04 17:32:45 -0600 | [diff] [blame] | 283 | // | identifier function_parameters post_decls // function prototype |
John Kessenich | 532543c | 2016-07-01 19:06:44 -0600 | [diff] [blame] | 284 | // |
John Kessenich | d5ed0b6 | 2016-07-04 17:32:45 -0600 | [diff] [blame] | 285 | // Parsing has to go pretty far in to know whether it's a variable, prototype, or |
| 286 | // function definition, so the implementation below doesn't perfectly divide up the grammar |
John Kessenich | 532543c | 2016-07-01 19:06:44 -0600 | [diff] [blame] | 287 | // as above. (The 'identifier' in the first item in init_declarator list is the |
| 288 | // same as 'identifier' for function declarations.) |
| 289 | // |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 290 | // This can generate more than one subtree, one per initializer or a function body. |
| 291 | // All initializer subtrees are put in their own aggregate node, making one top-level |
| 292 | // node for all the initializers. Each function created is a top-level node to grow |
| 293 | // into the passed-in nodeList. |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 294 | // |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 295 | // If 'nodeList' is passed in as non-null, it must an aggregate to extend for |
| 296 | // each top-level node the declaration creates. Otherwise, if only one top-level |
| 297 | // node in generated here, that is want is returned in nodeList. |
John Kessenich | 02467d8 | 2017-01-19 15:41:47 -0700 | [diff] [blame] | 298 | // |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 299 | bool HlslGrammar::acceptDeclaration(TIntermNode*& nodeList) |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 300 | { |
John Kessenich | d5ed0b6 | 2016-07-04 17:32:45 -0600 | [diff] [blame] | 301 | bool list = false; |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 302 | |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 303 | // attributes |
| 304 | TAttributeMap attributes; |
| 305 | acceptAttributes(attributes); |
| 306 | |
John Kessenich | 5e69ec6 | 2016-07-05 00:02:40 -0600 | [diff] [blame] | 307 | // typedef |
| 308 | bool typedefDecl = acceptTokenClass(EHTokTypedef); |
| 309 | |
John Kessenich | e82061d | 2016-09-27 14:38:57 -0600 | [diff] [blame] | 310 | TType declaredType; |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 311 | |
| 312 | // DX9 sampler declaration use a different syntax |
John Kessenich | 267590d | 2016-08-05 17:34:34 -0600 | [diff] [blame] | 313 | // DX9 shaders need to run through HLSL compiler (fxc) via a back compat mode, it isn't going to |
| 314 | // be possible to simultaneously compile D3D10+ style shaders and DX9 shaders. If we want to compile DX9 |
| 315 | // HLSL shaders, this will have to be a master level switch |
| 316 | // As such, the sampler keyword in D3D10+ turns into an automatic sampler type, and is commonly used |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 317 | // For that reason, this line is commented out |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 318 | // if (acceptSamplerDeclarationDX9(declaredType)) |
| 319 | // return true; |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 320 | |
| 321 | // fully_specified_type |
John Kessenich | e82061d | 2016-09-27 14:38:57 -0600 | [diff] [blame] | 322 | if (! acceptFullySpecifiedType(declaredType)) |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 323 | return false; |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 324 | |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 325 | // identifier |
John Kessenich | aecd497 | 2016-03-14 10:46:34 -0600 | [diff] [blame] | 326 | HlslToken idToken; |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 327 | TIntermAggregate* initializers = nullptr; |
John Kessenich | d5ed0b6 | 2016-07-04 17:32:45 -0600 | [diff] [blame] | 328 | while (acceptIdentifier(idToken)) { |
John Kessenich | 7838872 | 2017-03-08 18:53:51 -0700 | [diff] [blame^] | 329 | if (peekTokenClass(EHTokLeftParen)) { |
| 330 | // looks like function parameters |
| 331 | TString* fnName = idToken.string; |
steve-lunarg | f1e0c87 | 2016-10-31 15:13:43 -0600 | [diff] [blame] | 332 | |
John Kessenich | 7838872 | 2017-03-08 18:53:51 -0700 | [diff] [blame^] | 333 | // Potentially rename shader entry point function. No-op most of the time. |
| 334 | parseContext.renameShaderFunction(fnName); |
steve-lunarg | f1e0c87 | 2016-10-31 15:13:43 -0600 | [diff] [blame] | 335 | |
John Kessenich | 7838872 | 2017-03-08 18:53:51 -0700 | [diff] [blame^] | 336 | // function_parameters |
| 337 | TFunction& function = *new TFunction(fnName, declaredType); |
| 338 | if (!acceptFunctionParameters(function)) { |
| 339 | expected("function parameter list"); |
| 340 | return false; |
| 341 | } |
| 342 | |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 343 | // post_decls |
John Kessenich | 7735b94 | 2016-09-05 12:40:06 -0600 | [diff] [blame] | 344 | acceptPostDecls(function.getWritableType().getQualifier()); |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 345 | |
John Kessenich | d5ed0b6 | 2016-07-04 17:32:45 -0600 | [diff] [blame] | 346 | // compound_statement (function body definition) or just a prototype? |
| 347 | if (peekTokenClass(EHTokLeftBrace)) { |
| 348 | if (list) |
| 349 | parseContext.error(idToken.loc, "function body can't be in a declarator list", "{", ""); |
John Kessenich | 5e69ec6 | 2016-07-05 00:02:40 -0600 | [diff] [blame] | 350 | if (typedefDecl) |
| 351 | parseContext.error(idToken.loc, "function body can't be in a typedef", "{", ""); |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 352 | return acceptFunctionDefinition(function, nodeList, attributes); |
John Kessenich | 5e69ec6 | 2016-07-05 00:02:40 -0600 | [diff] [blame] | 353 | } else { |
| 354 | if (typedefDecl) |
| 355 | parseContext.error(idToken.loc, "function typedefs not implemented", "{", ""); |
John Kessenich | 9e07953 | 2016-09-02 20:05:19 -0600 | [diff] [blame] | 356 | parseContext.handleFunctionDeclarator(idToken.loc, function, true); |
John Kessenich | 5e69ec6 | 2016-07-05 00:02:40 -0600 | [diff] [blame] | 357 | } |
John Kessenich | d5ed0b6 | 2016-07-04 17:32:45 -0600 | [diff] [blame] | 358 | } else { |
John Kessenich | 6dbc0a7 | 2016-09-27 19:13:05 -0600 | [diff] [blame] | 359 | // A variable declaration. Fix the storage qualifier if it's a global. |
| 360 | if (declaredType.getQualifier().storage == EvqTemporary && parseContext.symbolTable.atGlobalLevel()) |
| 361 | declaredType.getQualifier().storage = EvqUniform; |
| 362 | |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 363 | // We can handle multiple variables per type declaration, so |
John Kessenich | e82061d | 2016-09-27 14:38:57 -0600 | [diff] [blame] | 364 | // the number of types can expand when arrayness is different. |
| 365 | TType variableType; |
| 366 | variableType.shallowCopy(declaredType); |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 367 | |
John Kessenich | e82061d | 2016-09-27 14:38:57 -0600 | [diff] [blame] | 368 | // recognize array_specifier |
John Kessenich | d5ed0b6 | 2016-07-04 17:32:45 -0600 | [diff] [blame] | 369 | TArraySizes* arraySizes = nullptr; |
| 370 | acceptArraySpecifier(arraySizes); |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 371 | |
John Kessenich | e82061d | 2016-09-27 14:38:57 -0600 | [diff] [blame] | 372 | // Fix arrayness in the variableType |
| 373 | if (declaredType.isImplicitlySizedArray()) { |
| 374 | // Because "int[] a = int[2](...), b = int[3](...)" makes two arrays a and b |
| 375 | // of different sizes, for this case sharing the shallow copy of arrayness |
| 376 | // with the parseType oversubscribes it, so get a deep copy of the arrayness. |
| 377 | variableType.newArraySizes(declaredType.getArraySizes()); |
| 378 | } |
| 379 | if (arraySizes || variableType.isArray()) { |
| 380 | // In the most general case, arrayness is potentially coming both from the |
| 381 | // declared type and from the variable: "int[] a[];" or just one or the other. |
| 382 | // Merge it all to the variableType, so all arrayness is part of the variableType. |
| 383 | parseContext.arrayDimMerge(variableType, arraySizes); |
| 384 | } |
| 385 | |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 386 | // samplers accept immediate sampler state |
John Kessenich | e82061d | 2016-09-27 14:38:57 -0600 | [diff] [blame] | 387 | if (variableType.getBasicType() == EbtSampler) { |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 388 | if (! acceptSamplerState()) |
| 389 | return false; |
| 390 | } |
| 391 | |
John Kessenich | d5ed0b6 | 2016-07-04 17:32:45 -0600 | [diff] [blame] | 392 | // post_decls |
John Kessenich | e82061d | 2016-09-27 14:38:57 -0600 | [diff] [blame] | 393 | acceptPostDecls(variableType.getQualifier()); |
John Kessenich | d5ed0b6 | 2016-07-04 17:32:45 -0600 | [diff] [blame] | 394 | |
| 395 | // EQUAL assignment_expression |
| 396 | TIntermTyped* expressionNode = nullptr; |
| 397 | if (acceptTokenClass(EHTokAssign)) { |
John Kessenich | 5e69ec6 | 2016-07-05 00:02:40 -0600 | [diff] [blame] | 398 | if (typedefDecl) |
| 399 | parseContext.error(idToken.loc, "can't have an initializer", "typedef", ""); |
John Kessenich | d5ed0b6 | 2016-07-04 17:32:45 -0600 | [diff] [blame] | 400 | if (! acceptAssignmentExpression(expressionNode)) { |
| 401 | expected("initializer"); |
| 402 | return false; |
| 403 | } |
| 404 | } |
| 405 | |
John Kessenich | 6dbc0a7 | 2016-09-27 19:13:05 -0600 | [diff] [blame] | 406 | // TODO: things scoped within an annotation need their own name space; |
| 407 | // TODO: strings are not yet handled. |
| 408 | if (variableType.getBasicType() != EbtString && parseContext.getAnnotationNestingLevel() == 0) { |
| 409 | if (typedefDecl) |
| 410 | parseContext.declareTypedef(idToken.loc, *idToken.string, variableType); |
| 411 | else if (variableType.getBasicType() == EbtBlock) |
steve-lunarg | dd8287a | 2017-02-23 18:04:12 -0700 | [diff] [blame] | 412 | parseContext.declareBlock(idToken.loc, variableType, idToken.string); |
John Kessenich | 6dbc0a7 | 2016-09-27 19:13:05 -0600 | [diff] [blame] | 413 | else { |
steve-lunarg | a2b01a0 | 2016-11-28 17:09:54 -0700 | [diff] [blame] | 414 | if (variableType.getQualifier().storage == EvqUniform && ! variableType.containsOpaque()) { |
John Kessenich | 6dbc0a7 | 2016-09-27 19:13:05 -0600 | [diff] [blame] | 415 | // this isn't really an individual variable, but a member of the $Global buffer |
| 416 | parseContext.growGlobalUniformBlock(idToken.loc, variableType, *idToken.string); |
| 417 | } else { |
| 418 | // Declare the variable and add any initializer code to the AST. |
| 419 | // The top-level node is always made into an aggregate, as that's |
| 420 | // historically how the AST has been. |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 421 | initializers = intermediate.growAggregate(initializers, |
| 422 | parseContext.declareVariable(idToken.loc, *idToken.string, variableType, expressionNode), |
| 423 | idToken.loc); |
John Kessenich | 6dbc0a7 | 2016-09-27 19:13:05 -0600 | [diff] [blame] | 424 | } |
| 425 | } |
John Kessenich | 5e69ec6 | 2016-07-05 00:02:40 -0600 | [diff] [blame] | 426 | } |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 427 | } |
John Kessenich | d5ed0b6 | 2016-07-04 17:32:45 -0600 | [diff] [blame] | 428 | |
| 429 | if (acceptTokenClass(EHTokComma)) { |
| 430 | list = true; |
| 431 | continue; |
| 432 | } |
| 433 | }; |
| 434 | |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 435 | // The top-level initializer node is a sequence. |
| 436 | if (initializers != nullptr) |
| 437 | initializers->setOperator(EOpSequence); |
| 438 | |
| 439 | // Add the initializers' aggregate to the nodeList we were handed. |
| 440 | if (nodeList) |
| 441 | nodeList = intermediate.growAggregate(nodeList, initializers); |
| 442 | else |
| 443 | nodeList = initializers; |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 444 | |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 445 | // SEMICOLON |
John Kessenich | d5ed0b6 | 2016-07-04 17:32:45 -0600 | [diff] [blame] | 446 | if (! acceptTokenClass(EHTokSemicolon)) { |
steve-lunarg | 5ca85ad | 2016-12-26 18:45:52 -0700 | [diff] [blame] | 447 | // This may have been a false detection of what appeared to be a declaration, but |
| 448 | // was actually an assignment such as "float = 4", where "float" is an identifier. |
| 449 | // We put the token back to let further parsing happen for cases where that may |
| 450 | // happen. This errors on the side of caution, and mostly triggers the error. |
| 451 | |
| 452 | if (peek() == EHTokAssign || peek() == EHTokLeftBracket || peek() == EHTokDot || peek() == EHTokComma) |
| 453 | recedeToken(); |
| 454 | else |
| 455 | expected(";"); |
John Kessenich | d5ed0b6 | 2016-07-04 17:32:45 -0600 | [diff] [blame] | 456 | return false; |
| 457 | } |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 458 | |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 459 | return true; |
| 460 | } |
| 461 | |
John Kessenich | 5bc4d9a | 2016-06-20 01:22:38 -0600 | [diff] [blame] | 462 | // control_declaration |
| 463 | // : fully_specified_type identifier EQUAL expression |
| 464 | // |
| 465 | bool HlslGrammar::acceptControlDeclaration(TIntermNode*& node) |
| 466 | { |
| 467 | node = nullptr; |
| 468 | |
| 469 | // fully_specified_type |
| 470 | TType type; |
| 471 | if (! acceptFullySpecifiedType(type)) |
| 472 | return false; |
| 473 | |
John Kessenich | 057df29 | 2017-03-06 18:18:37 -0700 | [diff] [blame] | 474 | // filter out type casts |
| 475 | if (peekTokenClass(EHTokLeftParen)) { |
| 476 | recedeToken(); |
| 477 | return false; |
| 478 | } |
| 479 | |
John Kessenich | 5bc4d9a | 2016-06-20 01:22:38 -0600 | [diff] [blame] | 480 | // identifier |
| 481 | HlslToken idToken; |
| 482 | if (! acceptIdentifier(idToken)) { |
| 483 | expected("identifier"); |
| 484 | return false; |
| 485 | } |
| 486 | |
| 487 | // EQUAL |
| 488 | TIntermTyped* expressionNode = nullptr; |
| 489 | if (! acceptTokenClass(EHTokAssign)) { |
| 490 | expected("="); |
| 491 | return false; |
| 492 | } |
| 493 | |
| 494 | // expression |
| 495 | if (! acceptExpression(expressionNode)) { |
| 496 | expected("initializer"); |
| 497 | return false; |
| 498 | } |
| 499 | |
John Kessenich | e82061d | 2016-09-27 14:38:57 -0600 | [diff] [blame] | 500 | node = parseContext.declareVariable(idToken.loc, *idToken.string, type, expressionNode); |
John Kessenich | 5bc4d9a | 2016-06-20 01:22:38 -0600 | [diff] [blame] | 501 | |
| 502 | return true; |
| 503 | } |
| 504 | |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 505 | // fully_specified_type |
| 506 | // : type_specifier |
| 507 | // | type_qualifier type_specifier |
| 508 | // |
| 509 | bool HlslGrammar::acceptFullySpecifiedType(TType& type) |
| 510 | { |
| 511 | // type_qualifier |
| 512 | TQualifier qualifier; |
| 513 | qualifier.clear(); |
John Kessenich | b9e3912 | 2016-08-17 10:22:08 -0600 | [diff] [blame] | 514 | if (! acceptQualifier(qualifier)) |
| 515 | return false; |
John Kessenich | 3d157c5 | 2016-07-25 16:05:33 -0600 | [diff] [blame] | 516 | TSourceLoc loc = token.loc; |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 517 | |
| 518 | // type_specifier |
steve-lunarg | a64ed3e | 2016-12-18 17:51:14 -0700 | [diff] [blame] | 519 | if (! acceptType(type)) { |
| 520 | // If this is not a type, we may have inadvertently gone down a wrong path |
steve-lunarg | 132d331 | 2016-12-19 15:48:01 -0700 | [diff] [blame] | 521 | // by parsing "sample", which can be treated like either an identifier or a |
steve-lunarg | a64ed3e | 2016-12-18 17:51:14 -0700 | [diff] [blame] | 522 | // qualifier. Back it out, if we did. |
| 523 | if (qualifier.sample) |
| 524 | recedeToken(); |
| 525 | |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 526 | return false; |
steve-lunarg | a64ed3e | 2016-12-18 17:51:14 -0700 | [diff] [blame] | 527 | } |
John Kessenich | 3d157c5 | 2016-07-25 16:05:33 -0600 | [diff] [blame] | 528 | if (type.getBasicType() == EbtBlock) { |
| 529 | // the type was a block, which set some parts of the qualifier |
John Kessenich | 34e7ee7 | 2016-09-16 17:10:39 -0600 | [diff] [blame] | 530 | parseContext.mergeQualifiers(type.getQualifier(), qualifier); |
John Kessenich | 3d157c5 | 2016-07-25 16:05:33 -0600 | [diff] [blame] | 531 | // further, it can create an anonymous instance of the block |
| 532 | if (peekTokenClass(EHTokSemicolon)) |
| 533 | parseContext.declareBlock(loc, type); |
steve-lunarg | bb0183f | 2016-10-04 16:58:14 -0600 | [diff] [blame] | 534 | } else { |
| 535 | // Some qualifiers are set when parsing the type. Merge those with |
| 536 | // whatever comes from acceptQualifier. |
| 537 | assert(qualifier.layoutFormat == ElfNone); |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 538 | |
steve-lunarg | bb0183f | 2016-10-04 16:58:14 -0600 | [diff] [blame] | 539 | qualifier.layoutFormat = type.getQualifier().layoutFormat; |
steve-lunarg | 3226b08 | 2016-10-26 19:18:55 -0600 | [diff] [blame] | 540 | qualifier.precision = type.getQualifier().precision; |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 541 | |
steve-lunarg | 5da1f03 | 2017-02-12 17:50:28 -0700 | [diff] [blame] | 542 | if (type.getQualifier().storage == EvqVaryingOut || |
| 543 | type.getQualifier().storage == EvqBuffer) { |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 544 | qualifier.storage = type.getQualifier().storage; |
steve-lunarg | 5da1f03 | 2017-02-12 17:50:28 -0700 | [diff] [blame] | 545 | qualifier.readonly = type.getQualifier().readonly; |
| 546 | } |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 547 | |
| 548 | type.getQualifier() = qualifier; |
steve-lunarg | bb0183f | 2016-10-04 16:58:14 -0600 | [diff] [blame] | 549 | } |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 550 | |
| 551 | return true; |
| 552 | } |
| 553 | |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 554 | // type_qualifier |
| 555 | // : qualifier qualifier ... |
| 556 | // |
| 557 | // Zero or more of these, so this can't return false. |
| 558 | // |
John Kessenich | b9e3912 | 2016-08-17 10:22:08 -0600 | [diff] [blame] | 559 | bool HlslGrammar::acceptQualifier(TQualifier& qualifier) |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 560 | { |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 561 | do { |
| 562 | switch (peek()) { |
| 563 | case EHTokStatic: |
John Kessenich | 6dbc0a7 | 2016-09-27 19:13:05 -0600 | [diff] [blame] | 564 | qualifier.storage = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 565 | break; |
| 566 | case EHTokExtern: |
| 567 | // TODO: no meaning in glslang? |
| 568 | break; |
| 569 | case EHTokShared: |
| 570 | // TODO: hint |
| 571 | break; |
| 572 | case EHTokGroupShared: |
| 573 | qualifier.storage = EvqShared; |
| 574 | break; |
| 575 | case EHTokUniform: |
| 576 | qualifier.storage = EvqUniform; |
| 577 | break; |
| 578 | case EHTokConst: |
| 579 | qualifier.storage = EvqConst; |
| 580 | break; |
| 581 | case EHTokVolatile: |
| 582 | qualifier.volatil = true; |
| 583 | break; |
| 584 | case EHTokLinear: |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 585 | qualifier.smooth = true; |
| 586 | break; |
| 587 | case EHTokCentroid: |
| 588 | qualifier.centroid = true; |
| 589 | break; |
| 590 | case EHTokNointerpolation: |
| 591 | qualifier.flat = true; |
| 592 | break; |
| 593 | case EHTokNoperspective: |
| 594 | qualifier.nopersp = true; |
| 595 | break; |
| 596 | case EHTokSample: |
| 597 | qualifier.sample = true; |
| 598 | break; |
| 599 | case EHTokRowMajor: |
John Kessenich | 10f7fc7 | 2016-09-25 20:25:06 -0600 | [diff] [blame] | 600 | qualifier.layoutMatrix = ElmColumnMajor; |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 601 | break; |
| 602 | case EHTokColumnMajor: |
John Kessenich | 10f7fc7 | 2016-09-25 20:25:06 -0600 | [diff] [blame] | 603 | qualifier.layoutMatrix = ElmRowMajor; |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 604 | break; |
| 605 | case EHTokPrecise: |
| 606 | qualifier.noContraction = true; |
| 607 | break; |
LoopDawg | 9249c70 | 2016-07-12 20:44:32 -0600 | [diff] [blame] | 608 | case EHTokIn: |
| 609 | qualifier.storage = EvqIn; |
| 610 | break; |
| 611 | case EHTokOut: |
| 612 | qualifier.storage = EvqOut; |
| 613 | break; |
| 614 | case EHTokInOut: |
| 615 | qualifier.storage = EvqInOut; |
| 616 | break; |
John Kessenich | b9e3912 | 2016-08-17 10:22:08 -0600 | [diff] [blame] | 617 | case EHTokLayout: |
| 618 | if (! acceptLayoutQualifierList(qualifier)) |
| 619 | return false; |
| 620 | continue; |
steve-lunarg | 5da1f03 | 2017-02-12 17:50:28 -0700 | [diff] [blame] | 621 | case EHTokGloballyCoherent: |
| 622 | qualifier.coherent = true; |
| 623 | break; |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 624 | |
| 625 | // GS geometries: these are specified on stage input variables, and are an error (not verified here) |
| 626 | // for output variables. |
| 627 | case EHTokPoint: |
| 628 | qualifier.storage = EvqIn; |
| 629 | if (!parseContext.handleInputGeometry(token.loc, ElgPoints)) |
| 630 | return false; |
| 631 | break; |
| 632 | case EHTokLine: |
| 633 | qualifier.storage = EvqIn; |
| 634 | if (!parseContext.handleInputGeometry(token.loc, ElgLines)) |
| 635 | return false; |
| 636 | break; |
| 637 | case EHTokTriangle: |
| 638 | qualifier.storage = EvqIn; |
| 639 | if (!parseContext.handleInputGeometry(token.loc, ElgTriangles)) |
| 640 | return false; |
| 641 | break; |
| 642 | case EHTokLineAdj: |
| 643 | qualifier.storage = EvqIn; |
| 644 | if (!parseContext.handleInputGeometry(token.loc, ElgLinesAdjacency)) |
| 645 | return false; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 646 | break; |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 647 | case EHTokTriangleAdj: |
| 648 | qualifier.storage = EvqIn; |
| 649 | if (!parseContext.handleInputGeometry(token.loc, ElgTrianglesAdjacency)) |
| 650 | return false; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 651 | break; |
| 652 | |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 653 | default: |
John Kessenich | b9e3912 | 2016-08-17 10:22:08 -0600 | [diff] [blame] | 654 | return true; |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 655 | } |
| 656 | advanceToken(); |
| 657 | } while (true); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 658 | } |
| 659 | |
John Kessenich | b9e3912 | 2016-08-17 10:22:08 -0600 | [diff] [blame] | 660 | // layout_qualifier_list |
John Kessenich | e3218e2 | 2016-09-05 14:37:03 -0600 | [diff] [blame] | 661 | // : LAYOUT LEFT_PAREN layout_qualifier COMMA layout_qualifier ... RIGHT_PAREN |
John Kessenich | b9e3912 | 2016-08-17 10:22:08 -0600 | [diff] [blame] | 662 | // |
| 663 | // layout_qualifier |
| 664 | // : identifier |
John Kessenich | 841db35 | 2016-09-02 21:12:23 -0600 | [diff] [blame] | 665 | // | identifier EQUAL expression |
John Kessenich | b9e3912 | 2016-08-17 10:22:08 -0600 | [diff] [blame] | 666 | // |
| 667 | // Zero or more of these, so this can't return false. |
| 668 | // |
| 669 | bool HlslGrammar::acceptLayoutQualifierList(TQualifier& qualifier) |
| 670 | { |
| 671 | if (! acceptTokenClass(EHTokLayout)) |
| 672 | return false; |
| 673 | |
| 674 | // LEFT_PAREN |
| 675 | if (! acceptTokenClass(EHTokLeftParen)) |
| 676 | return false; |
| 677 | |
| 678 | do { |
| 679 | // identifier |
| 680 | HlslToken idToken; |
| 681 | if (! acceptIdentifier(idToken)) |
| 682 | break; |
| 683 | |
| 684 | // EQUAL expression |
| 685 | if (acceptTokenClass(EHTokAssign)) { |
| 686 | TIntermTyped* expr; |
| 687 | if (! acceptConditionalExpression(expr)) { |
| 688 | expected("expression"); |
| 689 | return false; |
| 690 | } |
| 691 | parseContext.setLayoutQualifier(idToken.loc, qualifier, *idToken.string, expr); |
| 692 | } else |
| 693 | parseContext.setLayoutQualifier(idToken.loc, qualifier, *idToken.string); |
| 694 | |
| 695 | // COMMA |
| 696 | if (! acceptTokenClass(EHTokComma)) |
| 697 | break; |
| 698 | } while (true); |
| 699 | |
| 700 | // RIGHT_PAREN |
| 701 | if (! acceptTokenClass(EHTokRightParen)) { |
| 702 | expected(")"); |
| 703 | return false; |
| 704 | } |
| 705 | |
| 706 | return true; |
| 707 | } |
| 708 | |
LoopDawg | 6daaa4f | 2016-06-23 19:13:48 -0600 | [diff] [blame] | 709 | // template_type |
| 710 | // : FLOAT |
| 711 | // | DOUBLE |
| 712 | // | INT |
| 713 | // | DWORD |
| 714 | // | UINT |
| 715 | // | BOOL |
| 716 | // |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 717 | bool HlslGrammar::acceptTemplateVecMatBasicType(TBasicType& basicType) |
LoopDawg | 6daaa4f | 2016-06-23 19:13:48 -0600 | [diff] [blame] | 718 | { |
| 719 | switch (peek()) { |
| 720 | case EHTokFloat: |
| 721 | basicType = EbtFloat; |
| 722 | break; |
| 723 | case EHTokDouble: |
| 724 | basicType = EbtDouble; |
| 725 | break; |
| 726 | case EHTokInt: |
| 727 | case EHTokDword: |
| 728 | basicType = EbtInt; |
| 729 | break; |
| 730 | case EHTokUint: |
| 731 | basicType = EbtUint; |
| 732 | break; |
| 733 | case EHTokBool: |
| 734 | basicType = EbtBool; |
| 735 | break; |
| 736 | default: |
| 737 | return false; |
| 738 | } |
| 739 | |
| 740 | advanceToken(); |
| 741 | |
| 742 | return true; |
| 743 | } |
| 744 | |
| 745 | // vector_template_type |
| 746 | // : VECTOR |
| 747 | // | VECTOR LEFT_ANGLE template_type COMMA integer_literal RIGHT_ANGLE |
| 748 | // |
| 749 | bool HlslGrammar::acceptVectorTemplateType(TType& type) |
| 750 | { |
| 751 | if (! acceptTokenClass(EHTokVector)) |
| 752 | return false; |
| 753 | |
| 754 | if (! acceptTokenClass(EHTokLeftAngle)) { |
| 755 | // in HLSL, 'vector' alone means float4. |
| 756 | new(&type) TType(EbtFloat, EvqTemporary, 4); |
| 757 | return true; |
| 758 | } |
| 759 | |
| 760 | TBasicType basicType; |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 761 | if (! acceptTemplateVecMatBasicType(basicType)) { |
LoopDawg | 6daaa4f | 2016-06-23 19:13:48 -0600 | [diff] [blame] | 762 | expected("scalar type"); |
| 763 | return false; |
| 764 | } |
| 765 | |
| 766 | // COMMA |
| 767 | if (! acceptTokenClass(EHTokComma)) { |
| 768 | expected(","); |
| 769 | return false; |
| 770 | } |
| 771 | |
| 772 | // integer |
| 773 | if (! peekTokenClass(EHTokIntConstant)) { |
| 774 | expected("literal integer"); |
| 775 | return false; |
| 776 | } |
| 777 | |
| 778 | TIntermTyped* vecSize; |
| 779 | if (! acceptLiteral(vecSize)) |
| 780 | return false; |
| 781 | |
| 782 | const int vecSizeI = vecSize->getAsConstantUnion()->getConstArray()[0].getIConst(); |
| 783 | |
| 784 | new(&type) TType(basicType, EvqTemporary, vecSizeI); |
| 785 | |
| 786 | if (vecSizeI == 1) |
| 787 | type.makeVector(); |
| 788 | |
| 789 | if (!acceptTokenClass(EHTokRightAngle)) { |
| 790 | expected("right angle bracket"); |
| 791 | return false; |
| 792 | } |
| 793 | |
| 794 | return true; |
| 795 | } |
| 796 | |
| 797 | // matrix_template_type |
| 798 | // : MATRIX |
| 799 | // | MATRIX LEFT_ANGLE template_type COMMA integer_literal COMMA integer_literal RIGHT_ANGLE |
| 800 | // |
| 801 | bool HlslGrammar::acceptMatrixTemplateType(TType& type) |
| 802 | { |
| 803 | if (! acceptTokenClass(EHTokMatrix)) |
| 804 | return false; |
| 805 | |
| 806 | if (! acceptTokenClass(EHTokLeftAngle)) { |
| 807 | // in HLSL, 'matrix' alone means float4x4. |
| 808 | new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 4); |
| 809 | return true; |
| 810 | } |
| 811 | |
| 812 | TBasicType basicType; |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 813 | if (! acceptTemplateVecMatBasicType(basicType)) { |
LoopDawg | 6daaa4f | 2016-06-23 19:13:48 -0600 | [diff] [blame] | 814 | expected("scalar type"); |
| 815 | return false; |
| 816 | } |
| 817 | |
| 818 | // COMMA |
| 819 | if (! acceptTokenClass(EHTokComma)) { |
| 820 | expected(","); |
| 821 | return false; |
| 822 | } |
| 823 | |
| 824 | // integer rows |
| 825 | if (! peekTokenClass(EHTokIntConstant)) { |
| 826 | expected("literal integer"); |
| 827 | return false; |
| 828 | } |
| 829 | |
| 830 | TIntermTyped* rows; |
| 831 | if (! acceptLiteral(rows)) |
| 832 | return false; |
| 833 | |
| 834 | // COMMA |
| 835 | if (! acceptTokenClass(EHTokComma)) { |
| 836 | expected(","); |
| 837 | return false; |
| 838 | } |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 839 | |
LoopDawg | 6daaa4f | 2016-06-23 19:13:48 -0600 | [diff] [blame] | 840 | // integer cols |
| 841 | if (! peekTokenClass(EHTokIntConstant)) { |
| 842 | expected("literal integer"); |
| 843 | return false; |
| 844 | } |
| 845 | |
| 846 | TIntermTyped* cols; |
| 847 | if (! acceptLiteral(cols)) |
| 848 | return false; |
| 849 | |
| 850 | new(&type) TType(basicType, EvqTemporary, 0, |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 851 | rows->getAsConstantUnion()->getConstArray()[0].getIConst(), |
| 852 | cols->getAsConstantUnion()->getConstArray()[0].getIConst()); |
LoopDawg | 6daaa4f | 2016-06-23 19:13:48 -0600 | [diff] [blame] | 853 | |
| 854 | if (!acceptTokenClass(EHTokRightAngle)) { |
| 855 | expected("right angle bracket"); |
| 856 | return false; |
| 857 | } |
| 858 | |
| 859 | return true; |
| 860 | } |
| 861 | |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 862 | // layout_geometry |
| 863 | // : LINESTREAM |
| 864 | // | POINTSTREAM |
| 865 | // | TRIANGLESTREAM |
| 866 | // |
| 867 | bool HlslGrammar::acceptOutputPrimitiveGeometry(TLayoutGeometry& geometry) |
| 868 | { |
| 869 | // read geometry type |
| 870 | const EHlslTokenClass geometryType = peek(); |
| 871 | |
| 872 | switch (geometryType) { |
| 873 | case EHTokPointStream: geometry = ElgPoints; break; |
| 874 | case EHTokLineStream: geometry = ElgLineStrip; break; |
| 875 | case EHTokTriangleStream: geometry = ElgTriangleStrip; break; |
| 876 | default: |
| 877 | return false; // not a layout geometry |
| 878 | } |
| 879 | |
| 880 | advanceToken(); // consume the layout keyword |
| 881 | return true; |
| 882 | } |
| 883 | |
steve-lunarg | 858c928 | 2017-01-07 08:54:10 -0700 | [diff] [blame] | 884 | // tessellation_decl_type |
| 885 | // : INPUTPATCH |
| 886 | // | OUTPUTPATCH |
| 887 | // |
| 888 | bool HlslGrammar::acceptTessellationDeclType() |
| 889 | { |
| 890 | // read geometry type |
| 891 | const EHlslTokenClass tessType = peek(); |
| 892 | |
| 893 | switch (tessType) { |
| 894 | case EHTokInputPatch: break; |
| 895 | case EHTokOutputPatch: break; |
| 896 | default: |
| 897 | return false; // not a tessellation decl |
| 898 | } |
| 899 | |
| 900 | advanceToken(); // consume the keyword |
| 901 | return true; |
| 902 | } |
| 903 | |
| 904 | // tessellation_patch_template_type |
| 905 | // : tessellation_decl_type LEFT_ANGLE type comma integer_literal RIGHT_ANGLE |
| 906 | // |
| 907 | bool HlslGrammar::acceptTessellationPatchTemplateType(TType& type) |
| 908 | { |
| 909 | if (! acceptTessellationDeclType()) |
| 910 | return false; |
| 911 | |
| 912 | if (! acceptTokenClass(EHTokLeftAngle)) |
| 913 | return false; |
| 914 | |
| 915 | if (! acceptType(type)) { |
| 916 | expected("tessellation patch type"); |
| 917 | return false; |
| 918 | } |
| 919 | |
| 920 | if (! acceptTokenClass(EHTokComma)) |
| 921 | return false; |
| 922 | |
| 923 | // integer size |
| 924 | if (! peekTokenClass(EHTokIntConstant)) { |
| 925 | expected("literal integer"); |
| 926 | return false; |
| 927 | } |
| 928 | |
| 929 | TIntermTyped* size; |
| 930 | if (! acceptLiteral(size)) |
| 931 | return false; |
| 932 | |
| 933 | TArraySizes* arraySizes = new TArraySizes; |
| 934 | arraySizes->addInnerSize(size->getAsConstantUnion()->getConstArray()[0].getIConst()); |
| 935 | type.newArraySizes(*arraySizes); |
| 936 | |
| 937 | if (! acceptTokenClass(EHTokRightAngle)) { |
| 938 | expected("right angle bracket"); |
| 939 | return false; |
| 940 | } |
| 941 | |
| 942 | return true; |
| 943 | } |
| 944 | |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 945 | // stream_out_template_type |
| 946 | // : output_primitive_geometry_type LEFT_ANGLE type RIGHT_ANGLE |
| 947 | // |
| 948 | bool HlslGrammar::acceptStreamOutTemplateType(TType& type, TLayoutGeometry& geometry) |
| 949 | { |
| 950 | geometry = ElgNone; |
| 951 | |
| 952 | if (! acceptOutputPrimitiveGeometry(geometry)) |
| 953 | return false; |
| 954 | |
| 955 | if (! acceptTokenClass(EHTokLeftAngle)) |
| 956 | return false; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 957 | |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 958 | if (! acceptType(type)) { |
| 959 | expected("stream output type"); |
| 960 | return false; |
| 961 | } |
| 962 | |
| 963 | type.getQualifier().storage = EvqVaryingOut; |
| 964 | |
| 965 | if (! acceptTokenClass(EHTokRightAngle)) { |
| 966 | expected("right angle bracket"); |
| 967 | return false; |
| 968 | } |
| 969 | |
| 970 | return true; |
| 971 | } |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 972 | |
John Kessenich | a1e2d49 | 2016-09-20 13:22:58 -0600 | [diff] [blame] | 973 | // annotations |
| 974 | // : LEFT_ANGLE declaration SEMI_COLON ... declaration SEMICOLON RIGHT_ANGLE |
John Kessenich | 86f7138 | 2016-09-19 20:23:18 -0600 | [diff] [blame] | 975 | // |
John Kessenich | a1e2d49 | 2016-09-20 13:22:58 -0600 | [diff] [blame] | 976 | bool HlslGrammar::acceptAnnotations(TQualifier&) |
John Kessenich | 86f7138 | 2016-09-19 20:23:18 -0600 | [diff] [blame] | 977 | { |
John Kessenich | a1e2d49 | 2016-09-20 13:22:58 -0600 | [diff] [blame] | 978 | if (! acceptTokenClass(EHTokLeftAngle)) |
John Kessenich | 86f7138 | 2016-09-19 20:23:18 -0600 | [diff] [blame] | 979 | return false; |
| 980 | |
John Kessenich | a1e2d49 | 2016-09-20 13:22:58 -0600 | [diff] [blame] | 981 | // note that we are nesting a name space |
| 982 | parseContext.nestAnnotations(); |
John Kessenich | 86f7138 | 2016-09-19 20:23:18 -0600 | [diff] [blame] | 983 | |
| 984 | // declaration SEMI_COLON ... declaration SEMICOLON RIGHT_ANGLE |
| 985 | do { |
| 986 | // eat any extra SEMI_COLON; don't know if the grammar calls for this or not |
| 987 | while (acceptTokenClass(EHTokSemicolon)) |
| 988 | ; |
| 989 | |
| 990 | if (acceptTokenClass(EHTokRightAngle)) |
John Kessenich | a1e2d49 | 2016-09-20 13:22:58 -0600 | [diff] [blame] | 991 | break; |
John Kessenich | 86f7138 | 2016-09-19 20:23:18 -0600 | [diff] [blame] | 992 | |
| 993 | // declaration |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 994 | TIntermNode* node = nullptr; |
John Kessenich | 86f7138 | 2016-09-19 20:23:18 -0600 | [diff] [blame] | 995 | if (! acceptDeclaration(node)) { |
John Kessenich | a1e2d49 | 2016-09-20 13:22:58 -0600 | [diff] [blame] | 996 | expected("declaration in annotation"); |
John Kessenich | 86f7138 | 2016-09-19 20:23:18 -0600 | [diff] [blame] | 997 | return false; |
| 998 | } |
| 999 | } while (true); |
John Kessenich | a1e2d49 | 2016-09-20 13:22:58 -0600 | [diff] [blame] | 1000 | |
| 1001 | parseContext.unnestAnnotations(); |
| 1002 | return true; |
John Kessenich | 86f7138 | 2016-09-19 20:23:18 -0600 | [diff] [blame] | 1003 | } |
LoopDawg | 6daaa4f | 2016-06-23 19:13:48 -0600 | [diff] [blame] | 1004 | |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1005 | // sampler_type |
| 1006 | // : SAMPLER |
| 1007 | // | SAMPLER1D |
| 1008 | // | SAMPLER2D |
| 1009 | // | SAMPLER3D |
| 1010 | // | SAMPLERCUBE |
| 1011 | // | SAMPLERSTATE |
| 1012 | // | SAMPLERCOMPARISONSTATE |
| 1013 | bool HlslGrammar::acceptSamplerType(TType& type) |
| 1014 | { |
| 1015 | // read sampler type |
| 1016 | const EHlslTokenClass samplerType = peek(); |
| 1017 | |
LoopDawg | a78b029 | 2016-07-19 14:28:05 -0600 | [diff] [blame] | 1018 | // TODO: for DX9 |
LoopDawg | 5d58fae | 2016-07-15 11:22:24 -0600 | [diff] [blame] | 1019 | // TSamplerDim dim = EsdNone; |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1020 | |
LoopDawg | a78b029 | 2016-07-19 14:28:05 -0600 | [diff] [blame] | 1021 | bool isShadow = false; |
| 1022 | |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1023 | switch (samplerType) { |
| 1024 | case EHTokSampler: break; |
LoopDawg | 5d58fae | 2016-07-15 11:22:24 -0600 | [diff] [blame] | 1025 | case EHTokSampler1d: /*dim = Esd1D*/; break; |
| 1026 | case EHTokSampler2d: /*dim = Esd2D*/; break; |
| 1027 | case EHTokSampler3d: /*dim = Esd3D*/; break; |
| 1028 | case EHTokSamplerCube: /*dim = EsdCube*/; break; |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1029 | case EHTokSamplerState: break; |
LoopDawg | a78b029 | 2016-07-19 14:28:05 -0600 | [diff] [blame] | 1030 | case EHTokSamplerComparisonState: isShadow = true; break; |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1031 | default: |
| 1032 | return false; // not a sampler declaration |
| 1033 | } |
| 1034 | |
| 1035 | advanceToken(); // consume the sampler type keyword |
| 1036 | |
| 1037 | TArraySizes* arraySizes = nullptr; // TODO: array |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1038 | |
| 1039 | TSampler sampler; |
LoopDawg | a78b029 | 2016-07-19 14:28:05 -0600 | [diff] [blame] | 1040 | sampler.setPureSampler(isShadow); |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1041 | |
| 1042 | type.shallowCopy(TType(sampler, EvqUniform, arraySizes)); |
| 1043 | |
| 1044 | return true; |
| 1045 | } |
| 1046 | |
| 1047 | // texture_type |
| 1048 | // | BUFFER |
| 1049 | // | TEXTURE1D |
| 1050 | // | TEXTURE1DARRAY |
| 1051 | // | TEXTURE2D |
| 1052 | // | TEXTURE2DARRAY |
| 1053 | // | TEXTURE3D |
| 1054 | // | TEXTURECUBE |
| 1055 | // | TEXTURECUBEARRAY |
| 1056 | // | TEXTURE2DMS |
| 1057 | // | TEXTURE2DMSARRAY |
steve-lunarg | bb0183f | 2016-10-04 16:58:14 -0600 | [diff] [blame] | 1058 | // | RWBUFFER |
| 1059 | // | RWTEXTURE1D |
| 1060 | // | RWTEXTURE1DARRAY |
| 1061 | // | RWTEXTURE2D |
| 1062 | // | RWTEXTURE2DARRAY |
| 1063 | // | RWTEXTURE3D |
| 1064 | |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1065 | bool HlslGrammar::acceptTextureType(TType& type) |
| 1066 | { |
| 1067 | const EHlslTokenClass textureType = peek(); |
| 1068 | |
| 1069 | TSamplerDim dim = EsdNone; |
| 1070 | bool array = false; |
| 1071 | bool ms = false; |
steve-lunarg | bb0183f | 2016-10-04 16:58:14 -0600 | [diff] [blame] | 1072 | bool image = false; |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1073 | |
| 1074 | switch (textureType) { |
| 1075 | case EHTokBuffer: dim = EsdBuffer; break; |
| 1076 | case EHTokTexture1d: dim = Esd1D; break; |
| 1077 | case EHTokTexture1darray: dim = Esd1D; array = true; break; |
| 1078 | case EHTokTexture2d: dim = Esd2D; break; |
| 1079 | case EHTokTexture2darray: dim = Esd2D; array = true; break; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 1080 | case EHTokTexture3d: dim = Esd3D; break; |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1081 | case EHTokTextureCube: dim = EsdCube; break; |
| 1082 | case EHTokTextureCubearray: dim = EsdCube; array = true; break; |
| 1083 | case EHTokTexture2DMS: dim = Esd2D; ms = true; break; |
| 1084 | case EHTokTexture2DMSarray: dim = Esd2D; array = true; ms = true; break; |
steve-lunarg | bb0183f | 2016-10-04 16:58:14 -0600 | [diff] [blame] | 1085 | case EHTokRWBuffer: dim = EsdBuffer; image=true; break; |
| 1086 | case EHTokRWTexture1d: dim = Esd1D; array=false; image=true; break; |
| 1087 | case EHTokRWTexture1darray: dim = Esd1D; array=true; image=true; break; |
| 1088 | case EHTokRWTexture2d: dim = Esd2D; array=false; image=true; break; |
| 1089 | case EHTokRWTexture2darray: dim = Esd2D; array=true; image=true; break; |
| 1090 | case EHTokRWTexture3d: dim = Esd3D; array=false; image=true; break; |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1091 | default: |
| 1092 | return false; // not a texture declaration |
| 1093 | } |
| 1094 | |
| 1095 | advanceToken(); // consume the texture object keyword |
| 1096 | |
| 1097 | TType txType(EbtFloat, EvqUniform, 4); // default type is float4 |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 1098 | |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1099 | TIntermTyped* msCount = nullptr; |
| 1100 | |
steve-lunarg | bb0183f | 2016-10-04 16:58:14 -0600 | [diff] [blame] | 1101 | // texture type: required for multisample types and RWBuffer/RWTextures! |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1102 | if (acceptTokenClass(EHTokLeftAngle)) { |
| 1103 | if (! acceptType(txType)) { |
| 1104 | expected("scalar or vector type"); |
| 1105 | return false; |
| 1106 | } |
| 1107 | |
| 1108 | const TBasicType basicRetType = txType.getBasicType() ; |
| 1109 | |
| 1110 | if (basicRetType != EbtFloat && basicRetType != EbtUint && basicRetType != EbtInt) { |
| 1111 | unimplemented("basic type in texture"); |
| 1112 | return false; |
| 1113 | } |
| 1114 | |
steve-lunarg | d53f717 | 2016-07-27 15:46:48 -0600 | [diff] [blame] | 1115 | // Buffers can handle small mats if they fit in 4 components |
| 1116 | if (dim == EsdBuffer && txType.isMatrix()) { |
| 1117 | if ((txType.getMatrixCols() * txType.getMatrixRows()) > 4) { |
| 1118 | expected("components < 4 in matrix buffer type"); |
| 1119 | return false; |
| 1120 | } |
| 1121 | |
| 1122 | // TODO: except we don't handle it yet... |
| 1123 | unimplemented("matrix type in buffer"); |
| 1124 | return false; |
| 1125 | } |
| 1126 | |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1127 | if (!txType.isScalar() && !txType.isVector()) { |
| 1128 | expected("scalar or vector type"); |
| 1129 | return false; |
| 1130 | } |
| 1131 | |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1132 | if (ms && acceptTokenClass(EHTokComma)) { |
| 1133 | // read sample count for multisample types, if given |
| 1134 | if (! peekTokenClass(EHTokIntConstant)) { |
| 1135 | expected("multisample count"); |
| 1136 | return false; |
| 1137 | } |
| 1138 | |
| 1139 | if (! acceptLiteral(msCount)) // should never fail, since we just found an integer |
| 1140 | return false; |
| 1141 | } |
| 1142 | |
| 1143 | if (! acceptTokenClass(EHTokRightAngle)) { |
| 1144 | expected("right angle bracket"); |
| 1145 | return false; |
| 1146 | } |
| 1147 | } else if (ms) { |
| 1148 | expected("texture type for multisample"); |
| 1149 | return false; |
steve-lunarg | bb0183f | 2016-10-04 16:58:14 -0600 | [diff] [blame] | 1150 | } else if (image) { |
| 1151 | expected("type for RWTexture/RWBuffer"); |
| 1152 | return false; |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | TArraySizes* arraySizes = nullptr; |
steve-lunarg | 4f2da27 | 2016-10-10 15:24:57 -0600 | [diff] [blame] | 1156 | const bool shadow = false; // declared on the sampler |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1157 | |
| 1158 | TSampler sampler; |
steve-lunarg | bb0183f | 2016-10-04 16:58:14 -0600 | [diff] [blame] | 1159 | TLayoutFormat format = ElfNone; |
steve-lunarg | d53f717 | 2016-07-27 15:46:48 -0600 | [diff] [blame] | 1160 | |
steve-lunarg | 4f2da27 | 2016-10-10 15:24:57 -0600 | [diff] [blame] | 1161 | // Buffer, RWBuffer and RWTexture (images) require a TLayoutFormat. We handle only a limit set. |
| 1162 | if (image || dim == EsdBuffer) |
| 1163 | format = parseContext.getLayoutFromTxType(token.loc, txType); |
steve-lunarg | bb0183f | 2016-10-04 16:58:14 -0600 | [diff] [blame] | 1164 | |
| 1165 | // Non-image Buffers are combined |
| 1166 | if (dim == EsdBuffer && !image) { |
steve-lunarg | d53f717 | 2016-07-27 15:46:48 -0600 | [diff] [blame] | 1167 | sampler.set(txType.getBasicType(), dim, array); |
| 1168 | } else { |
| 1169 | // DX10 textures are separated. TODO: DX9. |
steve-lunarg | bb0183f | 2016-10-04 16:58:14 -0600 | [diff] [blame] | 1170 | if (image) { |
| 1171 | sampler.setImage(txType.getBasicType(), dim, array, shadow, ms); |
| 1172 | } else { |
| 1173 | sampler.setTexture(txType.getBasicType(), dim, array, shadow, ms); |
| 1174 | } |
steve-lunarg | d53f717 | 2016-07-27 15:46:48 -0600 | [diff] [blame] | 1175 | } |
steve-lunarg | 8b0227c | 2016-10-14 16:40:32 -0600 | [diff] [blame] | 1176 | |
| 1177 | // Remember the declared vector size. |
| 1178 | sampler.vectorSize = txType.getVectorSize(); |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 1179 | |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1180 | type.shallowCopy(TType(sampler, EvqUniform, arraySizes)); |
steve-lunarg | bb0183f | 2016-10-04 16:58:14 -0600 | [diff] [blame] | 1181 | type.getQualifier().layoutFormat = format; |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1182 | |
| 1183 | return true; |
| 1184 | } |
| 1185 | |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1186 | // If token is for a type, update 'type' with the type information, |
| 1187 | // and return true and advance. |
| 1188 | // Otherwise, return false, and don't advance |
| 1189 | bool HlslGrammar::acceptType(TType& type) |
| 1190 | { |
steve-lunarg | 3226b08 | 2016-10-26 19:18:55 -0600 | [diff] [blame] | 1191 | // Basic types for min* types, broken out here in case of future |
| 1192 | // changes, e.g, to use native halfs. |
| 1193 | static const TBasicType min16float_bt = EbtFloat; |
| 1194 | static const TBasicType min10float_bt = EbtFloat; |
steve-lunarg | 5ca85ad | 2016-12-26 18:45:52 -0700 | [diff] [blame] | 1195 | static const TBasicType half_bt = EbtFloat; |
steve-lunarg | 3226b08 | 2016-10-26 19:18:55 -0600 | [diff] [blame] | 1196 | static const TBasicType min16int_bt = EbtInt; |
| 1197 | static const TBasicType min12int_bt = EbtInt; |
| 1198 | static const TBasicType min16uint_bt = EbtUint; |
| 1199 | |
John Kessenich | 9c86c6a | 2016-05-03 22:49:24 -0600 | [diff] [blame] | 1200 | switch (peek()) { |
LoopDawg | 6daaa4f | 2016-06-23 19:13:48 -0600 | [diff] [blame] | 1201 | case EHTokVector: |
| 1202 | return acceptVectorTemplateType(type); |
| 1203 | break; |
| 1204 | |
| 1205 | case EHTokMatrix: |
| 1206 | return acceptMatrixTemplateType(type); |
| 1207 | break; |
| 1208 | |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 1209 | case EHTokPointStream: // fall through |
| 1210 | case EHTokLineStream: // ... |
| 1211 | case EHTokTriangleStream: // ... |
| 1212 | { |
| 1213 | TLayoutGeometry geometry; |
| 1214 | if (! acceptStreamOutTemplateType(type, geometry)) |
| 1215 | return false; |
| 1216 | |
| 1217 | if (! parseContext.handleOutputGeometry(token.loc, geometry)) |
| 1218 | return false; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 1219 | |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 1220 | return true; |
| 1221 | } |
| 1222 | |
steve-lunarg | 858c928 | 2017-01-07 08:54:10 -0700 | [diff] [blame] | 1223 | case EHTokInputPatch: // fall through |
| 1224 | case EHTokOutputPatch: // ... |
| 1225 | { |
| 1226 | if (! acceptTessellationPatchTemplateType(type)) |
| 1227 | return false; |
| 1228 | |
| 1229 | return true; |
| 1230 | } |
| 1231 | |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1232 | case EHTokSampler: // fall through |
| 1233 | case EHTokSampler1d: // ... |
| 1234 | case EHTokSampler2d: // ... |
| 1235 | case EHTokSampler3d: // ... |
| 1236 | case EHTokSamplerCube: // ... |
| 1237 | case EHTokSamplerState: // ... |
| 1238 | case EHTokSamplerComparisonState: // ... |
| 1239 | return acceptSamplerType(type); |
| 1240 | break; |
| 1241 | |
| 1242 | case EHTokBuffer: // fall through |
| 1243 | case EHTokTexture1d: // ... |
| 1244 | case EHTokTexture1darray: // ... |
| 1245 | case EHTokTexture2d: // ... |
| 1246 | case EHTokTexture2darray: // ... |
| 1247 | case EHTokTexture3d: // ... |
| 1248 | case EHTokTextureCube: // ... |
| 1249 | case EHTokTextureCubearray: // ... |
| 1250 | case EHTokTexture2DMS: // ... |
| 1251 | case EHTokTexture2DMSarray: // ... |
steve-lunarg | bb0183f | 2016-10-04 16:58:14 -0600 | [diff] [blame] | 1252 | case EHTokRWTexture1d: // ... |
| 1253 | case EHTokRWTexture1darray: // ... |
| 1254 | case EHTokRWTexture2d: // ... |
| 1255 | case EHTokRWTexture2darray: // ... |
| 1256 | case EHTokRWTexture3d: // ... |
| 1257 | case EHTokRWBuffer: // ... |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 1258 | return acceptTextureType(type); |
| 1259 | break; |
| 1260 | |
steve-lunarg | 5da1f03 | 2017-02-12 17:50:28 -0700 | [diff] [blame] | 1261 | case EHTokAppendStructuredBuffer: |
| 1262 | case EHTokByteAddressBuffer: |
| 1263 | case EHTokConsumeStructuredBuffer: |
| 1264 | case EHTokRWByteAddressBuffer: |
| 1265 | case EHTokRWStructuredBuffer: |
| 1266 | case EHTokStructuredBuffer: |
| 1267 | return acceptStructBufferType(type); |
| 1268 | break; |
| 1269 | |
John Kessenich | 27ffb29 | 2017-03-03 17:01:01 -0700 | [diff] [blame] | 1270 | case EHTokClass: |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1271 | case EHTokStruct: |
John Kessenich | 3d157c5 | 2016-07-25 16:05:33 -0600 | [diff] [blame] | 1272 | case EHTokCBuffer: |
| 1273 | case EHTokTBuffer: |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1274 | return acceptStruct(type); |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1275 | |
| 1276 | case EHTokIdentifier: |
| 1277 | // An identifier could be for a user-defined type. |
| 1278 | // Note we cache the symbol table lookup, to save for a later rule |
| 1279 | // when this is not a type. |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 1280 | token.symbol = parseContext.lookupUserType(*token.string, type); |
| 1281 | if (token.symbol != nullptr) { |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1282 | advanceToken(); |
| 1283 | return true; |
| 1284 | } else |
| 1285 | return false; |
| 1286 | |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1287 | case EHTokVoid: |
| 1288 | new(&type) TType(EbtVoid); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1289 | break; |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1290 | |
John Kessenich | a1e2d49 | 2016-09-20 13:22:58 -0600 | [diff] [blame] | 1291 | case EHTokString: |
| 1292 | new(&type) TType(EbtString); |
| 1293 | break; |
| 1294 | |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1295 | case EHTokFloat: |
John Kessenich | 8d72f1a | 2016-05-20 12:06:03 -0600 | [diff] [blame] | 1296 | new(&type) TType(EbtFloat); |
| 1297 | break; |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1298 | case EHTokFloat1: |
| 1299 | new(&type) TType(EbtFloat); |
John Kessenich | 8d72f1a | 2016-05-20 12:06:03 -0600 | [diff] [blame] | 1300 | type.makeVector(); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1301 | break; |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1302 | case EHTokFloat2: |
| 1303 | new(&type) TType(EbtFloat, EvqTemporary, 2); |
| 1304 | break; |
| 1305 | case EHTokFloat3: |
| 1306 | new(&type) TType(EbtFloat, EvqTemporary, 3); |
| 1307 | break; |
| 1308 | case EHTokFloat4: |
| 1309 | new(&type) TType(EbtFloat, EvqTemporary, 4); |
| 1310 | break; |
| 1311 | |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1312 | case EHTokDouble: |
| 1313 | new(&type) TType(EbtDouble); |
| 1314 | break; |
| 1315 | case EHTokDouble1: |
| 1316 | new(&type) TType(EbtDouble); |
| 1317 | type.makeVector(); |
| 1318 | break; |
| 1319 | case EHTokDouble2: |
| 1320 | new(&type) TType(EbtDouble, EvqTemporary, 2); |
| 1321 | break; |
| 1322 | case EHTokDouble3: |
| 1323 | new(&type) TType(EbtDouble, EvqTemporary, 3); |
| 1324 | break; |
| 1325 | case EHTokDouble4: |
| 1326 | new(&type) TType(EbtDouble, EvqTemporary, 4); |
| 1327 | break; |
| 1328 | |
| 1329 | case EHTokInt: |
| 1330 | case EHTokDword: |
| 1331 | new(&type) TType(EbtInt); |
| 1332 | break; |
| 1333 | case EHTokInt1: |
| 1334 | new(&type) TType(EbtInt); |
| 1335 | type.makeVector(); |
| 1336 | break; |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1337 | case EHTokInt2: |
| 1338 | new(&type) TType(EbtInt, EvqTemporary, 2); |
| 1339 | break; |
| 1340 | case EHTokInt3: |
| 1341 | new(&type) TType(EbtInt, EvqTemporary, 3); |
| 1342 | break; |
| 1343 | case EHTokInt4: |
| 1344 | new(&type) TType(EbtInt, EvqTemporary, 4); |
| 1345 | break; |
| 1346 | |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1347 | case EHTokUint: |
| 1348 | new(&type) TType(EbtUint); |
| 1349 | break; |
| 1350 | case EHTokUint1: |
| 1351 | new(&type) TType(EbtUint); |
| 1352 | type.makeVector(); |
| 1353 | break; |
| 1354 | case EHTokUint2: |
| 1355 | new(&type) TType(EbtUint, EvqTemporary, 2); |
| 1356 | break; |
| 1357 | case EHTokUint3: |
| 1358 | new(&type) TType(EbtUint, EvqTemporary, 3); |
| 1359 | break; |
| 1360 | case EHTokUint4: |
| 1361 | new(&type) TType(EbtUint, EvqTemporary, 4); |
| 1362 | break; |
| 1363 | |
| 1364 | case EHTokBool: |
| 1365 | new(&type) TType(EbtBool); |
| 1366 | break; |
| 1367 | case EHTokBool1: |
| 1368 | new(&type) TType(EbtBool); |
| 1369 | type.makeVector(); |
| 1370 | break; |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1371 | case EHTokBool2: |
| 1372 | new(&type) TType(EbtBool, EvqTemporary, 2); |
| 1373 | break; |
| 1374 | case EHTokBool3: |
| 1375 | new(&type) TType(EbtBool, EvqTemporary, 3); |
| 1376 | break; |
| 1377 | case EHTokBool4: |
| 1378 | new(&type) TType(EbtBool, EvqTemporary, 4); |
| 1379 | break; |
| 1380 | |
steve-lunarg | 5ca85ad | 2016-12-26 18:45:52 -0700 | [diff] [blame] | 1381 | case EHTokHalf: |
| 1382 | new(&type) TType(half_bt, EvqTemporary, EpqMedium); |
| 1383 | break; |
| 1384 | case EHTokHalf1: |
| 1385 | new(&type) TType(half_bt, EvqTemporary, EpqMedium); |
| 1386 | type.makeVector(); |
| 1387 | break; |
| 1388 | case EHTokHalf2: |
| 1389 | new(&type) TType(half_bt, EvqTemporary, EpqMedium, 2); |
| 1390 | break; |
| 1391 | case EHTokHalf3: |
| 1392 | new(&type) TType(half_bt, EvqTemporary, EpqMedium, 3); |
| 1393 | break; |
| 1394 | case EHTokHalf4: |
| 1395 | new(&type) TType(half_bt, EvqTemporary, EpqMedium, 4); |
| 1396 | break; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 1397 | |
steve-lunarg | 3226b08 | 2016-10-26 19:18:55 -0600 | [diff] [blame] | 1398 | case EHTokMin16float: |
| 1399 | new(&type) TType(min16float_bt, EvqTemporary, EpqMedium); |
| 1400 | break; |
| 1401 | case EHTokMin16float1: |
| 1402 | new(&type) TType(min16float_bt, EvqTemporary, EpqMedium); |
| 1403 | type.makeVector(); |
| 1404 | break; |
| 1405 | case EHTokMin16float2: |
| 1406 | new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 2); |
| 1407 | break; |
| 1408 | case EHTokMin16float3: |
| 1409 | new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 3); |
| 1410 | break; |
| 1411 | case EHTokMin16float4: |
| 1412 | new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 4); |
| 1413 | break; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 1414 | |
steve-lunarg | 3226b08 | 2016-10-26 19:18:55 -0600 | [diff] [blame] | 1415 | case EHTokMin10float: |
| 1416 | new(&type) TType(min10float_bt, EvqTemporary, EpqMedium); |
| 1417 | break; |
| 1418 | case EHTokMin10float1: |
| 1419 | new(&type) TType(min10float_bt, EvqTemporary, EpqMedium); |
| 1420 | type.makeVector(); |
| 1421 | break; |
| 1422 | case EHTokMin10float2: |
| 1423 | new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 2); |
| 1424 | break; |
| 1425 | case EHTokMin10float3: |
| 1426 | new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 3); |
| 1427 | break; |
| 1428 | case EHTokMin10float4: |
| 1429 | new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 4); |
| 1430 | break; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 1431 | |
steve-lunarg | 3226b08 | 2016-10-26 19:18:55 -0600 | [diff] [blame] | 1432 | case EHTokMin16int: |
| 1433 | new(&type) TType(min16int_bt, EvqTemporary, EpqMedium); |
| 1434 | break; |
| 1435 | case EHTokMin16int1: |
| 1436 | new(&type) TType(min16int_bt, EvqTemporary, EpqMedium); |
| 1437 | type.makeVector(); |
| 1438 | break; |
| 1439 | case EHTokMin16int2: |
| 1440 | new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 2); |
| 1441 | break; |
| 1442 | case EHTokMin16int3: |
| 1443 | new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 3); |
| 1444 | break; |
| 1445 | case EHTokMin16int4: |
| 1446 | new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 4); |
| 1447 | break; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 1448 | |
steve-lunarg | 3226b08 | 2016-10-26 19:18:55 -0600 | [diff] [blame] | 1449 | case EHTokMin12int: |
| 1450 | new(&type) TType(min12int_bt, EvqTemporary, EpqMedium); |
| 1451 | break; |
| 1452 | case EHTokMin12int1: |
| 1453 | new(&type) TType(min12int_bt, EvqTemporary, EpqMedium); |
| 1454 | type.makeVector(); |
| 1455 | break; |
| 1456 | case EHTokMin12int2: |
| 1457 | new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 2); |
| 1458 | break; |
| 1459 | case EHTokMin12int3: |
| 1460 | new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 3); |
| 1461 | break; |
| 1462 | case EHTokMin12int4: |
| 1463 | new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 4); |
| 1464 | break; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 1465 | |
steve-lunarg | 3226b08 | 2016-10-26 19:18:55 -0600 | [diff] [blame] | 1466 | case EHTokMin16uint: |
| 1467 | new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium); |
| 1468 | break; |
| 1469 | case EHTokMin16uint1: |
| 1470 | new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium); |
| 1471 | type.makeVector(); |
| 1472 | break; |
| 1473 | case EHTokMin16uint2: |
| 1474 | new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 2); |
| 1475 | break; |
| 1476 | case EHTokMin16uint3: |
| 1477 | new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 3); |
| 1478 | break; |
| 1479 | case EHTokMin16uint4: |
| 1480 | new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 4); |
| 1481 | break; |
| 1482 | |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1483 | case EHTokInt1x1: |
| 1484 | new(&type) TType(EbtInt, EvqTemporary, 0, 1, 1); |
| 1485 | break; |
| 1486 | case EHTokInt1x2: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1487 | new(&type) TType(EbtInt, EvqTemporary, 0, 1, 2); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1488 | break; |
| 1489 | case EHTokInt1x3: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1490 | new(&type) TType(EbtInt, EvqTemporary, 0, 1, 3); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1491 | break; |
| 1492 | case EHTokInt1x4: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1493 | new(&type) TType(EbtInt, EvqTemporary, 0, 1, 4); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1494 | break; |
| 1495 | case EHTokInt2x1: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1496 | new(&type) TType(EbtInt, EvqTemporary, 0, 2, 1); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1497 | break; |
| 1498 | case EHTokInt2x2: |
| 1499 | new(&type) TType(EbtInt, EvqTemporary, 0, 2, 2); |
| 1500 | break; |
| 1501 | case EHTokInt2x3: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1502 | new(&type) TType(EbtInt, EvqTemporary, 0, 2, 3); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1503 | break; |
| 1504 | case EHTokInt2x4: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1505 | new(&type) TType(EbtInt, EvqTemporary, 0, 2, 4); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1506 | break; |
| 1507 | case EHTokInt3x1: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1508 | new(&type) TType(EbtInt, EvqTemporary, 0, 3, 1); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1509 | break; |
| 1510 | case EHTokInt3x2: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1511 | new(&type) TType(EbtInt, EvqTemporary, 0, 3, 2); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1512 | break; |
| 1513 | case EHTokInt3x3: |
| 1514 | new(&type) TType(EbtInt, EvqTemporary, 0, 3, 3); |
| 1515 | break; |
| 1516 | case EHTokInt3x4: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1517 | new(&type) TType(EbtInt, EvqTemporary, 0, 3, 4); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1518 | break; |
| 1519 | case EHTokInt4x1: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1520 | new(&type) TType(EbtInt, EvqTemporary, 0, 4, 1); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1521 | break; |
| 1522 | case EHTokInt4x2: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1523 | new(&type) TType(EbtInt, EvqTemporary, 0, 4, 2); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1524 | break; |
| 1525 | case EHTokInt4x3: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1526 | new(&type) TType(EbtInt, EvqTemporary, 0, 4, 3); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1527 | break; |
| 1528 | case EHTokInt4x4: |
| 1529 | new(&type) TType(EbtInt, EvqTemporary, 0, 4, 4); |
| 1530 | break; |
| 1531 | |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1532 | case EHTokUint1x1: |
| 1533 | new(&type) TType(EbtUint, EvqTemporary, 0, 1, 1); |
| 1534 | break; |
| 1535 | case EHTokUint1x2: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1536 | new(&type) TType(EbtUint, EvqTemporary, 0, 1, 2); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1537 | break; |
| 1538 | case EHTokUint1x3: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1539 | new(&type) TType(EbtUint, EvqTemporary, 0, 1, 3); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1540 | break; |
| 1541 | case EHTokUint1x4: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1542 | new(&type) TType(EbtUint, EvqTemporary, 0, 1, 4); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1543 | break; |
| 1544 | case EHTokUint2x1: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1545 | new(&type) TType(EbtUint, EvqTemporary, 0, 2, 1); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1546 | break; |
| 1547 | case EHTokUint2x2: |
| 1548 | new(&type) TType(EbtUint, EvqTemporary, 0, 2, 2); |
| 1549 | break; |
| 1550 | case EHTokUint2x3: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1551 | new(&type) TType(EbtUint, EvqTemporary, 0, 2, 3); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1552 | break; |
| 1553 | case EHTokUint2x4: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1554 | new(&type) TType(EbtUint, EvqTemporary, 0, 2, 4); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1555 | break; |
| 1556 | case EHTokUint3x1: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1557 | new(&type) TType(EbtUint, EvqTemporary, 0, 3, 1); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1558 | break; |
| 1559 | case EHTokUint3x2: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1560 | new(&type) TType(EbtUint, EvqTemporary, 0, 3, 2); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1561 | break; |
| 1562 | case EHTokUint3x3: |
| 1563 | new(&type) TType(EbtUint, EvqTemporary, 0, 3, 3); |
| 1564 | break; |
| 1565 | case EHTokUint3x4: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1566 | new(&type) TType(EbtUint, EvqTemporary, 0, 3, 4); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1567 | break; |
| 1568 | case EHTokUint4x1: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1569 | new(&type) TType(EbtUint, EvqTemporary, 0, 4, 1); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1570 | break; |
| 1571 | case EHTokUint4x2: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1572 | new(&type) TType(EbtUint, EvqTemporary, 0, 4, 2); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1573 | break; |
| 1574 | case EHTokUint4x3: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1575 | new(&type) TType(EbtUint, EvqTemporary, 0, 4, 3); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1576 | break; |
| 1577 | case EHTokUint4x4: |
| 1578 | new(&type) TType(EbtUint, EvqTemporary, 0, 4, 4); |
| 1579 | break; |
| 1580 | |
| 1581 | case EHTokBool1x1: |
| 1582 | new(&type) TType(EbtBool, EvqTemporary, 0, 1, 1); |
| 1583 | break; |
| 1584 | case EHTokBool1x2: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1585 | new(&type) TType(EbtBool, EvqTemporary, 0, 1, 2); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1586 | break; |
| 1587 | case EHTokBool1x3: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1588 | new(&type) TType(EbtBool, EvqTemporary, 0, 1, 3); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1589 | break; |
| 1590 | case EHTokBool1x4: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1591 | new(&type) TType(EbtBool, EvqTemporary, 0, 1, 4); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1592 | break; |
| 1593 | case EHTokBool2x1: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1594 | new(&type) TType(EbtBool, EvqTemporary, 0, 2, 1); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1595 | break; |
| 1596 | case EHTokBool2x2: |
| 1597 | new(&type) TType(EbtBool, EvqTemporary, 0, 2, 2); |
| 1598 | break; |
| 1599 | case EHTokBool2x3: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1600 | new(&type) TType(EbtBool, EvqTemporary, 0, 2, 3); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1601 | break; |
| 1602 | case EHTokBool2x4: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1603 | new(&type) TType(EbtBool, EvqTemporary, 0, 2, 4); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1604 | break; |
| 1605 | case EHTokBool3x1: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1606 | new(&type) TType(EbtBool, EvqTemporary, 0, 3, 1); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1607 | break; |
| 1608 | case EHTokBool3x2: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1609 | new(&type) TType(EbtBool, EvqTemporary, 0, 3, 2); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1610 | break; |
| 1611 | case EHTokBool3x3: |
| 1612 | new(&type) TType(EbtBool, EvqTemporary, 0, 3, 3); |
| 1613 | break; |
| 1614 | case EHTokBool3x4: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1615 | new(&type) TType(EbtBool, EvqTemporary, 0, 3, 4); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1616 | break; |
| 1617 | case EHTokBool4x1: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1618 | new(&type) TType(EbtBool, EvqTemporary, 0, 4, 1); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1619 | break; |
| 1620 | case EHTokBool4x2: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1621 | new(&type) TType(EbtBool, EvqTemporary, 0, 4, 2); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1622 | break; |
| 1623 | case EHTokBool4x3: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1624 | new(&type) TType(EbtBool, EvqTemporary, 0, 4, 3); |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1625 | break; |
| 1626 | case EHTokBool4x4: |
| 1627 | new(&type) TType(EbtBool, EvqTemporary, 0, 4, 4); |
| 1628 | break; |
| 1629 | |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1630 | case EHTokFloat1x1: |
| 1631 | new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 1); |
| 1632 | break; |
| 1633 | case EHTokFloat1x2: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1634 | new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 2); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1635 | break; |
| 1636 | case EHTokFloat1x3: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1637 | new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 3); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1638 | break; |
| 1639 | case EHTokFloat1x4: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1640 | new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 4); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1641 | break; |
| 1642 | case EHTokFloat2x1: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1643 | new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 1); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1644 | break; |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1645 | case EHTokFloat2x2: |
| 1646 | new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 2); |
| 1647 | break; |
| 1648 | case EHTokFloat2x3: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1649 | new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 3); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1650 | break; |
| 1651 | case EHTokFloat2x4: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1652 | new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 4); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1653 | break; |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1654 | case EHTokFloat3x1: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1655 | new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 1); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1656 | break; |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1657 | case EHTokFloat3x2: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1658 | new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 2); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1659 | break; |
| 1660 | case EHTokFloat3x3: |
| 1661 | new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 3); |
| 1662 | break; |
| 1663 | case EHTokFloat3x4: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1664 | new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 4); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1665 | break; |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1666 | case EHTokFloat4x1: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1667 | new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 1); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1668 | break; |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1669 | case EHTokFloat4x2: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1670 | new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 2); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1671 | break; |
| 1672 | case EHTokFloat4x3: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1673 | new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 3); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1674 | break; |
| 1675 | case EHTokFloat4x4: |
| 1676 | new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 4); |
| 1677 | break; |
| 1678 | |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1679 | case EHTokDouble1x1: |
| 1680 | new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 1); |
| 1681 | break; |
| 1682 | case EHTokDouble1x2: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1683 | new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 2); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1684 | break; |
| 1685 | case EHTokDouble1x3: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1686 | new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 3); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1687 | break; |
| 1688 | case EHTokDouble1x4: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1689 | new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 4); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1690 | break; |
| 1691 | case EHTokDouble2x1: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1692 | new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 1); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1693 | break; |
| 1694 | case EHTokDouble2x2: |
| 1695 | new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 2); |
| 1696 | break; |
| 1697 | case EHTokDouble2x3: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1698 | new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 3); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1699 | break; |
| 1700 | case EHTokDouble2x4: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1701 | new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 4); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1702 | break; |
| 1703 | case EHTokDouble3x1: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1704 | new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 1); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1705 | break; |
| 1706 | case EHTokDouble3x2: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1707 | new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 2); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1708 | break; |
| 1709 | case EHTokDouble3x3: |
| 1710 | new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 3); |
| 1711 | break; |
| 1712 | case EHTokDouble3x4: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1713 | new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 4); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1714 | break; |
| 1715 | case EHTokDouble4x1: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1716 | new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 1); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1717 | break; |
| 1718 | case EHTokDouble4x2: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1719 | new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 2); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1720 | break; |
| 1721 | case EHTokDouble4x3: |
steve-lunarg | 297ae21 | 2016-08-24 14:36:13 -0600 | [diff] [blame] | 1722 | new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 3); |
John Kessenich | 0133c12 | 2016-05-20 12:17:26 -0600 | [diff] [blame] | 1723 | break; |
| 1724 | case EHTokDouble4x4: |
| 1725 | new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 4); |
| 1726 | break; |
| 1727 | |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 1728 | default: |
| 1729 | return false; |
| 1730 | } |
| 1731 | |
| 1732 | advanceToken(); |
| 1733 | |
| 1734 | return true; |
| 1735 | } |
| 1736 | |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1737 | // struct |
John Kessenich | 3d157c5 | 2016-07-25 16:05:33 -0600 | [diff] [blame] | 1738 | // : struct_type IDENTIFIER post_decls LEFT_BRACE struct_declaration_list RIGHT_BRACE |
| 1739 | // | struct_type post_decls LEFT_BRACE struct_declaration_list RIGHT_BRACE |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 1740 | // | struct_type IDENTIFIER // use of previously declared struct type |
John Kessenich | 3d157c5 | 2016-07-25 16:05:33 -0600 | [diff] [blame] | 1741 | // |
| 1742 | // struct_type |
| 1743 | // : STRUCT |
John Kessenich | 27ffb29 | 2017-03-03 17:01:01 -0700 | [diff] [blame] | 1744 | // | CLASS |
John Kessenich | 3d157c5 | 2016-07-25 16:05:33 -0600 | [diff] [blame] | 1745 | // | CBUFFER |
| 1746 | // | TBUFFER |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1747 | // |
| 1748 | bool HlslGrammar::acceptStruct(TType& type) |
| 1749 | { |
John Kessenich | b804de6 | 2016-09-05 12:19:18 -0600 | [diff] [blame] | 1750 | // This storage qualifier will tell us whether it's an AST |
| 1751 | // block type or just a generic structure type. |
| 1752 | TStorageQualifier storageQualifier = EvqTemporary; |
John Kessenich | 3d157c5 | 2016-07-25 16:05:33 -0600 | [diff] [blame] | 1753 | |
| 1754 | // CBUFFER |
| 1755 | if (acceptTokenClass(EHTokCBuffer)) |
John Kessenich | b804de6 | 2016-09-05 12:19:18 -0600 | [diff] [blame] | 1756 | storageQualifier = EvqUniform; |
John Kessenich | 3d157c5 | 2016-07-25 16:05:33 -0600 | [diff] [blame] | 1757 | // TBUFFER |
| 1758 | else if (acceptTokenClass(EHTokTBuffer)) |
John Kessenich | b804de6 | 2016-09-05 12:19:18 -0600 | [diff] [blame] | 1759 | storageQualifier = EvqBuffer; |
John Kessenich | 27ffb29 | 2017-03-03 17:01:01 -0700 | [diff] [blame] | 1760 | // CLASS |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1761 | // STRUCT |
John Kessenich | 27ffb29 | 2017-03-03 17:01:01 -0700 | [diff] [blame] | 1762 | else if (! acceptTokenClass(EHTokClass) && ! acceptTokenClass(EHTokStruct)) |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1763 | return false; |
| 1764 | |
| 1765 | // IDENTIFIER |
| 1766 | TString structName = ""; |
| 1767 | if (peekTokenClass(EHTokIdentifier)) { |
| 1768 | structName = *token.string; |
| 1769 | advanceToken(); |
| 1770 | } |
| 1771 | |
John Kessenich | 3d157c5 | 2016-07-25 16:05:33 -0600 | [diff] [blame] | 1772 | // post_decls |
John Kessenich | 7735b94 | 2016-09-05 12:40:06 -0600 | [diff] [blame] | 1773 | TQualifier postDeclQualifier; |
| 1774 | postDeclQualifier.clear(); |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 1775 | bool postDeclsFound = acceptPostDecls(postDeclQualifier); |
John Kessenich | 3d157c5 | 2016-07-25 16:05:33 -0600 | [diff] [blame] | 1776 | |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1777 | // LEFT_BRACE |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 1778 | // struct_type IDENTIFIER |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1779 | if (! acceptTokenClass(EHTokLeftBrace)) { |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 1780 | if (structName.size() > 0 && !postDeclsFound && parseContext.lookupUserType(structName, type) != nullptr) { |
| 1781 | // struct_type IDENTIFIER |
| 1782 | return true; |
| 1783 | } else { |
| 1784 | expected("{"); |
| 1785 | return false; |
| 1786 | } |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | // struct_declaration_list |
| 1790 | TTypeList* typeList; |
| 1791 | if (! acceptStructDeclarationList(typeList)) { |
| 1792 | expected("struct member declarations"); |
| 1793 | return false; |
| 1794 | } |
| 1795 | |
| 1796 | // RIGHT_BRACE |
| 1797 | if (! acceptTokenClass(EHTokRightBrace)) { |
| 1798 | expected("}"); |
| 1799 | return false; |
| 1800 | } |
| 1801 | |
| 1802 | // create the user-defined type |
John Kessenich | b804de6 | 2016-09-05 12:19:18 -0600 | [diff] [blame] | 1803 | if (storageQualifier == EvqTemporary) |
John Kessenich | 3d157c5 | 2016-07-25 16:05:33 -0600 | [diff] [blame] | 1804 | new(&type) TType(typeList, structName); |
John Kessenich | b804de6 | 2016-09-05 12:19:18 -0600 | [diff] [blame] | 1805 | else { |
John Kessenich | 7735b94 | 2016-09-05 12:40:06 -0600 | [diff] [blame] | 1806 | postDeclQualifier.storage = storageQualifier; |
| 1807 | new(&type) TType(typeList, structName, postDeclQualifier); // sets EbtBlock |
John Kessenich | b804de6 | 2016-09-05 12:19:18 -0600 | [diff] [blame] | 1808 | } |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1809 | |
John Kessenich | 727b374 | 2017-02-03 17:57:55 -0700 | [diff] [blame] | 1810 | parseContext.declareStruct(token.loc, structName, type); |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1811 | |
| 1812 | return true; |
| 1813 | } |
| 1814 | |
steve-lunarg | 5da1f03 | 2017-02-12 17:50:28 -0700 | [diff] [blame] | 1815 | // struct_buffer |
| 1816 | // : APPENDSTRUCTUREDBUFFER |
| 1817 | // | BYTEADDRESSBUFFER |
| 1818 | // | CONSUMESTRUCTUREDBUFFER |
| 1819 | // | RWBYTEADDRESSBUFFER |
| 1820 | // | RWSTRUCTUREDBUFFER |
| 1821 | // | STRUCTUREDBUFFER |
| 1822 | bool HlslGrammar::acceptStructBufferType(TType& type) |
| 1823 | { |
| 1824 | const EHlslTokenClass structBuffType = peek(); |
| 1825 | |
| 1826 | // TODO: globallycoherent |
| 1827 | bool hasTemplateType = true; |
| 1828 | bool readonly = false; |
| 1829 | |
| 1830 | TStorageQualifier storage = EvqBuffer; |
| 1831 | |
| 1832 | switch (structBuffType) { |
| 1833 | case EHTokAppendStructuredBuffer: |
| 1834 | unimplemented("AppendStructuredBuffer"); |
| 1835 | return false; |
| 1836 | case EHTokByteAddressBuffer: |
| 1837 | hasTemplateType = false; |
| 1838 | readonly = true; |
| 1839 | break; |
| 1840 | case EHTokConsumeStructuredBuffer: |
| 1841 | unimplemented("ConsumeStructuredBuffer"); |
| 1842 | return false; |
| 1843 | case EHTokRWByteAddressBuffer: |
| 1844 | hasTemplateType = false; |
| 1845 | break; |
| 1846 | case EHTokRWStructuredBuffer: |
| 1847 | break; |
| 1848 | case EHTokStructuredBuffer: |
| 1849 | readonly = true; |
| 1850 | break; |
| 1851 | default: |
| 1852 | return false; // not a structure buffer type |
| 1853 | } |
| 1854 | |
| 1855 | advanceToken(); // consume the structure keyword |
| 1856 | |
| 1857 | // type on which this StructedBuffer is templatized. E.g, StructedBuffer<MyStruct> ==> MyStruct |
| 1858 | TType* templateType = new TType; |
| 1859 | |
| 1860 | if (hasTemplateType) { |
| 1861 | if (! acceptTokenClass(EHTokLeftAngle)) { |
| 1862 | expected("left angle bracket"); |
| 1863 | return false; |
| 1864 | } |
| 1865 | |
| 1866 | if (! acceptType(*templateType)) { |
| 1867 | expected("type"); |
| 1868 | return false; |
| 1869 | } |
| 1870 | if (! acceptTokenClass(EHTokRightAngle)) { |
| 1871 | expected("right angle bracket"); |
| 1872 | return false; |
| 1873 | } |
| 1874 | } else { |
| 1875 | // byte address buffers have no explicit type. |
| 1876 | TType uintType(EbtUint, storage); |
| 1877 | templateType->shallowCopy(uintType); |
| 1878 | } |
| 1879 | |
| 1880 | // Create an unsized array out of that type. |
| 1881 | // TODO: does this work if it's already an array type? |
| 1882 | TArraySizes unsizedArray; |
| 1883 | unsizedArray.addInnerSize(UnsizedArraySize); |
| 1884 | templateType->newArraySizes(unsizedArray); |
steve-lunarg | 40efe5c | 2017-03-06 12:01:44 -0700 | [diff] [blame] | 1885 | templateType->getQualifier().storage = storage; |
steve-lunarg | dd8287a | 2017-02-23 18:04:12 -0700 | [diff] [blame] | 1886 | |
| 1887 | // field name is canonical for all structbuffers |
| 1888 | templateType->setFieldName("@data"); |
steve-lunarg | 5da1f03 | 2017-02-12 17:50:28 -0700 | [diff] [blame] | 1889 | |
| 1890 | // Create block type. TODO: hidden internal uint member when needed |
steve-lunarg | dd8287a | 2017-02-23 18:04:12 -0700 | [diff] [blame] | 1891 | |
steve-lunarg | 5da1f03 | 2017-02-12 17:50:28 -0700 | [diff] [blame] | 1892 | TTypeList* blockStruct = new TTypeList; |
| 1893 | TTypeLoc member = { templateType, token.loc }; |
| 1894 | blockStruct->push_back(member); |
| 1895 | |
steve-lunarg | dd8287a | 2017-02-23 18:04:12 -0700 | [diff] [blame] | 1896 | // This is the type of the buffer block (SSBO) |
steve-lunarg | 5da1f03 | 2017-02-12 17:50:28 -0700 | [diff] [blame] | 1897 | TType blockType(blockStruct, "", templateType->getQualifier()); |
| 1898 | |
steve-lunarg | dd8287a | 2017-02-23 18:04:12 -0700 | [diff] [blame] | 1899 | blockType.getQualifier().storage = storage; |
| 1900 | blockType.getQualifier().readonly = readonly; |
| 1901 | |
| 1902 | // We may have created an equivalent type before, in which case we should use its |
| 1903 | // deep structure. |
| 1904 | parseContext.shareStructBufferType(blockType); |
| 1905 | |
steve-lunarg | 5da1f03 | 2017-02-12 17:50:28 -0700 | [diff] [blame] | 1906 | type.shallowCopy(blockType); |
| 1907 | |
| 1908 | return true; |
| 1909 | } |
| 1910 | |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1911 | // struct_declaration_list |
| 1912 | // : struct_declaration SEMI_COLON struct_declaration SEMI_COLON ... |
| 1913 | // |
| 1914 | // struct_declaration |
| 1915 | // : fully_specified_type struct_declarator COMMA struct_declarator ... |
| 1916 | // |
| 1917 | // struct_declarator |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 1918 | // : IDENTIFIER post_decls |
| 1919 | // | IDENTIFIER array_specifier post_decls |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1920 | // |
| 1921 | bool HlslGrammar::acceptStructDeclarationList(TTypeList*& typeList) |
| 1922 | { |
| 1923 | typeList = new TTypeList(); |
steve-lunarg | 5ca85ad | 2016-12-26 18:45:52 -0700 | [diff] [blame] | 1924 | HlslToken idToken; |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1925 | |
| 1926 | do { |
| 1927 | // success on seeing the RIGHT_BRACE coming up |
| 1928 | if (peekTokenClass(EHTokRightBrace)) |
| 1929 | return true; |
| 1930 | |
| 1931 | // struct_declaration |
| 1932 | |
| 1933 | // fully_specified_type |
| 1934 | TType memberType; |
| 1935 | if (! acceptFullySpecifiedType(memberType)) { |
| 1936 | expected("member type"); |
| 1937 | return false; |
| 1938 | } |
| 1939 | |
| 1940 | // struct_declarator COMMA struct_declarator ... |
| 1941 | do { |
steve-lunarg | 5ca85ad | 2016-12-26 18:45:52 -0700 | [diff] [blame] | 1942 | if (! acceptIdentifier(idToken)) { |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1943 | expected("member name"); |
| 1944 | return false; |
| 1945 | } |
| 1946 | |
| 1947 | // add it to the list of members |
| 1948 | TTypeLoc member = { new TType(EbtVoid), token.loc }; |
| 1949 | member.type->shallowCopy(memberType); |
steve-lunarg | 5ca85ad | 2016-12-26 18:45:52 -0700 | [diff] [blame] | 1950 | member.type->setFieldName(*idToken.string); |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1951 | typeList->push_back(member); |
| 1952 | |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1953 | // array_specifier |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 1954 | TArraySizes* arraySizes = nullptr; |
| 1955 | acceptArraySpecifier(arraySizes); |
| 1956 | if (arraySizes) |
| 1957 | typeList->back().type->newArraySizes(*arraySizes); |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1958 | |
John Kessenich | 7735b94 | 2016-09-05 12:40:06 -0600 | [diff] [blame] | 1959 | acceptPostDecls(member.type->getQualifier()); |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 1960 | |
John Kessenich | 18adbdb | 2017-02-02 15:16:20 -0700 | [diff] [blame] | 1961 | // EQUAL assignment_expression |
| 1962 | if (acceptTokenClass(EHTokAssign)) { |
| 1963 | parseContext.warn(idToken.loc, "struct-member initializers ignored", "typedef", ""); |
| 1964 | TIntermTyped* expressionNode = nullptr; |
| 1965 | if (! acceptAssignmentExpression(expressionNode)) { |
| 1966 | expected("initializer"); |
| 1967 | return false; |
| 1968 | } |
| 1969 | } |
| 1970 | |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 1971 | // success on seeing the SEMICOLON coming up |
| 1972 | if (peekTokenClass(EHTokSemicolon)) |
| 1973 | break; |
| 1974 | |
| 1975 | // COMMA |
| 1976 | if (! acceptTokenClass(EHTokComma)) { |
| 1977 | expected(","); |
| 1978 | return false; |
| 1979 | } |
| 1980 | |
| 1981 | } while (true); |
| 1982 | |
| 1983 | // SEMI_COLON |
| 1984 | if (! acceptTokenClass(EHTokSemicolon)) { |
| 1985 | expected(";"); |
| 1986 | return false; |
| 1987 | } |
| 1988 | |
| 1989 | } while (true); |
| 1990 | } |
| 1991 | |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 1992 | // function_parameters |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 1993 | // : LEFT_PAREN parameter_declaration COMMA parameter_declaration ... RIGHT_PAREN |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 1994 | // | LEFT_PAREN VOID RIGHT_PAREN |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 1995 | // |
| 1996 | bool HlslGrammar::acceptFunctionParameters(TFunction& function) |
| 1997 | { |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 1998 | // LEFT_PAREN |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 1999 | if (! acceptTokenClass(EHTokLeftParen)) |
| 2000 | return false; |
| 2001 | |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 2002 | // VOID RIGHT_PAREN |
| 2003 | if (! acceptTokenClass(EHTokVoid)) { |
| 2004 | do { |
| 2005 | // parameter_declaration |
| 2006 | if (! acceptParameterDeclaration(function)) |
| 2007 | break; |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2008 | |
John Kessenich | 71351de | 2016-06-08 12:50:56 -0600 | [diff] [blame] | 2009 | // COMMA |
| 2010 | if (! acceptTokenClass(EHTokComma)) |
| 2011 | break; |
| 2012 | } while (true); |
| 2013 | } |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2014 | |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 2015 | // RIGHT_PAREN |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2016 | if (! acceptTokenClass(EHTokRightParen)) { |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2017 | expected(")"); |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2018 | return false; |
| 2019 | } |
| 2020 | |
| 2021 | return true; |
| 2022 | } |
| 2023 | |
steve-lunarg | 26d3145 | 2016-12-23 18:56:57 -0700 | [diff] [blame] | 2024 | // default_parameter_declaration |
| 2025 | // : EQUAL conditional_expression |
| 2026 | // : EQUAL initializer |
| 2027 | bool HlslGrammar::acceptDefaultParameterDeclaration(const TType& type, TIntermTyped*& node) |
| 2028 | { |
| 2029 | node = nullptr; |
| 2030 | |
| 2031 | // Valid not to have a default_parameter_declaration |
| 2032 | if (!acceptTokenClass(EHTokAssign)) |
| 2033 | return true; |
| 2034 | |
| 2035 | if (!acceptConditionalExpression(node)) { |
| 2036 | if (!acceptInitializer(node)) |
| 2037 | return false; |
| 2038 | |
| 2039 | // For initializer lists, we have to const-fold into a constructor for the type, so build |
| 2040 | // that. |
| 2041 | TFunction* constructor = parseContext.handleConstructorCall(token.loc, type); |
| 2042 | if (constructor == nullptr) // cannot construct |
| 2043 | return false; |
| 2044 | |
| 2045 | TIntermTyped* arguments = nullptr; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 2046 | for (int i = 0; i < int(node->getAsAggregate()->getSequence().size()); i++) |
steve-lunarg | 26d3145 | 2016-12-23 18:56:57 -0700 | [diff] [blame] | 2047 | parseContext.handleFunctionArgument(constructor, arguments, node->getAsAggregate()->getSequence()[i]->getAsTyped()); |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 2048 | |
steve-lunarg | 26d3145 | 2016-12-23 18:56:57 -0700 | [diff] [blame] | 2049 | node = parseContext.handleFunctionCall(token.loc, constructor, node); |
| 2050 | } |
| 2051 | |
| 2052 | // If this is simply a constant, we can use it directly. |
| 2053 | if (node->getAsConstantUnion()) |
| 2054 | return true; |
| 2055 | |
| 2056 | // Otherwise, it has to be const-foldable. |
| 2057 | TIntermTyped* origNode = node; |
| 2058 | |
| 2059 | node = intermediate.fold(node->getAsAggregate()); |
| 2060 | |
| 2061 | if (node != nullptr && origNode != node) |
| 2062 | return true; |
| 2063 | |
| 2064 | parseContext.error(token.loc, "invalid default parameter value", "", ""); |
| 2065 | |
| 2066 | return false; |
| 2067 | } |
| 2068 | |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2069 | // parameter_declaration |
steve-lunarg | 26d3145 | 2016-12-23 18:56:57 -0700 | [diff] [blame] | 2070 | // : fully_specified_type post_decls [ = default_parameter_declaration ] |
| 2071 | // | fully_specified_type identifier array_specifier post_decls [ = default_parameter_declaration ] |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2072 | // |
| 2073 | bool HlslGrammar::acceptParameterDeclaration(TFunction& function) |
| 2074 | { |
| 2075 | // fully_specified_type |
| 2076 | TType* type = new TType; |
| 2077 | if (! acceptFullySpecifiedType(*type)) |
| 2078 | return false; |
| 2079 | |
| 2080 | // identifier |
John Kessenich | aecd497 | 2016-03-14 10:46:34 -0600 | [diff] [blame] | 2081 | HlslToken idToken; |
| 2082 | acceptIdentifier(idToken); |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2083 | |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 2084 | // array_specifier |
| 2085 | TArraySizes* arraySizes = nullptr; |
| 2086 | acceptArraySpecifier(arraySizes); |
steve-lunarg | 265c061 | 2016-09-27 10:57:35 -0600 | [diff] [blame] | 2087 | if (arraySizes) { |
| 2088 | if (arraySizes->isImplicit()) { |
| 2089 | parseContext.error(token.loc, "function parameter array cannot be implicitly sized", "", ""); |
| 2090 | return false; |
| 2091 | } |
| 2092 | |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 2093 | type->newArraySizes(*arraySizes); |
steve-lunarg | 265c061 | 2016-09-27 10:57:35 -0600 | [diff] [blame] | 2094 | } |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 2095 | |
| 2096 | // post_decls |
John Kessenich | 7735b94 | 2016-09-05 12:40:06 -0600 | [diff] [blame] | 2097 | acceptPostDecls(type->getQualifier()); |
John Kessenich | c3387d3 | 2016-06-17 14:21:02 -0600 | [diff] [blame] | 2098 | |
steve-lunarg | 26d3145 | 2016-12-23 18:56:57 -0700 | [diff] [blame] | 2099 | TIntermTyped* defaultValue; |
| 2100 | if (!acceptDefaultParameterDeclaration(*type, defaultValue)) |
| 2101 | return false; |
| 2102 | |
John Kessenich | 5aa59e2 | 2016-06-17 15:50:47 -0600 | [diff] [blame] | 2103 | parseContext.paramFix(*type); |
| 2104 | |
steve-lunarg | 26d3145 | 2016-12-23 18:56:57 -0700 | [diff] [blame] | 2105 | // If any prior parameters have default values, all the parameters after that must as well. |
| 2106 | if (defaultValue == nullptr && function.getDefaultParamCount() > 0) { |
| 2107 | parseContext.error(idToken.loc, "invalid parameter after default value parameters", idToken.string->c_str(), ""); |
| 2108 | return false; |
| 2109 | } |
| 2110 | |
| 2111 | TParameter param = { idToken.string, type, defaultValue }; |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2112 | function.addParameter(param); |
| 2113 | |
| 2114 | return true; |
| 2115 | } |
| 2116 | |
| 2117 | // Do the work to create the function definition in addition to |
| 2118 | // parsing the body (compound_statement). |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 2119 | bool HlslGrammar::acceptFunctionDefinition(TFunction& function, TIntermNode*& nodeList, const TAttributeMap& attributes) |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2120 | { |
John Kessenich | a305166 | 2016-09-02 19:13:36 -0600 | [diff] [blame] | 2121 | TFunction& functionDeclarator = parseContext.handleFunctionDeclarator(token.loc, function, false /* not prototype */); |
John Kessenich | 1a4b775 | 2016-09-02 19:05:24 -0600 | [diff] [blame] | 2122 | TSourceLoc loc = token.loc; |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2123 | |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 2124 | // we might get back and entry-point |
| 2125 | TIntermNode* entryPointNode = nullptr; |
| 2126 | |
John Kessenich | 077e052 | 2016-06-09 02:02:17 -0600 | [diff] [blame] | 2127 | // This does a pushScope() |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 2128 | TIntermNode* functionNode = parseContext.handleFunctionDefinition(loc, functionDeclarator, attributes, |
| 2129 | entryPointNode); |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2130 | |
| 2131 | // compound_statement |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2132 | TIntermNode* functionBody = nullptr; |
John Kessenich | 02467d8 | 2017-01-19 15:41:47 -0700 | [diff] [blame] | 2133 | if (! acceptCompoundStatement(functionBody)) |
| 2134 | return false; |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2135 | |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 2136 | parseContext.handleFunctionBody(loc, functionDeclarator, functionBody, functionNode); |
| 2137 | |
| 2138 | // Hook up the 1 or 2 function definitions. |
| 2139 | nodeList = intermediate.growAggregate(nodeList, functionNode); |
| 2140 | nodeList = intermediate.growAggregate(nodeList, entryPointNode); |
John Kessenich | 02467d8 | 2017-01-19 15:41:47 -0700 | [diff] [blame] | 2141 | |
| 2142 | return true; |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2143 | } |
| 2144 | |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2145 | // Accept an expression with parenthesis around it, where |
| 2146 | // the parenthesis ARE NOT expression parenthesis, but the |
John Kessenich | 5bc4d9a | 2016-06-20 01:22:38 -0600 | [diff] [blame] | 2147 | // syntactically required ones like in "if ( expression )". |
| 2148 | // |
| 2149 | // Also accepts a declaration expression; "if (int a = expression)". |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2150 | // |
| 2151 | // Note this one is not set up to be speculative; as it gives |
| 2152 | // errors if not found. |
| 2153 | // |
| 2154 | bool HlslGrammar::acceptParenExpression(TIntermTyped*& expression) |
| 2155 | { |
| 2156 | // LEFT_PAREN |
| 2157 | if (! acceptTokenClass(EHTokLeftParen)) |
| 2158 | expected("("); |
| 2159 | |
John Kessenich | 5bc4d9a | 2016-06-20 01:22:38 -0600 | [diff] [blame] | 2160 | bool decl = false; |
| 2161 | TIntermNode* declNode = nullptr; |
| 2162 | decl = acceptControlDeclaration(declNode); |
| 2163 | if (decl) { |
| 2164 | if (declNode == nullptr || declNode->getAsTyped() == nullptr) { |
| 2165 | expected("initialized declaration"); |
| 2166 | return false; |
| 2167 | } else |
| 2168 | expression = declNode->getAsTyped(); |
| 2169 | } else { |
| 2170 | // no declaration |
| 2171 | if (! acceptExpression(expression)) { |
| 2172 | expected("expression"); |
| 2173 | return false; |
| 2174 | } |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | // RIGHT_PAREN |
| 2178 | if (! acceptTokenClass(EHTokRightParen)) |
| 2179 | expected(")"); |
| 2180 | |
| 2181 | return true; |
| 2182 | } |
| 2183 | |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2184 | // The top-level full expression recognizer. |
| 2185 | // |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2186 | // expression |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2187 | // : assignment_expression COMMA assignment_expression COMMA assignment_expression ... |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2188 | // |
| 2189 | bool HlslGrammar::acceptExpression(TIntermTyped*& node) |
| 2190 | { |
LoopDawg | ef764a2 | 2016-06-03 09:17:51 -0600 | [diff] [blame] | 2191 | node = nullptr; |
| 2192 | |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2193 | // assignment_expression |
| 2194 | if (! acceptAssignmentExpression(node)) |
| 2195 | return false; |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2196 | |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2197 | if (! peekTokenClass(EHTokComma)) |
| 2198 | return true; |
| 2199 | |
| 2200 | do { |
| 2201 | // ... COMMA |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2202 | TSourceLoc loc = token.loc; |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2203 | advanceToken(); |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2204 | |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2205 | // ... assignment_expression |
| 2206 | TIntermTyped* rightNode = nullptr; |
| 2207 | if (! acceptAssignmentExpression(rightNode)) { |
| 2208 | expected("assignment expression"); |
| 2209 | return false; |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2210 | } |
| 2211 | |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2212 | node = intermediate.addComma(node, rightNode, loc); |
| 2213 | |
| 2214 | if (! peekTokenClass(EHTokComma)) |
| 2215 | return true; |
| 2216 | } while (true); |
| 2217 | } |
| 2218 | |
John Kessenich | 0735424 | 2016-07-01 19:58:06 -0600 | [diff] [blame] | 2219 | // initializer |
John Kessenich | 98ad485 | 2016-11-27 17:39:07 -0700 | [diff] [blame] | 2220 | // : LEFT_BRACE RIGHT_BRACE |
| 2221 | // | LEFT_BRACE initializer_list RIGHT_BRACE |
John Kessenich | 0735424 | 2016-07-01 19:58:06 -0600 | [diff] [blame] | 2222 | // |
| 2223 | // initializer_list |
| 2224 | // : assignment_expression COMMA assignment_expression COMMA ... |
| 2225 | // |
| 2226 | bool HlslGrammar::acceptInitializer(TIntermTyped*& node) |
| 2227 | { |
| 2228 | // LEFT_BRACE |
| 2229 | if (! acceptTokenClass(EHTokLeftBrace)) |
| 2230 | return false; |
| 2231 | |
John Kessenich | 98ad485 | 2016-11-27 17:39:07 -0700 | [diff] [blame] | 2232 | // RIGHT_BRACE |
John Kessenich | 0735424 | 2016-07-01 19:58:06 -0600 | [diff] [blame] | 2233 | TSourceLoc loc = token.loc; |
John Kessenich | 98ad485 | 2016-11-27 17:39:07 -0700 | [diff] [blame] | 2234 | if (acceptTokenClass(EHTokRightBrace)) { |
| 2235 | // a zero-length initializer list |
| 2236 | node = intermediate.makeAggregate(loc); |
| 2237 | return true; |
| 2238 | } |
| 2239 | |
| 2240 | // initializer_list |
John Kessenich | 0735424 | 2016-07-01 19:58:06 -0600 | [diff] [blame] | 2241 | node = nullptr; |
| 2242 | do { |
| 2243 | // assignment_expression |
| 2244 | TIntermTyped* expr; |
| 2245 | if (! acceptAssignmentExpression(expr)) { |
| 2246 | expected("assignment expression in initializer list"); |
| 2247 | return false; |
| 2248 | } |
| 2249 | node = intermediate.growAggregate(node, expr, loc); |
| 2250 | |
| 2251 | // COMMA |
steve-lunarg | fe5a3ff | 2016-07-30 10:36:09 -0600 | [diff] [blame] | 2252 | if (acceptTokenClass(EHTokComma)) { |
| 2253 | if (acceptTokenClass(EHTokRightBrace)) // allow trailing comma |
| 2254 | return true; |
John Kessenich | 0735424 | 2016-07-01 19:58:06 -0600 | [diff] [blame] | 2255 | continue; |
steve-lunarg | fe5a3ff | 2016-07-30 10:36:09 -0600 | [diff] [blame] | 2256 | } |
John Kessenich | 0735424 | 2016-07-01 19:58:06 -0600 | [diff] [blame] | 2257 | |
| 2258 | // RIGHT_BRACE |
| 2259 | if (acceptTokenClass(EHTokRightBrace)) |
| 2260 | return true; |
| 2261 | |
| 2262 | expected(", or }"); |
| 2263 | return false; |
| 2264 | } while (true); |
| 2265 | } |
| 2266 | |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2267 | // Accept an assignment expression, where assignment operations |
John Kessenich | 0735424 | 2016-07-01 19:58:06 -0600 | [diff] [blame] | 2268 | // associate right-to-left. That is, it is implicit, for example |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2269 | // |
| 2270 | // a op (b op (c op d)) |
| 2271 | // |
| 2272 | // assigment_expression |
John Kessenich | 00957f8 | 2016-07-27 10:39:57 -0600 | [diff] [blame] | 2273 | // : initializer |
| 2274 | // | conditional_expression |
| 2275 | // | conditional_expression assign_op conditional_expression assign_op conditional_expression ... |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2276 | // |
| 2277 | bool HlslGrammar::acceptAssignmentExpression(TIntermTyped*& node) |
| 2278 | { |
John Kessenich | 0735424 | 2016-07-01 19:58:06 -0600 | [diff] [blame] | 2279 | // initializer |
| 2280 | if (peekTokenClass(EHTokLeftBrace)) { |
| 2281 | if (acceptInitializer(node)) |
| 2282 | return true; |
| 2283 | |
| 2284 | expected("initializer"); |
| 2285 | return false; |
| 2286 | } |
| 2287 | |
John Kessenich | 00957f8 | 2016-07-27 10:39:57 -0600 | [diff] [blame] | 2288 | // conditional_expression |
| 2289 | if (! acceptConditionalExpression(node)) |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2290 | return false; |
| 2291 | |
John Kessenich | 0735424 | 2016-07-01 19:58:06 -0600 | [diff] [blame] | 2292 | // assignment operation? |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2293 | TOperator assignOp = HlslOpMap::assignment(peek()); |
| 2294 | if (assignOp == EOpNull) |
| 2295 | return true; |
| 2296 | |
John Kessenich | 00957f8 | 2016-07-27 10:39:57 -0600 | [diff] [blame] | 2297 | // assign_op |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2298 | TSourceLoc loc = token.loc; |
| 2299 | advanceToken(); |
| 2300 | |
John Kessenich | 00957f8 | 2016-07-27 10:39:57 -0600 | [diff] [blame] | 2301 | // conditional_expression assign_op conditional_expression ... |
| 2302 | // Done by recursing this function, which automatically |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2303 | // gets the right-to-left associativity. |
| 2304 | TIntermTyped* rightNode = nullptr; |
| 2305 | if (! acceptAssignmentExpression(rightNode)) { |
| 2306 | expected("assignment expression"); |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2307 | return false; |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2308 | } |
| 2309 | |
John Kessenich | d21baed | 2016-09-16 03:05:12 -0600 | [diff] [blame] | 2310 | node = parseContext.handleAssign(loc, assignOp, node, rightNode); |
steve-lunarg | 9070796 | 2016-10-07 19:35:40 -0600 | [diff] [blame] | 2311 | node = parseContext.handleLvalue(loc, "assign", node); |
| 2312 | |
John Kessenich | fea226b | 2016-07-28 17:53:56 -0600 | [diff] [blame] | 2313 | if (node == nullptr) { |
| 2314 | parseContext.error(loc, "could not create assignment", "", ""); |
| 2315 | return false; |
| 2316 | } |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2317 | |
| 2318 | if (! peekTokenClass(EHTokComma)) |
| 2319 | return true; |
| 2320 | |
| 2321 | return true; |
| 2322 | } |
| 2323 | |
John Kessenich | 00957f8 | 2016-07-27 10:39:57 -0600 | [diff] [blame] | 2324 | // Accept a conditional expression, which associates right-to-left, |
| 2325 | // accomplished by the "true" expression calling down to lower |
| 2326 | // precedence levels than this level. |
| 2327 | // |
| 2328 | // conditional_expression |
| 2329 | // : binary_expression |
| 2330 | // | binary_expression QUESTION expression COLON assignment_expression |
| 2331 | // |
| 2332 | bool HlslGrammar::acceptConditionalExpression(TIntermTyped*& node) |
| 2333 | { |
| 2334 | // binary_expression |
| 2335 | if (! acceptBinaryExpression(node, PlLogicalOr)) |
| 2336 | return false; |
| 2337 | |
| 2338 | if (! acceptTokenClass(EHTokQuestion)) |
| 2339 | return true; |
| 2340 | |
| 2341 | TIntermTyped* trueNode = nullptr; |
| 2342 | if (! acceptExpression(trueNode)) { |
| 2343 | expected("expression after ?"); |
| 2344 | return false; |
| 2345 | } |
| 2346 | TSourceLoc loc = token.loc; |
| 2347 | |
| 2348 | if (! acceptTokenClass(EHTokColon)) { |
| 2349 | expected(":"); |
| 2350 | return false; |
| 2351 | } |
| 2352 | |
| 2353 | TIntermTyped* falseNode = nullptr; |
| 2354 | if (! acceptAssignmentExpression(falseNode)) { |
| 2355 | expected("expression after :"); |
| 2356 | return false; |
| 2357 | } |
| 2358 | |
| 2359 | node = intermediate.addSelection(node, trueNode, falseNode, loc); |
| 2360 | |
| 2361 | return true; |
| 2362 | } |
| 2363 | |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2364 | // Accept a binary expression, for binary operations that |
| 2365 | // associate left-to-right. This is, it is implicit, for example |
| 2366 | // |
| 2367 | // ((a op b) op c) op d |
| 2368 | // |
| 2369 | // binary_expression |
| 2370 | // : expression op expression op expression ... |
| 2371 | // |
| 2372 | // where 'expression' is the next higher level in precedence. |
| 2373 | // |
| 2374 | bool HlslGrammar::acceptBinaryExpression(TIntermTyped*& node, PrecedenceLevel precedenceLevel) |
| 2375 | { |
| 2376 | if (precedenceLevel > PlMul) |
| 2377 | return acceptUnaryExpression(node); |
| 2378 | |
| 2379 | // assignment_expression |
| 2380 | if (! acceptBinaryExpression(node, (PrecedenceLevel)(precedenceLevel + 1))) |
| 2381 | return false; |
| 2382 | |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2383 | do { |
John Kessenich | 64076ed | 2016-07-28 21:43:17 -0600 | [diff] [blame] | 2384 | TOperator op = HlslOpMap::binary(peek()); |
| 2385 | PrecedenceLevel tokenLevel = HlslOpMap::precedenceLevel(op); |
| 2386 | if (tokenLevel < precedenceLevel) |
| 2387 | return true; |
| 2388 | |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2389 | // ... op |
| 2390 | TSourceLoc loc = token.loc; |
| 2391 | advanceToken(); |
| 2392 | |
| 2393 | // ... expression |
| 2394 | TIntermTyped* rightNode = nullptr; |
| 2395 | if (! acceptBinaryExpression(rightNode, (PrecedenceLevel)(precedenceLevel + 1))) { |
| 2396 | expected("expression"); |
| 2397 | return false; |
| 2398 | } |
| 2399 | |
| 2400 | node = intermediate.addBinaryMath(op, node, rightNode, loc); |
John Kessenich | fea226b | 2016-07-28 17:53:56 -0600 | [diff] [blame] | 2401 | if (node == nullptr) { |
| 2402 | parseContext.error(loc, "Could not perform requested binary operation", "", ""); |
| 2403 | return false; |
| 2404 | } |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2405 | } while (true); |
| 2406 | } |
| 2407 | |
| 2408 | // unary_expression |
John Kessenich | 1cc1a28 | 2016-06-03 16:55:49 -0600 | [diff] [blame] | 2409 | // : (type) unary_expression |
| 2410 | // | + unary_expression |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2411 | // | - unary_expression |
| 2412 | // | ! unary_expression |
| 2413 | // | ~ unary_expression |
| 2414 | // | ++ unary_expression |
| 2415 | // | -- unary_expression |
| 2416 | // | postfix_expression |
| 2417 | // |
| 2418 | bool HlslGrammar::acceptUnaryExpression(TIntermTyped*& node) |
| 2419 | { |
John Kessenich | 1cc1a28 | 2016-06-03 16:55:49 -0600 | [diff] [blame] | 2420 | // (type) unary_expression |
| 2421 | // Have to look two steps ahead, because this could be, e.g., a |
| 2422 | // postfix_expression instead, since that also starts with at "(". |
| 2423 | if (acceptTokenClass(EHTokLeftParen)) { |
| 2424 | TType castType; |
| 2425 | if (acceptType(castType)) { |
steve-lunarg | 5964c64 | 2016-07-30 07:38:55 -0600 | [diff] [blame] | 2426 | if (acceptTokenClass(EHTokRightParen)) { |
| 2427 | // We've matched "(type)" now, get the expression to cast |
| 2428 | TSourceLoc loc = token.loc; |
| 2429 | if (! acceptUnaryExpression(node)) |
| 2430 | return false; |
| 2431 | |
| 2432 | // Hook it up like a constructor |
| 2433 | TFunction* constructorFunction = parseContext.handleConstructorCall(loc, castType); |
| 2434 | if (constructorFunction == nullptr) { |
| 2435 | expected("type that can be constructed"); |
| 2436 | return false; |
| 2437 | } |
| 2438 | TIntermTyped* arguments = nullptr; |
| 2439 | parseContext.handleFunctionArgument(constructorFunction, arguments, node); |
| 2440 | node = parseContext.handleFunctionCall(loc, constructorFunction, arguments); |
| 2441 | |
| 2442 | return true; |
| 2443 | } else { |
| 2444 | // This could be a parenthesized constructor, ala (int(3)), and we just accepted |
| 2445 | // the '(int' part. We must back up twice. |
| 2446 | recedeToken(); |
| 2447 | recedeToken(); |
John Kessenich | 1cc1a28 | 2016-06-03 16:55:49 -0600 | [diff] [blame] | 2448 | } |
John Kessenich | 1cc1a28 | 2016-06-03 16:55:49 -0600 | [diff] [blame] | 2449 | } else { |
| 2450 | // This isn't a type cast, but it still started "(", so if it is a |
| 2451 | // unary expression, it can only be a postfix_expression, so try that. |
| 2452 | // Back it up first. |
| 2453 | recedeToken(); |
| 2454 | return acceptPostfixExpression(node); |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | // peek for "op unary_expression" |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2459 | TOperator unaryOp = HlslOpMap::preUnary(peek()); |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 2460 | |
John Kessenich | 1cc1a28 | 2016-06-03 16:55:49 -0600 | [diff] [blame] | 2461 | // postfix_expression (if no unary operator) |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2462 | if (unaryOp == EOpNull) |
| 2463 | return acceptPostfixExpression(node); |
| 2464 | |
| 2465 | // op unary_expression |
| 2466 | TSourceLoc loc = token.loc; |
| 2467 | advanceToken(); |
| 2468 | if (! acceptUnaryExpression(node)) |
| 2469 | return false; |
| 2470 | |
| 2471 | // + is a no-op |
| 2472 | if (unaryOp == EOpAdd) |
| 2473 | return true; |
| 2474 | |
| 2475 | node = intermediate.addUnaryMath(unaryOp, node, loc); |
steve-lunarg | e5921f1 | 2016-10-15 10:29:58 -0600 | [diff] [blame] | 2476 | |
| 2477 | // These unary ops require lvalues |
| 2478 | if (unaryOp == EOpPreIncrement || unaryOp == EOpPreDecrement) |
| 2479 | node = parseContext.handleLvalue(loc, "unary operator", node); |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2480 | |
| 2481 | return node != nullptr; |
| 2482 | } |
| 2483 | |
| 2484 | // postfix_expression |
| 2485 | // : LEFT_PAREN expression RIGHT_PAREN |
| 2486 | // | literal |
| 2487 | // | constructor |
| 2488 | // | identifier |
| 2489 | // | function_call |
| 2490 | // | postfix_expression LEFT_BRACKET integer_expression RIGHT_BRACKET |
| 2491 | // | postfix_expression DOT IDENTIFIER |
| 2492 | // | postfix_expression INC_OP |
| 2493 | // | postfix_expression DEC_OP |
| 2494 | // |
| 2495 | bool HlslGrammar::acceptPostfixExpression(TIntermTyped*& node) |
| 2496 | { |
| 2497 | // Not implemented as self-recursive: |
| 2498 | // The logical "right recursion" is done with an loop at the end |
| 2499 | |
| 2500 | // idToken will pick up either a variable or a function name in a function call |
| 2501 | HlslToken idToken; |
| 2502 | |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2503 | // Find something before the postfix operations, as they can't operate |
| 2504 | // on nothing. So, no "return true", they fall through, only "return false". |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2505 | if (acceptTokenClass(EHTokLeftParen)) { |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2506 | // LEFT_PAREN expression RIGHT_PAREN |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2507 | if (! acceptExpression(node)) { |
| 2508 | expected("expression"); |
| 2509 | return false; |
| 2510 | } |
| 2511 | if (! acceptTokenClass(EHTokRightParen)) { |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2512 | expected(")"); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2513 | return false; |
| 2514 | } |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2515 | } else if (acceptLiteral(node)) { |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 2516 | // literal (nothing else to do yet), go on to the |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2517 | } else if (acceptConstructor(node)) { |
| 2518 | // constructor (nothing else to do yet) |
| 2519 | } else if (acceptIdentifier(idToken)) { |
| 2520 | // identifier or function_call name |
| 2521 | if (! peekTokenClass(EHTokLeftParen)) { |
steve-lunarg | a64ed3e | 2016-12-18 17:51:14 -0700 | [diff] [blame] | 2522 | node = parseContext.handleVariable(idToken.loc, idToken.symbol, idToken.string); |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2523 | } else if (acceptFunctionCall(idToken, node)) { |
| 2524 | // function_call (nothing else to do yet) |
| 2525 | } else { |
| 2526 | expected("function call arguments"); |
| 2527 | return false; |
| 2528 | } |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2529 | } else { |
| 2530 | // nothing found, can't post operate |
| 2531 | return false; |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2532 | } |
| 2533 | |
steve-lunarg | a2b01a0 | 2016-11-28 17:09:54 -0700 | [diff] [blame] | 2534 | // This is to guarantee we do this no matter how we get out of the stack frame. |
| 2535 | // This way there's no bug if an early return forgets to do it. |
| 2536 | struct tFinalize { |
| 2537 | tFinalize(HlslParseContext& p) : parseContext(p) { } |
| 2538 | ~tFinalize() { parseContext.finalizeFlattening(); } |
John Kessenich | f8d0d8c | 2017-02-08 17:31:03 -0700 | [diff] [blame] | 2539 | HlslParseContext& parseContext; |
John Kessenich | 32fd5d2 | 2017-02-02 14:55:02 -0700 | [diff] [blame] | 2540 | private: |
John Kessenich | ca71d94 | 2017-03-07 20:44:09 -0700 | [diff] [blame] | 2541 | const tFinalize& operator=(const tFinalize&) { return *this; } |
John Kessenich | efeefd9 | 2017-03-01 13:12:26 -0700 | [diff] [blame] | 2542 | tFinalize(const tFinalize& f) : parseContext(f.parseContext) { } |
steve-lunarg | a2b01a0 | 2016-11-28 17:09:54 -0700 | [diff] [blame] | 2543 | } finalize(parseContext); |
| 2544 | |
| 2545 | // Initialize the flattening accumulation data, so we can track data across multiple bracket or |
| 2546 | // dot operators. This can also be nested, e.g, for [], so we have to track each nesting |
| 2547 | // level: hence the init and finalize. Even though in practice these must be |
| 2548 | // constants, they are parsed no matter what. |
| 2549 | parseContext.initFlattening(); |
| 2550 | |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2551 | // Something was found, chain as many postfix operations as exist. |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2552 | do { |
| 2553 | TSourceLoc loc = token.loc; |
| 2554 | TOperator postOp = HlslOpMap::postUnary(peek()); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2555 | |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2556 | // Consume only a valid post-unary operator, otherwise we are done. |
| 2557 | switch (postOp) { |
| 2558 | case EOpIndexDirectStruct: |
| 2559 | case EOpIndexIndirect: |
| 2560 | case EOpPostIncrement: |
| 2561 | case EOpPostDecrement: |
| 2562 | advanceToken(); |
| 2563 | break; |
| 2564 | default: |
| 2565 | return true; |
| 2566 | } |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2567 | |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2568 | // We have a valid post-unary operator, process it. |
| 2569 | switch (postOp) { |
| 2570 | case EOpIndexDirectStruct: |
John Kessenich | 93a162a | 2016-06-17 17:16:27 -0600 | [diff] [blame] | 2571 | { |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 2572 | // DOT IDENTIFIER |
| 2573 | // includes swizzles and struct members |
John Kessenich | 93a162a | 2016-06-17 17:16:27 -0600 | [diff] [blame] | 2574 | HlslToken field; |
| 2575 | if (! acceptIdentifier(field)) { |
| 2576 | expected("swizzle or member"); |
| 2577 | return false; |
| 2578 | } |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 2579 | |
| 2580 | TIntermTyped* base = node; // preserve for method function calls |
John Kessenich | 93a162a | 2016-06-17 17:16:27 -0600 | [diff] [blame] | 2581 | node = parseContext.handleDotDereference(field.loc, node, *field.string); |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 2582 | |
| 2583 | // In the event of a method node, we look for an open paren and accept the function call. |
steve-lunarg | a2b01a0 | 2016-11-28 17:09:54 -0700 | [diff] [blame] | 2584 | if (node != nullptr && node->getAsMethodNode() != nullptr && peekTokenClass(EHTokLeftParen)) { |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 2585 | if (! acceptFunctionCall(field, node, base)) { |
| 2586 | expected("function parameters"); |
| 2587 | return false; |
| 2588 | } |
| 2589 | } |
| 2590 | |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2591 | break; |
John Kessenich | 93a162a | 2016-06-17 17:16:27 -0600 | [diff] [blame] | 2592 | } |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2593 | case EOpIndexIndirect: |
| 2594 | { |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 2595 | // LEFT_BRACKET integer_expression RIGHT_BRACKET |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2596 | TIntermTyped* indexNode = nullptr; |
| 2597 | if (! acceptExpression(indexNode) || |
| 2598 | ! peekTokenClass(EHTokRightBracket)) { |
| 2599 | expected("expression followed by ']'"); |
| 2600 | return false; |
| 2601 | } |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 2602 | advanceToken(); |
| 2603 | node = parseContext.handleBracketDereference(indexNode->getLoc(), node, indexNode); |
| 2604 | break; |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2605 | } |
| 2606 | case EOpPostIncrement: |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 2607 | // INC_OP |
| 2608 | // fall through |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2609 | case EOpPostDecrement: |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 2610 | // DEC_OP |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2611 | node = intermediate.addUnaryMath(postOp, node, loc); |
steve-lunarg | 07830e8 | 2016-10-10 10:00:14 -0600 | [diff] [blame] | 2612 | node = parseContext.handleLvalue(loc, "unary operator", node); |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2613 | break; |
| 2614 | default: |
| 2615 | assert(0); |
| 2616 | break; |
| 2617 | } |
| 2618 | } while (true); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2619 | } |
| 2620 | |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 2621 | // constructor |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 2622 | // : type argument_list |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 2623 | // |
| 2624 | bool HlslGrammar::acceptConstructor(TIntermTyped*& node) |
| 2625 | { |
| 2626 | // type |
| 2627 | TType type; |
| 2628 | if (acceptType(type)) { |
| 2629 | TFunction* constructorFunction = parseContext.handleConstructorCall(token.loc, type); |
| 2630 | if (constructorFunction == nullptr) |
| 2631 | return false; |
| 2632 | |
| 2633 | // arguments |
John Kessenich | 4678ca9 | 2016-05-13 09:33:42 -0600 | [diff] [blame] | 2634 | TIntermTyped* arguments = nullptr; |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 2635 | if (! acceptArguments(constructorFunction, arguments)) { |
steve-lunarg | 5ca85ad | 2016-12-26 18:45:52 -0700 | [diff] [blame] | 2636 | // It's possible this is a type keyword used as an identifier. Put the token back |
| 2637 | // for later use. |
| 2638 | recedeToken(); |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 2639 | return false; |
| 2640 | } |
| 2641 | |
| 2642 | // hook it up |
| 2643 | node = parseContext.handleFunctionCall(arguments->getLoc(), constructorFunction, arguments); |
| 2644 | |
| 2645 | return true; |
| 2646 | } |
| 2647 | |
| 2648 | return false; |
| 2649 | } |
| 2650 | |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2651 | // The function_call identifier was already recognized, and passed in as idToken. |
| 2652 | // |
| 2653 | // function_call |
| 2654 | // : [idToken] arguments |
| 2655 | // |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 2656 | bool HlslGrammar::acceptFunctionCall(HlslToken idToken, TIntermTyped*& node, TIntermTyped* base) |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2657 | { |
John Kessenich | 4678ca9 | 2016-05-13 09:33:42 -0600 | [diff] [blame] | 2658 | // arguments |
| 2659 | TFunction* function = new TFunction(idToken.string, TType(EbtVoid)); |
| 2660 | TIntermTyped* arguments = nullptr; |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 2661 | |
| 2662 | // methods have an implicit first argument of the calling object. |
| 2663 | if (base != nullptr) |
| 2664 | parseContext.handleFunctionArgument(function, arguments, base); |
| 2665 | |
John Kessenich | 4678ca9 | 2016-05-13 09:33:42 -0600 | [diff] [blame] | 2666 | if (! acceptArguments(function, arguments)) |
| 2667 | return false; |
| 2668 | |
| 2669 | node = parseContext.handleFunctionCall(idToken.loc, function, arguments); |
| 2670 | |
| 2671 | return true; |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2672 | } |
| 2673 | |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2674 | // arguments |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 2675 | // : LEFT_PAREN expression COMMA expression COMMA ... RIGHT_PAREN |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2676 | // |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 2677 | // The arguments are pushed onto the 'function' argument list and |
| 2678 | // onto the 'arguments' aggregate. |
| 2679 | // |
John Kessenich | 4678ca9 | 2016-05-13 09:33:42 -0600 | [diff] [blame] | 2680 | bool HlslGrammar::acceptArguments(TFunction* function, TIntermTyped*& arguments) |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2681 | { |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 2682 | // LEFT_PAREN |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2683 | if (! acceptTokenClass(EHTokLeftParen)) |
| 2684 | return false; |
| 2685 | |
| 2686 | do { |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 2687 | // expression |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2688 | TIntermTyped* arg; |
John Kessenich | 4678ca9 | 2016-05-13 09:33:42 -0600 | [diff] [blame] | 2689 | if (! acceptAssignmentExpression(arg)) |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2690 | break; |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 2691 | |
| 2692 | // hook it up |
| 2693 | parseContext.handleFunctionArgument(function, arguments, arg); |
| 2694 | |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 2695 | // COMMA |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2696 | if (! acceptTokenClass(EHTokComma)) |
| 2697 | break; |
| 2698 | } while (true); |
| 2699 | |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 2700 | // RIGHT_PAREN |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2701 | if (! acceptTokenClass(EHTokRightParen)) { |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2702 | expected(")"); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2703 | return false; |
| 2704 | } |
| 2705 | |
| 2706 | return true; |
| 2707 | } |
| 2708 | |
| 2709 | bool HlslGrammar::acceptLiteral(TIntermTyped*& node) |
| 2710 | { |
| 2711 | switch (token.tokenClass) { |
| 2712 | case EHTokIntConstant: |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 2713 | node = intermediate.addConstantUnion(token.i, token.loc, true); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2714 | break; |
steve-lunarg | 2de3291 | 2016-07-28 14:49:48 -0600 | [diff] [blame] | 2715 | case EHTokUintConstant: |
| 2716 | node = intermediate.addConstantUnion(token.u, token.loc, true); |
| 2717 | break; |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2718 | case EHTokFloatConstant: |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 2719 | node = intermediate.addConstantUnion(token.d, EbtFloat, token.loc, true); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2720 | break; |
| 2721 | case EHTokDoubleConstant: |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 2722 | node = intermediate.addConstantUnion(token.d, EbtDouble, token.loc, true); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2723 | break; |
| 2724 | case EHTokBoolConstant: |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 2725 | node = intermediate.addConstantUnion(token.b, token.loc, true); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2726 | break; |
John Kessenich | 86f7138 | 2016-09-19 20:23:18 -0600 | [diff] [blame] | 2727 | case EHTokStringConstant: |
steve-lunarg | 858c928 | 2017-01-07 08:54:10 -0700 | [diff] [blame] | 2728 | node = intermediate.addConstantUnion(token.string, token.loc, true); |
John Kessenich | 86f7138 | 2016-09-19 20:23:18 -0600 | [diff] [blame] | 2729 | break; |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2730 | |
| 2731 | default: |
| 2732 | return false; |
| 2733 | } |
| 2734 | |
| 2735 | advanceToken(); |
| 2736 | |
| 2737 | return true; |
| 2738 | } |
| 2739 | |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2740 | // compound_statement |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2741 | // : LEFT_CURLY statement statement ... RIGHT_CURLY |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2742 | // |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2743 | bool HlslGrammar::acceptCompoundStatement(TIntermNode*& retStatement) |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2744 | { |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2745 | TIntermAggregate* compoundStatement = nullptr; |
| 2746 | |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2747 | // LEFT_CURLY |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2748 | if (! acceptTokenClass(EHTokLeftBrace)) |
| 2749 | return false; |
| 2750 | |
| 2751 | // statement statement ... |
| 2752 | TIntermNode* statement = nullptr; |
| 2753 | while (acceptStatement(statement)) { |
John Kessenich | d02dc5d | 2016-07-01 00:04:11 -0600 | [diff] [blame] | 2754 | TIntermBranch* branch = statement ? statement->getAsBranchNode() : nullptr; |
| 2755 | if (branch != nullptr && (branch->getFlowOp() == EOpCase || |
| 2756 | branch->getFlowOp() == EOpDefault)) { |
| 2757 | // hook up individual subsequences within a switch statement |
| 2758 | parseContext.wrapupSwitchSubsequence(compoundStatement, statement); |
| 2759 | compoundStatement = nullptr; |
| 2760 | } else { |
| 2761 | // hook it up to the growing compound statement |
| 2762 | compoundStatement = intermediate.growAggregate(compoundStatement, statement); |
| 2763 | } |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2764 | } |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2765 | if (compoundStatement) |
| 2766 | compoundStatement->setOperator(EOpSequence); |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2767 | |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2768 | retStatement = compoundStatement; |
| 2769 | |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 2770 | // RIGHT_CURLY |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2771 | return acceptTokenClass(EHTokRightBrace); |
| 2772 | } |
| 2773 | |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2774 | bool HlslGrammar::acceptScopedStatement(TIntermNode*& statement) |
| 2775 | { |
| 2776 | parseContext.pushScope(); |
John Kessenich | 077e052 | 2016-06-09 02:02:17 -0600 | [diff] [blame] | 2777 | bool result = acceptStatement(statement); |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2778 | parseContext.popScope(); |
| 2779 | |
| 2780 | return result; |
| 2781 | } |
| 2782 | |
John Kessenich | 077e052 | 2016-06-09 02:02:17 -0600 | [diff] [blame] | 2783 | bool HlslGrammar::acceptScopedCompoundStatement(TIntermNode*& statement) |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2784 | { |
John Kessenich | 077e052 | 2016-06-09 02:02:17 -0600 | [diff] [blame] | 2785 | parseContext.pushScope(); |
| 2786 | bool result = acceptCompoundStatement(statement); |
| 2787 | parseContext.popScope(); |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2788 | |
| 2789 | return result; |
| 2790 | } |
| 2791 | |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2792 | // statement |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2793 | // : attributes attributed_statement |
| 2794 | // |
| 2795 | // attributed_statement |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2796 | // : compound_statement |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2797 | // | SEMICOLON |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 2798 | // | expression SEMICOLON |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2799 | // | declaration_statement |
| 2800 | // | selection_statement |
| 2801 | // | switch_statement |
| 2802 | // | case_label |
| 2803 | // | iteration_statement |
| 2804 | // | jump_statement |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2805 | // |
| 2806 | bool HlslGrammar::acceptStatement(TIntermNode*& statement) |
| 2807 | { |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2808 | statement = nullptr; |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2809 | |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2810 | // attributes |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 2811 | TAttributeMap attributes; |
| 2812 | acceptAttributes(attributes); |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2813 | |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2814 | // attributed_statement |
| 2815 | switch (peek()) { |
| 2816 | case EHTokLeftBrace: |
John Kessenich | 077e052 | 2016-06-09 02:02:17 -0600 | [diff] [blame] | 2817 | return acceptScopedCompoundStatement(statement); |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2818 | |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2819 | case EHTokIf: |
| 2820 | return acceptSelectionStatement(statement); |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2821 | |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2822 | case EHTokSwitch: |
| 2823 | return acceptSwitchStatement(statement); |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2824 | |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2825 | case EHTokFor: |
| 2826 | case EHTokDo: |
| 2827 | case EHTokWhile: |
| 2828 | return acceptIterationStatement(statement); |
| 2829 | |
| 2830 | case EHTokContinue: |
| 2831 | case EHTokBreak: |
| 2832 | case EHTokDiscard: |
| 2833 | case EHTokReturn: |
| 2834 | return acceptJumpStatement(statement); |
| 2835 | |
| 2836 | case EHTokCase: |
| 2837 | return acceptCaseLabel(statement); |
John Kessenich | d02dc5d | 2016-07-01 00:04:11 -0600 | [diff] [blame] | 2838 | case EHTokDefault: |
| 2839 | return acceptDefaultLabel(statement); |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2840 | |
| 2841 | case EHTokSemicolon: |
| 2842 | return acceptTokenClass(EHTokSemicolon); |
| 2843 | |
| 2844 | case EHTokRightBrace: |
| 2845 | // Performance: not strictly necessary, but stops a bunch of hunting early, |
| 2846 | // and is how sequences of statements end. |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2847 | return false; |
| 2848 | |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2849 | default: |
| 2850 | { |
| 2851 | // declaration |
| 2852 | if (acceptDeclaration(statement)) |
| 2853 | return true; |
| 2854 | |
| 2855 | // expression |
| 2856 | TIntermTyped* node; |
| 2857 | if (acceptExpression(node)) |
| 2858 | statement = node; |
| 2859 | else |
| 2860 | return false; |
| 2861 | |
| 2862 | // SEMICOLON (following an expression) |
| 2863 | if (! acceptTokenClass(EHTokSemicolon)) { |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2864 | expected(";"); |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2865 | return false; |
| 2866 | } |
| 2867 | } |
| 2868 | } |
| 2869 | |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 2870 | return true; |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 2871 | } |
| 2872 | |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2873 | // attributes |
| 2874 | // : list of zero or more of: LEFT_BRACKET attribute RIGHT_BRACKET |
| 2875 | // |
| 2876 | // attribute: |
| 2877 | // : UNROLL |
| 2878 | // | UNROLL LEFT_PAREN literal RIGHT_PAREN |
| 2879 | // | FASTOPT |
| 2880 | // | ALLOW_UAV_CONDITION |
| 2881 | // | BRANCH |
| 2882 | // | FLATTEN |
| 2883 | // | FORCECASE |
| 2884 | // | CALL |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 2885 | // | DOMAIN |
| 2886 | // | EARLYDEPTHSTENCIL |
| 2887 | // | INSTANCE |
| 2888 | // | MAXTESSFACTOR |
| 2889 | // | OUTPUTCONTROLPOINTS |
| 2890 | // | OUTPUTTOPOLOGY |
| 2891 | // | PARTITIONING |
| 2892 | // | PATCHCONSTANTFUNC |
| 2893 | // | NUMTHREADS LEFT_PAREN x_size, y_size,z z_size RIGHT_PAREN |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2894 | // |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 2895 | void HlslGrammar::acceptAttributes(TAttributeMap& attributes) |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2896 | { |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 2897 | // For now, accept the [ XXX(X) ] syntax, but drop all but |
| 2898 | // numthreads, which is used to set the CS local size. |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2899 | // TODO: subset to correct set? Pass on? |
| 2900 | do { |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 2901 | HlslToken idToken; |
| 2902 | |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2903 | // LEFT_BRACKET? |
| 2904 | if (! acceptTokenClass(EHTokLeftBracket)) |
| 2905 | return; |
| 2906 | |
| 2907 | // attribute |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 2908 | if (acceptIdentifier(idToken)) { |
| 2909 | // 'idToken.string' is the attribute |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2910 | } else if (! peekTokenClass(EHTokRightBracket)) { |
| 2911 | expected("identifier"); |
| 2912 | advanceToken(); |
| 2913 | } |
| 2914 | |
steve-lunarg | a22f7db | 2016-11-11 08:17:44 -0700 | [diff] [blame] | 2915 | TIntermAggregate* expressions = nullptr; |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 2916 | |
| 2917 | // (x, ...) |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2918 | if (acceptTokenClass(EHTokLeftParen)) { |
steve-lunarg | a22f7db | 2016-11-11 08:17:44 -0700 | [diff] [blame] | 2919 | expressions = new TIntermAggregate; |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 2920 | |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2921 | TIntermTyped* node; |
steve-lunarg | a22f7db | 2016-11-11 08:17:44 -0700 | [diff] [blame] | 2922 | bool expectingExpression = false; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 2923 | |
steve-lunarg | a22f7db | 2016-11-11 08:17:44 -0700 | [diff] [blame] | 2924 | while (acceptAssignmentExpression(node)) { |
| 2925 | expectingExpression = false; |
| 2926 | expressions->getSequence().push_back(node); |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 2927 | if (acceptTokenClass(EHTokComma)) |
steve-lunarg | a22f7db | 2016-11-11 08:17:44 -0700 | [diff] [blame] | 2928 | expectingExpression = true; |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 2929 | } |
| 2930 | |
steve-lunarg | a22f7db | 2016-11-11 08:17:44 -0700 | [diff] [blame] | 2931 | // 'expressions' is an aggregate with the expressions in it |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2932 | if (! acceptTokenClass(EHTokRightParen)) |
| 2933 | expected(")"); |
steve-lunarg | a22f7db | 2016-11-11 08:17:44 -0700 | [diff] [blame] | 2934 | |
| 2935 | // Error for partial or missing expression |
| 2936 | if (expectingExpression || expressions->getSequence().empty()) |
| 2937 | expected("expression"); |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | // RIGHT_BRACKET |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 2941 | if (!acceptTokenClass(EHTokRightBracket)) { |
| 2942 | expected("]"); |
| 2943 | return; |
| 2944 | } |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2945 | |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 2946 | // Add any values we found into the attribute map. This accepts |
| 2947 | // (and ignores) values not mapping to a known TAttributeType; |
steve-lunarg | a22f7db | 2016-11-11 08:17:44 -0700 | [diff] [blame] | 2948 | attributes.setAttribute(idToken.string, expressions); |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2949 | } while (true); |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2950 | } |
| 2951 | |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2952 | // selection_statement |
| 2953 | // : IF LEFT_PAREN expression RIGHT_PAREN statement |
| 2954 | // : IF LEFT_PAREN expression RIGHT_PAREN statement ELSE statement |
| 2955 | // |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2956 | bool HlslGrammar::acceptSelectionStatement(TIntermNode*& statement) |
| 2957 | { |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 2958 | TSourceLoc loc = token.loc; |
| 2959 | |
| 2960 | // IF |
| 2961 | if (! acceptTokenClass(EHTokIf)) |
| 2962 | return false; |
| 2963 | |
| 2964 | // so that something declared in the condition is scoped to the lifetimes |
| 2965 | // of the then-else statements |
| 2966 | parseContext.pushScope(); |
| 2967 | |
| 2968 | // LEFT_PAREN expression RIGHT_PAREN |
| 2969 | TIntermTyped* condition; |
| 2970 | if (! acceptParenExpression(condition)) |
| 2971 | return false; |
| 2972 | |
| 2973 | // create the child statements |
| 2974 | TIntermNodePair thenElse = { nullptr, nullptr }; |
| 2975 | |
| 2976 | // then statement |
| 2977 | if (! acceptScopedStatement(thenElse.node1)) { |
| 2978 | expected("then statement"); |
| 2979 | return false; |
| 2980 | } |
| 2981 | |
| 2982 | // ELSE |
| 2983 | if (acceptTokenClass(EHTokElse)) { |
| 2984 | // else statement |
| 2985 | if (! acceptScopedStatement(thenElse.node2)) { |
| 2986 | expected("else statement"); |
| 2987 | return false; |
| 2988 | } |
| 2989 | } |
| 2990 | |
| 2991 | // Put the pieces together |
| 2992 | statement = intermediate.addSelection(condition, thenElse, loc); |
| 2993 | parseContext.popScope(); |
| 2994 | |
| 2995 | return true; |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 2996 | } |
| 2997 | |
John Kessenich | d02dc5d | 2016-07-01 00:04:11 -0600 | [diff] [blame] | 2998 | // switch_statement |
| 2999 | // : SWITCH LEFT_PAREN expression RIGHT_PAREN compound_statement |
| 3000 | // |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 3001 | bool HlslGrammar::acceptSwitchStatement(TIntermNode*& statement) |
| 3002 | { |
John Kessenich | d02dc5d | 2016-07-01 00:04:11 -0600 | [diff] [blame] | 3003 | // SWITCH |
| 3004 | TSourceLoc loc = token.loc; |
| 3005 | if (! acceptTokenClass(EHTokSwitch)) |
| 3006 | return false; |
| 3007 | |
| 3008 | // LEFT_PAREN expression RIGHT_PAREN |
| 3009 | parseContext.pushScope(); |
| 3010 | TIntermTyped* switchExpression; |
| 3011 | if (! acceptParenExpression(switchExpression)) { |
| 3012 | parseContext.popScope(); |
| 3013 | return false; |
| 3014 | } |
| 3015 | |
| 3016 | // compound_statement |
| 3017 | parseContext.pushSwitchSequence(new TIntermSequence); |
| 3018 | bool statementOkay = acceptCompoundStatement(statement); |
| 3019 | if (statementOkay) |
| 3020 | statement = parseContext.addSwitch(loc, switchExpression, statement ? statement->getAsAggregate() : nullptr); |
| 3021 | |
| 3022 | parseContext.popSwitchSequence(); |
| 3023 | parseContext.popScope(); |
| 3024 | |
| 3025 | return statementOkay; |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 3026 | } |
| 3027 | |
John Kessenich | 119f8f6 | 2016-06-05 15:44:07 -0600 | [diff] [blame] | 3028 | // iteration_statement |
| 3029 | // : WHILE LEFT_PAREN condition RIGHT_PAREN statement |
| 3030 | // | DO LEFT_BRACE statement RIGHT_BRACE WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON |
| 3031 | // | FOR LEFT_PAREN for_init_statement for_rest_statement RIGHT_PAREN statement |
| 3032 | // |
| 3033 | // Non-speculative, only call if it needs to be found; WHILE or DO or FOR already seen. |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 3034 | bool HlslGrammar::acceptIterationStatement(TIntermNode*& statement) |
| 3035 | { |
John Kessenich | 119f8f6 | 2016-06-05 15:44:07 -0600 | [diff] [blame] | 3036 | TSourceLoc loc = token.loc; |
| 3037 | TIntermTyped* condition = nullptr; |
| 3038 | |
| 3039 | EHlslTokenClass loop = peek(); |
| 3040 | assert(loop == EHTokDo || loop == EHTokFor || loop == EHTokWhile); |
| 3041 | |
| 3042 | // WHILE or DO or FOR |
| 3043 | advanceToken(); |
| 3044 | |
| 3045 | switch (loop) { |
| 3046 | case EHTokWhile: |
| 3047 | // so that something declared in the condition is scoped to the lifetime |
| 3048 | // of the while sub-statement |
| 3049 | parseContext.pushScope(); |
| 3050 | parseContext.nestLooping(); |
| 3051 | |
| 3052 | // LEFT_PAREN condition RIGHT_PAREN |
| 3053 | if (! acceptParenExpression(condition)) |
| 3054 | return false; |
| 3055 | |
| 3056 | // statement |
| 3057 | if (! acceptScopedStatement(statement)) { |
| 3058 | expected("while sub-statement"); |
| 3059 | return false; |
| 3060 | } |
| 3061 | |
| 3062 | parseContext.unnestLooping(); |
| 3063 | parseContext.popScope(); |
| 3064 | |
| 3065 | statement = intermediate.addLoop(statement, condition, nullptr, true, loc); |
| 3066 | |
| 3067 | return true; |
| 3068 | |
| 3069 | case EHTokDo: |
| 3070 | parseContext.nestLooping(); |
| 3071 | |
| 3072 | if (! acceptTokenClass(EHTokLeftBrace)) |
| 3073 | expected("{"); |
| 3074 | |
| 3075 | // statement |
| 3076 | if (! peekTokenClass(EHTokRightBrace) && ! acceptScopedStatement(statement)) { |
| 3077 | expected("do sub-statement"); |
| 3078 | return false; |
| 3079 | } |
| 3080 | |
| 3081 | if (! acceptTokenClass(EHTokRightBrace)) |
| 3082 | expected("}"); |
| 3083 | |
| 3084 | // WHILE |
| 3085 | if (! acceptTokenClass(EHTokWhile)) { |
| 3086 | expected("while"); |
| 3087 | return false; |
| 3088 | } |
| 3089 | |
| 3090 | // LEFT_PAREN condition RIGHT_PAREN |
| 3091 | TIntermTyped* condition; |
| 3092 | if (! acceptParenExpression(condition)) |
| 3093 | return false; |
| 3094 | |
| 3095 | if (! acceptTokenClass(EHTokSemicolon)) |
| 3096 | expected(";"); |
| 3097 | |
| 3098 | parseContext.unnestLooping(); |
| 3099 | |
| 3100 | statement = intermediate.addLoop(statement, condition, 0, false, loc); |
| 3101 | |
| 3102 | return true; |
| 3103 | |
| 3104 | case EHTokFor: |
| 3105 | { |
| 3106 | // LEFT_PAREN |
| 3107 | if (! acceptTokenClass(EHTokLeftParen)) |
| 3108 | expected("("); |
| 3109 | |
| 3110 | // so that something declared in the condition is scoped to the lifetime |
| 3111 | // of the for sub-statement |
| 3112 | parseContext.pushScope(); |
| 3113 | |
John Kessenich | 5bc4d9a | 2016-06-20 01:22:38 -0600 | [diff] [blame] | 3114 | // initializer |
| 3115 | TIntermNode* initNode = nullptr; |
| 3116 | if (! acceptControlDeclaration(initNode)) { |
| 3117 | TIntermTyped* initExpr = nullptr; |
| 3118 | acceptExpression(initExpr); |
| 3119 | initNode = initExpr; |
| 3120 | } |
| 3121 | // SEMI_COLON |
John Kessenich | 119f8f6 | 2016-06-05 15:44:07 -0600 | [diff] [blame] | 3122 | if (! acceptTokenClass(EHTokSemicolon)) |
| 3123 | expected(";"); |
| 3124 | |
| 3125 | parseContext.nestLooping(); |
| 3126 | |
| 3127 | // condition SEMI_COLON |
| 3128 | acceptExpression(condition); |
| 3129 | if (! acceptTokenClass(EHTokSemicolon)) |
| 3130 | expected(";"); |
| 3131 | |
| 3132 | // iterator SEMI_COLON |
| 3133 | TIntermTyped* iterator = nullptr; |
| 3134 | acceptExpression(iterator); |
| 3135 | if (! acceptTokenClass(EHTokRightParen)) |
| 3136 | expected(")"); |
| 3137 | |
| 3138 | // statement |
| 3139 | if (! acceptScopedStatement(statement)) { |
| 3140 | expected("for sub-statement"); |
| 3141 | return false; |
| 3142 | } |
| 3143 | |
John Kessenich | 5bc4d9a | 2016-06-20 01:22:38 -0600 | [diff] [blame] | 3144 | statement = intermediate.addForLoop(statement, initNode, condition, iterator, true, loc); |
John Kessenich | 119f8f6 | 2016-06-05 15:44:07 -0600 | [diff] [blame] | 3145 | |
| 3146 | parseContext.popScope(); |
| 3147 | parseContext.unnestLooping(); |
| 3148 | |
| 3149 | return true; |
| 3150 | } |
| 3151 | |
| 3152 | default: |
| 3153 | return false; |
| 3154 | } |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 3155 | } |
| 3156 | |
| 3157 | // jump_statement |
| 3158 | // : CONTINUE SEMICOLON |
| 3159 | // | BREAK SEMICOLON |
| 3160 | // | DISCARD SEMICOLON |
| 3161 | // | RETURN SEMICOLON |
| 3162 | // | RETURN expression SEMICOLON |
| 3163 | // |
| 3164 | bool HlslGrammar::acceptJumpStatement(TIntermNode*& statement) |
| 3165 | { |
John Kessenich | 5bc4d9a | 2016-06-20 01:22:38 -0600 | [diff] [blame] | 3166 | EHlslTokenClass jump = peek(); |
| 3167 | switch (jump) { |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 3168 | case EHTokContinue: |
| 3169 | case EHTokBreak: |
| 3170 | case EHTokDiscard: |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 3171 | case EHTokReturn: |
John Kessenich | 5bc4d9a | 2016-06-20 01:22:38 -0600 | [diff] [blame] | 3172 | advanceToken(); |
| 3173 | break; |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 3174 | default: |
John Kessenich | 5bc4d9a | 2016-06-20 01:22:38 -0600 | [diff] [blame] | 3175 | // not something we handle in this function |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 3176 | return false; |
| 3177 | } |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 3178 | |
John Kessenich | 5bc4d9a | 2016-06-20 01:22:38 -0600 | [diff] [blame] | 3179 | switch (jump) { |
| 3180 | case EHTokContinue: |
| 3181 | statement = intermediate.addBranch(EOpContinue, token.loc); |
| 3182 | break; |
| 3183 | case EHTokBreak: |
| 3184 | statement = intermediate.addBranch(EOpBreak, token.loc); |
| 3185 | break; |
| 3186 | case EHTokDiscard: |
| 3187 | statement = intermediate.addBranch(EOpKill, token.loc); |
| 3188 | break; |
| 3189 | |
| 3190 | case EHTokReturn: |
| 3191 | { |
| 3192 | // expression |
| 3193 | TIntermTyped* node; |
| 3194 | if (acceptExpression(node)) { |
| 3195 | // hook it up |
steve-lunarg | c4a1307 | 2016-08-09 11:28:03 -0600 | [diff] [blame] | 3196 | statement = parseContext.handleReturnValue(token.loc, node); |
John Kessenich | 5bc4d9a | 2016-06-20 01:22:38 -0600 | [diff] [blame] | 3197 | } else |
| 3198 | statement = intermediate.addBranch(EOpReturn, token.loc); |
| 3199 | break; |
| 3200 | } |
| 3201 | |
| 3202 | default: |
| 3203 | assert(0); |
| 3204 | return false; |
| 3205 | } |
| 3206 | |
| 3207 | // SEMICOLON |
| 3208 | if (! acceptTokenClass(EHTokSemicolon)) |
| 3209 | expected(";"); |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 3210 | |
John Kessenich | 5bc4d9a | 2016-06-20 01:22:38 -0600 | [diff] [blame] | 3211 | return true; |
| 3212 | } |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 3213 | |
John Kessenich | d02dc5d | 2016-07-01 00:04:11 -0600 | [diff] [blame] | 3214 | // case_label |
| 3215 | // : CASE expression COLON |
| 3216 | // |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 3217 | bool HlslGrammar::acceptCaseLabel(TIntermNode*& statement) |
| 3218 | { |
John Kessenich | d02dc5d | 2016-07-01 00:04:11 -0600 | [diff] [blame] | 3219 | TSourceLoc loc = token.loc; |
| 3220 | if (! acceptTokenClass(EHTokCase)) |
| 3221 | return false; |
| 3222 | |
| 3223 | TIntermTyped* expression; |
| 3224 | if (! acceptExpression(expression)) { |
| 3225 | expected("case expression"); |
| 3226 | return false; |
| 3227 | } |
| 3228 | |
| 3229 | if (! acceptTokenClass(EHTokColon)) { |
| 3230 | expected(":"); |
| 3231 | return false; |
| 3232 | } |
| 3233 | |
| 3234 | statement = parseContext.intermediate.addBranch(EOpCase, expression, loc); |
| 3235 | |
| 3236 | return true; |
| 3237 | } |
| 3238 | |
| 3239 | // default_label |
| 3240 | // : DEFAULT COLON |
| 3241 | // |
| 3242 | bool HlslGrammar::acceptDefaultLabel(TIntermNode*& statement) |
| 3243 | { |
| 3244 | TSourceLoc loc = token.loc; |
| 3245 | if (! acceptTokenClass(EHTokDefault)) |
| 3246 | return false; |
| 3247 | |
| 3248 | if (! acceptTokenClass(EHTokColon)) { |
| 3249 | expected(":"); |
| 3250 | return false; |
| 3251 | } |
| 3252 | |
| 3253 | statement = parseContext.intermediate.addBranch(EOpDefault, loc); |
| 3254 | |
| 3255 | return true; |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 3256 | } |
| 3257 | |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 3258 | // array_specifier |
steve-lunarg | 7b211a3 | 2016-10-13 12:26:18 -0600 | [diff] [blame] | 3259 | // : LEFT_BRACKET integer_expression RGHT_BRACKET ... // optional |
| 3260 | // : LEFT_BRACKET RGHT_BRACKET // optional |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 3261 | // |
| 3262 | void HlslGrammar::acceptArraySpecifier(TArraySizes*& arraySizes) |
| 3263 | { |
| 3264 | arraySizes = nullptr; |
| 3265 | |
steve-lunarg | 7b211a3 | 2016-10-13 12:26:18 -0600 | [diff] [blame] | 3266 | // Early-out if there aren't any array dimensions |
| 3267 | if (!peekTokenClass(EHTokLeftBracket)) |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 3268 | return; |
| 3269 | |
steve-lunarg | 7b211a3 | 2016-10-13 12:26:18 -0600 | [diff] [blame] | 3270 | // If we get here, we have at least one array dimension. This will track the sizes we find. |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 3271 | arraySizes = new TArraySizes; |
steve-lunarg | 7b211a3 | 2016-10-13 12:26:18 -0600 | [diff] [blame] | 3272 | |
| 3273 | // Collect each array dimension. |
| 3274 | while (acceptTokenClass(EHTokLeftBracket)) { |
| 3275 | TSourceLoc loc = token.loc; |
| 3276 | TIntermTyped* sizeExpr = nullptr; |
| 3277 | |
John Kessenich | 057df29 | 2017-03-06 18:18:37 -0700 | [diff] [blame] | 3278 | // Array sizing expression is optional. If omitted, array will be later sized by initializer list. |
steve-lunarg | 7b211a3 | 2016-10-13 12:26:18 -0600 | [diff] [blame] | 3279 | const bool hasArraySize = acceptAssignmentExpression(sizeExpr); |
| 3280 | |
| 3281 | if (! acceptTokenClass(EHTokRightBracket)) { |
| 3282 | expected("]"); |
| 3283 | return; |
| 3284 | } |
| 3285 | |
| 3286 | if (hasArraySize) { |
| 3287 | TArraySize arraySize; |
| 3288 | parseContext.arraySizeCheck(loc, sizeExpr, arraySize); |
| 3289 | arraySizes->addInnerSize(arraySize); |
| 3290 | } else { |
| 3291 | arraySizes->addInnerSize(0); // sized by initializers. |
| 3292 | } |
steve-lunarg | 265c061 | 2016-09-27 10:57:35 -0600 | [diff] [blame] | 3293 | } |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 3294 | } |
| 3295 | |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3296 | // post_decls |
John Kessenich | cfd7ce8 | 2016-09-05 16:03:12 -0600 | [diff] [blame] | 3297 | // : COLON semantic // optional |
| 3298 | // COLON PACKOFFSET LEFT_PAREN c[Subcomponent][.component] RIGHT_PAREN // optional |
| 3299 | // COLON REGISTER LEFT_PAREN [shader_profile,] Type#[subcomp]opt (COMMA SPACEN)opt RIGHT_PAREN // optional |
John Kessenich | e3218e2 | 2016-09-05 14:37:03 -0600 | [diff] [blame] | 3300 | // COLON LAYOUT layout_qualifier_list |
John Kessenich | cfd7ce8 | 2016-09-05 16:03:12 -0600 | [diff] [blame] | 3301 | // annotations // optional |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3302 | // |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 3303 | // Return true if any tokens were accepted. That is, |
| 3304 | // false can be returned on successfully recognizing nothing, |
| 3305 | // not necessarily meaning bad syntax. |
| 3306 | // |
| 3307 | bool HlslGrammar::acceptPostDecls(TQualifier& qualifier) |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 3308 | { |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 3309 | bool found = false; |
| 3310 | |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3311 | do { |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 3312 | // COLON |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3313 | if (acceptTokenClass(EHTokColon)) { |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 3314 | found = true; |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3315 | HlslToken idToken; |
John Kessenich | e3218e2 | 2016-09-05 14:37:03 -0600 | [diff] [blame] | 3316 | if (peekTokenClass(EHTokLayout)) |
| 3317 | acceptLayoutQualifierList(qualifier); |
| 3318 | else if (acceptTokenClass(EHTokPackOffset)) { |
John Kessenich | 96e9f47 | 2016-07-29 14:28:39 -0600 | [diff] [blame] | 3319 | // PACKOFFSET LEFT_PAREN c[Subcomponent][.component] RIGHT_PAREN |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3320 | if (! acceptTokenClass(EHTokLeftParen)) { |
| 3321 | expected("("); |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 3322 | return false; |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3323 | } |
John Kessenich | 82d6baf | 2016-07-29 13:03:05 -0600 | [diff] [blame] | 3324 | HlslToken locationToken; |
| 3325 | if (! acceptIdentifier(locationToken)) { |
| 3326 | expected("c[subcomponent][.component]"); |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 3327 | return false; |
John Kessenich | 82d6baf | 2016-07-29 13:03:05 -0600 | [diff] [blame] | 3328 | } |
| 3329 | HlslToken componentToken; |
| 3330 | if (acceptTokenClass(EHTokDot)) { |
| 3331 | if (! acceptIdentifier(componentToken)) { |
| 3332 | expected("component"); |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 3333 | return false; |
John Kessenich | 82d6baf | 2016-07-29 13:03:05 -0600 | [diff] [blame] | 3334 | } |
| 3335 | } |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3336 | if (! acceptTokenClass(EHTokRightParen)) { |
| 3337 | expected(")"); |
| 3338 | break; |
| 3339 | } |
John Kessenich | 7735b94 | 2016-09-05 12:40:06 -0600 | [diff] [blame] | 3340 | parseContext.handlePackOffset(locationToken.loc, qualifier, *locationToken.string, componentToken.string); |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3341 | } else if (! acceptIdentifier(idToken)) { |
John Kessenich | e3218e2 | 2016-09-05 14:37:03 -0600 | [diff] [blame] | 3342 | expected("layout, semantic, packoffset, or register"); |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 3343 | return false; |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3344 | } else if (*idToken.string == "register") { |
John Kessenich | cfd7ce8 | 2016-09-05 16:03:12 -0600 | [diff] [blame] | 3345 | // REGISTER LEFT_PAREN [shader_profile,] Type#[subcomp]opt (COMMA SPACEN)opt RIGHT_PAREN |
| 3346 | // LEFT_PAREN |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3347 | if (! acceptTokenClass(EHTokLeftParen)) { |
| 3348 | expected("("); |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 3349 | return false; |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3350 | } |
John Kessenich | b38f071 | 2016-07-30 10:29:54 -0600 | [diff] [blame] | 3351 | HlslToken registerDesc; // for Type# |
| 3352 | HlslToken profile; |
John Kessenich | 96e9f47 | 2016-07-29 14:28:39 -0600 | [diff] [blame] | 3353 | if (! acceptIdentifier(registerDesc)) { |
| 3354 | expected("register number description"); |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 3355 | return false; |
John Kessenich | 96e9f47 | 2016-07-29 14:28:39 -0600 | [diff] [blame] | 3356 | } |
John Kessenich | cfd7ce8 | 2016-09-05 16:03:12 -0600 | [diff] [blame] | 3357 | if (registerDesc.string->size() > 1 && !isdigit((*registerDesc.string)[1]) && |
| 3358 | acceptTokenClass(EHTokComma)) { |
John Kessenich | b38f071 | 2016-07-30 10:29:54 -0600 | [diff] [blame] | 3359 | // Then we didn't really see the registerDesc yet, it was |
| 3360 | // actually the profile. Adjust... |
John Kessenich | 96e9f47 | 2016-07-29 14:28:39 -0600 | [diff] [blame] | 3361 | profile = registerDesc; |
| 3362 | if (! acceptIdentifier(registerDesc)) { |
| 3363 | expected("register number description"); |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 3364 | return false; |
John Kessenich | 96e9f47 | 2016-07-29 14:28:39 -0600 | [diff] [blame] | 3365 | } |
| 3366 | } |
John Kessenich | b38f071 | 2016-07-30 10:29:54 -0600 | [diff] [blame] | 3367 | int subComponent = 0; |
| 3368 | if (acceptTokenClass(EHTokLeftBracket)) { |
| 3369 | // LEFT_BRACKET subcomponent RIGHT_BRACKET |
| 3370 | if (! peekTokenClass(EHTokIntConstant)) { |
| 3371 | expected("literal integer"); |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 3372 | return false; |
John Kessenich | b38f071 | 2016-07-30 10:29:54 -0600 | [diff] [blame] | 3373 | } |
| 3374 | subComponent = token.i; |
| 3375 | advanceToken(); |
| 3376 | if (! acceptTokenClass(EHTokRightBracket)) { |
| 3377 | expected("]"); |
| 3378 | break; |
| 3379 | } |
| 3380 | } |
John Kessenich | cfd7ce8 | 2016-09-05 16:03:12 -0600 | [diff] [blame] | 3381 | // (COMMA SPACEN)opt |
| 3382 | HlslToken spaceDesc; |
| 3383 | if (acceptTokenClass(EHTokComma)) { |
| 3384 | if (! acceptIdentifier(spaceDesc)) { |
| 3385 | expected ("space identifier"); |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 3386 | return false; |
John Kessenich | cfd7ce8 | 2016-09-05 16:03:12 -0600 | [diff] [blame] | 3387 | } |
| 3388 | } |
| 3389 | // RIGHT_PAREN |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3390 | if (! acceptTokenClass(EHTokRightParen)) { |
| 3391 | expected(")"); |
| 3392 | break; |
| 3393 | } |
John Kessenich | cfd7ce8 | 2016-09-05 16:03:12 -0600 | [diff] [blame] | 3394 | parseContext.handleRegister(registerDesc.loc, qualifier, profile.string, *registerDesc.string, subComponent, spaceDesc.string); |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3395 | } else { |
| 3396 | // semantic, in idToken.string |
John Kessenich | 7735b94 | 2016-09-05 12:40:06 -0600 | [diff] [blame] | 3397 | parseContext.handleSemantic(idToken.loc, qualifier, *idToken.string); |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3398 | } |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 3399 | } else if (peekTokenClass(EHTokLeftAngle)) { |
| 3400 | found = true; |
John Kessenich | a1e2d49 | 2016-09-20 13:22:58 -0600 | [diff] [blame] | 3401 | acceptAnnotations(qualifier); |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 3402 | } else |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3403 | break; |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 3404 | |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 3405 | } while (true); |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 3406 | |
| 3407 | return found; |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 3408 | } |
| 3409 | |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 3410 | } // end namespace glslang |