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