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