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